Last updated: 2019-11-25
Checks: 7 0
Knit directory: STA_463_563_Fall2019/
This reproducible R Markdown analysis was created with workflowr (version 1.4.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
The command set.seed(20190905)
was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated.
Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish
or wflow_git_commit
). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:
Ignored files:
Ignored: .DS_Store
Ignored: .Rhistory
Ignored: .Rproj.user/
Ignored: analysis/.DS_Store
Untracked files:
Untracked: analysis/diagnostics_mr2.Rmd
Untracked: analysis/lec17_code.Rmd
Untracked: analysis/test_revealjs.Rmd
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
bodyfat=read.table("http://users.stat.ufl.edu/~rrandles/sta4210/Rclassnotes/data/textdatasets/KutnerData/Chapter%20%207%20Data%20Sets/CH07TA01.txt")
colnames(bodyfat)=c("X1","X2","X3","Y")
head(bodyfat)
X1 X2 X3 Y
1 19.5 43.1 29.1 11.9
2 24.7 49.8 28.2 22.8
3 30.7 51.9 37.0 18.7
4 29.8 54.3 31.1 20.1
5 19.1 42.2 30.9 12.9
6 25.6 53.9 23.7 21.7
fit1=lm(Y~X1,data=bodyfat)
fit2=lm(Y~X1+X2,data=bodyfat)
fit3=lm(Y~X1+X2+X3,data=bodyfat)
anova(fit1)
Analysis of Variance Table
Response: Y
Df Sum Sq Mean Sq F value Pr(>F)
X1 1 352.27 352.27 44.305 3.024e-06 ***
Residuals 18 143.12 7.95
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(fit2)
Analysis of Variance Table
Response: Y
Df Sum Sq Mean Sq F value Pr(>F)
X1 1 352.27 352.27 54.4661 1.075e-06 ***
X2 1 33.17 33.17 5.1284 0.0369 *
Residuals 17 109.95 6.47
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(fit3)
Analysis of Variance Table
Response: Y
Df Sum Sq Mean Sq F value Pr(>F)
X1 1 352.27 352.27 57.2768 1.131e-06 ***
X2 1 33.17 33.17 5.3931 0.03373 *
X3 1 11.55 11.55 1.8773 0.18956
Residuals 16 98.40 6.15
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
n=nrow(bodyfat)
p=4
q=3
#SSE(X1,X2)
SSE_X12=anova(fit2)$"Sum Sq"[3]
#SSE(X1,X2,X3)
SSE_X123=anova(fit3)$"Sum Sq"[4]
Fstar=(SSE_X12-SSE_X123)/(p-q)/((SSE_X123)/(n-p))
Fstar
[1] 1.877289
1-pf(Fstar,(p-q),(n-p))
[1] 0.1895628
anova(fit3)
Analysis of Variance Table
Response: Y
Df Sum Sq Mean Sq F value Pr(>F)
X1 1 352.27 352.27 57.2768 1.131e-06 ***
X2 1 33.17 33.17 5.3931 0.03373 *
X3 1 11.55 11.55 1.8773 0.18956
Residuals 16 98.40 6.15
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#fit1: reduced model, fit2: full model
anova(fit2,fit3)
Analysis of Variance Table
Model 1: Y ~ X1 + X2
Model 2: Y ~ X1 + X2 + X3
Res.Df RSS Df Sum of Sq F Pr(>F)
1 17 109.951
2 16 98.405 1 11.546 1.8773 0.1896
SSE_X1=anova(fit1)$"Sum Sq"[2]
Fstar2=(SSE_X1-SSE_X123)/(4-2)/(SSE_X123/(n-4))
Fstar2
[1] 3.63517
1-pf(Fstar2,2,(n-4))
[1] 0.04995028
anova(fit1,fit3)
Analysis of Variance Table
Model 1: Y ~ X1
Model 2: Y ~ X1 + X2 + X3
Res.Df RSS Df Sum of Sq F Pr(>F)
1 18 143.120
2 16 98.405 2 44.715 3.6352 0.04995 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(fmsb)
library(car)
Loading required package: carData
vif(fit3)
X1 X2 X3
708.8429 564.3434 104.6060
# Verify vif function result
fitvif1=lm(X1~X2+X3,data=bodyfat)
1/(1-summary(fitvif1)$r.squared)
[1] 708.8429
# cor
cor(bodyfat)
X1 X2 X3 Y
X1 1.0000000 0.9238425 0.4577772 0.8432654
X2 0.9238425 1.0000000 0.0846675 0.8780896
X3 0.4577772 0.0846675 1.0000000 0.1424440
Y 0.8432654 0.8780896 0.1424440 1.0000000
summary(fit3)
Call:
lm(formula = Y ~ X1 + X2 + X3, data = bodyfat)
Residuals:
Min 1Q Median 3Q Max
-3.7263 -1.6111 0.3923 1.4656 4.1277
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 117.085 99.782 1.173 0.258
X1 4.334 3.016 1.437 0.170
X2 -2.857 2.582 -1.106 0.285
X3 -2.186 1.595 -1.370 0.190
Residual standard error: 2.48 on 16 degrees of freedom
Multiple R-squared: 0.8014, Adjusted R-squared: 0.7641
F-statistic: 21.52 on 3 and 16 DF, p-value: 7.343e-06
fit4=lm(Y~X2+X3,data=bodyfat)
summary(fit4)
Call:
lm(formula = Y ~ X2 + X3, data = bodyfat)
Residuals:
Min 1Q Median 3Q Max
-4.0777 -1.8296 0.1893 1.3545 4.1275
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -25.99695 6.99732 -3.715 0.00172 **
X2 0.85088 0.11245 7.567 7.72e-07 ***
X3 0.09603 0.16139 0.595 0.55968
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 2.557 on 17 degrees of freedom
Multiple R-squared: 0.7757, Adjusted R-squared: 0.7493
F-statistic: 29.4 on 2 and 17 DF, p-value: 3.033e-06
vif(fit4)
X2 X3
1.00722 1.00722
sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] car_3.0-4 carData_3.0-2 fmsb_0.6.3
loaded via a namespace (and not attached):
[1] Rcpp_1.0.2 knitr_1.24 whisker_0.3-2
[4] magrittr_1.5 workflowr_1.4.0 hms_0.5.1
[7] rlang_0.4.0 stringr_1.4.0 tools_3.6.1
[10] data.table_1.12.2 xfun_0.9 rio_0.5.16
[13] git2r_0.26.1 htmltools_0.3.6 abind_1.4-5
[16] readxl_1.3.1 yaml_2.2.0 rprojroot_1.3-2
[19] digest_0.6.20 tibble_2.1.3 crayon_1.3.4
[22] zip_2.0.4 vctrs_0.2.0 fs_1.3.1
[25] zeallot_0.1.0 curl_4.0 glue_1.3.1
[28] evaluate_0.14 haven_2.1.1 rmarkdown_1.15
[31] openxlsx_4.1.3 stringi_1.4.3 cellranger_1.1.0
[34] pillar_1.4.2 compiler_3.6.1 forcats_0.4.0
[37] backports_1.1.4 foreign_0.8-71 pkgconfig_2.0.2