
R Under development (unstable) (2026-07-13 r90246) -- "Unsuffered Consequences"
Copyright (C) 2026 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(mboost)
Loading required package: parallel
Loading required package: stabs
> 
> ## library(mboost, lib.loc="~/R/experimental")
> ## attach(asNamespace("mboost"))
> ## library(Matrix)
> ## source("~/_Dateien_/R_Sources/mboost/pkg/R/brad.R")
> 
> ########################################
> #        Bivariate kriging             #
> ########################################
> 
> set.seed(1907)
> x1 <- runif(300, -2, 2)
> x2 <- runif(300, -x1, 2)
> f <- function(x,y){
+     x^2 + y^2
+ }
> y <- rnorm(300, mean=f(x1,x2), sd = 0.1)
> DF <- data.frame(y = y, x1=x1, x2=x2)
> x1 <- x2 <- seq(-2,2, by=0.1)
> X <- expand.grid(x1,x2)
> nD <-  data.frame(x1=X[,1], x2=X[,2])
> z <- matrix(f(X[,1], X[,2]), nrow=length(x1), ncol=length(x2))
> 
> mstop <- 1000 ## brad seems to "converge" much quicker in this situation
> # mstop <- 10000 ## now bspatial looks ok, too.
> 
> ###
> # Fit model with brad
> model_1 <- gamboost(y ~ brad(x1, x2, knots=100),
+                 data=DF, control=boost_control(mstop=mstop))
Loading required namespace: fields
> pr <- matrix(predict(model_1, nD), nrow=length(x1), ncol=length(x2))
> 
> par(mfrow=c(1,3))
> 
> contour(x1, x2, z)
> contour(x1, x2, pr, add=TRUE, lty="dashed", col="red")
> with(DF, points(x1, x2, cex=0.5))
> 
> ###
> # Fit model with bspatial
> model_2 <- gamboost(y ~ bspatial(x1, x2, knots=10),
+                  data=DF, control=boost_control(mstop=mstop))
Warning message:
In .qr.rank.def.warn(r) :
  matrix is structurally rank deficient; using augmented matrix with additional 54 row(s) of zeros
> pr2 <- matrix(predict(model_2, nD), nrow=length(x1), ncol=length(x2))
Warning messages:
1: In bsplines(mf[[i]], knots = args$knots[[i]]$knots, boundary.knots = args$knots[[i]]$boundary.knots,  :
  Some 'x' values are beyond 'boundary.knots'; Linear extrapolation used.
2: In bsplines(mf[[i]], knots = args$knots[[i]]$knots, boundary.knots = args$knots[[i]]$boundary.knots,  :
  Some 'x' values are beyond 'boundary.knots'; Linear extrapolation used.
> 
> contour(x1, x2, z)
> contour(x1, x2, pr2, add=TRUE, lty="dashed", col="red", levels=c(-10:10))
> with(DF, points(x1, x2, cex=0.5))
> 
> ###
> # Fit model with Krig (package fields)
> require(fields)
Loading required package: fields
Loading required package: spam
Spam version 2.11-4 (2026-05-28) is loaded.
Type 'help( Spam)' or 'demo( spam)' for a short introduction 
and overview of this package.
Help for individual functions is also obtained by adding the
suffix '.spam' to the function name, e.g. 'help( chol.spam)'.

Attaching package: 'spam'

The following objects are masked from 'package:base':

    backsolve, forwardsolve

Loading required package: viridisLite
Loading required package: RColorBrewer

Try help(fields) to get started.
> TMP <- mboost:::hyper_brad(DF[,2:3], vary= "", knots=100, covFun = stationary.cov, args=list(Covariance="Matern", smoothness = 1.5, theta=NULL))
> 
> contour(x1, x2, z)
> 
> ########################################
> #        Univariate kriging            #
> ########################################
> 
> set.seed(1907)
> x1 <- rnorm(300)
> y <- rnorm(300, mean=x1^2, sd = 0.5)
> DF <- data.frame(y = y, x1=x1, int=rep(1, length(x1)))
> 
> nknots <- 20
> model_uni <- gamboost(y ~ bols(int, intercept=FALSE) + brad(x1, knots=nknots),
+                 data=DF, control=boost_control(mstop=mstop))
> 
> #cv_uni <- cvrisk(model_uni) ## no overfitting until mstop = 1000
> #plot(cv_uni)
> 
> par(mfrow=c(1,1))
> plot(model_uni, which=2)
> lines(sort(x1), sort(x1)^2 - mean(sort(x1)^2), col="red")
> 
> ########################################
> #        Trivariate kriging            #
> ########################################
> 
> #.. todo
> 
> ########################################
> # Check effective range computation    #
> ########################################
> 
> x = DF[1:300,2:3]
> require(fields)
> theta_hat <- mboost:::effective_range(x, eps = 0.001, covFun=stationary.cov,
+                              args=list(Covariance = "Matern", smoothness = 1.5, theta = NULL))
> stopifnot( (attr(theta_hat, "c_value") - 9.23339238) < sqrt(.Machine$double.eps) )
> 
> proc.time()
   user  system elapsed 
  2.449   0.088   2.518 
