dataset <- read.csv(“C:/Users/hp/Downloads/dataset.csv”) # Summary statistics summary(dataset)
str(dataset)
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.test(dataset\(Price) shapiro.test(dataset\)Megapixels) shapiro.test(dataset\(Weight) shapiro.test(dataset\)Score)
pairs(dataset[, c(“Price”, “Megapixels”, “Weight_oz”, “Score”)])
cor_matrix <- cor(dataset[, c(“Price”, “Megapixels”, “Weight_oz”, “Score”)]) print(cor_matrix)
m1 <- lm(Price ~ Megapixels, data = dataset)
summary(m1)
plot(m1) # Fit a regression model m2 m2 <- lm(Price ~ Megapixels + Weight_oz, data = dataset)
summary(m2)
plot(m2)
m3 <- lm(Price ~ Megapixels + Weight_oz + Score, data = dataset)
summary(m3)
plot(m3)
anova(m1, m3)
summary(m1)\(adj.r.squared summary(m3)\)adj.r.squared
anova(m2, m3)
summary(m2)\(adj.r.squared summary(m3)\)adj.r.squared
dataset\(Nikon <- ifelse(dataset\)Brand == 0, 1, 0)
m4 <- lm(Price ~ Megapixels + Weight_oz + Score + Nikon, data = dataset) summary(m4)
plot(m4)
m4_nikon <- lm(Price ~ Megapixels + Weight_oz + Score, data = subset(dataset, Nikon== 1)) summary(m4_nikon)
m4_canon <- lm(Price ~ Megapixels + Weight_oz + Score, data = subset(dataset, Brand == 1))
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)