加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

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

(2012-09-26 09:45:58)
标签:

教育

    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

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有