Lily K.
asked 02/02/24Provided code and answer in r studio
The following data contains the Price, Age and Miles of 25 mustang cars.
• Price - Asking price (in $1,000’s)
• Miles - Mileage on the car (in 1,000’s)
• Age - Age of the car (in years)
#Run this code to install Lock5Data package and the MustangPrice dataset
install.packages("Lock5Data")
library("Lock5Data")
data(MustangPrice, package="Lock5Data")
attach(MustangPrice)
head(MustangPrice)
a. Regression Price against Miles using R. Report your results.
b. What changes and how does it change if I change Miles (in 1,000’s) to km (not in 1,000’s km)?
c. Create a new variable that has miles in km (not in 1,000’s) and rerun the regression model. Does either
the t-value or the p-value change? Explain.
d. What changes and how does it change if I change Price to euros (not in 1,000’s)? Use the exchange rate
where 1 US dollar equals 0.92 euro.
e. Create a new variable that has miles in km (not in 1,000’s) and rerun the regression model. Does either
the t-value or the p-value change? Explain.
f. What changes and how does it change if I make both changes listed above?
g. Rerun the model with both changes. Does either the t-value or the p-value change this time? Explain.
1 Expert Answer
Benjamin C. answered 04/29/25
Experienced Tutor Specializing in Applied Statistics
The following code can be used in a markdown file in R Studio to display the answers to these questions with an outline that has subsections. The chunks are not named, but they could be named by inserting a name following the "r".
## a
```{r}
#comparing our data to normal quantiles
qqnorm(MustangPrice$Price)
qqnorm(MustangPrice$Miles)
#plotting out data
plot(MustangPrice$Miles, MustangPrice$Price)
#using lm() for regression
price_miles<- lm(Price ~ Miles, data=MustangPrice)
summary(price_miles)
#plotting our regression line
abline(price_miles)
```
## b and c
### Change miles to kilometers
```{r}
# attaching the dplyr package to use the functions mutate()
library(dplyr)
MustangPrice<- MustangPrice %>% mutate(kM=(Miles*1000*1.609))
```
### Regress price onto kilometers
Because our x value is inflated, the negative slope of our regression line becomes less steep. Naturally, this change has very little effect on the intercept (i.e., the price of a mustang at 0 kilometers). The p-values and t-values remain the same. The model assumes a normal distribution, which means that variables are standardized to use the t distribution to make inferences. The standardized variance of our variables is not changing because of the type of units being used. Notice that the coefficient of determination is also the same. This is because it is a ratio of the variance accounted for in Y by X, given as a proportion.
```{r}
price_kM<- lm(Price ~ kM, data=MustangPrice)
summary(price_kM)
```
## d and e
### Creating the variable Euros
```{r}
MustangPrice<- MustangPrice %>% mutate(priceEuros=Price*.92)
```
### Euro on miles regression
The t-values, p-values, and model fit remain the same because significance levels are based on standardized distributions, which are robust to unit conversions. After all, p-values are based on standardized distances from the mean; in a sense, the mean and the distance are in the same units. Changing the units does not change the relative variance, but it does change the units in which our intercept and slope are displayed. We may now interpret our slope as an estimated change in price in Euros for every additional mile on a Mustang.
```{r}
euro_mile<- lm(priceEuros ~ Miles, data=MustangPrice)
summary(euro_mile)
```
## f and g
### Regressing the price of a Mustang in euros onto the "mileage" of a Mustang in kilometers
We may now interpret our slope as an estimated change in price in Euros for every kilometer on a mustang. Because variance (or more specifically in this case a variation of covariance) is how the model determines our p and t values, and variance is a measure relative to the mean, our p and t values remain the same.
```{r}
euro_kM<- lm(priceEuros ~ kM, data=MustangPrice)
summary(euro_kM)
```
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Marla G.
Here's a link to a website that should help you with anything you need to do in R: https://libguides.chapman.edu/R/welcome I can't do your homework for you, but this link should be helpful. Good Luck!09/22/24