-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadme.Rmd
117 lines (88 loc) · 2.96 KB
/
Readme.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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file
To regenerate, run `quarto::quarto_render("Readme.Rmd", output_file = "README.md")`
-->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# rabbit
<!-- badges: start -->
<!-- badges: end -->
The goal of rabbit is to ...
Use package `RcppRoll` to optimise claulcations of metrics clculated in wolling windows, e.g. rolling mean, var, sd etc.
## Installation
You can install the development version of rabbit from [GitHub](https://github.com/) with:
```{r install, eval=FALSE}
# install.packages("devtools")
devtools::install_github("traitecoevo/rabbit")
```
## Example
This is a basic example:
```{r example}
library(rabbit)
library(dplyr)
```
super-fast version of the rolling window calculations:
example file is less than one hour of a bilby called piccolo:
```{r}
df <- arrow::read_parquet("tests/testthat/raw_Pic2Jan_50000.parquet")
nrow(df)
```
the new version is pretty fast:
```{r}
system.time(dat <- moving_window_calcs_2(df))
```
## Identifying high sumVDBA times
sumVDBA is the best measure we have of heat-generating movement or activities:
```{r,warning=FALSE}
library(ggplot2)
dat %>%
ggplot(aes(x = time, y = sumVDBA)) +
geom_point(size = 0.2) + theme_classic()
```
Now can classify all these movements based on a pre-built classifier from a zoo animal:
```{r,warning=FALSE}
# load a classifcation object
MSOM = readRDS("tests/testthat/MSOM_8by7_small.rds")
# make predictions
nighttime_activities <- classify_behaviors(dat, MSOM)
```
we can order the activities by their estimated energy use / heat production:
```{r}
nighttime_activities <-
nighttime_activities %>%
filter(!is.na(behavior)&!is.na(sumVDBA)) %>%
mutate(behavior = forcats::fct_reorder(behavior, sumVDBA, .fun = median, na.rm = TRUE))
```
and we can plot energy use and estimated activity through time
```{r}
nighttime_activities %>%
ggplot(aes(x = time, y = sumVDBA, col = behavior)) +
geom_point(alpha = 0.7, size = 0.2) + theme_classic()
```
the data seems to at a temporal resolution of 25 readings per second which might be a lot to handle for various graphing applications. Here is a function to take the mode of the categorical variables at a given resolution.
```{r}
window_in_minutes <- 1
minute_summary <- summary_by_time(nighttime_activities,
time_col = "time",
behavior_col = "behavior",
window_minutes=window_in_minutes
)
minute_summary %>%
ggplot(aes(x = window, y = mode_behavior, color = mode_behavior)) +
geom_point(size = 3) +
labs(
x = "Time",
y = "Mode Behavior",
title = paste0("Most Common Behavior Within Every ", window_in_minutes, " Minute(s)")
) +
theme_minimal() -> plotting
print(plotting)
```