Project 1

Author

Emily Adams

You will be analyzing data from the Jackson Heart Study (JHS). You can find the data on Canvas. For full credit, you must include all code chunks and R output backing up your responses.

0. Import the JHS data; you can download it from Canvas. You need to research how to read a SAS data file into R (hint: look into the haven package).

##to install: install.packages('haven')
library(haven)
JHS_data <- read_sas("analysis1 (1).sas7bdat")
head(JHS_data, n=5)
# A tibble: 5 × 198
  subjid    visit VisitDate  DaysFromV1 YearsFromV1  ARIC recruit ageIneligible
  <chr>     <dbl> <date>          <dbl>       <dbl> <dbl>   <dbl>         <dbl>
1 "   2054"     1 2003-06-30          0           0     0       3             0
2 "   2013"     1 2003-09-30          0           0     0       3             0
3 "    455"     1 2004-01-03          0           0     0       5             0
4 "      5"     1 2003-10-27          0           0     0       3             0
5 "   2408"     1 2003-11-28          0           0     0       3             0
# ℹ 190 more variables: FastHours <dbl>, age <dbl>, brthyr <dbl>, brthmo <dbl>,
#   sex <chr>, male <dbl>, menopause <dbl>, alc <dbl>, alcw <dbl>,
#   currentSmoker <dbl>, everSmoker <dbl>, weight <dbl>, height <dbl>,
#   waist <dbl>, neck <dbl>, BMI <dbl>, hip <dbl>, bsa <dbl>, BPmeds <dbl>,
#   DMmedsOral <dbl>, DMmedsIns <dbl>, DMmeds <dbl>, statinMeds <dbl>,
#   hrtMeds <dbl>, betaBlkMeds <dbl>, calBlkMeds <dbl>, diureticMeds <dbl>,
#   antiArythMeds <dbl>, medAcct <dbl>, BPmedsSelf <dbl>, DMMedType <dbl>, …

Week 1: Categorical Predictors

1a. Model systolic blood pressure (sbp; mmHg) as a function of age (age; years), education (HSgrad; 0=no, 1=yes), and health status as defined by body mass index (BMI3cat; 0=poor health, 1=intermediate health, 2=ideal health). Remember to report the resulting model.

quantile(JHS_data$age, c(0, 0.25, 0.5, 0.75, 1), na.rm = TRUE) 
      0%      25%      50%      75%     100% 
22.91307 45.33333 54.19849 63.15674 83.21150 
quantile(JHS_data$HSgrad, c(0, 0.25, 0.5, 0.75, 1), na.rm = TRUE) 
  0%  25%  50%  75% 100% 
   0    1    1    1    1 
quantile(JHS_data$BMI3cat, c(0, 0.25, 0.5, 0.75, 1), na.rm = TRUE) 
  0%  25%  50%  75% 100% 
   0    0    0    1    2 
m1 <- glm(sbp ~ age + HSgrad + BMI3cat, data = JHS_data, family = 'gaussian')
summary(m1)

Call:
glm(formula = sbp ~ age + HSgrad + BMI3cat, family = "gaussian", 
    data = JHS_data)

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) 104.37912    1.77783  58.712  < 2e-16 ***
age           0.43382    0.02542  17.065  < 2e-16 ***
HSgrad       -0.93980    0.85489  -1.099    0.272    
BMI3cat      -1.73009    0.40132  -4.311 1.68e-05 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for gaussian family taken to be 214.2995)

    Null deviance: 640015  on 2641  degrees of freedom
Residual deviance: 565322  on 2638  degrees of freedom
  (11 observations deleted due to missingness)
AIC: 21684

Number of Fisher Scoring iterations: 2

1b. Construct the 95% confidence intervals for the regression coefficients.

confint(m1, level=0.95)
                 2.5 %      97.5 %
(Intercept) 100.894647 107.8635983
age           0.383995   0.4836442
HSgrad       -2.615350   0.7357596
BMI3cat      -2.516666  -0.9435156

1c. Is this a significant regression line? Test at the \(\alpha=0.05\) level. Remember to state your hypotheses and conclusion.

anova(m1, test = 'F')
Analysis of Deviance Table

Model: gaussian, link: identity

Response: sbp

Terms added sequentially (first to last)

        Df Deviance Resid. Df Resid. Dev        F    Pr(>F)    
NULL                     2641     640015                       
age      1    70429      2640     569586 328.6472 < 2.2e-16 ***
HSgrad   1      281      2639     569305   1.3133    0.2519    
BMI3cat  1     3983      2638     565322  18.5846 1.685e-05 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Hypotheses

#Null hyppothesis = there is not evidence to support a significant regression line
#Alternate hypothesis= there is evidence to support a significant regression line

F Statistic and p-Value

age: f statistic = 328.6472, p value = < 2.2e-16 
BMI3cat: f statistic = 18.5846, p value = 1.685e-05 

Rejection Region

# Reject null if p < 0.05

Conclusion/Interpretation

# We reject the null hypothesis. There is significant evidence to suggest a significant regression line 

1d. Which predictors, if any, are significant predictors of systolic blood pressure? Test at the \(\alpha=0.05\) level. Remember to state your conclusions.

anova(m1, test = 'F')
Analysis of Deviance Table

Model: gaussian, link: identity

Response: sbp

Terms added sequentially (first to last)

        Df Deviance Resid. Df Resid. Dev        F    Pr(>F)    
NULL                     2641     640015                       
age      1    70429      2640     569586 328.6472 < 2.2e-16 ***
HSgrad   1      281      2639     569305   1.3133    0.2519    
BMI3cat  1     3983      2638     565322  18.5846 1.685e-05 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
age and BMI3cat are significant predictors based on the F-test.

1e. Provide brief interpretations for the slopes of the predictors.

104.38sbp=0.434age-0.94HSgrad-1.73BMI3cat

1f. How many suspected outliers exist? You must justify your answer statistically. Remember to state your conclusion.

library(classpackage)

JHS_data_new <- JHS_data %>%
  mutate(outlier =  if_else(abs(rstandard(m1))>2.5, "Suspected", "Not Suspected"))
Error in `mutate()`:
ℹ In argument: `outlier = if_else(abs(rstandard(m1)) > 2.5, "Suspected",
  "Not Suspected")`.
Caused by error:
! `outlier` must be size 2653 or 1, not 2642.
JHS_data %>% count(outlier)
Error in `count()`:
! Must group by variables found in `.data`.
✖ Column `outlier` is not found.
JHS_data <- JHS_data %>% 
  filter(outlier == TRUE)
Error in `filter()`:
ℹ In argument: `outlier == TRUE`.
Caused by error:
! object 'outlier' not found
JHS_data %>% count(outlier)
Error in `count()`:
! Must group by variables found in `.data`.
✖ Column `outlier` is not found.

Insert your answer here :)

1g. How many suspected influential/leverage points exist? You must justify your answer statistically. Remember to state your conclusion.

cooks(m1)

There are many spikes in this graph, meaning there are many leverage points...

1h. Is multicollinearity a problem in this model? You must justify your answer statistically. Remember to state your conclusion.

car::vif(m1)
     age   HSgrad  BMI3cat 
1.095162 1.094919 1.000371 
Since multicollinearity is present if VIF > 10, multicollinearity is not present

1i. Assess the assumptions on the linear model. Remember to draw your conclusion with appropriate justification.

anova_check(m1)

Based on the scatterplot and the qq plot the assumptions are normal.

1j. Construct an appropriate data visualization to help with explaining the model results. Systolic blood pressure should be on the y-axis, age should be on the x-axis. Create lines for BMI (BMI3cat); remember that we will plug in a combination of 0’s and 1’s to represent BMI.

JHS_data %>% 
  ggplot(aes(x = age, y = sbp, color = as.factor(BMI3cat))) +
  geom_point() +
  labs(x = "age",
       y = "sbp",
       color = "BMI 3 Categories") +
  theme_bw()

2. Required for graduate students / extra credit for undergraduate students: Write a paragraph to summarize the above analysis, written such that a non-quantitative person could understand. Note - knowledge about medicine/health is not required. I am only looking for you to report results in a digestible manner.

Given the data, age and body mass index are significant predictors of systolic blood pressure. We can also note that a high school diploma is not indicated to be a signifcant predictor of systolic blood pressue. We can also see from the graph that as age increases, blood pressue also rises. 

Week 2: Interaction Terms

3a. Model systolic blood pressure (sbp; mmHg) as a function of age (age; years), education (HSgrad; 0=no, 1=yes), and body mass index (BMI; kg/m2), and the following interactions: body mass index \(\times\) age and body mass index \(\times\) education. Remember to report the resulting model.

m3 <- glm(sbp ~ age + HSgrad + BMI + BMI:age + BMI:HSgrad, data = JHS_data) 
summary(m3)

Call:
glm(formula = sbp ~ age + HSgrad + BMI + BMI:age + BMI:HSgrad, 
    data = JHS_data)

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) 74.749725   7.884470   9.481  < 2e-16 ***
age          0.869644   0.115042   7.559 5.56e-14 ***
HSgrad      -2.772950   4.009951  -0.692 0.489301    
BMI          0.885513   0.243923   3.630 0.000288 ***
age:BMI     -0.013472   0.003571  -3.773 0.000165 ***
HSgrad:BMI   0.055666   0.123568   0.450 0.652393    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for gaussian family taken to be 211.7859)

    Null deviance: 640015  on 2641  degrees of freedom
Residual deviance: 558268  on 2636  degrees of freedom
  (11 observations deleted due to missingness)
AIC: 21655

Number of Fisher Scoring iterations: 2

3b. Perform the appropriate hypothesis test to determine if the interaction between body mass index and age is significant. Test at the \(\alpha=0.05\) level. Remember to state your conclusion.

summary(m3)

Call:
glm(formula = sbp ~ age + HSgrad + BMI + BMI:age + BMI:HSgrad, 
    data = JHS_data)

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) 74.749725   7.884470   9.481  < 2e-16 ***
age          0.869644   0.115042   7.559 5.56e-14 ***
HSgrad      -2.772950   4.009951  -0.692 0.489301    
BMI          0.885513   0.243923   3.630 0.000288 ***
age:BMI     -0.013472   0.003571  -3.773 0.000165 ***
HSgrad:BMI   0.055666   0.123568   0.450 0.652393    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for gaussian family taken to be 211.7859)

    Null deviance: 640015  on 2641  degrees of freedom
Residual deviance: 558268  on 2636  degrees of freedom
  (11 observations deleted due to missingness)
AIC: 21655

Number of Fisher Scoring iterations: 2

Hypotheses

#Null hyppothesis = there is not interaction between body mass index and age  
#Alternate hypothesis= there is evidence to support interaction between body mass index and age

Test Statistic and p-Value

# test statistic = -3.773 
# p value = 0.000165 

Rejection Region

# Reject null if p < 0.05

Conclusion/Interpretation

# We reject the null hypothesis. There is significant evidence to suggest an interaction between body mass index and age

3c. Perform the appropriate hypothesis test to determine if the interaction between body mass index and education is significant Test at the \(\alpha=0.05\) level. Remember to state your conclusion.

summary(m3)

Call:
glm(formula = sbp ~ age + HSgrad + BMI + BMI:age + BMI:HSgrad, 
    data = JHS_data)

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) 74.749725   7.884470   9.481  < 2e-16 ***
age          0.869644   0.115042   7.559 5.56e-14 ***
HSgrad      -2.772950   4.009951  -0.692 0.489301    
BMI          0.885513   0.243923   3.630 0.000288 ***
age:BMI     -0.013472   0.003571  -3.773 0.000165 ***
HSgrad:BMI   0.055666   0.123568   0.450 0.652393    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for gaussian family taken to be 211.7859)

    Null deviance: 640015  on 2641  degrees of freedom
Residual deviance: 558268  on 2636  degrees of freedom
  (11 observations deleted due to missingness)
AIC: 21655

Number of Fisher Scoring iterations: 2

Hypotheses

#Null hyppothesis = there is not interaction between body mass and education  
#Alternate hypothesis = there is evidence to support interaction between body mass and education

Test Statistic and p-Value

# test statistic = 0.450 
# p value  = 0.652393 

Rejection Region

# Reject null if p < 0.05

Conclusion/Interpretation

# We do not reject the null hypothesis. There is not enough evidence to suggest an interaction between body mass and education.

3d. Create the following models (i.e., plug in the following values and algebraically simplify): (1) body mass index of 32, and (2) body mass index of 25. Remember to report the resulting simplified models.

  sbp = bmi32 + age
  sbp = bmi25 + age
  
  74.75=.87age+.89bmi-.01age:BMI

3e. Provide brief interpretations for the slopes of the predictors for the one of the models in 3d (your choice, but make sure you specify which model you are interpreting).

bmi (body mass index) when increased by 25 will also increase systolic blood pressue, but bmi when increased by 32 will increase systolic blood pressue even more. 

3f. Construct an appropriate data visualization to help with explaining the model results. Systolic blood pressure should be on the y-axis, age should be on the x-axis, and use the regression lines constructed in 3d to construct predicted values.

JHS_data %>% 
  ggplot(aes(x = age, y = sbp, color = as.factor(BMI3cat))) +
  geom_point() +
  labs(x = "Age",
       y = "Systolic Blood Pressue",
       color = "Body Mass Index") +
  theme_bw()

4. Required for graduate students / extra credit for undergraduate students: Write a paragraph to summarize the above analysis, written such that a non-quantitative person could understand. Note - knowledge about medicine/health is not required. I am only looking for you to report results in a digestible manner.

There is significant evidence to support that BMI and Age together is a predictor of SBP (systolic blood pressure). This means that as body mass index and age both increase, there is indication that SBP also increases.