【发布时间】:2017-06-22 21:29:04
【问题描述】:
我有一系列数据拟合幂曲线,我使用 R 中的预测函数允许我根据额外的 x 值预测 y 值。
set.seed(1485)
len <- 24
x <- runif(len)
y <- x^3 + rnorm(len, 0, 0.06)
ds <- data.frame(x = x, y = y)
mydata=data.frame(x,y)
z <- nls(y ~ a * x^b, data = mydata, start = list(a=1, b=1))
#z is same as M!
power <- round(summary(z)$coefficients[1], 3)
power.se <- round(summary(z)$coefficients[2], 3)
plot(y ~ x, main = "Fitted power model", sub = "Blue: fit; green: known")
s <- seq(0, 1, length = 100)
lines(s, s^3, lty = 2, col = "green")
lines(s, predict(z, list(x = s)), lty = 1, col = "blue")
text(0, 0.5, paste("y =x^ (", power, " +/- ", power.se,")", sep = ""), pos = 4)
我如何在此幂函数的基础上根据附加的 x 值手动计算估计的 y 值,而不是在此处使用预测函数。如果这只是一个简单的线性回归,我会计算斜率和 y 截距并通过
计算我的 y 值y= mx + b
我可以从 z 的输出中使用类似的等式,让我可以从额外的 x 值估计 y 值吗?
> z
Nonlinear regression model
model: y ~ a * x^b
data: mydata
a b
1.026 3.201
residual sum-of-squares: 0.07525
Number of iterations to convergence: 5
Achieved convergence tolerance: 5.162e-06
【问题讨论】:
标签: r curve-fitting prediction non-linear-regression