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.