So picture these two groups of females and males ages:
femalesage<-c(30,52,59,25,26,72,46,32,64,45)
malesage<-c(40,56,31,63,63,78,42,45,67)
I can easily do a t.test(females age,malesage) to achieve the following result:
t.test(femalesage,malesage)
Welch Two Sample t-test
data: femalesage and malesage
t = -1.2013, df = 16.99, p-value = 0.2461
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-24.224797 6.647019
sample estimates:
mean of x mean of y
45.10000 53.88889
Now, suppose I have this same data organized differently, so something like this:
ages<-c(30,52,59,25,26,72,46,32,64,45,40,56,31,63,63,78,42,45,67)
genders<-c("F","F","F","F","F","F","F","F","F","F","M","M","M","M","M","M","M","M","M","M")
df<-data.frame(ages, genders)
I want to achieve a similar result to the welsh two-sample t-test using some sort of regression test, testing the slope of Beta1=0 vs. Beta1 not equal to 0, where B1 is the coefficient of Gender and the response is ages. Any idea how I could get the same result?