# Chi Square and Coding Query

Hi, I am new to R Studio (and am very fragile when it comes to stats too). I have been getting a bit of help from my uni and from online. I just want to make sure that what I have created is giving me the correct info for a Chi Square test and creation of a mosaic plot.

An example of a table is:
A B
Red 8 24
Blue 6 16
Pink 0 1
White 1 0

My code is:

setwd("C:/Users/JC248686/R Files/SAPO")
QDC15= read.csv(file.choose(),row.names=1)
QDC15

chisq.test(QDC15)
chisq.test(QDC15,simulate.p.value=TRUE)

#'run this if the table contains 0s or <5'
fisher.test(QDC15,y=NULL,workspace=200000,hybrid=FALSE,hybridPars=c(except=5,percent=80,Emin=1),control=list(),or=1,alternative="two.sided",simulate.p.value=TRUE,B=2000)

# 'This shows the percentage of A & B (width)'

apply(QDC15,2,function(x)sum(x)/sum(QDC15))*100

# 'this shows the percentage of TOTAL A&B'

apply(QDC15,1,function(x)sum(x)/sum(QDC15))*100

# 'Shows percentage of each thing handed out by A/B

QDC15pct=round(100*QDC15/rowSums(QDC15),1)
QDC15pct

#'LOAD GGPLOT2 AND DYPLR!!!'

# 'This show percentage of each A/B given what thing

Colsums = mutate(QDC15,I_pct = I / sum(I),NI_pct = NI / sum(NI))*100
Colsums

# 'This counts the total of the rows'

courtrows=rowSums(QDC15,na.rm=FALSE,dims=1L)
courtrows

#This counts the total of the colums
courtcols=colSums(QDC15,na.rm=FALSE,dims=1L)
courtcols

# 'makes the chart grey scale'

palette(gray(seq(0,.9,len=5)))

## mosaicplot(t(QDC15),col=3:5,las=1,main="Title\n=(n=46)",xlab="A/B Status",ylab="Proportion")

Any suggestions would be gratefully received (P.s., had to tweek some to hide details for confidentiality so might look a bit weird in the description ).

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.