1

I am trying to extract fixed effects from two nlme models. my reprex is

SAC<-data.frame(
   row.names = c("1", "3", "4", "5", "6", "7"),
    SZCug_dL = c(46.875, 50, 65.625, 62.5, 40.625, 62.5),
          UrineZN_Cr = c(545.719546038266,
                         174.079978025994,915.970562853193,715.51555504984,
                         125.071835981547,488.546883216235),
                   z = c(3.84748448429057,
                         3.91202300542815,4.18395672091179,4.13516655674236,
                         3.7043836406499,4.13516655674236),
                   x = c(6.04681340416001,
                         4.36615081777328,6.61266697401435,6.85034696955171,
                         5.15700813886738,5.81233722866466),
          HH = as.factor(c("1837", "30", "164", "164", "165", "200")),
          CL = as.factor(c("303", "813", "459", "459", "459", "361"))
        )
#>   SZCug_dL UrineZN_Cr        z        x   HH  CL
#> 1   46.875   545.7195 3.847484 6.046813 1837 303
#> 3   50.000   174.0800 3.912023 4.366151   30 813
#> 4   65.625   915.9706 4.183957 6.612667  164 459
#> 5   62.500   715.5156 4.135167 6.850347  164 459
#> 6   40.625   125.0718 3.704384 5.157008  165 459
#> 7   62.500   488.5469 4.135167 5.812337  200 361

When I run the code and summary, I get an output without the fixed effects (most times) sometimes it appears and it's not as if I do anything different. What I usually get is

model1<-lme(z~1,data=df,random=~1|CL/HH)
summary(model1)
Linear mixed-effects model fit by REML
  Data: df 

Random effects:
 Formula: ~1 | CL
         (Intercept)
StdDev: 3.831037e-06

 Formula: ~1 | HH %in% CL
        (Intercept)   Residual
StdDev:   0.1914616 0.03440302

Fixed effects:  z ~ 1 

Standardized Within-Group Residuals:
        Min          Q1         Med          Q3         Max 
-0.61342297 -0.19294160 -0.06602971  0.11545996  0.80477144 

Number of Observations: 6
Number of Groups: 
        CL HH %in% CL 
         4          5 

or

model2<-lme(z~x,data=df,random=~1|CL/HH)
> summary(model2)
Linear mixed-effects model fit by REML
  Data: df 

Random effects:
 Formula: ~1 | CL
        (Intercept)
StdDev: 3.09174e-06

 Formula: ~1 | HH %in% CL
        (Intercept)     Residual
StdDev:   0.1264505 6.609614e-07

Fixed effects:  z ~ x 
 Correlation: 
  (Intr)
x 0     

Standardized Within-Group Residuals:
          Min            Q1           Med            Q3           Max 
-8.118371e-06 -4.120831e-06  9.382856e-07  4.479113e-06  6.386927e-06 

Number of Observations: 6
Number of Groups: 
        CL HH %in% CL 
         4          5 

for model 2.

However sometimes, weirdly enough, the fixed effects show up and when they do, it works for both models and I get something like this (note, this output below is not from the reprex, but from a previous run)

> summary(model2)
Linear mixed-effects model fit by REML
  Data: SAC 
        AIC       BIC   logLik
  -75.47897 -53.17945 42.73949

Random effects:
 Formula: ~1 | CL
        (Intercept)
StdDev:   0.1108957

 Formula: ~1 | HH %in% CL
        (Intercept)  Residual
StdDev:  0.08661432 0.1934164

Fixed effects:  z ~ x 
               Value  Std.Error  DF  t-value p-value
(Intercept) 3.743666 0.05369683 315 69.71857       0
x           0.062271 0.00921621 315  6.75669       0
 Correlation: 
  (Intr)
x -0.96 

Standardized Within-Group Residuals:
        Min          Q1         Med          Q3         Max 
-3.63918369 -0.55392006  0.03131735  0.54203818  3.48252151 

Number of Observations: 641
Number of Groups: 
        CL HH %in% CL 
        97        325 

This problem occurs for both the null and the saturated model. I need to extract these for about 30 models and have only gotten three so far after days of trying.

  • 1
    Could we please have a [mcve]? Is this fixed effects table missing in the summary if (and only if) you have an intercept-only fixed-effect model, i.e. `z ~ 1` rather than `z ~ x` ? – Ben Bolker Dec 09 '21 at 20:49
  • @BenBolker I have added a reprex to the question. The problem persists for both `z~1` and `z~x` and when it work, it also works for both – hendrina Likoswe Dec 10 '21 at 07:19
  • 1
    So far, not reproducible. Using your example posted above, I get the fixed-effect tables in the output of `summary()` just fine. FWIW you can get *just* the coefficient table via `summary(model1)$tTab` ... My main suggestions at this point are (1) run the example you gave above in a *clean* R session with only `nlme` loaded. (2) Post the results of `sessionInfo()`. (3) If you encounter the problem you've described, please `dput()` the problematic model and edit the results into your answer. – Ben Bolker Dec 10 '21 at 23:36
  • Thank you so so so so much!!!!! `summary(model1)$tTab` works !!!!!! and that's all I needed. I suppose there could be some interferences with other packages (as a layman, I am juggling a few analyses so have had the session open for a while). I will remember this for next time. Much appreciated – hendrina Likoswe Dec 15 '21 at 21:03

0 Answers0