的NLS assymptote功能的geom_smooth我有以下數據框:如何得到使用SSasympOff
df1<- structure(list(Site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("ALT01"), class = "factor"), Nets = 1:18, Cumulative.spp = c(12L,13L, 15L, 17L, 17L, 17L, 17L, 19L, 19L, 19L, 19L, 20L, 22L, 22L, 22L, 22L, 22L, 22L)), .Names = c("Site", "Nets", "Cumulative.spp"), row.names = c(NA, 18L), class = "data.frame")
,我試圖讓使用此功能的geom_smooth響應GGPLOT2情節:
Model1<-nls(Cumulative.spp ~ SSasympOff(Nets, A, lrc, c0), data = df1)
通常如果我有這樣的模式:
Model2 <- lm(Cumulative.spp ~ I(log(Nets), data = df1)
我嘗試了兩種方法
方法1
我這樣做:
library(ggplot2)
ggplot(df1, aes(x=Nets, y = Cumulative.spp)) + geom_point() + geom_smooth(method="lm", formula=y~log(x), fill="blue", fullrange=T)
但是當我嘗試做的assymptote同它不工作:
ggplot(df1, aes(x=Nets, y = Cumulative.spp)) + geom_point() + geom_smooth(method="nls", formula=y~SSasympOff(x, A, lrc, c0), color="blue", fullrange=T)
但我得到這個錯誤和這個情節:
Warning message:
Computation failed in `stat_smooth()`:
$ operator is invalid for atomic vectors
方法2
我試圖預測比原先的數據幀得到一個置信區間和區間使用geom_line
在預測值和geom_ribbon
,但是當我做
predict(Model1, df1, interval = "confidence")
但我沒有得到置信區間,只有t他預測值
任何幫助,將不勝感激
爲什麼不是更快只需使用'geom_line'添加預測值,然後使用'geom_ribbon'添加間隔? – bouncyball
嗨@bouncyball我試圖這樣做,但我沒有得到間隔,我試着預測(Model1,df1,interval =「confidence」),就像我在'predict.nls'文檔中找到的那樣,但是它不會給我一個置信區間,我會將此添加到我在問題中嘗試的內容。 –
你也許可以使用bootstrap百分比方法,然後......沒有意識到用'nls'獲得置信區間會非常困難。我的錯誤 – bouncyball