tidy() lists the estimates of a chemometric model in a long tibble, and
glance() summarizes the model in a one-row tibble, following the
conventions of the broom package. Through parsnip, they also apply to the
fitted models and workflows of the "rsimpls", "lts", "rsimca" and
"mcd" engines.
Usage
# S3 method for class 'specproc_robpca'
tidy(x, matrix = "eigenvalues", ...)
# S3 method for class 'specproc_robpca'
glance(x, ...)
# S3 method for class 'specproc_rsimpls'
tidy(x, matrix = "coefficients", ...)
# S3 method for class 'specproc_rsimpls'
glance(x, ...)
# S3 method for class 'specproc_rpcr'
tidy(x, matrix = "coefficients", ...)
# S3 method for class 'specproc_rpcr'
glance(x, ...)
# S3 method for class 'specproc_lts'
tidy(x, conf.int = FALSE, conf.level = 0.95, ...)
# S3 method for class 'specproc_lts'
glance(x, ...)
# S3 method for class 'specproc_rsimca'
tidy(x, ...)
# S3 method for class 'specproc_rsimca'
glance(x, ...)
# S3 method for class 'specproc_robust_da'
tidy(x, ...)
# S3 method for class 'specproc_robust_da'
glance(x, ...)
# S3 method for class 'specproc_opls'
tidy(x, matrix = "coefficients", ...)
# S3 method for class 'specproc_opls'
glance(x, ...)
# S3 method for class 'specproc_som'
tidy(x, ...)
# S3 method for class 'specproc_som'
glance(x, ...)
# S3 method for class 'specproc_wavelength_selection'
tidy(x, ...)
# S3 method for class 'specproc_wavelength_selection'
glance(x, ...)
# S3 method for class 'specproc_nas'
tidy(x, ...)
# S3 method for class 'specproc_nas'
glance(x, ...)
# S3 method for class 'specproc_domain'
tidy(x, ...)
# S3 method for class 'specproc_domain'
glance(x, ...)Arguments
- x
An object returned by
robpca(),rospca(),macropca(),cellpca(),rsimpls(),rpcr(),lts_fit(),rsimca(),robust_da(),opls(),som(),select_wavelengths(),nas()orapplicability_domain().- matrix
The table to return (see Details).
- ...
Not used.
- conf.int
A logical: add the confidence interval (
FALSE, default).- conf.level
The confidence level of the interval. Default is 0.95.
Details
tidy() returns, choosing the table with matrix when a model has
several:
robust PCA (
robpca(),rospca(),macropca(),cellpca()):"eigenvalues"(default), one row per componentPCwith itseigenvalueandstd.dev;"loadings", thevalueof each variable (column) on eachPC;"scores", thevalueof each observation (row) on eachPC, astidy()of aprcompobject in broom (whose names of the tables are also accepted, such as"rotation"and"x");rsimpls()andrpcr():"coefficients"(default), theestimateof eachterm(the intercept and the variables) for eachresponse, in the units of the responses;"components", the robustr.squaredand thermseof the models with 1 toncomp_maxcomponents (ncomp);"loadings"and"scores", as for robust PCA;lts_fit(): theterm,estimate,std.error,statisticandp.valueof the reweighted least-squares fit, and, withconf.int = TRUE, its confidence interval (conf.low,conf.high);rsimca()androbust_da(): one row perclass, with itsprior, the numbernof its regular observations and their misclassification rateerror, and, for RSIMCA, its number of componentsncompand the cutoffs of the score and orthogonal distances (cutoff.sd,cutoff.od);opls():"coefficients"(default), theestimateof eachterm(variable) with itsvipandortho.vip;"components", the explained variancesr2x,r2yandq2of each component, their cumulative values (r2x.cum, ...) and theirsignificance;som(): one row perunitof the map, with itsrowandcolin the grid, its position (x,y), the numbernof observations it represents and their mean quantization errorqe;select_wavelengths(): one row per variable (term), with itsimportance, whether it isselected, and, for iPLS, itsinterval;nas(): the regression vector, theestimateof eachterm;applicability_domain(): one row per componentPCof the PCA, with itsstd.dev,percentof the variance andcumulativepercent (as fractions).
glance() returns the number of observations nobs and of variables
nvar, and:
robust PCA: the number of components
ncomp,h,alpha, the cutoffscutoff.sdandcutoff.od, the numbers ofn.good.leverage,n.orthogonal.outlierandn.bad.leverageobservations, the number offlagged.cells(MacroPCA and cellPCA) and themethod;rsimpls()andrpcr():ncomp,ncomp_max,h,alpha, the robustr.squared, the robust scale of the residualssigma(one response), the numbers ofn.good.leverage,n.vertical.outlierandn.bad.leverageobservations, themethodand, for RPCR, theregression;lts_fit(): the robustr.squared, the robust scale of the residualssigma,df.residual,alphaand the number ofn.outliers(weight 0 in the reweighted fit);rsimca()androbust_da(): the number ofn.classes, the overall misclassification rateerror,alpha, the number of observations left out (n.outliers; for RSIMCA, those outlying for all classes) and themethod;opls(): the numbers of predictive and orthogonal components (ncomp,ncomp.ortho),r2x.cum,r2y.cum,q2.cum,rmseeand, after a permutation test, its p-valuesp.r2yandp.q2;som(): the number ofn.units, thetopology, thequantization.errorandtopographic.errorof the map, the number ofn.novelobservations (beyond the cutoff of the quantization error), theepochsand whether the map isrobust;select_wavelengths(): themethod,ncomp, the number of selected variablesn.selected,robust, thethresholdand, for iPLS, thermsecvof the final model;nas(): themethod,ncompand the figures of merit (sensitivity,selectivityand, with a noise level,analytical.sensitivity,lodandloq);applicability_domain(): the number of componentsncomp, the varianceexplained, theconf.leveland the limitst2.limitandq.limit.
See also
specproc-tidy for the fits, calibrations and plasma diagnostics
Examples
data(forageLIBS)
wl <- as.numeric(names(forageLIBS[-(1:14)]))
spectra <- forageLIBS[-(1:14)][, wl > 380 & wl < 430]
set.seed(1)
fit <- rsimpls(spectra[1:300, ], forageLIBS$Ca[1:300], ncomp = 4)
tidy(fit, matrix = "components")
#> # A tibble: 10 × 3
#> ncomp r.squared rmse
#> <int> <dbl> <dbl>
#> 1 1 0.211 0.141
#> 2 2 0.491 0.113
#> 3 3 0.689 0.0885
#> 4 4 0.761 0.0776
#> 5 5 0.762 0.0775
#> 6 6 0.768 0.0765
#> 7 7 0.767 0.0765
#> 8 8 0.767 0.0766
#> 9 9 0.767 0.0765
#> 10 10 0.775 0.0753
glance(fit)
#> # A tibble: 1 × 12
#> nobs nvar ncomp ncomp_max h alpha r.squared sigma n.good.leverage
#> <int> <int> <int> <int> <int> <dbl> <dbl> <dbl> <int>
#> 1 300 594 4 10 225 0.75 0.738 0.0918 39
#> # ℹ 3 more variables: n.vertical.outlier <int>, n.bad.leverage <int>,
#> # method <chr>
# the regression vector, one row per wavelength
head(tidy(fit))
#> # A tibble: 6 × 3
#> response term estimate
#> <chr> <chr> <dbl>
#> 1 y (Intercept) 1.61
#> 2 y 380.011254 -0.000000637
#> 3 y 380.096143 -0.00000117
#> 4 y 380.202312 -0.000000911
#> 5 y 380.285294 -0.000000907
#> 6 y 380.3682761 -0.00000108
pca <- robpca(spectra, ncomp = 3)
tidy(pca)
#> # A tibble: 3 × 3
#> PC eigenvalue std.dev
#> <int> <dbl> <dbl>
#> 1 1 786105711. 28038.
#> 2 2 54636943. 7392.
#> 3 3 39024510. 6247.
glance(pca)
#> # A tibble: 1 × 12
#> nobs nvar ncomp h alpha cutoff.sd cutoff.od n.good.leverage
#> <int> <int> <int> <int> <dbl> <dbl> <dbl> <int>
#> 1 368 594 3 276 0.75 3.06 12301. 39
#> # ℹ 4 more variables: n.orthogonal.outlier <int>, n.bad.leverage <int>,
#> # flagged.cells <int>, method <chr>
