R "linear regression analysis and statistical models" page119,4.2

rm(list = ls())
library(openxlsx)
library(MASS)
data = read.xlsx("xiti_4.xlsx",sheet = 2)
data
fm = lm(y~x1+x2+x3+x4+x5+x6+x7,data)
par(mfrow = c(2,2),mar = 0.4+c(4,4,1,1),oma = c(0,0,2,0))
a1 = boxcox(fm,lambda = seq(0,1,by = 0.1))

  

 

 

[lambda] = 0.76 # 
L = Which (A1 == $ Y max (Y $ A1)) 
A1 $ X [L] to give 0.76 # is the highest point of the image

  

= 0.76 Lamb 
ylam = (Y ^ $ Data Lamb -1) / Lamb 
new_data = cbind (Data, ylam) 
FM1 LM = (X1 + X2 ~ ylam + X3 + X4 + X5 + X6 + X7, new_data) transformed data # fitting model 
# calculated external student t residuals 
EI = RESID (FM1) 
X-cbind = (. 1, as.matrix (Data [, 2:. 8])) 
t = Ti (EI, X-)

  

# Residual FIG 
plot (fitted (fm1), t )

  

Seen from the figure, it shows no sign of significant variance arrhythmia

 

# Normality test 
shapiro.test (resid (fm1))
> shapiro.test(resid(fm1))

	Shapiro-Wilk normality test

data:  resid(fm1)
W = 0.97405, p-value = 0.748

  Normality Test by

 

The final regression model:

 

Guess you like

Origin www.cnblogs.com/jiaxinwei/p/11761750.html