jor*_*ran 13
使用示例中的第一个示例,?nls我逐行指向您实现以下内容:
#This is just our data frame
DNase1 <- subset(DNase, Run == 1)
DNase1$lconc <- log(DNase1$conc)
#Fit the model
fm1DNase1 <- nls(density ~ SSlogis(lconc, Asym, xmid, scal), DNase1)
#Plot the original points
# first argument is the x values, second is the y values
plot(DNase1$lconc,DNase1$density)
#This adds to the already created plot a line
# once again, first argument is x values, second is y values
lines(DNase1$lconc,predict(fm1DNase1))
Run Code Online (Sandbox Code Playgroud)
参数的predict方法nls是自动返回拟合y值.或者,您添加一个步骤并执行
yFitted <- predict(fm1DNase1)
Run Code Online (Sandbox Code Playgroud)
并传入yFitted第二个参数lines.结果如下:

或者,如果你想要一个"平滑"的曲线,你所做的就是简单地重复这一点,但在更多点评估函数:
r <- range(DNase1$lconc)
xNew <- seq(r[1],r[2],length.out = 200)
yNew <- predict(fm1DNase1,list(lconc = xNew))
plot(DNase1$lconc,DNase1$density)
lines(xNew,yNew)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15832 次 |
| 最近记录: |