【发布时间】:2017-12-13 02:02:14
【问题描述】:
我的数据集中有几个因变量,我想找到 x 和每个 y 之间的最佳拟合。如何修改以下代码(循环函数)以同时绘制 x 和所有 y 的图。我不想单独运行每个因变量的代码,而是想运行一个代码并为 (x,y) (x,y1) 和 (x,y2) 绘制三个图
fit1 <- read.table(header=TRUE,text="
x y y1 y2
1 0 2.36 3 5
2 1 1.10 3 6
3 2 0.81 4 7
4 3 0.69 1.3 8
5 4 0.64 2.3 9
6 5 0.61 4.3 15")
Various fits:
library(ggplot2)
ggplot(fit1,aes(x,y))+geom_point()+
geom_smooth(method="glm",se=FALSE,
method.args=list(family=gaussian(link="log")))+
geom_smooth(method="nls",se=FALSE,
formula=y~a+b*exp(-c*x),
method.args=list(start=list(a=0.6,b=1.5,c=1)),
colour="red")+
geom_smooth(method="lm",se=FALSE,
formula=y~exp(-x),
colour="purple")
【问题讨论】:
标签: regression