从R上的偏最小二乘回归中提取数据

时间:2016-07-11 15:30:02

标签: r model anova

我想使用偏最小二乘回归来找到最有代表性的变量来预测我的数据。 这是我的代码:

library(pls)
potion<-read.table("potion-insomnie.txt",header=T)

potionTrain <- potion[1:182,]
potionTest <- potion[183:192,]

potion1 <- plsr(Sommeil ~ Aubepine + Bave + Poudre + Pavot, data = potionTrain, validation = "LOO")

summary(lm(potion1))给我这个答案:

Call:
lm(formula = potion1)

Residuals:
     Min       1Q   Median       3Q      Max 
-14.9475  -5.3961   0.0056   5.2321  20.5847 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 37.63931    1.67955  22.410  < 2e-16 ***
Aubepine    -0.28226    0.05195  -5.434 1.81e-07 ***
Bave        -1.79894    0.26849  -6.700 2.68e-10 ***
Poudre       0.35420    0.72849   0.486    0.627    
Pavot       -0.47678    0.52027  -0.916    0.361    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 7.845 on 177 degrees of freedom
Multiple R-squared:  0.293,     Adjusted R-squared:  0.277 
F-statistic: 18.34 on 4 and 177 DF,  p-value: 1.271e-12

我推断只有变量AubepineBave具有代表性。所以我只用这两个变量重新编写模型:

potion1 <- plsr(Sommeil ~ Aubepine + Bave, data = potionTrain, validation = "LOO")

我的情节:

plot(potion1, ncomp = 2, asp = 1, line = TRUE)

以下是预测值与测量值的关系图:

Plot of predited vs measured values

问题在于我在情节上看到了线性回归,但我无法知道它的等式和。有可能吗?

第一部分是否与多元回归线性(ANOVA)相同?

1 个答案:

答案 0 :(得分:2)

pacman::p_load(pls)
data(mtcars)
potion <- mtcars

potionTrain <- potion[1:28,]
potionTest <- potion[29:32,]

potion1 <- plsr(mpg ~ cyl + disp + hp + drat, data = potionTrain, validation = "LOO")

coef(potion1) # coefficeints
scores(potion1) # scores

## R^2:
R2(potion1, estimate = "train")
## cross-validated R^2:
R2(potion1)
## Both:
R2(potion1, estimate = "all")