View on GitHub


R package for Companion Animal Population Management

Download this project as a .zip file Download this project as a tar.gz file


capm is a package for R, a free software environment for statistical computing and graphics.

capm stands for Companion Animal Population Management and is an initiative to guide and automate quantitative analysis to support companion animal population management.

Current version offers functions that allow users to implement the workflow outlined in Figure 1. The basic idea is simple, some functions are to implement a data collection process and other functions are to analyse collected data. Information generated in the analysis process support the design, implementation and assessment of population management programs. Detailed descriptions of workflow steps and used methods will be added to the links at the end of this page.

Figure 1. Workflow supported by the capm.

Data collection

Data collection is the first of the two main components of the workflow. When data is collected in censuses surveys, this component must be omitted. Remember that a census is a survey that includes ALL elements of the study population. For example, a household survey in a city is a census only if ALL households in that city are included in the survey. Costs associated with censuses are often prohibited and thus, sample surveys are the most common alternative to collect population data. The Data collection component is intended to support sample surveys.

The sample is a subset of population elements. Because we want information of the whole population, we must to infer that information (population parameters) from the sample. This process incorporates errors. We can not know the exact values of population parameters but we can get approximations (estimates). Estimates can be misleading but reasonable and useful estimates can be generated if a sound statistical process is followed to calculate the sample size and to select sampling units (elements included in the sample). To calculate the sample size, it is necessary to have a preliminar estimate of the parameters to be estimated. This preliminary estimates can be obtained in pilot studies or from previous studies. Using the capm, sample surveys for companion animal populations can be easily designed and implemented following well known statistical processes but without need to worry about them.

Data analysis

With sample or census data, some analysis can be made to support population management programs. For this second component, the capm has functions to estimate population parameters from sample data, according to the data collection process. Also, it is possible to build population pyramids conditioned not only on sex and age but on other characteristics such as reproductive status. The estimates of population parameters can be used as inputs in mathematical models to simulate population dynamics, prioritize interventions and build scenarios to assess the interaction between some interventions. The use of these models is straightforward in the capm.


To install the development version, run install_github('capm', 'oswaldosantos') in (ideally) RStudio. devtools package must be previously loaded.

To install the production version, run install.packages('capm') in (ideally) RStudio.

Current production version: 0.9.1


capm can be used at the command line but also has Graphic User Interfaces (GUI).

Command line


In the data collection process, selected sampling units can be mapped using capm GUI, other R functions or an external software such as Google Earth or QGIS to read files exported from the capm.


capm GUI



Google Earth

In the data analysis process, population pyramids and simulations of population dynamics help to characterize populations.

Population pyramid

Simulation of population dynamics (point estimates)

Global sensitivity of non sterilized stray dog population to all parameters

Global sensitivity of non sterilized stray dog population to each parameter

Local sensitivity of non sterilized stray dog population



If you find any error or have suggestions to improve or include functionality to the capm I will glad to know it. Please get in touch so I can better understand your needs.


Research documents

Dog and cat population management: quantitative methods to characterize populations, identify priorities and to establish indicators: PhD thesis with five research manuscripts (abstracts in english). The thesis brings the context in which the capm was developed.

Defining priorities for dog population management through mathematical modeling: manuscript describing the model implemented in the function SolveIASA. It was drawn from the thesis' chapter 5.

Dog and cat management through sterilization: Implications for population dynamics and veterinary public policies: manuscript describing a practical application of the model described in the above manuscript.

Demographic characteristics of owned dogs and cats of Votorantim, São Paulo State, Brazil: manuscript describing a survey made during the early capm development. It was drawn from the thesis' chapter 2.


Programming guide for the capm R package

Guía de programación para el paquete de R capm

Guia de programação para o pacote do R capm

Do IBGE ao pactoe do R capm. Guia para a obtenção e preparação de dados


I am particularly grateful to Fernando Ferreira and Marcos Amaku for their methodological advices.

I also want to acknowledge the financial support that the Fundação de Amparo à Pesquisa de São Paulo (FAPESP) gave to the PhD from which this package arose.


Copyright (C) 2016 Oswaldo Santos Baquero

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see