dataset <- read.csv(“C:/Users/hp/Downloads/dataset.csv”) # Summary statistics summary(dataset)

Type and measurement scale

str(dataset)

Make the histogram of all scaled variables

hist(dataset\(Price, main = "Histogram of Price", col = "lightblue", xlab = "Price") hist(dataset\)Megapixels, main = “Histogram of Megapixels”, col = “lightgreen”, xlab = “Megapixels”) hist(dataset\(Weight, main = "Histogram of Weight", col = "yellow", xlab = "Weight") hist(dataset\)Score, main = “Histogram of Score”, col = “orange”, xlab = “Score”)

Shapiro-Wilk test for normality

shapiro.test(dataset\(Price) shapiro.test(dataset\)Megapixels) shapiro.test(dataset\(Weight) shapiro.test(dataset\)Score)

Matrix scatter plot

pairs(dataset[, c(“Price”, “Megapixels”, “Weight_oz”, “Score”)])

Correlation matrix

cor_matrix <- cor(dataset[, c(“Price”, “Megapixels”, “Weight_oz”, “Score”)]) print(cor_matrix)

Fit a regression model m1

m1 <- lm(Price ~ Megapixels, data = dataset)

Summary of the model

summary(m1)

Residual analysis

plot(m1) # Fit a regression model m2 m2 <- lm(Price ~ Megapixels + Weight_oz, data = dataset)

Summary of the model

summary(m2)

Residual analysis

plot(m2)

Fit a regression model m3

m3 <- lm(Price ~ Megapixels + Weight_oz + Score, data = dataset)

Summary of the model

summary(m3)

Residual analysis

plot(m3)

ANOVA for m1 and m3

anova(m1, m3)

Adjusted R-squared for m1 and m3

summary(m1)\(adj.r.squared summary(m3)\)adj.r.squared

ANOVA for m2 and m3

anova(m2, m3)

Adjusted R-squared for m2 and m3

summary(m2)\(adj.r.squared summary(m3)\)adj.r.squared

Add the Nikon indicator variable

dataset\(Nikon <- ifelse(dataset\)Brand == 0, 1, 0)

Fit a regression model m4

m4 <- lm(Price ~ Megapixels + Weight_oz + Score + Nikon, data = dataset) summary(m4)

Residual analysis

plot(m4)

Model for Nikon

m4_nikon <- lm(Price ~ Megapixels + Weight_oz + Score, data = subset(dataset, Nikon== 1)) summary(m4_nikon)

Model for Canon

m4_canon <- lm(Price ~ Megapixels + Weight_oz + Score, data = subset(dataset, Brand == 1))

Plot each model on the data graph

plot(dataset$Price, predict(m4_nikon), col = “red”, main = “Regression Models for Nikon and Canon”, xlab = “Price”, ylab = “Predicted Price”)

points(dataset$Price, predict(m4_canon), col = “green”) legend(“topright”, legend = c(“Nikon”, “Canon”), col = c(“yellow”, “green”), lty = 1)