From 87d6b55588fd52fc423406c7a55ad429b6d878f2 Mon Sep 17 00:00:00 2001 From: Robert Nuske Date: Fri, 14 Feb 2020 16:35:42 +0100 Subject: [PATCH 1/5] remove superfluous help pages --- man/hello.Rd | 12 ------------ man/rcpp_hello.Rd | 13 ------------- 2 files changed, 25 deletions(-) delete mode 100644 man/hello.Rd delete mode 100644 man/rcpp_hello.Rd diff --git a/man/hello.Rd b/man/hello.Rd deleted file mode 100644 index 0fa7c4b..0000000 --- a/man/hello.Rd +++ /dev/null @@ -1,12 +0,0 @@ -\name{hello} -\alias{hello} -\title{Hello, World!} -\usage{ -hello() -} -\description{ -Prints 'Hello, world!'. -} -\examples{ -hello() -} diff --git a/man/rcpp_hello.Rd b/man/rcpp_hello.Rd deleted file mode 100644 index 9084505..0000000 --- a/man/rcpp_hello.Rd +++ /dev/null @@ -1,13 +0,0 @@ -\name{rcpp_hello} -\alias{rcpp_hello} -\title{Hello, Rcpp!} -\usage{ -rcpp_hello() -} -\description{ -Returns an \R \code{list} containing the character vector -\code{c("foo", "bar")} and the numeric vector \code{c(0, 1)}. -} -\examples{ -rcpp_hello() -} From dccf5ced46027939c03039a93badf84bde508927 Mon Sep 17 00:00:00 2001 From: Robert Nuske Date: Fri, 14 Feb 2020 16:42:42 +0100 Subject: [PATCH 2/5] make global variables known to check --- DESCRIPTION | 3 ++- R/fisim_package.R | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index f540985..c40ae97 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,5 +20,6 @@ Imports: maptools, spatstat, RANN, - rgeos + rgeos, + utils RoxygenNote: 6.0.1 diff --git a/R/fisim_package.R b/R/fisim_package.R index 3f946ad..aa0963a 100644 --- a/R/fisim_package.R +++ b/R/fisim_package.R @@ -7,3 +7,9 @@ #' @docType package #' @import data.table spatstat sp rgeos NULL + +# avoid R CMD check warnings due to global variables +utils::globalVariables(c("N", "d", "dbh", "ef", "ef_alt1", "ef_alt2", "f_edge", + "id_point", "id_sample", "id_stem", "id_tree", + "is_edge", "n", "n_corr", "s", "variable", "x_s", + "x_tree", "x_wt", "y_s", "y_tree", "y_wt")) From 450a220ec95818d3d08fc5e301156158a167f85e Mon Sep 17 00:00:00 2001 From: Robert Nuske Date: Fri, 14 Feb 2020 17:06:42 +0100 Subject: [PATCH 3/5] add required package stats to DESCRIPTION and clean up Depends and Imports --- DESCRIPTION | 8 +++++--- R/estimation_design.R | 2 +- R/sampling_design.R | 8 ++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c40ae97..7f59ba0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,12 +1,12 @@ Package: fisim Type: Package Title: Forest Inventory Simulator (fisim) is a package for simulating response - and samplign designs common in forest inventories. + and samplign designs common in forest inventories Version: 0.1.0 Author: Sebastian Schnell, Henning Aberle Maintainer: Sebastian Schnell URL: http://github.com/sebschnell/ -Description: The main purpose of the package is to illustrate basic statisitcal +Description: The main purpose of the package is to illustrate basic statistical principles of surveys of environmental resources with a focus on forest inventories. The main intention is to use the package in combination with a Shiny application to assist teaching in bachelor and master courses on forest @@ -14,12 +14,14 @@ Description: The main purpose of the package is to illustrate basic statisitcal License: What license is it under? Encoding: UTF-8 LazyData: true -Depends: data.table, sp, maptools, spatstat, rgeos +Depends: R (>= 2.15.1) Imports: + data.table, sp, maptools, spatstat, RANN, rgeos, + stats, utils RoxygenNote: 6.0.1 diff --git a/R/estimation_design.R b/R/estimation_design.R index 5c936d9..2241f4d 100644 --- a/R/estimation_design.R +++ b/R/estimation_design.R @@ -26,7 +26,7 @@ est_srs <- function(point_data, est_col = NULL) { dt_est <- point_data$data[, list(est_appr = names(.SD), y_hat = sapply(.SD, mean), - v_hat = sapply(.SD, var)/.N), + v_hat = sapply(.SD, stats::var)/.N), by = list(id_sample, variable), .SDcols = est_col]; return(dt_est); diff --git a/R/sampling_design.R b/R/sampling_design.R index a5d8cf2..7a9cf05 100644 --- a/R/sampling_design.R +++ b/R/sampling_design.R @@ -69,8 +69,8 @@ xy_sample_random <- function(sp_poly, n, M = 1) { y <- unlist(lapply(tri$tiles, function(x) x$bdry[[1]]$y)); s <- sample(length(a), n*M, prob = w, replace = TRUE); - r1 <- runif(n*M); - r2 <- runif(n*M); + r1 <- stats::runif(n*M); + r2 <- stats::runif(n*M); n_vtc <- 3; # Number of vertices in a triangle p4_x <- (1 - r1)*x[(s*n_vtc - 2)] + r1*x[(s*n_vtc - 1)]; @@ -137,9 +137,9 @@ xy_sample_regular <- function(sp_poly, n, M = 1, cell_size = NULL, random_rot = r_start <- 0L; r_end <- 0L; if (random_rot) { - alpha <- runif(M, min = 0, max = pi); + alpha <- stats::runif(M, min = 0, max = pi); } - u_d <- cbind(runif(M)*d, runif(M)*d); + u_d <- cbind(stats::runif(M)*d, stats::runif(M)*d); for (m in seq.int(M)) { # Enlarge grid to account for possible rotation x <- seq(1.5*min(e_cent["x", "min"]) + u_d[m, 1], 1.5*max(e_cent["x", "max"]), d); From 0a1dbf6afea9ed6d7849d1b492bdf512a9ce7e66 Mon Sep 17 00:00:00 2001 From: Robert Nuske Date: Fri, 14 Feb 2020 17:23:42 +0100 Subject: [PATCH 4/5] fix inconsistencies between variable names in function and documentation --- DESCRIPTION | 2 +- R/class_definitions.R | 10 ++-------- R/estimation_design.R | 2 +- R/utilities.R | 10 +++++----- man/est_srs.Rd | 6 +++--- man/extract_data.Rd | 4 ++-- man/fisim.Rd | 1 - man/response.Rd | 13 ++----------- man/sum_data.Rd | 2 +- man/sum_ef.Rd | 2 +- man/sum_k_tree.Rd | 2 +- 11 files changed, 19 insertions(+), 35 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7f59ba0..5bbcc1d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,4 +24,4 @@ Imports: rgeos, stats, utils -RoxygenNote: 6.0.1 +RoxygenNote: 7.0.2 diff --git a/R/class_definitions.R b/R/class_definitions.R index 8ac8a90..af30edb 100644 --- a/R/class_definitions.R +++ b/R/class_definitions.R @@ -219,20 +219,14 @@ is.tree_pop <- function(x) { #' #' @param data A \code{\link[data.table]{data.table}} object holding identifiers #' for the sample and respective point locations and row indices that indicate -#' which population elements are selected into the sample. +#' which population elements are selected into the sample. data must have +#' the columns "id_sample", "id_point", "s" and "ef". #' @param r_design A \code{character} string indicating the type of the response #' design. One of the following: "fixed_area", "k_tree", "angle_count". #' @param r_design_parm A response design specific parameter of type #' \code{numeric}. For "fixed_area" the plot radius in meter; for "k_tree" the #' number of trees closest to the sample location; for "angle_count" the basal #' area factor. -#' @param ef The expansion factor, i.e., the factor that is used to prorate tree -#' attributes to per hectare values (the inverse of the inclusion -#' probabilities). Provided by the particular response design functions. -#' @param ef_alt1 Alternative expansion factor that may be applied when using -#' k-tree sampling. -#' @param ef_alt2 A third alternative expansion factor approximation for k-tree -#' sampling #' #' @details The \code{\link[data.table]{data.table}} object (\code{data}) should #' have the following columns: diff --git a/R/estimation_design.R b/R/estimation_design.R index 2241f4d..3641881 100644 --- a/R/estimation_design.R +++ b/R/estimation_design.R @@ -1,6 +1,6 @@ #' Simple random sampling estimator of population means #' -#' @param data A data.table object with plot-level information of stand +#' @param point_data A data.table object with plot-level information of stand #' characteristics as coming from the \code{sum_data} function. #' @param est_col A character vector of column names for which estimates are #' produced. Used when there is more than one way to expand observations from diff --git a/R/utilities.R b/R/utilities.R index fec1e68..bdcfe65 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -1,8 +1,8 @@ #' Helper function to extract population elements into a sample using a list of #' indices #' -#' @param dt_pop The population from which to extract sampled elements. -#' @param s An integer matrix where rows represent sample locations and columns +#' @param tree_pop The population from which to extract sampled elements. +#' @param response An integer matrix where rows represent sample locations and columns #' represent indices of the trees in \code{dt_pop} that are selected at the #' individual sample locations. Zeroes are used to indicate no neighbours and #' to ensure a rectangular data format. @@ -42,7 +42,7 @@ extract_data <- function(tree_pop, response) { #' #' @param tree_sample A \code{\link{tree_sample}} object as coming from #' the \code{\link{extract_data}} function. -#' @param target_var A character vector of variable names which should be +#' @param target_vars A character vector of variable names which should be #' summarized at the plot level #' #' @return A data.table object with stand characteristics at the plot level. @@ -88,7 +88,7 @@ sum_data <- function(tree_sample, target_vars) { #' #' @param tree_sample A \code{\link{tree_sample}} object as coming from the #' \code{\link{extract_data}} function. -#' @param target_var A character vector of variable names which should be +#' @param target_vars A character vector of variable names which should be #' summarized at the plot level #' #' @details For k-tree sampling, individual tree inlcusion probabilities can @@ -157,7 +157,7 @@ sum_k_tree <- function(tree_sample, target_vars) { #' #' @param tree_sample A \code{\link{tree_sample}} object as coming from #' the \code{\link{extract_data}} function. -#' @param target_var A character vector of variable names which should be +#' @param target_vars A character vector of variable names which should be #' summarized at the plot level #' #' @return A data.table object with stand characteristics at the plot level. diff --git a/man/est_srs.Rd b/man/est_srs.Rd index da97fe4..259726f 100644 --- a/man/est_srs.Rd +++ b/man/est_srs.Rd @@ -7,12 +7,12 @@ est_srs(point_data, est_col = NULL) } \arguments{ +\item{point_data}{A data.table object with plot-level information of stand +characteristics as coming from the \code{sum_data} function.} + \item{est_col}{A character vector of column names for which estimates are produced. Used when there is more than one way to expand observations from individual sample locations.} - -\item{data}{A data.table object with plot-level information of stand -characteristics as coming from the \code{sum_data} function.} } \value{ A data.table object with mean and variance estimates for the target diff --git a/man/extract_data.Rd b/man/extract_data.Rd index 1177ece..d558f2c 100644 --- a/man/extract_data.Rd +++ b/man/extract_data.Rd @@ -8,9 +8,9 @@ indices} extract_data(tree_pop, response) } \arguments{ -\item{dt_pop}{The population from which to extract sampled elements.} +\item{tree_pop}{The population from which to extract sampled elements.} -\item{s}{An integer matrix where rows represent sample locations and columns +\item{response}{An integer matrix where rows represent sample locations and columns represent indices of the trees in \code{dt_pop} that are selected at the individual sample locations. Zeroes are used to indicate no neighbours and to ensure a rectangular data format.} diff --git a/man/fisim.Rd b/man/fisim.Rd index 285ea6f..2057f3d 100644 --- a/man/fisim.Rd +++ b/man/fisim.Rd @@ -3,7 +3,6 @@ \docType{package} \name{fisim} \alias{fisim} -\alias{fisim-package} \title{fisim} \description{ Forest Inventory Simulator (fisim) is a package for simulating response and diff --git a/man/response.Rd b/man/response.Rd index b69086a..9d17670 100644 --- a/man/response.Rd +++ b/man/response.Rd @@ -9,7 +9,8 @@ response(data, r_design, r_design_parm) \arguments{ \item{data}{A \code{\link[data.table]{data.table}} object holding identifiers for the sample and respective point locations and row indices that indicate -which population elements are selected into the sample.} +which population elements are selected into the sample. data must have +the columns "id_sample", "id_point", "s" and "ef".} \item{r_design}{A \code{character} string indicating the type of the response design. One of the following: "fixed_area", "k_tree", "angle_count".} @@ -18,16 +19,6 @@ design. One of the following: "fixed_area", "k_tree", "angle_count".} \code{numeric}. For "fixed_area" the plot radius in meter; for "k_tree" the number of trees closest to the sample location; for "angle_count" the basal area factor.} - -\item{ef}{The expansion factor, i.e., the factor that is used to prorate tree -attributes to per hectare values (the inverse of the inclusion -probabilities). Provided by the particular response design functions.} - -\item{ef_alt1}{Alternative expansion factor that may be applied when using -k-tree sampling.} - -\item{ef_alt2}{A third alternative expansion factor approximation for k-tree -sampling} } \value{ An object of class \code{response}. A named list with the following diff --git a/man/sum_data.Rd b/man/sum_data.Rd index 92036ad..7b99ad0 100644 --- a/man/sum_data.Rd +++ b/man/sum_data.Rd @@ -10,7 +10,7 @@ sum_data(tree_sample, target_vars) \item{tree_sample}{A \code{\link{tree_sample}} object as coming from the \code{\link{extract_data}} function.} -\item{target_var}{A character vector of variable names which should be +\item{target_vars}{A character vector of variable names which should be summarized at the plot level} } \value{ diff --git a/man/sum_ef.Rd b/man/sum_ef.Rd index f4c1a8f..cb12e35 100644 --- a/man/sum_ef.Rd +++ b/man/sum_ef.Rd @@ -10,7 +10,7 @@ sum_ef(tree_sample, target_vars) \item{tree_sample}{A \code{\link{tree_sample}} object as coming from the \code{\link{extract_data}} function.} -\item{target_var}{A character vector of variable names which should be +\item{target_vars}{A character vector of variable names which should be summarized at the plot level} } \value{ diff --git a/man/sum_k_tree.Rd b/man/sum_k_tree.Rd index d2770c5..a78d205 100644 --- a/man/sum_k_tree.Rd +++ b/man/sum_k_tree.Rd @@ -10,7 +10,7 @@ sum_k_tree(tree_sample, target_vars) \item{tree_sample}{A \code{\link{tree_sample}} object as coming from the \code{\link{extract_data}} function.} -\item{target_var}{A character vector of variable names which should be +\item{target_vars}{A character vector of variable names which should be summarized at the plot level} } \value{ From 586fa6bbb57e63284a1ecbc9df835d913de619ae Mon Sep 17 00:00:00 2001 From: Robert Nuske Date: Fri, 14 Feb 2020 17:45:42 +0100 Subject: [PATCH 5/5] add basic documentation for dataset ramdom_tree --- R/data.R | 22 ++++++++++++++++++++++ man/random_tree.Rd | 28 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 man/random_tree.Rd diff --git a/R/data.R b/R/data.R index 791560f..083c1a7 100644 --- a/R/data.R +++ b/R/data.R @@ -43,3 +43,25 @@ #' how often a tree is counted during estimation correcting for edge #' effects, unitless}} "hberg_beech" + + +#' Full census of a stand of random trees +#' +#' A dataset containing tree stem locations and other attributes of 20000 trees +#' randomly generated (by ...) on a 1000m by 500m rectangular plot. +#' +#' @format An object of class \code{\link{tree_pop}}. The data contains 20000 +#' rows and 9 columns: \describe{ +#' \item{id_tree}{Stem number - one tree can have mulitple stems} +#' \item{id_stem}{Tree number - repetitions possible due to multiple stems} +#' \item{x_tree}{Relative position of the stem center in x-direction} +#' \item{y_tree}{Relative position of the stem center in y-direction} +#' \item{is_dead}{Was the tree alive or dead?} +#' \item{dbh}{Diameter of the stem measured at breast height (1.3m) in cm} +#' \item{ba}{Cross-sectional area of the stem at breast height in square +#' meters} +#' \item{n}{Stem count - helper variable for stem number estimation, unitless} +#' \item{f_edge}{Edge factor - helper variable for edge_correction, indicates +#' how often a tree is counted during estimation correcting for edge +#' effects, unitless}} +"random_tree" diff --git a/man/random_tree.Rd b/man/random_tree.Rd new file mode 100644 index 0000000..2dd8f78 --- /dev/null +++ b/man/random_tree.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{random_tree} +\alias{random_tree} +\title{Full census of a stand of random trees} +\format{An object of class \code{\link{tree_pop}}. The data contains 20000 + rows and 9 columns: \describe{ + \item{id_tree}{Stem number - one tree can have mulitple stems} + \item{id_stem}{Tree number - repetitions possible due to multiple stems} + \item{x_tree}{Relative position of the stem center in x-direction} + \item{y_tree}{Relative position of the stem center in y-direction} + \item{is_dead}{Was the tree alive or dead?} + \item{dbh}{Diameter of the stem measured at breast height (1.3m) in cm} + \item{ba}{Cross-sectional area of the stem at breast height in square + meters} + \item{n}{Stem count - helper variable for stem number estimation, unitless} + \item{f_edge}{Edge factor - helper variable for edge_correction, indicates + how often a tree is counted during estimation correcting for edge + effects, unitless}}} +\usage{ +random_tree +} +\description{ +A dataset containing tree stem locations and other attributes of 20000 trees +randomly generated (by ...) on a 1000m by 500m rectangular plot. +} +\keyword{datasets}