-
Notifications
You must be signed in to change notification settings - Fork 0
/
correct_ffostare_visuals.Rmd
299 lines (202 loc) · 13.6 KB
/
correct_ffostare_visuals.Rmd
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
---
title: "getting_started"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(tidyselect)
library(ggplot2)
library(broom)
library(dplyr)
library(corrplot)
library(kableExtra)
library(knitr)
library(Hmisc)
library(infer)
library(plotly)
library(skimr)
library(stringr)
library(reshape2)
library(som)
library(readxl)
library(manipulate)
library(lavaan)
library(semPlot)
library(FactoMineR)
library(factoextra)
library(readxl)
library(xtable)
```
```{r}
ffostare_corrected <- read_excel("ffostare_corrected_spssout_full.xlsx")
View(ffostare_corrected)
selected_ffostare <- ffostare_corrected %>%
select(- Observations, - ResultContainers, - Intervals, - no_sec_behav_ffosta)
znormed_ffostare_v1 <- read_excel("znormed_ffostare_v1.xlsx")
skim(znormed_ffostare_v1)
selected_norms_ffostare_v1 <- znormed_ffostare_v1 %>%
select(-Observations, - ResultContainers, - Intervals, - Zno_sec_behav_ffosta)
```
```{r}
corr_selected_ffostare_v1 <- cor(selected_ffostare)
melted_corr_selected_ffostare_v1 <- melt(corr_selected_ffostare_v1)
write.csv(corr_selected_ffostare_v1, "corr_selected_ffostare_v1.csv")
ggplot(melted_corr_selected_ffostare_v1, aes(x=Var2, y=Var1, fill=value)) +
ggtitle("Combined Behavioral Correlations") +
geom_tile() +
scale_fill_gradient(low = "dark blue", high = "yellow") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45,
vjust = 1,
size = 9,
hjust = 1)
)
corrnorm_selected_ffostare_v1 <- cor(selected_norms_ffostare_v1)
melted_corrnorm_selected_ffostare_v1 <- melt(corrnorm_selected_ffostare_v1)
write.csv(corrnorm_selected_ffostare_v1, "corrnorm_selected_ffostare_v1.csv")
```
storage
selected_norms_ffostare_v1$Zstationary_middle_percent_butters , selected_norms_ffostare_v1$Zlocomotion_percent_butters , selected_norms_ffostare_v1$Zhanging_behaviors_butters , selected_norms_ffostare_v1$Ztactile_exploration_butters , selected_norms_ffostare_v1$Zmo_manip_apple_butters , selected_norms_ffostare_v1$Zstation_fr_ffostare , selected_norms_ffostare_v1$Zstation_mid_ffosta , selected_norms_ffostare_v1$Zlocomote_ffosta , selected_norms_ffostare_v1$Zmovement_ffosta , selected_norms_ffostare_v1$Ztac_expl_ffosta , selected_norms_ffostare_v1$Zstereo_ffosta , selected_norms_ffostare_v1$Zteethgrind_ffosta , selected_norms_ffostare_v1$Zlipsmack_ffosta , selected_norms_ffostare_v1$Ztouch_app_ffosta , selected_norms_ffostare_v1$Zmouth_app_ffosta , selected_norms_ffostare_v1$Zmanip_app_ffosta , selected_norms_ffostare_v1$Zeat_app_ffosta , selected_norms_ffostare_v1$Znonvigi_ffosta , selected_norms_ffostare_v1$Zdir_eye_contact_ffosta
```{r}
selected_norms_ffostare_v1$comp_1 <- selected_norms_ffostare_v1$Zstationary_middle_percent_butters + selected_norms_ffostare_v1$Zlocomotion_percent_butters + selected_norms_ffostare_v1$Zhanging_behaviors_butters + selected_norms_ffostare_v1$Ztactile_exploration_butters + selected_norms_ffostare_v1$Zmo_manip_apple_butters + selected_norms_ffostare_v1$Zstation_fr_ffostare + selected_norms_ffostare_v1$Zstation_mid_ffosta + selected_norms_ffostare_v1$Zlocomote_ffosta + selected_norms_ffostare_v1$Zmovement_ffosta + selected_norms_ffostare_v1$Ztac_expl_ffosta + selected_norms_ffostare_v1$Zstereo_ffosta + selected_norms_ffostare_v1$Zteethgrind_ffosta + selected_norms_ffostare_v1$Zlipsmack_ffosta + selected_norms_ffostare_v1$Ztouch_app_ffosta + selected_norms_ffostare_v1$Zmouth_app_ffosta + selected_norms_ffostare_v1$Zmanip_app_ffosta + selected_norms_ffostare_v1$Zeat_app_ffosta + selected_norms_ffostare_v1$Znonvigi_ffosta + selected_norms_ffostare_v1$Zdir_eye_contact_ffosta
#comp_1 <- selected_norms_ffostare_v1 %>%
#select(Zstationary_middle_percent_butters , Zlocomotion_percent_butters , Zhanging_behaviors_butters , Ztactile_exploration_butters , Zmo_manip_apple_butters , Zstation_fr_ffostare , Zstation_mid_ffosta , Zlocomote_ffosta , Zmovement_ffosta , Ztac_expl_ffosta , Zstereo_ffosta , Zteethgrind_ffosta , Zlipsmack_ffosta , Ztouch_app_ffosta , Zmouth_app_ffosta , Zmanip_app_ffosta , Zeat_app_ffosta , Znonvigi_ffosta , Zdir_eye_contact_ffosta)
View(comp_1)
selected_norms_ffostare_v1$comp_2 <- selected_norms_ffostare_v1$ZStationary_back_butters + selected_norms_ffostare_v1$Zstereotypy_butters + selected_norms_ffostare_v1$Zvigilant_percent_butters + selected_norms_ffostare_v1$Zstation_back_ffostare + selected_norms_ffostare_v1$Zself_gro_ffosta + selected_norms_ffostare_v1$Zthreat_stranger_ffosta + selected_norms_ffostare_v1$Zfreeze_back_ffosta
selected_norms_ffostare_v1$comp_3 <- selected_norms_ffostare_v1$Zstationary_front_percent_butters + selected_norms_ffostare_v1$Zmovement_percent_butters + selected_norms_ffostare_v1$Ztouch_butters_percent + selected_norms_ffostare_v1$Zcrouching_butters + selected_norms_ffostare_v1$Znonvigilant_percent_butters + selected_norms_ffostare_v1$Zcrouching_ffosta + selected_norms_ffostare_v1$Zvigi_ffosta + selected_norms_ffostare_v1$Zno_response_ffosta
selected_norms_ffostare_v1$comp_4 <- selected_norms_ffostare_v1$Zself_groom_percent_butters + selected_norms_ffostare_v1$Zmouth_butters_percent + selected_norms_ffostare_v1$Zoral_exploration_butters
View(selected_norms_ffostare_v1)
write.csv(selected_norms_ffostare_v1, "selected_norms_composites_demgraf_v1.csv")
```
```{r}
selected_norms_composites_demgraf_v1 <- read_excel("selected_norms_composites_demgraf_v1.xlsx")
View(selected_norms_composites_demgraf_v1)
composite_scores_withgroups <- selected_norms_composites_demgraf_v1 %>%
select(Observations, sex, initial_diet, new_diet, comp_1, comp_2, comp_3, comp_4)
composite_scores_withgroups$initial_diet <- as.factor(composite_scores_withgroups$initial_diet)
composite_scores_withgroups$new_diet <- as.factor(composite_scores_withgroups$new_diet)
skim(composite_scores_withgroups)
```
```{r}
#visuals of maternal diet
ggplot(composite_scores_withgroups, aes(x=Observations, y=comp_1, color=initial_diet)) +
geom_histogram(stat = "identity", binwidth = 30)
ggplot(composite_scores_withgroups, aes(x=Observations, y=comp_2, color=initial_diet)) +
geom_histogram(stat = "identity", binwidth = 30)
comp1_wilcoxtest <- wilcox.test(composite_scores_withgroups$comp_1~composite_scores_withgroups$initial_diet)
comp1_wilcoxtest$p.value
ggplot(composite_scores_withgroups, aes(x=Observations, y=comp_3, color=initial_diet)) +
geom_histogram(stat = "identity", binwidth = 30)
ggplot(composite_scores_withgroups, aes(x=Observations, y=comp_4, color=initial_diet)) +
geom_histogram(stat = "identity", binwidth = 30)
```
```{r}
#matdiet filtered = filtering out all subjects with a new diet value of 2. This eliminates the effects of the new diet
head(composite_scores_withgroups)
matdiet_filtered <- composite_scores_withgroups %>%
filter(!new_diet == 2)
matdiet_filtered$initial_diet <- as.factor(matdiet_filtered$initial_diet)
skim(matdiet_filtered) #removing new_diet = 2 removes 15 subjects
matdiet_filtered_wiltest_comp1 <- wilcox.test(matdiet_filtered$comp_1~matdiet_filtered$initial_diet)
matdiet_filtered_wiltest_comp2 <- wilcox.test(matdiet_filtered$comp_2~matdiet_filtered$initial_diet)
matdiet_filtered_wiltest_comp3 <- wilcox.test(matdiet_filtered$comp_3~matdiet_filtered$initial_diet)
matdiet_filtered_wiltest_comp4 <- wilcox.test(matdiet_filtered$comp_4~matdiet_filtered$initial_diet)
head(matdiet_filtered)
ggplot(matdiet_filtered, aes(x=initial_diet, y=comp_1)) +
geom_boxplot()
```
```{r}
#visuals of postnatal diet
ggcomp1 <- ggplot(matdiet_filtered, aes(x=Observations, y=comp_1, color=initial_diet, fill=initial_diet)) +
geom_bar(stat = "identity", width = 20, position = position_dodge())
ggplot(matdiet_filtered, aes(x=Observations, y=comp_1, color=initial_diet, fill=initial_diet)) +
geom_bar(stat = "identity", width = 20, position = position_dodge())
ggcompl1_ly <- ggplotly(ggcomp1)
ggcompl1_ly
plot_ly(matdiet_filtered, x = ~Observations, y=~comp_1, type = "bar", name = "Individual Component 1 Scores",colors="")
ggplot(matdiet_filtered, aes(x=Observations, y=comp_2, color=initial_diet, fill=initial_diet)) +
geom_histogram(stat = "identity")
ggplot(composite_scores_withgroups, aes(x=Observations, y=comp_3, color=new_diet)) +
geom_histogram(stat = "identity", width = 30)
ggplot(composite_scores_withgroups, aes(x=Observations, y=comp_4, color=new_diet)) +
geom_histogram(stat = "identity", width = 30)
#need to do a pca on community 1
```
```{r}
#sex differences
ggplot(composite_scores_withgroups, aes(x=Observations, y=comp_1, color=sex)) +
geom_histogram(stat = "identity", binwidth = 30)
ggplot(composite_scores_withgroups, aes(x=Observations, y=comp_2, color=sex)) +
geom_histogram(stat = "identity", binwidth = 30)
ggplot(composite_scores_withgroups, aes(x=Observations, y=comp_3, color=sex)) +
geom_histogram(stat = "identity", binwidth = 30)
ggplot(composite_scores_withgroups, aes(x=Observations, y=comp_4, color=sex)) +
geom_histogram(stat = "identity", binwidth = 30)
matdiet_sex_wiltest_comp1 <- wilcox.test(matdiet_filtered$comp_1~matdiet_filtered$sex)
matdiet_sex_wiltest_comp2 <- wilcox.test(matdiet_filtered$comp_2~matdiet_filtered$sex)
matdiet_sex_wiltest_comp3 <- wilcox.test(matdiet_filtered$comp_3~matdiet_filtered$sex)
matdiet_sex_wiltest_comp4 <- wilcox.test(matdiet_filtered$comp_4~matdiet_filtered$sex)
matdiet_sex_wiltest_comp4$p.value
```
```{r}
#princi_comp1 <- prcomp(comp_1)
#summary(princi_comp1)
#fviz_eig(princi_comp1)
```
```{r}
#creating new composite variables to investigate the groupings
comp1_indi <- selected_norms_ffostare_v1 %>%
select(Zstationary_middle_percent_butters, Zlocomotion_percent_butters, Zhanging_behaviors_butters, Ztactile_exploration_butters, Zmo_manip_apple_butters, Zstation_fr_ffostare, Zstation_mid_ffosta, Zlocomote_ffosta, Zmovement_ffosta, Ztac_expl_ffosta, Zstereo_ffosta, Zteethgrind_ffosta, Zlipsmack_ffosta, Ztouch_app_ffosta, Zmouth_app_ffosta, Zmanip_app_ffosta, Zeat_app_ffosta, Znonvigi_ffosta, Zdir_eye_contact_ffosta)
comp2_indi <- selected_norms_ffostare_v1 %>%
select(ZStationary_back_butters, Zstereotypy_butters, Zvigilant_percent_butters, Zstation_back_ffostare, Zself_gro_ffosta, Zthreat_stranger_ffosta, Zfreeze_back_ffosta)
comp3_indi <- selected_norms_ffostare_v1 %>%
select(Zstationary_front_percent_butters, Zmovement_percent_butters, Ztouch_butters_percent, Zcrouching_butters, Znonvigilant_percent_butters, Zcrouching_ffosta, Zvigi_ffosta, Zno_response_ffosta)
comp4_indi <- selected_norms_ffostare_v1 %>%
select(Zself_groom_percent_butters, Zmouth_butters_percent, Zoral_exploration_butters)
```
```{r}
#here i need to run a PCA for Damien and Lavaan for Elinor
princi_comp1 <- prcomp(comp1_indi)
summary(princi_comp1)
#princi_comp1$sdev
princ1_ploty <- ggplotly(fviz_eig(princi_comp1, main = "variance explained: components of comp_1"))
xtable(princi_comp1)
princ1_ploty
princi_comp2 <- prcomp(comp2_indi)
summary(princi_comp2)
fviz_eig(princi_comp2, main = 'variance explained: components of comp_2')
princ2_ploty <- ggplotly(fviz_eig(princi_comp2, main = 'variance explained: components of comp_2'))
princi_comp3 <- prcomp(comp3_indi)
summary(princi_comp3)
fviz_eig(princi_comp3, main = "variance explained: components of comp_3")
princ3_ploty <- ggplotly(fviz_eig(princi_comp3, main = 'variance explained: components of comp_3'))
princi_comp4 <- prcomp(comp4_indi)
summary(princi_comp4)
fviz_eig(princi_comp4, main = "variance explained: components of comp_4")
princ4_ploty <- ggplotly(fviz_eig(princi_comp4, main = 'variance explained: components of comp_4'))
```
```{r}
<<<<<<< HEAD
#SEM_comp1 <-
#SEM_comp2 <-
#SEM_comp3 <-
#SEM_comp4 <-
=======
#new behavior variable for removing composites
selected_behaviors_latemods <- selected_norms_ffostare_v1 %>%
select(- comp_1, - comp_2, - comp_3, - comp_4)
SEM_comp1 <- 'latemod_comp1 =~ Zstationary_middle_percent_butters + Zlocomotion_percent_butters + Zhanging_behaviors_butters + Ztactile_exploration_butters + Zmo_manip_apple_butters + Zstation_fr_ffostare + Zstation_mid_ffosta + Zlocomote_ffosta + Zmovement_ffosta + Ztac_expl_ffosta + Zstereo_ffosta + Zteethgrind_ffosta + Zlipsmack_ffosta + Ztouch_app_ffosta + Zmouth_app_ffosta + Zmanip_app_ffosta + Zeat_app_ffosta + Znonvigi_ffosta + Zdir_eye_contact_ffosta'
SEM_comp1_fit <- cfa(model = SEM_comp1, estimator = "MLR", data = selected_behaviors_latemods)
summary(SEM_comp1_fit, standardize = TRUE, fit.measures = TRUE)
SEM_comp2 <- 'latemod_comp2 =~ ZStationary_back_butters + Zstereotypy_butters + Zvigilant_percent_butters + Zstation_back_ffostare + Zself_gro_ffosta + Zthreat_stranger_ffosta + Zfreeze_back_ffosta'
SEM_comp2_fit <- cfa(model = SEM_comp2, estimator = "MLR", data = selected_behaviors_latemods)
summary(SEM_comp2_fit, standardize = TRUE, fit.measures = TRUE)
SEM_comp3 <- 'latemod_comp3 =~ Zstationary_front_percent_butters + Zmovement_percent_butters + Ztouch_butters_percent + Zcrouching_butters + Znonvigilant_percent_butters + Zcrouching_ffosta + Zvigi_ffosta + Zno_response_ffosta'
SEM_comp3_fit <- cfa(model = SEM_comp3, estimator = "MLR", data = selected_behaviors_latemods)
summary(SEM_comp3_fit, standardize = TRUE, fit.measures = TRUE)
SEM_comp4 <- 'latemod_comp4 =~ Zself_groom_percent_butters + Zmouth_butters_percent + Zoral_exploration_butters'
SEM_comp4_fit <- cfa(model = SEM_comp4, estimator = "MLR", data = selected_behaviors_latemods)
summary(SEM_comp4_fit, standardize = TRUE, fit.measures = TRUE)
```