Ivana Tonevska

Regression Analysis

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

Explanation of the dataset ‘European Ski Resorts’:

- Source: European Ski Resorts. (2022, February 20). Kaggle. https://www.kaggle.com/datasets/thomasnibb/european-ski-resorts
- Unit of obesrvation: one ski resot in Europe
- Sample size: 376 ski resorts
- Dependant variable:
  • DayPassPriceAdult: price of a daily pass for adults in EUR (numerical, ratio)
- Explanatory variables:
  • TotalSlope: Total number of slopes (numerical, ratio)
  • NightSki: categorical (No/Yes)
  • TotalLifts: Total number of lifts (numerical, ratio)
  • SnowCannons: Total number of snow cannons (numerical, ratio)

Research question: How is the price of a daily pass for adults in the ski resorts in Europe impacted by the total number of slopes, lifts, snow cannons and the availability of night ski?

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

Descriptive Statistics

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
  • DayPassPriceAdult Max=81: The most expensive daily pass for adults costs 81EUR.
  • SnowCannons 3rd Qu=252: 75% of the ski resorts have up to, or exactly 252 snow cannons.
  • TotalLifts median=17: Half (50%) of the ski resorts in Europe have up to, or exactly 17 lifts, while the remaining (50%) have more than 17 lifts.
#install.packages("car")
library(car)
## Loading required package: carData

Multiple Regression Model

Regression function:

DayPassPriceAdult^ = 𝛽0 + 𝛽1TotalSlope + 𝛽2TotalLifts + 𝛽3SnowCannons
Explanatory variables:
  • TotalSlope: I will be further analyzing the effect of this explanatory variable on the daily pass price for adults as I expect to see a positive coefficient, meaning that with each additional slope in the ski resort, the daily pass price will be higher.
  • TotalSlope: I expect a positive coefficient, indicating that with each additional lift in the ski resort, the daily pass price will be higher.
  • SnowCannons: I expect a positive coefficient, indicating that with each additional snow cannon in the ski resort, the daily pass price will be higher.

Assumptions:

  1. Linearity in parameters
  2. The expected value of errors equals 0
  3. Homoskedasticity (equal variances)
  4. Normal distribution of errors (applies only to small samples)
  5. Errors are independent (this assumption is met, as the data is not time-series nor hierarchical data)
  6. No perfect multicolinearity
  7. Number of units is greater than the number of estimated parameters (n>k) (assumption is met)

Requirements:

  1. The dependent variable should be numeric, explanatory variables can be either numerical or categorical (dummy) (requirement is met)
  2. Each explanatory variable must vary (nonzero variance) (requirement is met)
  3. No outliers or units of high impact
  4. No too strong multicolinearity
scatterplotMatrix(mydata[ ,c(-1, -4)],
                  smooth = FALSE)

# Only for numerical variables
  • Checking linearity from the first row of the scatter plot matrix (the row with the dependent variable): assumption is met (there are no curves in the graphs).
  • By observing the matrix, there is a high chance of violation of the assumption for multicollinearity between ‘total number of slopes’ and ’ total number of lifts’. This will be further analyzed with the variance inflation factor (VIF)
#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
  • 0.51: There is a semi-strong positive relationship between the price of a daily pass and the total number of slopes.
  • The higher values for correlation signal that there might be a problem with multicolinearity.
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
VIF scores for TotalSlope and TotalLifts are >5, so we have to remove one of those explanatory variables and reestimate the model.
DayPassPriceAdult^ = 𝛽0 + 𝛽1TotalLifts + 𝛽2SnowCannons
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")

Checking for outliers (StdResid. >3 | <-3)
From the histogram above we can see that there is an outlier (StdResid < -3)

Checking whether errors are normally distributed with the Shapiro Wilk test

shapiro.test(mydata$StdResid)
## 
##  Shapiro-Wilk normality test
## 
## data:  mydata$StdResid
## W = 0.97174, p-value = 1.09e-06
  • H0: Errors are normally distributed.
  • H1: Errors are not normally distributed.
  • We reject H0 (p<0.001) and conclude that errors are not normally distributed
  • However, this applies to smaller samples. As this sample is sufficiently large (n=376), we can assume normality of errors.
hist(mydata$CooksD,
     xlab = "Cook's Distances",
     ylab = "Frequency",
     main = "Histogram of Cook's Distances")

The gaps indicate that there are some units of high impact and those should be removed.
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
The observations in the rows 1-8 from the above output are outliers as their StdResid values are <-3.
head(mydata[order(-mydata$StdResid), c("ID", "StdResid")],3)
##      ID StdResid
## 296 296    2.993
## 336 336    2.993
## 36   36    2.778
No outliers with StdResid >3.
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
The units wit IDs 266, 267 and 268 are of high impact and cause gaps in the historgam of Cook’s Distances, meaning that they should be removed.
#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
Removing the outliers and units of high impact.
mydata <- mydata %>%
  filter(!ID %in% c(256, 132, 163, 124, 218, 219, 220, 221, 266, 267, 268))
Refitting the model after removing outliers and units of high impact.
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)

Formal test for checking homoskedasticity - Breusch Pagan Test
#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
  • H0: The variance is constant. (homoskedasticity)
  • H1: The variance is not constant. (heteroskedasticity)
  • p-value = 0.099
  • BSD we cannot reject H0. –> homoskedasticity assumption is met.
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

Explanation of the coefficients

  • TotalLifts
H0: 𝛽1 = 0
H1: 𝛽1 != 0
We reject H0 at p<0.001 and conclude that the total number of lifts has a statistically significant effect on the price of daily pass for adults.
If the total number of lifts increase by 1 lift, then on average the price of a daily pass for adults will increase by 0.172EUR (p<0.001), assuming everything else (number of snow cannons) remains unchanged.
  • SnowCannons
H0: 𝛽2 = 0
H1: 𝛽2 != 0
We cannot reject H0, therefore we cannot coclaim that the number of snow cannons has a statistically signifficant effect the price of a daily pass for adults

Coefficient of Determination

Multiple R-squared = 0.2149
21.49% of the variability of price of a daily pass for adults can be explained by variability (linear relationship) of TotalLifts and Snow Cannons.

Test of significance of regression

F-test:
H0: 𝜌^2 = 0
H1: 𝜌^2 > 0
BSD we reject H0 (p<0.001) and conclude that at least one of the explanatory variables (TotalLifts & SnowCannons) impacts the price of a daily pass for adults. (We can explain at least some variablility of the price with this model)

Multiple correlation coefficient

sqrt(summary(fit)$r.squared)
## [1] 0.4887302
The relationship between the price of a daily pass for adults and the explanatory variables (TotalLifts & SnowCannons) is semi-strong.
#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)

Adding the categorical (dummy) variable (NightSki) to the model

Research question: Does the price of daily pass for adults differ between resorts that offer night skiing and those which do not offer night skiing?

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.

DayPassPriceAdult^ = 𝛽0 + 𝛽1TotalLifts + 𝛽2SnowCannons + 𝛽3NightSki
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
The number of total lifts remained statistically signifficant, while the number of snow cannons remained statistically insignifficant.
H0: 𝛽3 = 0
H1: 𝛽3 != 0
BSD we cannot reject H0, therefore cannot claim that availability of night skiing affects the price of a daily pass for adults.
(If it was statistically signifficant, the interpretation would have been: Given the values of all other explanatory variables, the ski resorts which offer night skiing have on average prices of daily passes for adults lower by 1.56EUR compared to those which do not offer night skiing (p-value))
#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)
H0: Both models are equally good.
H1: Complex model is better. (the one with more variables)
We cannot reject H0. Therefore, since both models are equally good, it is better to use the simpler one (the one with less explanatory variables).