I need to calculate the p-value indicating the difference of score values between groups taking the 'Age' variable as a covariate- How should I calculate and present it given that each groups has a different sample size?
data<-structure(list(Subject = c(3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 27, 28, 1, 2, 18, 19, 22, 23, 24, 25, 26, 15, 16, 17, 20,
21), Group = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3,
3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1), Age = c(60.9, 60.9, 61.5,
61.5, 61.5, 61.5, 61.5, 61.5, 62.7, 62.7, 63.5, 63.5, 61.8, 61.8,
63.6, 63.6, 62.9, 62.9, 63.2, 63.2, 64.1, 60.4, 60.4, 62.9, 63.1,
63.1, 61.2, 61.2), Score = c(103, 92, 85, 84, 124, 120, 85, 87,
77, 83, 85, 75, 91, 90, 140, 99, 101, 101, 97, 100, 114, 105,
99, 101, 82, 92, 84, 89)), class = "data.frame", row.names = c(14L,
19L, 71L, 72L, 97L, 100L, 117L, 121L, 124L, 127L, 135L, 137L,
194L, 195L, 246L, 247L, 297L, 300L, 330L, 331L, 362L, 364L, 366L,
440L, 442L, 443L, 504L, 507L))
Would the correlation of each group score and age, then comparison of P, R suffice?
You could run a multiple regression and use robust standard errors:
data$Group <- factor(data$Group)
m <- lm(Score ~ Group * Age, data = data)
library(lmtest)
library(sandwich)
coeftest(m, vcov = vcovHC(m, type="HC1"))
t test of coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -56.17586 178.51065 -0.3147 0.75596
Group2 685.13412 255.34576 2.6832 0.01358 *
Group3 -26.46759 236.94890 -0.1117 0.91207
Age 2.33990 2.90589 0.8052 0.42931
Group2:Age -11.02058 4.11310 -2.6794 0.01370 *
Group3:Age 0.67231 3.86276 0.1740 0.86342
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
And maybe include a plot so that one can see that the groups are not of the same size:
library(dplyr)
library(ggplot2)
data %>%
ggplot(aes(x = Age, y = Score)) +
geom_smooth(method = "lm") +
geom_point() +
facet_wrap(~Group, labeller = as_labeller(c("1" = "group 1", "2" = "group 2", "3" = "group 3")))
Centered data:
data <- data %>%
mutate(Age_centered = scale(Age, center = TRUE))
m <- lm(Score ~ Group * Age_centered, data = data)
coeftest(m, vcov = vcovHC(m, type="HC1"))
t test of coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 89.44958 3.06921 29.1441 < 2e-16 ***
Group2 -0.73980 4.39059 -0.1685 0.86773
Group3 15.37412 4.81025 3.1961 0.00417 **
Age_centered 2.53076 3.14291 0.8052 0.42931
Group2:Age_centered -11.91951 4.44860 -2.6794 0.01370 *
Group3:Age_centered 0.72715 4.17783 0.1740 0.86342
data %>%
ggplot(aes(x = Age_centered, y = Score, color = Group)) +
geom_smooth(method = "lm") +
geom_point()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.