Title: | Approximate Bayesian Computational Model for Estimating P2 |
---|---|
Description: | Tests the goodness of fit of a distribution of offspring to the Normal, Poisson, and Gamma distribution and estimates the proportional paternity of the second male (P2) based on the best fit distribution. |
Authors: | M. Catherine Duryea, Andrew D. Kern, Robert M. Cox, and Ryan Calsbeek |
Maintainer: | M. Catherine Duryea <[email protected]> |
License: | GPL-2 |
Version: | 1.2 |
Built: | 2025-01-26 17:17:01 UTC |
Source: | https://github.com/cranhaven/cranhaven.r-universe.dev |
This function fits offspring data to a special case of the gamma distribution, in which zero values of offspring are excluded and all values are rounded to a whole number, and estimates P2 based on that distribution and the specificed priors.
ABC_P2_gamma(n, ObsMean, S_Lo, S_Hi, R_Lo, R_Hi, delta, iter)
ABC_P2_gamma(n, ObsMean, S_Lo, S_Hi, R_Lo, R_Hi, delta, iter)
n |
number of observations. |
ObsMean |
the observed mean number of offspring sired by the second male. |
S_Lo |
minimum shape value for the distribution. |
S_Hi |
maximum shape value for the distribution. |
R_Lo |
minimum rate value for the distribution. |
R_Hi |
maximum rate value for the distribution. |
delta |
maximum allowed difference between the estimated mean and observed mean number of offspring produced by the second male. |
iter |
number of iterations used to build the posterior. |
posterior |
Posterior distribution of P2 values. |
Shape |
Vector of values for the shape parameter. |
Rate |
Vector of values for the rate parameter. |
M. Catherine Duryea, Andrew D. Kern, Robert M. Cox, and Ryan Calsbeek
#Fit the Shape and Rate hyperpriors to a distribution of offspring. data(fungus) fit_dist_gamma(fungus$Total_Offspring) #Use hyperiors and priors calculated from the data to estimate P2. #Plot the saved distributions for the Shape and Rate parameters. #Adjust, if necessary. fungus_P2<-ABC_P2_gamma(12, 9.9, 1.14, 2.52, 0.06, 0.18, 0.1, 100) hist(fungus_P2$posterior) hist(fungus_P2$Shape) hist(fungus_P2$Rate)
#Fit the Shape and Rate hyperpriors to a distribution of offspring. data(fungus) fit_dist_gamma(fungus$Total_Offspring) #Use hyperiors and priors calculated from the data to estimate P2. #Plot the saved distributions for the Shape and Rate parameters. #Adjust, if necessary. fungus_P2<-ABC_P2_gamma(12, 9.9, 1.14, 2.52, 0.06, 0.18, 0.1, 100) hist(fungus_P2$posterior) hist(fungus_P2$Shape) hist(fungus_P2$Rate)
This function fits offspring data to a special case of the normal distribution, in which zero and negative values of offspring are excluded, and estimates P2 based on that distribution and the specificed priors.
ABC_P2_norm(n, ObsMean, M_Lo, M_Hi, SD_Lo, SD_Hi, delta, iter)
ABC_P2_norm(n, ObsMean, M_Lo, M_Hi, SD_Lo, SD_Hi, delta, iter)
n |
number of observations. |
ObsMean |
the observed mean number of offspring sired by the second male. |
M_Lo |
minimum mean value for the distribution. |
M_Hi |
maximum mean value for the distribution. |
SD_Lo |
minimum standard deviation value for the distribution. |
SD_Hi |
maximum standard deviation value for the distribution. |
delta |
maximum allowed difference between the estimated mean and observed mean number of offspring produced by the second male. |
iter |
number of iterations used to build the posterior. |
posterior |
Posterior distribution of P2 values. |
Avg |
Vector of values for the mean parameter. |
Std |
Vector of values for the standard deviation parameter. |
M. Catherine Duryea, Andrew D. Kern, Robert M. Cox, and Ryan Calsbeek
#Fit the Mean and Standard Deviation hyperpriors to a distribution of offspring. data(fungus) fit_dist_norm(fungus$Total_Offspring) #Use hyperiors and priors calculated from the data to estimate P2. #Plot the saved distributions for the Mean and Standard Deviation parameters. #Adjust, if necessary. fungus_P2<-ABC_P2_norm(12, 9.9, 11.35, 17.31, 8.22, 12.44, 0.1, 100) hist(fungus_P2$posterior) hist(fungus_P2$Avg) hist(fungus_P2$Std)
#Fit the Mean and Standard Deviation hyperpriors to a distribution of offspring. data(fungus) fit_dist_norm(fungus$Total_Offspring) #Use hyperiors and priors calculated from the data to estimate P2. #Plot the saved distributions for the Mean and Standard Deviation parameters. #Adjust, if necessary. fungus_P2<-ABC_P2_norm(12, 9.9, 11.35, 17.31, 8.22, 12.44, 0.1, 100) hist(fungus_P2$posterior) hist(fungus_P2$Avg) hist(fungus_P2$Std)
This function fits offspring data to the Poisson distribution and estimates P2 based on that distribution and the specificed priors.
ABC_P2_pois(n, ObsMean, L_Lo, L_Hi, delta, iter)
ABC_P2_pois(n, ObsMean, L_Lo, L_Hi, delta, iter)
n |
the number of observations. |
ObsMean |
the observed mean number of offspring sired by the second male. |
L_Lo |
minimum lambda value for the distribution. |
L_Hi |
maximum lambda value for the distribution. |
delta |
maximum allowed difference between the estimated mean and observed mean number of offspring produced by the second male. |
iter |
number of iterations used to build the posterior. |
posterior |
Posterior distribution of P2 values. |
Lambda |
Vector of values for the lambda parameter. |
M. Catherine Duryea, Andrew D. Kern, Robert M. Cox, and Ryan Calsbeek
#Fit the Lambda hyperprior to a distribution of offspring. data(fungus) fit_dist_pois(fungus$Total_Offspring) #Use hyperiors and priors calculated from the data to estimate P2. #Plot the saved distributions for the Lambda parameter. #Adjust, if necessary. fungus_P2<-ABC_P2_pois(12, 9.9, 13.24, 15.42, 0.1, 100) hist(fungus_P2$posterior) hist(fungus_P2$Lambda)
#Fit the Lambda hyperprior to a distribution of offspring. data(fungus) fit_dist_pois(fungus$Total_Offspring) #Use hyperiors and priors calculated from the data to estimate P2. #Plot the saved distributions for the Lambda parameter. #Adjust, if necessary. fungus_P2<-ABC_P2_pois(12, 9.9, 13.24, 15.42, 0.1, 100) hist(fungus_P2$posterior) hist(fungus_P2$Lambda)
This function fits offspring data to a special case of the gamma distribution, in which zero values of offspring are excluded and all values are rounded to a whole number, and tests the goodness of fit using the chi-squared test.
fit_dist_gamma(dist)
fit_dist_gamma(dist)
dist |
a numeric vector of data values for number of offspring per dam. |
estimate |
Shape and rate parameters estimated from the supplied distribution. |
sd |
Standard deviation of the shape and rate estimates. |
vcov |
Variance/covariance matrix of the shape and rate estimates. |
loglik |
the log-likelihood of the shape and rate estimates. |
n |
The number of observations. |
statistic |
The chi-squared test statistic. |
parameter |
Degrees of freedom for the chi-squared test. |
p.value |
P-value for the chi-squared test. |
data_gamma |
Vector of values generated from a special case of the gamma distribution. |
M. Catherine Duryea, Andrew D. Kern, Robert M. Cox, and Ryan Calsbeek
#Fit the Shape and Rate parameters to a distribution of offspring. #Test the goodness of fit. data(fungus) fungus_fit<-fit_dist_gamma(fungus$Total_Offspring) fungus_fit$fit_gamma fungus_fit$chi_gamma hist(fungus_fit$data_gamma)
#Fit the Shape and Rate parameters to a distribution of offspring. #Test the goodness of fit. data(fungus) fungus_fit<-fit_dist_gamma(fungus$Total_Offspring) fungus_fit$fit_gamma fungus_fit$chi_gamma hist(fungus_fit$data_gamma)
This function fits offspring data to a special case of the normal distribution, in which zero and negative values of offspring are excluded, and tests the goodness of fit using the chi-squared test.
fit_dist_norm(dist)
fit_dist_norm(dist)
dist |
a numeric vector of data values for number of offspring per dam. |
estimate |
Mean and standard deviation parameters estimated from the supplied distribution. |
sd |
Standard deviation of the mean and standard deviation estimates. |
vcov |
Variance/covariance matrix of the mean and standard deviation estimates. |
loglik |
the log-likelihood of the mean and standard deviation estimates. |
n |
The number of observations. |
statistic |
The chi-squared test statistic. |
parameter |
Degrees of freedom for the chi-squared test. |
p.value |
P-value for the chi-squared test. |
data_norm |
Vector of values generated from a special case of the normal distribution. |
M. Catherine Duryea, Andrew D. Kern, Robert M. Cox, and Ryan Calsbeek
#Fit the Mean and Standard Deviation parameters to a distribution of offspring. #Test the goodness of fit. data(fungus) fungus_fit<-fit_dist_norm(fungus$Total_Offspring) fungus_fit$fit_norm fungus_fit$chi_norm fungus_fit$data_norm
#Fit the Mean and Standard Deviation parameters to a distribution of offspring. #Test the goodness of fit. data(fungus) fungus_fit<-fit_dist_norm(fungus$Total_Offspring) fungus_fit$fit_norm fungus_fit$chi_norm fungus_fit$data_norm
This function fits offspring data to the Poisson distribution, and tests the goodness of fit using the chi-squared test.
fit_dist_pois(dist)
fit_dist_pois(dist)
dist |
a numeric vector of data values for number of offspring per dam. |
estimate |
Lambda parameter estimated from the supplied distribution. |
sd |
Standard deviation of the lambda estimate. |
vcov |
Variance/covariance matrix of the lambda estimate. |
loglik |
the log-likelihood of the lambda estimate. |
n |
The number of observations. |
statistic |
The chi-squared test statistic. |
parameter |
Degrees of freedom for the chi-squared test. |
p.value |
P-value for the chi-squared test. |
data_pois |
Vector of values generated from the Poisson distribution. |
M. Catherine Duryea, Andrew D. Kern, Robert M. Cox, and Ryan Calsbeek
#Fit the Lambda parameter to a distribution of offspring. #Test the goodness of fit. data(fungus) fungus_fit<-fit_dist_pois(fungus$Total_Offspring) fungus_fit$fit_pois fungus_fit$chi_pois hist(fungus_fit$data_pois)
#Fit the Lambda parameter to a distribution of offspring. #Test the goodness of fit. data(fungus) fungus_fit<-fit_dist_pois(fungus$Total_Offspring) fungus_fit$fit_pois fungus_fit$chi_pois hist(fungus_fit$data_pois)
Offspring counts and proportional paternity by mating order for a breeding experiment of the fungus beetle conducted by JK Conner (1995).
data(fungus)
data(fungus)
A data frame with 12 observations on the following 4 variables.
Female
a numeric vector to identify females.
P2
proportional paternity of the second male.
Total_Offspring
total number of offspring for the female.
No_2nd_Male
number of offspring sired by the second male.
J. K. Conner (1995) Extreme variability in sperm precedence in the fungus beetle, Bolitotherus cornutus (Coleoptera Tenebrionidae), Ethology Ecology & Evolution 7, 277-280.
#Fit fungus beetle data to the normal distribution and test goodness of fit. data(fungus) fit_dist_norm(fungus$Total_Offspring)
#Fit fungus beetle data to the normal distribution and test goodness of fit. data(fungus) fit_dist_norm(fungus$Total_Offspring)
Offspring counts from two clutches and proportional paternity by mating order for a breeding experiment of the rough-skinned newt conducted by Jones et al., (2002)
data(newt)
data(newt)
A data frame with 10 observations on the following 10 variables.
Female
a numeric code to identify females.
No_1st_Clutch
total offspring in the first clutch.
P2_1
proportional paternity of the second male for the first clutch.
No_2nd_Male_1st_Clutch
total offspring sired by the second male from the first clutch.
No_2nd_Clutch
total offspring in the second clutch.
P2_2
proportional paternity of the second male for the second clutch.
No_2nd_Male_2nd_Clutch
total offspring sired by the second male from the second clutch.
Total_2nd_Male
total offspring sired by the second male from both clutches.
Total_Offspring
total offspring for both clutches.
Total_P2
total overall proportional paternity of the second male for both clutches.
A. G. Jones, E. M. Adams, and S. J. Arnold (2002) A mechanism of first-male precedence in a vertebrate. Proceedings of the National Academy of Sciences of the United States of America 99, 2078-2081.
#Fit newt data to the Poisson distribution and test goodness of fit. data(newt) fit_dist_pois(newt$Total_Offspring)
#Fit newt data to the Poisson distribution and test goodness of fit. data(newt) fit_dist_pois(newt$Total_Offspring)
Offspring counts and proportional paternity by mating order for a breeding experiment of the rove beetle conducted by T Benken et al., (1999).
data(rove)
data(rove)
A data frame with 17 observations on the following 4 variables.
Female
a numeric vector to identify females.
Total_Offspring
total number of offspring for the female.
P2
proportional paternity of the second male.
No_2nd_Male
number of offspring sired by the second male.
T. Benken, A. Knaak, C. Gack, M. Eberle, and K. Peschke (1999) Variation of sperm precedence in the rove beetle, Aleochara curtula (Coleoptera: Staphylinidae), Behaviour 136, 1065-1077.
#Fit rove beetle data to the normal distribution and test goodness of fit. data(rove) fit_dist_norm(rove$Total_Offspring)
#Fit rove beetle data to the normal distribution and test goodness of fit. data(rove) fit_dist_norm(rove$Total_Offspring)
Offspring counts and proportional paternity by mating order for a breeding experiment of the soapberry bug conducted by SP Carroll (1991).
data(soap)
data(soap)
A data frame with 18 observations on the following 4 variables.
Female
a numeric vector to identify females.
P2
proportional paternity of the second male.
Total_Offspring
total number of offspring for the female.
No_2nd_Male
number of offspring sired by the second male.
S. P. Carroll (1991) The adaptive significance of mate guarding in the soapberry bug, Jadera haematoloma (Hemiptera: Rhopalidae), Journal of Insect Behavior, 4, 509-530.
#Fit soapberry bug data to the normal distribution and test goodness of fit. data(soap) fit_dist_norm(soap$Total_Offspring)
#Fit soapberry bug data to the normal distribution and test goodness of fit. data(soap) fit_dist_norm(soap$Total_Offspring)