-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathds_analysis2.R
More file actions
281 lines (215 loc) · 7.43 KB
/
ds_analysis2.R
File metadata and controls
281 lines (215 loc) · 7.43 KB
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
source("functions.R")
attach(ds)
# Calculation of Knowledge, Attitude and Substance Use Practice Scores
ds$attitude_score = adu_strict_measure + adu_load + adu_prob_per +
adu_prob_soc + adu_relations + adu_get_high
ds[c(29:30,32:33)] <- sapply(ds[c(29:30,32:33)], attifun)
ds[c(28,31)] <- sapply(ds[c(28,31)], attifun2)
myvars_a <- names(ds[28:35])
table_a <- CreateTableOne(vars = myvars_a, data = ds)
print(table_a)
ds$attitude_cat <- ifelse(ds$attitude_score >= 15, "Good Attitude",
"Poor Attitude")
ds$knowledge_score = (du_know + opioid + cocaine + amphe + inhalants + marijuana +
hallu + sedatives + tobacco + alcohols + feel_good + feel_better +
be_better + curiosity + aggressive + lack_parent + poor_social +
stress + experi + drug_availability + poverty + self_control + parental +
positive_rel + academic_excel + policies+crimes + poor_status + e_hiv +
e_hepatitis+e_tb+e_sti+poor_health+poor_economy+stigma+methadone+rehab+
cbt + fa_therapy+al_therapy)
ds$knowledge_cat <- ifelse(ds$knowledge_score <= 13,
"Poor Knowledge","Good Knowledge")
ds[51:59] <- sapply(ds[51:59], myfun)
myvars_b <- names(ds[51:59])
table_b <- CreateTableOne(vars = myvars_b, data = ds)
print(table_b)
ds[60:63] <- sapply(ds[60:63], myfun)
myvars_c <- names(ds[60:63])
table_c <- CreateTableOne(vars = myvars_c, data = ds)
print(table_c)
ds[76:89] <- sapply(ds[76:89], myfun)
myvars_d <- names(ds[76:89])
table_d <- CreateTableOne(vars = myvars_d, data = ds)
print(table_d)
ds$practice_score = (du_inject + du_past_six + di_share + du_happy + u_heroin +
u_cocaine + u_crack + u_amphe + u_inhalants+u_hero_coca +
u_marijuana + u_hallu)
ds$practice_cat <- ifelse(ds$practice_score >= 6,
"Poor Practice","Good Practice")
# ATTIDUDE TOWARDS SUBSTANCE USE
myVars5<-c("attitude_score","attitude_cat","knowledge_score",
"knowledge_cat", "practice_score","practice_cat")
tab5<-CreateTableOne(vars=myVars5, data=ds)
print(tab5)
# with strata
tab6<-CreateTableOne(vars=myVars5, strata=c("location"),
data=ds, test=TRUE)
print(tab6)
ds[90:97] <- sapply(ds[90:97], myfun)
myvars_e <- names(ds[90:97])
table_e <- CreateTableOne(vars = myvars_e, data = ds)
print(table_e)
ds$du_inject <- myfun(du_inject)
descriptives(ds$du_inject)
ds[,98:101] <- sapply(ds[,98:101],myfun)
descriptives(ds$ro_ingest)
descriptives(ds$ro_smoke)
descriptives(ds$ro_snif)
table(ds$alc_how_many)
du_location <- ds$du_location
du_location <- str_split(du_location, ",", simplify = TRUE)
du_location <- as.data.frame(du_location)
table(du_location$V1)
table(du_location$V2)
table(du_location$V3)
table(du_location$V4)
# PLOTTING...
(knowledge <- ds %>%
filter(!is.na(knowledge_cat)) %>%
group_by(location,knowledge_cat) %>%
summarise(count = n()) %>%
summarise(location,knowledge_cat,count,
prop = (count/sum(count)*100)) %>%
ungroup())
(p1 <- ggplot(knowledge) +
geom_col(
mapping = aes( x = location,
y = prop,
fill = knowledge_cat), width = 0.75,
position = position_dodge2(width = 0.9, preserve = "single")) +
theme_bw() +
common_theme()+
scale_fill_lancet() +
ylim(0,100) +
xlab("District") +
ylab("Proportion(%)") +
labs(fill = "Knowledge Level")+
ggtitle("Knowledge Level"))
ds$practice_cat <- factor(ds$practice_cat,
levels = c("Good Practice", "Poor Practice"))
(practice <- ds %>%
filter(!is.na(practice_cat)) %>%
group_by(location,practice_cat) %>%
summarise(count = n()) %>%
summarise(location,practice_cat,count,
prop = (count/sum(count)*100)) %>%
ungroup())
(p2 <- ggplot(practice) +
geom_col(
mapping = aes( x = location,
y = prop,
fill = practice_cat), width = 0.75,
position = position_dodge2(width = 0.9, preserve = "single")) +
theme_bw() +
common_theme()+
scale_fill_lancet() +
ylim(0,100) +
xlab("District") +
ylab("Proportion(%)") +
labs(fill = "Practice Level") +
ggtitle("Practice Level"))
(attitude <- ds %>%
filter(!is.na(attitude_cat)) %>%
group_by(location,attitude_cat) %>%
summarise(count = n()) %>%
summarise(location,attitude_cat,count,
prop = (count/sum(count)*100)) %>%
ungroup())
(p3 <- ggplot(attitude) +
geom_col(
mapping = aes( x = location,
y = prop,
fill = attitude_cat), width = 0.75,
position = position_dodge2(width = 0.9, preserve = "single")) +
theme_bw() +
common_theme()+
scale_fill_lancet() +
ylim(0,100) +
xlab("District") +
ylab("Proportion(%)") +
labs(fill = "Attitude Level") +
ggtitle('Attitude Level'))
p1 + p3 + p2+
plot_annotation(tag_levels = "A") +
plot_layout(guides = "collect")
ds$phone_pos <- factor(ds$phone_pos,
levels = c("Yes", "No"))
(phone_poss <- ds %>%
filter(!is.na(phone_pos)) %>%
group_by(location,phone_pos) %>%
summarise(count = n()) %>%
summarise(location,phone_pos,count,
prop = (count/sum(count)*100)) %>%
ungroup())
(p4 <- ggplot(phone_poss) +
geom_col(
mapping = aes( x = location,
y = prop,
fill = phone_pos), width = 0.75,
position = position_dodge2(width = 0.9, preserve = "single")) +
theme_bw() +
common_theme() +
scale_fill_lancet() +
ylim(0,100) +
xlab("District") +
ylab("Proportion(%)") +
labs(fill = "Own A Mobile Phone"))
ds$ph_learning <- factor(ds$ph_learning,
levels = c("Yes", "No"))
(phone_learning <- ds %>%
filter(!is.na(ph_learning)) %>%
group_by(location,ph_learning) %>%
summarise(count = n()) %>%
summarise(location,ph_learning,count,
prop = (count/sum(count)*100)) %>%
ungroup())
(p5 <- ggplot(phone_learning) +
geom_col(
mapping = aes( x = location,
y = prop,
fill = ph_learning), width = 0.75,
position = position_dodge2(width = 0.9, preserve = "single")) +
theme_bw() +
common_theme()+
scale_fill_lancet() +
ylim(0,100) +
xlab("District") +
ylab("Proportion(%)") +
labs(fill = "Ready to Use Phone for Learning"))
ds$ph_alone <- factor(ds$ph_alone,
levels = c("Yes", "No"))
(ph_alone <- ds %>%
filter(!is.na(ph_alone)) %>%
group_by(location,ph_alone) %>%
summarise(count = n()) %>%
summarise(location,ph_alone,count,
prop = (count/sum(count)*100)) %>%
ungroup())
(p6 <- ggplot(ph_alone) +
geom_col(
mapping = aes( x = location,
y = prop,
fill = ph_alone), width = 0.75,
position = position_dodge2(width = 0.9, preserve = "single")) +
theme_bw() +
common_theme() +
scale_fill_lancet() +
ylim(0,100) +
xlab("District") +
ylab("Proportion(%)") +
labs(fill = "Can Use Phone Alone to Learn"))
p4 + p5 + p6+
plot_annotation(tag_levels = "A") +
plot_layout(guides = "collect")
# Exploring Age Distribution
ggplot(ds,
aes(x=age)) +
geom_histogram(aes(y=..density..),binwidth = 3) +
geom_density(alpha = 0, fill ="#FF6666",col = "steelblue") +
facet_wrap(~location) +
theme_minimal() +
xlab("Participant Age") +
ylab("Density") +
ggtitle("Histogram of Participants Age by District with
Superimposed Density Plot")
#write_csv(ds,"mds.csv")