-
Notifications
You must be signed in to change notification settings - Fork 0
/
squirrel_data.R
96 lines (72 loc) · 2.23 KB
/
squirrel_data.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
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
#Library ----
library(here)
library(readr)
library(dplyr)
library(tidyverse)
library(tidylog)
library(summarytools) # RESUMEN DE LAS VARIABLES (niveles, freq, graph, missing data points)
#Data----
data <- read_csv("2018_Squirrel_Data.csv")
glimpse(data)
#create a subset with (possibly) interesting variables
data_sum <- data %>% select(X,
Y,
`Unique_Squirrel_ID`,
Shift,
Date,
Age,
Location,
16,17,18,19,20,27,28,29)
#create var "activity" - what was the sq doing at moment of obs.?
#var for +1 activity
data_sum2 <- data_sum %>%
mutate(activity = case_when (Running == 'TRUE' ~ 'running',
Chasing == "TRUE" ~ "chasing",
Climbing == "TRUE" ~ "climbing",
Eating == "TRUE" ~ "eating",
Foraging == "TRUE" ~ "foraging"))
data_sum2$activity<- as.factor(data_sum2$activity)
#limpiar datos de NA y observaciones en duda
data_sum3<-na.omit(data_sum2)
data_sum3<-data_sum3[!(data_sum3$Age=="?"),]
plot(factor(Eating) ~ factor(Age), data = data_sum3)
#¿qué necesitan las ardillas para comer?
#varios modelos ---------
sq <- glm(Eating ~ Shift+Location,
data = data_sum3,
family = binomial)
summary(sq)
library(report)
report(sq)
residuals(sq)
plot(sq)
report(sq)
sq4 <- glm(Eating ~ Shift,
data = data_sum3,
family = binomial)
summary(sq4)
sq1 <- glm(Eating ~ Location,
data = data_sum3,
family = binomial)
summary(sq1)
sq2 <- glm(Eating ~ Location*Age,
data = data_sum3,
family = binomial)
summary(sq2)
sq3 <- glm(Eating ~ Location*Shift,
data = data_sum3,
family = binomial)
summary(sq3)
AIC(sq, sq1, sq2, sq3)
library("effects")
allEffects(sq)
plot(allEffects(sq))
library(visreg)
visreg(sq, scale = "response", rug = FALSE)
#Es decir, ya sea tarde o temprano, las ardillas suelen estar
#comiendo en el suelo
#Model checking ----------
library("DHARMa")
simulateResiduals(sq, plot = TRUE)
library(performance)
check_predictions(sq)