betaval                package:popbio                R Documentation

_G_e_n_e_r_a_t_e _b_e_t_a-_d_i_s_t_r_i_b_u_t_e_d _r_a_n_d_o_m _n_u_m_b_e_r_s

_D_e_s_c_r_i_p_t_i_o_n:

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

_U_s_a_g_e:

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

_A_r_g_u_m_e_n_t_s:

      mn: mean rate between 0 and 1

    sdev: standard deviation 

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

_D_e_t_a_i_l_s:

     This function is used by 'vitalsim' .

_V_a_l_u_e:

     Returns a random beta value

_A_u_t_h_o_r(_s):

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

_S_o_u_r_c_e:

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

_R_e_f_e_r_e_n_c_e_s:

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

_S_e_e _A_l_s_o:

     Beta Distribution 'rbeta'

_E_x_a_m_p_l_e_s:

     betaval(.5, sd=.05)
     betaval(.5, sd=.05)

     ## histogram with mean=0.5 and sd=0.05
     x<-numeric(100)
     for (i in 1:100)
     {
        x[i]<-betaval(.5,.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(.6,.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")

