Package 'incR'

Title: Analysis of Incubation Data
Description: Suite of functions to study animal incubation. At the core of incR lies an algorithm that allows for the scoring of incubation behaviour. Additionally, several functions extract biologically relevant metrics of incubation such as off-bout number and off-bout duration - for a review of avian incubation studies, see Nests, Eggs, and Incubation: New ideas about avian reproduction (2015) edited by D. Charles Deeming and S. James Reynolds <doi:10.1093/acprof:oso/9780198718666.001.0001>.
Authors: Pablo Capilla-Lasheras [aut, cre]
Maintainer: Pablo Capilla-Lasheras <[email protected]>
License: GPL-3
Version: 2.1.1.9000
Built: 2025-02-18 06:58:49 UTC
Source: https://github.com/pablocapilla/incr

Help Index


incR: Analysis of animal incubation

Description

This packages is formed by a suite of R functions that help the user to get useful biological information from raw time-series data of incubation temperatures. It is thought to be of interest for the study of uni-parental or intermittent incubating species.

Suggested workflow

Check the package vignettes to find a suggested workflow and calibrate the main function in incR.

incR functions

The current version of incR contains the following functions and three example data sets: incRprep, incRenv, incRscan, incRact, incRatt incRbouts and incRt, along with three example data sets.


An example data set of environmental temperatures to test the use of link{incRenv}.

Description

A dataset containing environmental temperatures for the study area where the data in incR_rawdata were collected. This raw data set was produced by an iButton device (Maxim Integrated).

Usage

incR_envdata

Format

A data frame with 1570 rows and two variables, representing two days of environmental temperature recordings at two different locations in one study site.

DATE

a date-time column. Both elements, date and time, are concatenated in one column.

env_temperature

environmental temperature recordings.

Details

use this data set to try out link{incRenv} after the very first application of incRprep using incR_rawdata.


An example of incubation temperature time-series after the use of incRprep and incRenv.

Description

A dataset containing temperatures, time and date for a blue tit nest. It also includes variables added by incRprep and incRenv. The raw data set incR_rawdata was produced by an iButton device (Maxim) and represents raw data to start the analysis of incubation behaviour

Usage

incR_procdata

Format

A data frame with 954 rows and 11 variables, representing two days of nest temperatures.

DATE

a date-time column. Both elements, date and time, are concatenated in one column.

temperature

nest temperature recordings.

index

running number from first to last observation.

time
hour
minute
second
date
dec_time

time in decimal hours.

temp1

difference between the ith and the ith-1 nest temperature recording.

env_temp

environmental temperature, calculated per as hour average using incRenv.

incR_score

Incubation scores (0/1) as calculated by incRscan

Details

see incRprep and incRenvfor more details on the variables of this data set and how it was produced.


An example of incubation temperature time-series

Description

A dataset containing date, time and temperatures for a blue tit nest. This data set was produced by an iButton device (Maxim Integrated) and represents raw data to start the analysis of incubation behaviour.

Usage

incR_rawdata

Format

A data frame with 954 rows and 2 variables, representing three days of nest temperatures.

DATE

a date-time column. Both elements, date and time, are concatenated in one column

temperature

temperature recordings in Celsius


Calculation of daily first incubation off-bout and last incubation on-bout

Description

Using a vector of incubation scores, incRact calculates onset of activity (first off-bout in the morning), and end of daily activity (last on-bout in the evening) per day. A column for dates, named "date" is needed in the data argument.

Usage

incRact(data, time_column, vector.incubation)

Arguments

data

data frame containing a numeric vector of 1's and 0's (incubation scores), where "1" means "incubating individual inside nest" and "0" means "incubating individual outside the nests". This vector, under the name of incR_score is provided by incRscan in the first object (incRscan_data) of the returned list. A column named "date" is needed to refer to daily calculations.

time_column

(character class) name of the column containing times.

vector.incubation

(character class) name of the vector containing incubation scores. incRscan produces this vector named "incR_score".

Value

a data frame containing fist off-bout and last on-bout per day in data.

Author(s)

Pablo Capilla-Lasheras

See Also

incRprep incRscan

Examples

#' # loading example data
data(incR_procdata)
incRact (data=incR_procdata, 
              time_column="time",
              vector.incubation="incR_score")

Calculation of the percentage of daily time spent in nest

Description

This function calculates percentage of day time spent inside nest based on the "inc.vector" variable produced by incRscan (or any other method). Current version do not discriminate day and night times.

Usage

incRatt(data, vector.incubation)

Arguments

data

data frame containing a time-series vector of 1's and 0's, where "1" means "incubating individual inside nest" and "0" means "incubating individual outside nest". This vector, under the name of "inc.vector" is provided by incRscan in the first object of the returned list. A column named "date" is needed to refer to daily calculations.

vector.incubation

name of the column (vector class) storing the information about the presence/absence of the incubating individual in the nest.

Details

The 'date' column must have a 'year-month-day' format for this function to run correctly.

Value

Daily percentage of time in nest, returned in a data frame with one day per raw.

See Also

incRprep incRscan incRact

Examples

#' # loading example data
data(incR_procdata)
incRatt (data=incR_procdata, 
               vector.incubation="incR_score")

Calculation of the number of daily on- and off-bouts

Description

Calculation of number and duration of incubation on- and off-bouts.

Usage

incRbouts(data, vector.incubation, dec_time, temp, sampling.rate)

Arguments

data

data frame containing a time-series vector of 1's and 0's, where "1" means "incubating individual inside nest" and "0" means "incubating individual outside nest". This vector, under the name of "inc.vector", is provided by incRscan in the first object of the returned list. A column named "date" is needed to refer to daily calculations.

vector.incubation

name of the column (vector class) storing the information about the presence/absence of the incubating individual in the nest.

dec_time

(character class) name of the column with decimal time.

temp

(character class) name of the column with incubation temperatures.

sampling.rate

time difference between two consecutive recording points. Effectively, the rate at which data points were recorded (e.g. 1 data point per 50sec). The time units of the returned object will depend on the units of this argument.

Value

This function returns a list with two objects. The first object, named total_bouts, is a list of individual on- and off-bouts, giving information about their start time, duration, start nest temperature and final nest temperature. The second object, day_bouts, provides a summary of on- and off-bouts per day of observation. This second table shows number and mean duration of on- and off-bout per day. Mean times are shown in those time units you specify the argument sampling.rate.

Author(s)

Pablo Capilla-Lasheras

See Also

incRprep incRscan incRact incRatt

Examples

#' # loading example data
data(incR_procdata)
incRbouts (data=incR_procdata, 
           vector.incubation="incR_score", 
           dec_time="dec_time",
           temp="temperature",
           sampling.rate=240) # sampling rate in seconds.

Matching environmental and nest temperatures

Description

This function takes a data frame with recordings of environmental temperature and another with nest temperatures and merges both by time. The user can do this work manually, however, incRenv is thought to automate data preparation (in combination with incRprep) to use incRscan after. Code to update and improve this function provided by Natalie van Dis.

Usage

incRenv(
  data.nest,
  data.env,
  env.temperature.name,
  env.date.name,
  env.date.format,
  env.timezone
)

Arguments

data.nest

data frame containing nest temperature recordings. It must have two compulsory columns 'date' and 'hour' displaying dates and the hour of each observation. These two columns are provided if the user uses incRprep before.

data.env

data frame containing environmental temperatures to be merged with nest temperature records. Please, provide date and time of each observation in one unique column as requested for incRprep.

env.temperature.name

name of the column containing temperature recordings in the data.env data frame.

env.date.name

name of the column containing date and time in the data.env data frame.

env.date.format

format of env.date.name. Similar to incRprep.

env.timezone

time zone of the environmental recordings. Similar to incRprep.

Details

This function is thought to be used after incRprep as it uses some of the additional variables created by incRprep.

Value

The original data.nest with an additional column for hour-averaged environmental temperature. This new variable is thought to serve as env_temp in incRscan.

Author(s)

Pablo Capilla-Lasheras

See Also

incRprep incRscan

Examples

data(incR_envdata)  # environmental data
head (incR_envdata)

data(incR_rawdata)  # loading nest data
head (incR_rawdata)

# the first step in to format the raw data using incRprep
new.data <- incRprep (data=incR_rawdata,
                      date.name= "DATE",
                      date.format= "%d/%m/%Y %H:%M",
                      timezone="GMT",
                      temperature.name="temperature")
                      
# then use incRenv to merge environmental data
new.data2 <- incRenv (data.nest = new.data,
                      data.env = incR_envdata, 
                      env.temperature.name = "env_temperature", 
                      env.date.name = "DATE", 
                      env.date.format = "%d/%m/%Y %H:%M", 
                      env.timezone = "GMT")
                     
head (new.data2, 3)

Matching environmental and nest temperatures - Old version

Description

This function takes a data frame with recordings of environmental temperature and another with nest temperatures and merges both per unit of time. The user can do this work manually, however, incRenv is thought to automate data preparation (in combination with incRprep) to use incRscan after.

Usage

incRenv_old(
  data.nest,
  data.env,
  env.temperature.name,
  env.date.name,
  env.date.format,
  env.timezone
)

Arguments

data.nest

data frame containing nest temperature recordings. It must have two compulsory columns 'date' and 'hour' displaying dates and the hour of each observation. These two columns are provided if the user uses incRprep before.

data.env

data frame containing environmental temperatures to be merged with nest temperature records. Please, provide date and time of each observation in one unique column as requested for incRprep.

env.temperature.name

name of the column containing temperature recordings in the data.env data frame.

env.date.name

name of the column containing date and time in the data.env data frame.

env.date.format

format of env.date.name. Similar to incRprep.

env.timezone

time zone of the environmental recordings. Similar to incRprep.

Details

This function is thought to be used after incRprep as it uses some of the additional variables created by incRprep.

Value

The original data.nest with an additional column for hour-averaged environmental temperature. This new variable is thought to serve as env_temp in incRscan.

Author(s)

Pablo Capilla-Lasheras

See Also

incRprep incRscan

Examples

data(incR_envdata)  # environmental data
head (incR_envdata)

data(incR_rawdata)  # loading nest data
head (incR_rawdata)

# the first step in to format the raw data using incRprep
new.data <- incRprep (data=incR_rawdata,
                      date.name= "DATE",
                      date.format= "%d/%m/%Y %H:%M",
                      timezone="GMT",
                      temperature.name="temperature")
                      
# then use incRenv to merge environmental data
new.data2 <- incRenv_old (data.nest = new.data,
                      data.env = incR_envdata, 
                      env.temperature.name = "env_temperature", 
                      env.date.name = "DATE", 
                      env.date.format = "%d/%m/%Y %H:%M", 
                      env.timezone = "GMT")
                     
head (new.data2, 3)

Quick visualisation of incubation temperatures, on-bouts and off-bouts

Description

After incRscan has been used, incRplot provides a quick visualisation of the incubation temperature trace with coloured on- and off-bouts. Environmental temperatures can also be added to the plot

Usage

incRplot(
  data,
  time.var,
  day.var,
  inc.temperature.var,
  env.temperature.var = NULL,
  vector.incubation
)

Arguments

data

data table with incubation temperature data

time.var

Character string. Name of the variable with time of the day for temperature data. Please, have time in decimal hours. If incRprep has been previously used, "dec_time" can be used.

day.var

Character string. Name of the variable with date for temperature observation. No specific format is needed. If incRprep has been previously used, "date" can be used.

inc.temperature.var

Character string. Name of the variable with incubation temperatures.

env.temperature.var

Character string. Name of the variable with environmental temperatures. If no value is provided, a plot with no environmental temperatures is produced.

vector.incubation

name of the binary variable storing information about the presence/absence of the incubating individual in the nest. If incRscan has been used, "incR_score" can be used.

Value

Plot of incubation temperature, on-bouts and off-bouts with (optional) environmental temperatures. The plot is generated using ggplot2.The user can customised the appearance of the plot using tools within ggplot2(see example)

See Also

incRscan

Examples

# loading example data
data(incR_procdata)
my_plot <- incRplot(data = incR_procdata[complete.cases(incR_procdata$temperature),], 
                    time.var = "dec_time", 
                    day.var = "date", 
                    inc.temperature.var = "temperature", 
                    env.temperature.var = "env_temp",
                    vector.incubation = "incR_score")
                    
# see your plot
my_plot

# add new labels (ggplot2 required)
my_plot + ggplot2::labs(x = "New X label", y = "New Y label")

Data preparation for incubation analysis in incR

Description

Preparing incubation time series for further analysis. This function takes a data file containing a temporal series of temperature recordings and adds some the extra variables needed to use further functions embedded in the incR package. It simply accommodates a raw data frame, reformatting date and time columns automatically.

Usage

incRprep(data, date.name, date.format, timezone, temperature.name)

Arguments

data

raw data from incubation time series. It must contain a column with date and time information for each observation (e.g. "2017-05-01 21:01"). The function is written to handle date and time concatenated in one unique column (see example below).

date.name

name of the date and time column

date.format

format for date and time column. It must be a character object as specified in the function strptime. incRprep assumes that the date and time column contains date and time, If date and time are in different columns, please, concatenate them in one column before running the function.

timezone

time zone for time calculations. See strptime. documentation for more details.

temperature.name

name of the column storing temperature information.

Value

The original data frame with additional columns for:

  1. index: a running number identifying every row in the data set.

  2. time: in '

  3. hour: in 'H' format.

  4. minute: in 'M' format.

  5. second: in 'S' format.

  6. date: in 'Y-m-d' format.

  7. dec_time: time in decimal hours (e.g. "22:30" becomes 22.5).

  8. temp1: difference between the ith temperature value and the i-1 one.

Author(s)

Pablo Capilla-Lasheras

Examples

# loading example data
data(incR_rawdata)
new.data <- incRprep (data=incR_rawdata,
                       date.name= "DATE",
                       date.format= "%d/%m/%Y %H:%M",
                       timezone="GMT",
                       temperature.name="temperature")
head (new.data, 3)

Automated scoring of incubation

Description

This is the core algorithm of incR and classifies time points as 1's or 0's depending on whether or not the incubating individual is considered to be on the eggs. The algorithm uses night variation to daily calibrate itself to temperature variation when the incubating individual is assumed to be on the eggs. A major assumption of this algorithm is that there is a period of time in which temperature can be assumed to be constant or representative of time windows of constant incubation. This time window is defined by two arguments: lower.time and upper.time. The function is optimised to work using a data frame produced by incRprep.

Usage

incRscan(
  data,
  temp.name,
  lower.time,
  upper.time,
  sensitivity,
  temp.diff,
  temp.diff.threshold,
  maxNightVariation,
  env.temp
)

Arguments

data

data frame for analysis. It must contained four columns named as follow: date, temp1, dec_time and index, where temp1 is the difference between the ith and i-1th temperature recordings; dec_time is time in decimal hours; and index is a running number from 1 to N, N being the total number of observations. incRprep returns a data frame with these variables and the correct names, ready to be passed through incRscan.

temp.name

(character object) name of the column containing temperature data in data.

lower.time

lower limit of time window for calibration (numeric).

upper.time

upper limit of time window for calibration (numeric).

sensitivity

ratio of reduction in temperature threshold. When nest temperature does not drop close to environmental temperatures, this value can be kept to 1. If nest temperature follows environmental temperature at any point, then adjustment of this value may be required to detect short on/off-bouts at lower nest temperatures (see details).

temp.diff

deprecated. Use temp.diff.threshold.

temp.diff.threshold

threshold for temperature difference between env.temp and an observation which triggers the sensitivity parameter.

maxNightVariation

maximum temperature variation between two consecutive points within the calibrating window that is considered normal of this period. If this variation value is surpassed, the calibrating window is discarded and a previous night is used for calibration.

env.temp

name of a column containing environmental temperatures.

Value

The function returns a list with two objects. The first object, named incRscan_data, is the original data frame with an extra column named 'incR_score'. This variable is formed by 1's and 0's, representing whether the incubating individual is inside (1) or outside the nest (0).

The second object, named incRscan_threshold, is a data frame with one day per row. Four columns tell the user the thresholds employed to calculate the 'incR_score' column. A fifth column accounts for the ratio between temperature variation in the calibrating window and the variation in temperature between 11am and 3pm for each day morning. The lower this value the more clear the pattern between night and day variation and, therefore, stronger the signal in the data. This value may serve the user as an indication of the signal / noise ratio in the analysed data set.

Details

For further details about the calculation performed by incRscan, consult the package vignettes and the associated publications.

Author(s)

Pablo Capilla-Lasheras

See Also

incRprep incRenv

Examples

# incR_procdata is a dataframe processed by incRprep and incRenv.
# it contains suitable information to run incRscan
data(incR_procdata)

incubation.analysis <- incRscan (data=incR_procdata, 
                                  temp.name="temperature",
                                  lower.time=22,
                                  upper.time=3,
                                  sensitivity=0.15,
                                  temp.diff.threshold=5,
                                  maxNightVariation=2,
                                  env.temp="env_temp")
inc.data <- incubation.analysis[[1]]
inc.thresholds <- incubation.analysis[[2]]

Scoring of incubation based on a fixed temperature threshold

Description

Modified version of incRscan. Data points are assigned to incubation on/off-bout based on a fixed temperature threshold for the difference in nest temperature expected when an off-bout starts.

Usage

incRscan_v2(
  data,
  temp.name,
  sensitivity,
  temperature_threshold,
  temp.diff.threshold,
  env.temp
)

Arguments

data

data frame for analysis. It must contained four columns named as follow: date, temp1, dec_time and index, where temp1 is the difference between the ith and i-1th temperature recordings; dec_time is time in decimal hours; and index is a running number from 1 to N, N being the total number of observations. incRprep returns a data frame with these variables and the correct names, ready to be passed through incRscan.

temp.name

(character object) name of the column containing temperature data in data.

sensitivity

percentage of reduction in temperature threshold. When nest temperature does not drop close to environmental temperature, this value can be kept to 1. If nest temperature follows environmental temperature at any point, then, adjustment of this value may be required to detect short on/off-bouts at lower nest temperatures (see details).

temperature_threshold

Maximum temperature difference between two consecutive nest temperature recordings allowed for an on-bout. When the difference in nest temperature between two consecutive recordings is higher than this value, an off-bout is detected.

temp.diff.threshold

threshold for temperature difference between env.temp and an observation which triggers application of the sensitivity parameter.

env.temp

name of a column containing environmental temperatures.

Value

The function returns the original data frame with a new column named 'incR_score'. This new variable is formed by 1's and 0's, representing whether the incubating individual is inside ("1") or outside the nest ("0"). #' @section Details: See incRenv for more details

Author(s)

Pablo Capilla-Lasheras

See Also

incRprep incRenv incRscan

Examples

# incR_procdata is a data frame processed by incRprep and incRenv.
# It contains suitable information to run incRscan
data(incR_procdata)

incubation.analysis <- incRscan_v2 (data=incR_procdata, 
                                  temp.name="temperature",
                                  temperature_threshold = 0.75,
                                  sensitivity=0.15,
                                  temp.diff.threshold=5,
                                  env.temp="env_temp")

Scoring of incubation based on combination of dynamic (as in incRscan) and fixed temperature thresholds (as in incRscan_v2

Description

Modified version of incRscan. It combines the assignment of incubation on/off-bout implemented in incRscan and incRscan_v2.

Usage

incRscan_v3(
  data,
  temp.name,
  temperature_threshold,
  lower.time,
  upper.time,
  sensitivity,
  temp.diff,
  temp.diff.threshold,
  maxNightVariation,
  env.temp
)

Arguments

data

data frame for analysis. It must contained four columns named as follow: date, temp1, dec_time and index, where temp1 is the difference between the ith and i-1th temperature recordings; dec_time is time in decimal hours; and index is a running number from 1 to N, N being the total number of observations. incRprep returns a data frame with these variables and the correct names, ready to be passed through incRscan.

temp.name

(character object) name of the column containing temperature data in data.

temperature_threshold

Maximum temperature difference between two consecutive nest temperature recordings allowed for an on-bout. When the difference in nest temperature between two consecutive recordings is higher than this value, an off-bout is detected. Only applies for days when a calibration window is not available or temp.diff.threshold is exceeded.

lower.time

lower limit of time window for calibration (numeric).

upper.time

upper limit of time window for calibration (numeric).

sensitivity

percentage of reduction in temperature threshold. When nest temperature does not drop close to environmental temperature, this value can be kept to 1. If nest temperature follows environmental temperature at any point, then, adjustment of this value may be required to detect short on/off-bouts at lower nest temperatures (see details).

temp.diff

deprecated. Use temp.diff.threshold.

temp.diff.threshold

threshold for temperature difference between env.temp and an observation which triggers application of the sensitivity parameter.

env.temp

name of a column containing environmental temperatures.

Value

The function returns the original data frame with a new column named 'incR_score'. This new variable is formed by 1's and 0's, representing whether the incubating individual is inside ("1") or outside the nest ("0"). #' @section Details: See incRenv for more details

Author(s)

Pablo Capilla-Lasheras

See Also

incRscan incRscan_v2


Calculation of temperature average and variance for customised time windows

Description

Calculation of temperature average and variation between two customised time periods per day. Time windows can be defined by the user using the limits argument, defined by bird activity time (using the activity.times parameter) or set according to twilight times if coordinates are provided (coor).

Usage

incRt(
  data,
  temp.name,
  limits = NULL,
  coor = NULL,
  activity.times = FALSE,
  civil.twilight = FALSE,
  time.zone = NULL,
  ...
)

Arguments

data

data frame containing a time-series vector of 1's and 0's (incubation scores), where "1" means "incubating individual inside nest" and "0" means "incubating individual outside the nests". This vector, under the name of incR_score, is provided by incRscan in the first object of the returned list. A column named "date" is needed to refer to daily calculations.

temp.name

(character object) name of the column containing temperature data in data.

limits

vector of length 2 giving the time limits for calculations. For example, 'c(6,20)' would calculate temperature averages and variances for two time periods, from 6 to 20 and from 20 to 6 of the next day. 'civil.twilight' and 'activity.times' must be FALSE to allow the use of 'limits'.

coor

coordinates for the location where temperature was recorded, formatted as decimal degrees N/S, decimal degrees E/W. When 'civil.twilight' is TRUE, 'coor' allows the user to define sunrise and sunset times based on the getSunlightTimes function (in suncalc package).

activity.times

TRUE or FALSE. Set as TRUE when time periods for calculation are defined by incRact. Data must contain a column named 'incR_score' for the use of incRact.

civil.twilight

TRUE or FALSE. Set as TRUE when time periods for calculation are to be defined by civil twilight times - calculated using getSunlightTimes. If 'civil.twilight = TRUE', 'coor' and 'time.zone' need to be specified.

time.zone

time zone for getSunlightTimes dawn and dusk calculations.

...

use parameters in incRact if activity.times = TRUE.

Value

a data frame containing temperature means and variance for the defined time window.

Author(s)

Pablo Capilla-Lasheras

See Also

incRprep incRscan incRact getSunlightTimes

Examples

# loading example data
data(incR_procdata)

# calculation based on chosen times from 6am to 7pm and 7pm to 6am
incRt (data=incR_procdata, 
        temp.name="temperature",
        limits=c(6,19), 
        coor=NULL, 
        civil.twilight=FALSE, 
        activity.times=FALSE,
        time.zone=NULL)
        
# calculation based on activity times
incRt (data=incR_procdata, 
        temp.name="temperature", 
        limits=NULL, 
        coor=NULL, 
        civil.twilight=FALSE, 
        activity.times=TRUE,
        time.zone=NULL,
        time_column="time",             # extra argument needed for incRact
        vector.incubation="incR_score") # extra argument needed for incRact
        
# calculation based on civil twilight
incRt (data=incR_procdata, 
        temp.name="temperature",
        limits=NULL, 
        coor=c(42,0.89), 
        civil.twilight=TRUE, 
        activity.times=FALSE,
        time.zone="GMT")