rm(list=ls()) #BEL2 ! #These days, I feel like I belong. # (values 1 thru 7) 1: not true, 7: very true #BSS8 (values: 0, 1, 2) (rare, frequent, continuous) # I accept the idea of killing myself. #IBS3 O #Have you had any self-mutilation thoughts and impulses # (without taking action)? #IBS15 H #Have you had any suicidal thoughts and impulses (without taking action)? # Question #1. Is level of belongingness related to level of suicidal ideation? # Answer # I will use correlation to establish any relation # We will use tools from categories #---------------------------------------------------------------------- # all numerical data, but this data links to textual answers file = "VanOrden_for dist.csv" dall = read.csv(file) dall #d = dall[c("bel2","bss8")] d = dall[c("bel2","ibs15")] d # clean up unused variables rm(dall) # bss8 has many 999 undefines. Must get rid of them d = d[d$ibs15 != 999,] #d = d[d$bel2 != 999,] d t = table(d) total = sum(t) rowsum = apply(t,1,sum) colsum = apply(t,2,sum) prop = t/total rowprop = sweep(t,1,rowsum,"/") colprop = sweep(t,2,colsum,"/") l = list(s.table=t, s.total=total, s.rowsum=rowsum, s.colsum=colsum, s.prop=prop, s.colprop=colprop, s.rowprop=rowprop) print("-----------------") l$s.total print("-----------------") l$s.table l$s.rowsum l$s.colsum l$s.rowprop l$s.colprop print("-----------------") # Chi-Square testing chisq.test(l$s.table) ### Cannot do this. WHY NOT? ### chisq.test(l$s.prop) ### The reason is likely that there are not enough samples. y = l$s.table[1:4,2:3] y #y print("*** chisq.test(y) ***") chisq.test(y) #prop.test(y,y) print("================") chisq.test(y,y) print("================")