rm(list=ls()) #4. Is level or loneliness related to level of belongingness? #ISEL7 F #When I feel lonely, there are several people I could call and talk to. #SPS12 # #I feel so lonely I cannot stand it. #BEL2 ! #These days, I feel like I belong. #---------------------------------------------------------------------- # all numerical data, but this data links to textual answers file = "VanOrden_for dist.csv" dall = read.csv(file) attach(dall) d = dall[c("isel7","sps12","bel2")] d = d[d$isel7 != 999,] d = d[d$sps12 != 999,] print(d) detach(dall) # clean up unused variables rm(dall) attach(d) v1 = isel7 z = max(v1)-min(v1) v1 = jitter(v1,amount=z/50) v2 = sps12 z = max(v2)-min(v2) v2 = jitter(v2,amount=z/50) v3 = bel2 z = max(v3)-min(v3) v3 = jitter(v3,amount=z/50) # plot one variable versus the other par(mfcol=c(2,2)) attach(d) p = plot(v1,v2) p = plot(v1,v3) p = plot(v2,v3) detach(d) # There are 22 values, but only 10 points. Must change the type of # plot. Either add jitter, or a 3D plot, with count as the 3rd axis. # Or perform a correlation # Conclusion from plot # most results are that # bss8 is mostly 0 (6 out of 9) across bel2 (only 7 values) # print("*** Correlation of variable 1 with ideation ****") attach(d) cp = cor(v1,v3, method="pearson") ck = cor(v1,v3, method="kendall") cs = cor(v1,v3, method="spearman") detach(d) # I need better way of printing print("cp= "); print(cp) print("ck= "); print(ck) print("cs= "); print(cs) # correlation of 0.4 : not much relation attach(d) cp = cor(v2,v3, method="pearson") ck = cor(v2,v3, method="kendall") cs = cor(v2,v3, method="spearman") detach(d) # I need better way of printing print("cp= "); print(cp) print("ck= "); print(ck) print("cs= "); print(cs) # correlation of 0.4 : not much relation attach(d) cp = cor(v2,v1, method="pearson") ck = cor(v2,v1, method="kendall") cs = cor(v2,v1, method="spearman") detach(d) # I need better way of printing print("cp= "); print(cp) print("ck= "); print(ck) print("cs= "); print(cs) # correlation of 0.4 : not much relation ##### # What are some other way to determine causality?