-
Notifications
You must be signed in to change notification settings - Fork 0
/
mardia_dm1633_assignment9.Rmd
68 lines (51 loc) · 1.69 KB
/
mardia_dm1633_assignment9.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
title: "assignment9"
output:
pdf_document: default
html_document: default
date: "2023-04-14"
---
#HW09
#Use the R programs covered in the MultipleTesting module as a guide for HW09.
#Perform a multiple regression on all 100 predictors from the meatspec dataset in the
#faraway package and extract the p-values for the coefficients of the 100 variables.
```{r}
library(faraway)
data(meatspec,package="faraway") #the dataset meatspec is found in the faraway package
lmod=lm(fat ~ . , data=meatspec)
summary(lmod)
# Extract p-values for coefficients and exluding the intercept
p_values <- summary(lmod)$coefficients[-1, 4]
```
```{r}
p_values
```
```{r}
#Use the p-values vector to list the variables with coefficients that are significantly
#different from 0 with
#a) using no FWER adjustment (alpha=.05 for each test of hypothesis).
alpha <- 0.05
print(p_values[p_values < alpha])
names(p_values[p_values < alpha])
# We reject these 15 features based on the p values
```
```{r}
#b) using the Bonferroni procedure to control the FWER alpha at 0.05.
#Get adjusted p value
p_values_bonfadjust <- p.adjust(p_values, method = "bonferroni")
# Identify variables with significant coefficients
adj_bonferroni <- p_values_bonfadjust[p_values_bonfadjust < alpha]
adj_bonferroni
names(adj_bonferroni)
# We reject only V1 based on the Bonferroni procedure
```
```{r}
#c) using the Holm procedure to control the FWER alpha at 0.05.
# Get the adjusted p-val
p_values_holmadjust <- p.adjust(p_values, method = "holm")
# Identify variables with significant coefficients
adj_holm <- p_values_holmadjust[p_values_holmadjust < alpha]
adj_holm
names(adj_holm)
#We again reject only V1 based on Holm procedure as well
```