forked from wleuenberger/GitHub_HPCC_Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWarblerForHPCC.R
More file actions
37 lines (29 loc) · 1.48 KB
/
WarblerForHPCC.R
File metadata and controls
37 lines (29 loc) · 1.48 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
# Black-throated Blue Warbler Binomial GLM (ML) ---------------------------
# SOLUTIONS
rm(list = ls())
library(tidyverse)
library(spAbundance)
# Our goal for this analysis is to determine how elevation and forest cover
# influence the probability of observing a black-throated blue warbler at
# 1076 locations across the eastern US. Our response variable takes value
# 1 if a black-throated blue warbler was detected at the given site, or takes
# value 0 if the warbler was not detected. We will fit a binomial GLM to
# these data with elevation and forest cover as predictors. This is a
# very basic type of species distribution model.
# Load the data and change your working directory as needed.
load("Data/warbler-data.rda")
ls()
# y = detection (1) or non-detection (0) data of black-throated blue warbler
# at 1076 locations across eastern US.
# elev = standardized elevation at each of the 1076 locations
# forest = standardized local forest cover at each of the 1076 locations
# coords = latitude/longitude coordinates of each location (will use for the optional
# plotting at the end).
# Put the detection data, elevation, and forest together in a data frame.
dat <- data.frame(y, elev, forest)
# Fit a binomial GLM to the data ------------------------------------------
# Fit a binomial GLM to the model with elevation and forest as predictors
# in the model (assume they do not interact).
# ANSWER:
out <- glm(y ~ elev + forest, data = dat, family = binomial)
summary(out)