# Install packages
install.packages("rgdal")
install.packages("sp")
install.packages("adehabitatHR")
install.packages("gplots")
Q1: What seasons are represented? Write in a few sentences why is seasonality important to understand for wildlife?
winter, spring, summer, fall. seasonality affect food availability and behavior which in turn determine home ranges.Seasons help understand changes in wildlife distributions on a yearly cycle.
# Open coyote data in R
setwd("P:/Lab3")
coyote <- read.csv("Coyote.csv")
# Examine the object "coyote"
head(coyote)
## ID Date Time Y X Season
## 1 Cy2 25/01/2006 16:01:18 56.11957 -113.3292 WINTER
## 2 Cy2 25/01/2006 20:01:18 56.11961 -113.3291 WINTER
## 3 Cy2 26/01/2006 00:01:19 56.11967 -113.3293 WINTER
## 4 Cy2 26/01/2006 04:00:49 56.11959 -113.3291 WINTER
## 5 Cy2 26/01/2006 08:00:55 56.11957 -113.3292 WINTER
## 6 Cy2 26/01/2006 12:01:09 56.11970 -113.3292 WINTER
tail(coyote)
## ID Date Time Y X Season
## 8426 Cy9 01/02/2008 04:00:52 55.91841 -113.9382 WINTER
## 8427 Cy9 01/02/2008 06:00:54 55.91700 -113.9661 WINTER
## 8428 Cy9 01/02/2008 08:00:50 55.91284 -113.9774 WINTER
## 8429 Cy9 01/02/2008 10:00:53 55.91284 -113.9774 WINTER
## 8430 Cy9 01/02/2008 12:00:53 55.91289 -113.9775 WINTER
## 8431 Cy9 01/02/2008 14:01:11 55.90490 -113.9787 WINTER
nrow(coyote)
## [1] 8431
ncol(coyote)
## [1] 6
dim(coyote)
## [1] 8431 6
summary(coyote)
## ID Date Time Y
## Length:8431 Length:8431 Length:8431 Min. :55.68
## Class :character Class :character Class :character 1st Qu.:55.88
## Mode :character Mode :character Mode :character Median :55.91
## Mean :56.07
## 3rd Qu.:56.50
## Max. :56.59
## X Season
## Min. :-114.7 Length:8431
## 1st Qu.:-114.0 Class :character
## Median :-113.9 Mode :character
## Mean :-113.8
## 3rd Qu.:-113.5
## Max. :-113.0
# what type of object is coyote
class(coyote)
## [1] "data.frame"
Q2: What type of object is coyote (0.5 pts)? And why (0.5 pts) (think back to the first R lab where we went over the difference between vectors, matrices, data frames, and lists)?
Coyote is a data frame: a list of vectors (variables) of equal lenght. It is a 2D structure of row and colums. Each observation is a row, each variable is a colum.
Q3: Which type of object can contain both numbers and factors (factors like “WINTER”, “SUMMER”, or “MALE”, “FEMALE”)? (0.5 pts)
list
Q4: Can these units be simply translated into a distance? Will X1 – X2 = distance along X between points? (0.5 pts)
No, these coordinate are in decimal degrees and represent angle values not distances
#open the package in R
library(rgdal)
## Warning: package 'rgdal' was built under R version 4.1.3
## Loading required package: sp
## Warning: package 'sp' was built under R version 4.1.3
## Please note that rgdal will be retired by the end of 2023,
## plan transition to sf/stars/terra functions using GDAL and PROJ
## at your earliest convenience.
##
## rgdal: version: 1.5-32, (SVN revision 1176)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.4.1, released 2021/12/27
## Path to GDAL shared files: C:/Users/mgonza79/Documents/R/win-library/4.1/rgdal/gdal
## GDAL binary built with GEOS: TRUE
## Loaded PROJ runtime: Rel. 7.2.1, January 1st, 2021, [PJ_VERSION: 721]
## Path to PROJ shared files: C:/Users/mgonza79/Documents/R/win-library/4.1/rgdal/proj
## PROJ CDN enabled: FALSE
## Linking to sp version:1.5-0
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal.
#take coyote X_utm & Y_utm, and project them as a matrix (2 dimensional) using UTM zone 11.
coyote[,c("X_utm","Y_utm")] <- project(as.matrix(coyote[,c("X", "Y")]), "+proj=utm +zone=11")
Q5: Now what are the units of ou X_utm and Y_utm? (0.5 pts) Meters
# Tell R that this is spatial data
library(sp) #open the package in R
coordinates(coyote) <- c("X_utm", "Y_utm")
coyote[1:10,]
## coordinates ID Date Time Y X Season
## 1 (728170.7, 6225459) Cy2 25/01/2006 16:01:18 56.11957 -113.3292 WINTER
## 2 (728178.1, 6225464) Cy2 25/01/2006 20:01:18 56.11961 -113.3291 WINTER
## 3 (728165.5, 6225470) Cy2 26/01/2006 00:01:19 56.11967 -113.3293 WINTER
## 4 (728177, 6225462) Cy2 26/01/2006 04:00:49 56.11959 -113.3291 WINTER
## 5 (728170.9, 6225458) Cy2 26/01/2006 08:00:55 56.11957 -113.3292 WINTER
## 6 (728170.5, 6225473) Cy2 26/01/2006 12:01:09 56.11970 -113.3292 WINTER
## 7 (728067.1, 6225278) Cy2 26/01/2006 16:00:49 56.11800 -113.3311 WINTER
## 8 (728062.8, 6225278) Cy2 26/01/2006 20:00:58 56.11800 -113.3311 WINTER
## 9 (728062.1, 6225282) Cy2 27/01/2006 00:01:18 56.11804 -113.3311 WINTER
## 10 (728061.2, 6225266) Cy2 27/01/2006 04:00:49 56.11790 -113.3312 WINTER
# Visualize coyote X Y coordinates
plot(coyote, axes = TRUE)
#The unique() command tells what the unique values of a column are.
coyote.ids <- unique(coyote$ID)
coyote.ids
## [1] "Cy2" "Cy3" "Cy4" "Cy5" "Cy9"
# colour each individual differently on our graph so we can see how they move around
plot(coyote, axes = TRUE) #Draws the first plot
title(xlab = "Longitude (m)", ylab = "Latitude (m)") #Adds axes labels to plot
colours <- c("red", "brown", "green", "purple", "blue") #Sets the colours for out plot
for(i in 1:length(coyote.ids)){
plot(coyote[coyote$ID == coyote.ids[i], ], add = TRUE, col = colours[i])
} #add a new colour to the plot
library(adehabitatHR) #open the package in R
## Warning: package 'adehabitatHR' was built under R version 4.1.3
## Loading required package: deldir
## Warning: package 'deldir' was built under R version 4.1.3
## deldir 1.0-6 Nickname: "Mendacious Cosmonaut"
##
## The syntax of deldir() has had an important change.
## The arguments have been re-ordered (the first three
## are now "x, y, z") and some arguments have been
## eliminated. The handling of the z ("tags")
## argument has been improved.
##
## The "dummy points" facility has been removed.
## This facility was a historical artefact, was really
## of no use to anyone, and had hung around much too
## long. Since there are no longer any "dummy points",
## the structure of the value returned by deldir() has
## changed slightly. The arguments of plot.deldir()
## have been adjusted accordingly; e.g. the character
## string "wpoints" ("which points") has been
## replaced by the logical scalar "showpoints".
## The user should consult the help files.
## Loading required package: ade4
## Warning: package 'ade4' was built under R version 4.1.3
## Loading required package: adehabitatMA
## Warning: package 'adehabitatMA' was built under R version 4.1.3
## Registered S3 methods overwritten by 'adehabitatMA':
## method from
## print.SpatialPixelsDataFrame sp
## print.SpatialPixels sp
## Loading required package: adehabitatLT
## Warning: package 'adehabitatLT' was built under R version 4.1.3
## Loading required package: CircStats
## Warning: package 'CircStats' was built under R version 4.1.3
## Loading required package: MASS
## Loading required package: boot
coyote.mcp<-mcp(coyote[,1], percent=100, unout = "km2")
# take a look at the result
coyote.mcp
## Object of class "SpatialPolygonsDataFrame" (package sp):
##
## Number of SpatialPolygons: 5
##
## Variables measured:
## id area
## Cy2 Cy2 365.07447
## Cy3 Cy3 70.54053
## Cy4 Cy4 760.02507
## Cy5 Cy5 23.21367
## Cy9 Cy9 2102.00750
# plot these home ranges on top of our old plot as polygons
# colour each individual differently on our graph so we can see how they move around
plot(coyote, axes = TRUE) #Draws the first plot
title(xlab = "Longitude (m)", ylab = "Latitude (m)") #Adds axes labels to plot
colours <- c("red", "brown", "green", "purple", "blue") #Sets the colours for out plot
for(i in 1:length(coyote.ids)){
plot(coyote[coyote$ID == coyote.ids[i], ], add = TRUE, col = colours[i])
} #add a new colour to the plot
plot(coyote.mcp, col=colours, add = TRUE) #Plot these home range polygon
Q6: The way it looks now, which colour coyote appears to have the largest home range, and what is its area? (0.5 pts)
Cy9 (blue), area=2102.00750 m2
Q7: Which one appears to have the smallest, and what is its area? (0.5 pts)
Cy5 (purple), area=23.21367 m2
# Calculates the home ranges for the sequence of percentages 20 to 100, by units of 5
coyote.mcp.area <- mcp.area(coyote[,1], percent = seq(20, 100, by = 5), unout = "km2")
# lets look at the table
coyote.mcp.area
## Cy2 Cy3 Cy4 Cy5 Cy9
## 20 61.22633 3.152930 7.126678 0.7832743 2.856772
## 25 86.98462 3.517477 7.537980 0.9938066 11.450617
## 30 88.30940 3.620851 12.458540 1.2749979 15.312119
## 35 92.33012 7.247768 18.002590 1.8095545 17.760458
## 40 92.64718 12.094441 23.413128 1.9531205 26.697886
## 45 92.99602 13.023266 26.382104 2.2383501 31.549915
## 50 98.05511 13.043228 28.013543 2.5307773 33.523108
## 55 110.88178 13.102919 28.663168 2.7874943 42.480423
## 60 111.16833 13.103151 29.037640 3.1887127 48.735846
## 65 136.07476 13.107088 29.880897 3.5480166 52.819018
## 70 137.48941 14.447102 30.429624 4.2420767 96.580584
## 75 224.15031 31.971027 35.654935 4.9774124 110.865591
## 80 328.20513 33.323561 40.556271 5.9614138 133.809985
## 85 332.10698 38.616528 52.169431 6.6313380 168.278403
## 90 362.15368 55.351995 70.963834 7.5070106 276.170274
## 95 363.66332 57.356903 234.420668 9.3027682 647.766479
## 100 365.07447 70.540535 760.025066 23.2136749 2102.007505
#Plots all the home ranges vs. percentage data used
par(mfrow = c(2,3), mar = c(4,6,2,2)) #Set graph parameters to allow multiple plots with smaller margins. Mfrow=c(2,3) means 2X3 graphs, and mar=margins.
for(i in 1:ncol(coyote.mcp.area)){ #For all the columns in coyote.mcp.area
plot(seq(20,100, by = 5), coyote.mcp.area[,i], xlab = "Homerange level", ylab = expression("Home-range size" ~ (km^{2})),
type = "b", ylim = c(0, 2200), main =
colnames(coyote.mcp.area)[i]) #plot each column
} #plot mcp area for the sequence (20-100, by 5) of percentage of home range area used vs size of home range for different coyotes.
Q8: Which coyote has the largest home range when 100% of the data are included? (0.5 pts) Can you think of a reason why an individual animal might have a much higher area than its peers at the 100% level? (0.5 pts)
Cy9, the home range area so is much higher because of the outlier point included when 100% of the data is used. This outlier point might be because during the last time period it was collard, the coyote was displaced over an area significantly larger than its home range.
# logarithmically transform our home range sizes so we can get a better idea what is happening at lower percentages
par(mfrow = c(2,3), mar = c(4,6,2,2)) #Plots all the log transformed home range sizes vs. percentage data used
for(i in 1:ncol(coyote.mcp.area)){
plot(seq(20,100, by = 5), log(coyote.mcp.area[,i]), xlab =
"Home-range level", ylab =
expression("Log home-range" ~ (log ~ km^{2})), type = "b",
ylim = c(0.1, 8), main = colnames(coyote.mcp.area)[i])
}
Q9: Which coyote has the largest home range when 50% of the data are included? (0.5 pts)
Cy2
Q10: Three of these coyotes are young males who, during the period that they were collared, were displaced from their territories and wandered over an area that is significantly larger than their home range. This wandering period only took up 5% of the time period they were collared. Which three coyotes am I talking about? (0.75 pts)
Cy4, Cy5, Cy9
#Make the old plot:
par(mfrow = c(1,1)) #one plot
plot(coyote, axes = TRUE) #Draws the first plot
title(xlab = "Longitude (m)", ylab = "Latitude (m)") #Adds axes labels to plot
#Add kernel home ranges:
coyote.kud <- kernelUD(coyote[,1]) #Creates the utilization distribution for each animal
coyote.kd <- getverticeshr(coyote.kud, unout = "km2", percent = 95) #Calculates 95% homeranges
plot(coyote.kd, col = c("red", "brown", "green", "purple", "blue"), add = TRUE) #Plots the 95% home ranges
Compare the 95% kernel home range estimation map with th 95% minimum convex polygon estimation map:
#Compare kernel and mcp:
par(mfrow = c(2,2)) #Sets your graphing window to accept 1 row of 2 graphs
coyote.mcp <- mcp(coyote[,1], percent=95, unout = "km2") #Calculates minimum convex polygon
#MCP Plot
plot(coyote, axes = TRUE) #Draws the initial plot
title(xlab = "Longitude (m)", ylab = "Latitude (m)") #Adds axes labels to plot}
plot(coyote.mcp, col = colours, add = TRUE) #Add MCP shapes
title(main = "Minimum Convex Polygon 95%") #Give it a title
#Kernel Plot
plot(coyote, axes = TRUE) #Draws the initial plot
title(xlab = "Longitude (m)", ylab = "Latitude (m)") #Adds axes labels to plot
plot(coyote.kd, col = colours, add = TRUE) #Add Kernel shapes
title(main = "Kernel Density 95%") #Give it a title
Q11: Overall, which method on average gives larger home range estimates at the 95% level? Hint: look at both the coyote.mcp and the coyote.kd objects. Try the command: mean(). Remember that to call a column, you need to use the number sign ($). (0.5 pts)
mean(coyote.mcp$area)
## [1] 262.502
mean(coyote.kd$area)
## [1] 392.0903
On average the Kernel Density Method gives larger home range estimates at the 95% level
Q12: Which method produces less contiguous home ranges (ie: which one produced home ranges that are broken up?) (0.5 pts)
the Minimum Convex Polygon (MCP) produces less contiguous home ranges
# Compare home ranges at the 50% level
# Repeat the process, using percent= 50
coyote.mcp <- mcp(coyote[,1], percent=50, unout = "km2")
coyote.kd <- getverticeshr(coyote.kud, unout = "km2", percent= 50)
#MCP Plot
plot(coyote, axes = TRUE) #Draws the intial plot
title(xlab = "Longitude (m)", ylab = "Latitude (m)") #Adds axes labels to plot
plot(coyote.mcp, col = colours, add = TRUE) #Add MCP shapes
title(main = "Minimum Convex Polygon 50%") #Give it a title
#Kernel Plot
plot(coyote, axes = TRUE) #Draws the intial plot
title(xlab = "Longitude (m)", ylab = "Latitude (m)") #Adds axes labels to plot
plot(coyote.kd, col = colours, add = TRUE) #Add Kernel shapes
title(main = "Kernel Density 50%") #Give it a title
Q13: For coyote ID Cy2 (red), which technique estimates the larger home range? (0.5 pts) Kernel Density
Q14: Is it typical for this technique to estimate a larger home range than the other? (0.5 pts)
No, usually MCP gives larger estimates
Q15: What is it about the space use of this coyote that could explain why this technique estimated a larger home range than the other? (0.5 pts)
the Kernel density technique asses intensity of use of habitat unlike MCP, therefore Cy2 could be using very intensely a specific habitat at the 50% level.
# subset our coyote data frame based on the four seasons identified in the “Season” column
coyote.sum <- subset(coyote, Season=="SUMMER")
coyote.fal <- subset(coyote, Season=="FALL")
coyote.win <- subset(coyote, Season=="WINTER")
coyote.spr <- subset(coyote, Season=="SPRING")
# Refresh ID because summer and fall has data for 3 coyotes (not five)
coyote.sum$ID <- factor(coyote.sum$ID)
coyote.fal$ID <- factor(coyote.fal$ID)
#combine each individual season's dataframe into a list
coyote.sea <- list(coyote.sum, coyote.fal, coyote.win, coyote.spr) #Combine all the coyote seasons into one list
#add the Seasons as factors to coyote object
coyote$Season<-as.factor(coyote$Season)
is.factor(coyote$Season)
## [1] TRUE
#create a vector with all the seasons:
seasons <- factor(levels(coyote$Season)[c(3,1,4,2)], levels =
levels(coyote$Season)[c(3,1,4,2)]) #create a vector with all the seasons
coyote.kud.sea <- list() #Initialize a list to contain four dataframes, 1 for each season
for(i in 1:length(seasons)){
coyote.kud.sea[[i]] <- kernelUD(coyote.sea[[i]][, 1])
}
# calculate the kernel density for each season using a home range level of 70 percent
coyote.kd.sea <- list() #Create an empty list for the kernel densities
for(i in 1:length(seasons)){ #For each season, calculate the vertices of each home range
coyote.kd.sea[[i]] <- getverticeshr(coyote.kud.sea[[i]],
unout = "km2", percent = 70)
}
par(mfrow = c(2,2), mar = c(3,2,1.5,0.5)) #Set plot window for 4 plots
for(i in 1:length(seasons)){ #For all seasons
if(i == 1 | i == 2){ #If its summer or fall there is no red or brown!
#Draws the first plot:
plot(coyote, axes = TRUE) #Draws the first plot
title(xlab = "Longitude (m)", ylab = "Latitude (m)") #Adds axes labels to plot
for(j in 1:length(coyote.ids)){ #For every coyote ID, add a new colour to the plot
plot(coyote[coyote$ID == coyote.ids[j], ], add = TRUE, col =
colours[j])
}
#Adds the polygons:
title(xlab = "Longitude (m)", ylab = "Latitude (m)") #Adds axes labels to plot
plot(coyote.kd.sea[[i]], col = c("green", "purple", "blue"), add =
TRUE, lwd = 2)
title(main = as.character(levels(seasons)[i]))
}
else{ #For winter and spring there are all five coyotes
#Draws the first plot:
plot(coyote, axes = TRUE)
title(xlab = "Longitude (m)", ylab = "Latitude (m)") #Adds axes labels to plot
for(j in 1:length(coyote.ids)){ #For every coyote ID, add a new colour to the plot
plot(coyote[coyote$ID == coyote.ids[j], ], add = TRUE, col =
colours[j])
}
#Adds the polygons:
title(xlab = "Longitude (m)", ylab = "Latitude (m)") #Adds axes labels to plot
plot(coyote.kd.sea[[i]], col = colours, add = TRUE, lwd = 2)
title(main = as.character(levels(seasons)[i]))
}
}
Q16: In which season do most coyotes appear to occupy the largest home ranges? (0.5 pts)
Winter
Q17: Why do you believe this is the case? (0.5 pts)
Food is more scare in winter, coyotes need to go further to find food.
Q18: In which season do these coyotes appear to occupy the smallest home range? (0.5 pts)
Spring
Q19: Why do you think this is the case? (0.5 pts)
pups are born in the spring and the parents don’t travel as far to keep their young close.
Q20: Which coyote appears to occupy a different summer and winter range? (not just the area, but the actual location changes) (0.5 pts)
Cy4 (green)
Q21: One of these coyotes was displaced out of its home range during the summer by a nearby wolf pack. Which coyote am I talking about? (0.5 pts)
Cy2 (red)
#open required library
library(gplots)
## Warning: package 'gplots' was built under R version 4.1.3
##
## Attaching package: 'gplots'
## The following object is masked from 'package:stats':
##
## lowess
par(mfrow = c(1,1), mar = c(4,6,1,1)) #Set graph window parameters
#Gather all the seasons home range sizes
home.range.area <- data.frame(area = numeric(), season =
factor(levels = levels(seasons)))
row <- c(1,4,7,12,17)
for(i in 1:length(seasons)){
home.range.area[row[i]:(row[i+1]-1),"area"] <-
unlist(coyote.kd.sea[[i]]$area)
home.range.area[row[i]:(row[i+1]-1),"season"] <- seasons[i]
}
#Create an X and Y vector of home range sizes and season
Y <- home.range.area$area
X <- home.range.area$season
#Plot
plotmeans(Y ~ X, xlab = "Season", ylab = "Kernel Estimated 70%
Home\nRange Size in km squared", minbar = 0) #Plots the mean and confidence interval for the estimated home range size for each season
## Warning in arrows(x, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, : zero-
## length arrow is of indeterminate angle and so skipped
## Warning in arrows(x, ui, x, pmin(y + gap, ui), col = barcol, lwd = lwd, : zero-
## length arrow is of indeterminate angle and so skipped
This plot contains 95% confidence intervals of the estimated average coyote home range size by season using 70% kernel density estimates.
Q22: Which season has the largest confidence interval for its estimated home range size? (0.5 pts)
Summer
Q23: Which season has the smallest? (0.5 pts)
Spring
Q24: So, in what season were the coyotes most consistent in the way they used their home range? What is happening during this season that requires such loyalty to a particular geographic area? (0.5 pts)
Spring = offspring birth and rearing
Q25: Describe 3 ways in which home range location, size, or shape could be used to protect or conserve a species or landscape? (1.5 pts)
1. Home range locations help identify which areas to protect.
2. Home range shapes help asses intra and interspecific interactions at a larger scale (what is avoided or fallowed? Is there mutualism or parasitism?). protecting connected species might be require to ensure conservation of a target species.
3.Home range size help asses on average what area is required by an individual of a specific species. This helps design nature reserves or sanctuaries that want to host that species.