
magComp: model fitting, prediction, and summaries
magComp-package.RdBayesian magnitude-composition models for fixed-area stem counts and
point-sampling basal area. A negative-binomial model describes the total
count, and multinomial allocation distributes that count among categories.
Users choose one categorical variable or two in a conditional allocation;
neither their names nor their conditioning order is tied to a forestry response.
Models can include regression, group effects, spatial effects, and composition
factors, with smoothing across ordered categories. Fit either component alone
by setting the other formula to NULL; the existing nested composition
structure remains available without magnitude.
Getting started
The website articles simulate data and illustrate magnitude, composition, and full models using forest inventory examples. Their Quarto sources and HTML previews are in the source repository; the articles are not installed with the package.
- Prepare data
Use
magCompDatawith afixedAreaorpointSamplingdesign. Each sampling unit has total counts, counts by one category, or counts by two crossed categories. Standalone composition does not require a sampling design.- Specify and fit a model
Use
magComp. For two categories,magCompCompositionspecifies the leading allocation and the conditional child allocation. Formula syntax is described in magCompTerms. Set priors withmagCompPriors, smoothing withmagCompSmooth, and MCMC controls withmagCompControl.- Inspect settings
Use
magCompSettingsfor resolved priors, parameter constraints, and editable starting values. UsemagCompStartingto extract starts from a previous fit.- Check the chains
Use
summaryandplot. Both usesamplesand support individual effects and combined coefficients through theirtypeargument.spatialDiagnosticssummarizes spatial parameters.samplesextracts all retained parameter draws.- Obtain fitted values and predictions
Use
fittedat observed units andpredictat new units. Both offer expected quantities or simulated observations. magCompPrediction explains the returned quantities and dimensions.- Summarize and assess
Use
summaryon stored prediction draws for means and intervals. UsestandSummaryto aggregate stored expected or observation density draws with represented land-area weights,ppcSummaryto compare observed and replicate counts, andmagCompCVfor cross-validation predictions.
Call generic functions such as summary(fit), plot(fit),
fitted(fit), and
predict(fit, newdata);
R selects the appropriate method. magCompNotation and
magCompPrediction are explanatory help topics, not functions.
Technical document
The Methods and Implementation Details
guide gives the model equations, notation, priors, full conditional and
Metropolis updates, numerical solvers, and prediction calculations.
Its source and PDF are maintained in
dev/modeling_and_software_details/ in the source repository.
Help pages refer to its section titles so those references remain useful
when equation and section numbers change.