#Identifying pertinent variables for nonresponse survey: MoSAiCH #Load the necessary packages library(foreign) library(descr) library(fmsb) library ("Hmisc") library(hexbin) library("psych") library("fmsb") library("lawstat") library(MASS) library("car") library("gmodels") library(survey) #Read the correct file. setwd("I:/Work Caro/Documents/nonresponse surveys/MOSAiCH") sink(file="M11_1.txt",split=T) M11NR<-read.spss("M11 for R.sav",use.missings=T,use.value.labels=T) M11<-as.data.frame(M11NR) #Data cleaning and variables recoding. Recoded variable finishing with M originate from main survey M11$polintr<-M11$Qu1_I M11$polintr[M11$Qu1_I<0|M11$Qu1_I>5]<-NA M11$polintrM<-M11$polint M11$polintrM[M11$polint<0|M11$polint>5]<-NA M11$satdem<-5-M11$Qu2 M11$satdem[M11$Qu2<0|M11$Qu2>4]<-NA M11$satdemM<-M11$CH2 M11$satdemM[M11$CH2<0|M11$CH2>4]<-NA M11$trust<-M11$Qu3 M11$trust[M11$Qu3<0|M11$Qu3>=6]<-NA M11$trustM<-M11$E4a M11$trustM[M11$E4a<0|M11$E4a>6]<-NA M11$envir<-M11$Qu4 M11$envir[M11$Qu4<0|M11$Qu4>=6]<-NA M11$envirM<-M11$E6 M11$envirM[M11$E6<0|M11$E6>6]<-NA M11$trstedu<-6-M11$Qu5_1 M11$trstedu[M11$Qu5_1<0|M11$Qu5_1>=6]<-NA M11$trsteduM<-M11$H2a M11$trsteduM[M11$H2a<0|M11$H2a>=6]<-NA M11$trsthlth<-6-M11$Qu5_2 M11$trsthlth[M11$Qu5_2<0|M11$Qu5_2>=6]<-NA M11$trsthlthM<-M11$H2b M11$trsthlthM[M11$H2b<0|M11$H2b>=6]<-NA M11$immig<-M11$Q6 M11$immig[M11$Q6<0|M11$Q6>=7]<-NA M11$immigM<-M11$CH6_04 M11$immigM[M11$CH6_04<0|M11$CH6_04>7]<-NA M11$science<-6-M11$Q7_1 M11$science[M11$Q7_1<0|M11$Q7_1>=6]<-NA M11$scienceM<-M11$Atos2 M11$scienceM[M11$Atos2<0|M11$Atos2>=6]<-NA M11$survey<-M11$Q7_2_I M11$survey[M11$Q7_2_I<0|M11$Q7_2_I>6]<-NA M11$surveyM<-M11$S1 M11$surveyM[M11$S1<0|M11$S1>6]<-NA M11$health<-M11$Q8_1 M11$health[M11$Q8_1<0|M11$Q8_1>=6]<-NA M11$healthM<-M11$H17b M11$healthM[M11$H17b<0|M11$H17b>6]<-NA M11$happy<-M11$Q8_2 M11$happy[M11$Q8_2<0|M11$Q8_2>6]<-NA M11$happyM<-M11$H17c M11$happyM[M11$H17c<0|M11$H17c>6]<-NA M11$infl<-6-M11$Q9_1 M11$infl[M11$Q9_1<00&M11$Q9_1>=6]<-NA M11$inflM<-M11$D9_02 M11$inflM[M11$D9_02<0|M11$D9_02>6]<-NA M11$prb<-6-M11$Q9_2 M11$prb[M11$Q9_2<0|M11$Q9_2>=6]<-NA M11$prbM<-M11$D9_03 M11$prbM[M11$D9_03<0|M11$D9_03>6]<-NA M11$daytaskM<-M11$Socsup4 M11$daytaskM[M11$Socsup4<0|M11$Socsup4>7]<-NA M11$daytask<-M11$Q10_1 M11$daytask[M11$Q10_1<0|M11$Q10_1>=7]<-NA M11$emotM<-M11$Socsup5 M11$emotM[M11$Socsup5<00|M11$Socsup5>7]<-NA M11$emot<-M11$Q10_2 M11$emot[M11$Q10_2<0|M11$Q10_2>6]<-NA M11$educr<-M11$Q11 M11$educr[M11$Q11<0|M11$Q11>=10]<-NA table(M11$educr) M11$educrM<-M11$D14a_c M11$educrM[M11$D14a_c<0|M11$D14a_c>=10]<-NA M11$work<-NA M11$work[M11$Q12>=0&M11$Q12<2]<-1 M11$work[M11$Q12>=2&M11$Q12<7]<-0 M11$workM<-NA M11$workM[M11$wo>=0&M11$wo<=1]<-1 M11$workM[M11$wo>=2&M11$wo<10]<-0 M11$workhou<-NA M11$workhou[M11$Q13>=0&M11$Q12<36]<-0 M11$workhou[M11$Q13>=36&M11$Q12<101]<-1 M11$workhouM<-NA M11$workhouM[M11$D25v2>=0&M11$D25v2<36]<-0 M11$workhouM[M11$D25v2>=36&M11$D25v2<101]<-1 M11$fix<-NA M11$fix[M11$Q14==1]<-1 M11$fix[M11$Q14==2]<-0 M11$fixM<-NA M11$fixM[M11$Q1==1]<-1 M11$fixM[M11$Q1==2]<-0 M11$mobile<-NA M11$mobile[M11$Q15==1]<-1 M11$mobile[M11$Q15==2]<-0 M11$mobileM<-NA M11$mobileM[M11$Q4==1]<-1 M11$mobileM[M11$Q4==2]<-0 M11$dir<-NA M11$dir[M11$Q14b==1|M11$Q15b==1]<-1 M11$dir[M11$Q14b==2&M11$Q15b<=0]<-0 M11$dir[M11$Q14b==2&M11$Q15b==2]<-0 M11$dir[M11$Q14b==3&M11$Q15b==2]<-0 M11$dirM<-NA M11$dirM[M11$Q3==1|M11$Q5==1]<-1 M11$dirM[M11$Q3==2&M11$Q5<=0]<-0 M11$dirM[M11$Q3==2&M11$Q5==2]<-0 M11$dirM[M11$Q3==3&M11$Q5==2]<-0 M11$alone<-NA M11$alone[M11$Q16==1]<-1 M11$alone[M11$Q16>=2&M11$Q16<=66]<-0 M11$aloneM<-NA M11$aloneM[M11$D18v2==1]<-1 M11$aloneM[M11$D18v2>=2&M11$D18v2<=66]<-0 M11$child<-NA M11$child[M11$Q16b==0]<-0 M11$child[M11$Q16b>=1&M11$Q16b<=66]<-1 M11$childM<-NA M11$childM[M11$ag17b==0]<-0 M11$childM[M11$ag17b>=1&M11$ag17b<=66]<-1 M11$partner<-NA M11$partner[M11$Q17==1]<-1 M11$partner[M11$Q17==2]<-0 M11$partnerM<-NA M11$partnerM[M11$D13b==1|M11$D13b==3]<-1 M11$partnerM[M11$D13b==2]<-0 M11$gndr<-NA M11$gndr[M11$Q18==2]<-0 M11$gndr[M11$Q18==1]<-1 table(M11$gndr) M11$gndrM<-NA M11$gndrM[M11$sex==2]<-0 M11$gndrM[M11$sex==1]<-1 M11$ager<-NA M11$ager<-2011-M11$Q19 M11$ager[M11$Q19<1815|M11$Q19>2021]<-NA M11$agerM<-NA M11$agerM<-2011-M11$ag M11$agerM[M11$ag<1913|M11$ag>2021]<-NA #select the cases for which the respondent answered both survey and sex and year of birth corresponds. nrandmain <- which(M11$nrsurv==1&M11$mainsurv==1) M111<-M11[nrandmain,] table(M111$sex) table(M111$Q18) M111$test<-M111$ager-M111$agerM M111$agetest<-0 M111$agetest[M111$test<=-3|M111$test>=3]<-1 table(M111$agetest) nrandmain1<-which((M111$sex==M111$Q18| M111$Q18 == 3)&M111$agetest==0) M11corr<-M111[nrandmain1,] type<- c("corr","mean") M11corrmean<-as.data.frame(type) #create difference varaibles for mean difference.correlation M11corr$polintrD<-NA M11corr$polintrD<-M11corr$polintr-M11corr$polintrM M11corrmean$polintr[M11corrmean$type=="corr"]<-cor(M11corr$polintr,M11corr$polintrM,"pairwise.complete.obs", method="spearman") M11corrmean$polintr[M11corrmean$type=="mean"]<-mean(M11corr$polintrD, na.rm=TRUE) M11corr$satdemD<-NA M11corr$satdemD<-M11corr$satdem-M11corr$satdemM M11corrmean$satdem[M11corrmean$type=="corr"]<-cor(M11corr$satdem,M11corr$satdemM,"pairwise.complete.obs", method="spearman") M11corrmean$satdem[M11corrmean$type=="mean"]<-mean(M11corr$satdemD, na.rm=TRUE) M11corr$trustD<-NA M11corr$trustD<-M11corr$trust-M11corr$trustM M11corrmean$trust[M11corrmean$type=="corr"]<-cor(M11corr$trust,M11corr$trustM,"pairwise.complete.obs", method="spearman") M11corrmean$trust[M11corrmean$type=="mean"]<-mean(M11corr$trustD, na.rm=TRUE) M11corr$envirD<-NA M11corr$envirD<-M11corr$envir-M11corr$envirM M11corrmean$envir[M11corrmean$type=="corr"]<-cor(M11corr$envir,M11corr$envirM,"pairwise.complete.obs", method="spearman") M11corrmean$envir[M11corrmean$type=="mean"]<-mean(M11corr$envirD, na.rm=TRUE) M11corr$trsteduD<-NA M11corr$trsteduD<-M11corr$trstedu-M11corr$trsteduM M11corrmean$trstedu[M11corrmean$type=="corr"]<-cor(M11corr$trstedu,M11corr$trsteduM,"pairwise.complete.obs", method="spearman") M11corrmean$trstedu[M11corrmean$type=="mean"]<-mean(M11corr$trsteduD, na.rm=TRUE) M11corr$trsthlthD<-NA M11corr$trsthlthD<-M11corr$trsthlth-M11corr$trsthlthM M11corrmean$trsthlth[M11corrmean$type=="corr"]<-cor(M11corr$trsthlth,M11corr$trsthlthM,"pairwise.complete.obs", method="spearman") M11corrmean$trsthlth[M11corrmean$type=="mean"]<-mean(M11corr$trsthlthD, na.rm=TRUE) M11corr$immigD<-NA M11corr$immigD<-M11corr$immig-M11corr$immigM M11corrmean$immig[M11corrmean$type=="corr"]<-cor(M11corr$immig,M11corr$immigM,"pairwise.complete.obs", method="spearman") M11corrmean$immig[M11corrmean$type=="mean"]<-mean(M11corr$immigD, na.rm=TRUE) M11corr$surveyD<-NA M11corr$surveyD<-M11corr$survey-M11corr$surveyM M11corrmean$survey[M11corrmean$type=="corr"]<-cor(M11corr$survey,M11corr$surveyM,"pairwise.complete.obs", method="spearman") M11corrmean$survey[M11corrmean$type=="mean"]<-mean(M11corr$surveyD, na.rm=TRUE) M11corr$scienceD<-NA M11corr$scienceD<-M11corr$science-M11corr$scienceM M11corrmean$science[M11corrmean$type=="corr"]<-cor(M11corr$science,M11corr$scienceM,"pairwise.complete.obs", method="spearman") M11corrmean$science[M11corrmean$type=="mean"]<-mean(M11corr$scienceD, na.rm=TRUE) M11corr$happyD<-NA M11corr$happyD<-M11corr$happy-M11corr$happyM M11corrmean$happy[M11corrmean$type=="corr"]<-cor(M11corr$happy,M11corr$happyM,"pairwise.complete.obs", method="spearman") M11corrmean$happy[M11corrmean$type=="mean"]<-mean(M11corr$happyD, na.rm=TRUE) M11corr$healthD<-NA M11corr$healthD<-M11corr$health-M11corr$healthM M11corrmean$health[M11corrmean$type=="corr"]<-cor(M11corr$health,M11corr$healthM,"pairwise.complete.obs", method="spearman") M11corrmean$health[M11corrmean$type=="mean"]<-mean(M11corr$healthD, na.rm=TRUE) M11corr$inflD<-NA M11corr$inflD<-M11corr$infl-M11corr$inflM M11corrmean$infl[M11corrmean$type=="corr"]<-cor(M11corr$infl,M11corr$inflM,"pairwise.complete.obs", method="spearman") M11corrmean$infl[M11corrmean$type=="mean"]<-mean(M11corr$inflD, na.rm=TRUE) M11corr$prbD<-NA M11corr$prbD<-M11corr$prb-M11corr$prbM M11corrmean$prb[M11corrmean$type=="corr"]<-cor(M11corr$prb,M11corr$prbM,"pairwise.complete.obs", method="spearman") M11corrmean$prb[M11corrmean$type=="mean"]<-mean(M11corr$prbD, na.rm=TRUE) M11corr$daytaskD<-NA M11corr$daytaskD<-M11corr$daytask-M11corr$daytaskM M11corrmean$daytask[M11corrmean$type=="corr"]<-cor(M11corr$daytask,M11corr$daytaskM,"pairwise.complete.obs", method="spearman") M11corrmean$daytask[M11corrmean$type=="mean"]<-mean(M11corr$daytaskD, na.rm=TRUE) M11corr$emotD<-NA M11corr$emotD<-M11corr$emot-M11corr$emotM M11corrmean$emot[M11corrmean$type=="corr"]<-cor(M11corr$emot,M11corr$emotM,"pairwise.complete.obs", method="spearman") M11corrmean$emot[M11corrmean$type=="mean"]<-mean(M11corr$emotD, na.rm=TRUE) M11corr$educrD<-NA M11corr$educrD<-M11corr$educr-M11corr$educrM M11corrmean$educr[M11corrmean$type=="corr"]<-cor(M11corr$educr,M11corr$educrM,"pairwise.complete.obs", method="spearman") M11corrmean$educr[M11corrmean$type=="mean"]<-mean(M11corr$educrD, na.rm=TRUE) table(M11corr$educrD) M11corr$workD<-NA M11corr$workD<-M11corr$work-M11corr$workM table(M11corr$workD) M11corrmean$work[M11corrmean$type=="corr"]<-phi(table(M11corr$work,M11corr$workM)) M11corrmean$work[M11corrmean$type=="mean"]<-mean(M11corr$workD, na.rm=TRUE) M11corr$workhouD<-NA M11corr$workhouD<-M11corr$workhou-M11corr$workhouM M11corrmean$workhou[M11corrmean$type=="corr"]<-phi(table(M11corr$workhou,M11corr$workhouM)) M11corrmean$workhou[M11corrmean$type=="mean"]<-mean(M11corr$workhouD, na.rm=TRUE) M11corr$fixD<-NA M11corr$fixD<-M11corr$fix-M11corr$fixM M11corrmean$fix[M11corrmean$type=="corr"]<-phi(table(M11corr$fix,M11corr$fixM)) M11corrmean$fix[M11corrmean$type=="mean"]<-mean(M11corr$fixD, na.rm=TRUE) M11corr$mobileD<-NA M11corr$mobileD<-M11corr$mobile-M11corr$mobileM M11corrmean$mobile[M11corrmean$type=="corr"]<-phi(table(M11corr$mobile,M11corr$mobileM)) M11corrmean$mobile[M11corrmean$type=="mean"]<-mean(M11corr$mobileD, na.rm=TRUE) M11corr$dirD<-NA M11corr$dirD<-M11corr$dir-M11corr$dirM M11corrmean$dir[M11corrmean$type=="corr"]<-phi(table(M11corr$dir,M11corr$dirM)) M11corrmean$dir[M11corrmean$type=="mean"]<-mean(M11corr$dirD, na.rm=TRUE) M11corr$aloneD<-NA M11corr$aloneD<-M11corr$alone-M11corr$aloneM M11corrmean$alone[M11corrmean$type=="corr"]<-phi(table(M11corr$alone,M11corr$aloneM)) M11corrmean$alone[M11corrmean$type=="mean"]<-mean(M11corr$aloneD, na.rm=TRUE) M11corr$childD<-NA M11corr$childD<-M11corr$child-M11corr$childM M11corrmean$child[M11corrmean$type=="corr"]<-phi(table(M11corr$child,M11corr$childM)) M11corrmean$child[M11corrmean$type=="mean"]<-mean(M11corr$childD, na.rm=TRUE) M11corr$partnerD<-NA M11corr$partnerD<-M11corr$partner-M11corr$partnerM M11corrmean$partner[M11corrmean$type=="corr"]<-phi(table(M11corr$partner,M11corr$partnerM)) M11corrmean$partner[M11corrmean$type=="mean"]<-mean(M11corr$partnerD, na.rm=TRUE) M11corr$gndrD<-NA M11corr$gndrD<-M11corr$gndr-M11corr$gndrM M11corrmean$gndr[M11corrmean$type=="corr"]<-phi(table(M11corr$gndr,M11corr$gndrM)) M11corrmean$gndr[M11corrmean$type=="mean"]<-mean(M11corr$gndrD, na.rm=TRUE) M11corr$agerD<-NA M11corr$agerD<-M11corr$ager-M11corr$agerM M11corrmean$ager[M11corrmean$type=="corr"]<-cor(M11corr$ager,M11corr$agerM,"pairwise.complete.obs", method="spearman") M11corrmean$ager[M11corrmean$type=="mean"]<-mean(M11corr$agerD, na.rm=TRUE) boxplot(M11corr$educrD,M11corr$polintrD,M11corr$immigD,M11corr$trustD,M11corr$emotD,names=c("edu","polint","immig","trust","emot")) #wilcoxon test. symmetry.test(M11corr$polintrD) symmetry.test(M11corr$satdemD) symmetry.test(M11corr$trustD) symmetry.test(M11corr$envirD) symmetry.test(M11corr$trsteduD) symmetry.test(M11corr$trsthlthD) symmetry.test(M11corr$immigD) symmetry.test(M11corr$scienceD) symmetry.test(M11corr$surveyD) symmetry.test(M11corr$happyD) symmetry.test(M11corr$healthD) symmetry.test(M11corr$inflD) symmetry.test(M11corr$prbD) symmetry.test(M11corr$daytaskD) symmetry.test(M11corr$emotD) symmetry.test(M11corr$educrD) wilcox.test(M11corr$polintr, M11corr$polintrM,paired=TRUE) wilcox.test(M11corr$satdem, M11corr$satdemM,paired=TRUE) wilcox.test(M11corr$trust, M11corr$trustM,paired=TRUE) wilcox.test(M11corr$envir, M11corr$envirM,paired=TRUE) wilcox.test(M11corr$trstedu, M11corr$trsteduM,paired=TRUE) wilcox.test(M11corr$trsthlth, M11corr$trsthlthM,paired=TRUE) wilcox.test(M11corr$immig, M11corr$immigM,paired=TRUE) wilcox.test(M11corr$immigr, M11corr$immigM,paired=TRUE) wilcox.test(M11corr$survey, M11corr$surveyM,paired=TRUE) wilcox.test(M11corr$science, M11corr$scienceM,paired=TRUE) wilcox.test(M11corr$happy, M11corr$happyM,paired=TRUE) wilcox.test(M11corr$health, M11corr$healthM,paired=TRUE) wilcox.test(M11corr$infl, M11corr$inflM,paired=TRUE) wilcox.test(M11corr$prb, M11corr$prbM,paired=TRUE) wilcox.test(M11corr$emot, M11corr$emotM,paired=TRUE) wilcox.test(M11corr$daytask, M11corr$daytaskM,paired=TRUE) t.test(M11corr$ager,M11corr$agerM,paired=TRUE) wilcox.test(M11corr$educr, M11corr$educrM,paired=TRUE) table(M11corr$work) table(M11corr$workM) prop.test(matrix(c(63,59,112,116),nrow=2,ncol=2)) table(M11corr$alone) table(M11corr$aloneM) prop.test(matrix(c(149,150,23,25),nrow=2,ncol=2)) table(M11corr$workhou) table(M11corr$workhouM) prop.test(matrix(c(34,41,141,116),nrow=2,ncol=2)) table(M11corr$fix) table(M11corr$fixM) prop.test(matrix(c(19,22,156,153),nrow=2,ncol=2)) table(M11corr$mobile) table(M11corr$mobileM) prop.test(matrix(c(8,15,165,158),nrow=2,ncol=2)) table(M11corr$dir) table(M11corr$dirM) prop.test(matrix(c(24,17,132,138),nrow=2,ncol=2)) table(M11corr$child) table(M11corr$childM) prop.test(matrix(c(105,121,54,54),nrow=2,ncol=2)) table(M11corr$partner) table(M11corr$partnerM) prop.test(matrix(c(4,4,131,132),nrow=2,ncol=2)) #creation of harmonized variable: takes the values of the main survey for respondents and of NRS for nonrespondents.. M11<-M11[order(-M11$mainsurv,-M11$nrsurv),] v1<-M11$gndrM[M11$mainsurv==1] v2<-M11$gndr[M11$mainsurv==0] M11$gndr_h<-c(v1,v2) table(M11$gndr_h) v1<-M11$agerM[M11$mainsurv==1] v2<-M11$ager[M11$mainsurv==0] M11$ager_h<-c(v1,v2) table(M11$ager_h) v1<-M11$educrM[M11$mainsurv==1] v2<-M11$educr[M11$mainsurv==0] M11$educr_h<-c(v1,v2) table(M11$educr_h) v1<-M11$workM[M11$mainsurv==1] v2<-M11$work[M11$mainsurv==0] M11$work_h<-c(v1,v2) table(M11$work_h) v1<-M11$aloneM[M11$mainsurv==1] v2<-M11$alone[M11$mainsurv==0] M11$alone_h<-c(v1,v2) table(M11$alone_h) v1<-M11$inflM[M11$mainsurv==1] v2<-M11$infl[M11$mainsurv==0] M11$infl_h<-c(v1,v2) table(M11$infl_h) v1<-M11$workhouM[M11$mainsurv==1] v2<-M11$workhou[M11$mainsurv==0] M11$workhou_h<-c(v1,v2) table(M11$workhou_h) v1<-M11$trsthlthM[M11$mainsurv==1] v2<-M11$trsthlth[M11$mainsurv==0] M11$trsthlth_h<-c(v1,v2) table(M11$trsthlth_h) v1<-M11$envirM[M11$mainsurv==1] v2<-M11$envir[M11$mainsurv==0] M11$envir_h<-c(v1,v2) table(M11$envir_h) v1<-M11$trustM[M11$mainsurv==1] v2<-M11$trust[M11$mainsurv==0] M11$trust_h<-c(v1,v2) table(M11$trust_h) v1<-M11$polintrM[M11$mainsurv==1] v2<-M11$polintr[M11$mainsurv==0] M11$polintr_h<-c(v1,v2) table(M11$polintr_h) v1<-M11$satdemM[M11$mainsurv==1] v2<-M11$satdem[M11$mainsurv==0] M11$satdem_h<-c(v1,v2) table(M11$satdem_h) v1<-M11$trsteduM[M11$mainsurv==1] v2<-M11$trstedu[M11$mainsurv==0] M11$trstedu_h<-c(v1,v2) table(M11$trstedu) v1<-M11$immigM[M11$mainsurv==1] v2<-M11$immig[M11$mainsurv==0] M11$immig_h<-c(v1,v2) table(M11$immig_h) v1<-M11$immigrM[M11$mainsurv==1] v2<-M11$immigr[M11$mainsurv==0] M11$immigr_h<-c(v1,v2) table(M11$immigr_h) v1<-M11$scienceM[M11$mainsurv==1] v2<-M11$science[M11$mainsurv==0] M11$science_h<-c(v1,v2) table(M11$science_h) v1<-M11$surveyM[M11$mainsurv==1] v2<-M11$survey[M11$mainsurv==0] M11$survey_h<-c(v1,v2) table(M11$survey_h) v1<-M11$healthM[M11$mainsurv==1] v2<-M11$health[M11$mainsurv==0] M11$health_h<-c(v1,v2) table(M11$health_h) v1<-M11$happyM[M11$mainsurv==1] v2<-M11$happy[M11$mainsurv==0] M11$happy_h<-c(v1,v2) table(M11$happy_h) v1<-M11$prbM[M11$mainsurv==1] v2<-M11$prb[M11$mainsurv==0] M11$prob_h<-c(v1,v2) table(M11$prob_h) v1<-M11$daytaskM[M11$mainsurv==1] v2<-M11$daytask[M11$mainsurv==0] M11$daytask_h<-c(v1,v2) table(M11$daytask_h) v1<-M11$emotM[M11$mainsurv==1] v2<-M11$emot[M11$mainsurv==0] M11$emot_h<-c(v1,v2) table(M11$emot_h) v1<-M11$fixM[M11$mainsurv==1] v2<-M11$fix[M11$mainsurv==0] M11$fix_h<-c(v1,v2) table(M11$fix_h) v1<-M11$mobileM[M11$mainsurv==1] v2<-M11$mobile[M11$mainsurv==0] M11$mobile_h<-c(v1,v2) table(M11$mobile_h) v1<-M11$dirM[M11$mainsurv==1] v2<-M11$dir[M11$mainsurv==0] M11$dir_h<-c(v1,v2) table(M11$dir_h) M11$dir_h[M11$fix_h==0&M11$mobile_h==0]<-0 v1<-M11$childM[M11$mainsurv==1] v2<-M11$child[M11$mainsurv==0] M11$child_h<-c(v1,v2) table(M11$child_h) v1<-M11$partnerM[M11$mainsurv==1] v2<-M11$partner[M11$mainsurv==0] M11$partner_h<-c(v1,v2) table(M11$partner_h) v1<-M11$polintrM[M11$mainsurv==1] v2<-M11$polintr[M11$mainsurv==0] M11$polintr_h<-c(v1,v2) table(M11$polintr_h) v1<-M11$satdemM[M11$mainsurv==1] v2<-M11$satdem[M11$mainsurv==0] M11$satdem_h<-c(v1,v2) table(M11$satdem_h) v1<-M11$trustM[M11$mainsurv==1] v2<-M11$trust[M11$mainsurv==0] M11$trust_h<-c(v1,v2) table(M11$trust_h) v1<-M11$envirM[M11$mainsurv==1] v2<-M11$envir[M11$mainsurv==0] M11$envir_h<-c(v1,v2) table(M11$envir_h) v1<-M11$trsteduM[M11$mainsurv==1] v2<-M11$trstedu[M11$mainsurv==0] M11$trstedu_h<-c(v1,v2) table(M11$trstedu_h) v1<-M11$trsthlthM[M11$mainsurv==1] v2<-M11$trsthlth[M11$mainsurv==0] M11$trsthlth_h<-c(v1,v2) table(M11$trsthlth_h) v1<-M11$prbM[M11$mainsurv==1] v2<-M11$prb[M11$mainsurv==0] M11$prb_h<-c(v1,v2) table(M11$prb_h) M11$agecat<-NA M11$agecat[M11$ager_h<30]<-1 M11$agecat[M11$ager_h>=30&M11$ager<=65]<-2 M11$agecat[M11$ager_h>65]<-3 M11$educat<-NA M11$educat[M11$educr_h<=2]<-0 M11$educat[M11$educr_h>2]<-1 table(M11$educr_h, M11$mainsurv) #compare the distrubutions for respondents and not respondents. crosstab(M11$gndr_h,M11$mainsurv,prop.c=T,chisq=T) crosstab(M11$agecat,M11$mainsurv,prop.c=T,chisq=T) crosstab(M11$educat,M11$mainsurv,prop.c=T,chisq=T) crosstab(M11$work_h,M11$mainsurv,prop.c=T,chisq=T) crosstab(M11$alone_h,M11$mainsurv,prop.c=T,chisq=T) crosstab(M11$workhou_h,M11$mainsurv,prop.c=T,chisq=T) crosstab(M11$partner_h,M11$mainsurv,prop.c=T,chisq=T) crosstab(M11$child_h,M11$mainsurv,prop.c=T,chisq=T) crosstab(M11$trust_h,M11$mainsurv,prop.c=T,chisq=T) crosstab(M11$envir_h,M11$mainsurv,prop.c=T,chisq=T) crosstab(M11$trsthlth_h,M11$mainsurv,prop.c=T,chisq=T) crosstab(M11$fix_h,M11$mainsurv,prop.c=T,chisq=T) crosstab(M11$dir_h,M11$mainsurv,prop.c=T,chisq=T) crosstab(M11$emot_h,M11$mainsurv,prop.c=T,chisq=T) #review M11NR<-M11[which(M11$nrsurv==1),] M11NR<-M11NR[which(!is.na(M11NR$ager)&!is.na(M11NR$gndr)&!is.na(M11NR$educr)&!is.na(M11NR$work)&!is.na(M11NR$alone)&!is.na(M11NR$satdem) &!is.na(M11NR$trust)&!is.na(M11NR$envir)&!is.na(M11NR$trstedu)&!is.na(M11NR$trsthlth)&!is.na(M11NR$immig)&!is.na(M11NR$science) &!is.na(M11NR$survey)&!is.na(M11NR$health)&!is.na(M11NR$happy)&!is.na(M11NR$infl)&!is.na(M11NR$prb)&!is.na(M11NR$daytask) &!is.na(M11NR$child)&!is.na(M11NR$partner)&!is.na(M11NR$emot)&!is.na(M11NR$dir)&!is.na(M11NR$fix)&!is.na(M11NR$mobile) &!is.na(M11NR$workhou) &!is.na(M11NR$polintr)),] M11NR$NR<-1 M11NR$NR[M11NR$mainsurv==1]<-0 table(M11NR$NR) M11review<-glm(NR~ager+gndr+educr+work+alone+satdem+trust+envir+trstedu+trsthlth+immig+science+survey+health+happy+infl+prb+daytask+child+partner +emot+workhou+fix+mobile+dir+polintr,data=M11NR,family=binomial) summary(M11review) NagelkerkeR2(M11review) M11NR$propscore<-predict(M11review, type="response") M11NR$propweight<-1/M11NR$propscore type<- c("RUmean","RWmean", "NRmean") M11r<-as.data.frame(type) M11NRNR<-M11NR[which(M11NR$NR==1),] M11r$polintr[M11r$type=="RUmean"]<-mean(M11NR$polintrM, na.rm=TRUE) M11r$polintr[M11r$type=="RWmean"]<-weighted.mean(M11NR$polintrM,M11NR$propweight, na.rm=TRUE) M11r$polintr[M11r$type=="NRmean"]<-mean(M11NR$polintr, na.rm=TRUE) M11r$satdem[M11r$type=="RUmean"]<-mean(M11NR$satdemM, na.rm=TRUE) M11r$satdem[M11r$type=="RWmean"]<-weighted.mean(M11NR$satdemM,M11NR$propweight, na.rm=TRUE) M11r$satdem[M11r$type=="NRmean"]<-mean(M11NR$satdem, na.rm=TRUE) M11r$immig[M11r$type=="RUmean"]<-mean(M11NR$immigM, na.rm=TRUE) M11r$immig[M11r$type=="RWmean"]<-weighted.mean(M11NR$immigM,M11NR$propweight, na.rm=TRUE) M11r$immig[M11r$type=="NRmean"]<-mean(M11NR$immig, na.rm=TRUE) M11r$trust[M11r$type=="RUmean"]<-mean(M11NR$trustM, na.rm=TRUE) M11r$trust[M11r$type=="RWmean"]<-weighted.mean(M11NR$trustM,M11NR$propweight, na.rm=TRUE) M11r$trust[M11r$type=="NRmean"]<-mean(M11NR$trust, na.rm=TRUE) M11r$envir[M11r$type=="RUmean"]<-mean(M11NR$envirM, na.rm=TRUE) M11r$envir[M11r$type=="RWmean"]<-weighted.mean(M11NR$envirM,M11NR$propweight, na.rm=TRUE) M11r$envir[M11r$type=="NRmean"]<-mean(M11NR$envir, na.rm=TRUE) M11r$trstedu[M11r$type=="RUmean"]<-mean(M11NR$trsteduM, na.rm=TRUE) M11r$trstedu[M11r$type=="RWmean"]<-weighted.mean(M11NR$trsteduM,M11NR$propweight, na.rm=TRUE) M11r$trstedu[M11r$type=="NRmean"]<-mean(M11NR$trstedu, na.rm=TRUE) M11r$trsthlth[M11r$type=="RUmean"]<-mean(M11NR$trsthlthM, na.rm=TRUE) M11r$trsthlth[M11r$type=="RWmean"]<-weighted.mean(M11NR$trsthlthM,M11NR$propweight, na.rm=TRUE) M11r$trsthlth[M11r$type=="NRmean"]<-mean(M11NR$trsthlth, na.rm=TRUE) M11r$science[M11r$type=="RUmean"]<-mean(M11NR$scienceM, na.rm=TRUE) M11r$science[M11r$type=="RWmean"]<-weighted.mean(M11NR$scienceM,M11NR$propweight, na.rm=TRUE) M11r$science[M11r$type=="NRmean"]<-mean(M11NR$science, na.rm=TRUE) M11r$survey[M11r$type=="RUmean"]<-mean(M11NR$surveyM, na.rm=TRUE) M11r$survey[M11r$type=="RWmean"]<-weighted.mean(M11NR$surveyM,M11NR$propweight, na.rm=TRUE) M11r$survey[M11r$type=="NRmean"]<-mean(M11NR$survey, na.rm=TRUE) M11r$health[M11r$type=="RUmean"]<-mean(M11NR$healthM, na.rm=TRUE) M11r$health[M11r$type=="RWmean"]<-weighted.mean(M11NR$healthM,M11NR$propweight, na.rm=TRUE) M11r$health[M11r$type=="NRmean"]<-mean(M11NR$health, na.rm=TRUE) M11r$happy[M11r$type=="RUmean"]<-mean(M11NR$happyM, na.rm=TRUE) M11r$happy[M11r$type=="RWmean"]<-weighted.mean(M11NR$happyM,M11NR$propweight, na.rm=TRUE) M11r$happy[M11r$type=="NRmean"]<-mean(M11NR$happy, na.rm=TRUE) M11r$infl[M11r$type=="RUmean"]<-mean(M11NR$inflM, na.rm=TRUE) M11r$infl[M11r$type=="RWmean"]<-weighted.mean(M11NR$inflM,M11NR$propweight, na.rm=TRUE) M11r$infl[M11r$type=="NRmean"]<-mean(M11NR$infl, na.rm=TRUE) M11r$prb[M11r$type=="RUmean"]<-mean(M11NR$prbM, na.rm=TRUE) M11r$prb[M11r$type=="RWmean"]<-weighted.mean(M11NR$prbM,M11NR$propweight, na.rm=TRUE) M11r$prb[M11r$type=="NRmean"]<-mean(M11NR$prb, na.rm=TRUE) M11r$daytask[M11r$type=="RUmean"]<-mean(M11NR$daytaskM, na.rm=TRUE) M11r$daytask[M11r$type=="RWmean"]<-weighted.mean(M11NR$daytaskM,M11NR$propweight, na.rm=TRUE) M11r$daytask[M11r$type=="NRmean"]<-mean(M11NR$daytask, na.rm=TRUE) M11r$emot[M11r$type=="RUmean"]<-mean(M11NR$emotM, na.rm=TRUE) M11r$emot[M11r$type=="RWmean"]<-weighted.mean(M11NR$emotM,M11NR$propweight, na.rm=TRUE) M11r$emot[M11r$type=="NRmean"]<-mean(M11NR$emot, na.rm=TRUE) write.table(M11r,file= "M11r.txt",sep="\t") #significance #create the right dataset M11bothw<-M11NR[which(M11NR$mainsurv==1),] M11bothw$propweight2<-M11bothw$propweight M11bothw$type<-1 M11bothw$type2<-1 M11bothnw<-M11bothw M11bothnw$propweight<-1 M11bothnw$propweight2<-0 M11bothnw$type<-0 M11bothnw$type2<-NA M11NRnw<-M11NR M11NRnw$propweight<-0 M11NRnw$propweight2<-1 M11NRnw$type<-NA M11NRnw$type2<-0 M11sign<-rbind(M11bothw,M11bothnw,M11NRnw) library(survey) design1<-svydesign(ids=~1,weights=M11sign$propweight, data=M11sign) svychisq(~type+polintr_h, design = design1, statistic = "F") svychisq(~type+trust_h, design = design1, statistic = "F") svychisq(~type+envir_h, design = design1, statistic = "F") svychisq(~type+trstedu_h, design = design1, statistic = "F") svychisq(~type+trsthlth_h, design = design1, statistic = "F") svychisq(~type+immig_h, design = design1, statistic = "F") svychisq(~type+science_h, design = design1, statistic = "F") svychisq(~type+survey_h, design = design1, statistic = "F") svychisq(~type+health_h, design = design1, statistic = "F") svychisq(~type+happy_h, design = design1, statistic = "F") svychisq(~type+infl_h, design = design1, statistic = "F") svychisq(~type+prb_h, design = design1, statistic = "F") svychisq(~type+daytask_h, design = design1, statistic = "F") svychisq(~type+emot_h, design = design1, statistic = "F") #all p-value above .95 design2<-svydesign(ids=~1,weights=M11sign$propweight2, data=M11sign) svychisq(~type2+polintr_h, design = design2, statistic = "F") svychisq(~type2+trust_h, design = design2, statistic = "F") svychisq(~type2+envir_h, design = design2, statistic = "F") svychisq(~type2+trstedu_h, design = design2, statistic = "F") svychisq(~type2+trsthlth_h, design = design2, statistic = "F") svychisq(~type2+immig_h, design = design2, statistic = "F") svychisq(~type2+science_h, design = design2, statistic = "F") svychisq(~type2+survey_h, design = design2, statistic = "F") svychisq(~type2+health_h, design = design2, statistic = "F") svychisq(~type2+happy_h, design = design2, statistic = "F") svychisq(~type2+infl_h, design = design2, statistic = "F") svychisq(~type2+prb_h, design = design2, statistic = "F") svychisq(~type2+daytask_h, design = design2, statistic = "F") svychisq(~type2+emot_h, design = design2, statistic = "F") table(M11sign$polintr_h)