【发布时间】:2021-11-10 21:57:09
【问题描述】:
我正在模拟四个河口的盐度水平与一条大河的淡水排放(影响所有 4 个河口)的关系,其中每个盐度站都被视为随机效应(每个河口有多个传感器)。
我的 df 看起来像这样: *注意 = 实际上,每个站点都有数十个甚至数百个观测值
estuary station salinity discharge
A s1 10.8 1185.18
A s2 11.1 1551.91
A s3 12.5 1749.98
B s4 9.2 1100.65
B s5 11.8 1692.67
C s6 8.1 591.41
C s7 8.7 742.88
D s8 10.4 1098.1
D s9 11.9 1174.6
我使用自启动函数 SSasymp 为数据拟合了指数衰减函数。该模型将站点作为随机效应。代码如下:
df$station <- as.factor(df$station)
df.g <- groupedData(salinity ~ discharge | station, data = df)
df.nlis <- nlsList(salinity ~ SSasymp(discharge, Asym, R0, lrc), data = df.g)
## Fit a nonlinear mixed model
df.nlme <- nlme(df.nlis, control=list(MaxIter = 200, msVerbose = T))
我还想运行另一个将河口作为固定效应的模型,但是我不确定如何编写模型。我试过了:
df.g <- groupedData(salinity ~ discharge + estuary | station, data = df)
df.nlis <- nlsList(salinity ~ SSasymp(discharge, Asym, R0, lrc) + estuary, data = df.g)
df.nlme <- nlme(df.nlis, control=list(MaxIter = 200, msVerbose = T))
但是当它运行时,我会收到消息:
Error in names(start$fixed) <- names(cf) : attempt to set an attribute on
NULL
【问题讨论】:
-
请与
dput()而不是代码块共享您的数据 -
IMO 代码块还不错——用
read.table(header=TRUE, text = "...")阅读它们很容易,但如果有一个示例,每组有足够的数据点以允许代码运行,这将很有用跨度> -
我不知道,谢谢
read.table()提示
标签: r nlme exponential-distribution