简体   繁体   English

如何在R中的nls包(非线性模型)中计算R平方?

[英]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!!!非常感谢!!!

  • OutPut输出

在此处输入图片说明

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.

相关问题 具有低r平方值的非线性回归问题 - Problem with non-linear regression with low r-squared value 如何从装有来自 R 中 nlme 包的 gls 的模型计算伪 R 平方 - How to calculate pseudo R-squared from a model fitted with gls from the nlme package in R 如何引导混合 model 的 R 平方? - How to bootstrap R-squared of a mixed model? R:使用二维非线性最小二乘(nls)的流行扩散模型 - R: epidemic diffusion model using two-dimensional non-linear least squares (nls) 为什么 R 中的 nls(非线性模型)方程与 Excel 不同? - Why nls (non-linear model) equation in R is different from Excel? 在R中使用nls进行非线性回归的交叉验证 - Cross-validation for non-linear regression using nls in R 非线性回归,nls,在 R:奇异梯度 - Non-linear regression, nls, in R: singular gradient 在具有单个预测变量的线性回归模型中,R平方和调整R平方是否应该相同? - should R-squared and adj.R-squared be the same in a linear regression model with single predictor? 如何使用 mgcv package 从非线性 model 在 R 中创建 ggplot? - How do I create a ggplot in R from a non-linear model using the mgcv package? 如何在R中的nls(非线性最小二乘法)函数中使用“权重”? - How to use the 'weights' in the nls (non-linear least squares) function in R?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM