-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean_data.R
More file actions
207 lines (152 loc) · 5.25 KB
/
clean_data.R
File metadata and controls
207 lines (152 loc) · 5.25 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
###
# EDA things to subset the data
###
setwd("/home/noah/git/datavis_project2/")
load(file = "data/realitymining.Rda")
### Save friends matrix and mapping of indices to subject IDs
friends <- data$network[[1]] # 94 by 94 matrix, where each row maps to responses from some subject
N <- 106 # number of total subjects in data
network_N <- 93 # cut off row 94, because the sub_sort mapping maps that to subject ID 107, which doesn't exist :(
friends <- friends[1:network_N, 1:network_N]
sub_sort <- data$network[4][[1]][1,] # Maps network indices to subject ID
mapped_ids <- sapply(1:network_N, function(x) return (sub_sort[x])) # Get subject IDs for network indices
save(friends, file = "Self-Report-Bias/data/friendsmatrix.Rda")
save(mapped_ids, file = "Self-Report-Bias/data/networkIDmapping.Rda")
# Save my.group response for every subject in network
groups <- rep(NA, network_N)
for (index in 1:network_N) {
#print(mapped_ids[index])
temp <- data$s["my.group", 1, mapped_ids[index]][[1]]
if (!is_empty(temp)) {
temp <- temp[[1]]
if (!is_empty(temp)) {
temp <- temp[[1]]
if (!is_empty(temp)) {
groups[index] <- temp[1,1]
}
}
}
}
save(groups, file = "Self-Report-Bias/data/groups.Rda")
# Save my.affil response for every subject in network
affiliations <- rep(NA, network_N)
for (index in 1:network_N) {
temp <- data$s["my.affil", 1, mapped_ids[index]][[1]]
if (length(temp) != 0) {
affiliations[index] <- temp[[1]][[1]][1,1]
}
}
map_affiliations <- function(s) {
return (switch(s,
grad =,
mlgrad = "Media Lab Grad Student",
'1styeargrad ' = "Media Lab 1st Year Grad Student",
professor = "Media Lab Professor",
mlstaff = "Media Lab Staff",
sloan =,
sloan_2 = "Sloan Business School",
mlurop = "Media Lab Undergraduate",
mlfrosh = "Media Lab First Year Undergraduate"))
}
affiliations <- sapply(affiliations, map_affiliations, USE.NAMES = FALSE)
save(affiliations, file = "Self-Report-Bias/data/affiliations.Rda")
# Save survey start date for every subject (all 106)
start.dates <- rep(NA, N)
for (subjectID in 1:N) {
temp <- data$s["survey.start.n", 1, subjectID][[1]]
if (ncol(temp) > 0) {
start.dates[subjectID] <- temp[1,1]
}
}
#save(start.dates, file = "Self-Report-Bias/data/startDates.Rda")
# Get a list of mac addresses in integer form for every subject in network
library(install.load)
install_load('Rmpfr')
macs <- rep(NA, network_N)
for (index in 1:network_N) {
temp <- data$s["my.mac", 1, mapped_ids[index]][[1]]
#print(mapped_ids[index])
if (length(temp) != 0) {
macs[index] <- as.numeric(mpfr(temp[[1]][[1]][1,1], base=16))
}
}
# Use mac addresses to save number of proximity events between network subjects
proximity.events <- matrix(0, nrow=network_N, ncol=network_N)
for (i in 1:network_N) {
event_list <- data$s["device.macs", 1, mapped_ids[i]][[1]]
#print(mapped_ids[i])
event_list.length <- length(event_list)
if (event_list.length != 0) {
for (j in 1:network_N) {
if (!is.na(macs[j])) {
count <- 0
for (k in 1:event_list.length) {
temp <- event_list[k][[1]]
if (!is.null(temp)) {
temp <- temp[[1]][,1]
count <- count + sum(temp == macs[j])
}
}
proximity.events[i,j] <- count
}
}
}
}
save(proximity.events, file = "Self-Report-Bias/data/proximityEvents.Rda")
# Save predictability survey response for all subjects
predictability.responses <- rep(NA, N)
for (index in 1:N) {
temp <- data$s["my.predictable", 1, index][[1]]
if (length(temp) != 0) {
temp <- temp[[1]][[1]]
if (length(temp) != 0) {
predictability.responses[index] <- temp[1,1]
}
}
}
save(predictability.responses, file = "Self-Report-Bias/data/predictabilityResponses.Rda")
# Save text message data frame for all subjects
text.responses <- rep(NA, N)
for (index in 1:N) {
temp <- data$s["surveydata", 1, index][[1]]
if (length(temp) != 0) {
text.responses[index] <- temp[1,][9]
}
}
map_text_response <- function(x) {
t <- switch(x,
"Several times / day",
"once / day",
"once / week",
"once / month",
"never")
if (is.null(t)) {
t <- "No Response"
}
return(t)
}
text.responses <- sapply(text.responses, map_text_response)
text.responses <- factor(text.responses,
levels = c(
"No Response",
"never",
"once / month",
"once / week",
"once / day",
"Several times / day"
),
ordered = TRUE
)
end.dates <- rep(NA, N)
for (subjectID in 1:N) {
temp <- data$s["my.enddate", 1, subjectID][[1]]
if (ncol(temp) > 0) {
start.dates[subjectID] <- temp[1,1]
}
}
numTextsPerMonth <- rep(NA, N)
for (index in 1:N) {
numTexts[index] <- data$s["comm.sms", 1, index][[1]][1,1]
}
texts <- data.frame(id = 1:N, response = text.responses, num = numTexts)
save(texts, file = "Self-Report-Bias/data/texts.Rda")