【问题标题】:Tensor product based Gaussian process smoother in mgcvmgcv中基于张量积的高斯过程更平滑
【发布时间】:2019-05-21 12:53:22
【问题描述】:

我正在尝试运行 GAM 模型,其中 X 和 Y 之间的交互使用高斯过程建模。下面的代码在 mgcv 中使用默认平滑 (s()) 时工作​​正常,但我想用张量积 (te()) 对我的数据进行建模,因为我了解 te 产品专门解决各向异性交互。但是,当我使用te() 时,我似乎无法将所需的参数传递给模型。下面的例子。

library(mgcv)
set.seed(540)
df <- gamSim(2, n = 300, scale = 0.15)[[1]]
df$x <- scales::rescale(df$x, to = c(-180,180))
df$y <- scales::rescale(df$y, to = c(-90,90))
head(df)
# works fine using s()
m1 <- gam(z ~ s(x, y, bs = "gp", m = c(2, 5, 2), k = 30), data = df)
summary(m1)
Family: gaussian 
Link function: identity 

Formula:
z ~ s(x, y, bs = "gp", m = c(2, 5, 2), k = 30)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.46143    0.01581   29.19   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Approximate significance of smooth terms:
         edf Ref.df     F p-value
s(x,y) 8.055  12.73 0.333   0.983

R-sq.(adj) =  0.0248   Deviance explained = 5.11%
GCV = 0.077292  Scale est. = 0.074959  n = 300

# Fails
# pass list as per example in ?te for multivariate marginal
mp <- list(c(2, 5, 2))
m2 <- gam(z ~ te(x, y, bs = "gp", m = mp, k = 30), data = df)
Error in gpE(knt, knt, object$p.order) : 
  incorrect arguments to GP smoother
In addition: Warning message:
In mgcv::te(x, y, bs = "gp", m = mp, k = 30) : m wrong length and ignored.

# try passing directly
m2 <- gam(z ~ te(x, y, bs = "gp", m = c(2,5,2), k = 30), data = df) # FAILS
Error in gpE(knt, knt, object$p.order) : 
  incorrect arguments to GP smoother
In addition: Warning message:
In mgcv::te(x, y, bs = "gp", m = c(2, 5, 2), k = 30) :
  m wrong length and ignored.

# don't pass m
m2 <- gam(z ~ te(x, y, bs = "gp", k = 10), data = df) # works
summary(m2)
Family: gaussian 
Link function: identity 

Formula:
z ~ te(x, y, bs = "gp", k = 10)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.46143    0.01299   35.52   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Approximate significance of smooth terms:
          edf Ref.df     F p-value    
te(x,y) 14.69  20.14 7.633  <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

R-sq.(adj) =  0.341   Deviance explained = 37.4%
GCV = 0.05341  Scale est. = 0.050618  n = 300

gam.check(m2) # k has been ignored!?
Method: GCV   Optimizer: magic
Smoothing parameter selection converged after 15 iterations.
The RMS GCV score gradient at convergence was 6.499192e-07 .
The Hessian was positive definite.
Model rank =  100 / 100 

Basis dimension (k) checking results. Low p-value (k-index<1) may
indicate that k is too low, especially if edf is close to k'.

          k'  edf k-index p-value
te(x,y) 99.0 14.7    1.08    0.94

【问题讨论】:

    标签: r gam mgcv


    【解决方案1】:

    在意识到d 必须在te() 函数中显式设置后,我解决了这个问题。下面的代码有效。

    library(mgcv)
    set.seed(540)
    df <- gamSim(2, n = 300, scale = 0.15)[[1]]
    df$x <- scales::rescale(df$x, to = c(-180,180))
    df$y <- scales::rescale(df$y, to = c(-90,90))
    head(df)
    
    m1 <- gam(z ~ s(x, y, bs = "gp", m = c(2, 5, 2), k = 30), data = df, method = "ML")
    
    mp <- list(c(2, 5, 2))
    m2 <- gam(z ~ te(x, y, bs = "gp", m = mp, d = 2, k = 30), data = df, method = "ML")
    

    【讨论】:

    • 我不确定这是否符合您的想法。我希望这些是相同的,因为您指定的 te 平滑请求 2d gp 平滑作为 only 边际基础。我会检查两个模型m1$spm2$sp 中估计的平滑参数的数量,看看它们是否不同。对于 te 平滑中的各向异性,我希望您需要两个单独的边缘 GP 基,te(x, y, bs = "gp", m = list(x = mp, y = mp), k = 30),如果您想要各向异性,您可能希望更改 mp 中 x 和 y 的长度比例。
    【解决方案2】:

    您想要的似乎不存在(还没有?),即高斯过程 (GP) 平滑本质上是各向同性的。您可以从 MGCV 包中可用于 GP 平滑的可能自相关函数中看到它们是各向同性的(参见 Wood 2017 的第 242 页,或者在加载库后在 R 中简单地键入“?gp.smooth”):所有这些都依赖于 仅在数据点之间的距离 d 上。如果有类似各向异性 GP 平滑的东西,您可以为每个轴的自相关标度定义不同的值,但似乎并非如此。

    如果您的 x 和 y 数据具有不同的单位,并且您确实需要 GP 平滑,据我所知,您唯一能做的就是将它们缩放为单位(“就像在 LOESS 平滑中经常做的那样”,见第 227 页,Wood 2017)。

    Wood 2017:“广义加法模型。R. 第二版简介”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-04
      • 2011-02-15
      • 2015-05-07
      • 2011-01-20
      • 1970-01-01
      • 2013-02-01
      • 1970-01-01
      • 2020-06-26
      相关资源
      最近更新 更多