Title: | Companion Animal Population Management |
---|---|
Description: | Quantitative analysis to support companion animal population management. Some functions assist survey sampling tasks (calculate sample size for simple and complex designs, select sampling units and estimate population parameters) while others assist the modelling of population dynamics. For demographic characterizations and population management evaluations see: "Baquero, et al." (2018), <doi:10.1016/j.prevetmed.2018.07.006>. For modelling of population dynamics see: "Baquero et al." (2016), <doi:10.1016/j.prevetmed.2015.11.009>. For sampling methods see: "Levy PS & Lemeshow S" (2013), "ISBN-10: 0470040076"; "Lumley" (2010), "ISBN: 978-0-470-28430-8". |
Authors: | Oswaldo Santos Baquero [aut, cre], Marcos Amaku [ctb], Fernando Ferreira [ctb] |
Maintainer: | Oswaldo Santos Baquero <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.13.10 |
Built: | 2025-02-20 02:59:03 UTC |
Source: | https://github.com/oswaldosantos/capm |
Companion Animal Population Management. Provides functions for quantitative Companion Animal Population Management. Further information can be found in the URL given below.
Package: | capm |
Type: | Package |
Version: | 0.13.10 |
Date: | 2019-04-19 |
Depends: | R (>= 3.4) |
Imports: | deSolve, FME, survey, dplyr, tidyr, magrittr, ggplot2, grid, stats, utils, sf |
License: | GPL (>= 2) |
LazyLoad: | yes |
URL: | http://oswaldosantos.github.io/capm |
Author: | Oswaldo Santos Baquero [email protected] |
Maintainer: | Oswaldo Santos Baquero [email protected] |
Contributors: | Marcos Amaku [email protected], Fernando Ferreira [email protected] |
Calculates sample size and composition to estimate a total from a two-stage cluster sampling design. This function is deprecated, see details.
Calculate2StageSampleSize(psu.ssu = NULL, psu.x = NULL, conf.level = 0.95, error = 0.1, cost = 4, minimum.ssu = 15)
Calculate2StageSampleSize(psu.ssu = NULL, psu.x = NULL, conf.level = 0.95, error = 0.1, cost = 4, minimum.ssu = 15)
psu.ssu |
|
psu.x |
|
conf.level |
the confidence level required. It must be |
error |
the maximum relative difference between the estimate and the unknown population value. It must be |
cost |
the ratio of the cost of sampling a PSU to the cost of sampling a SSU. |
minimum.ssu |
integer to define the minimum number of SSU to be selected per PSU. If the calculated number of SSU to be selected is lesser than |
It is assumed that PSU from the pilot are selected with probability proportional to size (PPS) and with replacement. SSU are assumed to be selected via simple (systematic) random sampling.
PSU must have the same identifiers in psu.ssu
and in psu.x
.
This function is deprecated because a study (Baquero et. al, 2018a) showed that the calculated sample size are too large for practical purposes. The same study found predefined sample compositions that result in estimates with precision equivalent to that achieved with the algorithm implemented in this function.
The predefined sample compositions are (PSU * SSU): 65 \* 15, 50 \* 20, and 30 \* 30. If possible, take larger samples.
Matrix with the sample size and composition and with variability estimates.
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
Levy P and Lemeshow S (2008). Sampling of populations: methods and applications, Fourth edition. John Wiley and Sons, Inc.
http://oswaldosantos.github.io/capm
Wraper for sensRange
function, which calculates sensitivities of population sizes to parameters used in one of the following functions: SolveIASA
, SolveSI
or SolveTC
.
CalculateGlobalSens(model.out = NULL, ranges = NULL, sensv = NULL, all = FALSE)
CalculateGlobalSens(model.out = NULL, ranges = NULL, sensv = NULL, all = FALSE)
model.out |
output from one of the previous function or a |
ranges |
output from the |
sensv |
string with the name of the output variables for which the sensitivity are to be estimated. |
all |
logical. If |
When all
is equal to TRUE, dist
argument in sensRange
is defined as "latin" and when equal to FALSE
, as "grid". The num
argument in sensRange
is defined as 100.
A data.frame
(extended by summary.sensRange
when all == TRUE
) containing the parameter set and the corresponding values of the sensitivity output variables.
Soetaert K and Petzoldt T (2010). Inverse modelling, sensitivity and monte carlo analysis in R using package FME. Journal of Statistical Software, 33(3), pp. 1-28.
Reichert P and Kfinsch HR (2001). Practical identifiability analysis of large environmental simulation models. Water Resources Research, 37(4), pp.1015-1030.
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
http://oswaldosantos.github.io/capm
## IASA model ## Parameters and intial conditions. data(dogs) dogs_iasa <- GetDataIASA(dogs, destination.label = "Pinhais", total.estimate = 50444) # Solve for point estimates. solve_iasa_pt <- SolveIASA(pars = dogs_iasa$pars, init = dogs_iasa$init, time = 0:15, alpha.owned = TRUE, method = 'rk4') ## Set ranges 10 % greater and lesser than the ## point estimates. rg_solve_iasa <- SetRanges(pars = dogs_iasa$pars) ## Calculate golobal sensitivity of combined parameters. ## To calculate global sensitivity to each parameter, set ## all as FALSE. glob_all_solve_iasa <- CalculateGlobalSens( model.out = solve_iasa_pt, ranges = rg_solve_iasa, sensv = "n2", all = TRUE)
## IASA model ## Parameters and intial conditions. data(dogs) dogs_iasa <- GetDataIASA(dogs, destination.label = "Pinhais", total.estimate = 50444) # Solve for point estimates. solve_iasa_pt <- SolveIASA(pars = dogs_iasa$pars, init = dogs_iasa$init, time = 0:15, alpha.owned = TRUE, method = 'rk4') ## Set ranges 10 % greater and lesser than the ## point estimates. rg_solve_iasa <- SetRanges(pars = dogs_iasa$pars) ## Calculate golobal sensitivity of combined parameters. ## To calculate global sensitivity to each parameter, set ## all as FALSE. glob_all_solve_iasa <- CalculateGlobalSens( model.out = solve_iasa_pt, ranges = rg_solve_iasa, sensv = "n2", all = TRUE)
Wraper for sensFun
function, which estimates local effect of all model parameters on population size, applying the so-called sensitivity functions. The set of parameters used in any of the following functions can be assessed: SolveIASA
, SolveSI
or SolveTC
.
CalculateLocalSens(model.out = NULL, sensv = "n")
CalculateLocalSens(model.out = NULL, sensv = "n")
model.out |
output from one of the previous functions or a |
sensv |
string with the name of the output variables for which sensitivity are to be estimated. |
For further arguments of sensFun
, defaults are used. See the help page of this function for details. Methods for class "sensFun" can be used.
a data.frame
of class sensFun
containing the sensitivity functions. There is one row for each sensitivity variable at each independent time. The first column x
, contains the time value; the second column var
, the name of the observed variable; and remaining columns have the sensitivity parameters.
Soetaert K and Petzoldt T (2010). Inverse modelling, sensitivity and monte carlo analysis in R using package FME. Journal of Statistical Software, 33(3), pp. 1-28.
Reichert P and Kfinsch HR (2001). Practical identifiability analysis of large environmental simulation models. Water Resources Research, 37(4), pp.1015-1030.
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
http://oswaldosantos.github.io/capm
## IASA model ## Parameters and intial conditions. data(dogs) dogs_iasa <- GetDataIASA(dogs, destination.label = "Pinhais", total.estimate = 50444) # Solve for point estimates. solve_iasa_pt <- SolveIASA(pars = dogs_iasa$pars, init = dogs_iasa$init, time = 0:15, alpha.owned = TRUE, method = 'rk4') ## Calculate local sensitivities to all parameters. local_solve_iasa2 <- CalculateLocalSens( model.out = solve_iasa_pt, sensv = "n2") local_solve_iasa1 <- CalculateLocalSens( model.out = solve_iasa_pt, sensv = "n1")
## IASA model ## Parameters and intial conditions. data(dogs) dogs_iasa <- GetDataIASA(dogs, destination.label = "Pinhais", total.estimate = 50444) # Solve for point estimates. solve_iasa_pt <- SolveIASA(pars = dogs_iasa$pars, init = dogs_iasa$init, time = 0:15, alpha.owned = TRUE, method = 'rk4') ## Calculate local sensitivities to all parameters. local_solve_iasa2 <- CalculateLocalSens( model.out = solve_iasa_pt, sensv = "n2") local_solve_iasa1 <- CalculateLocalSens( model.out = solve_iasa_pt, sensv = "n1")
Calculate the change in population size between two times. When only one time is specified, the population size at that time is returned.
CalculatePopChange(model.out = NULL, variable = NULL, t1 = NULL, t2 = NULL, ratio = TRUE)
CalculatePopChange(model.out = NULL, variable = NULL, t1 = NULL, t2 = NULL, ratio = TRUE)
model.out |
output from one of the following functions or a |
variable |
string with the name of the the output variable for which the change are to be calculated (see the variable argument for |
t1 |
value specifying the first time. |
t2 |
value specifying the second time. |
ratio |
logical. When |
Value representing the ratio (if ratio
is TRUE
) or the difference (if ratio
is FALSE
) between population size at time t2 and t1. If only one time is specified, the value is the population size at that time.
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
http://oswaldosantos.github.io/capm
## IASA model ## Parameters and intial conditions. data(dogs) dogs_iasa <- GetDataIASA(dogs, destination.label = "Pinhais", total.estimate = 50444) # Solve for point estimates. solve_iasa_pt <- SolveIASA(pars = dogs_iasa$pars, init = dogs_iasa$init, time = 0:15, alpha.owned = TRUE, method = 'rk4') # Calculate the population change (ratio) between times 0 and 15. CalculatePopChange(solve_iasa_pt, variable = 'N1', t2 = 15, t1 = 0) # Calculate the population change (difference) between times 0 and 15. CalculatePopChange(solve_iasa_pt, variable = 'N1', t2 = 15, t1 = 0, ratio = FALSE) # Calculate the population zises at time 15. CalculatePopChange(solve_iasa_pt, variable = 'N1', t2 = 15)
## IASA model ## Parameters and intial conditions. data(dogs) dogs_iasa <- GetDataIASA(dogs, destination.label = "Pinhais", total.estimate = 50444) # Solve for point estimates. solve_iasa_pt <- SolveIASA(pars = dogs_iasa$pars, init = dogs_iasa$init, time = 0:15, alpha.owned = TRUE, method = 'rk4') # Calculate the population change (ratio) between times 0 and 15. CalculatePopChange(solve_iasa_pt, variable = 'N1', t2 = 15, t1 = 0) # Calculate the population change (difference) between times 0 and 15. CalculatePopChange(solve_iasa_pt, variable = 'N1', t2 = 15, t1 = 0, ratio = FALSE) # Calculate the population zises at time 15. CalculatePopChange(solve_iasa_pt, variable = 'N1', t2 = 15)
Calculates sample size to estimate a total from a simple sampling design.
CalculateSimpleSampleSize(x = NULL, N = NULL, conf.level = 0.95, error = 0.1)
CalculateSimpleSampleSize(x = NULL, N = NULL, conf.level = 0.95, error = 0.1)
x |
|
N |
|
conf.level |
the confidence level required. It must be |
error |
the maximum relative difference between the estimate and the unknown population value. It must be |
numeric sample size rounded up to nearest integer.
Levy P and Lemeshow S (2008). Sampling of populations: methods and applications, Fourth edition. John Wiley and Sons, Inc.
http://oswaldosantos.github.io/capm
# Using a pilot sample from a population with 10000 sampling units. pilot <- rpois(50, 0.8) CalculateSimpleSampleSize(x = pilot, N = 10000, conf.level = 0.95, error = 0.1) # Using expected mean and standard deviation for a population # with 10000 sampling units. mean_x <- mean(pilot) sd_x <- sd(pilot) N <- 10000 V <- ((N - 1) / N * sd_x^2) / mean_x^2 CalculateSimpleSampleSize(x = V, N = 10000, conf.level = 0.95, error = 0.1)
# Using a pilot sample from a population with 10000 sampling units. pilot <- rpois(50, 0.8) CalculateSimpleSampleSize(x = pilot, N = 10000, conf.level = 0.95, error = 0.1) # Using expected mean and standard deviation for a population # with 10000 sampling units. mean_x <- mean(pilot) sd_x <- sd(pilot) N <- 10000 V <- ((N - 1) / N * sd_x^2) / mean_x^2 CalculateSimpleSampleSize(x = V, N = 10000, conf.level = 0.95, error = 0.1)
Calculates sample size to estimate a total from a stratified random sampling design.
CalculateStratifiedSampleSize(strata = NULL, x = NULL, conf.level = 0.95, error = 0.1)
CalculateStratifiedSampleSize(strata = NULL, x = NULL, conf.level = 0.95, error = 0.1)
strata |
|
x |
|
conf.level |
the confidence level required. It must be |
error |
the maximum relative difference between the estimate and the unknown population value. It must be |
numeric sample size rounded up to nearest integer.
Levy P and Lemeshow S (2008). Sampling of populations: methods and applications, Fourth edition. John Wiley and Sons, Inc.
http://oswaldosantos.github.io/capm
# Using a pilot sample from a population with 10000 sampling units. strata <- rep(c("rural", "urban"), c(100, 9900)) pilot <- data.frame(c(rpois(5, 1.3), rpois(45, 0.8)), rep(c("rural", "urban"), c(5, 45))) CalculateStratifiedSampleSize(strata, pilot) # Using expected mean and variance for a population with # 10000 sampling units. str_n <- c(rural = 100, urban = 9900) str_mean <- c(rural = 1.4, urban = 0.98) str_var <- c(rural = 1.48, urban = 1.02) CalculateStratifiedSampleSize(cbind(str_n, str_mean, str_var))
# Using a pilot sample from a population with 10000 sampling units. strata <- rep(c("rural", "urban"), c(100, 9900)) pilot <- data.frame(c(rpois(5, 1.3), rpois(45, 0.8)), rep(c("rural", "urban"), c(5, 45))) CalculateStratifiedSampleSize(strata, pilot) # Using expected mean and variance for a population with # 10000 sampling units. str_n <- c(rural = 100, urban = 9900) str_mean <- c(rural = 1.4, urban = 0.98) str_var <- c(rural = 1.48, urban = 1.02) CalculateStratifiedSampleSize(cbind(str_n, str_mean, str_var))
Data described and analyzed by Baquero et al., 2018.
cats
cats
Data frame with 195 observations (cats) and 22 variables:
Interview's ID.
Census tract's ID.
Cat's name.
Animal's species
Cat's sex.
Cat's age. An age equal to 0 means that the cat had less than 1 year.
Cat's reproductive status.
For sterilized cats, indicates if the cat was sterilized during the last year.
Indicates if the cat had access to the street without supervision (free-roaming).
Acquisition type.
Indicates if the cat was acquired during the last year.
Indicates if the cat was sterilized when acquired.
City of acquisition.
State of acquisition.
Indicates if the cat was acquired during the year following the lost of another car
Litter size if the bitch had the litter during the last year.
Dog's name (cats not present anymore in the household).
Animal's species (animals not present anymore in the household).
Dog's sex (cats not present anymore in the household).
Dog's age (cats not present anymore in the household). An age equal to 0 means that the dog had less than 1 year.
Dog's reproductive status (cats not present anymore in the household).
Dog's fate.
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
Data described and analyzed by Baquero et al., 2018.
cluster_sample
cluster_sample
Data frame with 1230 observations (households) and 14 variables:
Interview's ID.
Census tract's ID.
Interviewer's name.
Interview's date.
Household's address.
Interview status.
Interviewee's name.
Number of dogs.
Number of cats.
Number of persons.
Interviewee's cell phone.
Interviewee's e-mail.
Interviewee's reported reason for not sterilizing her/his animal.
Other reasons for not sterilizing her/his animal.
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
A wraper for svydesign
function from the survey package, to define one of the following survey designs: two-stage cluster, simple (systematic) or stratified. In the first case, weights are calculated considering a sample with probability proportional to size and with replacement for the first stage and a simple random sampling for the second stage. Finite population correction is specified as the population size for each level of sampling.
DesignSurvey(sample = NULL, psu.ssu = NULL, psu.col = NULL, ssu.col = NULL, cal.col = NULL, N = NULL, strata = NULL, cal.N = NULL, ...)
DesignSurvey(sample = NULL, psu.ssu = NULL, psu.col = NULL, ssu.col = NULL, cal.col = NULL, N = NULL, strata = NULL, cal.N = NULL, ...)
sample |
|
psu.ssu |
|
psu.col |
the column of |
ssu.col |
the column of |
cal.col |
the column of |
N |
for simple designs, a |
strata |
for stratified designs, a column of |
cal.N |
population total for the variable to calibrate the estimates. It must be used togheter with |
... |
further arguments passed to |
For two-stage cluster designs, a PSU appearing in both psu.ssu
and in sample
must have the same identifier. SSU identifiers must be unique but can appear more than once if there is more than one observation per SSU. sample
argument must have just the varibles to be estimated plus the variables required to define the design (two-stage cluster or stratified). cal.col
and cal.N
are needed only if estimates will be calibrated. The calibration is based on a population total.
An object of class survey.design.
Lumley, T. (2011). Complex surveys: A guide to analysis using R (Vol. 565). Wiley.
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
http://oswaldosantos.github.io/capm
data("cluster_sample") data("psu_ssu") ## Calibrated two-stage cluster design design <- DesignSurvey(na.omit(cluster_sample), psu.ssu = psu_ssu, psu.col = "census_tract_id", ssu.col = "interview_id", cal.col = "number_of_persons", cal.N = 129445) ## Simple design # If data in cluster_sample were from a simple design: design <- DesignSurvey(na.omit(cluster_sample), N = sum(psu_ssu$hh), cal.N = 129445) ## Stratified design # Simulate strata and assume that the data in cluster_design came # from a stratified design cluster_sample$strat <- sample(c("urban", "rural"), nrow(cluster_sample), prob = c(.95, .05), replace = TRUE) cluster_sample$strat_size <- round(sum(psu_ssu$hh) * .95) cluster_sample$strat_size[cluster_sample$strat == "rural"] <- round(sum(psu_ssu$hh) * .05) design <- DesignSurvey(cluster_sample, N = "strat_size", strata = "strat", cal.N = 129445)
data("cluster_sample") data("psu_ssu") ## Calibrated two-stage cluster design design <- DesignSurvey(na.omit(cluster_sample), psu.ssu = psu_ssu, psu.col = "census_tract_id", ssu.col = "interview_id", cal.col = "number_of_persons", cal.N = 129445) ## Simple design # If data in cluster_sample were from a simple design: design <- DesignSurvey(na.omit(cluster_sample), N = sum(psu_ssu$hh), cal.N = 129445) ## Stratified design # Simulate strata and assume that the data in cluster_design came # from a stratified design cluster_sample$strat <- sample(c("urban", "rural"), nrow(cluster_sample), prob = c(.95, .05), replace = TRUE) cluster_sample$strat_size <- round(sum(psu_ssu$hh) * .95) cluster_sample$strat_size[cluster_sample$strat == "rural"] <- round(sum(psu_ssu$hh) * .05) design <- DesignSurvey(cluster_sample, N = "strat_size", strata = "strat", cal.N = 129445)
Data described and analyzed by Baquero et al., 2018.
dogs
dogs
Data frame with 1252 observations (dogs) and 22 variables:
Interview's ID.
Census tract's ID.
Dog's name.
Animal's species
Dog's sex.
Dog's age. An age equal to 0 means that the dog had less than 1 year.
Dog's reproductive status.
For sterilized dogs, indicates if the dog was sterilized during the last year.
Indicates if the dog had access to the street without supervision (free-roaming).
Acquisition type.
Indicates if the dog was acquired during the last year.
Indicates if the dog was sterilized when acquired.
City of acquisition.
State of acquisition.
Indicates if the dog was acquired during the year following the lost of another dog
Litter size if the bitch had the litter during the last year.
Dog's name (dogs not present anymore in the household).
Animal's species (animals not present anymore in the household).
Dog's sex (dogs not present anymore in the household).
Dog's age (dogs not present anymore in the household). An age equal to 0 means that the dog had less than 1 year.
Dog's reproductive status (dogs not present anymore in the household).
Dog's fate.
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
Calculates and sort the count and relative frequency of categories.
FreqTab(data = NULL, variables = NULL, rnd = 3, decreasing = TRUE, use.na = FALSE)
FreqTab(data = NULL, variables = NULL, rnd = 3, decreasing = TRUE, use.na = FALSE)
data |
|
variables |
name or position of categorical variables. If more than one variable is provided, contingency frequencies are calculated. |
rnd |
the number of decimal places (round) or significant digits (signif) to be used. |
decreasing |
|
use.na |
|
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine. http://oswaldosantos.github.io/capm
data(cluster_sample) FreqTab(cluster_sample$number_of_dogs) data(dogs) FreqTab(dogs, c("species", "sex"))
data(cluster_sample) FreqTab(cluster_sample$number_of_dogs) data(dogs) FreqTab(dogs, c("species", "sex"))
Calculates initial values and paramters for the IASA model, from survey data collectected with the questionnaire described by Bquero at al., 2018.
GetDataIASA(data = NULL, sex.col = "sex", female.label = "female", male.label = "male", sterilized.col = "sterilized", sterilized.label = "yes", sterilized.ly.col = "sterilized_ly", sterilized.ly.label = "yes", births.ly.col = "births_ly", species3.col = "species3", species.label = "dog", sex3.col = "sex2", fate.col = "fate", died.label = "died", lost.label = "lost", acquisition.col = "acquisition", acquired.ly.col = "acquired_ly", acquired.ly.label = "yes", adopted.label = "adopted", bought.label = "bought", acquisition.source.col = "acquisition_city", acquired.sterilized.col = "acquired_sterilized", destination.label = NULL, total.estimate = NULL, k1.scale = 5, h1 = 1, N2.scale = 0.05, f2.scale = 0.9, fs2.scale = 0.1, m2.scale = 0.95, ms2.scale = 0.05, b2.scale = 1.5, df2.scale = 1.2, dm2.scale = 1.2, sf2.scale = 0.3, sm2.scale = 0.3, k2.scale = 2, h2 = 0.5)
GetDataIASA(data = NULL, sex.col = "sex", female.label = "female", male.label = "male", sterilized.col = "sterilized", sterilized.label = "yes", sterilized.ly.col = "sterilized_ly", sterilized.ly.label = "yes", births.ly.col = "births_ly", species3.col = "species3", species.label = "dog", sex3.col = "sex2", fate.col = "fate", died.label = "died", lost.label = "lost", acquisition.col = "acquisition", acquired.ly.col = "acquired_ly", acquired.ly.label = "yes", adopted.label = "adopted", bought.label = "bought", acquisition.source.col = "acquisition_city", acquired.sterilized.col = "acquired_sterilized", destination.label = NULL, total.estimate = NULL, k1.scale = 5, h1 = 1, N2.scale = 0.05, f2.scale = 0.9, fs2.scale = 0.1, m2.scale = 0.95, ms2.scale = 0.05, b2.scale = 1.5, df2.scale = 1.2, dm2.scale = 1.2, sf2.scale = 0.3, sm2.scale = 0.3, k2.scale = 2, h2 = 0.5)
data |
|
sex.col |
name or index of the column with the *sex* variable. |
female.label |
string with the *female* category in |
male.label |
string with the *male* category in |
sterilized.col |
name or index of the column with the *sterilized* variable. |
sterilized.label |
string with the *sterilized* category (ex. yes) in |
sterilized.ly.col |
name or index of the column with *sterilized last year* variable. |
sterilized.ly.label |
string with the *sterilized during the last year* category (ex. yes) in |
births.ly.col |
name or index of the column with the *births during the last year* variable. |
species3.col |
name or index of the column with the *species* variable form the third questionnaire's section (animals that left the household). |
species.label |
string with the *species* category of interest (ex. dog) in |
sex3.col |
name or index of the column with the *sex* variable form the third questionnaire's section (animals that left the household). |
fate.col |
name or index of the column with the *fate* variable. |
died.label |
string with the *died* category in |
lost.label |
string with the *lost* category in |
acquisition.col |
name or index of the column with the *acquisition* variable. |
acquired.ly.col |
name or index of the column with the *acquisition during the last year* variable. |
acquired.ly.label |
string with the *acquisition during the last year* category (ex. yes) in |
adopted.label |
string with the *adopted* category in |
bought.label |
string with the *bought* category in |
acquisition.source.col |
name or index of the column with the *source* variable (ex. city). |
acquired.sterilized.col |
name or index of the column with the *sterilized when acquired* variable. |
destination.label |
string with the *destination* category (ex. city) in |
total.estimate |
number representing the estimated total population size. |
k1.scale |
scale to define the carrying capacity of the owned population as k1 = k.scale * total.estimate. |
h1 |
number representing the mean harem size in the owned population. |
N2.scale |
scale to define the unowned population size as N2 = N2.sclae * total.estimate. |
f2.scale |
scale to define the female unowned population size as f2 = f2.scale * f1. |
fs2.scale |
scale to define the sterilized female unowned population size as fs2 = fs2.scale * fs1. |
m2.scale |
scale to define the sterimlized male unowned population as m2 = m2.scale * m1. |
ms2.scale |
scale to define the sterilized male unowned population size as ms2 = ms2.scale * ms1. |
b2.scale |
scale to define the birth function of the unowned population as b2 = f2 \* b1 / f1 \* b2.scale. |
df2.scale |
scale to define the death rate of the female unowned population as df2 = df2.scale * df1. |
dm2.scale |
scale to define the death rate of the male unowned population as dm2 = dm2.scale * dm1. |
sf2.scale |
scale to define the sterilized female unowned population size as sf2 = sf2 = sf2.scale * sf1. |
sm2.scale |
scale to define the sterilized male unowned population size as sm2 = sm2.scale * sm1. |
k2.scale |
scale to define the carrying capacity of the unowned population as k2 = k2.scale * N2. |
h2 |
number representing the mean harem size in the unowned population. |
If column and category names in data
match arguments' defaults, the function call is simplified as in the example below.
list
with two vectors: init
(initial values) and pars
(parameters).
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
http://oswaldosantos.github.io/capm
data(dogs) GetDataIASA(dogs, destination.label = "Pinhais", total.estimate = 50444)
data(dogs) GetDataIASA(dogs, destination.label = "Pinhais", total.estimate = 50444)
Subset the polygons specified in psu
and creates *.kml files of theses polygons.
MapkmlPSU(shape = NULL, psu = NULL, id = NULL, path = "./psu_maps/")
MapkmlPSU(shape = NULL, psu = NULL, id = NULL, path = "./psu_maps/")
shape |
string with the path of a polygon shapefile or an object of |
psu |
polygons to subset. |
id |
column of the *.dbf file with the values to be matched against. |
path |
|
If there are *.kml files in the working directory, the new created files will overwrite it in case of name matching.
shape
must receive a shapefile with appropriate coordinate reference system, otherwise, MapkmlPSU
report an error.
*.kml files of the subsetted polygons.
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
http://oswaldosantos.github.io/capm
data("psu_ssu") # Take a sample of 5 PSU. (selected_psu <- SamplePPS(psu.ssu = psu_ssu, psu = 5)) ## Define shape from shapefile. shp_path <- system.file("extdata/35SEE250GC_SIR.shp", package="capm") # The code above used a shapefile avaliable in the # capm package. # You might want to write a code like: # shp.path <- 'path_to_the_folder_with_the_shapefile' # Create *kml files of 10 polygons. ## Not run: MapkmlPSU(shape = shp_path, psu = selected_psu[, "selected_psu"], id = "CD_GEOCODI") ## Define the shape argument as an object x of class sf. x <- read_sf(shp_path) MapkmlPSU(shape = x, psu = selected_psu[, "selected_psu"], id = "CD_GEOCODI") ## End(Not run)
data("psu_ssu") # Take a sample of 5 PSU. (selected_psu <- SamplePPS(psu.ssu = psu_ssu, psu = 5)) ## Define shape from shapefile. shp_path <- system.file("extdata/35SEE250GC_SIR.shp", package="capm") # The code above used a shapefile avaliable in the # capm package. # You might want to write a code like: # shp.path <- 'path_to_the_folder_with_the_shapefile' # Create *kml files of 10 polygons. ## Not run: MapkmlPSU(shape = shp_path, psu = selected_psu[, "selected_psu"], id = "CD_GEOCODI") ## Define the shape argument as an object x of class sf. x <- read_sf(shp_path) MapkmlPSU(shape = x, psu = selected_psu[, "selected_psu"], id = "CD_GEOCODI") ## End(Not run)
Plot results of of CalculateGlobalSens
function.
PlotGlobalSens(global.out = NULL, x.label = "Time", y.label = "Population", legend.label = "Sensitivity range", qt.label = "Qt 0.05 - 0.95", sd.label = "mean +- sd ", inner.color = "DarkRed", outer.color = "LightBlue")
PlotGlobalSens(global.out = NULL, x.label = "Time", y.label = "Population", legend.label = "Sensitivity range", qt.label = "Qt 0.05 - 0.95", sd.label = "mean +- sd ", inner.color = "DarkRed", outer.color = "LightBlue")
global.out |
output from |
x.label |
string with the name for the x axis. |
y.label |
string with the name for the y axis. |
legend.label |
string with the name for the legend. |
qt.label |
string with the name for the envelope calculated using the quantiles 0.05 and 0.95. |
sd.label |
string with the name for the envelope calculated using the mean +- standard deviation ranges. |
inner.color |
any valid specification of a color for the inner envelope. |
outer.color |
any valid specification of a color for the outer envelope. |
Font size of saved plots is usually different to the font size seen in graphic browsers. Before changing font sizes, see the final result in saved (or preview) plots.
Other details of the plot can be modifyed using appropriate functions from ggplot2
package.
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
http://oswaldosantos.github.io/capm
## IASA model ## Parameters and intial conditions. data(dogs) dogs_iasa <- GetDataIASA(dogs, destination.label = "Pinhais", total.estimate = 50444) # Solve for point estimates. solve_iasa_pt <- SolveIASA(pars = dogs_iasa$pars, init = dogs_iasa$init, time = 0:15, alpha.owned = TRUE, method = 'rk4') ## Set ranges 10 % greater and lesser than the ## point estimates. rg_solve_iasa <- SetRanges(pars = dogs_iasa$pars) ## Calculate golobal sensitivity of combined parameters. ## To calculate global sensitivity to each parameter, set ## all as FALSE. glob_all_solve_iasa <- CalculateGlobalSens( model.out = solve_iasa_pt, ranges = rg_solve_iasa, sensv = "n2", all = TRUE) PlotGlobalSens(glob_all_solve_iasa)
## IASA model ## Parameters and intial conditions. data(dogs) dogs_iasa <- GetDataIASA(dogs, destination.label = "Pinhais", total.estimate = 50444) # Solve for point estimates. solve_iasa_pt <- SolveIASA(pars = dogs_iasa$pars, init = dogs_iasa$init, time = 0:15, alpha.owned = TRUE, method = 'rk4') ## Set ranges 10 % greater and lesser than the ## point estimates. rg_solve_iasa <- SetRanges(pars = dogs_iasa$pars) ## Calculate golobal sensitivity of combined parameters. ## To calculate global sensitivity to each parameter, set ## all as FALSE. glob_all_solve_iasa <- CalculateGlobalSens( model.out = solve_iasa_pt, ranges = rg_solve_iasa, sensv = "n2", all = TRUE) PlotGlobalSens(glob_all_solve_iasa)
Dodged bar plot of the distribution of households according to the number of inhabitants of one or more species.
PlotHHxSpecies(dat = NULL, species = NULL, proportion = TRUE, x.label = "Individuals per household", y.label = "Proportion of households", legend = TRUE)
PlotHHxSpecies(dat = NULL, species = NULL, proportion = TRUE, x.label = "Individuals per household", y.label = "Proportion of households", legend = TRUE)
dat |
|
species |
names or positions of columns with species data. |
proportion |
|
x.label |
title for x axis. |
y.label |
title for y axis. |
legend |
|
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
data(cluster_sample) PlotHHxSpecies(cluster_sample, c("number_of_persons", "number_of_dogs", "number_of_cats"))
data(cluster_sample) PlotHHxSpecies(cluster_sample, c("number_of_persons", "number_of_dogs", "number_of_cats"))
Plot rimmigration flows from many sources to one destination.
PlotImmigrationFlow(data = NULL, source = NULL, destination = NULL, n.sources = 5, agg.sources.prefix = "Other ", agg.sources.suffix = " sources", cls = NULL, start.degree = 0, sources.label.dist = 0.15, sources.label.size = 0.75, ticks.label.size = 0.7)
PlotImmigrationFlow(data = NULL, source = NULL, destination = NULL, n.sources = 5, agg.sources.prefix = "Other ", agg.sources.suffix = " sources", cls = NULL, start.degree = 0, sources.label.dist = 0.15, sources.label.size = 0.75, ticks.label.size = 0.7)
data |
|
source |
|
destination |
destination's name. |
n.sources |
number of sources to plot. If smaller than the total number of sources |
agg.sources.prefix |
string. If n.sources is smaller than the total number of sources, |
agg.sources.suffix |
|
cls |
|
start.degree |
The starting degree from which the circle begins to draw. It is passed to the |
sources.label.dist |
Data point on y-axis to separate the sources' labels from the circle. It is passed to the |
sources.label.size |
Font size for sources' labels. It is passed to the |
ticks.label.size |
Font size for sources' labels. It is passed to the |
The numbers arround the circle indicate the number of animals.
Gu, Z. (2014) circlize implements and enhances circular visualization in R. Bioinformatics. DOI: 10.1093/bioinformatics/btu393
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
http://oswaldosantos.github.io/capm
data(dogs) cls <- c("blue3", "orange", "skyblue", "darkgreen", "yellow3", "black") PlotImmigrationFlow(dogs, "acquisition_city", "Pinhais", cls = cls, agg.sources.suffix = " cities")
data(dogs) cls <- c("blue3", "orange", "skyblue", "darkgreen", "yellow3", "black") PlotImmigrationFlow(dogs, "acquisition_city", "Pinhais", cls = cls, agg.sources.suffix = " cities")
Plot results of the CalculateLocalSens
function.
PlotLocalSens(local.out = NULL, x.sens = "Time", y.sens = "Sensitivity", y.ind = c("L1", "L2", "Mean", "Min", "Max"), bar.colors = "DarkRed", label.size = 10, x.axis.angle = 90, type = 1)
PlotLocalSens(local.out = NULL, x.sens = "Time", y.sens = "Sensitivity", y.ind = c("L1", "L2", "Mean", "Min", "Max"), bar.colors = "DarkRed", label.size = 10, x.axis.angle = 90, type = 1)
local.out |
output from |
x.sens |
string with the name for the x axis. |
y.sens |
string with the name for the y axis of the sensitivity functions (when |
y.ind |
string with the name for the y axis of the parameter importance indices. |
bar.colors |
any valid specification of a color. |
label.size |
a number to specify the size of axes labels and text. |
x.axis.angle |
a number with angle of rotation for x axis text. Passed to |
type |
a number to define the type of graphical output. |
Font size of saved plots is usually different to the font size seen in graphic browsers. Before changing font sizes, see the final result in saved (or preview) plots.
Chang W (2012). R Graphics Cookbook. O'Reilly Media, Inc.
Soetaert K, Cash J and Mazzia F (2012). Solving differential equations in R. Springer.
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
http://oswaldosantos.github.io/capm
## IASA model#' ## Parameters and intial conditions. data(dogs) dogs_iasa <- GetDataIASA(dogs, destination.label = "Pinhais", total.estimate = 50444) # Solve for point estimates. solve_iasa_pt <- SolveIASA(pars = dogs_iasa$pars, init = dogs_iasa$init, time = 0:15, alpha.owned = TRUE, method = 'rk4') ## Calculate local sensitivities to all parameters. local_solve_iasa2 <- CalculateLocalSens( model.out = solve_iasa_pt, sensv = "n2") ## Plot local sensitivities PlotLocalSens(local_solve_iasa2)
## IASA model#' ## Parameters and intial conditions. data(dogs) dogs_iasa <- GetDataIASA(dogs, destination.label = "Pinhais", total.estimate = 50444) # Solve for point estimates. solve_iasa_pt <- SolveIASA(pars = dogs_iasa$pars, init = dogs_iasa$init, time = 0:15, alpha.owned = TRUE, method = 'rk4') ## Calculate local sensitivities to all parameters. local_solve_iasa2 <- CalculateLocalSens( model.out = solve_iasa_pt, sensv = "n2") ## Plot local sensitivities PlotLocalSens(local_solve_iasa2)
Plot results of one of the following functions: SolveIASA
, SolveSI
or SolveTC
.
PlotModels(model.out = NULL, variable = NULL, col = "red", col1 = c("cadetblue1", "yellow", "red"), col2 = c("blue", "darkgreen", "darkred"), x.label = "Years", y.label = NULL, legend.label = NULL, pop = NULL)
PlotModels(model.out = NULL, variable = NULL, col = "red", col1 = c("cadetblue1", "yellow", "red"), col2 = c("blue", "darkgreen", "darkred"), x.label = "Years", y.label = NULL, legend.label = NULL, pop = NULL)
model.out |
output of one of the function previously mentioned. |
variable |
string to specify the variable to be ploted. For "n" (population size). "q" (proportion of sterilized animals). For "f1" (owned intact females). "fs1" (owned sterilized females). "m1" (owned intact males). "ms1" (owned sterilized males). "f2" (unowned intact females). "fs2" (unowned sterilized females). "m2" (unowned intact males). "ms2" (unowned sterilized males). "n1" (owned intact animals). "ns1" (owned sterilized animals). "n2" (unowned intact animals). "ns2" (unowned sterilized animals). "N1" (owned animals). "N2" (unowned animals). "N" (total population). For "f" (intact females). "fs" (sterilized females). "m" (intact males). "ms" (sterilized males). "n" (intact animals). "ns" (sterilized animals). "N" (Total population stratified by reproductive status). For "n" (fertile animals). "g" (sterilized animals). "u" (cumulative of sterilized animals) |
col |
string indicating the color of ploted line, when |
col1 |
|
col2 |
|
x.label |
string with the name for x axis. |
y.label |
string with the name for y axis. |
legend.label |
string with the name of the legend, for plots of |
pop |
value indicating the output of |
Font size of saved plots is usually different to the font size seen in graphic browsers. Before changing font sizes, see the final result in saved (or preview) plots.
Other details of the plot can be modifyed using appropriate functions from ggplot2
package.
Chang W (2012). R Graphics Cookbook. O'Reilly Media, Inc.
http://oswaldosantos.github.io/capm
## IASA model ## Parameters and intial conditions. data(dogs) dogs_iasa <- GetDataIASA(dogs, destination.label = "Pinhais", total.estimate = 50444) # Solve for point estimates. solve_iasa_pt <- SolveIASA(pars = dogs_iasa$pars, init = dogs_iasa$init, time = 0:15, alpha.owned = TRUE, method = 'rk4') solve_iasa_rg <- SolveIASA(pars = dogs_iasa$pars, init = dogs_iasa$init, time = 0:10, alpha.owned = TRUE, s.range = seq(0, .4, l = 15), a.range = c(0, .2), alpha.range = c(0, .05), v.range = c(0, .1), method = 'rk4') ## Plot unowned population sizes using point estimates ## Not run: PlotModels(solve_iasa_pt, variable = "ns2") ## Plot all scenarios and change the label for the scenarios. ## Not run PlotModels(solve_iasa_rg, variable = "ns") ## End(Not run)
## IASA model ## Parameters and intial conditions. data(dogs) dogs_iasa <- GetDataIASA(dogs, destination.label = "Pinhais", total.estimate = 50444) # Solve for point estimates. solve_iasa_pt <- SolveIASA(pars = dogs_iasa$pars, init = dogs_iasa$init, time = 0:15, alpha.owned = TRUE, method = 'rk4') solve_iasa_rg <- SolveIASA(pars = dogs_iasa$pars, init = dogs_iasa$init, time = 0:10, alpha.owned = TRUE, s.range = seq(0, .4, l = 15), a.range = c(0, .2), alpha.range = c(0, .05), v.range = c(0, .1), method = 'rk4') ## Plot unowned population sizes using point estimates ## Not run: PlotModels(solve_iasa_pt, variable = "ns2") ## Plot all scenarios and change the label for the scenarios. ## Not run PlotModels(solve_iasa_rg, variable = "ns") ## End(Not run)
Displays two opposed horizontal barplots (pyramid).
PlotPopPyramid(dat = NULL, age.col = NULL, sex.col = NULL, str.col = NULL, str.tip = NULL, x.label = "Count", stage.label = "Years", legend.label = "Sterilized", inner.color = "LightBlue", outer.color = "DarkRed", label.size = 13)
PlotPopPyramid(dat = NULL, age.col = NULL, sex.col = NULL, str.col = NULL, str.tip = NULL, x.label = "Count", stage.label = "Years", legend.label = "Sterilized", inner.color = "LightBlue", outer.color = "DarkRed", label.size = 13)
dat |
|
age.col |
|
sex.col |
|
str.col |
|
str.tip |
string with the category of |
x.label |
string to be used as a label for the x axis. If undefined, |
stage.label |
a string to be used as a label for the ages or stage categories. If undefined, |
legend.label |
a string to be used as a label for the legend. If undefined, |
inner.color |
any valid specification of a color. When |
outer.color |
any valid way specification of a color. When |
label.size |
string to define the font size for labels. |
PlotPopPyramid
is mainly intended for companion animals population pyramids, although it can display other types of opposed bar charts.
The bars to the left of the x axis correspond to sort(unique(dat[, sex.col]))[1]
. If str.col
is not NULL
, bars will be stacked, with sort(unique(dat[, str.col]))[1]
as their base.
On the top of the plot, it is displayed the total number of observations of each dat[, sex.col]
unique value. This unique values are used as labels
.
The legend labels
are equal to the dat[, str.col]
unique values.
Font size of saved plots is usually different to the font size seen in graphic browsers. Before changing font sizes, see the final result in saved (or preview) plots.
Other details of the plot can be modifyed using appropriate functions from ggplot2
package (see examples).
Two opposed horizontal barplots.
In companion animals population surveys, some age categories might be empty. One difference between PlotPopPyramid
and pryramid.plot
is that the first does not drop empty age categories.
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
http://oswaldosantos.github.io/capm
data(dogs) PlotPopPyramid(dogs, age.col = "age", sex.col = "sex", str.col = "sterilized") PlotPopPyramid(dogs, age.col = "age", sex.col = "sex") ## Merge age categories pp_age <- cut(c(dogs$age, dogs$age3), breaks = c(0, 1, 3, 5, 7, 9, 11, 13, 15, max(c(dogs$age, dogs$age3), na.rm = TRUE)), labels = c("<1", "1-3", "3-5", "5-7", "7-9", "9-11", "11-13", "13-15", ">15"), include.lowest = TRUE) pp_sex <- c(dogs$sex, dogs$sex3) pp_ster <- c(dogs$sterilized, dogs$sterilized3) pp <- data.frame(age = pp_age, sex = pp_sex, sterilized = pp_ster) PlotPopPyramid(pp, age.col = "age", sex.col = "sex", str.col = "sterilized") PlotPopPyramid(pp, age.col = "age", sex.col = "sex")
data(dogs) PlotPopPyramid(dogs, age.col = "age", sex.col = "sex", str.col = "sterilized") PlotPopPyramid(dogs, age.col = "age", sex.col = "sex") ## Merge age categories pp_age <- cut(c(dogs$age, dogs$age3), breaks = c(0, 1, 3, 5, 7, 9, 11, 13, 15, max(c(dogs$age, dogs$age3), na.rm = TRUE)), labels = c("<1", "1-3", "3-5", "5-7", "7-9", "9-11", "11-13", "13-15", ">15"), include.lowest = TRUE) pp_sex <- c(dogs$sex, dogs$sex3) pp_ster <- c(dogs$sterilized, dogs$sterilized3) pp <- data.frame(age = pp_age, sex = pp_sex, sterilized = pp_ster) PlotPopPyramid(pp, age.col = "age", sex.col = "sex", str.col = "sterilized") PlotPopPyramid(pp, age.col = "age", sex.col = "sex")
Census tracts of Pinhais, Brazil, according to the census of 2010. Data described and analyzed by Baquero et al., 2018.
psu_ssu
psu_ssu
A data frame with 655 observations and 5 variables:
Census track's ID.
Number of households.
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
Select Primary Sampling Units (PSU) with probability proportional to size and with replacement.
SamplePPS(psu.ssu = NULL, psu = NULL, write = FALSE, ...)
SamplePPS(psu.ssu = NULL, psu = NULL, write = FALSE, ...)
psu.ssu |
|
psu |
the number of PSU to be selected. |
write |
logical. If |
... |
further arguments passed to |
data.frame
. First column contains the selected PSU identifiers, coerced by as.character
, to avoid scientific notation in case the identifiers be large numbers of class
numeric
. Second column contain PSU sizes, a variable needed for second stage sampling with SampleSystematic
.
Levy P and Lemeshow S (2008). Sampling of populations: methods and applications, Fourth edition. John Wiley and Sons, Inc.
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
http://oswaldosantos.github.io/capm
data(psu_ssu) # Take a sample of 10 PSU. SamplePPS(psu.ssu = psu_ssu, psu = 10, write = FALSE)
data(psu_ssu) # Take a sample of 10 PSU. SamplePPS(psu.ssu = psu_ssu, psu = 10, write = FALSE)
Select sampling units using simple or stratified systematic samplin. In the context of two-stage cluster sampling, select Secondary Sampling Units (SSU) in one or more Primary Sampling Units (PSU), using systematic sampling.
SampleSystematic(psu.ssu = NULL, su = NULL, N = NULL, write = FALSE, ...)
SampleSystematic(psu.ssu = NULL, su = NULL, N = NULL, write = FALSE, ...)
psu.ssu |
|
su |
|
N |
|
write |
logical. If |
... |
further arguments passed to |
When N
is defined, psu.ssu
is ignored. If N
has one element, su
must too and the result is a simple systematic selection. If N
has more than one element, su
must have the same number of elements and each oredered pair represent an strata. Thus, when N has more than one element, the result is a stratified sampling with systematic selection within each strata (see examples).
A matrix
. For the second stage in a two-stage cluster sampling, the names of columns are the identifiers of selected psu, coerced by as.character
to avoid scientific notation in case the identifiers be of class
numeric
. The rows correspond to the selected SSU within each PSU. For simple systematic sampling, the rows correspond to the selected sampling units. For stratified sampling, each column represent an strata and the rows correspond to the selected sampling units in each strata.
Levy P and Lemeshow S (2008). Sampling of populations: methods and applications, Fourth edition. John Wiley and Sons, Inc.
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
http://oswaldosantos.github.io/capm
data(psu_ssu) ## Two-stage cluster sampling selected_psu <- SamplePPS(psu.ssu = psu_ssu, psu = 10) # Take a systematic sampling of 5 SSU within each selected PSU. SampleSystematic(selected_psu, 5, write = FALSE) ## Simple systematic sampling SampleSystematic(su = 5, N = 100) ## Stratified systematic sampling SampleSystematic(su = c("urban" = 50, "rural" = 10), N = c("urban" = 4000, "rural" = 150))
data(psu_ssu) ## Two-stage cluster sampling selected_psu <- SamplePPS(psu.ssu = psu_ssu, psu = 10) # Take a systematic sampling of 5 SSU within each selected PSU. SampleSystematic(selected_psu, 5, write = FALSE) ## Simple systematic sampling SampleSystematic(su = 5, N = 100) ## Stratified systematic sampling SampleSystematic(su = c("urban" = 50, "rural" = 10), N = c("urban" = 4000, "rural" = 150))
Define the minimum and maximum values for parameters whose global sensitivities are to be assessed with CalculateGlobalSens
or sensRange
functions.
SetRanges(pars = NULL, range = 0.1)
SetRanges(pars = NULL, range = 0.1)
pars |
the same |
range |
scale factor to define the minimum and maximum for each parameter. The default is 0.1, which set the minimum and maximum as 10 percent lesser and greater than the |
data.frame
with the complete set of parameter ranges.
Soetaert K and Petzoldt T (2010). Inverse modelling, sensitivity and monte carlo analysis in R using package FME. Journal of Statistical Software, 33(3), pp. 1-28.
Reichert P and Kfinsch HR (2001). Practical identifiability analysis of large environmental simulation models. Water Resources Research, 37(4), pp. 1015-1030.
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
http://oswaldosantos.github.io/capm
## IASA model ## Parameters and intial conditions. data(dogs) dogs_iasa <- GetDataIASA(dogs, destination.label = "Pinhais", total.estimate = 50444) ## Set ranges 10 % greater and lesser than the ## point estimates. rg_solve_iasa <- SetRanges(pars = dogs_iasa$pars)
## IASA model ## Parameters and intial conditions. data(dogs) dogs_iasa <- GetDataIASA(dogs, destination.label = "Pinhais", total.estimate = 50444) ## Set ranges 10 % greater and lesser than the ## point estimates. rg_solve_iasa <- SetRanges(pars = dogs_iasa$pars)
System of ordinary differential equations to simulate the effect of immigration of owned dogs, abandonment, sterilization of owned and unowned dogs and adoption, on population dynamics.
SolveIASA(pars = NULL, init = NULL, time = NULL, alpha.owned = TRUE, immigration.reference = "N1", s.range = NULL, a.range = NULL, alpha.range = NULL, v.range = NULL, s.fm = TRUE, ...)
SolveIASA(pars = NULL, init = NULL, time = NULL, alpha.owned = TRUE, immigration.reference = "N1", s.range = NULL, a.range = NULL, alpha.range = NULL, v.range = NULL, s.fm = TRUE, ...)
pars |
a named |
init |
a named |
time |
time sequence for which output is wanted; the first value of times must be the initial time. |
alpha.owned |
|
immigration.reference |
|
s.range |
optional sequence (between 0 and 1) of the sterilization rates to be simulated. |
a.range |
optional |
alpha.range |
optional |
v.range |
optional |
s.fm |
logical. If |
... |
further arguments passed to ode function. |
The implemented model is described by Baquero, et. al., 2016 and the function is a wrapper around the defaults of ode function, whose help page must be consulted for details.
The pars
argument must contain named values, using the following conventions: 1
: owned animals; 2
: unowned animals; f
: females; m
: males. Then:
b1
and b2
: number of births.
df1
, dm1
, df2
and dm2
: death rate.
sf1
, sm1
, sf2
and sm2
: sterilization rate.
k1
and k2
: carrying capacity.
h1
and h2
: mean harem size.
a
: abandonment rate.
alpha
: adoption rate.
v
: immigration rate.
z
: proportion of sterilized immigrants.
The init
argument must contain named values for the inital number of animals, using the following conventions: 1
: owned animals; 2
: unowned animals; f
: females; m
: males; and s
: sterilized. Then, the names are:
f1
, fs1
, m1
, ms1
, f2
, fs2
, m2
and ms2
.
If any range is specified (e.g s.range
), the remaining ranges must be specified too (a.range
, alpha.range
and v.range
).
The function is a wrapper around the defaults of ode function, whose help page must be consulted for details. An exception is the method argument, which here has "rk4" as a default.
list
. The first element, name
, is a string with the name of the function, the second element, model
, is the model function. The third, fourth and fifth elements are vectors (pars
, init
, time
, respectively) containing the pars
, init
and time
arguments of the function. The sixth element results
is a data.frame
with up to as many rows as elements in time. The first column contain the time and subsequent columns contain the size of specific subpopulations, named according to conventions above. The group
column differentiate between owned and unowned. When *.range arguments are given, the last fourth columsn specify their instances.
Logistic growth models are not intended for scenarios in which population size is greater than carrying capacity and growth rate is negative.
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine. Baquero, O. S., Akamine, L. A., Amaku, M., & Ferreira, F. (2016). Defining priorities for dog population management through mathematical modeling. Preventive veterinary medicine, 123, 121-127.
http://oswaldosantos.github.io/capm
ode.
## Parameters and intial conditions. data(dogs) dogs_iasa <- GetDataIASA(dogs, destination.label = "Pinhais", total.estimate = 50444) # Solve for point estimates. solve_iasa_pt <- SolveIASA(pars = dogs_iasa$pars, init = dogs_iasa$init, time = 0:15, alpha.owned = TRUE, method = 'rk4') solve_iasa_rg <- SolveIASA(pars = dogs_iasa$pars, init = dogs_iasa$init, time = 0:10, alpha.owned = TRUE, s.range = seq(0, .4, l = 15), a.range = c(0, .2), alpha.range = c(0, .05), v.range = c(0, .1), method = 'rk4')
## Parameters and intial conditions. data(dogs) dogs_iasa <- GetDataIASA(dogs, destination.label = "Pinhais", total.estimate = 50444) # Solve for point estimates. solve_iasa_pt <- SolveIASA(pars = dogs_iasa$pars, init = dogs_iasa$init, time = 0:15, alpha.owned = TRUE, method = 'rk4') solve_iasa_rg <- SolveIASA(pars = dogs_iasa$pars, init = dogs_iasa$init, time = 0:10, alpha.owned = TRUE, s.range = seq(0, .4, l = 15), a.range = c(0, .2), alpha.range = c(0, .05), v.range = c(0, .1), method = 'rk4')
System of ordinary differential equations to simulate the effect of sterilization and immigration on population dynamics.
SolveSI(pars = NULL, init = NULL, time = NULL, dd = "b", im = 0, s.range = NULL, ...)
SolveSI(pars = NULL, init = NULL, time = NULL, dd = "b", im = 0, s.range = NULL, ...)
pars |
|
init |
|
time |
time sequence for which output is wanted; the first value of times must be the initial time. |
dd |
string equal to |
im |
a number representing the total of immigrants per time unit. |
s.range |
optional sequence (between 0 and 1) of the sterilization rates to be simulated. |
... |
further arguments passed to ode function. |
The implemented model is described by Amaku, et. al., 2009 and the function is a wrapper around the defaults of ode function, whose help page must be consulted for details.
list
. The first element, name
, is a string with the name of the function, the second element, model
, is the model function. The third, fourth and fifth elements are vectors (pars
, init
, time
, respectively) containing the pars
, init
and time
arguments of the function. The sisxth element results
is a data.frame
with up to as many rows as elements in time. First column contains the time, second column the population size and third column the proportion of sterilized animals. If s.range
is specified, fourth column contains its specific instances.
Logistic growth models are not intended for scenarios in which population size is greater than carrying capacity and growth rate is negative.
Amaku M, Dias R and Ferreira F (2009). Dinamica populacional canina: potenciais efeitos de campanhas de esterilizacao. Revista Panamericana de Salud Publica, 25(4), pp. 300-304.
Soetaert K, Cash J and Mazzia F (2012). Solving differential equations in R. Springer.
http://oswaldosantos.github.io/capm
ode.
# Parameters and initial conditions. pars_solve_si = c(b = 0.245, d = 0.101, k = 98050, s = 0.048) init_solve_si = c(n = 89137, q = 0.198) # Solve for a specific sterilization rate. solve_si_pt = SolveSI(pars = pars_solve_si, init = init_solve_si, time = 0:15, dd = "b", im = 100, method = "rk4") # Solve for a range of sterilization rates. solve_si_rg = SolveSI(pars = pars_solve_si, init = init_solve_si, time = 0:15, dd = "b", im = 100, s.range = seq(0, .4, l = 50), method = "rk4")
# Parameters and initial conditions. pars_solve_si = c(b = 0.245, d = 0.101, k = 98050, s = 0.048) init_solve_si = c(n = 89137, q = 0.198) # Solve for a specific sterilization rate. solve_si_pt = SolveSI(pars = pars_solve_si, init = init_solve_si, time = 0:15, dd = "b", im = 100, method = "rk4") # Solve for a range of sterilization rates. solve_si_rg = SolveSI(pars = pars_solve_si, init = init_solve_si, time = 0:15, dd = "b", im = 100, s.range = seq(0, .4, l = 50), method = "rk4")
System of ordinary differential equations to simulate the effect of reversible contraception in a population at equilibrium, where deaths are compensated by births and net immigration.
SolveTC(pars = NULL, init = NULL, time = NULL, f.range = NULL, s.range = NULL, z.range = NULL, ...)
SolveTC(pars = NULL, init = NULL, time = NULL, f.range = NULL, s.range = NULL, z.range = NULL, ...)
pars |
a named |
init |
a named |
time |
time sequence for which output is wanted; the first value of times must be the initial time. |
f.range |
optional sequence (between 0 and 1) with the fertility recovery rates to be simulated. |
s.range |
optional |
z.range |
optional |
... |
further arguments passed to ode function. |
list
. The first element, name
, is a string with the name of the function, the second element, model
, is the model function. The third, fourth and fifth elements are vectors (pars
, init
, time
, respectively) containing the pars
, init
and time
arguments of the function. The sisxthth element results
is a data.frame
with up to as many rows as elements in time. The first fourth columns contain the time and the variables: n
, g
and u
. When *.range arguments are given, additional columns contain the variables f
, s
and z
.
http://oswaldosantos.github.io/capm
Baquero, O. S., Brandao, A. P. D., Amaku, M., & Ferreira, F. (2016). Effectiveness of reversible contraception in dog population management. Acta Scientiae Veterinariae, 44, 01-06.
ode.
# Parameters and initial conditions. pars_solvetc <- c(d = 1 / 6, f = 0.5, s = 0.2, z = 0.2, r = 0.8) init_solvetc <- c(n = 950, g = 50) # Solve for point estimates. solve_tc_pt <- SolveTC(pars = pars_solvetc, init = init_solvetc, time = 0:10, method = "rk4") # Solve for parameter ranges. solve_tc_rg <- SolveTC(pars = pars_solvetc, init = init_solvetc, time = 0:15, f.range = seq(0, 1, 0.1), s.range = c(0.05, 0.4), z.range = c(0.05, 0.4), method = "rk4")
# Parameters and initial conditions. pars_solvetc <- c(d = 1 / 6, f = 0.5, s = 0.2, z = 0.2, r = 0.8) init_solvetc <- c(n = 950, g = 50) # Solve for point estimates. solve_tc_pt <- SolveTC(pars = pars_solvetc, init = init_solvetc, time = 0:10, method = "rk4") # Solve for parameter ranges. solve_tc_rg <- SolveTC(pars = pars_solvetc, init = init_solvetc, time = 0:15, f.range = seq(0, 1, 0.1), s.range = c(0.05, 0.4), z.range = c(0.05, 0.4), method = "rk4")
Wraps functions for summary statistics from survey package.
SummarySurvey(design = NULL, variables = NULL, conf.level = 0.95, rnd = 3)
SummarySurvey(design = NULL, variables = NULL, conf.level = 0.95, rnd = 3)
design |
an output form |
variables |
|
conf.level |
the confidence level required. |
rnd |
the number of decimal places (round) or significant digits (signif) to be used. If |
The length of variables
must be equal to the length of names(design$variables)
(see examples).
Matrix with survey summaries.
Lumley, T. (2011). Complex surveys: A guide to analysis using R (Vol. 565). Wiley.
Baquero, O. S., Akamine, L. A., Amaku, M., & Ferreira, F. (2016). Defining priorities for dog population management through mathematical modeling. Preventive veterinary medicine, 123, 121-127.
http://oswaldosantos.github.io/capm
data("cluster_sample") data("psu_ssu") ## Calibrated two-stage cluster design cs <- cluster_sample[ , c("interview_id", "census_tract_id", "number_of_persons", "number_of_dogs", "number_of_cats")] design <- DesignSurvey(na.omit(cs), psu.ssu = psu_ssu, psu.col = "census_tract_id", ssu.col = "interview_id", cal.col = "number_of_persons", cal.N = 129445) SummarySurvey(design, c("total", "total", "total"))
data("cluster_sample") data("psu_ssu") ## Calibrated two-stage cluster design cs <- cluster_sample[ , c("interview_id", "census_tract_id", "number_of_persons", "number_of_dogs", "number_of_cats")] design <- DesignSurvey(na.omit(cs), psu.ssu = psu_ssu, psu.col = "census_tract_id", ssu.col = "interview_id", cal.col = "number_of_persons", cal.N = 129445) SummarySurvey(design, c("total", "total", "total"))