The downloaded binary packages are in
/var/folders/4w/gljslth537l5fz1ys3jw1xj40000gn/T//RtmprQNmWH/downloaded_packages
library(effectsize)library(car)
Loading required package: carData
Attaching package: 'car'
The following object is masked from 'package:purrr':
some
The following object is masked from 'package:dplyr':
recode
hist(general_health, main ="General Health", breaks ="Sturges")
hist(pain, main ="Pain", breaks ="Sturges")
hist(emotional_wb, main ="Emotional Well Being", breaks ="Sturges")
hist(fatigue, main ="Fatigue", breaks ="Sturges")
hist(emotional_role, main ="Emotional Role Limitations", breaks ="Sturges")
hist(physical_func, main ="Physical Functioning", breaks ="Sturges")
ANOVA of age and race on total RAND scores
rand_aov <-aov(total_rand ~ age_group*race, data = d)summary(rand_aov)
Df Sum Sq Mean Sq F value Pr(>F)
age_group 1 348 347.8 1.360 0.24503
race 1 1735 1735.4 6.784 0.00992 **
age_group:race 1 26 26.2 0.102 0.74924
Residuals 193 49373 255.8
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
1 observation deleted due to missingness
install.packages("car")
The downloaded binary packages are in
/var/folders/4w/gljslth537l5fz1ys3jw1xj40000gn/T//RtmprQNmWH/downloaded_packages
library(car)leveneTest(total_rand ~ age_group*race, data = d)
Levene's Test for Homogeneity of Variance (center = median)
Df F value Pr(>F)
group 3 3.6575 0.01347 *
193
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Okay, for total scores from the RAND SF-36, no interaction between our age factor and race factor here. Data is not normally distributed. I am log transforming it here:
d$log_rand <-log1p(total_rand)hist(d$log_rand)
leveneTest(log_rand ~ age_group*race, data = d)
Levene's Test for Homogeneity of Variance (center = median)
Df F value Pr(>F)
group 3 1.459 0.2271
193
ANOVA with log transformed data
log_rand_aov <-aov(log_rand ~ age_group * race, data = d)summary(log_rand_aov)
Df Sum Sq Mean Sq F value Pr(>F)
age_group 1 0.07 0.0661 0.277 0.5993
race 1 0.77 0.7722 3.237 0.0736 .
age_group:race 1 0.27 0.2669 1.119 0.2915
Residuals 193 46.04 0.2386
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
1 observation deleted due to missingness
Still no effect here.
Linear model predicting RAND scores from age (continuous) and race (binary)
rand_lm <-lm(log_rand ~ d$CurrAge*d$AA_White, data = d)summary(rand_lm)
Call:
lm(formula = log_rand ~ d$CurrAge * d$AA_White, data = d)
Residuals:
Min 1Q Median 3Q Max
-4.2817 -0.0504 0.0892 0.1984 0.4214
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.378339 0.236966 18.477 <2e-16 ***
d$CurrAge -0.004353 0.004543 -0.958 0.339
d$AA_White2 0.024495 0.285391 0.086 0.932
d$CurrAge:d$AA_White2 0.002227 0.005352 0.416 0.678
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.4886 on 193 degrees of freedom
(1 observation deleted due to missingness)
Multiple R-squared: 0.02286, Adjusted R-squared: 0.007669
F-statistic: 1.505 on 3 and 193 DF, p-value: 0.2146
#t_rand_lm <- lm(total_rand ~ d$CurrAge*d$AA_White, data = d)#summary(t_rand_lm)
Let’s check the rest of the subscales included in the RAND SF-36.
health_aov <-aov(general_health ~ age_group * race, data = d)pain_aov <-aov(pain ~ age_group * race, data = d)emotionalwb_aov <-aov(emotional_wb ~ age_group * race, data = d)fatigue_aov <-aov(fatigue ~ age_group * race, data = d)emotionalrole_aov <-aov(emotional_role ~ age_group * race, data = d)physicalrole_aov <-aov(physical_role ~ age_group * race, data = d)physicalfunc_aov <-aov(physical_func ~ age_group * race, data = d)summary(pain_aov)
ggplot(d, aes(x = d$CurrAge, y = total_rand, color = d$AA_White)) +geom_point() +xlab("Age") +ylab("Total Rand Scores") +ggtitle("Scatterplot of Total Rand Scores by Age")
Warning: Use of `d$CurrAge` is discouraged.
ℹ Use `CurrAge` instead.
Warning: Use of `d$AA_White` is discouraged.
ℹ Use `AA_White` instead.
Since most of the data has a very heavy left skew, lets just look at Pain and Fatigue, which have a bit more variance.
Pain scores
ggplot(d, aes(x = d$CurrAge, y = pain, color = d$AA_White)) +geom_point() +xlab("Age") +ylab("Pain Scores") +ggtitle("Scatterplot of Pain Scores by Age")
Warning: Use of `d$CurrAge` is discouraged.
ℹ Use `CurrAge` instead.
Warning: Use of `d$AA_White` is discouraged.
ℹ Use `AA_White` instead.
Fatigue
ggplot(d, aes(x = d$CurrAge, y = fatigue, color = d$AA_White)) +geom_point() +xlab("Age") +ylab("Fatigue Scores") +ggtitle("Scatterplot of Fatigue Scores by Age")
Warning: Use of `d$CurrAge` is discouraged.
ℹ Use `CurrAge` instead.
Warning: Use of `d$AA_White` is discouraged.
ℹ Use `AA_White` instead.
ggplot(d, aes(x = age_race_names, fill =factor(hypertension_names))) +geom_bar(position ="dodge") +ggtitle("Hypertension Frequency by Age Race Category") +xlab("Category") +ylab("Frequency") +scale_fill_discrete(name ="Hypertension Status", labels =c("Hypertension", "No Hypertension"))
Two-way anova for Hypertension outcomes by age and race
hypertension_aov <-aov(hypertension ~ age_group * race, data = d)summary(hypertension_aov)
Df Sum Sq Mean Sq F value Pr(>F)
age_group 1 5.55 5.549 26.866 5.52e-07 ***
race 1 1.34 1.335 6.466 0.0118 *
age_group:race 1 0.05 0.049 0.239 0.6258
Residuals 191 39.45 0.207
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
3 observations deleted due to missingness
leveneTest(hypertension ~ age_group*race, data = d)
Levene's Test for Homogeneity of Variance (center = median)
Df F value Pr(>F)
group 3 5.7274 0.0008974 ***
191
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
No interaction of age and race here. Also fails Levene’s test.
Logistic regression function
logit <-function(outcome, predictor1, predictor2, data, intercept =TRUE){if(intercept ==TRUE){ model <-glm(outcome ~ predictor1 + predictor2, data = data, family =binomial(link ="logit")) }else{ model <-glm(outcome ~ predictor1 + predictor2 -1, data = data, family =binomial(link ="logit")) }return(model)}
reg_hyper_age <-logit(hypertension, d$CurrAge, d$AA_White, data = d)summary(reg_hyper_age)
Call:
glm(formula = outcome ~ predictor1 + predictor2, family = binomial(link = "logit"),
data = data)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.7378 -0.8826 -0.5015 0.9902 2.2618
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -3.41322 0.69322 -4.924 8.49e-07 ***
predictor1 0.06674 0.01256 5.312 1.09e-07 ***
predictor22 -0.99930 0.35454 -2.819 0.00482 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 260.77 on 194 degrees of freedom
Residual deviance: 221.91 on 192 degrees of freedom
(3 observations deleted due to missingness)
AIC: 227.91
Number of Fisher Scoring iterations: 4
predict_hyper <-predict(reg_hyper_age, type ="response")# Create a data frame for plotting the predictionsplot_data <-data.frame(d$CurrAge, d$AA_White)plot_data$predictions <-predict(reg_hyper_age, newdata = plot_data, type ="response")# Plot the logistic regression using ggplot2ggplot(plot_data, aes(x = d$CurrAge, y = predictions, color = d$AA_White)) +geom_line() +xlab("Age") +ylab("Predicted Probability of Hypertension") +ggtitle("Hypertension Diagnosis by Age and Race") +scale_color_discrete(name ="Race")
In this plot here, 1 is Black athletes, and 2 is white athletes.
#reg_hyper_contact <- glm(contact_df$MedHistory_Hypertension_Diagnosed ~ contact_df$CurrAge + contact_df$AA_White, family = binomial)reg_hyper_contact <-logit(contact_df$MedHistory_Hypertension_Diagnosed, contact_df$CurrAge, contact_df$AA_White, data = contact_df)summary(reg_hyper_contact)
Call:
glm(formula = outcome ~ predictor1 + predictor2, family = binomial(link = "logit"),
data = data)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.7718 -0.9306 -0.5304 1.0099 2.1827
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -3.35170 0.75199 -4.457 8.31e-06 ***
predictor1 0.06584 0.01372 4.798 1.60e-06 ***
predictor22 -0.90884 0.37487 -2.424 0.0153 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 228.33 on 166 degrees of freedom
Residual deviance: 198.07 on 164 degrees of freedom
(3 observations deleted due to missingness)
AIC: 204.07
Number of Fisher Scoring iterations: 3
predict_hyper <-predict(reg_hyper_contact, type ="response")# Create a data frame for plotting the predictionsplot_data_c <-data.frame(contact_df$CurrAge, contact_df$AA_White)plot_data_c$predictions <-predict(reg_hyper_contact, newdata = plot_data_c, type ="response")# Plot the logistic regression using ggplot2ggplot(plot_data_c, aes(x = contact_df$CurrAge, y = predictions, color = contact_df$AA_White)) +geom_line() +xlab("Age") +ylab("Predicted Probability of Hypertension") +ggtitle("Hypertension Diagnosis by Age and Race") +scale_color_discrete(name ="Race")
These plots look pretty much the same, but the AIC is a bit lower
Same thing, but with contact participation included as a predictor (0 or 1)
diabetes_names <-ifelse(diabetes ==1, "Diabetes", "No Diabetes")ggplot(d, aes(x = age_race_names, fill =factor(diabetes_names))) +geom_bar(position ="dodge") +ggtitle("Diabetes Frequency by Age Race Category") +xlab("Category") +ylab("Frequency") +scale_fill_discrete(name ="Diabetes Status", labels =c("Diabetes", "No Diabetes"))
This is what I initially thought. We have no people in the younger white category that have been diagnosed with Diabetes.
Two-way anova for Diabetes by age and race
diabetes_aov <-aov(diabetes ~ age_group * race, data = d)summary(diabetes_aov)
Df Sum Sq Mean Sq F value Pr(>F)
age_group 1 0.115 0.1154 1.893 0.1705
race 1 0.369 0.3688 6.048 0.0148 *
age_group:race 1 0.003 0.0034 0.056 0.8129
Residuals 191 11.646 0.0610
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
3 observations deleted due to missingness
Arthritis
r_arthritis <- d$MedHistory_RhArthritis_Diagnosedo_arthritis <- d$MedHistory_Arthritis_Diagnosedr_arthritis_names <-ifelse(r_arthritis ==1, "Rheumatoid Arthritis", "No Arthritis")o_arthritis_names <-ifelse(o_arthritis ==1, "Osteoarthritis", "No Arthritis")table(r_arthritis_names)
r_arthritis_names
No Arthritis Rheumatoid Arthritis
181 14
table(o_arthritis_names)
o_arthritis_names
No Arthritis Osteoarthritis
145 50
ggplot(d, aes(x = age_race_names, fill =factor(r_arthritis_names))) +geom_bar(position ="dodge") +ggtitle("R. Arthritis Frequency by Age Race Category") +xlab("Category") +ylab("Frequency") +scale_fill_discrete(name ="Arthritis Status", labels =c("No Arthritis", "R. Arthritis"))
ggplot(d, aes(x = age_race_names, fill =factor(o_arthritis_names))) +geom_bar(position ="dodge") +ggtitle("O. Arthritis Frequency by Age Race Category") +xlab("Category") +ylab("Frequency") +scale_fill_discrete(name ="Arthritis Status", labels =c("No Arthritis", "O. Arthritis"))
table(o_arthritis_names)
o_arthritis_names
No Arthritis Osteoarthritis
145 50
table(r_arthritis_names)
r_arthritis_names
No Arthritis Rheumatoid Arthritis
181 14
Looks like there are no participants in the younger black group with rheumatoid arthritis.
Two-way ANOVA of arthritis (both) by age and race
r_arth_aov <-aov(r_arthritis ~ age_group * race, data = d)summary(r_arth_aov)
Df Sum Sq Mean Sq F value Pr(>F)
age_group 1 0.477 0.4769 7.727 0.00598 **
race 1 0.339 0.3392 5.496 0.02009 *
age_group:race 1 0.389 0.3893 6.307 0.01285 *
Residuals 191 11.789 0.0617
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
3 observations deleted due to missingness
o_arth_aov <-aov(o_arthritis ~ age_group * race, data = d)summary(o_arth_aov)
Df Sum Sq Mean Sq F value Pr(>F)
age_group 1 1.92 1.9181 10.529 0.00139 **
race 1 0.01 0.0055 0.030 0.86253
age_group:race 1 0.46 0.4629 2.541 0.11258
Residuals 191 34.79 0.1822
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
3 observations deleted due to missingness
Okay. There’s an interaction between age and race here for rheumatoid arthritis, but I wonder if this is because of the poor distribution across groups?
leveneTest(r_arthritis ~ age_group*race, data = d)
Levene's Test for Homogeneity of Variance (center = median)
Df F value Pr(>F)
group 3 6.51 0.0003241 ***
191
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Looks like there is a notable degree of variance across groups for Rheumatoid Arthritis.
reg_arth <-logit(o_arthritis, d$CurrAge, d$AA_White, data = d)summary(reg_arth)
Call:
glm(formula = outcome ~ predictor1 + predictor2, family = binomial(link = "logit"),
data = data)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.3585 -0.8078 -0.5399 1.1121 2.2508
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -3.83272 0.76725 -4.995 5.87e-07 ***
predictor1 0.05212 0.01284 4.058 4.96e-05 ***
predictor22 -0.18108 0.37247 -0.486 0.627
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 222.01 on 194 degrees of freedom
Residual deviance: 203.12 on 192 degrees of freedom
(3 observations deleted due to missingness)
AIC: 209.12
Number of Fisher Scoring iterations: 4
predict_hyper <-predict(reg_arth, type ="response")# Create a data frame for plotting the predictionsplot_data <-data.frame(d$CurrAge, d$AA_White)plot_data$predictions <-predict(reg_arth, newdata = plot_data, type ="response")# Plot the logistic regression using ggplot2ggplot(plot_data, aes(x = d$CurrAge, y = predictions, color = d$AA_White)) +geom_line() +xlab("Age") +ylab("Predicted Probability of O. Arthritis") +ggtitle("O. Arthritis Diagnosis by Age and Race") +scale_color_discrete(name ="Race")
Here’s a logistic model of osteoarthritis as predicted by age and race. Age appears to be driving the effect here, with no notable differences across our two racial groups
Recap of analyses steps to work on so we can start writing the paper.
Run two-way ANOVA for all analyses run with 4 groups. Use two factors: age factor and race factor. The Age factor has two levels: old and young. The Race factor has two levels: Black and White. Test the interaction age * race. The pairwise comparisons are only valid if the interaction test shows a significant (p < .05) result.
Done
Provide bar graphs showing mean and standard error for the four groups, young white, young black, old white, old black athletes.
Report the odds ratio result as a ratio rather than a percent. The formula is easy. Odds-ratio for hypertension in Blacks is (#blacks w-htn /#blacks w-o-htn) / (#whites w-htn/#whites w-o-htn).
I would add the Cohen’s D effect size. It give the same information as Etta-squared but will be more familiar to a wider audience. The formula is easy if you have the means for Group-1 and Group-2. (MeanG1 – MeanG2) / pooled SD. Of course R will do it for you.
The following is just stuff to add to your presentation (slides or code output) but you have already done.
Show sample sizes of each of the 4 groups young white, young black, old white, old black. Provide this for hypertension, diabetes, RAND-total, rheumatoid, osteo, etc.
Show the full set of analyses for diabetes, rheumatoid, and osteo in the same way you did for hypertension, i.e. two-way ANOVA and then pairwise tests.
Show the full set of analyses for RAND subscales e.g. emotional well-being.
Other additional questions -> Emotional Impacts of physical impairments across the age spectrum