dataSet <- read.csv("C:/Users/Waleed/Desktop/hafsa/ds_19122039.csv")
This code loads the data Set
summary(dataSet)
## Observation Brand Price_. Megapixels
## Min. : 1.00 Length:28 Min. : 72.0 Min. :10.00
## 1st Qu.: 7.75 Class :character 1st Qu.: 99.0 1st Qu.:12.00
## Median :14.50 Mode :character Median :144.0 Median :12.00
## Mean :14.50 Mean :157.8 Mean :12.86
## 3rd Qu.:21.25 3rd Qu.:180.0 3rd Qu.:14.00
## Max. :28.00 Max. :360.0 Max. :16.00
## Weight_oz Score Brand.1
## Min. :4.000 Min. :45.00 Min. :0.0000
## 1st Qu.:5.000 1st Qu.:55.00 1st Qu.:0.0000
## Median :6.000 Median :59.50 Median :0.0000
## Mean :5.821 Mean :59.36 Mean :0.4643
## 3rd Qu.:7.000 3rd Qu.:64.25 3rd Qu.:1.0000
## Max. :7.000 Max. :69.00 Max. :1.0000
str(dataSet)
## 'data.frame': 28 obs. of 7 variables:
## $ Observation: int 1 2 3 4 5 6 7 8 9 10 ...
## $ Brand : chr "Canon" "Canon" "Canon" "Canon" ...
## $ Price_. : int 297 180 270 180 162 180 180 117 117 99 ...
## $ Megapixels : int 10 12 12 10 12 12 14 10 12 16 ...
## $ Weight_oz : int 7 5 7 6 5 7 5 7 5 5 ...
## $ Score : int 69 69 68 65 65 64 63 63 62 58 ...
## $ Brand.1 : int 1 1 1 1 1 1 1 1 1 1 ...
It summarizes camera data across 28 observations, detailing attributes like Price, Megapixels, Weight, Score, and a categorical variable ‘Brand.1’, offering an overview of their distributions and central tendencies.
hist(dataSet$Price)
A histogram of the Price variable showing positive skewness indicate that the data is not normally distributed
hist(dataSet$Megapixels)
A histogram of the megapixel variable showing positive skewness indicate that the data is not normally distributed
hist(dataSet$Weight)
A histogram of the Weight_oz variable showing positive skewness indicate that the data is not normally distributed
hist(dataSet$Score)
A histogram of the Score variable showing negative skewness indicate that the data is not normally distributed
attach(dataSet)
pairs(~Price_. + Megapixels + Weight_oz + Score )
Positive skewness in the megapixel histogram signals fewer high
megapixel cameras, indicating a non-normal distribution favoring lower
resolution within this data set
cor_matrix <- cor(dataSet[, c("Price_.", "Megapixels", "Weight_oz", "Score")])
print(cor_matrix)
## Price_. Megapixels Weight_oz Score
## Price_. 1.0000000 0.138906307 0.3488151 0.683211844
## Megapixels 0.1389063 1.000000000 -0.1988338 -0.007729723
## Weight_oz 0.3488151 -0.198833809 1.0000000 0.285688204
## Score 0.6832118 -0.007729723 0.2856882 1.000000000
The correlation matrix reveals,Strong positive correlation between price and score.Weak relationships between megapixels, weight, and other attributes, except a moderate correlation between weight and price
m1 <- lm(Price_.~Megapixels, dataSet=dataSet)
## Warning: In lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
## extra argument 'dataSet' will be disregarded
summary(dataSet)
## Observation Brand Price_. Megapixels
## Min. : 1.00 Length:28 Min. : 72.0 Min. :10.00
## 1st Qu.: 7.75 Class :character 1st Qu.: 99.0 1st Qu.:12.00
## Median :14.50 Mode :character Median :144.0 Median :12.00
## Mean :14.50 Mean :157.8 Mean :12.86
## 3rd Qu.:21.25 3rd Qu.:180.0 3rd Qu.:14.00
## Max. :28.00 Max. :360.0 Max. :16.00
## Weight_oz Score Brand.1
## Min. :4.000 Min. :45.00 Min. :0.0000
## 1st Qu.:5.000 1st Qu.:55.00 1st Qu.:0.0000
## Median :6.000 Median :59.50 Median :0.0000
## Mean :5.821 Mean :59.36 Mean :0.4643
## 3rd Qu.:7.000 3rd Qu.:64.25 3rd Qu.:1.0000
## Max. :7.000 Max. :69.00 Max. :1.0000
plot(m1)
The table summarizes 28 camera entries with price, megapixels,
weight, score, and a categorical ‘Brand.1’. It offers insights into
these attributes’ distribution among various brands
m2 <- lm(Price_. ~ Megapixels + Weight_oz,dataSet=dataSet)
## Warning: In lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
## extra argument 'dataSet' will be disregarded
summary(dataSet)
## Observation Brand Price_. Megapixels
## Min. : 1.00 Length:28 Min. : 72.0 Min. :10.00
## 1st Qu.: 7.75 Class :character 1st Qu.: 99.0 1st Qu.:12.00
## Median :14.50 Mode :character Median :144.0 Median :12.00
## Mean :14.50 Mean :157.8 Mean :12.86
## 3rd Qu.:21.25 3rd Qu.:180.0 3rd Qu.:14.00
## Max. :28.00 Max. :360.0 Max. :16.00
## Weight_oz Score Brand.1
## Min. :4.000 Min. :45.00 Min. :0.0000
## 1st Qu.:5.000 1st Qu.:55.00 1st Qu.:0.0000
## Median :6.000 Median :59.50 Median :0.0000
## Mean :5.821 Mean :59.36 Mean :0.4643
## 3rd Qu.:7.000 3rd Qu.:64.25 3rd Qu.:1.0000
## Max. :7.000 Max. :69.00 Max. :1.0000
plot(m2)
This table summarizes camera data across brands. For “plot m2,”
it provides essential statistics, helping identify trends and central
tendencies in the data set.
m3 <- lm(Price_. ~ Megapixels + Weight_oz + Score,dataSet=dataSet)
## Warning: In lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
## extra argument 'dataSet' will be disregarded
summary(dataSet)
## Observation Brand Price_. Megapixels
## Min. : 1.00 Length:28 Min. : 72.0 Min. :10.00
## 1st Qu.: 7.75 Class :character 1st Qu.: 99.0 1st Qu.:12.00
## Median :14.50 Mode :character Median :144.0 Median :12.00
## Mean :14.50 Mean :157.8 Mean :12.86
## 3rd Qu.:21.25 3rd Qu.:180.0 3rd Qu.:14.00
## Max. :28.00 Max. :360.0 Max. :16.00
## Weight_oz Score Brand.1
## Min. :4.000 Min. :45.00 Min. :0.0000
## 1st Qu.:5.000 1st Qu.:55.00 1st Qu.:0.0000
## Median :6.000 Median :59.50 Median :0.0000
## Mean :5.821 Mean :59.36 Mean :0.4643
## 3rd Qu.:7.000 3rd Qu.:64.25 3rd Qu.:1.0000
## Max. :7.000 Max. :69.00 Max. :1.0000
plot(m3)
This table summarizes camera data, crucial for understanding
trends. For “plot m3,” it offers insights into central tendencies and
distributions within the data set.
anova(m1, m3)
## Analysis of Variance Table
##
## Model 1: Price_. ~ Megapixels
## Model 2: Price_. ~ Megapixels + Weight_oz + Score
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 26 147035
## 2 24 71184 2 75852 12.787 0.0001658 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The analysis compares two models predicting price: one with only megapixels and another with megapixels, weight, and score. The latter significantly improves the model’s predictive power (p < 0.001)
anova(m2, m3)
## Analysis of Variance Table
##
## Model 1: Price_. ~ Megapixels + Weight_oz
## Model 2: Price_. ~ Megapixels + Weight_oz + Score
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 25 124916
## 2 24 71184 1 53732 18.116 0.0002752 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Comparing models, adding ‘Score’ significantly enhances the predictive power for price (p < 0.001), indicating its relevance in improving the model’s accuracy
dataSet$Nikon <- ifelse(dataSet$Brand.1 == 0, 1, 0)
dataSet
## Observation Brand Price_. Megapixels Weight_oz Score Brand.1 Nikon
## 1 1 Canon 297 10 7 69 1 0
## 2 2 Canon 180 12 5 69 1 0
## 3 3 Canon 270 12 7 68 1 0
## 4 4 Canon 180 10 6 65 1 0
## 5 5 Canon 162 12 5 65 1 0
## 6 6 Canon 180 12 7 64 1 0
## 7 7 Canon 180 14 5 63 1 0
## 8 8 Canon 117 10 7 63 1 0
## 9 9 Canon 117 12 5 62 1 0
## 10 10 Canon 99 16 5 58 1 0
## 11 11 Canon 81 14 5 55 1 0
## 12 12 Canon 90 10 6 54 1 0
## 13 13 Canon 81 12 7 49 1 0
## 14 14 Nikon 243 16 5 68 0 1
## 15 15 Nikon 270 16 7 66 0 1
## 16 16 Nikon 180 14 6 64 0 1
## 17 17 Nikon 360 14 7 62 0 1
## 18 18 Nikon 108 14 5 60 0 1
## 19 19 Nikon 153 16 6 59 0 1
## 20 20 Nikon 135 12 5 59 0 1
## 21 21 Nikon 207 14 6 58 0 1
## 22 22 Nikon 162 12 6 56 0 1
## 23 23 Nikon 117 12 6 56 0 1
## 24 24 Nikon 72 12 7 55 0 1
## 25 25 Nikon 72 14 7 53 0 1
## 26 26 Nikon 90 12 4 49 0 1
## 27 27 Nikon 99 12 5 48 0 1
## 28 28 Nikon 117 14 4 45 0 1
The data set contains 28 camera entries from Canon and Nikon. It includes attributes such as Price, Megapixels, Weight, Score, and categorical indicators for brand types (‘Brand.1’), revealing distinct specifications between Canon and Nikon models
attach(dataSet)
## The following objects are masked from dataSet (pos = 3):
##
## Brand, Brand.1, Megapixels, Observation, Price_., Score, Weight_oz
m4 <- lm(Price_. ~ Megapixels + Weight_oz + Score + Nikon)
summary(m4)
##
## Call:
## lm(formula = Price_. ~ Megapixels + Weight_oz + Score + Nikon)
##
## Residuals:
## Min 1Q Median 3Q Max
## -82.379 -28.677 -3.307 22.454 143.936
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -454.620 126.971 -3.581 0.001584 **
## Megapixels 2.626 6.438 0.408 0.687152
## Weight_oz 13.671 11.103 1.231 0.230666
## Score 8.062 1.735 4.648 0.000112 ***
## Nikon 38.388 24.395 1.574 0.129228
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 52.86 on 23 degrees of freedom
## Multiple R-squared: 0.5714, Adjusted R-squared: 0.4968
## F-statistic: 7.665 on 4 and 23 DF, p-value: 0.0004448
The linear regression model predicts Price using Megapixels, Weight, Score, and Nikon as predictors. ‘Score’ significantly impacts price (p < 0.001), explaining around 57% of price variation (R-squared = 0.5714). ‘Nikon’ doesn’t significantly impact price.The linear regression model predicts Price using Megapixels, Weight, Score, and Nikon as predictors. ‘Score’ significantly impacts price (p < 0.001), explaining around 57% of price variation (R-squared = 0.5714). ‘Nikon’ doesn’t significantly impact price.
m4_nikon <- lm(Price_. ~ Megapixels + Weight_oz + Score, data = subset(dataSet, Nikon == 1))
m4_canon <- lm(Price_. ~ Megapixels + Weight_oz + Score, data = subset(dataSet, Nikon == 0))
# Plotting
plot(dataSet$Price_. ~ dataSet$Megapixels, col = ifelse(dataSet$Nikon == 1,"red","green"))
abline(m4_nikon,col ="red")
## Warning in abline(m4_nikon, col = "red"): only using the first two of 4
## regression coefficients
abline(m4_canon,col ="green")
## Warning in abline(m4_canon, col = "green"): only using the first two of 4
## regression coefficients
This code fits separate regression models for Nikon and Canon cameras, then plots a Price-Megapixels scatter with distinct colors for Nikon (red) and Canon (green), overlaying their respective regression lines for comparison.