eppSimDat: Type I error rate simulations

Description Usage Arguments Details Value Examples

View source: R/eppSimDat.R

Description

A helper function to perform Type I error rate simulations.

Usage

1
2
3
4
5
6
7
8
eppSimDat(
  N = 10,
  meanClutch = 10,
  eppRate = 0.1,
  eppMax = 12,
  eppMales = 0.35,
  nLags = 3
)

Arguments

N

Number of breeding pairs; default value is 10

meanClutch

Mean clutch size (integer); clutch size it is assumed to be Poisson distributed; default is 10

eppRate

Proportion of extra-pair young in population; default is 0.10

eppMax

Maximum number of extra-pair young by male; default is 12

eppMales

Proportion of extra-pair males in population; default is 0.35

nLags

maxlag parameter to pass to DirichletPolygons

Details

All default values match the values found in one of our study populations ('Westerholz').

Value

An object of class epp The data.frame of the EPP slot contains two variable (trait_MALE trait_FEMALE ) simulated independent from the epp variable.

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
d = eppSimDat()
plot(d)



# Type I error rate simulation

require(lme4)
pval_glmer = vector(mode = "numeric", length = 0)
pval_glm = vector(mode = "numeric", length = 0)

# For meaningful results increase i to e.g. 500 and N in eppSimDat to e.g. 120
for(i in 1:5) { 
  x = as.data.frame(eppSimDat(N = 25, meanClutch = 10, eppRate = 0.10, eppMax = 12, 
      eppMales = 0.35, nLags = 3))
  
  fm1glmer = glmer(epp ~ rank + trait_MALE + trait_FEMALE + (1 | male) + (1 | female) , 
  data = x, family = binomial, nAGQ =  0)
  fm0glmer = update(fm1glmer, epp ~ 1 + (1 | male) + (1 | female) )
  pval_glmer[i] = anova(fm0glmer, fm1glmer)$"Pr(>Chisq)"[2]
  
  fm1glm = glm(epp ~ rank + trait_MALE + trait_FEMALE  , data = x, family = binomial)
  fm0glm = update(fm1glm, epp ~ 1 )
  pval_glm[i] = anova(fm0glm, fm1glm, test = "Chisq")$"Pr(>Chi)"[2]
  
  print(i)
 }

# Type I error rate of glmer models
table(pval_glmer<0.05)[2]/length(pval_glmer)


# Type I error rate of the equivalent glm models
table(pval_glm<0.05)[2]/length(pval_glm)

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