我正在尝试使用R中的spaMM软件包和fitme()函数运行线性混合模型,但是当我添加第三个随机效果时,predict()函数无法完成。
我希望meanfit1模型具有一种固定的效果:
elev
和三种随机效果:
Matern(1|long+lat)
1|river_ID
1|source_ID
但是,预测函数似乎不允许三个随机效应。
Data <- data.frame(source_ID = c("A","B","C","D","E"),
lat = c(51.63,51.69,51.72,51.69,51.72),
long = c(1.56,1.51,1.37,1.43,1.60),
river_ID = c("b","a","b","b","t"),
elev = c(63,54,32,45,48),
mean = c(28,28,31,31,27),
n = rep(5,5),
var = c(0.1,0.4,0.5,1.5,0.8))
dispfit1 <- fitme(
formula = var ~ 1 + Matern(1|long + lat) + (1|river_ID) +
(1|source_ID),
family = stats::Gamma(log), data = Data, fixed = list(phi = 2),
prior.weights = n - 1, control.dist = list(dist.method =
"Earth"),
method = "REML")
Data$disp <- spaMM::predict.HLfit(dispfit1, newdata = Data, variances =
list(respVar = T))
meanfit1 <- fitme(
formula = mean ~ 1 + elev + Matern(1|long + lat) + (1|river_ID) +
(1|source_ID),
data = Data, resid.model = list(formula = ~0 + offset(disp), family =
stats::Gamma(identity)),
prior.weights = n, control.dist = list(dist.method = "Earth"),
method = "REML")
如果我删除(1 | source_ID)或(1 | river_ID),则代码运行良好,但是当包括所有三个随机效果时,会给出以下错误消息:''+'(c(0,0, 0,0,0,0,0.00508460138716231,0,0,0,0,0,0,: 运算符需要一个或两个参数”
这是编码问题还是建模问题?
非常感谢您的帮助
答案 0 :(得分:0)
对于OP中的问题,
这是编码问题还是建模问题?
答案是这是spaMM源代码中的错误;海报的代码是正确的。 spaMM应该能够评估涉及两个以上随机效应的模型的预测方差。此package的版本3.0.0已纠正了该错误。