Pur*_*ina 5 r curve-fitting ggplot2
我是 R 的初学者,我正在尝试将曲线拟合到(例如)可能如下所示的数据集上:
(x- value) (y-value)
105 423
115 471
125 567
135 808
145 921.5
155 1040
Run Code Online (Sandbox Code Playgroud)
x 值代表刺激量,y 值代表运动反应(以 uV 为单位)。这些是 10 个科目的平均值,其中每个科目的 x 值都相同。
有人告诉我,这个数据集通常遵循 sigmoidal 拟合。我尝试用以下方法拟合它:
fit <- lm( y ~ poly(x, 3) )
Run Code Online (Sandbox Code Playgroud)
但我不确定这是否是执行此操作的合适方法:(
到目前为止,我的代码如下所示:
p <- ggplot (data, aes(x, y)) +
geom_point(shape= 21, fill= "blue", colour= "black", size=2) +
xlab("X value") + ylab("Y value") +
geom_smooth(method= "lm", se= FALSE, colour= "red", formula=y ~ poly(x, 3, raw=TRUE)) +
geom_errorbar(aes(ymin=y-SE, ymax=y+SE), width=.9)+
ggtitle ("Title")
p
Run Code Online (Sandbox Code Playgroud)
另外:一旦我拟合了曲线,我还想获得斜率(计算为曲线最陡点处的切线值)
提前致谢,任何帮助将不胜感激!
我不知道 poly() 函数应该如何工作,但如果你想要三阶多项式拟合,只需使用:
lm1=lm(y~I(x^3)+I(x^2)+x)
Run Code Online (Sandbox Code Playgroud)
这非常适合您上面的玩具数据。为拐点处的斜率。我会将二阶导数设置为零并求解 x。然后计算 x 处的第一个导数。
但我认为您更喜欢物流增长模式。
| 归档时间: |
|
| 查看次数: |
7324 次 |
| 最近记录: |