一般来说,线性模型是否存在无法解释的错误或数据中未显示的错误?
In general, do linear models have unexplainable error or error that isn't shown in the data?
我 运行 对模型进行线性回归并对其执行反向选择。然后为了检查模型的拟合度,我对其进行了交叉验证。
线性模型:
GoalWeight ~ Measurement + Age + Gender
向后选择:
GoalWeight ~ Measurement + Gender
当我交叉验证两个模型时,我发现点几乎没有移动。为了检查发生了什么,我用 varImp 函数找到了均方和变量重要性。
cvTotal <- CVlm(form.lm = formula(GoalWeight ~ Measurement + Gender + Age), data = clean_GW2, m = 3)
cvBS <- CVlm(form.lm = formula(GoalWeight ~ Measurement + Gender), data = clean_GW2, m = 3)
attr(cvTotal, "ms")
attr(cvBS, "ms")
两种型号的 MS(毫不奇怪)是相同的。
varImp(linmod, scale = TRUE)
varImp(new_linmod, scale = TRUE)
当我执行 varImp 函数时,输出是
> varImp(linmod, scale = TRUE)
Overall
clean_GW2$Measurement 60.7
clean_GW2$Gender 30.9
clean_GW2$Age 1.0
> varImp(new_linmod, scale = TRUE)
Overall
clean_GW2$Measurement 60.9
clean_GW2$Gender 31.0
我确实注意到变量的整体重要性不等于 100%。剩余的 ~10% 误差是模型无法解释的吗?
谢谢
根据 ?varImp
的文档,对于线性模型,它 returns "the absolute value of the t–statistic for each model parameter is used," 因此这些数字是指示统计显着性的标量,而不是百分比。
这可以在下面看到:
library(caret)
a <- rnorm(1000,1,2)
b <- rnorm(1000,-2,1)
c <- rnorm(1000,1.5,3)
d <- rnorm(1000)
e <- rnorm(1000)
y <- rnorm(1000,0,2)+a+b+c+d
df <- data.frame(y=y,a=a,b=b,c=c,d=d,e=e)
mod <- lm(y~.,df)
varImp(mod)
Overall
a 30.9973810
b 14.1027980
c 43.4574054
d 15.3868891
e 0.1844951
sum(varImp(mod))
[1] 104.129 #not a percentage
所有不完美的模型(所以基本上所有模型)都有无法解释的变化,但对于线性模型,这与您的 r 平方值有关,而不是 varImp
[=13= 的输出]
我 运行 对模型进行线性回归并对其执行反向选择。然后为了检查模型的拟合度,我对其进行了交叉验证。
线性模型:
GoalWeight ~ Measurement + Age + Gender
向后选择:
GoalWeight ~ Measurement + Gender
当我交叉验证两个模型时,我发现点几乎没有移动。为了检查发生了什么,我用 varImp 函数找到了均方和变量重要性。
cvTotal <- CVlm(form.lm = formula(GoalWeight ~ Measurement + Gender + Age), data = clean_GW2, m = 3)
cvBS <- CVlm(form.lm = formula(GoalWeight ~ Measurement + Gender), data = clean_GW2, m = 3)
attr(cvTotal, "ms")
attr(cvBS, "ms")
两种型号的 MS(毫不奇怪)是相同的。
varImp(linmod, scale = TRUE)
varImp(new_linmod, scale = TRUE)
当我执行 varImp 函数时,输出是
> varImp(linmod, scale = TRUE)
Overall
clean_GW2$Measurement 60.7
clean_GW2$Gender 30.9
clean_GW2$Age 1.0
> varImp(new_linmod, scale = TRUE)
Overall
clean_GW2$Measurement 60.9
clean_GW2$Gender 31.0
我确实注意到变量的整体重要性不等于 100%。剩余的 ~10% 误差是模型无法解释的吗?
谢谢
根据 ?varImp
的文档,对于线性模型,它 returns "the absolute value of the t–statistic for each model parameter is used," 因此这些数字是指示统计显着性的标量,而不是百分比。
这可以在下面看到:
library(caret)
a <- rnorm(1000,1,2)
b <- rnorm(1000,-2,1)
c <- rnorm(1000,1.5,3)
d <- rnorm(1000)
e <- rnorm(1000)
y <- rnorm(1000,0,2)+a+b+c+d
df <- data.frame(y=y,a=a,b=b,c=c,d=d,e=e)
mod <- lm(y~.,df)
varImp(mod)
Overall
a 30.9973810
b 14.1027980
c 43.4574054
d 15.3868891
e 0.1844951
sum(varImp(mod))
[1] 104.129 #not a percentage
所有不完美的模型(所以基本上所有模型)都有无法解释的变化,但对于线性模型,这与您的 r 平方值有关,而不是 varImp
[=13= 的输出]