为什么我在r中得到两个不同的R ^ 2,哪个是正确的?

问题描述 投票:0回答:1

我有下面的数据,并想要使用lm和变量2的对数来建立指数回归模型。

[当我评估模型时,我从模型摘要中得到两个不同的r2,而当我对模型调用进行摘要时。为什么我得到这个d

  data <- structure(list(V1 = c(0.79, 0.61, 0.83, 0.86, 0.84, 0.78, 0.8, 
                      0.81, 0.77, 0.83, 0.8, 0.86, 0.31, 0.8, 0.85, 0.77, 0.77, 0.86, 
                      0.66, 0.81, 0.84, 0.68, 0.81, 0.81, 0.75, 0.64, 0.83, 0.52, 0.85, 
                      0.5), V2 = c(832.69, 411.64, 1150.85, 1236, 751.09, 723.46, 1056.16, 
                                   904.22, 361.76, 695.04, 948.45, 812.51, 75.52, 700.64, 1193.39, 
                                   523.02, 1713.68, 1183.73, 320.96, 678.42, 825.22, 159.17, 891.43, 
                                   177.52, 863.89, 217.45, 552.3, 223.9, 564.05, 99.26)), row.names = c(41L, 
                                                                                                        25L, 74L, 40L, 130L, 118L, 109L, 83L, 77L, 16L, 49L, 86L, 23L, 
                                                                                                        13L, 45L, 3L, 15L, 37L, 31L, 14L, 5L, 85L, 103L, 36L, 126L, 38L, 
                                                                                                        30L, 54L, 95L, 81L), class = "data.frame")

fit <- lm(formula = log(data$V2) ~ data$V1)
fit
plot(data)
lines(sort(data$V1), exp(sort(predict(fit, list(x =data$V1)))), col="red")
points(sort(data$V1), exp(sort(predict(fit, list(x =data$V1)))), col="red")
summary(fit)

调整后的R平方:0.64

data$V2predicted <- exp(predict(fit,list(x =data$V1)))
points(data$V1, data$V2predicted, col = 'blue')


summary(lm(data$V2 ~ data$V2predicted))

调整后的R平方:0.4166

这不是关于多个R ^ 2与调整后的R ^ 2之间的差异,而是关于为什么我从模型调用和lm()中获得不同的R ^ 2。

我做错什么了吗?

r regression lm
1个回答
1
投票

您将获得不同的rsq值,因为您的响应变量的比例不同。对于第一次拟合lm(formula = log(data$V2) ~ data$V1),您的响应变量在对数刻度中。在第二个中,您将它们转换回指数

© www.soinside.com 2019 - 2024. All rights reserved.