fit.SpectraModel-method {soil.spec} | R Documentation |
Fits a calibration model that can be used to convert absorbances to soil properties. Implements the "plsr"
function available from the pls package.
## S4 method for signature 'formula,SpectraPoints,data.frame' 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", ...) ## S4 method for signature 'list,SpectraPoints,data.frame' fit(formulaString, sampled, reference, ...)
formulaString |
|
sampled |
|
reference |
|
idcol |
|
ab.r |
|
CO2.band |
|
ncomp |
|
ncomp.max |
|
repl |
|
segment.type |
|
prefix |
|
... |
other optional arguments |
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.
Andrew Sila and Tomislav Hengl
Mevik, B.-H., Wehrens, R. (2007) The pls Package: Principal Component and Partial Least Squares Regression in R. Journal of Statistical Software 18(2), 1-24.
Africa Soil Information Service (http://africasoils.net)
predict.SpectraPoints
, spec.opts
## 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)