-
Notifications
You must be signed in to change notification settings - Fork 0
/
7 descriptives.R
211 lines (146 loc) · 12.1 KB
/
7 descriptives.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#################################
#### Frequency and Percentage####
#################################
summary(is.na(dfaddress$wealth))
summary(is.na(dfaddress$maritalStatus))
summary(is.na(dfaddress$occupation))
summary(is.na(dfaddress$cohabAge))
summary(is.na(dfaddress$totalChildrenEverBorn))
summary(is.na(dfaddress$residence))
dfaddress <- dfaddress[!is.na(dfaddress$occupation),]
round(wtd.table(x = dfaddress$status, weights = dfaddress$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = dfaddress$status, weights = dfaddress$weightsdf, normwt = TRUE))),2)
#############
### Total ###
#############
round(wtd.table(x = dfaddress$residence, weights = dfaddress$weightsdf, normwt = TRUE), 0)
round(wtd.table(x = dfaddress$residence, weights = dfaddress$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = dfaddress$residence, weights = dfaddress$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = dfaddress$occupation, weights = dfaddress$weightsdf, normwt = TRUE),0)
round(wtd.table(x = dfaddress$occupation, weights = dfaddress$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = dfaddress$occupation, weights = dfaddress$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = dfaddress$wealth, weights = dfaddress$weightsdf, normwt = TRUE),0)
round(wtd.table(x = dfaddress$wealth, weights = dfaddress$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = dfaddress$wealth, weights = dfaddress$weightsdf, normwt = TRUE))), 2)
round(wtd.table(x = dfaddress$maritalStatus, weights = dfaddress$weightsdf, normwt = TRUE),0)
round(wtd.table(x = dfaddress$maritalStatus, weights = dfaddress$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = dfaddress$maritalStatus, weights = dfaddress$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = dfaddress$totalChildrenEverBorn, weights = dfaddress$weightsdf, normwt = TRUE),0)
round(wtd.table(x = dfaddress$totalChildrenEverBorn, weights = dfaddress$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = dfaddress$totalChildrenEverBorn, weights = dfaddress$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = dfaddress$education, weights = dfaddress$weightsdf, normwt = TRUE), 0)
round(wtd.table(x = dfaddress$education, weights = dfaddress$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = dfaddress$education, weights = dfaddress$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = dfaddress$religion, weights = dfaddress$weightsdf, normwt = TRUE), 0)
round(wtd.table(x = dfaddress$religion, weights = dfaddress$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = dfaddress$religion, weights = dfaddress$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = dfaddress$education_partner, weights = dfaddress$weightsdf, normwt = TRUE), 0)
round(wtd.table(x = dfaddress$education_partner, weights = dfaddress$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = dfaddress$education_partner, weights = dfaddress$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = dfaddress$occupation_partner, weights = dfaddress$weightsdf, normwt = TRUE),0)
round(wtd.table(x = dfaddress$occupation_partner, weights = dfaddress$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = dfaddress$occupation_partner, weights = dfaddress$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = dfaddress$aliveChildren, weights = dfaddress$weightsdf, normwt = TRUE),0)
round(wtd.table(x = dfaddress$aliveChildren, weights = dfaddress$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = dfaddress$aliveChildren, weights = dfaddress$weightsdf, normwt = TRUE))),2)
#wtd.table(x = dfaddress$cohabAge, weights = dfaddress$weightsdf, normwt = TRUE)*100/(sum(wtd.table(x = dfaddress$cohabAge, weights = dfaddress$weightsdf, normwt = TRUE)))
weighted.median <- function(x, w, na.rm=TRUE) {
unname(weighted.quantile(x, probs=0.5, w=w, na.rm=na.rm))
}
weighted.25 <- function(x, w, na.rm=TRUE) {
unname(weighted.quantile(x, probs=0.25, w=w, na.rm=na.rm))
}
weighted.75 <- function(x, w, na.rm=TRUE) {
unname(weighted.quantile(x, probs=0.75, w=w, na.rm=na.rm))
}
weighted.median(dfaddress$cohabAgeC, dfaddress$weightsdf, na.rm=TRUE)
weighted.75(dfaddress$cohabAgeC, dfaddress$weightsdf, na.rm=TRUE) -
weighted.25(dfaddress$cohabAgeC, dfaddress$weightsdf, na.rm=TRUE)
weighted.median(dfaddress$currentAge_exact, dfaddress$weightsdf, na.rm=TRUE)
weighted.75(dfaddress$currentAge_exact, dfaddress$weightsdf, na.rm=TRUE) -
weighted.25(dfaddress$currentAge_exact, dfaddress$weightsdf, na.rm=TRUE)
##########################################
##### Data: Terminated Pregnancies #######
##########################################
terminate <- subset(dfaddress, status == 1)
## Frequency and Percentage
round(wtd.table(x = terminate$residence, weights = terminate$weightsdf, normwt = TRUE), 0)
round(wtd.table(x = terminate$residence, weights = terminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = terminate$residence, weights = terminate$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = terminate$occupation, weights = terminate$weightsdf, normwt = TRUE),0)
round(wtd.table(x = terminate$occupation, weights = terminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = terminate$occupation, weights = terminate$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = terminate$wealth, weights = terminate$weightsdf, normwt = TRUE),0)
round(wtd.table(x = terminate$wealth, weights = terminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = terminate$wealth, weights = terminate$weightsdf, normwt = TRUE))), 2)
round(wtd.table(x = terminate$maritalStatus, weights = terminate$weightsdf, normwt = TRUE),0)
round(wtd.table(x = terminate$maritalStatus, weights = terminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = terminate$maritalStatus, weights = terminate$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = terminate$totalChildrenEverBorn, weights = terminate$weightsdf, normwt = TRUE),0)
round(wtd.table(x = terminate$totalChildrenEverBorn, weights = terminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = terminate$totalChildrenEverBorn, weights = terminate$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = terminate$education, weights = terminate$weightsdf, normwt = TRUE), 0)
round(wtd.table(x = terminate$education, weights = terminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = terminate$education, weights = terminate$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = terminate$religion, weights = terminate$weightsdf, normwt = TRUE), 0)
round(wtd.table(x = terminate$religion, weights = terminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = terminate$religion, weights = terminate$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = terminate$education_partner, weights = terminate$weightsdf, normwt = TRUE), 0)
round(wtd.table(x = terminate$education_partner, weights = terminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = terminate$education_partner, weights = terminate$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = terminate$occupation_partner, weights = terminate$weightsdf, normwt = TRUE),0)
round(wtd.table(x = terminate$occupation_partner, weights = terminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = terminate$occupation_partner, weights = terminate$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = terminate$aliveChildren, weights = terminate$weightsdf, normwt = TRUE),0)
round(wtd.table(x = terminate$aliveChildren, weights = terminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = terminate$aliveChildren, weights = terminate$weightsdf, normwt = TRUE))),2)
weighted.median(terminate$cohabAgeC, terminate$weightsdf, na.rm=TRUE)
weighted.75(terminate$cohabAgeC, terminate$weightsdf, na.rm=TRUE) -
weighted.25(terminate$cohabAgeC, terminate$weightsdf, na.rm=TRUE)
weighted.median(terminate$currentAge_exact, terminate$weightsdf, na.rm=TRUE)
weighted.75(terminate$currentAge_exact, terminate$weightsdf, na.rm=TRUE) -
weighted.25(terminate$currentAge_exact, terminate$weightsdf, na.rm=TRUE)
#wtd.table(x = terminate$cohabAge, weights = terminate$weightsdf, normwt = TRUE)
#################################################
##### Data: Did not Terminate Pregnancies #######
#################################################
didnotterminate <- subset(dfaddress, status == 0)
## Frequency and Percentage
round(wtd.table(x = didnotterminate$residence, weights = didnotterminate$weightsdf, normwt = TRUE), 0)
round(wtd.table(x = didnotterminate$residence, weights = didnotterminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = didnotterminate$residence, weights = didnotterminate$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = didnotterminate$occupation, weights = didnotterminate$weightsdf, normwt = TRUE),0)
round(wtd.table(x = didnotterminate$occupation, weights = didnotterminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = didnotterminate$occupation, weights = didnotterminate$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = didnotterminate$wealth, weights = didnotterminate$weightsdf, normwt = TRUE),0)
round(wtd.table(x = didnotterminate$wealth, weights = didnotterminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = didnotterminate$wealth, weights = didnotterminate$weightsdf, normwt = TRUE))), 2)
round(wtd.table(x = didnotterminate$maritalStatus, weights = didnotterminate$weightsdf, normwt = TRUE),0)
round(wtd.table(x = didnotterminate$maritalStatus, weights = didnotterminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = didnotterminate$maritalStatus, weights = didnotterminate$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = didnotterminate$totalChildrenEverBorn, weights = didnotterminate$weightsdf, normwt = TRUE),0)
round(wtd.table(x = didnotterminate$totalChildrenEverBorn, weights = didnotterminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = didnotterminate$totalChildrenEverBorn, weights = didnotterminate$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = didnotterminate$education, weights = didnotterminate$weightsdf, normwt = TRUE), 0)
round(wtd.table(x = didnotterminate$education, weights = didnotterminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = didnotterminate$education, weights = didnotterminate$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = didnotterminate$religion, weights = didnotterminate$weightsdf, normwt = TRUE), 0)
round(wtd.table(x = didnotterminate$religion, weights = didnotterminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = didnotterminate$religion, weights = didnotterminate$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = didnotterminate$education_partner, weights = didnotterminate$weightsdf, normwt = TRUE), 0)
round(wtd.table(x = didnotterminate$education_partner, weights = didnotterminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = didnotterminate$education_partner, weights = didnotterminate$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = didnotterminate$occupation_partner, weights = didnotterminate$weightsdf, normwt = TRUE),0)
round(wtd.table(x = didnotterminate$occupation_partner, weights = didnotterminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = didnotterminate$occupation_partner, weights = didnotterminate$weightsdf, normwt = TRUE))),2)
round(wtd.table(x = didnotterminate$aliveChildren, weights = didnotterminate$weightsdf, normwt = TRUE),0)
round(wtd.table(x = didnotterminate$aliveChildren, weights = didnotterminate$weightsdf, normwt = TRUE)*100/
(sum(wtd.table(x = didnotterminate$aliveChildren, weights = didnotterminate$weightsdf, normwt = TRUE))),2)
#wtd.table(x = terminate$cohabAge, weights = terminate$weightsdf, normwt = TRUE)
#wtd.table(x = dfaddress$cohabAge, weights = dfaddress$weightsdf, normwt = TRUE)*100/(sum(wtd.table(x = dfaddress$cohabAge, weights = dfaddress$weightsdf, normwt = TRUE)))
weighted.median(didnotterminate$cohabAgeC, didnotterminate$weightsdf, na.rm=TRUE)
weighted.75(didnotterminate$cohabAgeC, didnotterminate$weightsdf, na.rm=TRUE) -
weighted.25(didnotterminate$cohabAgeC, didnotterminate$weightsdf, na.rm=TRUE)
weighted.median(didnotterminate$currentAge_exact, didnotterminate$weightsdf, na.rm=TRUE)
weighted.75(didnotterminate$currentAge_exact, didnotterminate$weightsdf, na.rm=TRUE) -
weighted.25(didnotterminate$currentAge_exact, didnotterminate$weightsdf, na.rm=TRUE)