makeStrata: Make and assign strata based on two input columns, typically...

View source: R/makeStrata.R

makeStrataR Documentation

Make and assign strata based on two input columns, typically at least one is numeric

Description

Make and assign strata based on two input attributes and some parameters functions are makeStrata and assignStrata

Usage

makeStrata(
  data,
  x1 = "PlotStrata1",
  x2 = "Elev.P95",
  split_x1 = c("qt", "eq"),
  split_x2 = c("qt", "eq"),
  nest_x2 = T,
  n1 = 10,
  n2 = 10,
  type_x1 = c("factor", "numeric")[1],
  type_x2 = c("numeric", "factor")[1],
  minRecs = 7,
  precision = 0,
  collapse = T
)

Arguments

data

input data

x1

name of input x field

x2

name of input y field

split_x1

how to split - equal interval or quantile based

split_x2

how to split - equal interval or quantile based

nest_x2

should x2 be nested in x1, or should x1 and x2 be split independently

n1

number of strata for x1

n2

number of strata for x2

type_x1

is x1 numeric or factor

type_x2

is x2 numeric or factor

minRecs

what is the minimum number of records in a stratum before collapse

precision

what precision is retained for cutting numeric values into strata

Details

<Delete and Replace>


Revision History

1.0 2019 01 24 created
1.1 2020 06 25 updated to allow more complex inputs

Value

makeStrata returns a data.frame of strata boundaries assignStrata takes a data.frame and appends a column with the stratum name for each record

Author(s)

Jacob Strunk <Jstrunk@fs.fed.us>

Examples




      #prepare pseudo data
      n=500
      hts = sample(1:150,n,T)
      dbhs = abs(hts/5 + rnorm(#' )*2)
      dat_test = data.frame(height = hts , dbh = dbhs, height_cat = cut(hts,10) , dbh_cat = cut(dbhs,10))
      plot(dbhs,hts)

      #example 1 factor and numeric
      str_test = makeStrata(
        dat_test
        , x1="height_cat"
        , x2="dbh"
        , split_x1 =c("qt","eq")[1]
        , split_x2 =c("qt","eq")[1]
        , nest_x2 =  T
        , n1 = 10
        , n2 = 10
        , type_x1 = "factor"
        , type_x2 = "numeric"
        , minRecs = 7
        , precision = 0
      )


      res = assignStrata(
       str_test
        ,dat_test
      )

      res$stratum

      summary(lm(height ~ dbh , data = res))
      summary(lm(height ~ dbh_cat , data = res))
      summary(lm(height ~ stratum , data = res))

      #example 2 numeric and numeric
      str_test1 = makeStrata(
        dat_test
        , x1="height"
        , x2="dbh"
        , split_x1 =c("qt","eq")[1]
        , split_x2 =c("qt","eq")[1]
        , nest_x2 =  T
        , n1 = 10
        , n2 = 10
        , type_x1 = "numeric"
        , type_x2 = "numeric"
        , minRecs = 7
        , precision = 0
      )

      res1 = assignStrata(
        str_test1
        ,dat_test
      )

      #example 3 numeric and factor
      str_test2 = makeStrata(
        dat_test
        , x1="height"
        , x2="dbh_cat"
        , split_x1 =c("qt","eq")[1]
        , split_x2 =c("qt","eq")[1]
        , nest_x2 =  T
        , n1 = 10
        , n2 = 10
        , type_x1 = "numeric"
        , type_x2 = "factor"
        , minRecs = 7
        , precision = 0
      )

      res2 = assignStrata(
        str_test2
        ,dat_test
      )





jstrunk001/RSForInvt documentation built on April 18, 2022, 11:03 p.m.