Closed lentinj closed 4 months ago
It does the job, great! Note that the two data extractions below both seem to work now. min and max lengths in the model are 3 and 21 cm but in the first case the data component length span 0:Inf. Are the two extractions really equivalent for the model? Should one of the two be preferred?
> si.ven.aco <- mfdb_sample_count(mdb, c('age'),
list(...,
age = mfdb_group('age3pl'=3:maxage))) [[1]]
> dimnames(g3_distribution_preview(si.ven.aco))
$length
[1] "0:Inf"
$age
[1] "2:10"
...
> si.ven.aco <- mfdb_sample_count(mdb, c('age','length'),
list(...,
age = mfdb_group('age3pl'=3:maxage))) [[1]]
> attributes(si.ven.aco)$length$all <- c(minlen,maxlen)
> dimnames(g3_distribution_preview(si.ven.aco))
$length
[1] "3:21"
$age
[1] "2:10"
...
Are the two extractions really equivalent for the model?
No, the former ignores length, whereas the latter filters the plus group.
A plus group is added by default to a stock:
> s <- g3_stock('s', seq(3, 21, 3))
> s__num <- g3_stock_instance(s, 100)
> s__num
length
3:6 6:9 9:12 12:15 15:18 18:21 21:Inf
100 100 100 100 100 100 100
Aggregating this into a "3:21" vector removes this plus group:
> s_noplus <- g3_stock('s_noplus', c(3, 21), open_ended = FALSE) ; s_noplus
g3_stock s_noplus with dimensions:
$length
[1] "3:21"
> g3_eval(~stock_iterate(s, stock_reshape(s_noplus, stock_ss(s__num))))
[1] 600
OTOH, a length group of "0:Inf" includes everything:
> s_inf <- g3_stock('s_inf', c(0,Inf), open_ended = FALSE) ; s_inf
g3_stock s_inf with dimensions:
$length
[1] "0:Inf"
> g3_eval(~stock_iterate(s, stock_reshape(s_inf, stock_ss(s__num))))
[1] 700
Should one of the two be preferred?
Ignoring the plus-group isn't ideal, but depending on your model the results of doing so may be insignificant.
Instead of removing length, you could also set the open_ended
option in mfdb_group. The data returned would be the same, but the option will follow through to gadget3 and result in "3:Inf".
@vbartolino would you mind giving this branch a go at some point and let me know if it helps fix your example #142?
If it helps, then I'll merge this.
Fixes #142 (well, hopefullly)