library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(broom)
laptop_prices <- read.csv("~/Documents/statistics(1)/annotated-laptop_prices(new).csv")
laptop_prices$Touchscreen <- ifelse(tolower(laptop_prices$Touchscreen) == "yes", 1, 0)
model <- glm(Touchscreen ~ Inches + Ram + Weight + Price_euros, data = laptop_prices, family = binomial)
summary(model)
##
## Call:
## glm(formula = Touchscreen ~ Inches + Ram + Weight + Price_euros,
## family = binomial, data = laptop_prices)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 4.4089582 0.9440330 4.670 3.01e-06 ***
## Inches -0.5241747 0.0807271 -6.493 8.40e-11 ***
## Ram 0.0264296 0.0198202 1.333 0.182
## Weight 0.7587570 0.1758423 4.315 1.60e-05 ***
## Price_euros 0.0005830 0.0001352 4.311 1.62e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 1512.0 on 1274 degrees of freedom
## Residual deviance: 1388.6 on 1270 degrees of freedom
## AIC: 1398.6
##
## Number of Fisher Scoring iterations: 4
Inches, Ram, Weight, and Price_euros—are logically related to the presence of a touchscreen, and the model gives a reasonable interpretation of these relationships
Intercept (Estimate = 4.409): This represents the log-odds of a laptop having a touchscreen when all other variables are zero. While it’s not practically interpretable in isolation, it serves as the model’s baseline.
Inches (Estimate = -0.524): Each additional inch in screen size decreases the log-odds of having a touchscreen by 0.524. This suggests that larger screens are associated with a lower probability of having a touchscreen.
Ram (Estimate = 0.026): Each additional GB of RAM slightly increases the log-odds of having a touchscreen by 0.026. However, with a p-value of 0.182, this variable is not statistically significant in predicting touchscreen likelihood.
Weight (Estimate = 0.759): Each additional kg of weight increases the log-odds of having a touchscreen by 0.759. This indicates that heavier laptops are more likely to include a touchscreen, and this effect is statistically significant
Price_euros (Estimate = 0.000583): For each additional euro in price, the log-odds of having a touchscreen increase slightly by 0.000583. Although the increase per euro is small, this effect is statistically significant (p<0.001), suggesting that more expensive laptops are more likely to have a touchscreen.
coef_ram <- coef(summary(model))["Ram", "Estimate"]
se_ram <- coef(summary(model))["Ram", "Std. Error"]
# 95% confidence interval
ci_lower <- coef_ram - 1.96 * se_ram
ci_upper <- coef_ram + 1.96 * se_ram
cat("95% Confidence Interval for ram coefficient:", ci_lower, "to", ci_upper, "\n")
## 95% Confidence Interval for ram coefficient: -0.01241794 to 0.06527721
The effect of Ram on the likelihood of having a touchscreen is not statistically significant. This implies that adding more RAM does not have a consistent, meaningful impact on whether a laptop has a touchscreen.