-
Notifications
You must be signed in to change notification settings - Fork 4
/
homework06_Rcode.R
59 lines (49 loc) · 1.75 KB
/
homework06_Rcode.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
# ==================================
# Homework 06 - logistic regression
#
# Melinda Higgins, PhD
# dated 11/25/2018
# ==================================
# ==================================
# we're be working with the
# helpmkh dataset
# ==================================
library(tidyverse)
library(haven)
helpdat <- haven::read_spss("helpmkh.sav")
# ============================================
# For this homework we'll use the helpmkh dataset
#
# You will be working with the e2b variable
# Number of times in past 6 months entered a
# detox program (collected at Baseline)
#
# For this logistic regression homework 6,
# I've provided the code below to capture the
# individuals who did NOT say they had entered a detox
# program in the 6 months preceeding baseline
# ============================================
helpdat$nodetox <- is.na(helpdat$e2b)
# check results - there are 239 NA's or missing values
# for e2b - these should now be 0's for nodetox
summary(helpdat$e2b)
summary(helpdat$nodetox)
# another way to check using table
# to get a 2-way table
# and include NA's in output
# check that the NA's for e2b are TRUE's for nodetox
table(helpdat$e2b, helpdat$nodetox, useNA = "ifany")
# For this logistic regression homework, you will
# use nodetox as your main outcome variable
# which is a logic variables coded FALSE and TRUE.
# R interprets FALSE as 0 and TRUE as 1. A
# logic class type variable works fine
# as an outcome in logistic regression.
# We'll use logistic regression to predict
# whether someone in a detox program or not (nodetox)
# prior to baseline using these variables
# age, female, pss_fr, pcs, mcs, and cesd.
# ============================================
h1 <- helpdat %>%
select(nodetox, age, female, pss_fr,
pcs, mcs, cesd)