1

这是我上一个问题的后续,

所以给定以下数据,

> foo
Resp         A         B         C
1  1.629 0.3333333 0.3333333 0.3333333
2  1.734 0.1666667 0.6666667 0.1666667
3   1.957 0.0000000 1.0000000 0.0000000
4  1.778 1.0000000 0.0000000 0.0000000
5  1.682 0.6666667 0.1666667 0.1666667
6  1.407 0.1666667 0.1666667 0.6666667
7  1.589 0.0000000 0.5000000 0.5000000
8  1.251 0.0000000 0.0000000 1.0000000
9  1.774 0.5000000 0.5000000 0.0000000
10 1.940 0.5000000 0.0000000 0.5000000
>

我正在尝试从这篇文章中复制一个图表(私人访问)。文章声称使用了特殊的立方模型

但是,当我尝试使用符号value ~ (x + y + z)^3 -1时,我得到

object 'z' not found

我假设是因为z线性依赖于xy

当我尝试仅使用xand重新创建特殊立方模型时y,我尝试使用cubicSandquad函数与expand.formula,

      > expand.formula(Resp ~ cubicS(A,B) + quad(A,B))
       Resp ~ (A + B)^3 + I(A * B * (A - B)) + (A + B)^2 + I(A^2) + I(B^2)
      > 

但是,geom_interpolate_tern会说我使用了太多的预测器,

    foo <-
      structure(
        list(
          Resp = c(1.629, 1.734, 1.957, 1.778, 1.682, 1.407,
                   1.589, 1.251, 1.774, 1.94),
          A = c(0.3333333, 0.1666667, 0, 1,
                0.6666667, 0.1666667, 0, 0, 0.5, 0.5),
          B = c(0.3333333, 0.6666667,
                1, 0, 0.1666667, 0.1666667, 0.5, 0, 0.5, 0),
          C = c(0.3333333,
                0.1666667, 0, 0, 0.1666667, 0.6666667, 0.5, 1, 0, 0.5)
        ),
        .Names = c("Resp",
                   "A", "B", "C"),
        class = "data.frame",
        row.names = c("1", "2",
                      "3", "4", "5", "6", "7", "8", "9", "10")
      )

    ggtern(data=foo,aes(y = A,x = B,z = C)) +
      geom_interpolate_tern(
        data = foo,
        mapping = aes(
          value = Resp,color=..level..
        ),
        formula = expand.formula(value ~ cubicS(x,y) + quad(x,y)),
        base = "identity"
      ) 

输出:

    Warning messages:
      1: In structure(c(), class = c(class(x), class(y))) :
      Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
    Consider 'structure(list(), *)' instead.
    2: Computation failed in `stat_interpolate_tern()`:
      only 1-4 predictors are allowed 
4

1 回答 1

2

默认情况下,插值方法是“黄土”,以保持与ggplot2诸如geom_smooth(...). 由于黄土回归的预测变量限制,此错误被抛出。

无论如何,这很容易解决,请指定method = lm。我添加了彩色点以查看模型如何适合您的数据。

ggtern(data=foo,aes(y = A,x = B,z = C)) +
  geom_point(aes(color=Resp)) + 
  geom_interpolate_tern(
    data = foo,
    mapping = aes(
      value = Resp,color=..level..
    ),
    method=lm,   # <<<<<< SPECIFY METHOD HERE <<<<<<<
    formula = expand.formula(value ~ cubicS(x,y) + quad(x,y)),
    base = "identity"
)

输出

于 2017-09-14T01:25:28.500 回答