Home > Software design >  printCoefmat() function turns back an error
printCoefmat() function turns back an error

Time:10-28

I've built the followinf model

model2 <- lmerTest::lmer(LPP2POz ~ 1   COND   (1|ID), data = dataLPP2POz)

If I try to run the following function it turns back this error:

printCoefmat(summary(model2)$tTable, 
             has.Pvalue = T, P.values = T)

Here a short dataframe from the dataset I'm working on

dput(head(dataLPP2POz))
structure(list(ID = structure(c(1L, 1L, 1L, 2L, 2L, 2L), .Label = c("01", 
"04", "06", "07", "08", "09", "10", "11", "12", "13", "15", "16", 
"17", "18", "19", "21", "22", "23", "25", "27", "28", "30", "44", 
"46", "49"), class = "factor"), GR = c("RP", "RP", "RP", "RP", 
"RP", "RP"), SES = c("V", "V", "V", "V", "V", "V"), COND = structure(c(1L, 
2L, 3L, 1L, 2L, 3L), .Label = c("NEG-CTR", "NEG-NOC", "NEU-NOC"
), class = "factor"), LPP2POz = c(7.91468942320841, 9.94838815736199, 
10.2186482048953, 1.07455889922813, 1.65917850515029, 3.22422743232682
)), row.names = c(NA, 6L), class = "data.frame")

Error in printCoefmat(summary(model2)$tTable, has.Pvalue = T, P.values = T) : 
  'x' must be coefficient matrix/data frame

Anyone is able to understand what the error is?

CodePudding user response:

Following up and clarifying @aosmith's comments a little bit.

Extracting the coefficient table works differently for different mixed-model packages. The newer default (which works for lme4, lmerTest, glmmTMB) is that the coefficient table can be extracted as summary(model)$coefficients (under the hood, this means that the summary() method returns a list with the coeff table stored as the $coefficients) element. For these packages, coef(summary(model)) is even better practice.

For objects from the nlme package (i.e. lme), the summary table is stored as summary(model)$tTable (this is unfortunate, but nlme is older than R itself ...

It doesn't give exactly the same results as printCoefmat, but you might also look into some of the options for pretty-printing the output of broom.mixed::tidy(), which aims to build a compatibility layer so you don't have to remember all this stuff ...

  • Related