我正在参数化一些代谢缩放模型的指数拟合。我已经在lmer中完成了这个,没有问题,使用记录的依赖和自变量。但是,我现在想要合并其他参数,这些参数不一定与因变量呈指数关系。因此,我转向nlme(lme4 :: nlmer似乎没有处理固定效果),但我没有太多经验。为新手错误提前道歉。
使用下面的代码,我收到以下错误。我猜这与错误指定的'网站'因素有关:
Error in nlme.formula(dep ~ scaling_fun(alpha, beta, ind, site), data = scale_df, :
Singularity in backsolve at level 0, block 1
当我适合一个不涉及'site'的简单函数时,该模型似乎正常工作。
任何想法都将不胜感激!
谢谢, 艾莉
# dput for data
# copy from http://pastebin.com/WNHhi2kZ (too large to include here)
> head(scale_df)
dep ind spp site
2 0.28069471 -0.0322841 157 A
3 -0.69719050 -1.2568901 183 A
4 0.29252012 0.1592420 246 A
5 0.72030740 -0.3282789 154 A
6 -0.08601891 0.3623756 110 A
7 0.30793594 0.2230840 154 A
scaling_fun <- function(alpha, beta, ind, site) {
return(beta + ind^alpha + site*(ind^alpha))
}
# results in singularity in backsolve error
nlme(dep ~ trait_scaling_fun(alpha, beta, ind, site),
data = scale_df,
fixed = list(alpha + beta + site ~ 1), random = alpha ~ 1|spp,
start = list(fixed = c(0.7, 0, 1)))
##############################
# simpler function converges #
##############################
scaling_fun <- function(alpha, beta, ind) {
return(beta + ind^alpha)
}
nlme(dep ~ scaling_fun(alpha, beta, ind),
data = scale_df,
fixed = list(alpha + beta ~ 1), random = alpha ~ 1|spp,
start = list(fixed = c(0.7, 0)))
答案 0 :(得分:1)
你的模型没有意义,因为site
是一个因子变量(而不是参数)。我怀疑你确实想要alpha
对site
进行分层:
library(nlme)
scaling_fun <- function(alpha, beta, ind) {
return(beta + ind^alpha)
}
nlme(dep ~ scaling_fun(alpha, beta, ind),
data = scale_df,
fixed = list(alpha ~ site, beta ~ 1), random = alpha ~ 1|spp,
start = list(fixed = c(0.487, rep(0, 19), -0.3)))
#Nonlinear mixed-effects model fit by maximum likelihood
# Model: dep ~ scaling_fun(alpha, beta, ind)
# Data: scale_df
# Log-likelihood: -716.4634
# Fixed: list(alpha ~ site, beta ~ 1)
#alpha.(Intercept) alpha.siteB alpha.siteC alpha.siteD alpha.siteE
# 0.57671912 -0.61258632 -0.59244337 -0.25793558 -0.24572998
# alpha.siteF alpha.siteG alpha.siteH alpha.siteI alpha.siteJ
# -0.23615274 -0.31015393 0.17970575 0.01286117 -0.12539377
# alpha.siteK alpha.siteL alpha.siteM alpha.siteN alpha.siteO
# 3.72445972 -0.08560994 0.13636185 0.31877456 -0.25952204
# alpha.siteQ alpha.siteR alpha.siteS alpha.siteT alpha.siteU
# 0.15663989 0.66511079 0.10785082 -0.21547379 -0.23656126
# beta
# -0.30280707
#
#Random effects:
# Formula: alpha ~ 1 | spp
# alpha.(Intercept) Residual
#StdDev: 0.6426563 0.4345844
#
#Number of Observations: 1031
#Number of Groups: 279
但是,我也怀疑site
应该是随机效应。