Need it in R-code. Thank you? 7. Consider the uswages data in the Faraway packag
ID: 3918072 • Letter: N
Question
Need it in R-code. Thank you?
7. Consider the uswages data in the Faraway package. (20 Points) (a) Create a new predictor called region which takes values "NE", "MW","WE", and "SO", and summarizes the variables ne, mw, we, and so in the data set (b) Turn region into a factor variable with "NE" as the baseline. Fit the regression model with region as the predictor and wage as the outcome. Summarize the fit of the model and use an F-test to determine if region is significantly associated with wages (take a - 0.05). Take special care to interpret what each of the betas represents (c) Now use "SO" as the baseline and redo (b). Contrast the results. (d) Keep "SO" as the baseline. Now use an F-test to determine if region is still significant after correcting for education. Use ?-0.1 (e) Keep "SO" as the baseline. Now fit a model with eduction, region, and their interaction. Summarize of the fit of the model (paying attention to how to inter- pret the betas) and use an F-test to determine if the interaction effect is, overall, significant. (f) Plot the results from (e) by creating a scatter plot of wage vs education. Color code the points by region and plot the regression lines for each region (make sure the color of the regression line matches the color of the points)Explanation / Answer
The R snippet is as follows
library(faraway)
data("uswages")
uswages
attach(uswages)
## ne as baseline
uswages$region = ifelse(so==1, "so",ifelse(mw==1,"mw",ifelse(we==1,"we","ne")))
uswages$region <- as.factor(uswages$region)
fit <- lm(wage ~ region,data=uswages)
summary(fit)
## so as baseline
uswages$region1 = ifelse(ne==1, "ne",ifelse(mw==1,"mw",ifelse(we==1,"we","so")))
uswages$region1 <- as.factor(uswages$region1)
fit1 <- lm(wage ~ region1,data=uswages)
summary(fit1)
The results are
summary(fit)
Call:
lm(formula = wage ~ region, data = uswages)
Residuals:
Min 1Q Median 3Q Max
-596.1 -295.9 -86.8 176.4 7135.2
Coefficients:
Estimate Std. Error tvalue Pr(>|t|)
(Intercept) 585.368 20.600 28.416 <2e-16 ***
regionne 46.291 29.746 1.556 0.1198
regionso -4.532 27.601 -0.164 0.8696
regionwe 64.598 30.439 2.122 0.0339 * ## signficant as the p value is less than0.05
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘’ 1
Residual standard error: 459.2 on 1996 degrees of freedom
Multiple R-squared: 0.00405, Adjusted R-squared: 0.002553
F-statistic: 2.705 on 3 and 1996 DF, p-value:0.04395 ## F test , overall the model is statisticallysignficant
> summary(fit1)
Call:
lm(formula = wage ~ region1, data = uswages)
Residuals:
Min 1Q Median 3Q Max
-596.1 -295.9 -86.8 176.4 7135.2
Coefficients:
Estimate Std. Error tvalue Pr(>|t|)
(Intercept) 585.368 20.600 28.416 <2e-16 ***
region1ne 46.291 29.746 1.556 0.1198
region1so -4.532 27.601 -0.164 0.8696
region1we 64.598 30.439 2.122 0.0339 * ##signficant as the p value is less than 0.05
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘’ 1
Residual standard error: 459.2 on 1996 degrees of freedom
Multiple R-squared: 0.00405, Adjusted R-squared: 0.002553
F-statistic: 2.705 on 3 and 1996 DF, p-value:0.04395 , as the p value of the model is less than 0.05 , hence themodel is overall significant
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.