data <- read.table("C:/Users/aiman/Documents/LAST DEGREE/SMS/lab report/lab report 1/gmp.txt")
data
model <- lm(y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11,data = data)
summary(model)
Call:
lm(formula = y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 +
x10 + x11, data = data)
Residuals:
Min 1Q Median 3Q Max
-5.3441 -1.6711 -0.4486 1.4906 5.2508
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 17.339838 30.355375 0.571 0.5749
x1 -0.075588 0.056347 -1.341 0.1964
x2 -0.069163 0.087791 -0.788 0.4411
x3 0.115117 0.088113 1.306 0.2078
x4 1.494737 3.101464 0.482 0.6357
x5 5.843495 3.148438 1.856 0.0799 .
x6 0.317583 1.288967 0.246 0.8082
x7 -3.205390 3.109185 -1.031 0.3162
x8 0.180811 0.130301 1.388 0.1822
x9 -0.397945 0.323456 -1.230 0.2344
x10 -0.005115 0.005896 -0.868 0.3971
x11 0.638483 3.021680 0.211 0.8350
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 3.227 on 18 degrees of freedom
(2 observations deleted due to missingness)
Multiple R-squared: 0.8355, Adjusted R-squared: 0.7349
F-statistic: 8.31 on 11 and 18 DF, p-value: 5.231e-05
Part A
i)Normal Probability Plot
plot(model,which = 2,main = "Normal Probability Plot of Residuals")
Interpretation: The normal probability plot shows that most residuals approximately follow the straight reference line, although some deviations are observed at both tails. This suggests a slight departure from normality; therefore, formal normality tests are conducted to further assess the normality assumption.
ii)Normality Test
install.packages("nortest")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:
https://cran.rstudio.com/bin/windows/Rtools/
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.5/nortest_1.0-4.zip'
Content type 'application/zip' length 39886 bytes (38 KB)
downloaded 38 KB
package ‘nortest’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\aiman\AppData\Local\Temp\RtmpAx0Osb\downloaded_packages
library(nortest)
Shapiro-Wilk
shapiro.test(residuals(model))
Shapiro-Wilk normality test
data: residuals(model)
W = 0.964, p-value = 0.3904
Kolmogorov Smirnov (K-S)
ks.test(scale(residuals(model)), "pnorm")
Exact one-sample Kolmogorov-Smirnov test
data: scale(residuals(model))
D = 0.14285, p-value = 0.5266
alternative hypothesis: two-sided
Anderson-Darling
ad.test(residuals(model))
Anderson-Darling normality test
data: residuals(model)
A = 0.51613, p-value = 0.1756
Interpretation: The Shapiro-Wilk, Kolmogorov-Smirnov, and Anderson-Darling tests produced p-values of 0.3904, 0.5266, and 0.1756, respectively. Since all p-values are greater than the 0.05 significance level, we fail to reject the null hypothesis. Therefore, there is insufficient evidence to conclude that the residuals are not normally distributed. The normality assumption is considered satisfied.
iii)Plot of residuals versus the predicted response.
plot(model,
which = 1,
main = "Residuals vs Predicted Response")
Interpretation: The residuals are scattered around the zero line; however, the red smooth line shows a noticeable curved pattern rather than remaining approximately horizontal. This suggests that there may be some non-linearity in the relationship between the response and the explanatory variables. Therefore, the linearity assumption may not be fully satisfied.
Part B
i)Plot the influential observation by Cook’s Distance
cooksd <- cooks.distance(model)
plot(cooksd,pch = "*",cex = 2,main = "Influential Observations by Cook's Distance")
abline(h = 4 * mean(cooksd, na.rm = TRUE), col = "red")
text(x = 1:length(cooksd) + 1,y = cooksd,
labels = ifelse(cooksd > 4 * mean(cooksd,
na.rm = TRUE),names(cooksd),""),col = "red")
Interpretation: The Cook’s Distance plot shows that observations 14 and 17 have Cook’s Distance values above the reference cutoff of 4 times the mean Cook’s Distance. These observations are considered potentially influential observations and should be investigated further.
influential <- as.numeric(names(cooksd)[cooksd > 4 * mean(cooksd,
na.rm = TRUE)])
influential
[1] 14 17
head(data[influential,])
Interpretation: Observations 14 and 17 were identified as potentially influential observations because their Cook’s Distance values exceeded the reference cutoff. Observation 17 has relatively high values for several explanatory variables, particularly x1, x2, x3, x4 and x8, while observation 14 also has relatively large values for some explanatory variables. These unusual values may contribute to their influence on the fitted regression model. Therefore, observations 14 and 17 should be examined further when assessing the adequacy of the model.
Part C
i)Lack-of-Fit Test
Model 2
model2 <- lm(y ~ x1 + x2 + x3 + x8 + x9 + x10,data = data)
summary(model2)
Call:
lm(formula = y ~ x1 + x2 + x3 + x8 + x9 + x10, data = data)
Residuals:
Min 1Q Median 3Q Max
-4.7829 -1.6308 -0.2023 1.7894 6.2575
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 31.891090 19.188065 1.662 0.110
x1 -0.051858 0.044919 -1.154 0.260
x2 0.001803 0.056564 0.032 0.975
x3 0.031761 0.070140 0.453 0.655
x8 0.129341 0.116709 1.108 0.279
x9 -0.206554 0.275463 -0.750 0.461
x10 -0.003947 0.004986 -0.792 0.437
Residual standard error: 3.206 on 23 degrees of freedom
(2 observations deleted due to missingness)
Multiple R-squared: 0.7924, Adjusted R-squared: 0.7383
F-statistic: 14.64 on 6 and 23 DF, p-value: 7.75e-07
anova(model2, model)
Analysis of Variance Table
Model 1: y ~ x1 + x2 + x3 + x8 + x9 + x10
Model 2: y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11
Res.Df RSS Df Sum of Sq F Pr(>F)
1 23 236.43
2 18 187.40 5 49.024 0.9418 0.478
Interpretation: H₀: Full model do not adequete H₁: Full model adequate p-value = 0.478 Since p-value(0.478) > alpha=0.05 ,fail to reject H₀ At alpha = 0.05, there is insufficient statistical evidence to conclude that full model provides a significantly better fit than the reduced model containing x1, x2, x3, x8, x9 and x10. Hence, the reduced model is considered adequate compared with the full model.