#Identifying pertinent variables for nonresponse survey: EVS 2008 #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/EVS") sink(file="EV08_1.txt",split=T) EV8NR<-read.spss("EV08 for R.sav",use.missings=T,use.value.labels=T) EV8<-as.data.frame(EV8NR) #Data cleaning and variables recoding. Recoded variable finishing with M originate from main survey EV8$f1_0[EV8$f1_0<0&EV8$f1_0>5]<-NA EV8$v1[EV8$v1<0&EV8$v1>5]<-NA EV8$f1_1[EV8$f1_1<0&EV8$f1_1>5]<-NA EV8$v2[EV8$v2<0&EV8$v2>5]<-NA EV8$f1_2[EV8$f1_2<0&EV8$f1_2>5]<-NA EV8$v3[EV8$v3<0&EV8$v3>5]<-NA EV8$f1_3[EV8$f1_3<0&EV8$f1_3>5]<-NA EV8$v4[EV8$v4<0&EV8$v4>5]<-NA EV8$f1_4[EV8$f1_4<0&EV8$f1_4>5]<-NA EV8$v5[EV8$v5<0&EV8$v5>5]<-NA EV8$f1_5[EV8$f1_5<0&EV8$vf1_5>5]<-NA EV8$v6[EV8$v6<0&EV8$v6>5]<-NA EV8$f2[EV8$f2<0&EV8$f2>5]<-NA EV8$v63[EV8$v63<0&EV8$v63>5]<-NA EV8$f3_0[EV8$f3_0<0&EV8$f3_0>5]<-NA EV8$v275[EV8$v275<0&EV8$v275>5]<-NA EV8$f3_0_r[EV8$f3_0_r<0&EV8$f3_0_r>5]<-NA EV8$v2275_r[EV8$v2275_r<0&EV8$v2275_r>5]<-NA EV8$f3_1[EV8$f3_1<0&EV8$f3_1>5]<-NA EV8$v282[EV8$v282<0&EV8$v282>5]<-NA EV8$f3_2[EV8$f3_2<0&EV8$f3_2>5]<-NA EV8$v283[EV8$v283<0&EV8$v283>5]<-NA EV8$group<-NA EV8$group[EV8$f4_0==1|EV8$f4_1==1|EV8$f4_2==1|EV8$f4_3==1|EV8$f4_4==1|EV8$f4_5==1|EV8$f4_6==1|EV8$f4_7==1|EV8$f4_8==1|EV8$f4_9==1|EV8$f4_10==1|EV8$f4_11==1| EV8$f4_12==1|EV8$f4_13==1|EV8$f4_14==1]<-1 EV8$group[EV8$f4_0==2&EV8$f4_1==2&EV8$f4_2==2&EV8$f4_3==2&EV8$f4_4==2&EV8$f4_5==2&EV8$f4_6==2&EV8$f4_7==2&EV8$f4_8==2&EV8$f4_9==2&EV8$f4_10==2&EV8$f4_11==2& EV8$f4_12==2&EV8$f4_13==2&EV8$f4_14==2]<-0 table(EV8$group) EV8$groupM<-NA EV8$groupM[EV8$v10==1|EV8$v11==1|EV8$v12==1|EV8$v13==1|EV8$v14==1|EV8$v15==1|EV8$v16==1|EV8$v17==1|EV8$v18==1|EV8$v19==1|EV8$v20==1|EV8$v21==1| EV8$v22==1|EV8$v23==1|EV8$v24==1]<-1 EV8$groupM[EV8$v10==2&EV8$v11==2&EV8$v12==2&EV8$v13==2&EV8$v14==2&EV8$v15==2&EV8$v16==2&EV8$v17==2&EV8$v18==2&EV8$v19==2&EV8$v20==2&EV8$v21==2& EV8$v22==2&EV8$v23==2&EV8$v24==2]<-0 table(EV8$groupM) EV8$f5[EV8$f5<0&EV8$f5>5]<-NA EV8$v186[EV8$v186<0&EV8$v186>5]<-NA EV8$ager<-NA EV8$ager<-108-EV8$f7 EV8$ager[EV8$f7<15&EV8$f7>99]<-NA table(EV8$ager) EV8$agerM<-NA EV8$agerM<-108-EV8$v303 EV8$agerM[EV8$v303<15&EV8$v303>99]<-0 table(EV8$agerM) EV8$gndr<-NA EV8$gndr[EV8$f8==2]<-0 EV8$gndr[EV8$f8==1]<-1 table(EV8$gndr) EV8$gndrM<-NA EV8$gndrM[EV8$v302==2]<-0 EV8$gndrM[EV8$v302==1]<-1 table(EV8$gndrM) EV8$edu<-NA EV8$edu[EV8$f9tp_0==1|EV8$f9tp_1==1|EV8$f9tp_2==1|EV8$f9tp_3==1|EV8$f9tp_12==1|EV8$f9tp_4==1|EV8$f9tp_5==1|EV8$f9tp_6==1|EV8$f9tp_7==1|EV8$f9tp_8==1| EV8$f9tp_9==1|EV8$f9tp_10==1|EV8$f9tp_11==1]<-2 EV8$edu[EV8$f9tp_0==2|EV8$f9tp_1==2|EV8$f9tp_2==2|EV8$f9tp_3==2|EV8$f9tp_12==2|EV8$f9tp_4==2|EV8$f9tp_5==2|EV8$f9tp_6==2|EV8$f9tp_7==2|EV8$f9tp_8==2 |EV8$f9tp_9==2|EV8$f9tp_10==2|EV8$f9tp_11==2]<-3 EV8$edu[EV8$f9tp_0==3|EV8$f9tp_1==3|EV8$f9tp_2==3|EV8$f9tp_3==3|EV8$f9tp_12==3|EV8$f9tp_4==3|EV8$f9tp_5==3|EV8$f9tp_6==3|EV8$f9tp_7==3|EV8$f9tp_8==3 |EV8$f9tp_9==3|EV8$f9tp_10==3|EV8$f9tp_11==3]<-6 EV8$edu[EV8$f9tp_0==4|EV8$f9tp_1==4|EV8$f9tp_2==4|EV8$f9tp_3==4|EV8$f9tp_12==4|EV8$f9tp_4==4|EV8$f9tp_5==4|EV8$f9tp_6==4|EV8$f9tp_7==4|EV8$f9tp_8==4 |EV8$f9tp_9==4|EV8$f9tp_10==4|EV8$f9tp_11==4]<-4 EV8$edu[EV8$f9tp_0==5|EV8$f9tp_1==5|EV8$f9tp_2==5|EV8$f9tp_3==5|EV8$f9tp_12==5|EV8$f9tp_4==5|EV8$f9tp_5==5|EV8$f9tp_6==5|EV8$f9tp_7==5|EV8$f9tp_8==5 |EV8$f9tp_9==5|EV8$f9tp_10==5|EV8$f9tp_11==5]<-5 EV8$edu[EV8$f9tp_0==6|EV8$f9tp_1==6|EV8$f9tp_2==6|EV8$f9tp_3==6|EV8$f9tp_12==6|EV8$f9tp_4==6|EV8$f9tp_5==6|EV8$f9tp_6==6|EV8$f9tp_7==6|EV8$f9tp_8==6 |EV8$f9tp_9==6|EV8$f9tp_10==6|EV8$f9tp_11==6]<-9 EV8$edu[EV8$f9tp_0==7|EV8$f9tp_1==7|EV8$f9tp_2==7|EV8$f9tp_3==7|EV8$f9tp_12==7|EV8$f9tp_4==7|EV8$f9tp_5==7|EV8$f9tp_6==7|EV8$f9tp_7==7|EV8$f9tp_8==7 |EV8$f9tp_9==7|EV8$f9tp_10==7|EV8$f9tp_11==7]<-12 EV8$edu[EV8$f9tp_0==8|EV8$f9tp_1==8|EV8$f9tp_2==8|EV8$f9tp_3==8|EV8$f9tp_12==8|EV8$f9tp_4==8|EV8$f9tp_5==8|EV8$f9tp_6==8|EV8$f9tp_7==8|EV8$f9tp_8==8 |EV8$f9tp_9==8|EV8$f9tp_10==8|EV8$f9tp_11==8]<-7 EV8$edu[EV8$f9tp_0==9|EV8$f9tp_1==9|EV8$f9tp_2==9|EV8$f9tp_3==9|EV8$f9tp_12==9|EV8$f9tp_4==9|EV8$f9tp_5==9|EV8$f9tp_6==9|EV8$f9tp_7==9|EV8$f9tp_8==9 |EV8$f9tp_9==9|EV8$f9tp_10==9|EV8$f9tp_11==9]<-8 EV8$edu[EV8$f9tp_0==10|EV8$f9tp_1==10|EV8$f9tp_2==10|EV8$f9tp_3==10|EV8$f9tp_12==10|EV8$f9tp_4==10|EV8$f9tp_5==10|EV8$f9tp_6==10|EV8$f9tp_7==10|EV8$f9tp_8==10 |EV8$f9tp_9==10|EV8$f9tp_10==10|EV8$f9tp_11==10]<-10 EV8$edu[EV8$f9tp_0==11|EV8$f9tp_1==11|EV8$f9tp_2==11|EV8$f9tp_3==11|EV8$f9tp_12==11|EV8$f9tp_4==11|EV8$f9tp_5==11|EV8$f9tp_6==11|EV8$f9tp_7==11|EV8$f9tp_8==11 |EV8$f9tp_9==11|EV8$f9tp_10==11|EV8$f9tp_11==11]<-11 EV8$edu[EV8$f9tp_0==13|EV8$f9tp_1==12|EV8$f9tp_2==12|EV8$f9tp_3==12|EV8$f9tp_12==12|EV8$f9tp_4==12|EV8$f9tp_5==12|EV8$f9tp_6==12|EV8$f9tp_7==12|EV8$f9tp_8==12 |EV8$f9tp_9==12|EV8$f9tp_10==12|EV8$f9tp_11==12]<-13 EV8$edu[EV8$f9tp_0==13|EV8$f9tp_1==13|EV8$f9tp_2==13|EV8$f9tp_3==13|EV8$f9tp_12==13|EV8$f9tp_4==13|EV8$f9tp_5==13|EV8$f9tp_6==13|EV8$f9tp_7==13|EV8$f9tp_8==13 |EV8$f9tp_9==13|EV8$f9tp_10==13|EV8$f9tp_11==13]<-14 EV8$edu[EV8$f9tp_0==14|EV8$f9tp_1==14|EV8$f9tp_2==14|EV8$f9tp_3==14|EV8$f9tp_12==14|EV8$f9tp_4==14|EV8$f9tp_5==14|EV8$f9tp_6==14|EV8$f9tp_7==14|EV8$f9tp_8==14 |EV8$f9tp_9==14|EV8$f9tp_10==14|EV8$f9tp_11==14]<-15 EV8$edu[EV8$f9tp_0==15|EV8$f9tp_1==15|EV8$f9tp_2==15|EV8$f9tp_3==15|EV8$f9tp_12==15|EV8$f9tp_4==15|EV8$f9tp_5==15|EV8$f9tp_6==15|EV8$f9tp_7==15|EV8$f9tp_8==15 |EV8$f9tp_9==15|EV8$f9tp_10==15|EV8$f9tp_11==15]<-16 EV8$edu[EV8$f9tp_0==16|EV8$f9tp_1==16|EV8$f9tp_2==16|EV8$f9tp_3==16|EV8$f9tp_12==16|EV8$f9tp_4==16|EV8$f9tp_5==16|EV8$f9tp_6==16|EV8$f9tp_7==16|EV8$f9tp_8==16 |EV8$f9tp_9==16|EV8$f9tp_10==16|EV8$f9tp_11==16]<-17 table(EV8$edu) EV8$eduM<-EV8$v336 EV8$eduM[EV8$v336<1&EV8$v336>=18]<-NA table(EV8$eduM) EV8$work<-NA EV8$work[(EV8$f10tp_0>=1&EV8$f10tp_0<=10)|(EV8$f10tp_1>=1&EV8$f10tp_1<=10)|(EV8$f10tp_2>=1&EV8$f9tp_2<=10)| (EV8$f10tp_3>=1&EV8$f10tp_3<=10)|(EV8$f10tp_4>=1&EV8$f10tp_4<=10)]<-0 EV8$work[(EV8$f10tp_0>=1&EV8$f10tp_0<=4)|(EV8$f10tp_1>=1&EV8$f10tp_1<=4)|(EV8$f10tp_2>=1&EV8$f9tp_2<=4)| (EV8$f10tp_3>=1&EV8$f10tp_3<=4)|(EV8$f10tp_4>=1&EV8$f10tp_4<=4)]<-1 table(EV8$work) EV8$workM<-NA EV8$workM[EV8$v337>=1&EV8$v337<5]<-1 EV8$workM[EV8$v337>=5&EV8$v337<=10]<-0 table(EV8$workM) EV8$alone<-NA EV8$alone[EV8$f11==1]<-1 EV8$alone[EV8$f11>1]<-0 table(EV8$alone) EV8$aloneM<-NA EV8$aloneM[EV8$v323==1|EV8$v324a==1|EV8$v325a==1|EV8$v326a==1]<-0 EV8$aloneM[EV8$v323==2&EV8$v324a==2&EV8$v325a==2&EV8$v326a==2]<-1 table(EV8$aloneM) #select the cases for which the respondent answered both survey and sex and year of birth corresponds. nrandmain <- which(EV8$nrsurv==1&EV8$mainsurv==1) EV81<-EV8[nrandmain,] table(EV81$f8) table(EV81$v302) EV81$f8b<-0 EV81$f8b[EV81$f8==1]<-1 EV81$f8b[EV81$f8==2]<-2 EV81$test<-EV81$ager-EV81$agerM EV81$agetest<-0 EV81$agetest[EV81$test<=-3|EV81$test>=3]<-1 nrandmain1<-which((EV81$f8==EV81$v302| EV81$f8 == 3|EV81$f8b==0)&EV81$agetest==0) EV8corr<-EV81[nrandmain1,] type<- c("corr","diff") EV8corrmean<-as.data.frame(type) EV8corrmean$polintr[EV8corrmean$type=="corr"]<-cor(EV8corr$f5,EV8corr$v186,"pairwise.complete.obs", method="spearman") EV8corrmean$impwork[EV8corrmean$type=="corr"]<-cor(EV8corr$f1_0,EV8corr$v1,"pairwise.complete.obs", method="spearman") EV8corrmean$impfami[EV8corrmean$type=="corr"]<-cor(EV8corr$f1_1,EV8corr$v2,"pairwise.complete.obs", method="spearman") EV8corrmean$impfrie[EV8corrmean$type=="corr"]<-cor(EV8corr$f1_2,EV8corr$v3,"pairwise.complete.obs", method="spearman") EV8corrmean$impleas[EV8corrmean$type=="corr"]<-cor(EV8corr$f1_3,EV8corr$v4,"pairwise.complete.obs", method="spearman") EV8corrmean$imppol[EV8corrmean$type=="corr"]<-cor(EV8corr$f1_4,EV8corr$v5,"pairwise.complete.obs", method="spearman") EV8corrmean$imprel[EV8corrmean$type=="corr"]<-cor(EV8corr$f1_5,EV8corr$v6,"pairwise.complete.obs", method="spearman") EV8corrmean$trust[EV8corrmean$type=="corr"]<-cor(EV8corr$f2,EV8corr$v63,"pairwise.complete.obs", method="spearman") EV8corrmean$immig[EV8corrmean$type=="corr"]<-cor(EV8corr$f3_0,EV8corr$v275,"pairwise.complete.obs", method="spearman") EV8corrmean$just[EV8corrmean$type=="corr"]<-cor(EV8corr$f3_1,EV8corr$v282,"pairwise.complete.obs", method="spearman") EV8corrmean$stick[EV8corrmean$type=="corr"]<-cor(EV8corr$f3_2,EV8corr$v283,"pairwise.complete.obs", method="spearman") EV8corrmean$group[EV8corrmean$type=="corr"]<-phi(table(EV8corr$group,EV8corr$groupM)) EV8corrmean$alone[EV8corrmean$type=="corr"]<-phi(table(EV8corr$alone,EV8corr$aloneM)) EV8corrmean$ager[EV8corrmean$type=="corr"]<-cor(EV8corr$ager,EV8corr$agerM,"pairwise.complete.obs", method="pearson") EV8corrmean$edu[EV8corrmean$type=="corr"]<-cor(EV8corr$edu,EV8corr$eduM,"pairwise.complete.obs", method="spearman") EV8corrmean$work[EV8corrmean$type=="corr"]<-phi(table(EV8corr$work,EV8corr$workM)) #create difference varaibles for mean EV8corr$polintrD<-NA EV8corr$polintrD<-EV8corr$f5-EV8corr$v186 EV8corrmean$polintr[EV8corrmean$type=="diff"]<-mean(EV8corr$polintrD, na.rm=TRUE) EV8corr$impworkD<-NA EV8corr$impworkD<-EV8corr$f1_0-EV8corr$v1 EV8corrmean$impwork[EV8corrmean$type=="diff"]<-mean(EV8corr$impworkD, na.rm=TRUE) EV8corr$impfamiD<-NA EV8corr$impfamiD<-EV8corr$f1_1-EV8corr$v2 EV8corrmean$impfami[EV8corrmean$type=="diff"]<-mean(EV8corr$impfamiD, na.rm=TRUE) EV8corr$impfrieD<-NA EV8corr$impfrieD<-EV8corr$f1_2-EV8corr$v3 EV8corrmean$impfrie[EV8corrmean$type=="diff"]<-mean(EV8corr$impfrieD, na.rm=TRUE) EV8corr$impleasD<-NA EV8corr$impleasD<-EV8corr$f1_3-EV8corr$v4 EV8corrmean$impleas[EV8corrmean$type=="diff"]<-mean(EV8corr$impleasD, na.rm=TRUE) EV8corr$imppolD<-NA EV8corr$imppolD<-EV8corr$f1_4-EV8corr$v5 EV8corrmean$imppol[EV8corrmean$type=="diff"]<-mean(EV8corr$imppolD, na.rm=TRUE) EV8corr$imprelD<-NA EV8corr$imprelD<-EV8corr$f1_5-EV8corr$v6 EV8corrmean$imprel[EV8corrmean$type=="diff"]<-mean(EV8corr$imprelD, na.rm=TRUE) EV8corr$trustD<-NA EV8corr$trustD<-EV8corr$f2-EV8corr$v63 EV8corrmean$trust[EV8corrmean$type=="diff"]<-mean(EV8corr$trustD, na.rm=TRUE) EV8corr$immigD<-NA EV8corr$immigD<-EV8corr$f3_0-EV8corr$v275 EV8corrmean$immig[EV8corrmean$type=="diff"]<-mean(EV8corr$immigD, na.rm=TRUE) median(EV8corr$immigD, na.rm=TRUE) EV8corr$justD<-NA EV8corr$justD<-EV8corr$f3_1-EV8corr$v282 EV8corrmean$just[EV8corrmean$type=="diff"]<-mean(EV8corr$justD, na.rm=TRUE) EV8corr$stickD<-NA EV8corr$stickD<-EV8corr$f3_2-EV8corr$v283 EV8corrmean$stick[EV8corrmean$type=="diff"]<-mean(EV8corr$stickD, na.rm=TRUE) EV8corr$groupD<-NA EV8corr$groupD<-EV8corr$group-EV8corr$groupM EV8corrmean$group[EV8corrmean$type=="diff"]<-mean(EV8corr$groupD, na.rm=TRUE) EV8corr$agerD<-NA EV8corr$agerD<-EV8corr$ager-EV8corr$agerM EV8corrmean$ager[EV8corrmean$type=="diff"]<-mean(EV8corr$agerD, na.rm=TRUE) EV8corr$gndrD<-NA EV8corr$gndrD<-EV8corr$gndr-EV8corr$gndrM EV8corrmean$gndr[EV8corrmean$type=="diff"]<-mean(EV8corr$gndrD, na.rm=TRUE) EV8corr$eduD<-NA EV8corr$eduD<-EV8corr$edu-EV8corr$eduM EV8corrmean$edu[EV8corrmean$type=="diff"]<-mean(EV8corr$eduD, na.rm=TRUE) EV8corr$workD<-NA EV8corr$workD<-EV8corr$work-EV8corr$workM EV8corrmean$work[EV8corrmean$type=="diff"]<-mean(EV8corr$workD, na.rm=TRUE) EV8corr$aloneD<-NA EV8corr$aloneD<-EV8corr$alone-EV8corr$aloneM EV8corrmean$alone[EV8corrmean$type=="diff"]<-mean(EV8corr$aloneD, na.rm=TRUE) #symmetry test. symmetry.test(EV8corr$polintrD) symmetry.test(EV8corr$impfamiD) symmetry.test(EV8corr$impleasD) symmetry.test(EV8corr$imppolD) symmetry.test(EV8corr$imprelD) symmetry.test(EV8corr$immigD) symmetry.test(EV8corr$eduD) #wilcoxon test. wilcox.test(EV8corr$f5, EV8corr$v186,paired=TRUE,na.rm=TRUE) wilcox.test(EV8corr$f1_0, EV8corr$v1,paired=TRUE,na.rm=TRUE) wilcox.test(EV8corr$f1_1, EV8corr$v2,paired=TRUE,na.rm=TRUE) wilcox.test(EV8corr$f1_2, EV8corr$v3,paired=TRUE,na.rm=TRUE) wilcox.test(EV8corr$f1_3, EV8corr$v4,paired=TRUE,na.rm=TRUE) wilcox.test(EV8corr$f1_4, EV8corr$v5,paired=TRUE,na.rm=TRUE) wilcox.test(EV8corr$f1_5, EV8corr$v6,paired=TRUE,na.rm=TRUE) wilcox.test(EV8corr$f2, EV8corr$v63,paired=TRUE,na.rm=TRUE) wilcox.test(EV8corr$f3_0, EV8corr$v275,paired=TRUE,na.rm=TRUE) wilcox.test(EV8corr$f3_1, EV8corr$v282,paired=TRUE,na.rm=TRUE) wilcox.test(EV8corr$f3_2, EV8corr$v283,paired=TRUE,na.rm=TRUE) t.test(EV8corr$ager, EV8corr$agerM,paired=TRUE,na.rm=TRUE) wilcox.test(EV8corr$edu, EV8corr$eduM,paired=TRUE,na.rm=TRUE) prop.test(matrix(c(45,43,101,102),nrow=2,ncol=2)) table(EV8corr$work) table(EV8corr$workM) prop.test(matrix(c(110,104,37,22),nrow=2,ncol=2)) table(EV8corr$alone) table(EV8corr$aloneM) EV8$mnsurv<-0 EV8$mnsurv[EV8$mainsurv==1]<-1 #creation of harmonized variable: takes the values of the main survey for respondents and of NRS for nonrespondents. EV8<-EV8[order(-EV8$mnsurv,-EV8$nrsurv),] v1<-EV8$gndrM[EV8$mnsurv>=1] v2<-EV8$gndr[EV8$mnsurv==0] EV8$gndr_h<-c(v1,v2) table(EV8$gndr_h) v1<-EV8$v1[EV8$mnsurv==1] v2<-EV8$f1_0[EV8$mnsurv==0] EV8$impwork_h<-c(v1,v2) table(EV8$impwork_h) v1<-EV8$v2[EV8$mnsurv==1] v2<-EV8$f1_1[EV8$mnsurv==0] EV8$impfami_h<-c(v1,v2) table(EV8$impfami_h) v1<-EV8$v3[EV8$mnsurv==1] v2<-EV8$f1_2[EV8$mnsurv==0] EV8$impfrie_h<-c(v1,v2) table(EV8$impfrie_h) v1<-EV8$v4[EV8$mnsurv==1] v2<-EV8$f1_3[EV8$mnsurv==0] EV8$impleas_h<-c(v1,v2) table(EV8$impleas_h) v1<-EV8$v5[EV8$mnsurv==1] v2<-EV8$f1_4[EV8$mnsurv==0] EV8$imppol_h<-c(v1,v2) table(EV8$imppol_h) v1<-EV8$v6[EV8$mnsurv==1] v2<-EV8$f1_5[EV8$mnsurv==0] EV8$imprel_h<-c(v1,v2) table(EV8$imprel_h) v1<-EV8$v63[EV8$mnsurv==1] v2<-EV8$f2[EV8$mnsurv==0] EV8$trust_h<-c(v1,v2) table(EV8$trust_h) v1<-EV8$v275[EV8$mnsurv==1] v2<-EV8$f3_0[EV8$mnsurv==0] EV8$immig_h<-c(v1,v2) table(EV8$immig_h) v1<-EV8$v282[EV8$mnsurv==1] v2<-EV8$f3_1[EV8$mnsurv==0] EV8$just_h<-c(v1,v2) table(EV8$just_h) v1<-EV8$v283[EV8$mnsurv==1] v2<-EV8$f3_2[EV8$mnsurv==0] EV8$stick_h<-c(v1,v2) table(EV8$stick_h) v1<-EV8$v186[EV8$mnsurv==1] v2<-EV8$v186[EV8$mnsurv==0] EV8$polintr_h<-c(v1,v2) table(EV8$polintr_h) v1<-EV8$agerM[EV8$mnsurv==1] v2<-EV8$ager[EV8$mnsurv==0] EV8$ager_h<-c(v1,v2) table(EV8$ager_h) v1<-EV8$gndrM[EV8$mnsurv==1] v2<-EV8$gndr[EV8$mnsurv==0] EV8$gndr_h<-c(v1,v2) table(EV8$gndr_h) v1<-EV8$eduM[EV8$mnsurv==1] v2<-EV8$edu[EV8$mnsurv==0] EV8$edu_h<-c(v1,v2) table(EV8$edu_h) v1<-EV8$workM[EV8$mnsurv==1] v2<-EV8$work[EV8$mnsurv==0] EV8$work_h<-c(v1,v2) table(EV8$work_h) v1<-EV8$aloneM[EV8$mnsurv==1] v2<-EV8$alone[EV8$mnsurv==0] EV8$alone_h<-c(v1,v2) table(EV8$alone_h) #compare the distrubutions for respondents and non-respondents. crosstab(EV8$gndr_h,EV8$mnsurv,prop.c=T,chisq=T) crosstab(EV8$ager_h,EV8$mnsurv,prop.c=T,chisq=T) crosstab(EV8$edu_h,EV8$mnsurv,prop.c=T,chisq=T) crosstab(EV8$work_h,EV8$mnsurv,prop.c=T,chisq=T) crosstab(EV8$alone_h,EV8$mnsurv,prop.c=T,chisq=T) crosstab(EV8$impwork_h,EV8$mnsurv,prop.c=T,chisq=T) crosstab(EV8$impfami_h,EV8$mnsurv,prop.c=T,chisq=T) crosstab(EV8$impfrie_h,EV8$mnsurv,prop.c=T,chisq=T) crosstab(EV8$impleas_h,EV8$mnsurv,prop.c=T,chisq=T) crosstab(EV8$imppol_h,EV8$mnsurv,prop.c=T,chisq=T) crosstab(EV8$imprel_h,EV8$mnsurv,prop.c=T,chisq=T) crosstab(EV8$trust_h,EV8$mnsurv,prop.c=T,chisq=T) crosstab(EV8$immig_h,EV8$mnsurv,prop.c=T,chisq=T) crosstab(EV8$just_h,EV8$mnsurv,prop.c=T,chisq=T) crosstab(EV8$stick_h,EV8$mnsurv,prop.c=T,chisq=T) #review evsNR<-EV8[which(EV8$nrsurv==1),] evsNR<-evsNR[which(!is.na(evsNR$ager)&!is.na(evsNR$gndr)&!is.na(evsNR$edu)&!is.na(evsNR$work)&!is.na(evsNR$alone)&!is.na(evsNR$f1_0) &!is.na(evsNR$f1_1)&!is.na(evsNR$f1_2)&!is.na(evsNR$f1_3)&!is.na(evsNR$f1_5)&!is.na(evsNR$f1_4)&!is.na(evsNR$f2) &!is.na(evsNR$f3_0)&!is.na(evsNR$f3_1)&!is.na(evsNR$f3_2)&!is.na(evsNR$group) &!is.na(evsNR$f5)),] evsNR$NR<-1 evsNR$NR[evsNR$mainsurv==1]<-0 table(evsNR$NR) evsreview<-glm(NR~ager+gndr+edu+work+alone+f1_0+f1_1+f1_2+f1_3+f1_4+f1_5+f2+f3_0+f3_1+f3_2+group+f5,data=evsNR,family=binomial) summary(evsreview) NagelkerkeR2(evsreview) evsNR$propscore<-predict(evsreview, type="response") evsNR$propweight<-1/evsNR$propscore type<- c("RUmean","RWmean", "NRmean") evsr<-as.data.frame(type) evsNRNR<-evsNR[which(evsNR$NR==1),] evsr$impwork[evsr$type=="RUmean"]<-mean(evsNR$f1_0, na.rm=TRUE) evsr$impwork[evsr$type=="RWmean"]<-weighted.mean(evsNR$f1_0,evsNR$propweight, na.rm=TRUE) evsr$impwork[evsr$type=="NRmean"]<-mean(evsNR$v1, na.rm=TRUE) evsr$impfam[evsr$type=="RUmean"]<-mean(evsNR$f1_1, na.rm=TRUE) evsr$impfam[evsr$type=="RWmean"]<-weighted.mean(evsNR$f1_1,evsNR$propweight, na.rm=TRUE) evsr$impfam[evsr$type=="NRmean"]<-mean(evsNR$v2, na.rm=TRUE) evsr$imfrie[evsr$type=="RUmean"]<-mean(evsNR$f1_2, na.rm=TRUE) evsr$imfrie[evsr$type=="RWmean"]<-weighted.mean(evsNR$f1_2,evsNR$propweight, na.rm=TRUE) evsr$imfrie[evsr$type=="NRmean"]<-mean(evsNR$v3, na.rm=TRUE) evsr$implea[evsr$type=="RUmean"]<-mean(evsNR$f1_3, na.rm=TRUE) evsr$implea[evsr$type=="RWmean"]<-weighted.mean(evsNR$f1_3,evsNR$propweight, na.rm=TRUE) evsr$implea[evsr$type=="NRmean"]<-mean(evsNR$v4, na.rm=TRUE) evsr$imppol[evsr$type=="RUmean"]<-mean(evsNR$f1_4, na.rm=TRUE) evsr$imppol[evsr$type=="RWmean"]<-weighted.mean(evsNR$f1_4,evsNR$propweight, na.rm=TRUE) evsr$imppol[evsr$type=="NRmean"]<-mean(evsNR$v5, na.rm=TRUE) evsr$imprel[evsr$type=="RUmean"]<-mean(evsNR$f1_5, na.rm=TRUE) evsr$imprel[evsr$type=="RWmean"]<-weighted.mean(evsNR$f1_5,evsNR$propweight, na.rm=TRUE) evsr$imprel[evsr$type=="NRmean"]<-mean(evsNR$v6, na.rm=TRUE) evsr$trust[evsr$type=="RUmean"]<-mean(evsNR$f2, na.rm=TRUE) evsr$trust[evsr$type=="RWmean"]<-weighted.mean(evsNR$f2,evsNR$propweight, na.rm=TRUE) evsr$trust[evsr$type=="NRmean"]<-mean(evsNR$v63, na.rm=TRUE) evsr$immig[evsr$type=="RUmean"]<-mean(evsNR$f3_0, na.rm=TRUE) evsr$immig[evsr$type=="RWmean"]<-weighted.mean(evsNR$f3_0,evsNR$propweight, na.rm=TRUE) evsr$immig[evsr$type=="NRmean"]<-mean(evsNR$v275, na.rm=TRUE) evsr$just[evsr$type=="RUmean"]<-mean(evsNR$f3_1, na.rm=TRUE) evsr$just[evsr$type=="RWmean"]<-weighted.mean(evsNR$f3_1,evsNR$propweight, na.rm=TRUE) evsr$just[evsr$type=="NRmean"]<-mean(evsNR$v282, na.rm=TRUE) evsr$stick[evsr$type=="RUmean"]<-mean(evsNR$f3_2, na.rm=TRUE) evsr$stick[evsr$type=="RWmean"]<-weighted.mean(evsNR$f3_2,evsNR$propweight, na.rm=TRUE) evsr$stick[evsr$type=="NRmean"]<-mean(evsNR$v283, na.rm=TRUE) evsr$just[evsr$type=="RUmean"]<-mean(evsNR$group, na.rm=TRUE) evsr$just[evsr$type=="RWmean"]<-weighted.mean(evsNR$group,evsNR$propweight, na.rm=TRUE) evsr$just[evsr$type=="NRmean"]<-mean(evsNR$groupM, na.rm=TRUE) evsr$stick[evsr$type=="RUmean"]<-mean(evsNR$f5, na.rm=TRUE) evsr$stick[evsr$type=="RWmean"]<-weighted.mean(evsNR$f5,evsNR$propweight, na.rm=TRUE) evsr$stick[evsr$type=="NRmean"]<-mean(evsNR$v186, na.rm=TRUE) write.table(evsr,file= "evsr.txt",sep="\t") #significance #create the right dataset evsbothw<-evsNR[which(evsNR$mainsurv==1),] evsbothw$propweight2<-evsbothw$propweight evsbothw$type<-1 evsbothw$type2<-1 evsbothnw<-evsbothw evsbothnw$propweight<-1 evsbothnw$propweight2<-0 evsbothnw$type<-0 evsbothnw$type2<-NA evsNRnw<-evsNR evsNRnw$propweight<-0 evsNRnw$propweight2<-1 evsNRnw$type<-NA evsNRnw$type2<-0 evssign<-rbind(evsbothw,evsbothnw,evsNRnw) table(evssign$type2) library(survey) design1<-svydesign(ids=~1,weights=evssign$propweight, data=evssign) svymean(evssign$impwork_h,design=design1, na.rm=TRUE) svychisq(~type+impwork_h, design = design1, statistic = "F") svychisq(~type+impfami_h, design = design1, statistic = "F") svychisq(~type+impfrie_h, design = design1, statistic = "F") svychisq(~type+impleas_h, design = design1, statistic = "F") svychisq(~type+imppol_h, design = design1, statistic = "F") svychisq(~type+imprel_h, design = design1, statistic = "F") svychisq(~type+trust_h, design = design1, statistic = "F") svychisq(~type+immig_h, design = design1, statistic = "F") svychisq(~type+just_h, design = design1, statistic = "F") svychisq(~type+stick_h, design = design1, statistic = "F") svychisq(~type+polintr_h, design = design1, statistic = "F") #all p-value above .95 design2<-svydesign(ids=~1,weights=evssign$propweight2, data=evssign) svymean(evssign$impwork_h,design=design2, na.rm=TRUE) svychisq(~type2+impwork_h, design = design2, statistic = "F") svychisq(~type2+impfami_h, design = design2, statistic = "F") svychisq(~type2+impfrie_h, design = design2, statistic = "F") svychisq(~type2+impleas_h, design = design2, statistic = "F") svychisq(~type2+imppol_h, design = design2, statistic = "F") svychisq(~type2+imprel_h, design = design2, statistic = "F") svychisq(~type2+trust_h, design = design2, statistic = "F") svychisq(~type2+immig_h, design = design2, statistic = "F") svychisq(~type2+just_h, design = design2, statistic = "F") svychisq(~type2+stick_h, design = design2, statistic = "F") svychisq(~type2+polintr_h, design = design2, statistic = "F")