Skip to content
Snippets Groups Projects
Commit 9d1edc94 authored by Raimon Tolosana-Delgado's avatar Raimon Tolosana-Delgado
Browse files

v0.10.9-9001: corection of bugs in predict methods and in fit_lmc

parent 072179c4
No related branches found
No related tags found
No related merge requests found
Package: gmGeostats Package: gmGeostats
Version: 0.10-8-9001 Version: 0.10.9-9001
Date: 2021-07-15 Date: 2021-10-01
Title: Geostatistics for Compositional Analysis Title: Geostatistics for Compositional Analysis
Authors@R: c(person(given = "Raimon", Authors@R: c(person(given = "Raimon",
family = "Tolosana-Delgado", family = "Tolosana-Delgado",
......
...@@ -102,6 +102,7 @@ S3method(precision,accuracy) ...@@ -102,6 +102,7 @@ S3method(precision,accuracy)
S3method(predict,LMCAnisCompo) S3method(predict,LMCAnisCompo)
S3method(predict,genDiag) S3method(predict,genDiag)
S3method(predict,gmCgram) S3method(predict,gmCgram)
S3method(predict,gmSpatialModel)
S3method(print,mask) S3method(print,mask)
S3method(setMask,DataFrameStack) S3method(setMask,DataFrameStack)
S3method(setMask,GridTopology) S3method(setMask,GridTopology)
...@@ -236,6 +237,7 @@ exportClasses(gmValidationStrategy) ...@@ -236,6 +237,7 @@ exportClasses(gmValidationStrategy)
exportMethods(Predict) exportMethods(Predict)
exportMethods(as.gstat) exportMethods(as.gstat)
exportMethods(logratioVariogram) exportMethods(logratioVariogram)
exportMethods(predict)
exportMethods(stackDim) exportMethods(stackDim)
exportMethods(variogram) exportMethods(variogram)
import(RColorBrewer) import(RColorBrewer)
......
# gmGeostats 0.10.9-9001
* (2021-09-30) minor bug corrected on the way fit_lmc passes its arguments to surrogate gstat and gmGeostats functions
* (2021-10-01) management of `predict()` methods for S3 and S4 objects, wth the help of the internal function `Predict()` (not recommended to use)
# gmGeostats 0.10.9
(release of polished 0.10.8.900x dev versions)
* minor correction on C source code for compatibility with clang13
# gmGeostats 0.10.8-9001 # gmGeostats 0.10.8-9001
* (2021-07-22) conversion methods between variogram models: `as.gmCgram()` methods for "variogramModel" and "variogramModelList" objects (from package "gstat") * (2021-07-22) conversion methods between variogram models: `as.gmCgram()` methods for "variogramModel" and "variogramModelList" objects (from package "gstat")
......
...@@ -283,6 +283,8 @@ make.gmCompositionalMPSSpatialModel = function( ...@@ -283,6 +283,8 @@ make.gmCompositionalMPSSpatialModel = function(
### exporter to gstat ----- ### exporter to gstat -----
as.gstat.gmSpatialModel <- function(object, ...){ as.gstat.gmSpatialModel <- function(object, ...){
# extra arguments
lldots = list(...)
# data elements # data elements
coords = sp::coordinates(object) coords = sp::coordinates(object)
X = compositions::rmult(object@data, V= gsi.getV(object@data), orig=gsi.orig(object@data)) X = compositions::rmult(object@data, V= gsi.getV(object@data), orig=gsi.orig(object@data))
...@@ -306,10 +308,17 @@ as.gstat.gmSpatialModel <- function(object, ...){ ...@@ -306,10 +308,17 @@ as.gstat.gmSpatialModel <- function(object, ...){
if(any(is.infinite(beta))) beta = NULL if(any(is.infinite(beta))) beta = NULL
# neighbourhood # neighbourhood
ng = object@parameters ng = object@parameters
# manage manual changes of parameters given in dots...
for(nm in names(ng)){
tk = grep(nm, names(lldots))
if(length(tk)>1) ng[[tk]] = lldots[[tk]]
}
# convert
if(!is(ng, "gmKrigingNeighbourhood")) stop("as.gstat: object@parameters must be of class 'gmGaussianMethodParameters'!") if(!is(ng, "gmKrigingNeighbourhood")) stop("as.gstat: object@parameters must be of class 'gmGaussianMethodParameters'!")
res = compo2gstatLR(coords=coords, compo=compo, V=Vinv, lrvgLMC=lrvgLMC, res = compo2gstatLR(coords=coords, compo=compo, V=Vinv, lrvgLMC=lrvgLMC,
nscore=FALSE, formulaterm = formulaterm, prefix=prefix, beta=beta, nscore=FALSE, formulaterm = formulaterm, prefix=prefix, beta=beta,
nmax=ng$nmax, nmin=ng$nmin, omax=ng$omax, maxdist=ng$maxdist, force=ng$force) nmax=ng$nmax, nmin=ng$nmin, omax=ng$omax, maxdist=ng$maxdist, force=ng$force,
...)
return(res) return(res)
}else{ }else{
# non-compositional case # non-compositional case
...@@ -320,9 +329,15 @@ as.gstat.gmSpatialModel <- function(object, ...){ ...@@ -320,9 +329,15 @@ as.gstat.gmSpatialModel <- function(object, ...){
if(any(is.infinite(beta))) beta = NULL if(any(is.infinite(beta))) beta = NULL
# neighbourhood # neighbourhood
ng = object@parameters ng = object@parameters
# manage manual changes of parameters given in dots...
for(nm in names(ng)){
tk = grep(nm, names(lldots))
if(length(tk)>1) ng[[tk]] = lldots[[tk]]
}
res = rmult2gstat(coords=coords, data=X, V=V, vgLMC=vgLMC, res = rmult2gstat(coords=coords, data=X, V=V, vgLMC=vgLMC,
nscore=FALSE, formulaterm = formulaterm, prefix=prefix, beta=beta, nscore=FALSE, formulaterm = formulaterm, prefix=prefix, beta=beta,
nmax=ng$nmax, nmin=ng$nmin, omax=ng$omax, maxdist=ng$maxdist, force=ng$force) nmax=ng$nmax, nmin=ng$nmin, omax=ng$omax, maxdist=ng$maxdist, force=ng$force,
...)
} }
} }
...@@ -400,26 +415,38 @@ as.gmSpatialModel.gstat = function(object, V=NULL, ...){ ...@@ -400,26 +415,38 @@ as.gmSpatialModel.gstat = function(object, V=NULL, ...){
#' @name predict_gmSpatialModel #' @name predict_gmSpatialModel
NULL NULL
#' @rdname predict_gmSpatialModel #' @rdname predict_gmSpatialModel
setMethod("predict", signature(object="gmSpatialModel"), #' @export
function(object, newdata, pars, ...){ #' @method predict gmSpatialModel
Predict(object, newdata, pars, ...) predict.gmSpatialModel <- function(object, newdata, pars=NULL, ...){
}) if(is.null(pars)){
return(Predict(object, newdata, ...))
}else{
return(Predict(object, newdata, pars, ...))
}
}
#' @rdname predict_gmSpatialModel
#' @export
setMethod("predict", signature(object="gmSpatialModel"), definition = predict.gmSpatialModel)
#' @rdname predict_gmSpatialModel #' @rdname predict_gmSpatialModel
#' @include gmAnisotropy.R #' @include gmAnisotropy.R
#' @include preparations.R #' @include preparations.R
#' @export #' @export
setMethod("Predict",signature(object="gmSpatialModel", newdata="ANY", pars="missing"), setMethod("Predict",signature(object="gmSpatialModel", newdata="ANY"),
function(object, newdata, pars, ...){ function(object, newdata, ...){
if(is.null(object$pars)) object$pars = KrigingNeighbourhood() if(is.null(object@parameters)) object@parameters = KrigingNeighbourhood()
predict(object, newdata, pars = object$pars, ...) Predict(object, newdata, pars = object@parameters , ...)
} }
) )
#' @rdname predict_gmSpatialModel #' @rdname predict_gmSpatialModel
#' @include gmSpatialMethodParameters.R #' @include gmSpatialMethodParameters.R
#' @export #' @export
......
...@@ -30,10 +30,15 @@ fit_lmc <- function(v, ...) UseMethod("fit_lmc", v) ...@@ -30,10 +30,15 @@ fit_lmc <- function(v, ...) UseMethod("fit_lmc", v)
#' @describeIn fit_lmc wrapper around gstat::fit.lmc method #' @describeIn fit_lmc wrapper around gstat::fit.lmc method
#' @param g spatial data object, containing the original data #' @param g spatial data object, containing the original data
#' @param model LMC or variogram model to fit #' @param model LMC or variogram model to fit
#' @param fit.ranges logical, should ranges be modified? (default=FALSE)
#' @param fit.lmc logical, should the nugget and partial sill matrices be modified (default=TRUE)
#' @param correct.diagonal positive value slightly larger than 1, for multiplying the direct variogram
#' models and reduce the risk of numerically negative eigenvalues
#' @export #' @export
#' @method fit_lmc gstatVariogram #' @method fit_lmc gstatVariogram
fit_lmc.gstatVariogram <- function(v, g, model,...){ fit_lmc.gstatVariogram <- function(v, g, model, fit.ranges = FALSE, fit.lmc = !fit.ranges, correct.diagonal = 1.0, ...){
res = gstat::fit.lmc(as.gstatVariogram(v, ...), as.gstat(g, ...), as.variogramModel(model, ...)) res = gstat::fit.lmc(as.gstatVariogram(v, ...), as.gstat(g, ...), as.variogramModel(model, ...),
fit.ranges = fit.ranges, fit.lmc = fit.lmc, correct.diagonal=correct.diagonal)
class(res$model) = c("variogramModelList", "list") class(res$model) = c("variogramModelList", "list")
return(res) return(res)
} }
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
*/ */
// attention: comment this if not compiling // attention: comment this if not compiling
#include <stdio.h> #include <stdio.h>
#include <Rinternals.h>
#ifdef _OPENMP #ifdef _OPENMP
#include <omp.h> #include <omp.h>
#endif #endif
#include <Rinternals.h>
#define inR // attention: this must be uncommented if not compiling #define inR // attention: this must be uncommented if not compiling
......
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment