make_strata: Make and assign strata based on two input columns

View source: R/make_strata.R

make_strataR Documentation

Make and assign strata based on two input columns

Description

Make and assign strata based on two input attributes and some parameters functions are make_strata and assign_strata

Usage

make_strata(
  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],
  min_recs = 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

min_recs

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

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

Author(s)

Jacob Strunk <jacob@some.domain>

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 = make_strata(
        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"
        , min_recs = 7
        , precision = 0
      )


      res = assign_strata(
       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 = make_strata(
        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"
        , min_recs = 7
        , precision = 0
      )

      res1 = assign_strata(
        str_test1
        ,dat_test
      )

      #example 3 numeric and factor
      str_test2 = make_strata(
        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"
        , min_recs = 7
        , precision = 0
      )

      res2 = assign_strata(
        str_test2
        ,dat_test
      )




jstrunk001/RForInvt documentation built on April 17, 2025, 5:02 p.m.