############################################################ # Chisq test of goodness of fit: # Legalization, Decriminalization, Existing Law, No Opinion # Proportion in population known. # Data collected after airing of advertisement. # Hypothesis: Does the ad change the distribution of opinion? #################################################### x<-c(39,99,336,26) chisq.test(x,p=c(0.07,0.18,0.65,0.1)) qchisq(.99,3) ####################################################### #Chisq test of independence using HairEyeColor data ######################################################### data("HairEyeColor") HairEyeColor chisq.test(HairEyeColor[,,"Female"]) #Independence of hair color and eye color for females dim(HairEyeColor[,,"Female"]) chisq.test(HairEyeColor[,,"Male"]) chisq.test(HairEyeColor[,,"Male"]+HairEyeColor[,,"Female"]) #Both genders together margin.table(HairEyeColor,c(1,3)) chisq.test(margin.table(HairEyeColor,c(1,3))) #Independence of hair color and gender chisq.test(margin.table(HairEyeColor,c(2,3))) #Independence of eye color and gender