betaval: Generate beta-distributed random numbers

Description Usage Arguments Details Value Author(s) Source References See Also Examples

View source: R/betaval.R

Description

Calculates a random number from a beta distribution and uses the R function pbeta(x,vv,ww).

Usage

1
betaval(mn, sdev, fx = runif(1))

Arguments

mn

mean rate between 0 and 1

sdev

standard deviation

fx

cumulative distribution function, default is a random number between 0 and 1

Details

This function is used by vitalsim

Value

a random beta value

Author(s)

Original MATLAB code by Morris and Doak (2002: 277- 278), adapted to R by Patrick Nantel, 20 June 2005

Source

converted Matlab code from Box 8.3 in Morris and Doak (2002)

References

Morris, W. F., and D. F. Doak. 2002. Quantitative conservation biology: Theory and practice of population viability analysis. Sinauer, Sunderland, Massachusetts, USA.

See Also

Beta Distribution rbeta

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
betaval(.5, sd=.05)
betaval(.5, sd=.05)
## histogram with mean=0.5 and sd=0.05
x <- sapply(1:100, function(x) betaval(0.5, 0.05))
hist(x, seq(0,1,.025), col="green", ylim=c(0,25), xlab="Value",
main="Beta distribution with mean=0.5 and sd=0.05")
# generates a graph similar to Figure 8.2 A in Morris & Doak (2002:264)
# a much simpler version of BetaDemo in Box 8.3
x <- matrix(numeric(3*1000), nrow=3)
sd <-c(.05, .25, .45)
for (i in 1:3){
  for (j in 1:1000){
    x[i,j]<-betaval(.5,sd[i])
  }
}
plot(0,0,xlim=c(0,1), ylim=c(0,0.4), type='n', ylab='Frequency',
xlab='Value', main="Examples of beta distributions")
for (i in 1:3){
   h <- hist(x[i,], plot=FALSE, breaks=seq(0,1,.02)  )
   lines(h$mids, h$counts/1000, type='l', col=1+i, lwd=2, lty=i)
}
legend(0.5,0.4, c("(0.50, 0.05)", "(0.50, 0.25)", "(0.50, 0.45)"),
lty=1:3, lwd=2, col=2:4, title="mean and sd")

popbio documentation built on March 26, 2020, 8:44 p.m.