epp: Building data-set for realized and unrealized EPP-pairs

Description Usage Arguments Details Value See Also Examples

View source: R/epp.R

Description

epp combines a SpatialPointsBreeding, a SpatialPolygons* as obtained from DirichletPolygons and a eppMatrix to create the spatial context for every potential and realized extra-pair male-female combination.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
epp(breedingDat, polygonsDat, eppDat, maxlag = 3)

## S4 method for signature 'epp,missing'
plot(x, zoom, maxlag = 3, zoom.col = "grey", ...)

## S4 method for signature 'epp'
barplot(height, relativeValues = FALSE, ...)

## S4 method for signature 'epp'
as.data.frame(x)

Arguments

breedingDat

A SpatialPointsBreeding object, created by the SpatialPointsBreeding function

polygonsDat

A SpatialPolygons* object as obtained by calling DirichletPolygons function

eppDat

An object of class eppMatrix

maxlag

A numeric value indicating the maximum breeding distance for which male-female combinations should be calculated. When plotting it defines the outermost row of neighbors plotted around a focal id set by zoom

x, height

an epp object

zoom

a SpatialPointsBreeding id which is used for subsetting prior to plot

zoom.col

background color of the id (and hence the polygon) set by zoom

...

further arguments to pass to plot.SpatialPointsBreeding and plot.SpatialPolygons*

relativeValues

Defines the unit of the y-axis. TRUE plots proportions, FALSE absolute numbers.

Details

'plot' plots the territories, the identity of males ('m...') and females ('f...') at breeding sites (numbers), and the extra-pair events (dashed red arrows). Individuals that had extra-pair offspring are marked red. The parameter 'zoom' can be used to make a detailed visual check of a specific location (nestbox) and its surroundings.

'barplot' displays the distribution of extra-pair events over different breeding distances between the partners (in the number of territories) as vertical bars. Note that the distribution of all potential extra-pair partners is displayed as a dashed line only if the argument 'relativeValues' is TRUE.

Value

Returns an S4-class epp-object with 5 slots:

breedingDat

Input breeding data-set.

polygonsDat

Either polygons are estimated automatically using Thiessen Polygons, or input breeding polygons.

eppDat

Input data.frame with all male-female combinations that had EPP together.

maxlag

Input rank. Defaults to 3.

EPP

data.frame containing columns for the focal male and female ("male", "female"), their breeding distance ("rank"), and the parameters associated either with the male (column with prefix "_MALE") or the female (column with prefix "_FEMALE") territory.

See Also

vignette(expp)

Examples

 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
  ### Simple example with three breeding pairs
  require(expp)
  # create raw data
  set.seed(1310)
  b = data.frame(id = as.integer(10:12), x = rnorm(3), y = rnorm(3), 
  male = paste0("m",1:3), female =  paste0("f",1:3), xx = rnorm(3), stringsAsFactors=FALSE  )  
  eppPairs = data.frame(male = c("m1", "m2", "m1"), female=c("f3", "f1", "f2") )
  
  # prepare data
  breedingDat = SpatialPointsBreeding(b, id = 'id', coords = ~ x + y, breeding = ~ male + female)
  polygonsDat = DirichletPolygons(breedingDat)
  eppDat   = eppMatrix(eppPairs, pairs = ~ male + female)

  plot(breedingDat, eppDat)
  
  # convert to epp class     
  x = epp(breedingDat, polygonsDat, eppDat, maxlag = 3)
  as.data.frame(x)
  
  
  #plot 
  plot(x) 
  
  ### Example on a random data set with n breeding pairs and  n/2 extra-pair paternity rate
  # create raw data
  set.seed(123)
  n = 20
  b = data.frame(id = 1:n, x = rnorm(n), y = rnorm(n), 
  male = paste0("m",1:n), female =  paste0("f",1:n), xx = rnorm(n), stringsAsFactors=FALSE  )  
  eppPairs = data.frame(male = sample(b$male, round(n/2) ), female = sample(b$female, round(n/2) ) )
  
  # prepare data
  breedingDat = SpatialPointsBreeding(b, id = 'id', coords = ~ x + y, breeding = ~ male + female)
  polygonsDat = DirichletPolygons(breedingDat)
  eppDat   = eppMatrix(eppPairs, pairs = ~ male + female)
  
  # convert to epp class
  x = epp(breedingDat, polygonsDat, eppDat, maxlag = 10)
  
  # plot 
  plot(x)
  barplot(x) 
  barplot(x, relativeValues = TRUE) 
  

   
  ### Real data example
  # Raw datasets 
  data(bluetit_breeding)
  data(bluetit_epp)
  # select one year 
  year = 2010
  b = bluetit_breeding[bluetit_breeding$year_ == year, ]
  eppPairs = bluetit_epp[bluetit_epp$year_ == year, ]
  
  # prepare data
  breedingDat  = SpatialPointsBreeding(b, id = 'id', coords = ~ x + y, breeding = ~ male + female)
  polygonsDat = DirichletPolygons(breedingDat)
  eppDat = eppMatrix(eppPairs, pairs = ~ male + female)
  
  # convert to epp class
  x = epp(breedingDat, polygonsDat, eppDat, maxlag = 2)
  
  # plot
  plot(x)
  barplot(x) 
  # plot zoom
  plot(x, zoom = 120, maxlag = 3) 
  
  # run model on epp probability     
  dat = as.data.frame(x)
  nrow(dat[dat$epp == 1, c('male', 'female')] )
  nrow(unique(eppPairs))
  
  if(require(lme4))
   (summary(glmer(epp ~ rank + male_age_MALE + (1|male) + (1|female), 
    data = dat, family = binomial)))


  

expp documentation built on June 20, 2021, 5:06 p.m.