新浪博客

R语言中非线性模型的R^2的计算

2012-09-26 09:45阅读:
R^2通常的定义是 R^2=1-(SSre/SStot)
SSre 是 the sum of the squares of the distances of the points from the fit.
SStot是 the sum of the squares of the distances of the points from a horizontal line through the mean of all Y values.
据此,可以在R语言中实现的代码如下:
#首先得到非线性拟合的结果
#假设V为实测的因变量值
Reg <- nls(...)
#计算SSre
# 得到fitted value
fit<-fitted(Reg)
SSre<-sum((V-fit)^2)
#或者
SSre<-sum(residuals(Reg)^2)
#计算SStot
SStot<-sum((V-mean(V))^2)
#计算R^2
R2=1-SSre/SStot

我的更多文章

下载客户端阅读体验更佳

APP专享