Learn R Programming

soil.spec (version 2.1.4)

fit.SpectraModel-method: Fits a calibration model for soil spectroscopy

Description

Fits a calibration model that can be used to convert absorbances to soil properties. Implements the "plsr" function available from the pls package.

Usage

"fit"(formulaString, sampled, reference, idcol = "SAMPLEID", ab.r = get("MIR", envir=spec.opts), CO2.band = get("CO2.band", envir=spec.opts), ncomp, ncomp.max=15, repl = 5, segment.type = "interleaved", prefix = "X", ...) "fit"(formulaString, sampled, reference, ...)

Arguments

formulaString
"formula"; formula string
sampled
"SpectraPoints"; absorbances
reference
"data.frame"; reference values estimated in laboratory using at the order of magnitude more precise technique
idcol
"character"; column with sample IDs
ab.r
"numeric"; natural range of wavenumbers of interest
CO2.band
"numeric"; range of wavenumbers for the CO2 band
ncomp
"integer"; number of components (if not specified will be determined using cross-validation)
ncomp.max
"integer"; maximum number of components to be used for model fitting
repl
"integer"; number of repetitions for "pls::plsr"
segment.type
"character"; segment type for "pls::plsr"
prefix
"character"; default prefix to be added to the band names
...
other optional arguments

Details

Returns an object of class "SpectraModel", which contains slots: (1) "variable" (variable name according to the global soil data registry), (2) "Space" (3D space defined by the 1--3 principal components for absorbances), and (3) "model" (fitted model; usually of type pls::plsr and as an output from the partial least squares regression). Fitting models for large data sets can be time and memory consuming.

References

See Also

predict.SpectraPoints, spec.opts

Examples

Run this code
## Not run: 
# ## build a callibration model using AfSIS data:
# library(plyr)
# library(sp)
# library(rgdal)
# 
# data(afss)
# afss.tbl <- join(afss$sites, afss$horizons)
# con <- url("http://gsif.isric.org/lib/exe/fetch.php?media=afss.spec.rda")
# load(con)
# afss.spec.ab <- Spectra(samples=data.frame(SAMPLEID=afss.spec$SAMPLEID, 
#    MID="ICR_SOIL", DateTime=Sys.time()), ab=afss.spec)
# sel.r <- !afss.tbl$LONWGS84==100
# sp <- data.frame(afss.tbl[sel.r,c("LONWGS84","LATWGS84")])
# coordinates(sp) <- ~LONWGS84+LATWGS84
# proj4string(sp) <- CRS("+proj=longlat")
# attr(sp@coords, "dimnames")[[1]] <- afss.tbl$SAMPLEID[sel.r]
# ## extend to SprectraPoints:
# afss.spec.sp <- SpectraPoints(Spectra=afss.spec.ab, sp=sp)
# ## select bands of interest:
# cutspec <- c(600,2350.8,2379.8,4000)
# col.no <- sapply(names(afss.spec.sp@data@ab)[-1], 
#    function(x){as.numeric(strsplit(x, "X")[[1]][2])})
# sel <- col.no>cutspec[1] & col.no<cutspec[2] | 
#        col.no>cutspec[3] & col.no<cutspec[4]
# summary(sel)
# formulaString <- as.formula(paste("na.omit(log(ORCDRC)) ~ ", 
#    paste(names(afss.spec.sp@data@ab[-1])[sel], collapse="+")))
# m.ORC <- fit(formulaString, sampled=afss.spec.sp, reference=afss.tbl) 
# str(m.ORC)
# ## End(Not run)
## this model, in fact, is included in the package:
data(m.ORCCNS)
str(m.ORCCNS)

Run the code above in your browser using DataLab