This function compares for each plot (and other provided variables) the differences between periods/years for the column names given in parameter measure_vars. It gives results for differences between subsequent measures (based on period) and between the last and the first measure. All column names of the dataset that are not added to parameter measure_vars, are considered as grouping variables, except for period. If the result is not as expected, please verify that the dataset only consists of grouping variables, variables added to measure_vars and period.

compare_periods_per_plot(dataset, measure_vars, replace_na_in_vars = NA)

Arguments

dataset

dataframe with values for each period, plot and year, in addition to grouping variables and measure_vars

measure_vars

column names of variables that should be compared between periods (including year)

replace_na_in_vars

column names of variables (measure_vars) in which NA should be replaced by 0 in case at least one record is measured in the same plot_id in the same period. Similar to function add_zeros(), this argument allows to add zeros to end up with records for all species or heights in which measures were taken, even if this specific species or height was absent in the period (and thus the tree volume or number of trees being 0 for all periods and plots in which observations were done). Care should be taken to use this argument: it should only be used for aggregated results of measures (e.d. tree volume, tree number,...) and not for measures of individual trees (which will lead to unwanted additional records) or id's referring to coded tables. It is useless to use this argument if only one result per plot is given.

Value

dataframe with columns plot, year_diff, n_years, grouping variables and differences between periods for each column of measure_vars

Examples

library(forrescalc)
library(dplyr)
treenr_by_plot <-
  read_forresdat_table(tablename = "dendro_by_plot") %>%
  select(
    period, year, plot_id, number_of_tree_species, number_of_trees_ha
  ) %>%
  distinct()
#> Rows: 17 Columns: 16
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr  (1): plottype
#> dbl (15): plot_id, year, period, number_of_tree_species, number_of_trees_ha,...
#> 
#>  Use `spec()` to retrieve the full column specification for this data.
#>  Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> Rows: 17 Columns: 13
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (2): forest_reserve, plottype
#> dbl (4): plot_id, period, survey_number, year_dendro
#> lgl (7): survey_trees, survey_deadw, survey_veg, survey_reg, game_impact_veg...
#> 
#>  Use `spec()` to retrieve the full column specification for this data.
#>  Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> Warning: The dataset only contains presence data and lacks zero observations (except for 1 observation per plot_id and period to indicate that observations are done).  Please use function add_zeros() to add zero observations when needed.
compare_periods_per_plot(
  treenr_by_plot, c("year", "number_of_tree_species", "number_of_trees_ha")
)
#> # A tibble: 5 × 6
#>   plot_id year_diff   period_diff n_year number_of_tree_species_diff
#>     <dbl> <chr>       <chr>        <dbl>                       <dbl>
#> 1     204 2000 - 2011 1_2             11                           0
#> 2    2006 2000 - 2010 1_2             10                           0
#> 3     101 2002 - 2012 1_2             10                          -1
#> 4    1005 2006 - 2016 1_2             10                           0
#> 5    2006 2010 - 2020 2_3             10                           0
#> # ℹ 1 more variable: number_of_trees_ha_diff <dbl>