Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

hi. this is a Regression analysis with R In here i want a get values df, SSE, R

ID: 3330861 • Letter: H

Question

hi.

this is a Regression analysis with R

In here i want a get values df, SSE, R square, MSE, Cp, PRESSp ""when None case""

#####code is below

set.seed(1)
x1 <- c(98.352,100.416,90.858,91.146,101.194,77.820,117.960,112.186,308.404,289.196,116.564,106.006,125.424,119.184,101.000,164.928,133.938,155.682,180.768,119.788,150.844,175.902,121.862,167.214,162.800,182.832,240.000)
x2 <- c(34.720,35.310,22.750,40.500,44.550,44.550,58.500,95.200,98.000,128.000,64.350,49.883,55.200,66.660,50.000,51.500,69.020,71.020,78.000,55.200,40.000,98.900,67.265,91.500,80.000,73.262,50.000)
x3 <- c(19.96,30.00,23.50,24.64,22.42,19.76,24.80,30.02,68.40,60.00,24.50,31.04,19.50,22.42,20.40,33.28,29.76,27.52,30.00,25.12,33.80,36.40,33.04,35.54,30.08,36.62,24.00)
x4 <- c(4.2,6.2,4.0,5.4,4.2,5.6,5.1,3.2,4.2,1.4,3.2,3.0,3.0,3.2,4.6,5.0,2.2,1.7,2.3,4.0,2.2,5.0,4.4,4.8,0.3,3.1,3.0)
y <- c(12.95,14.75,13.95,12.95,14.95,14.95,15.45,14.45,42.45,41.45,17.95,15.75,15.50,15.45,15.00,18.45,20.95,20.25,21.95,18.75,18.95,22.25,18.95,19.45,18.45,22.90,20.50)

mydata <- data.frame(y,x1,x2,x3,x4)

PRESS 1434.900 SS Ep p df 1 26 1330.58 2 25 R2 0.000 MSEp 51.18 8.60 Cp 295.04 28.95 None 316.087 X1 216.00 0.838

Explanation / Answer

First we can load the data in R:

x1 <- c(98.352,100.416,90.858,91.146,101.194,77.820,117.960,112.186,308.404,289.196,116.564,106.006,125.424,119.184,101.000,164.928,133.938,155.682,180.768,119.788,150.844,175.902,121.862,167.214,162.800,182.832,240.000)
x2 <- c(34.720,35.310,22.750,40.500,44.550,44.550,58.500,95.200,98.000,128.000,64.350,49.883,55.200,66.660,50.000,51.500,69.020,71.020,78.000,55.200,40.000,98.900,67.265,91.500,80.000,73.262,50.000)
x3 <- c(19.96,30.00,23.50,24.64,22.42,19.76,24.80,30.02,68.40,60.00,24.50,31.04,19.50,22.42,20.40,33.28,29.76,27.52,30.00,25.12,33.80,36.40,33.04,35.54,30.08,36.62,24.00)
x4 <- c(4.2,6.2,4.0,5.4,4.2,5.6,5.1,3.2,4.2,1.4,3.2,3.0,3.0,3.2,4.6,5.0,2.2,1.7,2.3,4.0,2.2,5.0,4.4,4.8,0.3,3.1,3.0)
y <- c(12.95,14.75,13.95,12.95,14.95,14.95,15.45,14.45,42.45,41.45,17.95,15.75,15.50,15.45,15.00,18.45,20.95,20.25,21.95,18.75,18.95,22.25,18.95,19.45,18.45,22.90,20.50)
mydata <- data.frame(y,x1,x2,x3,x4)

We can fit the linear model on only a constant like below:
fit <- lm(y ~ 1, data=mydata)

Now we can check out the summary of the model using the summary function :

summary(fit)

Call:
lm(formula = y ~ 1, data = mydata)

Residuals:
Min 1Q Median 3Q Max
-6.300 -4.275 -0.800 1.125 23.200

Coefficients:
Estimate Std. Error t value Pr(>|t|)   
(Intercept) 19.250 1.377 13.98 1.32e-13 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 7.154 on 26 degrees of freedom


Degrees of freedom is 27 - 1 = 26.

SSE can be calculated by taking sum of squares of residuals as below:
sum(fit$residuals^2)
=1330.58

R squared can be calculated as below:
TSS = sum( (y-mean(y))^2 ) = 1330.58
SSE = sum(fit$residuals^2) = 1330.58

R squared = 1 - RSS/TSS = 1 - 1330.58/1330.58 = 1 - 1 = 0

The Residual standard error mentioned in the summary is RMSE. So we can square that to get MSE.

So MSE = (7.154)^2 = 51.17972


Predictively adjusted residuals can be calcualted as below:
pr <- resid(fit)/(1 - lm.influence(fit)$hat)

PRESS is :
sum(pr^2)
=1434.901