-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathWeek6_worksheet.R
68 lines (49 loc) · 1.86 KB
/
Week6_worksheet.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
####### WEEK 6 WORKSHEET - missing data #######
library(data.table)
library(JWileymisc)
library(mice)
library(VIM)
library(ggplot2)
library(haven)
# Load in the daily diary dataset (multiple surveys per person)
dd <- as.data.table(???("???"))
# When you have lots of variables, it's hard to get the pattern plots
# to look useful.
# Make a subset of dd called dd_sub that has these variables:
# SurveyDay, dSE, dMood, dStress, dEnergy, dLoneliness
??? <- ???[, .(???)]
# Now use the aggr() function on the subset to look at missing data patterns
# Hint: if the proportions are not showing up on the right hand side,
# add this argument: 'cex.numbers = .8'. If variable labels don't show up,
# add: 'cex.axis = .8'
aggr(???)
# Which variables don't have any missing data?
# A:
# What percentage of the observations aren't missing any data?
# A:
# Make a marginplot comparing missingness of dLoneliness to the values of dMood
???
# Does there seem to be much association?
# A:
# To do MI, we have to make sure the class of all the variables are correct.
# Because they were imported from SPSS, they're all wrong. How do we change them?
# if these are problems usually you can convert to numeric/integer/factor like
# d[, v := as.numeric(v)]
# d[, v := as.integer(v)]
# d[, v := as.factor(v)]
???
### FROM HERE ONWARDS, ANSWERS WILL NOT BE UPLOADED, AS THEY ARE TOO SIMILAR
### TO YOUR LAB REPORTS. I WILL HELP YOU IN CLASS BUT I CAN'T GIVE THE ANSWERS
# Multiply impute the dataset with 5 MI datasets and 30 iterations.
# Bonus: Make me get the same results if you were to give me the seed 666
mi.ddsub <- mice(
???)
## plot convergence diagnostics for dLoneliness
plot(???)
# use the with() and pool() functions to run a linear regression where
# loneliness predicts mood
???
???
# For every one unit change in daily loneliness,
# mood ___creased by ____ units, p _____
#A: