在R
中构造具有随机误差项的非线性结构方程模型library(piecewiseSEM)
library(lme4)
library(nlme)
head(VTmodelmeansadults)
id Round Cycle Day Stage Temp Type Sample Pos md possal posabd mat.max mat.mean adj.r8 cage matage
70 1 G1 3 27 1 1 G1 3 G1 3 27 abd 27 1 abd 0 0.25 0 0 2.426511 0.6378 0 G1 3 27 3
73 1 G1 3 27.2 1 G1 3 G1 3 27 abd 27.2 abd 0 0.25 0 0 2.426511 0.6378 0 G1 3 27 3
76 1 G1 3 27.3 1 G1 3 G1 3 27 abd 27.3 abd 0 0.25 0 0 2.426511 0.6378 0 G1 3 27 3
82 1 G1 3 27.4 1 G1 3 G1 3 27 abd 27.4 abd 0 0.25 0 0 2.426511 0.6378 0 G1 3 27 3
85 1 G1 3 27.5 1 G1 3 G1 3 27 abd 27.5 abd 0 0.25 0 0 2.426511 0.6378 0 G1 3 27 3
88 1 G1 3 27.7 1 G1 3 G1 3 27 abd 27.7 abd 0 0.25 0 0 2.426511 0.6378 0 G1 3 27 3
从数据中可以看出,我想知道day,md和cycle对二项式结果Pos的影响。 md本身受温度和成熟度的影响,并且笼子有随机效应。
model = list(
lme(md ~ Temp + matage, random = ~ 1|cage, na.action = na.omit,
data = VTmodelmeansadults),
glmer(Pos ~ Day + md + Cycle +(1|cage),
family=binomial(link = "logit"), data = VTmodelmeansadults))
summary(model)
Length Class Mode
[1,] 18 lme list
[2,] 1 glmerMod S4
评估模型匹配时,我收到以下错误消息
sem.fit(model, VTmodelmeansadults)
|========================================| 75%
Error in MEEM(object, conLin, control$niterEM) :
Singularity in backsolve at level 0, block 1
我已经尝试用lmer()代替lme(),以防出现别名问题但是会收到此错误
model = list(
lmer(md ~ Temp + matage + (1|cage), na.action = na.omit,
data = VTmodelmeansadults),
glmer(Pos ~ Day + md + Cycle +(1|cage),
family=binomial(link = "logit"), data = VTmodelmeansadults))
sem.fit(model, VTmodelmeansadults)
|==================================================================| 75%
Error in KRmodcomp.lmerMod(basis.mod.new, basis.mod.drop) :
Models have either equal fixed mean stucture or are not nested'
它仍然是一个别名问题吗?或者glmer模型可能与lmer模型冲突?
非常感谢任何帮助。
改编自jshlefe超级有用的piecewiseSEM包的方法 https://github.com/jslefche/piecewiseSEM