-
Notifications
You must be signed in to change notification settings - Fork 0
/
MW_WTASentiment.Rmd
185 lines (151 loc) · 5.98 KB
/
MW_WTASentiment.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
---
title: "MW_WTASentiment.Rmd"
author: "Janneke Hille Ris Lambers, Aji John, Meera Sethi, Elli Theobald"
date: "12/22/2020"
output: html_document
---
**IN PROGRESS: exploratory in nature**
# This notebook expands on **MW_WTAanalysis.Rmd**
# Setup R markdown, load packages
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(randomForest)
```
## Visualize the sentiments
```{r }
WTA_MW_dat <- read.csv("output/WTA_MW_dat.csv", header=TRUE)
WTA_MW_dat %>%
filter (trail=='GB') %>%
ggplot() + geom_point(aes(year,total_s,color=month)) + geom_jitter(aes(year,total_s,color=month)) + theme_minimal(base_size = 18) +
labs(x="Year", y="Overall score", color="Month")
```
## By year, and month what is the spread.
```{r, echo=FALSE}
WTA_MW_dat %>%
filter (trail=='GB') %>%
ggplot() + geom_point(aes(year,month,color=as.factor(total_s))) + geom_jitter(aes(year,month,color=as.factor(total_s))) + theme_minimal(base_size = 18) +
# scale_y_discrete(limits=c('January','May','June','July','August','September','October')) +
labs(x="Year", y="Overall score", color="Score")
```
## By year, and month what is the spread - histogram
```{r, echo=FALSE}
WTA_MW_dat %>%
filter (trail=='GB') %>%
ggplot() + geom_bar(aes(month,fill=as.factor(round(total_s,digits = 1)))) +
theme_minimal(base_size = 18) +
facet_grid(.~year)+
#coord_flip() +
scale_x_discrete(limits=c('May','June','July','August','September','October')) +
labs(x="Month", y="Count", fill="Score") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
```
## Overlap the sentiment score with richness
```{r, echo=FALSE}
Factor <- 1
WTA_MW_dat %>%
filter (trail=='GB') %>%
ggplot() +
geom_bar(aes(month,fill=as.factor(round(total_s,digits = 1)))) +
geom_smooth(aes(month,rich), method="loess", col="red") +
theme_minimal(base_size = 18) +
scale_y_continuous(name="Score", sec.axis=sec_axis(~./Factor, name="Richness")) +
facet_grid(.~year)+
#coord_flip() +
scale_x_discrete(limits=c('May','June','July','August','September','October')) +
labs(x="Month", y="Count", fill="Score") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
```
##
```{r, echo=FALSE}
Factor <- 1
WTA_MW_dat %>%
filter (trail=='GB') %>%
ggplot() +
geom_bar(aes(DOY,fill=as.factor(round(total_s,digits = 1)))) +
geom_smooth(aes(DOY,rich/10), col="red") +
theme_minimal(base_size = 18) +
facet_grid(.~year)+
scale_y_continuous(name="Count", sec.axis=sec_axis(~./10, name="Richness")) +
#coord_flip() +
#scale_x_discrete(limits=c('May','June','July','August','September','October')) +
labs(x="DOY", y="Count", fill="Score") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
```
## See if the sentiment overlaps with species richness
```{r, echo=FALSE}
scaleFactor = 2
WTA_MW_dat %>% filter (trail=='GB') %>%
ggplot() + geom_point(aes(DOY,total_s)) +
geom_smooth(aes(DOY,total_s)) +
geom_smooth(aes(DOY,y=rich/scaleFactor), method="loess", col="red") +
scale_y_continuous(name="Score", sec.axis=sec_axis(~./scaleFactor, name="Richness")) +
theme_minimal(base_size = 18) +
facet_grid(.~year)+
labs(x="DOY", y="Score",title = "GB - Richness vs Score")+
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
```
## Importance of individual sentiment scores on final sentiment
```{r }
WTA_MW_dat_notnull <- WTA_MW_dat[,c('bug_s','wild_s',
'crowd_s','trail_s',
'weather_s','view_s',
'wildflower_s','total_s')]
bag.sentiments<-randomForest(total_s ~ . ,data=WTA_MW_dat_notnull,importance=TRUE,keep.inbag = TRUE,ntree=500,na.action = na.omit)
# View the forest results.
print(bag.sentiments)
# Importance of each predictor.
print(importance(bag.sentiments,type = 2))
```
Trail sentiment contributes the most to the final score
```{r }
importrf <- importance(bag.sentiments,type = 2)
importrf <-importrf %>% as.data.frame()
importrf$variables <- c("bug_s", "wild_s" , "crowd_s" , "trail_s" , "weather_s" , "view_s", "wildflower_s" )
importrf<-importrf%>% arrange(desc(IncNodePurity) )
importrf%>% ggplot() + geom_col(aes(x=reorder(variables, -IncNodePurity),IncNodePurity)) +
theme_minimal(base_size = 18) +
labs(x="Variables","Importance") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
```
## Is it - Trail sentiment is correlated with Wildflower sentiment
```{r }
rel_trail_wildflower <- lm(data = WTA_MW_dat_notnull,trail_s~wildflower_s)
summary(rel_trail_wildflower)
```
Not really.
## check if trail sentiment was sufficient to explain the total sentiment
```{r }
rel_total_trail <- lm(data = WTA_MW_dat_notnull,total_s~trail_s)
summary(rel_total_trail)
```
Singificant, and explains 15% of the variation.
## Lets check the richness and total sentiment
```{r }
WTA_MW_dat_richness <- WTA_MW_dat[,c('bug_s','wild_s',
'crowd_s','trail_s',
'weather_s','view_s',
'wildflower_s','total_s','total_s2','rich')]
rel_total_richness <- lm(data = WTA_MW_dat_richness,total_s~rich)
summary(rel_total_richness)
```
Not really correlated.
## Visitation and sentiment related ?
```{r }
MR_Visitation <- read_csv('./data/Visitation by Month.csv')
# Reshaping the dataframe -
MR_Visitation_reshaped <- MR_Visitation %>%
pivot_longer(-Year, names_to = "Month", values_to = "Visitation")
head(MR_Visitation_reshaped)
```
```{r }
MR_Visitation_reshaped %>%
filter(Year %in% c(2015:2019)) %>%
ggplot() + geom_point(aes(Month,Visitation, color=as.factor(Year))) +
scale_x_discrete(limits=c('JAN','FEB','MAR','APR','MAY',
'JUN','JUL','AUG','SEP','OCT','NOV','DEC')) +
theme_minimal(base_size = 18)+
labs(color='Year') +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
```
Highest visitations in 2019, especially in peak months - July and August. Seems to link to trail sentiments.