## 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