Part A. Variables In the field of psychology, much research is done using self-report surveys using Likert scales (look it up!).
A1 What type of variable is a Likert response? (1 pt) A Likert response is an Ordinal variable which means that it contains a whole number within a set range, for example rating Customer satisfaction from 1 to 5.
A2 What are some (at least 2) benefits of using Likert scales? (2 pts) One benefit of Likert scales is that is gives more insight and nuance than a simple Binary yes/no response. Another benefit is that because it is not open ended, it is “clean” to collect and analyze.
A3 What are some drawbacks — and dangers — of using them? Make sure you mention at least one ‘drawback’ and one ‘danger’ (a ‘drawback’ is a shortcoming, while a ‘danger’ implies potential harm). (2 pts) One drawback is that the respondants are limited to the ordinal range given, so there is not a continuous variable to analyze in the model. A danger is that some respondants may chose neutrality (i.e. choosing 3 in range of 1-5) which may be less informative to the anaylsis.
Perform linear regressions on a dataset from a European Toyota car dealer on the sales records of used cars (Toyota Corolla). We would like to construct a reasonable linear regression model for the relationship between the sales prices of used cars and various explanatory variables (such as age, mileage, horsepower). We are interested to see what factors affect the sales price of a used car and by how much.
Data Description
Id - ID number of each used car Model - Model name of each used car Price - The price (in Euros) at which each used car was sold Age - Age (in months) of each used car as of August 2004 KM - Accumulated kilometers on odometer HP - Horsepower Metallic - Metallic color? (Yes = 1, No = 0) Automatic - Automatic transmission? ( Yes = 1, No = 0) CC - Cylinder volume (in cubic centimeters) Doors - Number of doors Gears - Number of gears Weight - Weight (in kilograms)
The data is in the file “UsedCars.csv”. To read the data in
R, save the file in your working directory (make sure you
have changed the directory if different from the R working directory)
and read the data using the R function
read.csv().
Read data and show few rows of data.
# Read in the data
data = read.csv("UsedCars.csv",sep = ",",header = TRUE)
# Show the first few rows of data
head(data, 5)
## Id Model Price Age KM HP
## 1 1 TOYOTA Corolla 1800 T SPORT VVT I 2/3-Doors 21500 27 19700 192
## 2 2 TOYOTA Corolla 1.8 VVTL-i T-Sport 3-Drs 2/3-Doors 20950 25 31461 192
## 3 3 TOYOTA Corolla 1.8 16V VVTLI 3DR T SPORT BNS 2/3-Doors 19950 22 43610 192
## 4 4 TOYOTA Corolla 1.8 16V VVTLI 3DR T SPORT 2/3-Doors 19600 25 32189 192
## 5 5 TOYOTA Corolla 1.8 16V VVTLI 3DR T SPORT 2/3-Doors 21500 31 23000 192
## Metallic Automatic CC Doors Gears Weight
## 1 0 0 1800 3 5 1185
## 2 0 0 1800 3 6 1185
## 3 0 0 1800 3 6 1185
## 4 0 0 1800 3 6 1185
## 5 1 0 1800 3 6 1185
price = data[,3]
km = data[,5]
plot(km, price, main="ACCUMULATED KILOMETERS VS PRICE", xlab="Accumulated KMs ", ylab="Price ")
We can observe visually from this scatterplot that there is an inverse relationship between Price and Accumulated KMs - as KMs increase, the price of the vehicle decreases. While it looks somewhat linear there could be a bit of a curve to the distribution as well as a majority of datapoints falling between 50000 and 100000 KMs
cor(price, km)
## [1] -0.6183873
The correlation coefficient between Price and KM is -.61. This indicates a clear negative correlation between the variables, a relatively Strong Correlation.
No I would not recommend a simple linear regression model.This correlation coefficient of -.61 is Strong, but based on the skew & curvature of the distribution I believe another model could perform better.
Yes I might try a log transform or an exponential model based on the shape of the distribution.
Fit a linear regression model, named model_1, to evaluate the relationship between UsedCars Price and the accumulated KM. Do not transform the data. The function you should use in R is:
# Your code here...
model_1 = lm(price~km)
summary(model_1)
##
## Call:
## lm(formula = price ~ km)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7993 -1774 -457 1394 11437
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.494e+04 1.693e+02 88.24 <2e-16 ***
## km -6.817e-02 2.439e-03 -27.95 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2615 on 1262 degrees of freedom
## Multiple R-squared: 0.3824, Adjusted R-squared: 0.3819
## F-statistic: 781.4 on 1 and 1262 DF, p-value: < 2.2e-16
3 pts What are the model parameters and what are their estimates? The model has two parameters: an intercept of 1.494e+04 (\(\beta_1\) ) and a Slope of -6.817e-02 \(\beta_2\)
2 pts Write down the estimated simple linear regression equation. Price = 14,940 - 0.06817 (KM)
2 pts Interpret the estimated value of the \(\beta_1\) parameter in the context of the problem.
Fresh off the Lot, with Zero accumulated kilometers, We would expect the price of the car to be 14,940 euros.
confint(model_1, level=0.95)
## 2.5 % 97.5 %
## (Intercept) 1.461094e+04 1.527539e+04
## km -7.296019e-02 -6.339078e-02
Our confidence interval for \(\beta_1\) is -.07296 to -.06339.
# Your code here...
Create and interpret the following graphs with respect to the assumptions of the linear regression model. In other words, comment on whether there are any apparent departures from the assumptions of the linear regression model. Make sure that you state the model assumptions and assess each one. Each graph may be used to assess one or more model assumptions.
# Your code here...
plot(km,price)
abline(lm(price ~ km))
This graph appears consistent with our linear model and negative correlation between Price and KM.
# Your code here...
plot(model_1$fitted, model_1$residuals)
abline(0,0)
The residuals are skewed negative in the mid-range and positive near the low and high ranges. This suggests another model may give us better fit.
hist(residuals(model_1))
qqnorm(residuals(model_1))
qqline(residuals(model_1))
It is clear from the Histogram that there is a skew towards negative residuals and a longer postive residual tail. This Q-Q plot leads me to question the Normality of our distribution because it is not a straight line.
Use the results from both model_1 to discuss the effects of KM on the dependent variable: Holding everything else equal, how much the sales price would decrease if a car accumulated 10,000 more kilometers? What observations can you make about the result in the context of the problem? (3 pts)
# multiplying KM by slope of linear model:
lessprice = 10000*-.06817
lessprice
## [1] -681.7
Holding All else equal, I would estimate the price of the vehicle to decrease by 681.70 Euros with an increase of 10,000 KM. In the context of this problem, I would note that the actual price decrease due to additional 10K KM may depend on where it started in Accumulated KM - it could be more a more drastic decrease if it started with fewer miles, and less drastic decrease if it started with More miles.
You work for the National Park Service (NPS), and you absolutely love bears. Describe an imaginary (it can be realistic) scenario in which you get to run a one-way ANOVA on a few (3+) species of bears.
What are you comparing (name the variable!)? What do you hope to learn from ANOVA? (2 pts)
Hibernation time. I hope to learn whether different species of Bears hibernate for different amounts of time, on average.
Imagine that the results are “mixed”, meaning you can draw some conclusions and not others. Describe your conclusions and make sure you detail, with reference to your ANOVA, why the results were “mixed.” (3 pts)
It was clear from the ANOVA testing that the 3 species of Bears under investigation did not have equal mean hibernation Time; however pairwise comparison was necessary but the result was mixed. From this, I can conclude that Black Bears sleep for longer period in the winter than Polar bears, but I could not find a significant pairwise difference between Black bears and Grizzley bears.
Now imagine that you have just been granted 3 months and $50,000 to continue this study (you’re a great grant writer and a very likable member of the NPS!). Describe some next steps you would take to clarify, reinforce and/or further explore your nascent investigation. You MUST reference using a ‘controlling’ variable somehow in your response. (5 pts)
I would control for the Age of bears by sampling only small baby cubs that were born the previous Spring between February to May to see if this adds any clarity to my results.
Explain in detail what it means specifically — in a statistical sense — for any result to be “statistically significant” at a particular -level. In other words, explain the meaning and use of p-values. You should research this question, and you should expect your answer to be at least a paragraph long. (6 pts)
A p-value represents the probability that our model can explain the variance observed in a dataset. In a simple linear setting, it measures how much the response variable is likely to be correlated in a non-random way to another parameter. In this linear setting, the null hypothesis is that the slope of the linear equation between the two is zero. In ANOVA testing, we assume there is no difference in means between, samples, so our null hypothesis is that the means are Equal. In both cases, the p-value is the probability that are null hypothesis is true, given the results of the sample. If the P-value is less than a signifigance value Alpha, we reject it, if greater, we accept the null hypotheses that one variable has no measurable relationship with another, or that the means between populations are virtually the same and variation between them is random.