Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need it in R code please. Thank you. Load the prostate data from the Faraway pac

ID: 2949554 • Letter: N

Question

Need it in R code please. Thank you.

Load the prostate data from the Faraway package into R. Let Ipsa be the outcome and treat all of the other variables as predictors. (a) Construct 90% and 95% confidence intervals for the parameter associated with (b) Using ?-0.1, test if Ibph has a significant impact on Ipsa levels. age (c) Use an F test to determine if at least one of the predictors is significantly different from zero. Compute this test "by hand" (i.e. not using summary, Im, or anova) as well as using anova to double check that your answers are the same d) Remove all predictors that are not significant at a 0.05. Compare that sub model to the full model using an F-test, which model is preferred?

Explanation / Answer

require(faraway)

head(prostate)

regmodel <- lm(lpsa ~ lcavol+lweight+age+lbph+svi+lcp+gleason+pgg45,data = prostate)

summary(regmodel)

Output:

> summary(regmodel)

Call:

lm(formula = lpsa ~ lcavol + lweight + age + lbph + svi + lcp +

    gleason + pgg45, data = prostate)

Residuals:

    Min      1Q Median      3Q     Max

-1.7331 -0.3713 -0.0170 0.4141 1.6381

Coefficients:

             Estimate Std. Error t value Pr(>|t|)   

(Intercept) 0.669337   1.296387   0.516 0.60693   

lcavol       0.587022   0.087920   6.677 2.11e-09 ***

lweight      0.454467   0.170012   2.673 0.00896 **

age         -0.019637   0.011173 -1.758 0.08229 .

lbph         0.107054   0.058449   1.832 0.07040 .

svi          0.766157   0.244309   3.136 0.00233 **

lcp         -0.105474   0.091013 -1.159 0.24964   

gleason      0.045142   0.157465   0.287 0.77503   

pgg45        0.004525   0.004421   1.024 0.30886   

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.7084 on 88 degrees of freedom

Multiple R-squared: 0.6548, Adjusted R-squared: 0.6234

F-statistic: 20.86 on 8 and 88 DF, p-value: < 2.2e-16

a)

## 95% CI

confint(regmodel,parm = "age")

Output:

## 90% CI

confint(regmodel,parm = "age",level = .90)

Output:

           5 %         95 %

age -0.0382102 -0.001064151

b)

At Alpha = 0.1, the variable lbph seems to be a significant variable as the p-value is less than 0.1.

c)

Null and Alternate Hypothesis:

H0: Coefficient of all the variables are zero

Ha: Not all coefficients are zero

Since, the p-value from the ANOVA results is less than 0.05, we reject the null hypothesis ie at least one of the predictors is significantly different from zero.

d)

Model 2

#Using only the significant variables from model 1

regmodel2 <- lm(lpsa ~ lcavol+lweight+svi,data = prostate)

summary(regmodel2)

Output:

Model 2 is better than Model 1 as the difference between R Square and Adjusted R Square is less for Model 2. This gap is more for model 1 which indicates that there are insignificant variables in Model1

           5 %         95 %

age -0.0382102 -0.001064151

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote