Repository navigation
Expand file tree
/
Copy pathNwadiugwu-A1-ISQA 8720.Rmd
More file actions
128 lines (91 loc) · 2.35 KB
/
Copy pathNwadiugwu-A1-ISQA 8720.Rmd
File metadata and controls
128 lines (91 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
---
title: "Nwadiugwu-A1-ISQA 8720"
author: "Martin Nwadiugwu"
date: "9/5/2020"
output:
html_document: default
pdf_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
# load libraries with additional functionality
library(ggplot2) # library for plots
library(reshape2) # library for data handling
library(tidyverse) # library for general data processing and handling
library(skimr) # to get a better formatted overview of the data
library(tidyverse)
library(GGally)
library(Hmisc)
library(DataExplorer)
library(ISLR)
#Data prepareation
head(Carseats)
describe(Carseats)
introduce(Carseats)
# structure of the data set
plot_intro(Carseats)
plot_str(Carseats)
# plot missing values
plot_missing(Carseats)
# plot the correlation between variables
plot_correlation(Carseats)
#Converting Cataegorical data variables as factor
Carseats$Urban= as.factor(Carseats$Urban)
Carseats$US=as.factor(Carseats$US)
Carseats$ShelveLoc=as.factor(Carseats$ShelveLoc)
table(Carseats$Urban)
table(Carseats$US)
table(Carseats$ShelveLoc)
#Fitting regression model
Sales_predict = lm(Sales~Price+Urban+US, Carseats)
summary(Sales_predict)
#Fitting a smaller model with significant predictors from above
Sales_predict2 = lm(Sales~Price+US, Carseats)
summary(Sales_predict2)
#Confirming significance
Sales_predict3 = lm(Sales~., Carseats)
summary(Sales_predict3)
anova(Sales_predict2, Sales_predict3)
#Data visualization
plot(Sales_predict2)
#obtaining 95% confidence interval for (e)
confint(Sales_predict2)
```
## R Markdown
## Question 2
```{r cars}
#a. Perform the following commands in R (use your NU-ID as random number seed):
set.seed(32089289)
x1 <- runif(100)
x2 <- 0.5 * x1 + rnorm (100)/10
y <- 2 + 2 * x1 +0.3 * x2+rnorm(100)
#creating a correlation coefficient and scatter plot
cor(x1, x2)
plot(x1, x2)
#Fitting a least square regression
P_y = lm(y~x1+x2)
summary(P_y)
#predicting y using only x1
P_y1 = lm(y~x1)
summary(P_y1)
#predicting y using only x2
P_y2 = lm(y~x2)
summary(P_y2)
#Refitting the linear model
x1 <- c(x1 , 0.1)
x2 <- c(x2 , 0.8)
y <- c(y,6)
#for (c)
R_y = lm(y~x1+x2)
summary(R_y)
plot(R_y)
#for (d)
R_y1 = lm(y~x1)
summary(R_y1)
plot(R_y1)
#for (e)
R_y2 = lm(y~x2)
summary(R_y2)
plot(R_y2)
```
## End