使用R的非线性混合模型?

时间:2013-11-26 02:32:07

标签: r mixed-models nlme

我有一个像这个示例数据的数据集,其中包括三个站点。我想用“timeInt”模拟“cumSR”的趋势。我使用以下模型为每个站点做了这个(“cumSR~b /(cc +(timeInt)^( - z))”)。现在我想使用相同的模型来获得这三个站点的一条曲线。我认为我需要使用非线性混合模型,对吧?我在“nlme”包中尝试了“nlme”函数,在“lme4”函数中尝试了“nlmer”函数,但还没弄明白。有人可以帮忙吗?非常感谢。

    dat = data.frame(cumSR=c(17, 25, 34, 43, 46, 49, 51, 52, 55, 57, 59, 60, 18, 26, 34, 38, 41, 43, 45, 49, 51, 54, 
                     57, 58, 59, 23, 29, 33, 37, 38, 40, 44, 46, 47),
             timeInt=c(2.5, 7.5, 12.5, 17.5, 22.5, 27.5, 32.5, 42.5, 47.5, 52.5, 62.5, 67.5, 2.5, 7.5, 12.5, 17.5, 
                       22.5, 27.5, 32.5, 37.5, 42.5, 47.5, 52.5, 57.5, 62.5, 2.5, 7.5, 12.5, 17.5, 22.5, 37.5, 42.5, 47.5, 57.5),
             site=c("A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "B","B", 
                    "B", "B", "B", "B", "B", "B", "C","C","C","C","C","C","C","C","C"))


    par(mfcol=c(1,3))
    dat1 <- dat[which(dat$site=="A"),]
    SAR.nls.logist <- nls(cumSR~b/(cc+(timeInt)^(-z)), data=dat1,start = list(b=10,cc=.1,z=.5))
    plot(dat1$timeInt,dat1$cumSR, type="b",col=1)
    curve(coef(SAR.nls.logist)[1]/(coef(SAR.nls.logist)[2]+(x)^(-coef(SAR.nls.logist)[3])), col = "pink", type="l",add = TRUE,lwd=2)

    dat1 <- dat[which(dat$site=="B"),]
    SAR.nls.logist <- nls(cumSR~b/(cc+(timeInt)^(-z)), data=dat1,start = list(b=10,cc=.1,z=.5))
    plot(dat1$timeInt,dat1$cumSR, type="b",col=1)
    curve(coef(SAR.nls.logist)[1]/(coef(SAR.nls.logist)[2]+(x)^(-coef(SAR.nls.logist)[3])), col = "pink", type="l",add = TRUE,lwd=2)

    dat1 <- dat[which(dat$site=="C"),]
    SAR.nls.logist <- nls(cumSR~b/(cc+(timeInt)^(-z)), data=dat1,start = list(b=10,cc=.1,z=.5))
    plot(dat1$timeInt,dat1$cumSR, type="b",col=1)
    curve(coef(SAR.nls.logist)[1]/(coef(SAR.nls.logist)[2]+(x)^(-coef(SAR.nls.logist)[3])), col = "pink", type="l",add = TRUE,lwd=2)

0 个答案:

没有答案