简体   繁体   中英

Error R - t.test

I am attempting to run a t.test on this data (to 'test' whether males really do drink more than females). I am not entirely sure what I am doing haha - I think I have worked out how to do t.test but now an error is coming up saying:

"Error in complete.cases(x, y) : not all arguments have the same length".

x is males, y is females - are these even the correct x and y values?

My full code:

surv <- read.csv("classsurvey.csv")
library(ggplot2)
ggplot(surv, aes(y=UnitsAlcohol, x=Gender)) + geom_boxplot()
#This boxplot shows that males drink more units of alcohol than females.
t.test(??Male,??Female,paired=TRUE)

In your t.test you have used paired = TRUE which actually isn't the case. We use paired = TRUE when the subject is the same ie the same person is being twice. For example = reflex to stimulus before and after taking the drug. In this case the subjects are completely different.

Also, the main test that you want to run is on UnitsAlcohol and not on Gender.

Try this code:

t.test(UnitsAlchohol ~ Gender, paired = FALSE, data = surv)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM