[英]How to calculate R-squared in nls package (non-linear model) in R?
I analyzed non-linear regression using nls package.我使用 nls 包分析了非线性回归。
power<- nls(formula= agw~a*area^b, data=calibration_6, start=list(a=1, b=1))
summary(power)
I heard in non-linear model, R-squared is not valid and rather than R-squared, we usually show residual standard error which R provides我听说在非线性模型中,R 平方无效,而不是 R 平方,我们通常显示 R 提供的残差标准误差
However, I just want to know what R-squared is.但是,我只想知道 R 平方是什么。 Is that possible to check R-squared in nls package?
是否可以在 nls 包中检查 R 平方?
Many thanks!!!非常感谢!!!
I found the solution.我找到了解决方案。 This method might not be correct in terms of statistics (As R^2 is not valid in non-linear model), but I just want see the overall goodness of fit for my non-linear model.
这种方法在统计方面可能不正确(因为 R^2 在非线性模型中无效),但我只想看看我的非线性模型的整体拟合优度。
Step 1> to transform data as log (common logarithm)步骤1>将数据转换为对数(常用对数)
When I use non-linear model, I can't check R^2当我使用非线性模型时,我无法检查 R^2
nls(formula= agw~a*area^b, data=calibration, start=list(a=1, b=1))
Therefore, I transform my data to log因此,我将数据转换为日志
x1<- log10(calibration$area)
y1<- log10(calibration$agw)
cal<- data.frame (x1,y1)
Step 2> to analyze linear regression Step 2> 分析线性回归
logdata<- lm (formula= y1~ x1, data=cal)
summary(logdata)
Call:
lm(formula = y1 ~ x1)
This model provides, y= -0.122 + 1.42x该模型提供,y= -0.122 + 1.42x
But, I want to force intercept to zero, therefore,但是,我想强制截距为零,因此,
Step 3> to force intercept to zero步骤 3> 强制截距为零
logdata2<- lm (formula= y1~ 0 + x1)
summary(logdata2)
Now the equation is y= 1.322x, which means log (y) = 1.322 log (x),现在方程是 y= 1.322x,这意味着 log (y) = 1.322 log (x),
so it's y= x^1.322.所以它是 y= x^1.322。
In power curve model, I force intercept to zero.在功率曲线模型中,我强制截距为零。 The R^2 is 0.9994
R^2 是 0.9994
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.