I have some very rudimentary code for generating a chisq test for some of the variables in the titanic dataset. I would like to have a way to differentiate categorical vs numeric/cont variables, so it would only do the chisq test on the categorical variables or t.tests if there were to be numeric variables.
I'm interested in being able to compare multiple levels between the Survived and Not-Survived groups like so:
Prop Survived Female vs Prop Not-Survived Female, Prop Survived Class 1 vs Prop Not-Survived Class 1, And so on..
The table subsets are directed for The Survived/Not-Survived Female comparison
library(Titanic)
titanic <- as.data.frame(Titanic)
names <- names(titanic)
names(cars)
for (var in names) {
tabla<-table(titanic$Survived, titanic[[var]])
tabla<-addmargins(tabla)
print(tab)
res<-prop.test(x = c(tabla[1,2], tabla[2,2]), n = c(tabla[1,3], tabla[2,3]), correct = F)
print(var)
print(res)
}
}
Thank you