Shift the start time of potential mortalities earlier, if station/location has not changed.

backwards(data, morts, ID, station, res.start, stnchange = NULL)

Arguments

data

a dataframe of residence events. Residence events must include tag ID, location name, start time, and duration. Residence events should be continuous (i.e., not subset by season).

morts

a dataframe containing potential mortalities. Must use #' the same column names and in the same order as data.

ID

a string of the name of the column in data that holds the tag or sample IDs.

station

a string of the name of the column in data that holds the station name or receiver location.

res.start

a string of the name of the column in data that holds the start date and time. Must be specified and in POSIXt if type="manual".

stnchange

a dataframe with the start time and location of the most recent station or location change. Must use the same column names and in the same order as data.

Value

a dataframe with one row for each tag ID, including the date/time of the residence start when the potential mortality or expelled tag was identified. Returns the input morts dataframe if no potential mortalities are shifted earlier. All input data fields (e.g., any name, location, or species information that was included with the input data) will be retained.

Examples

morts<-morts(data=events,type="mort",ID="ID",station="Station.Name",
method="any")
#> [1] "Identifying last station change"
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |=========================================                             |  58%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |======================================================================| 100%[1] "Identifying the resmax threshold"
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |=========================================                             |  58%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |======================================================================| 100%[1] "Identifying mortalities for method='any'"
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |=========================================                             |  58%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |======================================================================| 100%
head(morts)
#>          ResidenceStart Station.Name ID        ResidenceEnd
#> 100 2005-07-02 17:02:03            5  D 2005-10-10 21:55:45
#> 101 2004-07-15 21:09:22            5  E 2004-10-12 21:44:11
#> 106 2005-06-28 21:12:58            1  F 2005-10-09 20:28:05
#> 201 2006-02-04 21:25:18           17  G 2006-05-01 06:30:02
#>     ResidenceLength.days
#> 100            100.20396
#> 101             89.02418
#> 106            102.96883
#> 201             85.37829

# If station change not identified yet:
morts_bw<-backwards(data=events,morts=morts,ID="ID",
station="Station.Name",res.start="ResidenceStart")
head(morts_bw)
#>          ResidenceStart Station.Name ID        ResidenceEnd
#> 100 2004-08-31 16:48:00            5  D 2004-08-31 17:38:18
#> 101 2004-07-15 21:09:22            5  E 2004-10-12 21:44:11
#> 106 2005-06-28 21:12:58            1  F 2005-10-09 20:28:05
#> 201 2004-06-28 12:30:56           17  G 2004-06-30 09:59:17
#>     ResidenceLength.days
#> 100           0.03493056
#> 101          89.02417824
#> 106         102.96883102
#> 201           1.89468750

# Identify station change first:
station.change<-stationchange(data=events,type="mort",
ID="ID",station="Station.Name")
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |=========================================                             |  58%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |======================================================================| 100%

morts_bw<-backwards(data=events,morts=morts,ID="ID",
station="Station.Name",res.start="ResidenceStart",
stnchange=station.change)
head(morts_bw)
#>          ResidenceStart Station.Name ID        ResidenceEnd
#> 100 2004-08-31 16:48:00            5  D 2004-08-31 17:38:18
#> 101 2004-07-15 21:09:22            5  E 2004-10-12 21:44:11
#> 106 2005-06-28 21:12:58            1  F 2005-10-09 20:28:05
#> 201 2004-06-28 12:30:56           17  G 2004-06-30 09:59:17
#>     ResidenceLength.days
#> 100           0.03493056
#> 101          89.02417824
#> 106         102.96883102
#> 201           1.89468750