A) Choose a data set and an event, with an associated duration; define as many predictors as you need to do your analysis.

For this analysis the National Longitudinal Study of Adolescent to Adult Health (ADD Health) is used to determine if the likelihood of being jumped or beaten up for LGB individuals is greater and earlier then the liklihood of being beaten up for straight people.. ADD Health is a nationally representative longitudinal study of adolescents in the United States who are between 7 and 12 years old. The survey was conducted in 1994 with follow up surveys in 1996, 2008, and 2016. A Cox Proportional Hazards Model was utilized to analyze the data.

B) Define the key variables: episodes, events, duration, censoring, predictors

Episode - calculated from the start time, or age at first interview, and end time, or age when event occured, and censoring

Event - being jumped and beaten up

Duration - the time until the even of being beaten up occurs

Censoring - if someone is not beaten up they are right censored at the end of the study, or wave 4 (survival time)

Predictors - sex, race/ethnicity, physical limitations, U.S. citizen, education, marriage, income, residence

library(haven)
#download datasets - AddHealth
wave1<-read_dta("/projects/add_health/data/11613344/ICPSR_27021/DS0001/da27021p1.dta")
wave3<-read_dta("/projects/add_health/data/11613344/ICPSR_27021/DS0003/da27021p3.dta")
wave4<-read_dta("/projects/add_health/data/11613344/ICPSR_27021/DS0012/da27021p12.dta")
addhealth.wghtW4<-read_dta("/projects/add_health/data/11613344/ICPSR_27021/DS0028/da27021p28.dta")
#addhealth<-merge(wave1,wave3,by="aid")
addhealth1<-merge(wave1,wave3,by="aid")
addhealth1<-merge(addhealth1,wave4,by="aid")
addhealth1<-merge(addhealth1,addhealth.wghtW4,by="aid")
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
#select variables to use
addhealth<-addhealth1%>%
  select(GSWGT4,region,psuscid,BIO_SEX,H3SE13,H1GI6A,H1GI6B,H1GI4,H1GI6D,H1GI6E,H4ED2,iyear,imonth,H1GI1M,H1GI1Y,IYEAR3,IMONTH3,H3OD1Y,H3OD1M,H4OD1M,H4OD1Y,IMONTH4,IYEAR4,H4MH22,H3GH1,H4GH1,H1GI6C,H1FS6,H3SP9,H4DS18,H3DS18F,H4MH22,H4GH1,H4EC1,H4TR1,H3DS18G,H1FV6,H4LM1,H4ID1,H4ID1,H3HR2,H4OD4)
#complete cases
addhealth<-addhealth%>%
 filter(complete.cases(.))
library(car)
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
## 
##     recode
#UScitizen
addhealth$UScitizen<-Recode(addhealth$H4OD4,recodes="0='a_no';1='b_yes';else=NA",as.factor=T)

#physical limitations
addhealth$physical.limits<-Recode(addhealth$H4ID1,recodes="1='a_not_limited';2:3='b_limited';else=NA",as.factor=T)

#residence
addhealth$w3.residence<-Recode(addhealth$H3HR2,recodes="1='a_withparents';2='b_withsomeone';3='c_myownplace';4='d_group.qrts';5='e_homeless';6='f_other';else=NA",as.factor=T)
#number of times married
addhealth$W4.married<-Recode(addhealth$H4TR1,recodes="0='a_never married';1='b_married_once';2:4='c_married_twice+';else=NA",as.factor=T)
#general health
#addhealth$W4.general_health<-Recode(addhealth$H4GH1,recodes="1:3='c_good/vg/excellent';4:5='b_poor/fair';else=NA")
#depression
#addhealth$W4.depression<-Recode(addhealth$H4MH22,recodes="0:1='a_never_some';2:3='b_most_always';else=NA")
#Date of birth variables; Wave 1: H1GI1M (month), H1GI1Y (year); Wave 3: H3OD1M (month), H3OD1Y (year); Wave 4: H4OD1M (month), H4OD1Y (year)
#birth year w1
addhealth$birthyearw1 <- factor(ifelse(addhealth$H1GI1Y=="74",1974,
                                             ifelse(addhealth$H1GI1Y=="75",1975,
                                                           ifelse(addhealth$H1GI1Y=="76",1976,
                                                                         ifelse(addhealth$H1GI1Y=="77",1977,
                                                                                       ifelse(addhealth$H1GI1Y=="78",1978,
                                                                                                     ifelse(addhealth$H1GI1Y=="79",1979,
                                                                                                                   ifelse(addhealth$H1GI1Y=="80",1980,
                                                                                                                                ifelse(addhealth$H1GI1Y=="81",1981,
                                                                                                                                               ifelse(addhealth$H1GI1Y=="82",1982,
                                                                                                                                                             ifelse(addhealth$H1GI1Y=="83",1983,1979)))))))))))
#birth month w1
addhealth$birthmonthw1 <- Recode(addhealth$H1GI1M,recodes="1=1;2=2;3=3;4=4;5=5;6=6;7=7;8=8;9=9;10=10;11=11;12=12;else=NA")
#combine year and month for a birth date wave 1
library(zoo)
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
addhealth$birthdatew1 <- as.yearmon(paste(addhealth$birthyearw1, addhealth$birthmonthw1), "%Y %m")
#birth month wave 4
addhealth$birthmonthw4 <- Recode(addhealth$H4OD1M,recodes="1=1;2=2;3=3;4=4;5=5;6=6;7=7;8=8;9=9;10=10;11=11;12=12")
#birth year wave 4
addhealth$birthyearw4<-addhealth$H4OD1Y
addhealth$birthyearw4 <- Recode(addhealth$H4OD1Y,recodes="1974=1974;1975=1975;1976=1976;1977=1977;1978=1978;1979=1979;1980=1980;1981=1981;1982=1982;1983=1983")
#combine year and month for birth date wave 4
addhealth$birthdatew4 <- as.yearmon(paste(addhealth$birthyearw4, addhealth$birthmonthw4), "%Y %m")
#birth date wave 3
addhealth$birthdatew3<-as.yearmon(paste(addhealth$H3OD1Y,addhealth$H3OD1M),"%Y %m")
#interview date w1
addhealth$iyearfix <- Recode(addhealth$iyear,recodes="'94'='1994';'95'='1995'")
addhealth$interviewdatew1 <- as.yearmon(paste(addhealth$iyearfix, addhealth$imonth), "%Y %m")
#interview date w4
addhealth$interviewmonthw4 <- Recode(addhealth$IMONTH4,recodes="1=1;2=2;3=3;4=4;5=5;6=6;7=7;8=8;9=9;10=10;11=11;12=12")
addhealth$interviewyearw4 <- Recode(addhealth$IYEAR4,recodes="2007=2007;2008=2008;2009=2009")
addhealth$interviewdatew4<-as.yearmon(paste(addhealth$interviewyearw4,addhealth$interviewmonthw4),"%Y %m")
#interview date w3
addhealth$interviewdatew3<-as.yearmon(paste(addhealth$IYEAR3,addhealth$IMONTH3 ),"%Y %m")
#age - derived from date of birth subtracted from wave interview date 
addhealth$agew4<-(as.numeric(round(addhealth$interviewdatew4 - addhealth$birthdatew4)))
addhealth$agew3<-(as.numeric(round(addhealth$interviewdatew3 - addhealth$birthdatew3)))
addhealth$agew1<-(as.numeric(round(addhealth$interviewdatew1 - addhealth$birthdatew1)))

#sex variable - Male is reference group
addhealth$sex <- ifelse(addhealth$BIO_SEX==2,2,1)
addhealth$sex<-Recode(addhealth$sex, recodes="1='a_male'; 2='b_female'",as.factor=T)   
#sexual orientation from wave 3.  Reference group is straight people
addhealth$sexorient <- factor(ifelse(addhealth$H3SE13=="(1) 100% heterosexual (straight)",1,
                                       ifelse(addhealth$H3SE13=="(2) Mostly #heterosexual.somewhat attracted to people of own",2, 
                                           ifelse(addhealth$H3SE13=="(3) Bisexual-attracted #to men and women equally",3,
                                                   ifelse(addhealth$H3SE13=="(4) Mostly #homosexual.somewhat attracted to opposite sex",4,
                                                          ifelse(addhealth$H3SE13=="(5) 100% #homosexual (gay)",5,NA))))))

addhealth$sexorient<-Recode(addhealth$H3SE13, recodes="1:2='a_straight'; 3='b_bisexual';4:5='c_LGB';else=NA",as.factor=T)
#race variables - Reference group is nhwhite
#nhwhite
addhealth$nhwhite <- ifelse(addhealth$H1GI6A==1,1,0)
addhealth$nhwhite<-Recode(addhealth$nhwhite, recodes="1='nhwhite'; 0='nonnhwhite'; 6:8=NA",as.factor=T)
#nhblack
addhealth$nhblack <- ifelse(addhealth$H1GI6B==1,1,0)
addhealth$nhblack<-Recode(addhealth$nhblack, recodes="1='nhblack'; 0='nonnhblack'; 6:8=NA",as.factor=T)
#Hispanic
addhealth$hispanic <- ifelse(addhealth$H1GI4==1,1,0)
addhealth$hispanic<-Recode(addhealth$hispanic, recodes="1='hispanic'; 0='nonhispanic'; 6:8=NA",as.factor=T)
#Asian
addhealth$asian <- ifelse(addhealth$H1GI6D==1,1,0)
addhealth$asian<-Recode(addhealth$asian, recodes="1='asian'; 0='nonasian'; 6:8=NA",as.factor=T)
#Native American
addhealth$native_american <- ifelse(addhealth$H1GI6C==1,1,0)
addhealth$native_american<-Recode(addhealth$native_american, recodes="1='native_american'; 0='nonnative_american'; 6:8=NA",as.factor=T)
#other
addhealth$other <- ifelse(addhealth$H1GI6E==1,1,0)
addhealth$other<-Recode(addhealth$other, recodes="1='other'; 0='nonother'; 6:8=NA",as.factor=T)
#combine race to one variable
addhealth$racethnic <- factor(ifelse(addhealth$nhwhite=="nhwhite","a-nhwhite", 
                                            ifelse(addhealth$nhblack=="nhblack", "b-nhblack", 
                                            ifelse(addhealth$hispanic=="hispanic", "c-hispanic",
                                                   ifelse(addhealth$asian=="asian","d-asian",
                                                          ifelse(addhealth$native_american=="native_american","e-native_american",
                                                                 ifelse(addhealth$other=="other","f-other",NA)))))))

#Education.  Less then high school is reference group
addhealth$educ<-Recode(addhealth$H4ED2,recodes="1:2='a_less_highschool';3:6='b_highschool_grad';7='c_college_bach';8:13='d_college+';else=NA",as.factor=T)
#income variable
addhealth$incomeW4<-Recode(addhealth$H4EC1,recodes="1:5='a_<$25k';6:8='b_$25k>$50k';9:10='c_$50k>$100k';11:12='e_$100k+';else=NA",as.factor=T)
#transition
addhealth$W1.jumped.beatenup<-Recode(addhealth$H1FV6, recodes="0='a.no'; 1:2='b.yes';else=NA")
addhealth$W3.jumped1<-ifelse(addhealth$H3DS18F==1,1,
                                  ifelse(addhealth$H3DS18F==0,0,NA))
addhealth$W3.jumped2<-ifelse(addhealth$H3DS18G==1,1,
                                  ifelse(addhealth$H3DS18G==0,0,NA))
addhealth$transition.w1<-ifelse(addhealth$W1.jumped.beatenup=="a.no"&addhealth$W3.jumped1==1|addhealth$W3.jumped2==1,1,0)
addhealth$W4.jumped.beatenup<-Recode(addhealth$H4DS18, recodes="0='a.no'; 1='b.yes';else=NA")   
addhealth$transition<-ifelse(addhealth$transition.w1==0&addhealth$W4.jumped.beatenup=="b.yes",1,0)
table(addhealth$transition)                                             
## 
##    0    1 
## 8383 1003
#select variables to use
addhealth<-addhealth%>%
  select(psuscid,region,GSWGT4,agew1,agew3, agew4, sex,sexorient,racethnic,educ,incomeW4,transition,W4.married,transition.w1,physical.limits,w3.residence,incomeW4,UScitizen)
#filter complete cases
addhealth<-addhealth%>%
 filter(complete.cases(.))
adlong<-reshape(data.frame(addhealth), idvar = 'aid', varying=list(c('agew1', 'agew3'), c('agew3','agew4')),
                v.names = c('age_enter', 'age_exit'), 
                times = 1:2, direction='long')

adlong<-adlong[order(adlong$aid, adlong$time),]
head(adlong)
adlong$trans<-NA
adlong$trans[adlong$transition.w1==0& adlong$time==1]<-0
adlong$trans[adlong$transition.w1==1& adlong$time==1]<-1
adlong$trans[adlong$transition==0& adlong$time==2]<-0
adlong$trans[adlong$transition==1& adlong$time==2]<-1


adlong$racethnic_new<-as.factor(ifelse(adlong$racethnic%in%c("d-asian","e-native_american","f-other"), "other", adlong$racethnic))
adlong$racethnic_new<-Recode(adlong$racethnic_new, recodes = "1='a_white'; 2='b_black'; 3='c_hispanic'", as.factor=T)
library(survminer)
## Loading required package: ggplot2
## Registered S3 methods overwritten by 'ggplot2':
##   method         from 
##   [.quosures     rlang
##   c.quosures     rlang
##   print.quosures rlang
## Loading required package: ggpubr
## Loading required package: magrittr
library(survey)
## Loading required package: grid
## Loading required package: Matrix
## Loading required package: survival
## 
## Attaching package: 'survey'
## The following object is masked from 'package:graphics':
## 
##     dotchart
library(survival)
#Kaplan-Meier survival analysis of the outcome
fit.kaplan<-survfit(Surv(time = time , event=trans)~1,data=adlong)
summary(fit.kaplan)
## Call: survfit(formula = Surv(time = time, event = trans) ~ 1, data = adlong)
## 
##  time n.risk n.event survival  std.err lower 95% CI upper 95% CI
##     1  17268     210    0.988 0.000834        0.986        0.989
##     2   8634     925    0.882 0.003371        0.875        0.889
f1<-survfit(Surv(time = time , event=trans)~1, data=adlong)
summary(f1)
## Call: survfit(formula = Surv(time = time, event = trans) ~ 1, data = adlong)
## 
##  time n.risk n.event survival  std.err lower 95% CI upper 95% CI
##     1  17268     210    0.988 0.000834        0.986        0.989
##     2   8634     925    0.882 0.003371        0.875        0.889
ggsurvplot(f1,data = adlong,risk.table = T,title="Survival function for violence transition",ylim=c(.85,1))

library(muhaz)
haz<-kphaz.fit(time=adlong$time,status = adlong$trans,method = "product-limit")
kphaz.plot(haz,main="Hazard function plot")
data.frame(haz)
ggsurvplot(f1,data = adlong,risk.table = T,fun="cumhaz",title="Cumulative Hazard Function for violence transition")

#Kaplan-Meier survival analysis of the outcome across sexual orientation
fit.kaplan.LGB<-survfit(Surv(time = time , event=trans)~sexorient,data=adlong)
summary(fit.kaplan.LGB)
## Call: survfit(formula = Surv(time = time, event = trans) ~ sexorient, 
##     data = adlong)
## 
##                 sexorient=a_straight 
##  time n.risk n.event survival  std.err lower 95% CI upper 95% CI
##     1  16720     203    0.988 0.000847        0.986        0.990
##     2   8360     879    0.884 0.003400        0.877        0.891
## 
##                 sexorient=b_bisexual 
##  time n.risk n.event survival std.err lower 95% CI upper 95% CI
##     1    284       6    0.979 0.00853        0.962        0.996
##     2    142      25    0.807 0.03207        0.746        0.872
## 
##                 sexorient=c_LGB 
##  time n.risk n.event survival std.err lower 95% CI upper 95% CI
##     1    264       1    0.996 0.00378        0.989        1.000
##     2    132      21    0.838 0.03187        0.778        0.903
ggsurvplot(fit.kaplan.LGB,conf.int = T,risk.table = F,title="Survivorship Function for violence transition by sexual orientation",xlab="Wave of Survey",ylim=c(.85,1))
## Warning: Removed 2 rows containing missing values (geom_path).
## Warning: Removed 2 rows containing missing values (geom_point).
## Warning: Removed 2 rows containing missing values (geom_path).
## Warning: Removed 2 rows containing missing values (geom_point).

ggsurvplot(fit.kaplan.LGB,risk.table = T,fun="cumhaz",title="Cumulative Hazard Function for violence transition by sexual orientation")

  fit0 <- coxph(Surv(time = time , event=trans) ~ factor(sexorient), data=adlong,
  iter=0, na.action=na.exclude)
  o.minus.e <- tapply(resid(fit0), adlong$sexorient, sum)
  obs       <- tapply(adlong$transition, adlong$sexorient, sum)
  cbind(observed=obs, expected= obs- o.minus.e, "o-e"=o.minus.e) 
##            observed   expected        o-e
## a_straight     1758 1775.94266 -17.942658
## b_bisexual       50   37.08701  12.912995
## c_LGB            42   36.97034   5.029664

C) Carry out the following analysis

a. Fit the Cox model the data.

#Survey design
library(survey)
des2<-svydesign(ids=~psuscid,
                strata = ~region,
                weights=~GSWGT4,
                data=adlong,
                nest=T)
#fit to cox model
library(eha)
fit.cox<-coxreg(Surv(time = time,event = trans)~sex+sexorient+racethnic_new+physical.limits+UScitizen+educ+W4.married+incomeW4+w3.residence,data = adlong)
summary(fit.cox)
## Call:
## coxreg(formula = Surv(time = time, event = trans) ~ sex + sexorient + 
##     racethnic_new + physical.limits + UScitizen + educ + W4.married + 
##     incomeW4 + w3.residence, data = adlong)
## 
## Covariate           Mean       Coef     Rel.Risk   S.E.    Wald p
## sex 
##           a_male    0.454     0         1 (reference)
##         b_female    0.546    -0.022     0.979     0.061     0.726 
## sexorient 
##       a_straight    0.968     0         1 (reference)
##       b_bisexual    0.016     0.510     1.666     0.184     0.006 
##            c_LGB    0.015     0.296     1.345     0.218     0.173 
## racethnic_new 
##          a_white    0.660     0         1 (reference)
##          b_black    0.197     0.193     1.213     0.076     0.011 
##       c_hispanic    0.074     0.238     1.269     0.111     0.032 
##            other    0.070     0.088     1.092     0.132     0.506 
## physical.limits 
##    a_not_limited    0.916     0         1 (reference)
##        b_limited    0.084     0.048     1.050     0.103     0.638 
## UScitizen 
##             a_no    0.057     0         1 (reference)
##            b_yes    0.943     0.148     1.160     0.147     0.312 
## educ 
## a_less_highschoo    0.066     0         1 (reference)
## b_highschool_gra    0.579    -0.255     0.775     0.106     0.016 
##   c_college_bach    0.218    -0.414     0.661     0.127     0.001 
##       d_college+    0.136    -0.444     0.642     0.139     0.001 
## W4.married 
##  a_never married    0.505     0         1 (reference)
##   b_married_once    0.459     0.086     1.090     0.065     0.182 
## c_married_twice+    0.036     0.217     1.242     0.151     0.153 
## incomeW4 
##          a_<$25k    0.153     0         1 (reference)
##      b_$25k>$50k    0.279    -0.175     0.840     0.090     0.051 
##     c_$50k>$100k    0.407    -0.264     0.768     0.089     0.003 
##         e_$100k+    0.161    -0.157     0.854     0.110     0.153 
## w3.residence 
##    a_withparents    0.410     0         1 (reference)
##    b_withsomeone    0.054     0.133     1.142     0.129     0.301 
##     c_myownplace    0.473     0.081     1.085     0.066     0.215 
##     d_group.qrts    0.056    -0.016     0.984     0.151     0.915 
##       e_homeless    0.000     1.617     5.040     0.713     0.023 
##          f_other    0.006     0.512     1.668     0.306     0.094 
## 
## Events                    1135 
## Total time at risk         25902 
## Max. log. likelihood      -10347 
## LR test statistic         66.09 
## Degrees of freedom        21 
## Overall p-value           1.46731e-06
plot(survfit(fit.cox,conf.int = F),ylab = "S(t)",xlab="Age",ylim=c(.85,1))

###i. Include all main effects in the model

#Cox model with all main effects in the model
fit1<-svycoxph(Surv(time=time,event=trans)~sex+sexorient+racethnic_new+physical.limits+UScitizen+educ+W4.married+incomeW4+w3.residence,design=des2)
summary(fit1)
## Stratified 1 - level Cluster Sampling design (with replacement)
## With (132) clusters.
## svydesign(ids = ~psuscid, strata = ~region, weights = ~GSWGT4, 
##     data = adlong, nest = T)
## Call:
## svycoxph(formula = Surv(time = time, event = trans) ~ sex + sexorient + 
##     racethnic_new + physical.limits + UScitizen + educ + W4.married + 
##     incomeW4 + w3.residence, design = des2)
## 
##   n= 17268, number of events= 1135 
## 
##                                coef exp(coef) se(coef)      z Pr(>|z|)   
## sexb_female                -0.06789   0.93436  0.07674 -0.885  0.37628   
## sexorientb_bisexual         0.52443   1.68950  0.22043  2.379  0.01735 * 
## sexorientc_LGB              0.29857   1.34793  0.24210  1.233  0.21748   
## racethnic_newb_black        0.28495   1.32969  0.08798  3.239  0.00120 **
## racethnic_newc_hispanic     0.30618   1.35823  0.13959  2.193  0.02828 * 
## racethnic_newother          0.14362   1.15444  0.22269  0.645  0.51898   
## physical.limitsb_limited    0.06730   1.06961  0.11819  0.569  0.56907   
## UScitizenb_yes              0.10918   1.11536  0.22079  0.494  0.62096   
## educb_highschool_grad      -0.16793   0.84541  0.15745 -1.067  0.28615   
## educc_college_bach         -0.36426   0.69471  0.18271 -1.994  0.04619 * 
## educd_college+             -0.37385   0.68808  0.19375 -1.929  0.05367 . 
## W4.marriedb_married_once    0.07789   1.08101  0.08714  0.894  0.37141   
## W4.marriedc_married_twice+  0.34543   1.41260  0.17375  1.988  0.04680 * 
## incomeW4b_$25k>$50k        -0.17424   0.84009  0.10467 -1.665  0.09597 . 
## incomeW4c_$50k>$100k       -0.27972   0.75599  0.10511 -2.661  0.00779 **
## incomeW4e_$100k+           -0.18443   0.83158  0.15153 -1.217  0.22356   
## w3.residenceb_withsomeone   0.12171   1.12943  0.15344  0.793  0.42765   
## w3.residencec_myownplace    0.06102   1.06292  0.07244  0.842  0.39958   
## w3.residenced_group.qrts    0.01925   1.01944  0.19944  0.097  0.92309   
## w3.residencee_homeless      0.37479   1.45468  0.99266  0.378  0.70576   
## w3.residencef_other         0.43168   1.53984  0.32488  1.329  0.18394   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##                            exp(coef) exp(-coef) lower .95 upper .95
## sexb_female                   0.9344     1.0703    0.8039    1.0860
## sexorientb_bisexual           1.6895     0.5919    1.0968    2.6025
## sexorientc_LGB                1.3479     0.7419    0.8387    2.1664
## racethnic_newb_black          1.3297     0.7521    1.1191    1.5799
## racethnic_newc_hispanic       1.3582     0.7363    1.0331    1.7856
## racethnic_newother            1.1544     0.8662    0.7461    1.7862
## physical.limitsb_limited      1.0696     0.9349    0.8485    1.3484
## UScitizenb_yes                1.1154     0.8966    0.7236    1.7193
## educb_highschool_grad         0.8454     1.1829    0.6209    1.1510
## educc_college_bach            0.6947     1.4394    0.4856    0.9939
## educd_college+                0.6881     1.4533    0.4707    1.0059
## W4.marriedb_married_once      1.0810     0.9251    0.9113    1.2823
## W4.marriedc_married_twice+    1.4126     0.7079    1.0049    1.9857
## incomeW4b_$25k>$50k           0.8401     1.1903    0.6843    1.0314
## incomeW4c_$50k>$100k          0.7560     1.3228    0.6152    0.9289
## incomeW4e_$100k+              0.8316     1.2025    0.6179    1.1191
## w3.residenceb_withsomeone     1.1294     0.8854    0.8361    1.5257
## w3.residencec_myownplace      1.0629     0.9408    0.9222    1.2251
## w3.residenced_group.qrts      1.0194     0.9809    0.6896    1.5071
## w3.residencee_homeless        1.4547     0.6874    0.2079   10.1793
## w3.residencef_other           1.5398     0.6494    0.8146    2.9108
## 
## Concordance= 0.579  (se = 0.013 )
## Likelihood ratio test= NA  on 21 df,   p=NA
## Wald test            = 75.54  on 21 df,   p=4e-08
## Score (logrank) test = NA  on 21 df,   p=NA

ii. Test for an interaction between at least two of the predictors

#Cox model with all main effects in the model and an interaction between sex and sexual orientation
fit.interact1<-svycoxph(Surv(time=time,event=trans)~sex*sexorient+racethnic_new+physical.limits+UScitizen+educ+W4.married+incomeW4+w3.residence,design=des2)
summary(fit.interact1)
## Stratified 1 - level Cluster Sampling design (with replacement)
## With (132) clusters.
## svydesign(ids = ~psuscid, strata = ~region, weights = ~GSWGT4, 
##     data = adlong, nest = T)
## Call:
## svycoxph(formula = Surv(time = time, event = trans) ~ sex * sexorient + 
##     racethnic_new + physical.limits + UScitizen + educ + W4.married + 
##     incomeW4 + w3.residence, design = des2)
## 
##   n= 17268, number of events= 1135 
## 
##                                     coef exp(coef) se(coef)      z
## sexb_female                     -0.08344   0.91995  0.07688 -1.085
## sexorientb_bisexual             -0.35212   0.70319  0.91029 -0.387
## sexorientc_LGB                   0.18194   1.19954  0.33562  0.542
## racethnic_newb_black             0.28422   1.32872  0.08791  3.233
## racethnic_newc_hispanic          0.30517   1.35686  0.13945  2.188
## racethnic_newother               0.14615   1.15738  0.22171  0.659
## physical.limitsb_limited         0.06247   1.06446  0.11838  0.528
## UScitizenb_yes                   0.10537   1.11113  0.22006  0.479
## educb_highschool_grad           -0.16692   0.84627  0.15713 -1.062
## educc_college_bach              -0.36068   0.69720  0.18207 -1.981
## educd_college+                  -0.36689   0.69289  0.19341 -1.897
## W4.marriedb_married_once         0.07807   1.08120  0.08708  0.896
## W4.marriedc_married_twice+       0.34872   1.41726  0.17447  1.999
## incomeW4b_$25k>$50k             -0.17376   0.84050  0.10447 -1.663
## incomeW4c_$50k>$100k            -0.28295   0.75355  0.10578 -2.675
## incomeW4e_$100k+                -0.18821   0.82844  0.15182 -1.240
## w3.residenceb_withsomeone        0.11998   1.12748  0.15337  0.782
## w3.residencec_myownplace         0.06221   1.06419  0.07229  0.861
## w3.residenced_group.qrts         0.01639   1.01652  0.20004  0.082
## w3.residencee_homeless           0.37236   1.45116  0.99421  0.375
## w3.residencef_other              0.42853   1.53501  0.32460  1.320
## sexb_female:sexorientb_bisexual  0.97949   2.66309  0.92603  1.058
## sexb_female:sexorientc_LGB       0.30709   1.35947  0.55825  0.550
##                                 Pr(>|z|)   
## sexb_female                      0.27777   
## sexorientb_bisexual              0.69889   
## sexorientc_LGB                   0.58776   
## racethnic_newb_black             0.00122 **
## racethnic_newc_hispanic          0.02864 * 
## racethnic_newother               0.50975   
## physical.limitsb_limited         0.59770   
## UScitizenb_yes                   0.63205   
## educb_highschool_grad            0.28812   
## educc_college_bach               0.04759 * 
## educd_college+                   0.05784 . 
## W4.marriedb_married_once         0.37000   
## W4.marriedc_married_twice+       0.04564 * 
## incomeW4b_$25k>$50k              0.09626 . 
## incomeW4c_$50k>$100k             0.00747 **
## incomeW4e_$100k+                 0.21509   
## w3.residenceb_withsomeone        0.43403   
## w3.residencec_myownplace         0.38943   
## w3.residenced_group.qrts         0.93470   
## w3.residencee_homeless           0.70801   
## w3.residencef_other              0.18677   
## sexb_female:sexorientb_bisexual  0.29018   
## sexb_female:sexorientc_LGB       0.58225   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##                                 exp(coef) exp(-coef) lower .95 upper .95
## sexb_female                        0.9199     1.0870    0.7913    1.0696
## sexorientb_bisexual                0.7032     1.4221    0.1181    4.1871
## sexorientc_LGB                     1.1995     0.8337    0.6213    2.3158
## racethnic_newb_black               1.3287     0.7526    1.1184    1.5786
## racethnic_newc_hispanic            1.3569     0.7370    1.0324    1.7834
## racethnic_newother                 1.1574     0.8640    0.7495    1.7873
## physical.limitsb_limited           1.0645     0.9394    0.8440    1.3425
## UScitizenb_yes                     1.1111     0.9000    0.7219    1.7103
## educb_highschool_grad              0.8463     1.1817    0.6220    1.1515
## educc_college_bach                 0.6972     1.4343    0.4880    0.9962
## educd_college+                     0.6929     1.4432    0.4743    1.0123
## W4.marriedb_married_once           1.0812     0.9249    0.9115    1.2824
## W4.marriedc_married_twice+         1.4173     0.7056    1.0068    1.9951
## incomeW4b_$25k>$50k                0.8405     1.1898    0.6849    1.0315
## incomeW4c_$50k>$100k               0.7536     1.3270    0.6125    0.9272
## incomeW4e_$100k+                   0.8284     1.2071    0.6152    1.1156
## w3.residenceb_withsomeone          1.1275     0.8869    0.8348    1.5228
## w3.residencec_myownplace           1.0642     0.9397    0.9236    1.2262
## w3.residenced_group.qrts           1.0165     0.9837    0.6868    1.5045
## w3.residencee_homeless             1.4512     0.6891    0.2067   10.1857
## w3.residencef_other                1.5350     0.6515    0.8125    2.9001
## sexb_female:sexorientb_bisexual    2.6631     0.3755    0.4337   16.3540
## sexb_female:sexorientc_LGB         1.3595     0.7356    0.4552    4.0602
## 
## Concordance= 0.581  (se = 0.013 )
## Likelihood ratio test= NA  on 23 df,   p=NA
## Wald test            = 90.64  on 23 df,   p=6e-10
## Score (logrank) test = NA  on 23 df,   p=NA

iii. Perform a likelihood ratio test for two nested models

AIC(fit1)
##        eff.p          AIC     deltabar 
##    31.126260 20743.492968     1.482203
AIC(fit.interact1)
##        eff.p          AIC     deltabar 
##    34.099146 20749.438739     1.482572
regTermTest(fit1,~racethnic_new)
## Wald test for racethnic_new
##  in svycoxph(formula = Surv(time = time, event = trans) ~ sex + sexorient + 
##     racethnic_new + physical.limits + UScitizen + educ + W4.married + 
##     incomeW4 + w3.residence, design = des2)
## F =  4.272134  on  3  and  108  df: p= 0.0068339
regTermTest(fit.interact1,~racethnic_new)
## Wald test for racethnic_new
##  in svycoxph(formula = Surv(time = time, event = trans) ~ sex * sexorient + 
##     racethnic_new + physical.limits + UScitizen + educ + W4.married + 
##     incomeW4 + w3.residence, design = des2)
## F =  4.251747  on  3  and  106  df: p= 0.0070472
regTermTest(fit1,~racethnic_new,method="LRT")
## Working (Rao-Scott+F) LRT for racethnic_new
##  in svycoxph(formula = Surv(time = time, event = trans) ~ sex + sexorient + 
##     racethnic_new + physical.limits + UScitizen + educ + W4.married + 
##     incomeW4 + w3.residence, design = des2)
## Working 2logLR =  10.8118 p= 0.01784 
## (scale factors:  1.4 0.91 0.72 );  denominator df= 108
regTermTest(fit.interact1,~racethnic_new,method="LRT")
## Working (Rao-Scott+F) LRT for racethnic_new
##  in svycoxph(formula = Surv(time = time, event = trans) ~ sex * sexorient + 
##     racethnic_new + physical.limits + UScitizen + educ + W4.married + 
##     incomeW4 + w3.residence, design = des2)
## Working 2logLR =  10.80937 p= 0.017844 
## (scale factors:  1.4 0.92 0.73 );  denominator df= 106

D) Assess proportionality of hazards for each covariate

a. What method did you use?

#schoenfeld residuals
schoenresid<-resid(fit1,type = "schoenfeld")
fit.sr<-lm(schoenresid~des2$variables$time[des2$variables$trans==1])
summary(fit.sr)
## Response sexb_female :
## 
## Call:
## lm(formula = sexb_female ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.5793 -0.5377  0.4244  0.4623  0.4623 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                     0.12468    0.07072   1.763
## des2$variables$time[des2$variables$trans == 1] -0.03790    0.03810  -0.995
##                                                Pr(>|t|)  
## (Intercept)                                      0.0782 .
## des2$variables$time[des2$variables$trans == 1]   0.3201  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4984 on 1133 degrees of freedom
## Multiple R-squared:  0.0008724,  Adjusted R-squared:  -9.469e-06 
## F-statistic: 0.9893 on 1 and 1133 DF,  p-value: 0.3201
## 
## 
## Response sexorientb_bisexual :
## 
## Call:
## lm(formula = sexorientb_bisexual ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.02869 -0.02797 -0.02797 -0.02797  0.97631 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                    -0.007361   0.023144
## des2$variables$time[des2$variables$trans == 1]  0.004282   0.012469
##                                                t value Pr(>|t|)
## (Intercept)                                     -0.318    0.751
## des2$variables$time[des2$variables$trans == 1]   0.343    0.731
## 
## Residual standard error: 0.1631 on 1133 degrees of freedom
## Multiple R-squared:  0.0001041,  Adjusted R-squared:  -0.0007784 
## F-statistic: 0.1179 on 1 and 1133 DF,  p-value: 0.7313
## 
## 
## Response sexorientc_LGB :
## 
## Call:
## lm(formula = sexorientc_LGB ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.02325 -0.02258 -0.02258 -0.02258  0.99535 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.03210    0.01955  -1.642
## des2$variables$time[des2$variables$trans == 1]  0.01793    0.01054   1.701
##                                                Pr(>|t|)  
## (Intercept)                                      0.1009  
## des2$variables$time[des2$variables$trans == 1]   0.0891 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1378 on 1133 degrees of freedom
## Multiple R-squared:  0.002549,   Adjusted R-squared:  0.001668 
## F-statistic: 2.895 on 1 and 1133 DF,  p-value: 0.08913
## 
## 
## Response racethnic_newb_black :
## 
## Call:
## lm(formula = racethnic_newb_black ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.2409 -0.2243 -0.2210 -0.2210  0.7790 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                     0.07199    0.05926   1.215
## des2$variables$time[des2$variables$trans == 1] -0.01655    0.03193  -0.518
##                                                Pr(>|t|)
## (Intercept)                                       0.225
## des2$variables$time[des2$variables$trans == 1]    0.604
## 
## Residual standard error: 0.4177 on 1133 degrees of freedom
## Multiple R-squared:  0.000237,   Adjusted R-squared:  -0.0006454 
## F-statistic: 0.2686 on 1 and 1133 DF,  p-value: 0.6044
## 
## 
## Response racethnic_newc_hispanic :
## 
## Call:
## lm(formula = racethnic_newc_hispanic ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.10964 -0.08336 -0.08322 -0.08322  0.91678 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                     0.06238    0.04022   1.551
## des2$variables$time[des2$variables$trans == 1] -0.02628    0.02167  -1.213
##                                                Pr(>|t|)
## (Intercept)                                       0.121
## des2$variables$time[des2$variables$trans == 1]    0.225
## 
## Residual standard error: 0.2835 on 1133 degrees of freedom
## Multiple R-squared:  0.001297,   Adjusted R-squared:  0.0004151 
## F-statistic: 1.471 on 1 and 1133 DF,  p-value: 0.2255
## 
## 
## Response racethnic_newother :
## 
## Call:
## lm(formula = racethnic_newother ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.06671 -0.06383 -0.06383 -0.06383  0.93641 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                     0.027409   0.034834
## des2$variables$time[des2$variables$trans == 1] -0.002877   0.018768
##                                                t value Pr(>|t|)
## (Intercept)                                      0.787    0.432
## des2$variables$time[des2$variables$trans == 1]  -0.153    0.878
## 
## Residual standard error: 0.2455 on 1133 degrees of freedom
## Multiple R-squared:  2.075e-05,  Adjusted R-squared:  -0.0008618 
## F-statistic: 0.02351 on 1 and 1133 DF,  p-value: 0.8782
## 
## 
## Response physical.limitsb_limited :
## 
## Call:
## lm(formula = physical.limitsb_limited ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.1006 -0.1006 -0.1006 -0.0715  0.9289 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.05366    0.04164  -1.289
## des2$variables$time[des2$variables$trans == 1]  0.02912    0.02243   1.298
##                                                Pr(>|t|)
## (Intercept)                                       0.198
## des2$variables$time[des2$variables$trans == 1]    0.194
## 
## Residual standard error: 0.2935 on 1133 degrees of freedom
## Multiple R-squared:  0.001485,   Adjusted R-squared:  0.0006039 
## F-statistic: 1.685 on 1 and 1133 DF,  p-value: 0.1945
## 
## 
## Response UScitizenb_yes :
## 
## Call:
## lm(formula = UScitizenb_yes ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.94929  0.05071  0.05071  0.05126  0.05284 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                    -0.013729   0.031272
## des2$variables$time[des2$variables$trans == 1]  0.001583   0.016848
##                                                t value Pr(>|t|)
## (Intercept)                                     -0.439    0.661
## des2$variables$time[des2$variables$trans == 1]   0.094    0.925
## 
## Residual standard error: 0.2204 on 1133 degrees of freedom
## Multiple R-squared:  7.787e-06,  Adjusted R-squared:  -0.0008748 
## F-statistic: 0.008823 on 1 and 1133 DF,  p-value: 0.9252
## 
## 
## Response educb_highschool_grad :
## 
## Call:
## lm(formula = educb_highschool_grad ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.6131 -0.6131  0.3869  0.3869  0.4149 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.06596    0.06931  -0.952
## des2$variables$time[des2$variables$trans == 1]  0.02728    0.03734   0.730
##                                                Pr(>|t|)
## (Intercept)                                       0.342
## des2$variables$time[des2$variables$trans == 1]    0.465
## 
## Residual standard error: 0.4886 on 1133 degrees of freedom
## Multiple R-squared:  0.0004706,  Adjusted R-squared:  -0.0004116 
## F-statistic: 0.5335 on 1 and 1133 DF,  p-value: 0.4653
## 
## 
## Response educc_college_bach :
## 
## Call:
## lm(formula = educc_college_bach ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.1851 -0.1851 -0.1851 -0.1764  0.8247 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                    -0.001882   0.054930
## des2$variables$time[des2$variables$trans == 1]  0.008697   0.029595
##                                                t value Pr(>|t|)
## (Intercept)                                     -0.034    0.973
## des2$variables$time[des2$variables$trans == 1]   0.294    0.769
## 
## Residual standard error: 0.3872 on 1133 degrees of freedom
## Multiple R-squared:  7.622e-05,  Adjusted R-squared:  -0.0008063 
## F-statistic: 0.08636 on 1 and 1133 DF,  p-value: 0.7689
## 
## 
## Response educd_college+ :
## 
## Call:
## lm(formula = `educd_college+` ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.1239 -0.1103 -0.1103 -0.1101  0.8899 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                     0.03909    0.04491   0.870
## des2$variables$time[des2$variables$trans == 1] -0.01353    0.02420  -0.559
##                                                Pr(>|t|)
## (Intercept)                                       0.384
## des2$variables$time[des2$variables$trans == 1]    0.576
## 
## Residual standard error: 0.3165 on 1133 degrees of freedom
## Multiple R-squared:  0.000276,   Adjusted R-squared:  -0.0006063 
## F-statistic: 0.3128 on 1 and 1133 DF,  p-value: 0.5761
## 
## 
## Response W4.marriedb_married_once :
## 
## Call:
## lm(formula = W4.marriedb_married_once ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.4716 -0.4699 -0.4235  0.5301  0.5765 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.06736    0.07075  -0.952
## des2$variables$time[des2$variables$trans == 1]  0.04642    0.03812   1.218
##                                                Pr(>|t|)
## (Intercept)                                       0.341
## des2$variables$time[des2$variables$trans == 1]    0.224
## 
## Residual standard error: 0.4987 on 1133 degrees of freedom
## Multiple R-squared:  0.001307,   Adjusted R-squared:  0.0004258 
## F-statistic: 1.483 on 1 and 1133 DF,  p-value: 0.2236
## 
## 
## Response W4.marriedc_married_twice+ :
## 
## Call:
## lm(formula = `W4.marriedc_married_twice+` ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.05276 -0.04253 -0.04208 -0.04208  0.95792 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                     0.01242    0.02913   0.426
## des2$variables$time[des2$variables$trans == 1] -0.01023    0.01570  -0.652
##                                                Pr(>|t|)
## (Intercept)                                       0.670
## des2$variables$time[des2$variables$trans == 1]    0.515
## 
## Residual standard error: 0.2054 on 1133 degrees of freedom
## Multiple R-squared:  0.0003747,  Adjusted R-squared:  -0.0005076 
## F-statistic: 0.4246 on 1 and 1133 DF,  p-value: 0.5148
## 
## 
## Response incomeW4b_$25k>$50k :
## 
## Call:
## lm(formula = `incomeW4b_$25k>$50k` ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.3333 -0.2746 -0.2746  0.6667  0.7255 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                     0.09549    0.06405   1.491
## des2$variables$time[des2$variables$trans == 1] -0.05874    0.03451  -1.702
##                                                Pr(>|t|)  
## (Intercept)                                       0.136  
## des2$variables$time[des2$variables$trans == 1]    0.089 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4515 on 1133 degrees of freedom
## Multiple R-squared:  0.00255,    Adjusted R-squared:  0.00167 
## F-statistic: 2.897 on 1 and 1133 DF,  p-value: 0.08901
## 
## 
## Response incomeW4c_$50k>$100k :
## 
## Call:
## lm(formula = `incomeW4c_$50k>$100k` ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.3788 -0.3788 -0.3766  0.6212  0.6876 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.10386    0.06833  -1.520
## des2$variables$time[des2$variables$trans == 1]  0.06414    0.03681   1.742
##                                                Pr(>|t|)  
## (Intercept)                                      0.1288  
## des2$variables$time[des2$variables$trans == 1]   0.0817 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4816 on 1133 degrees of freedom
## Multiple R-squared:  0.002672,   Adjusted R-squared:  0.001792 
## F-statistic: 3.036 on 1 and 1133 DF,  p-value: 0.08171
## 
## 
## Response incomeW4e_$100k+ :
## 
## Call:
## lm(formula = `incomeW4e_$100k+` ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.1572 -0.1503 -0.1503 -0.1500  0.8500 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                     0.028839   0.050916
## des2$variables$time[des2$variables$trans == 1] -0.006865   0.027432
##                                                t value Pr(>|t|)
## (Intercept)                                      0.566    0.571
## des2$variables$time[des2$variables$trans == 1]  -0.250    0.802
## 
## Residual standard error: 0.3589 on 1133 degrees of freedom
## Multiple R-squared:  5.527e-05,  Adjusted R-squared:  -0.0008273 
## F-statistic: 0.06263 on 1 and 1133 DF,  p-value: 0.8024
## 
## 
## Response w3.residenceb_withsomeone :
## 
## Call:
## lm(formula = w3.residenceb_withsomeone ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.07676 -0.06002 -0.05933 -0.05933  0.94067 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                     0.03248    0.03437   0.945
## des2$variables$time[des2$variables$trans == 1] -0.01675    0.01852  -0.904
##                                                Pr(>|t|)
## (Intercept)                                       0.345
## des2$variables$time[des2$variables$trans == 1]    0.366
## 
## Residual standard error: 0.2423 on 1133 degrees of freedom
## Multiple R-squared:  0.0007211,  Adjusted R-squared:  -0.0001609 
## F-statistic: 0.8176 on 1 and 1133 DF,  p-value: 0.3661
## 
## 
## Response w3.residencec_myownplace :
## 
## Call:
## lm(formula = w3.residencec_myownplace ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.4952 -0.4924 -0.4662  0.5075  0.5338 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.04322    0.07098  -0.609
## des2$variables$time[des2$variables$trans == 1]  0.02624    0.03824   0.686
##                                                Pr(>|t|)
## (Intercept)                                       0.543
## des2$variables$time[des2$variables$trans == 1]    0.493
## 
## Residual standard error: 0.5003 on 1133 degrees of freedom
## Multiple R-squared:  0.0004155,  Adjusted R-squared:  -0.0004667 
## F-statistic: 0.471 on 1 and 1133 DF,  p-value: 0.4927
## 
## 
## Response w3.residenced_group.qrts :
## 
## Call:
## lm(formula = w3.residenced_group.qrts ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.04764 -0.04764 -0.04764 -0.04728  0.96185 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.01670    0.02969  -0.563
## des2$variables$time[des2$variables$trans == 1]  0.00948    0.01599   0.593
##                                                Pr(>|t|)
## (Intercept)                                       0.574
## des2$variables$time[des2$variables$trans == 1]    0.553
## 
## Residual standard error: 0.2092 on 1133 degrees of freedom
## Multiple R-squared:  0.00031,    Adjusted R-squared:  -0.0005723 
## F-statistic: 0.3514 on 1 and 1133 DF,  p-value: 0.5535
## 
## 
## Response w3.residencee_homeless :
## 
## Call:
## lm(formula = w3.residencee_homeless ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.00217 -0.00217 -0.00217 -0.00213  0.99787 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                    -0.003141   0.005954
## des2$variables$time[des2$variables$trans == 1]  0.002163   0.003208
##                                                t value Pr(>|t|)
## (Intercept)                                     -0.528    0.598
## des2$variables$time[des2$variables$trans == 1]   0.674    0.500
## 
## Residual standard error: 0.04197 on 1133 degrees of freedom
## Multiple R-squared:  0.0004011,  Adjusted R-squared:  -0.0004812 
## F-statistic: 0.4546 on 1 and 1133 DF,  p-value: 0.5003
## 
## 
## Response w3.residencef_other :
## 
## Call:
## lm(formula = w3.residencef_other ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.01441 -0.00879 -0.00879 -0.00879  0.99198 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                     0.010246   0.013912
## des2$variables$time[des2$variables$trans == 1] -0.005620   0.007495
##                                                t value Pr(>|t|)
## (Intercept)                                      0.736    0.462
## des2$variables$time[des2$variables$trans == 1]  -0.750    0.454
## 
## Residual standard error: 0.09806 on 1133 degrees of freedom
## Multiple R-squared:  0.0004959,  Adjusted R-squared:  -0.0003863 
## F-statistic: 0.5621 on 1 and 1133 DF,  p-value: 0.4536
#schoenfeld residuals for interaction model
schoenresid2<-resid(fit.interact1,type = "schoenfeld")
fit.sr2<-lm(schoenresid2~des2$variables$time[des2$variables$trans==1])
summary(fit.sr2)
## Response sexb_female :
## 
## Call:
## lm(formula = sexb_female ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.5794 -0.5377  0.4244  0.4623  0.4623 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                     0.12468    0.07072   1.763
## des2$variables$time[des2$variables$trans == 1] -0.03790    0.03810  -0.995
##                                                Pr(>|t|)  
## (Intercept)                                      0.0782 .
## des2$variables$time[des2$variables$trans == 1]   0.3201  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4985 on 1133 degrees of freedom
## Multiple R-squared:  0.0008724,  Adjusted R-squared:  -9.396e-06 
## F-statistic: 0.9893 on 1 and 1133 DF,  p-value: 0.3201
## 
## 
## Response sexorientb_bisexual :
## 
## Call:
## lm(formula = sexorientb_bisexual ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.02875 -0.02796 -0.02796 -0.02796  0.97632 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                    -0.007356   0.023144
## des2$variables$time[des2$variables$trans == 1]  0.004281   0.012469
##                                                t value Pr(>|t|)
## (Intercept)                                     -0.318    0.751
## des2$variables$time[des2$variables$trans == 1]   0.343    0.731
## 
## Residual standard error: 0.1631 on 1133 degrees of freedom
## Multiple R-squared:  0.000104,   Adjusted R-squared:  -0.0007785 
## F-statistic: 0.1179 on 1 and 1133 DF,  p-value: 0.7314
## 
## 
## Response sexorientc_LGB :
## 
## Call:
## lm(formula = sexorientc_LGB ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.02326 -0.02257 -0.02257 -0.02257  0.99535 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.03210    0.01955  -1.642
## des2$variables$time[des2$variables$trans == 1]  0.01793    0.01054   1.701
##                                                Pr(>|t|)  
## (Intercept)                                      0.1009  
## des2$variables$time[des2$variables$trans == 1]   0.0891 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1378 on 1133 degrees of freedom
## Multiple R-squared:  0.002549,   Adjusted R-squared:  0.001668 
## F-statistic: 2.895 on 1 and 1133 DF,  p-value: 0.08914
## 
## 
## Response racethnic_newb_black :
## 
## Call:
## lm(formula = racethnic_newb_black ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.2409 -0.2243 -0.2210 -0.2210  0.7790 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                     0.07200    0.05926   1.215
## des2$variables$time[des2$variables$trans == 1] -0.01655    0.03193  -0.518
##                                                Pr(>|t|)
## (Intercept)                                       0.225
## des2$variables$time[des2$variables$trans == 1]    0.604
## 
## Residual standard error: 0.4177 on 1133 degrees of freedom
## Multiple R-squared:  0.000237,   Adjusted R-squared:  -0.0006454 
## F-statistic: 0.2686 on 1 and 1133 DF,  p-value: 0.6044
## 
## 
## Response racethnic_newc_hispanic :
## 
## Call:
## lm(formula = racethnic_newc_hispanic ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.10963 -0.08335 -0.08322 -0.08322  0.91678 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                     0.06238    0.04022   1.551
## des2$variables$time[des2$variables$trans == 1] -0.02628    0.02167  -1.213
##                                                Pr(>|t|)
## (Intercept)                                       0.121
## des2$variables$time[des2$variables$trans == 1]    0.225
## 
## Residual standard error: 0.2835 on 1133 degrees of freedom
## Multiple R-squared:  0.001297,   Adjusted R-squared:  0.0004151 
## F-statistic: 1.471 on 1 and 1133 DF,  p-value: 0.2255
## 
## 
## Response racethnic_newother :
## 
## Call:
## lm(formula = racethnic_newother ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.06671 -0.06383 -0.06383 -0.06383  0.93642 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                     0.027408   0.034834
## des2$variables$time[des2$variables$trans == 1] -0.002877   0.018768
##                                                t value Pr(>|t|)
## (Intercept)                                      0.787    0.432
## des2$variables$time[des2$variables$trans == 1]  -0.153    0.878
## 
## Residual standard error: 0.2455 on 1133 degrees of freedom
## Multiple R-squared:  2.074e-05,  Adjusted R-squared:  -0.0008619 
## F-statistic: 0.0235 on 1 and 1133 DF,  p-value: 0.8782
## 
## 
## Response physical.limitsb_limited :
## 
## Call:
## lm(formula = physical.limitsb_limited ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.10061 -0.10061 -0.10061 -0.07149  0.92888 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.05365    0.04164  -1.289
## des2$variables$time[des2$variables$trans == 1]  0.02912    0.02243   1.298
##                                                Pr(>|t|)
## (Intercept)                                       0.198
## des2$variables$time[des2$variables$trans == 1]    0.195
## 
## Residual standard error: 0.2935 on 1133 degrees of freedom
## Multiple R-squared:  0.001485,   Adjusted R-squared:  0.0006037 
## F-statistic: 1.685 on 1 and 1133 DF,  p-value: 0.1945
## 
## 
## Response UScitizenb_yes :
## 
## Call:
## lm(formula = UScitizenb_yes ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.94929  0.05071  0.05071  0.05125  0.05284 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                    -0.013729   0.031271
## des2$variables$time[des2$variables$trans == 1]  0.001582   0.016848
##                                                t value Pr(>|t|)
## (Intercept)                                     -0.439    0.661
## des2$variables$time[des2$variables$trans == 1]   0.094    0.925
## 
## Residual standard error: 0.2204 on 1133 degrees of freedom
## Multiple R-squared:  7.786e-06,  Adjusted R-squared:  -0.0008748 
## F-statistic: 0.008822 on 1 and 1133 DF,  p-value: 0.9252
## 
## 
## Response educb_highschool_grad :
## 
## Call:
## lm(formula = educb_highschool_grad ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.6131 -0.6131  0.3869  0.3869  0.4149 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.06596    0.06931  -0.952
## des2$variables$time[des2$variables$trans == 1]  0.02728    0.03735   0.730
##                                                Pr(>|t|)
## (Intercept)                                       0.342
## des2$variables$time[des2$variables$trans == 1]    0.465
## 
## Residual standard error: 0.4886 on 1133 degrees of freedom
## Multiple R-squared:  0.0004706,  Adjusted R-squared:  -0.0004116 
## F-statistic: 0.5335 on 1 and 1133 DF,  p-value: 0.4653
## 
## 
## Response educc_college_bach :
## 
## Call:
## lm(formula = educc_college_bach ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.1851 -0.1851 -0.1851 -0.1764  0.8247 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                    -0.001882   0.054930
## des2$variables$time[des2$variables$trans == 1]  0.008697   0.029595
##                                                t value Pr(>|t|)
## (Intercept)                                     -0.034    0.973
## des2$variables$time[des2$variables$trans == 1]   0.294    0.769
## 
## Residual standard error: 0.3872 on 1133 degrees of freedom
## Multiple R-squared:  7.622e-05,  Adjusted R-squared:  -0.0008063 
## F-statistic: 0.08636 on 1 and 1133 DF,  p-value: 0.7689
## 
## 
## Response educd_college+ :
## 
## Call:
## lm(formula = `educd_college+` ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.1239 -0.1103 -0.1103 -0.1101  0.8899 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                     0.03909    0.04491   0.870
## des2$variables$time[des2$variables$trans == 1] -0.01353    0.02420  -0.559
##                                                Pr(>|t|)
## (Intercept)                                       0.384
## des2$variables$time[des2$variables$trans == 1]    0.576
## 
## Residual standard error: 0.3165 on 1133 degrees of freedom
## Multiple R-squared:  0.000276,   Adjusted R-squared:  -0.0006063 
## F-statistic: 0.3128 on 1 and 1133 DF,  p-value: 0.5761
## 
## 
## Response W4.marriedb_married_once :
## 
## Call:
## lm(formula = W4.marriedb_married_once ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.4716 -0.4700 -0.4235  0.5300  0.5765 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.06737    0.07075  -0.952
## des2$variables$time[des2$variables$trans == 1]  0.04642    0.03812   1.218
##                                                Pr(>|t|)
## (Intercept)                                       0.341
## des2$variables$time[des2$variables$trans == 1]    0.224
## 
## Residual standard error: 0.4987 on 1133 degrees of freedom
## Multiple R-squared:  0.001307,   Adjusted R-squared:  0.0004259 
## F-statistic: 1.483 on 1 and 1133 DF,  p-value: 0.2235
## 
## 
## Response W4.marriedc_married_twice+ :
## 
## Call:
## lm(formula = `W4.marriedc_married_twice+` ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.05276 -0.04253 -0.04208 -0.04208  0.95792 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                     0.01242    0.02913   0.426
## des2$variables$time[des2$variables$trans == 1] -0.01023    0.01570  -0.652
##                                                Pr(>|t|)
## (Intercept)                                       0.670
## des2$variables$time[des2$variables$trans == 1]    0.515
## 
## Residual standard error: 0.2054 on 1133 degrees of freedom
## Multiple R-squared:  0.0003747,  Adjusted R-squared:  -0.0005076 
## F-statistic: 0.4247 on 1 and 1133 DF,  p-value: 0.5148
## 
## 
## Response incomeW4b_$25k>$50k :
## 
## Call:
## lm(formula = `incomeW4b_$25k>$50k` ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.3333 -0.2746 -0.2746  0.6666  0.7255 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                     0.09548    0.06405   1.491
## des2$variables$time[des2$variables$trans == 1] -0.05874    0.03451  -1.702
##                                                Pr(>|t|)  
## (Intercept)                                       0.136  
## des2$variables$time[des2$variables$trans == 1]    0.089 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4515 on 1133 degrees of freedom
## Multiple R-squared:  0.00255,    Adjusted R-squared:  0.00167 
## F-statistic: 2.897 on 1 and 1133 DF,  p-value: 0.08902
## 
## 
## Response incomeW4c_$50k>$100k :
## 
## Call:
## lm(formula = `incomeW4c_$50k>$100k` ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.3788 -0.3788 -0.3766  0.6212  0.6876 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.10386    0.06833  -1.520
## des2$variables$time[des2$variables$trans == 1]  0.06414    0.03681   1.742
##                                                Pr(>|t|)  
## (Intercept)                                      0.1288  
## des2$variables$time[des2$variables$trans == 1]   0.0817 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4816 on 1133 degrees of freedom
## Multiple R-squared:  0.002672,   Adjusted R-squared:  0.001792 
## F-statistic: 3.036 on 1 and 1133 DF,  p-value: 0.08171
## 
## 
## Response incomeW4e_$100k+ :
## 
## Call:
## lm(formula = `incomeW4e_$100k+` ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.1572 -0.1503 -0.1503 -0.1500  0.8500 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                     0.028837   0.050916
## des2$variables$time[des2$variables$trans == 1] -0.006865   0.027432
##                                                t value Pr(>|t|)
## (Intercept)                                      0.566    0.571
## des2$variables$time[des2$variables$trans == 1]  -0.250    0.802
## 
## Residual standard error: 0.3589 on 1133 degrees of freedom
## Multiple R-squared:  5.527e-05,  Adjusted R-squared:  -0.0008273 
## F-statistic: 0.06262 on 1 and 1133 DF,  p-value: 0.8024
## 
## 
## Response w3.residenceb_withsomeone :
## 
## Call:
## lm(formula = w3.residenceb_withsomeone ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.07676 -0.06002 -0.05933 -0.05933  0.94067 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                     0.03248    0.03437   0.945
## des2$variables$time[des2$variables$trans == 1] -0.01675    0.01852  -0.904
##                                                Pr(>|t|)
## (Intercept)                                       0.345
## des2$variables$time[des2$variables$trans == 1]    0.366
## 
## Residual standard error: 0.2423 on 1133 degrees of freedom
## Multiple R-squared:  0.0007211,  Adjusted R-squared:  -0.0001609 
## F-statistic: 0.8176 on 1 and 1133 DF,  p-value: 0.3661
## 
## 
## Response w3.residencec_myownplace :
## 
## Call:
## lm(formula = w3.residencec_myownplace ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.4952 -0.4924 -0.4662  0.5075  0.5338 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.04322    0.07098  -0.609
## des2$variables$time[des2$variables$trans == 1]  0.02624    0.03824   0.686
##                                                Pr(>|t|)
## (Intercept)                                       0.543
## des2$variables$time[des2$variables$trans == 1]    0.493
## 
## Residual standard error: 0.5003 on 1133 degrees of freedom
## Multiple R-squared:  0.0004155,  Adjusted R-squared:  -0.0004668 
## F-statistic: 0.4709 on 1 and 1133 DF,  p-value: 0.4927
## 
## 
## Response w3.residenced_group.qrts :
## 
## Call:
## lm(formula = w3.residenced_group.qrts ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.04764 -0.04764 -0.04764 -0.04728  0.96184 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.01670    0.02969  -0.563
## des2$variables$time[des2$variables$trans == 1]  0.00948    0.01599   0.593
##                                                Pr(>|t|)
## (Intercept)                                       0.574
## des2$variables$time[des2$variables$trans == 1]    0.553
## 
## Residual standard error: 0.2092 on 1133 degrees of freedom
## Multiple R-squared:  0.00031,    Adjusted R-squared:  -0.0005723 
## F-statistic: 0.3514 on 1 and 1133 DF,  p-value: 0.5535
## 
## 
## Response w3.residencee_homeless :
## 
## Call:
## lm(formula = w3.residencee_homeless ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.00217 -0.00217 -0.00217 -0.00213  0.99787 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                    -0.003141   0.005954
## des2$variables$time[des2$variables$trans == 1]  0.002163   0.003208
##                                                t value Pr(>|t|)
## (Intercept)                                     -0.528    0.598
## des2$variables$time[des2$variables$trans == 1]   0.674    0.500
## 
## Residual standard error: 0.04197 on 1133 degrees of freedom
## Multiple R-squared:  0.0004011,  Adjusted R-squared:  -0.0004812 
## F-statistic: 0.4546 on 1 and 1133 DF,  p-value: 0.5003
## 
## 
## Response w3.residencef_other :
## 
## Call:
## lm(formula = w3.residencef_other ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.01442 -0.00880 -0.00880 -0.00880  0.99198 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                     0.010245   0.013912
## des2$variables$time[des2$variables$trans == 1] -0.005620   0.007496
##                                                t value Pr(>|t|)
## (Intercept)                                      0.736    0.462
## des2$variables$time[des2$variables$trans == 1]  -0.750    0.454
## 
## Residual standard error: 0.09806 on 1133 degrees of freedom
## Multiple R-squared:  0.0004959,  Adjusted R-squared:  -0.0003863 
## F-statistic: 0.5621 on 1 and 1133 DF,  p-value: 0.4536
## 
## 
## Response sexb_female:sexorientb_bisexual :
## 
## Call:
## lm(formula = `sexb_female:sexorientb_bisexual` ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.02658 -0.02580 -0.02580 -0.02580  0.97632 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                    -0.003547   0.022406
## des2$variables$time[des2$variables$trans == 1]  0.002119   0.012072
##                                                t value Pr(>|t|)
## (Intercept)                                     -0.158    0.874
## des2$variables$time[des2$variables$trans == 1]   0.176    0.861
## 
## Residual standard error: 0.1579 on 1133 degrees of freedom
## Multiple R-squared:  2.719e-05,  Adjusted R-squared:  -0.0008554 
## F-statistic: 0.0308 on 1 and 1133 DF,  p-value: 0.8607
## 
## 
## Response sexb_female:sexorientc_LGB :
## 
## Call:
## lm(formula = `sexb_female:sexorientc_LGB` ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.00893 -0.00858 -0.00858 -0.00858  0.99142 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                    -0.016366   0.011870
## des2$variables$time[des2$variables$trans == 1]  0.008641   0.006395
##                                                t value Pr(>|t|)
## (Intercept)                                     -1.379    0.168
## des2$variables$time[des2$variables$trans == 1]   1.351    0.177
## 
## Residual standard error: 0.08367 on 1133 degrees of freedom
## Multiple R-squared:  0.001609,   Adjusted R-squared:  0.0007274 
## F-statistic: 1.825 on 1 and 1133 DF,  p-value: 0.1769
#Grambsch and Therneau
fit.test<-cox.zph(fit1)
fit.test
##                                 rho   chisq        p
## sexb_female                 0.18530  76.845 1.85e-18
## sexorientb_bisexual         0.07373  12.885 3.31e-04
## sexorientc_LGB              0.00758   0.108 7.43e-01
## racethnic_newb_black        0.08895  19.511 1.00e-05
## racethnic_newc_hispanic    -0.06905  11.631 6.48e-04
## racethnic_newother         -0.03985   5.380 2.04e-02
## physical.limitsb_limited   -0.05023   5.476 1.93e-02
## UScitizenb_yes             -0.09771  31.262 2.25e-08
## educb_highschool_grad      -0.01390   0.548 4.59e-01
## educc_college_bach          0.03112   2.535 1.11e-01
## educd_college+              0.03448   2.839 9.20e-02
## W4.marriedb_married_once    0.11873  36.956 1.21e-09
## W4.marriedc_married_twice+  0.03974   2.678 1.02e-01
## incomeW4b_$25k>$50k         0.02098   0.919 3.38e-01
## incomeW4c_$50k>$100k        0.04379   3.741 5.31e-02
## incomeW4e_$100k+            0.05238   7.019 8.07e-03
## w3.residenceb_withsomeone   0.05985   7.778 5.29e-03
## w3.residencec_myownplace    0.08362  12.183 4.82e-04
## w3.residenced_group.qrts    0.04495   5.430 1.98e-02
## w3.residencee_homeless     -0.00891   0.196 6.58e-01
## w3.residencef_other        -0.08686  12.246 4.66e-04
## GLOBAL                           NA 206.222 2.15e-32
#Martingale residuals
res.mar<-resid(fit1,type="martingale")
scatter.smooth(des2$variables$sexorient,res.mar,degree=2,span=1,ylab="Martingale Residual",col=1,cex=.5,lpars=list(col="red",lwd=3))
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : pseudoinverse used at 0.99
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : neighborhood radius 2.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : There are other near singularities as well. 4.0401
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : pseudoinverse used at 0.99
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : neighborhood radius 2.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : There are other near singularities as well. 4.0401
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : pseudoinverse used at 0.99
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : neighborhood radius 2.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : There are other near singularities as well. 4.0401
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : pseudoinverse used at 0.99
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : neighborhood radius 2.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : There are other near singularities as well. 4.0401
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : pseudoinverse used at 0.99
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : neighborhood radius 2.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## FALSE, : There are other near singularities as well. 4.0401
title(main="martingale residuals for sexual orientation")

###b If you find non-proportional hazards, use an appropriate method to fit an extended Cox model that addresses the non-proportionality

#I am going to stratify by the variables that showed significance in schoenfeld residuals for correlation, however, when I made an interaction between the sex and sexual orientation variables (above) the significance for correlation goes away in the schoenfeld residuals.  I don't know if I should use a stratified model or the model with an interaction.
fit.stratify<-svycoxph(Surv(time=time,event=trans)~sex+sexorient+strata(racethnic_new)+physical.limits+strata(UScitizen)+educ+W4.married+strata(incomeW4)+w3.residence,design=des2)
summary(fit.stratify)
## Stratified 1 - level Cluster Sampling design (with replacement)
## With (132) clusters.
## svydesign(ids = ~psuscid, strata = ~region, weights = ~GSWGT4, 
##     data = adlong, nest = T)
## Call:
## svycoxph(formula = Surv(time = time, event = trans) ~ sex + sexorient + 
##     strata(racethnic_new) + physical.limits + strata(UScitizen) + 
##     educ + W4.married + strata(incomeW4) + w3.residence, design = des2)
## 
##   n= 17268, number of events= 1135 
## 
##                                coef exp(coef) se(coef)      z Pr(>|z|)  
## sexb_female                -0.07059   0.93185  0.07706 -0.916   0.3597  
## sexorientb_bisexual         0.52940   1.69792  0.22186  2.386   0.0170 *
## sexorientc_LGB              0.33020   1.39125  0.24575  1.344   0.1791  
## physical.limitsb_limited    0.07396   1.07676  0.11932  0.620   0.5354  
## educb_highschool_grad      -0.16139   0.85096  0.16067 -1.004   0.3152  
## educc_college_bach         -0.35813   0.69898  0.18471 -1.939   0.0525 .
## educd_college+             -0.35611   0.70039  0.19621 -1.815   0.0695 .
## W4.marriedb_married_once    0.07580   1.07874  0.08697  0.872   0.3834  
## W4.marriedc_married_twice+  0.34932   1.41810  0.17332  2.015   0.0439 *
## w3.residenceb_withsomeone   0.11618   1.12319  0.15158  0.766   0.4434  
## w3.residencec_myownplace    0.05547   1.05704  0.07298  0.760   0.4472  
## w3.residenced_group.qrts    0.02059   1.02080  0.19971  0.103   0.9179  
## w3.residencee_homeless      0.47307   1.60492  1.00698  0.470   0.6385  
## w3.residencef_other         0.37368   1.45307  0.31907  1.171   0.2415  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##                            exp(coef) exp(-coef) lower .95 upper .95
## sexb_female                   0.9318     1.0731    0.8012     1.084
## sexorientb_bisexual           1.6979     0.5890    1.0992     2.623
## sexorientc_LGB                1.3913     0.7188    0.8595     2.252
## physical.limitsb_limited      1.0768     0.9287    0.8522     1.360
## educb_highschool_grad         0.8510     1.1751    0.6211     1.166
## educc_college_bach            0.6990     1.4307    0.4867     1.004
## educd_college+                0.7004     1.4278    0.4768     1.029
## W4.marriedb_married_once      1.0787     0.9270    0.9097     1.279
## W4.marriedc_married_twice+    1.4181     0.7052    1.0097     1.992
## w3.residenceb_withsomeone     1.1232     0.8903    0.8345     1.512
## w3.residencec_myownplace      1.0570     0.9460    0.9162     1.220
## w3.residenced_group.qrts      1.0208     0.9796    0.6902     1.510
## w3.residencee_homeless        1.6049     0.6231    0.2230    11.550
## w3.residencef_other           1.4531     0.6882    0.7775     2.716
## 
## Concordance= 0.54  (se = 0.016 )
## Likelihood ratio test= NA  on 14 df,   p=NA
## Wald test            = 39.94  on 14 df,   p=3e-04
## Score (logrank) test = NA  on 14 df,   p=NA
#Schoenfeld residuals for stratified model
schoenresid3<-resid(fit.stratify,type = "schoenfeld")
fit.sr3<-lm(schoenresid3~des2$variables$time[des2$variables$trans==1])
summary(fit.sr3)
## Response sexb_female :
## 
## Call:
## lm(formula = sexb_female ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.6676 -0.5495  0.3507  0.4505  0.7873 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.13693    0.07037  -1.946
## des2$variables$time[des2$variables$trans == 1]  0.10780    0.03791   2.843
##                                                Pr(>|t|)   
## (Intercept)                                     0.05193 . 
## des2$variables$time[des2$variables$trans == 1]  0.00454 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.496 on 1133 degrees of freedom
## Multiple R-squared:  0.007085,   Adjusted R-squared:  0.006209 
## F-statistic: 8.085 on 1 and 1133 DF,  p-value: 0.004544
## 
## 
## Response sexorientb_bisexual :
## 
## Call:
## lm(formula = sexorientb_bisexual ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.06495 -0.04640 -0.02708 -0.01653  0.99880 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                    -0.004648   0.023248
## des2$variables$time[des2$variables$trans == 1]  0.003987   0.012526
##                                                t value Pr(>|t|)
## (Intercept)                                     -0.200    0.842
## des2$variables$time[des2$variables$trans == 1]   0.318    0.750
## 
## Residual standard error: 0.1639 on 1133 degrees of freedom
## Multiple R-squared:  8.943e-05,  Adjusted R-squared:  -0.0007931 
## F-statistic: 0.1013 on 1 and 1133 DF,  p-value: 0.7503
## 
## 
## Response sexorientc_LGB :
## 
## Call:
## lm(formula = sexorientc_LGB ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.24413 -0.02206 -0.01728 -0.01341  0.99238 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                     0.009963   0.019620
## des2$variables$time[des2$variables$trans == 1] -0.005353   0.010571
##                                                t value Pr(>|t|)
## (Intercept)                                      0.508    0.612
## des2$variables$time[des2$variables$trans == 1]  -0.506    0.613
## 
## Residual standard error: 0.1383 on 1133 degrees of freedom
## Multiple R-squared:  0.0002263,  Adjusted R-squared:  -0.0006561 
## F-statistic: 0.2565 on 1 and 1133 DF,  p-value: 0.6126
## 
## 
## Response physical.limitsb_limited :
## 
## Call:
## lm(formula = physical.limitsb_limited ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.21900 -0.11093 -0.08409 -0.04877  0.97625 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.03138    0.04142  -0.758
## des2$variables$time[des2$variables$trans == 1]  0.01826    0.02231   0.818
##                                                Pr(>|t|)
## (Intercept)                                       0.449
## des2$variables$time[des2$variables$trans == 1]    0.413
## 
## Residual standard error: 0.2919 on 1133 degrees of freedom
## Multiple R-squared:  0.0005909,  Adjusted R-squared:  -0.0002912 
## F-statistic: 0.6699 on 1 and 1133 DF,  p-value: 0.4133
## 
## 
## Response educb_highschool_grad :
## 
## Call:
## lm(formula = educb_highschool_grad ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.7922 -0.6041  0.3218  0.3896  0.6653 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                    -0.031023   0.068394
## des2$variables$time[des2$variables$trans == 1]  0.009211   0.036849
##                                                t value Pr(>|t|)
## (Intercept)                                     -0.454    0.650
## des2$variables$time[des2$variables$trans == 1]   0.250    0.803
## 
## Residual standard error: 0.4821 on 1133 degrees of freedom
## Multiple R-squared:  5.515e-05,  Adjusted R-squared:  -0.0008274 
## F-statistic: 0.06249 on 1 and 1133 DF,  p-value: 0.8027
## 
## 
## Response educc_college_bach :
## 
## Call:
## lm(formula = educc_college_bach ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.44142 -0.21257 -0.13907 -0.06495  0.93505 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.02097    0.05349  -0.392
## des2$variables$time[des2$variables$trans == 1]  0.01748    0.02882   0.607
##                                                Pr(>|t|)
## (Intercept)                                       0.695
## des2$variables$time[des2$variables$trans == 1]    0.544
## 
## Residual standard error: 0.377 on 1133 degrees of freedom
## Multiple R-squared:  0.0003246,  Adjusted R-squared:  -0.0005577 
## F-statistic: 0.3679 on 1 and 1133 DF,  p-value: 0.5443
## 
## 
## Response educd_college+ :
## 
## Call:
## lm(formula = `educd_college+` ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.38356 -0.12324 -0.09504 -0.08042  0.96208 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                     0.02175    0.04415   0.493
## des2$variables$time[des2$variables$trans == 1] -0.00515    0.02379  -0.216
##                                                Pr(>|t|)
## (Intercept)                                       0.622
## des2$variables$time[des2$variables$trans == 1]    0.829
## 
## Residual standard error: 0.3112 on 1133 degrees of freedom
## Multiple R-squared:  4.137e-05,  Adjusted R-squared:  -0.0008412 
## F-statistic: 0.04687 on 1 and 1133 DF,  p-value: 0.8286
## 
## 
## Response W4.marriedb_married_once :
## 
## Call:
## lm(formula = W4.marriedb_married_once ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.7206 -0.4708 -0.2696  0.4906  0.7988 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.10187    0.06877  -1.481
## des2$variables$time[des2$variables$trans == 1]  0.06839    0.03705   1.846
##                                                Pr(>|t|)  
## (Intercept)                                      0.1388  
## des2$variables$time[des2$variables$trans == 1]   0.0652 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4847 on 1133 degrees of freedom
## Multiple R-squared:  0.002998,   Adjusted R-squared:  0.002118 
## F-statistic: 3.407 on 1 and 1133 DF,  p-value: 0.06518
## 
## 
## Response W4.marriedc_married_twice+ :
## 
## Call:
## lm(formula = `W4.marriedc_married_twice+` ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.11501 -0.05083 -0.04792 -0.02608  1.00647 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                     0.03504    0.02899   1.209
## des2$variables$time[des2$variables$trans == 1] -0.02169    0.01562  -1.389
##                                                Pr(>|t|)
## (Intercept)                                       0.227
## des2$variables$time[des2$variables$trans == 1]    0.165
## 
## Residual standard error: 0.2044 on 1133 degrees of freedom
## Multiple R-squared:  0.001699,   Adjusted R-squared:  0.0008183 
## F-statistic: 1.929 on 1 and 1133 DF,  p-value: 0.1652
## 
## 
## Response w3.residenceb_withsomeone :
## 
## Call:
## lm(formula = w3.residenceb_withsomeone ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.26637 -0.06376 -0.05107 -0.04789  0.97224 
## 
## Coefficients:
##                                                  Estimate Std. Error
## (Intercept)                                     0.0021786  0.0341449
## des2$variables$time[des2$variables$trans == 1] -0.0008666  0.0183965
##                                                t value Pr(>|t|)
## (Intercept)                                      0.064    0.949
## des2$variables$time[des2$variables$trans == 1]  -0.047    0.962
## 
## Residual standard error: 0.2407 on 1133 degrees of freedom
## Multiple R-squared:  1.959e-06,  Adjusted R-squared:  -0.0008807 
## F-statistic: 0.002219 on 1 and 1133 DF,  p-value: 0.9624
## 
## 
## Response w3.residencec_myownplace :
## 
## Call:
## lm(formula = w3.residencec_myownplace ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.7115 -0.4990 -0.2582  0.4817  0.8139 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                     0.15019    0.06999   2.146
## des2$variables$time[des2$variables$trans == 1] -0.07440    0.03771  -1.973
##                                                Pr(>|t|)  
## (Intercept)                                      0.0321 *
## des2$variables$time[des2$variables$trans == 1]   0.0487 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4933 on 1133 degrees of freedom
## Multiple R-squared:  0.003424,   Adjusted R-squared:  0.002544 
## F-statistic: 3.892 on 1 and 1133 DF,  p-value: 0.04875
## 
## 
## Response w3.residenced_group.qrts :
## 
## Call:
## lm(formula = w3.residenced_group.qrts ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.12760 -0.05471 -0.05220 -0.02861  0.98965 
## 
## Coefficients:
##                                                Estimate Std. Error t value
## (Intercept)                                    -0.04241    0.02952  -1.437
## des2$variables$time[des2$variables$trans == 1]  0.02376    0.01590   1.494
##                                                Pr(>|t|)
## (Intercept)                                       0.151
## des2$variables$time[des2$variables$trans == 1]    0.135
## 
## Residual standard error: 0.2081 on 1133 degrees of freedom
## Multiple R-squared:  0.001966,   Adjusted R-squared:  0.001085 
## F-statistic: 2.232 on 1 and 1133 DF,  p-value: 0.1355
## 
## 
## Response w3.residencee_homeless :
## 
## Call:
## lm(formula = w3.residencee_homeless ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.01923 -0.00161 -0.00123 -0.00123  0.99839 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                    -0.002947   0.005926
## des2$variables$time[des2$variables$trans == 1]  0.002087   0.003193
##                                                t value Pr(>|t|)
## (Intercept)                                     -0.497    0.619
## des2$variables$time[des2$variables$trans == 1]   0.654    0.513
## 
## Residual standard error: 0.04177 on 1133 degrees of freedom
## Multiple R-squared:  0.0003771,  Adjusted R-squared:  -0.0005052 
## F-statistic: 0.4274 on 1 and 1133 DF,  p-value: 0.5134
## 
## 
## Response w3.residencef_other :
## 
## Call:
## lm(formula = w3.residencef_other ~ des2$variables$time[des2$variables$trans == 
##     1])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.08684 -0.01331 -0.00641 -0.00448  1.00011 
## 
## Coefficients:
##                                                 Estimate Std. Error
## (Intercept)                                     0.010764   0.013902
## des2$variables$time[des2$variables$trans == 1] -0.006026   0.007490
##                                                t value Pr(>|t|)
## (Intercept)                                      0.774    0.439
## des2$variables$time[des2$variables$trans == 1]  -0.805    0.421
## 
## Residual standard error: 0.09799 on 1133 degrees of freedom
## Multiple R-squared:  0.000571,   Adjusted R-squared:  -0.0003111 
## F-statistic: 0.6473 on 1 and 1133 DF,  p-value: 0.4212
ggcoxdiagnostics(fit.stratify, type = , linear.predictions = TRUE)

ggcoxdiagnostics(fit1, type = , linear.predictions = TRUE)

ggcoxdiagnostics(fit.stratify, type = "dfbeta",
                 linear.predictions = FALSE, ggtheme = theme_bw())

ggcoxdiagnostics(fit1, type = "dfbeta",
                 linear.predictions = FALSE, ggtheme = theme_bw())

###E) Fit the discrete time hazard model to your outcome ###i. You must form a person-period data set

fit.0<-svyglm(trans~as.factor(age_enter)-1,design=des2,family="binomial")
## Warning in eval(family$initialize): non-integer #successes in a binomial
## glm!
summary(fit.0)
## 
## Call:
## svyglm(formula = trans ~ as.factor(age_enter) - 1, design = des2, 
##     family = "binomial")
## 
## Survey design:
## svydesign(ids = ~psuscid, strata = ~region, weights = ~GSWGT4, 
##     data = adlong, nest = T)
## 
## Coefficients:
##                         Estimate Std. Error t value Pr(>|t|)    
## as.factor(age_enter)11 -12.30561    1.00000 -12.306  < 2e-16 ***
## as.factor(age_enter)12  -1.90808    1.08906  -1.752   0.0825 .  
## as.factor(age_enter)13  -3.08545    0.22740 -13.568  < 2e-16 ***
## as.factor(age_enter)14  -3.62076    0.25864 -13.999  < 2e-16 ***
## as.factor(age_enter)15  -3.70566    0.22719 -16.311  < 2e-16 ***
## as.factor(age_enter)16  -3.67144    0.19859 -18.488  < 2e-16 ***
## as.factor(age_enter)17  -3.86690    0.24762 -15.616  < 2e-16 ***
## as.factor(age_enter)18  -3.78375    0.32896 -11.502  < 2e-16 ***
## as.factor(age_enter)19  -2.62466    0.20353 -12.895  < 2e-16 ***
## as.factor(age_enter)20  -2.17933    0.11651 -18.705  < 2e-16 ***
## as.factor(age_enter)21  -2.31696    0.11247 -20.601  < 2e-16 ***
## as.factor(age_enter)22  -2.19856    0.08852 -24.838  < 2e-16 ***
## as.factor(age_enter)23  -2.01187    0.11583 -17.369  < 2e-16 ***
## as.factor(age_enter)24  -2.01886    0.09287 -21.739  < 2e-16 ***
## as.factor(age_enter)25  -2.02378    0.21528  -9.401 7.99e-16 ***
## as.factor(age_enter)26  -1.69980    0.41261  -4.120 7.30e-05 ***
## as.factor(age_enter)27  -2.10905    1.13202  -1.863   0.0651 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 0.9998443)
## 
## Number of Fisher Scoring iterations: 10
  1. Consider both the general model and other time specifications
#linear term for time
fit.1<-svyglm(trans~as.factor(age_enter),design=des2,family="binomial")
## Warning in eval(family$initialize): non-integer #successes in a binomial
## glm!
summary(fit.1)
## 
## Call:
## svyglm(formula = trans ~ as.factor(age_enter), design = des2, 
##     family = "binomial")
## 
## Survey design:
## svydesign(ids = ~psuscid, strata = ~region, weights = ~GSWGT4, 
##     data = adlong, nest = T)
## 
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)    
## (Intercept)            -12.3056     1.0000 -12.306  < 2e-16 ***
## as.factor(age_enter)12  10.3975     1.4684   7.081 1.34e-10 ***
## as.factor(age_enter)13   9.2202     1.0170   9.066 4.71e-15 ***
## as.factor(age_enter)14   8.6848     1.0270   8.457 1.16e-13 ***
## as.factor(age_enter)15   8.6000     1.0690   8.045 9.90e-13 ***
## as.factor(age_enter)16   8.6342     1.0176   8.485 1.00e-13 ***
## as.factor(age_enter)17   8.4387     1.0332   8.168 5.24e-13 ***
## as.factor(age_enter)18   8.5219     1.0510   8.108 7.14e-13 ***
## as.factor(age_enter)19   9.6809     1.0875   8.902 1.12e-14 ***
## as.factor(age_enter)20  10.1263     1.0124  10.003  < 2e-16 ***
## as.factor(age_enter)21   9.9887     0.9945  10.044  < 2e-16 ***
## as.factor(age_enter)22  10.1070     1.0006  10.101  < 2e-16 ***
## as.factor(age_enter)23  10.2937     1.0057  10.236  < 2e-16 ***
## as.factor(age_enter)24  10.2867     1.0057  10.228  < 2e-16 ***
## as.factor(age_enter)25  10.2818     1.0251  10.030  < 2e-16 ***
## as.factor(age_enter)26  10.6058     1.0750   9.866  < 2e-16 ***
## as.factor(age_enter)27  10.1966     1.5172   6.721 7.91e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 0.9998443)
## 
## Number of Fisher Scoring iterations: 10

iii. Include all main effects in the model

fit.00<-svyglm(trans~as.factor(age_enter)+sex+sexorient+racethnic_new+physical.limits+UScitizen+educ+W4.married+incomeW4+w3.residence,design=des2,family="binomial")
## Warning in eval(family$initialize): non-integer #successes in a binomial
## glm!
summary(fit.00)
## 
## Call:
## svyglm(formula = trans ~ as.factor(age_enter) + sex + sexorient + 
##     racethnic_new + physical.limits + UScitizen + educ + W4.married + 
##     incomeW4 + w3.residence, design = des2, family = "binomial")
## 
## Survey design:
## svydesign(ids = ~psuscid, strata = ~region, weights = ~GSWGT4, 
##     data = adlong, nest = T)
## 
## Coefficients:
##                             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                -12.32040    1.18612 -10.387  < 2e-16 ***
## as.factor(age_enter)12      10.60859    1.49041   7.118 2.46e-10 ***
## as.factor(age_enter)13       9.39091    1.09504   8.576 2.43e-13 ***
## as.factor(age_enter)14       8.82979    1.10645   7.980 4.21e-12 ***
## as.factor(age_enter)15       8.72190    1.14368   7.626 2.26e-11 ***
## as.factor(age_enter)16       8.77803    1.09822   7.993 3.96e-12 ***
## as.factor(age_enter)17       8.57060    1.11334   7.698 1.61e-11 ***
## as.factor(age_enter)18       8.61390    1.12966   7.625 2.27e-11 ***
## as.factor(age_enter)19       9.82784    1.15917   8.478 3.88e-13 ***
## as.factor(age_enter)20      10.28438    1.08908   9.443 3.73e-15 ***
## as.factor(age_enter)21      10.12111    1.06590   9.495 2.90e-15 ***
## as.factor(age_enter)22      10.24843    1.07800   9.507 2.74e-15 ***
## as.factor(age_enter)23      10.42946    1.08292   9.631 1.51e-15 ***
## as.factor(age_enter)24      10.41194    1.08518   9.595 1.80e-15 ***
## as.factor(age_enter)25      10.34807    1.10795   9.340 6.14e-15 ***
## as.factor(age_enter)26      10.51637    1.14151   9.213 1.13e-14 ***
## as.factor(age_enter)27      10.12187    1.58802   6.374 7.46e-09 ***
## sexb_female                 -0.06576    0.08206  -0.801  0.42501    
## sexorientb_bisexual          0.57981    0.23868   2.429  0.01710 *  
## sexorientc_LGB               0.28180    0.25746   1.095  0.27659    
## racethnic_newb_black         0.28257    0.09413   3.002  0.00346 ** 
## racethnic_newc_hispanic      0.31305    0.14714   2.128  0.03608 *  
## racethnic_newother           0.15701    0.22926   0.685  0.49517    
## physical.limitsb_limited     0.07902    0.12778   0.618  0.53786    
## UScitizenb_yes               0.15268    0.22745   0.671  0.50375    
## educb_highschool_grad       -0.16464    0.16453  -1.001  0.31964    
## educc_college_bach          -0.36842    0.18988  -1.940  0.05544 .  
## educd_college+              -0.38494    0.20201  -1.906  0.05987 .  
## W4.marriedb_married_once     0.06022    0.09197   0.655  0.51429    
## W4.marriedc_married_twice+   0.33341    0.18580   1.794  0.07606 .  
## incomeW4b_$25k>$50k         -0.18345    0.11190  -1.639  0.10459    
## incomeW4c_$50k>$100k        -0.28630    0.11313  -2.531  0.01310 *  
## incomeW4e_$100k+            -0.19358    0.16091  -1.203  0.23206    
## w3.residenceb_withsomeone    0.11143    0.16092   0.692  0.49042    
## w3.residencec_myownplace     0.03904    0.07779   0.502  0.61697    
## w3.residenced_group.qrts     0.02653    0.20937   0.127  0.89946    
## w3.residencee_homeless       0.38636    1.14866   0.336  0.73737    
## w3.residencef_other          0.47664    0.37962   1.256  0.21248    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 0.9787943)
## 
## Number of Fisher Scoring iterations: 10

iv. Test for an interaction between at least two of the predictors

v. Generate hazard plots for interesting cases highlighting the significant predictors in your analysis

haz<-1/(1+exp(-coef(fit.0)))
time<-seq(11,27,1)
plot(haz~time,ylab="h(t)")
title(main="discrete time hazard")

F) Provide the following as a single word document:

a. Code and output

b. Technical write up

c. Descriptive write up consisting of

i. Tables of descriptive statistics

ii. Results of statistical tests

iii. Interpretation of the results