#------------ setwd
setwd("C:/Users/C00252837/Dropbox/StudentParentsData")

#------------Read in Data
data<-read.csv("sutdentparents_survey_weighted.csv", header = T)
data<-as_tibble(data)
names(data)
##  [1] "ï..Column1"                       "x1"                              
##  [3] "Ã.Column1"                        "x"                               
##  [5] "classification"                   "enrollment"                      
##  [7] "department"                       "q4"                              
##  [9] "finanacial_assistance"            "q24_8_text"                      
## [11] "q23"                              "q38"                             
## [13] "q5"                               "q43"                             
## [15] "employment_status"                "gender"                          
## [17] "gender2"                          "q10_5_text"                      
## [19] "age_original"                     "race"                            
## [21] "race2"                            "q46"                             
## [23] "q46_4_text"                       "q47"                             
## [25] "q47_11_text"                      "pregnancy"                       
## [27] "parenthood"                       "numb_children"                   
## [29] "age_children"                     "q35_13"                          
## [31] "q35_14"                           "q35_15"                          
## [33] "q62"                              "column226"                       
## [35] "res_aware_both_mean"              "res_aware_patuniq_mean"          
## [37] "res_use_both_mean"                "res_use_patuniq_mean"            
## [39] "socialsupport_both_mean"          "socialsupport_patuniq_mean"      
## [41] "positive_exp_both_mean"           "positive_exp_patuniq_mean"       
## [43] "negative_exp_gen_both_mean"       "negative_exp_gen_patuniq_mean"   
## [45] "academic_diffty_both_mean"        "academic_diffty_patuniq_mean"    
## [47] "financial_ins_both_mean"          "financial_ins_patuniq_mean"      
## [49] "housing_ins_both_mean"            "physical_health_both_mean"       
## [51] "psycsocemo_health_both_mean"      "psycsocemo_health_patuniq_mean"  
## [53] "expectations_both_mean"           "expectations_patuniq_mean"       
## [55] "pat_childcare_patuniq_mean"       "child_issues_patuniq_mean"       
## [57] "pregnancy_patuniq_mean"           "age_recoded"                     
## [59] "age_recoded_narm"                 "parenthood_age"                  
## [61] "parenthood_age_narm"              "res_aware_both_mean_recode"      
## [63] "res_use_both_mean_recode"         "socialsupport_both_mean_recode"  
## [65] "positive_exp_both_mean_recode"    "negative_exp_gen_both_mean_recod"
## [67] "academic_diffty_both_mean_recode" "financial_ins_both_mean_recode"  
## [69] "housing_ins_both_mean_recode"     "physical_health_both_mean_recode"
## [71] "psycsocemo_health_both_mean_reco" "nurs_or_not"                     
## [73] "age"                              "agegroup"                        
## [75] "binary_gender_original"           "binary_gender"                   
## [77] "race3"                            "graduate"                        
## [79] "agegroup_tot"                     "binary_gender_tot"               
## [81] "race3_tot"                        "graduate_tot"                    
## [83] "counter1"                         "sample_tot"                      
## [85] "baseweight"                       "finalweight"
data <- data%>%
  rename(
    ID = x)

Complex Survey Analysis

Differential respondent weighting (following https://rpubs.com/corey_sparks/53683)

#Total count of the sample
count(data)
## # A tibble: 1 x 1
##       n
##   <int>
## 1   738
#parenthood status
table(data$parenthood)
## 
##  No Yes 
## 571 167
prop.table(table(data$parenthood))
## 
##        No       Yes 
## 0.7737127 0.2262873
#graduate status
table(data$graduate)#0=undergraduate, 1=graduate
## 
##   0   1 
## 535 203
prop.table(table(data$graduate))
## 
##         0         1 
## 0.7249322 0.2750678
#parenthood by graduate status
table(data$parenthood, data$graduate)
##      
##         0   1
##   No  445 126
##   Yes  90  77
prop.table(table(data$parenthood, data$graduate), margin=2)
##      
##               0         1
##   No  0.8317757 0.6206897
##   Yes 0.1682243 0.3793103

##Create a survey design object ##Use functions in a new library, called survey

library(survey)
des<-svydesign(ids=~1, weights=~finalweight, data = data)

#re-do the analysis from above using sample weights
library(questionr)
wtd.table(data$parenthood,weights = data$finalweight)
##    No   Yes 
## 12521  2203
prop.table(wtd.table(data$parenthood,weights = data$finalweight))
##        No       Yes 
## 0.8503803 0.1496197
wtd.table(data$graduate, weights = data$finalweight)#0=undergraduate, 1=graduate
##     0     1 
## 12353  2371
prop.table(wtd.table(data$graduate, weights = data$finalweight))
##         0         1 
## 0.8389704 0.1610296
wtd.table(data$parenthood, data$graduate, weights = data$finalweight)
##         0     1
## No  10949  1572
## Yes  1404   799
prop.table(wtd.table(data$parenthood, data$graduate, weights = data$finalweight), margin=2)
##             0         1
## No  0.8863434 0.6630114
## Yes 0.1136566 0.3369886

t- tests

data$parenthood<-as.factor(data$parenthood)
data$agegroup<-as.factor(data$agegroup)
data$binary_gender<-as.factor(data$binary_gender)#1=female, 2=male
data$race3<-as.factor(data$race3)
data$graduate<-as.factor(data$graduate)
##### Social Support #################################################################

#unweighted
Hmisc::describe(data$socialsupport_both_mean)
## data$socialsupport_both_mean 
##        n  missing distinct     Info     Mean      Gmd 
##      607      131        5    0.878    3.489   0.9084 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency      6    63   229   246    63
## Proportion 0.010 0.104 0.377 0.405 0.104
var.test(data$socialsupport_both_mean~data$parenthood)#F-test var.test to compare two variances
## 
##  F test to compare two variances
## 
## data:  data$socialsupport_both_mean by data$parenthood
## F = 1.0125, num df = 483, denom df = 122, p-value = 0.9539
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  0.7546569 1.3261734
## sample estimates:
## ratio of variances 
##           1.012468
t.test(socialsupport_both_mean~parenthood, data=data, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  socialsupport_both_mean by parenthood
## t = -2.8398, df = 605, p-value = 0.004665
## alternative hypothesis: true difference in means between group No and group Yes is not equal to 0
## 95 percent confidence interval:
##  -0.4107835 -0.0749049
## sample estimates:
##  mean in group No mean in group Yes 
##          3.440083          3.682927
#weighted
Hmisc::describe(data$socialsupport_both_mean, weights = data$finalweight)
## data$socialsupport_both_mean 
##        n  missing distinct     Info     Mean 
##    12375     2349        5    0.881    3.445 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency    148  1466  4679  4896  1186
## Proportion 0.012 0.118 0.378 0.396 0.096
t.test(socialsupport_both_mean~parenthood, data=data, weights = data$finalweight, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  socialsupport_both_mean by parenthood
## t = -2.8398, df = 605, p-value = 0.004665
## alternative hypothesis: true difference in means between group No and group Yes is not equal to 0
## 95 percent confidence interval:
##  -0.4107835 -0.0749049
## sample estimates:
##  mean in group No mean in group Yes 
##          3.440083          3.682927
##### academic_difficulty 
#un-weighted
Hmisc::describe(data$academic_diffty_both_mean)
## data$academic_diffty_both_mean 
##        n  missing distinct     Info     Mean      Gmd 
##      542      196        5    0.899    3.321    1.001 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency      7    93   218   167    57
## Proportion 0.013 0.172 0.402 0.308 0.105
var.test(data$academic_diffty_both_mean~data$parenthood)#F-test var.test to compare two variances
## 
##  F test to compare two variances
## 
## data:  data$academic_diffty_both_mean by data$parenthood
## F = 1.0314, num df = 432, denom df = 108, p-value = 0.8634
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  0.7542056 1.3727219
## sample estimates:
## ratio of variances 
##           1.031434
t.test(academic_diffty_both_mean~parenthood, data=data, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  academic_diffty_both_mean by parenthood
## t = 3.0432, df = 540, p-value = 0.002454
## alternative hypothesis: true difference in means between group No and group Yes is not equal to 0
## 95 percent confidence interval:
##  0.1058207 0.4911664
## sample estimates:
##  mean in group No mean in group Yes 
##          3.381062          3.082569
#weighted
Hmisc::describe(data$academic_diffty_both_mean, weights = data$finalweight)
## data$academic_diffty_both_mean 
##        n  missing distinct     Info     Mean 
##    11049     3675        5    0.897    3.381 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     70  1719  4545  3356  1359
## Proportion 0.006 0.156 0.411 0.304 0.123
t.test(academic_diffty_both_mean~parenthood, data=data, weights = data$finalweight, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  academic_diffty_both_mean by parenthood
## t = 3.0432, df = 540, p-value = 0.002454
## alternative hypothesis: true difference in means between group No and group Yes is not equal to 0
## 95 percent confidence interval:
##  0.1058207 0.4911664
## sample estimates:
##  mean in group No mean in group Yes 
##          3.381062          3.082569
##### psycsocemo_health_issues ##########################################################
#un-weighted
Hmisc::describe(data$psycsocemo_health_both_mean)
## data$psycsocemo_health_both_mean 
##        n  missing distinct     Info     Mean      Gmd 
##      557      181        5    0.883    3.578   0.9382 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency      1    66   174   242    74
## Proportion 0.002 0.118 0.312 0.434 0.133
var.test(data$psycsocemo_health_both_mean~data$parenthood)#F-test var.test to compare two variances
## 
##  F test to compare two variances
## 
## data:  data$psycsocemo_health_both_mean by data$parenthood
## F = 1.0878, num df = 451, denom df = 104, p-value = 0.6105
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  0.792012 1.451305
## sample estimates:
## ratio of variances 
##            1.08777
t.test(psycsocemo_health_both_mean~parenthood, data=data, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  psycsocemo_health_both_mean by parenthood
## t = 2.4613, df = 555, p-value = 0.01415
## alternative hypothesis: true difference in means between group No and group Yes is not equal to 0
## 95 percent confidence interval:
##  0.04668813 0.41572232
## sample estimates:
##  mean in group No mean in group Yes 
##          3.621681          3.390476
#weighted
Hmisc::describe(data$psycsocemo_health_both_mean, weights = data$finalweight)
## data$psycsocemo_health_both_mean 
##        n  missing distinct     Info     Mean 
##    11361     3363        5    0.888    3.592 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     42  1343  3469  4866  1641
## Proportion 0.004 0.118 0.305 0.428 0.144
t.test(psycsocemo_health_both_mean~parenthood, data=data, weights = data$finalweight, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  psycsocemo_health_both_mean by parenthood
## t = 2.4613, df = 555, p-value = 0.01415
## alternative hypothesis: true difference in means between group No and group Yes is not equal to 0
## 95 percent confidence interval:
##  0.04668813 0.41572232
## sample estimates:
##  mean in group No mean in group Yes 
##          3.621681          3.390476
reg_psycsocemo_health_both<-lm(psycsocemo_health_both_mean~age + + binary_gender + race3 + graduate + parenthood + socialsupport_both_mean + financial_ins_both_mean + physical_health_both_mean, data=data, weights = data$finalweight, var.equal=TRUE)

summary(reg_psycsocemo_health_both)
## 
## Call:
## lm(formula = psycsocemo_health_both_mean ~ age + +binary_gender + 
##     race3 + graduate + parenthood + socialsupport_both_mean + 
##     financial_ins_both_mean + physical_health_both_mean, data = data, 
##     weights = data$finalweight, var.equal = TRUE)
## 
## Weighted Residuals:
##      Min       1Q   Median       3Q      Max 
## -10.9910  -1.7849   0.1997   1.8542   9.8603 
## 
## Coefficients:
##                             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                3.4714008  0.2608697  13.307  < 2e-16 ***
## age                       -0.0007088  0.0053087  -0.134   0.8938    
## binary_gender2            -0.0765995  0.0611564  -1.253   0.2110    
## race31                    -0.1642199  0.2100395  -0.782   0.4347    
## race32                    -0.2959086  0.1182939  -2.501   0.0127 *  
## race33                     0.0625217  0.1487053   0.420   0.6744    
## race34                    -0.2091063  0.1023361  -2.043   0.0416 *  
## graduate1                 -0.2170863  0.0969263  -2.240   0.0256 *  
## parenthoodYes             -0.1445870  0.1129213  -1.280   0.2010    
## socialsupport_both_mean   -0.3197893  0.0385706  -8.291 1.16e-15 ***
## financial_ins_both_mean    0.2553369  0.0391273   6.526 1.73e-10 ***
## physical_health_both_mean  0.2047043  0.0310271   6.598 1.12e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.966 on 476 degrees of freedom
##   (250 observations deleted due to missingness)
## Multiple R-squared:  0.4635, Adjusted R-squared:  0.4511 
## F-statistic: 37.38 on 11 and 476 DF,  p-value: < 2.2e-16
reg_academic_diffty_both_mean<-lm(academic_diffty_both_mean~age + binary_gender + race3 + graduate + parenthood + socialsupport_both_mean + financial_ins_both_mean + physical_health_both_mean + psycsocemo_health_both_mean, data=data, weights = data$finalweight, var.equal=TRUE)

summary(reg_academic_diffty_both_mean)
## 
## Call:
## lm(formula = academic_diffty_both_mean ~ age + binary_gender + 
##     race3 + graduate + parenthood + socialsupport_both_mean + 
##     financial_ins_both_mean + physical_health_both_mean + psycsocemo_health_both_mean, 
##     data = data, weights = data$finalweight, var.equal = TRUE)
## 
## Weighted Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.6248 -1.7103 -0.0164  1.5945  8.7083 
## 
## Coefficients:
##                              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                  1.328290   0.291148   4.562 6.55e-06 ***
## age                         -0.002495   0.005114  -0.488  0.62588    
## binary_gender2               0.174801   0.058051   3.011  0.00275 ** 
## race31                      -0.020991   0.197691  -0.106  0.91549    
## race32                      -0.198444   0.113926  -1.742  0.08222 .  
## race33                      -0.283147   0.142926  -1.981  0.04819 *  
## race34                      -0.323229   0.097920  -3.301  0.00104 ** 
## graduate1                   -0.177911   0.094072  -1.891  0.05924 .  
## parenthoodYes               -0.045430   0.106625  -0.426  0.67026    
## socialsupport_both_mean     -0.093543   0.039427  -2.373  0.01809 *  
## financial_ins_both_mean      0.394690   0.038766  10.181  < 2e-16 ***
## physical_health_both_mean    0.040824   0.030541   1.337  0.18201    
## psycsocemo_health_both_mean  0.345652   0.043343   7.975 1.29e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.741 on 447 degrees of freedom
##   (278 observations deleted due to missingness)
## Multiple R-squared:  0.5692, Adjusted R-squared:  0.5577 
## F-statistic: 49.22 on 12 and 447 DF,  p-value: < 2.2e-16
unique(data$age)
##  [1] 20 21 49 19 26 18 30 34 33 22 41 27 23 36 39 24 38 28 44 31 45 55 47 57 25
## [26] 32 43 40 29 52 35 53 37 46 50 51 42 17 59 48 62 65 74 63 60 56