2016-07-25 83 views
0

我是一些代謝縮放模型的參數化指數擬合。我已經在lmer中完成了這個工作,沒有問題,使用了記錄的依賴變量和獨立變量。但是,我現在想要包含與因變量不一定成指數關係的其他參數。因此,我轉向nlme(lme4 :: nlmer似乎不處理固定效果),但我沒有太多的經驗。提前道歉爲新手的錯誤。nlme中的因素:backsolve錯誤中的奇異點

隨着下面的代碼,我收到以下錯誤。我猜,這事做的「現場」的因素被錯誤識別:

Error in nlme.formula(dep ~ scaling_fun(alpha, beta, ind, site), data = scale_df, : 
    Singularity in backsolve at level 0, block 1 

當我適合不涉及「網站」一個簡單的功能,該模型似乎正常工作。

任何想法將不勝感激!

感謝, 艾莉

# 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

您的模型並沒有真正意義,因爲site是一個因素變量(而不是參數)。我懷疑你真的想通過site分層alpha

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應該是隨機效應。

+0

謝謝羅蘭 - 這很有道理。我對以下數學公式感興趣: D =(β_1+β_site+β_spp)•I ^(α_1+α_site+α_spp), 其中β_1是大平均β項,β_site是每站點偏差從這意味着,並且β_spp是一個隨機項(對於α是相同的)。爲此,我編碼網站的偏差(總和爲零)對比[例如對比(site)= contr.sum(levels(site))]。使用您的scaling_fun,我運行nlme: fixed = list(alpha + beta_site),random = alpha + beta〜1 | spp。 然後,我將α(截距)解釋爲α_1和β(截距)作爲β_1。你同意嗎? –

+0

順便說一句,我其實對每站點偏差的價值感興趣,因此,我將它們編碼爲固定效果。 –

+0

你知道你也可以提取隨機效應,而不僅僅是固定係數? – Roland