I am getting different p-values for a variable in t-test and its coefficient in multiple linear regression so I am unsure which one to believe. As an example, my hypothetical dataset consists of measurements of time taken to complete task A or B by cats and dogs, with 6 animals per group. I used R to analyse the data.
I want to know if there is a time difference according to the pet and task. So I do a 2-way ANOVA with interaction for pet and task.
# 2-way ANOVA with interaction
a1<-aov(time ~ pet * task, data)
summary(a1)
> summary(a1)
Df Sum Sq Mean Sq F value Pr(>F)
pet 1 15.819 15.819 90.372 7.36e-09 ***
task 1 0.492 0.492 2.814 0.109
pet:task 1 0.854 0.854 4.880 0.039 *
Residuals 20 3.501 0.175
The ANOVA output tells me that time differs for pet (p-value significant) but not task (p-value not significant). The significant interaction term indicates that the time difference for pet depends on the type of task. Indeed the box plot shows that time looks different between cats doing task A vs task B, but not for dogs doing task A vs B.
To find the time difference between the subgroup cat.taskA vs the subgroup cat.taskB, I do a t-test and compare the results to a multiple linear regression. The t-test comparing cat.taskA vs cat.taskB shows that the p-value is not significant (p=0.05201). The mean difference is 0.6638174.
# t-test of task B vs A in cat only
dcat<-filter(data,pet=="cat")
t1<-t.test(time ~ task, dcat, var.equal=T)
t1
# standard error
t1$stderr
# mean difference
1.5931352-0.9293178
> t1
Two Sample t-test
data: time by task
t = 2.2048, df = 10, p-value = 0.05201
alternative hypothesis: true difference in means between group A and group B is not equal to 0
95 percent confidence interval:
-0.007014563 1.334649298
sample estimates:
mean in group A mean in group B
1.5931352 0.9293178
> # standard error
> t1$stderr
[1] 0.3010728
> # mean difference
> 1.5931352-0.9293178
[1] 0.6638174
When I fit a multiple linear regression model with interaction for pet and task, the coefficient for "taskB" is the time difference between cat.taskA and cat.taskB, which is the same as calculated manually (0.6638). However the coefficient is significant with a p-value of 0.0124 and the t-statistic is different from the t-test.
## multiple linear reg with interaction
m1 <- lm(time ~ pet * task, data)
summary(m1)
> summary(m1)
Call:
lm(formula = time ~ pet * task, data = data)
Residuals:
Min 1Q Median 3Q Max
-0.7877 -0.2352 -0.0554 0.2427 1.1500
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.5931 0.1708 9.327 1.01e-08 ***
petdog 1.2464 0.2415 5.160 4.76e-05 ***
taskB -0.6638 0.2415 -2.748 0.0124 *
petdog:taskB 0.7546 0.3416 2.209 0.0390 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.4184 on 20 degrees of freedom
Multiple R-squared: 0.8306, Adjusted R-squared: 0.8052
F-statistic: 32.69 on 3 and 20 DF, p-value: 6.621e-08
I see that the t-statistic from the multiple linear regression is different from the t-test because of the smaller standard error for the "taskB" coefficient. But I am not understanding how this smaller standard error is made smaller in the multiple linear regression.
Should I believe the p-value from the t-test results or the multiple linear regression results? If I had only done a t-test comparing cat.taskA vs cat.taskB without bothering with ANOVA or multiple linear regression at all, I would have concluded that there is no difference in time. But the multiple linear regression is telling me there is a difference, unless it is not correct?