문제

Is it possible to calculate chi squared in R when your data is in the form of a list of observations? What I mean is, it is simple to get chi squared if you know the cross. For instance, if you have a survey and you ask for gender and a true-false question, you only need four numbers to calculate the chi squared. What I have instead is two columns of data with each respondent's answers. Is it possible to get chi squared from this structure of the data, or do I have to convert it?

If I have to convert it for R, does anyone know of another language that will allow me to get the chi squared directly?

도움이 되었습니까?

해결책

If you use table before putting your data into chisq.test you should be fine

# Create some fake 'raw' data
dat <- data.frame(gender = sample(c("M","F"), 100,rep = T), ans = as.logical(rbinom(100,1,.3)))
head(dat)
# just use table to get the data into the form needed
chisq.test(table(dat))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top