Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement weights argument for slab() #229

Closed
brownag opened this issue Jul 13, 2021 · 4 comments · Fixed by #259
Closed

implement weights argument for slab() #229

brownag opened this issue Jul 13, 2021 · 4 comments · Fixed by #259
Assignees

Comments

@brownag
Copy link
Member

brownag commented Jul 13, 2021

A planned feature for slab() is to (re-)support site-level weights. See #3

When specifying some dummy weights the following error message is issued

library(aqp)
#> This is aqp 1.30
#> 
#> Attaching package: 'aqp'
#> The following object is masked from 'package:stats':
#> 
#>     filter
data(sp1)
depths(sp1) <- id ~ top + bottom
slab(sp1, fm = ~ prop, weights = 1:length(sp1))
#> Error: weighted aggregation is not yet supported

Example use case:

  • component percent weighted averages from an SPC derived from one or more SSURGO mapunits worth of horizon data (containing multiple soil components).

See ncss-tech/soilDB#194 for some sample DMU record IDs for weighted average aggregation and validation against Web Soil Survey aggregation

@dylanbeaudette
Copy link
Member

dylanbeaudette commented Jul 14, 2021

Moving some specific content over from #3. It is on my list. I think that a full re-write based on data.table is in order. At the time (2016), I didn't have a viable alternative to split/apply/rbind or base::aggregate.

From #3

  1. not currently possible with aggregate() as it can only operate on vectors
  2. possible with other functions: https://stat.ethz.ch/pipermail/r-help/2003-June/035321.html
  3. switching to data.table may be required:
  4. split + lapply + parse list labels may be fast + flexible
    • split(d, list(d$g, d$h), drop=TRUE)
  5. pre-standardization of weights based on entire range of weights in collection, or within a slab?

@brownag
Copy link
Member Author

brownag commented Aug 18, 2022

Note to consider option of supplying weights as a character vector length 1 column name (implemented in #258), or as a vector equal in length to number of profiles.
In principle I think it would be possible to support a matrix of weights, and/or horizon level weights.

@dylanbeaudette
Copy link
Member

Note to consider option of supplying weights as a character vector length 1 column name (implemented in #258), or as a vector equal in length to number of profiles. In principle I think it would be possible to support a matrix of weights, and/or horizon level weights.

Yes: the original implementation (2008?) allowed for site-level or horizon-level weights. It wasn't entirely clear to me at the time how to implement horizon-level weighting into things like weighted SD over intervals > 1cm thickness.

I'd prefer that the updates as part of this issue and related PR implement site-level weighted first, via named column from site. Once the details of horizon-level weighting are determined, then I'd prefer to use a similar approach via named column from horizons.

@brownag
Copy link
Member Author

brownag commented Aug 19, 2022

I'd prefer that the updates as part of this issue and related PR implement site-level weighted first, via named column from site.

This is done

brownag added a commit that referenced this issue Aug 19, 2022
@brownag brownag mentioned this issue Aug 19, 2022
5 tasks
brownag added a commit that referenced this issue Aug 19, 2022
 - closes #229

 - NA_real_ for proper expectation of missing weights passed to base
   weighted.mean() (minimal custom slab function)
brownag added a commit that referenced this issue Aug 22, 2022
 - closes #229

 - NA_real_ for proper expectation of missing weights passed to base
   weighted.mean() (minimal custom slab function)
brownag added a commit that referenced this issue Aug 22, 2022
 - closes #229

 - NA_real_ for proper expectation of missing weights passed to base
   weighted.mean() (minimal custom slab function)
brownag added a commit that referenced this issue Aug 22, 2022
 - closes #229

 - NA_real_ for proper expectation of missing weights passed to base
   weighted.mean() (minimal custom slab function)
brownag added a commit that referenced this issue Aug 24, 2022
 - closes #229

 - NA_real_ for proper expectation of missing weights passed to base
   weighted.mean() (minimal custom slab function)
brownag added a commit that referenced this issue Aug 24, 2022
 - closes #229

 - NA_real_ for proper expectation of missing weights passed to base
   weighted.mean() (minimal custom slab function)
brownag added a commit that referenced this issue Sep 12, 2022
 - closes #229

 - NA_real_ for proper expectation of missing weights passed to base
   weighted.mean() (minimal custom slab function)
brownag added a commit that referenced this issue Oct 13, 2022
* Add an explicit tests of overlapping horizons

* Fix dice() link in segment() docs

* Updates to `slab()`
 - closes #229

 - NA_real_ for proper expectation of missing weights passed to base
   weighted.mean() (minimal custom slab function)

* `slab()`: pass thru `byhz`

* Slab tests

* Add internal replacement genSlabLabels for testing

* cleanup

* Add `suppressWarnings()` for `data.table::melt()`

* Fix errors from misspecified formula

* standardize data.frame conversion

* use alternate name to avoid NSE collision with `"wt"`

* Add comments for .genSlabLabels2

* Fix segment docs

* Add comments for data.table weighted slab aggregation

* convert to data.table
 - need to refactor slab functions so that a single call is possible for weighted/unweighted/numeric/factor

* Fix cpm arg in donttest perturb() example

* Docs, removing old TODO

* Fix for dice() related to SPCs with horizon designation name set

* Update slab-factor-eval.R

* Add slab-factor-2x.rds

* `dice()`: fillHzGaps recalculates hzID and sets it as `hzidname()`
 - need to recalculate local var to avoid errors

* slab: update cpm=2 comparison

* slab: add cpm=2 comparison
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants