StatusCorrectionByTree: StatusCorrectionByTree

View source: R/StatusCorrection.R

StatusCorrectionByTreeR Documentation

StatusCorrectionByTree

Description

Detect errors or detect errors and correct the tree life status evolution over the censuses. Inspired by the code of Nino Page package (ForestData::correct_alive() and .correct_alive_tree())

Usage

StatusCorrectionByTree(
  DataTree,
  PlotCensuses,
  InvariantColumns = c("Site", "GenusCor", "SpeciesCor", "FamilyCor",
    "ScientificNameCor"),
  DeathConfirmation = 2,
  UseSize = FALSE,
  AddRowsForForgottenCensuses = TRUE,
  DetectOnly = FALSE,
  RemoveRBeforeAlive = FALSE,
  RemoveRAfterDeath = FALSE
)

Arguments

DataTree

A dataset corresponding to a single tree's (1 IdTree/IdStem) measurements (data.frame or data.table) The LifeStatus column must be coded as: - TRUE = alive, - FALSE = dead, - NA = unseen

PlotCensuses

Census years for the plot in which the tree is (numeric or integer)

InvariantColumns

Vector with the names of the columns that are supposed to have always the same value for each measurement of the same tree (character). It is recommended to use the columns that have already been corrected, such as the columns containing the corrected botanical information.

DeathConfirmation

Number of times (censuses) needed for an unseen tree to be considered dead (numeric)

UseSize

Use the size presence as a witness of the living status of the tree (logical)

AddRowsForForgottenCensuses

TRUE: adds rows for forgotten censuses between 2 'Alive', FALSE: does not add any rows (logical)

DetectOnly

TRUE: Only detect errors, FALSE: detect and correct errors (logical)

RemoveRBeforeAlive

Do you want to delete the rows about the tree before it was seen alive for the 1st time? (logical)

RemoveRAfterDeath

After correction do you want to delete the rows concerning the tree after its death? (logical)

Details

  • if UseSize : if Diameter != NA -> Alive

  • Dead > Alive -> NA

  • add rows for the forgotten censuses between 2 'Alive' if chosen

  • Alive > Dead/NA > Alive -> Alive

  • Alive > NA > Dead -> NA

  • Alive > Dead > NA -> Dead

  • Alive > NA > NA: if DeathConfirmation > unseens -> NA if DeathConfirmation =< unseens -> Dead

Value

Fill the Comment column with error type informations. If DetectOnly = FALSE, add a LifeStatusCor column with the corrected tree life status.

Examples

library(data.table)
data(TestData)
Data <- TestData

# Wanted seq: Dead > Alive > NA > Dead > Alive > NA > NA > Dead > NA

DataTree <- Data[IdTree == "101623"]

AddR <- DataTree[2:5] # the rows to copy
AddR[, Year := c(2012:2015)] # the rows to add

DataTree <- rbindlist(list(DataTree, AddR)) # add rows

DataTree <- DataTree[order(Year)] # arrange years in ascending order

# Write the sequence
DataTree[, LifeStatus := c(FALSE, TRUE, NA, FALSE, TRUE, NA, NA, FALSE, NA)]

Rslt <- StatusCorrectionByTree(DataTree, PlotCensuses = c(2011:2021),
                               InvariantColumns = c("Site",
                                                    "Genus",
                                                    "Species",
                                                    "Family",
                                                    "ScientificName"))
setnames(Rslt, "LifeStatusCor", "LifeStatus_TreeDataCor")
LifeStatusCorrectionPlot(Rslt)


VincyaneBadouard/TreeData documentation built on Jan. 4, 2024, 2:56 a.m.