**R – Traversing Bits**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Chi-squared test is useful to see differences between two distributions when they are not normal. Here’s an easy-to-do chi squared test on R. In this test, I’m trying to see if two hashtags are different in terms of collective coping in response to a social issue (e.g., displaying togetherness, talking about the issue) and social movement intent (e.g., organizing protest activity online). We manually coded two samples from #BlackLivesMatter and #AliveWhileBlack. You can see the test is significant for most of the indicators.

############# BlackLivesMatter & AliveWhileBlack Preliminary Statistics ################

data1 <- read.csv(“/Research/…/Data/Collective_Coping_FinalDataset.csv”, header = TRUE)

summary(data1)

data <-as.data.frame(data1)

##################### FREQUENCIES AND CHI-SQUARE TESTS ###################

#Full names of variables: 1)Communication_about_the_Stressor (COMSTRS) #2)Displaying_Communal_Coping_Orientation (COMCOP)

#3)Advising_and_Social_Support (ADVSS) 4)Defining_ the_boundaries_of_the_collective (BOUND)

#5)Maintaining_collective_identity (IDENT) 6)Group_communication (GRPCOM)

#7)Information_dissemination (INFODIS) 8)Coordination_of_activities (COORD)

#Resource: http://www.statmethods.net/stats/frequencies.html

# Rows: 0=#BlackLivesMatter, 1=#AliveWhileBlack/ Columns= 0=NO, 1=YES

#These frequency tables give an idea on the distribution of data

# A will be rows, B will be columns

table1 <- table(data$Hashtag,data$COMSTRS)

table2 <- table(data$Hashtag,data$COMCOP)

table3 <- table(data$Hashtag,data$ADVSS)

table4 <- table(data$Hashtag,data$BOUND)

table5 <- table(data$Hashtag,data$IDENT)

table6 <- table(data$Hashtag,data$GRPCOM)

table7 <- table(data$Hashtag,data$INFODIS)

table8 <- table(data$Hashtag,data$COORD)

# Chi-Square Tests for each variable. Tests the null hypothesis that the distribution of each variable

#is not different between the two hashtags

chisq.test(table1) #COMSTRS

chisq.test(table2) #COMCOP

chisq.test(table3) #ADVSS

chisq.test(table4) #BOUND

chisq.test(table5) #IDENT

chisq.test(table6) #GRPCOM

chisq.test(table7) #INFODIS

chisq.test(table8) #COORD

#######################################################################

Chamil Rathnayake

The post R for Beginners: Running Chi-Squared Tests appeared first on Traversing Bits.

**leave a comment**for the author, please follow the link and comment on their blog:

**R – Traversing Bits**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.