-
Notifications
You must be signed in to change notification settings - Fork 1
/
nonhealthy.behavior.R
37 lines (26 loc) · 1.04 KB
/
nonhealthy.behavior.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
#Import Data and subset for the test set:
delay <- fread("delay_discounting_data.csv", header = T)
nonhealthy<- delay[,c("userid", "smoking_status", "alcohol_status")]
nonhealthy[nonhealthy == -1] <- NA
nonhealthy<- unique( na.omit(nonhealthy))
nonhealthy$nonhealthy<- rowMeans(nonhealthy[,2:3])
nonhealthy[ ,4] = 4 - nonhealthy[ ,4]
nonhealthy.final<- nonhealthy[,c("userid", "nonhealthy")]
#merge with the big 5:
nonhealthy.big5<- unique(merge(big5.100Q,nonhealthy.final, by="userid"))
dim(nonhealthy.big5)
#Take 800 for the test set:
set.seed(1)
size_test <- 800
test_ind <- sample(seq_len(nrow(nonhealthy.big5)),
size = size_test)
test.nonhealthy <- data.table(nonhealthy.big5[test_ind, ])
train.nonhealthy<- data.table(nonhealthy.big5[-test_ind, ])
dim(train.nonhealthy)
#Regression model:
nonhealthy.train.100<- train.nonhealthy[,-c(
"userid", "O","C","E","A","N")]
nonhealthy.model<- lm(nonhealthy~.,nonhealthy.train.100)
coef(nonhealthy.model)
length( coef(nonhealthy.model))
summary(nonhealthy.model)