-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path00-dataElectro.Rmd
More file actions
118 lines (89 loc) · 3.18 KB
/
00-dataElectro.Rmd
File metadata and controls
118 lines (89 loc) · 3.18 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
## Electrofishing data {#dataElectro}
This section retrieves electrofishing data, including both tagged and untagged fish. Fish were untagged if they were too small (< 60 mm, 2 g wet weight) or were captured outside of the core study area (tributaries and 47 sections of the mainstem West Brook).
```{r globalGetDataElectro, include=FALSE}
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
```
```{r librariesDataElectro, echo = FALSE}
# library(devtools)
# install_github(repo = "Conte-Ecology/westBrookData", subdir = "getWBData")
library(getWBData)
library(tidyverse)
library(lubridate)
#library(validate)
devtools::install_github('bletcher/getPrepareWBData')
# use this if command above doesn't work: options(download.file.method = "wininet")
library(getPrepareWBData) # this has functions for preparing West Brook data
```
### Get data
```{r cdWB_electro0}
# default values for createCoreData()
# function (sampleType = "electrofishing", baseColumns = T,
# columnsToAdd = NULL, includeUntagged = F, whichDrainage = "west")
if(getNew_cdsB_electro0) {
cdsB_electro0 <- createCoreData(
sampleType = "electrofishing", #"stationaryAntenna","portableAntenna"
columnsToAdd = c("sampleNumber",
"river",
"survey",
"pass",
"observedLength",
"observedWeight",
"comments"),
includeUntagged = TRUE,
whichDrainage = "west"
) %>%
addTagProperties(
columnsToAdd = c("cohort",
"species",
"dateEmigrated",
"sex",
"species"
)
) %>%
dplyr::filter(species %in% c( "bkt","bnt","ats"),
area %in% c("trib","inside","below","above"),
!is.na(sampleNumber)) %>%
addSampleProperties() %>%
addEnvironmental() #this crashes for stanley data
save(cdsB_electro0, file = './data/cdsB_electro0.RData')
} else {
load(file = './data/cdsB_electro0.RData')
}
str(cdsB_electro0)
```
### Wrangle data
```{r globalWrangle, include=FALSE}
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
```
This section takes cdsB_electro0 and cleans it to create cdsB_electro.
```{r}
reclean_cdsB_electro <- FALSE
```
```{r wrangleElectroMain, cache = TRUE}
if(reclean_cdsB_electro){
drainage <- 'west'
# functions in getPrepareWBData library
cdsB_electro <- cdsB_electro0 %>%
cleanData(drainage) %>%
mergeSites(drainage) %>%
addNPasses(drainage) %>%
mutate(drainage = drainage)
save(cdsB_electro, file = './data/cdsB_electro.RData')
} else {
load(file = './data/cdsB_electro.RData')
}
```
### Explore data
```{r lw, cache = TRUE}
ggplot(cdsB_electro, aes(observedLength, observedWeight, color = species)) +
geom_point(alpha = 0.1) +
scale_x_log10() +
scale_y_log10() +
theme_publication() +
facet_wrap(~ species)
lwReg <- cdsB_electro %>%
nest_by(species) %>%
mutate(reg = list(lm(log(observedWeight) ~ log(observedLength), data = data)))
lwReg %>% summarise(broom::tidy(reg))
lwReg %>% summarise(broom::glance(reg))
```