mydata_all <- read.csv("/Users/ivanatonevska/Desktop/European_Ski_Resorts.csv")
head(mydata_all)
## X
## 1 1
## 2 2
## 3 3
## 4 4
## 5 5
## 6 6
## Resort
## 1 Alpendorf (Ski amedé)
## 2 Soldeu-Pas de la Casa/Grau Roig/El Tarter/Canillo/Encamp (Grandvalira)
## 3 Oberau (Wildschönau)
## 4 Dachstein West
## 5 Rosa Khutor
## 6 Białka Tatrzańska-Kotelnica-Kaniówka-Bania
## Country HighestPoint LowestPoint DayPassPriceAdult
## 1 Austria 1980 740 52
## 2 Andorra 2640 1710 47
## 3 Austria 1130 900 30
## 4 Austria 1620 780 42
## 5 Southern Russia 2320 940 22
## 6 Poland 910 680 23
## BeginnerSlope IntermediateSlope DifficultSlope TotalSlope Snowparks
## 1 30 81 4 115 Yes
## 2 100 77 33 210 Yes
## 3 1 0 1 2 No
## 4 15 33 3 51 Yes
## 5 30 26 21 77 Yes
## 6 12 3 0 16 Yes
## NightSki SurfaceLifts ChairLifts GondolaLifts TotalLifts
## 1 No 22 16 11 49
## 2 Yes 37 28 7 72
## 3 No 2 0 0 2
## 4 Yes 25 8 3 36
## 5 No 6 11 10 27
## 6 Yes 7 1 0 8
## LiftCapacity SnowCannons
## 1 75398 600
## 2 99017 1032
## 3 1932 0
## 4 32938 163
## 5 49228 450
## 6 28020 0
mydata <- mydata_all[ ,c(1,6, 10, 12, 16, 18 )]
head(mydata)
## X DayPassPriceAdult TotalSlope NightSki TotalLifts SnowCannons
## 1 1 52 115 No 49 600
## 2 2 47 210 Yes 72 1032
## 3 3 30 2 No 2 0
## 4 4 42 51 Yes 36 163
## 5 5 22 77 No 27 450
## 6 6 23 16 Yes 8 0
nrow(mydata)
## [1] 376
sum(is.na(mydata))
## [1] 0
There are no missing values.
colnames(mydata)[1] <- "ID"
#Changing the name of the first column from 'x' to 'ID'
mydata$NightSki <- factor(mydata$NightSki,
levels = c("No", "Yes"),
labels = c("No", "Yes"))
# Factoring the categorical variable NightSki
# If there were more than two categories, the most common one would have been a reference group (the value on the first position for arguments 'levels' and 'labels' in the factor function)
head(mydata)
## ID DayPassPriceAdult TotalSlope NightSki TotalLifts SnowCannons
## 1 1 52 115 No 49 600
## 2 2 47 210 Yes 72 1032
## 3 3 30 2 No 2 0
## 4 4 42 51 Yes 36 163
## 5 5 22 77 No 27 450
## 6 6 23 16 Yes 8 0
summary(mydata[,-1])
## DayPassPriceAdult TotalSlope NightSki TotalLifts
## Min. : 0.00 Min. : 0.00 No :224 Min. : 0.00
## 1st Qu.:34.00 1st Qu.: 25.00 Yes:152 1st Qu.: 10.00
## Median :42.00 Median : 48.00 Median : 17.00
## Mean :40.78 Mean : 86.26 Mean : 26.96
## 3rd Qu.:49.00 3rd Qu.:100.00 3rd Qu.: 29.25
## Max. :81.00 Max. :600.00 Max. :174.00
## SnowCannons
## Min. : 0.0
## 1st Qu.: 0.0
## Median : 54.0
## Mean : 218.4
## 3rd Qu.: 252.0
## Max. :2383.0
#install.packages("car")
library(car)
## Loading required package: carData
scatterplotMatrix(mydata[ ,c(-1, -4)],
smooth = FALSE)
# Only for numerical variables
#install.packages("Hmisc")
library(Hmisc)
##
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
##
## format.pval, units
rcorr(as.matrix(mydata[ ,c(-1, -4)]))
## DayPassPriceAdult TotalSlope TotalLifts SnowCannons
## DayPassPriceAdult 1.00 0.51 0.46 0.39
## TotalSlope 0.51 1.00 0.94 0.77
## TotalLifts 0.46 0.94 1.00 0.81
## SnowCannons 0.39 0.77 0.81 1.00
##
## n= 376
##
##
## P
## DayPassPriceAdult TotalSlope TotalLifts SnowCannons
## DayPassPriceAdult 0 0 0
## TotalSlope 0 0 0
## TotalLifts 0 0 0
## SnowCannons 0 0 0
fit1 <- lm(DayPassPriceAdult ~ TotalSlope + TotalLifts + SnowCannons,
data = mydata)
vif(fit1)
## TotalSlope TotalLifts SnowCannons
## 8.685108 10.474810 2.944759
mean(vif(fit1))
## [1] 7.368226
fit <- lm(DayPassPriceAdult ~ TotalLifts + SnowCannons,
data = mydata)
mydata$StdResid <- round(rstandard(fit), 3)
mydata$CooksD <- round(cooks.distance(fit),3)
hist(mydata$StdResid,
xlab = "Standardized residuals",
ylab = "Frequency",
main = "Histogram of standardized residuals")
shapiro.test(mydata$StdResid)
##
## Shapiro-Wilk normality test
##
## data: mydata$StdResid
## W = 0.97174, p-value = 1.09e-06
hist(mydata$CooksD,
xlab = "Cook's Distances",
ylab = "Frequency",
main = "Histogram of Cook's Distances")
head(mydata[order(mydata$StdResid), c("ID", "StdResid")],10)
## ID StdResid
## 256 256 -3.443
## 132 132 -3.427
## 163 163 -3.381
## 124 124 -3.320
## 218 218 -3.243
## 219 219 -3.243
## 220 220 -3.243
## 221 221 -3.243
## 223 223 -1.887
## 7 7 -1.847
head(mydata[order(-mydata$StdResid), c("ID", "StdResid")],3)
## ID StdResid
## 296 296 2.993
## 336 336 2.993
## 36 36 2.778
head(mydata[order(-mydata$CooksD), c("ID", "CooksD")], 10)
## ID CooksD
## 266 266 0.074
## 267 267 0.074
## 268 268 0.074
## 296 296 0.049
## 336 336 0.049
## 319 319 0.030
## 320 320 0.030
## 321 321 0.030
## 322 322 0.030
## 218 218 0.017
#install.packages("dplyr")
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:Hmisc':
##
## src, summarize
## The following object is masked from 'package:car':
##
## recode
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
mydata <- mydata %>%
filter(!ID %in% c(256, 132, 163, 124, 218, 219, 220, 221, 266, 267, 268))
fit <- lm(DayPassPriceAdult ~ TotalLifts + SnowCannons,
data = mydata)
mydata$StdFitted <- scale(fit$fitted.values)
library(car)
scatterplot(StdResid ~ StdFitted,
ylab = "Standardized residuals",
xlab = "Standardized fitted values",
smooth = FALSE,
regLine = FALSE,
boxplot = FALSE,
data = mydata)
#install.packages("olsrr")
library(olsrr)
##
## Attaching package: 'olsrr'
## The following object is masked from 'package:datasets':
##
## rivers
ols_test_breusch_pagan(fit)
##
## Breusch Pagan Test for Heteroskedasticity
## -----------------------------------------
## Ho: the variance is constant
## Ha: the variance is not constant
##
## Data
## ---------------------------------------------
## Response : DayPassPriceAdult
## Variables: fitted values of DayPassPriceAdult
##
## Test Summary
## -----------------------------
## DF = 1
## Chi2 = 2.736603
## Prob > Chi2 = 0.09807306
fit <- lm(DayPassPriceAdult ~ TotalLifts + SnowCannons,
data = mydata)
summary(fit)
##
## Call:
## lm(formula = DayPassPriceAdult ~ TotalLifts + SnowCannons, data = mydata)
##
## Residuals:
## Min 1Q Median 3Q Max
## -21.552 -6.858 -0.063 6.111 32.550
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 36.5517575 0.7197958 50.781 < 2e-16 ***
## TotalLifts 0.1950560 0.0315187 6.189 1.64e-09 ***
## SnowCannons -0.0003683 0.0022082 -0.167 0.868
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.673 on 362 degrees of freedom
## Multiple R-squared: 0.2389, Adjusted R-squared: 0.2347
## F-statistic: 56.8 on 2 and 362 DF, p-value: < 2.2e-16
sqrt(summary(fit)$r.squared)
## [1] 0.4887302
#install.packages("lm.beta")
library(lm.beta)
lm.beta(fit)
##
## Call:
## lm(formula = DayPassPriceAdult ~ TotalLifts + SnowCannons, data = mydata)
##
## Standardized Coefficients::
## (Intercept) TotalLifts SnowCannons
## NA 0.49975751 -0.01346916
The variable TotalLifts has the highest impact on the dependent variable (DayPassPriceAdult)
I assume that the ski resorts which also offer night skiing are more developed and more expensive in general, meaning that also the passes have higher prices. I will further analyze the prices of daily ski passes for adults for both of the groups to check this.
fit2 <- lm(DayPassPriceAdult ~ TotalLifts + SnowCannons + NightSki,
data = mydata)
summary(fit2)
##
## Call:
## lm(formula = DayPassPriceAdult ~ TotalLifts + SnowCannons + NightSki,
## data = mydata)
##
## Residuals:
## Min 1Q Median 3Q Max
## -22.0025 -6.9965 0.1692 6.1659 31.6040
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 37.0024848 0.7821119 47.311 < 2e-16 ***
## TotalLifts 0.2014884 0.0317760 6.341 6.83e-10 ***
## SnowCannons -0.0002832 0.0022055 -0.128 0.898
## NightSkiYes -1.5625227 1.0696833 -1.461 0.145
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.657 on 361 degrees of freedom
## Multiple R-squared: 0.2433, Adjusted R-squared: 0.237
## F-statistic: 38.7 on 3 and 361 DF, p-value: < 2.2e-16
#install.packages("lmtest")
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
waldtest(fit, fit2, test = "F")
## Wald test
##
## Model 1: DayPassPriceAdult ~ TotalLifts + SnowCannons
## Model 2: DayPassPriceAdult ~ TotalLifts + SnowCannons + NightSki
## Res.Df Df F Pr(>F)
## 1 362
## 2 361 1 2.1337 0.145
anova(fit, fit2)
## Analysis of Variance Table
##
## Model 1: DayPassPriceAdult ~ TotalLifts + SnowCannons
## Model 2: DayPassPriceAdult ~ TotalLifts + SnowCannons + NightSki
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 362 33868
## 2 361 33669 1 199.01 2.1337 0.145
# (Same result as waldtest)