CenterForStatistics-UGent / pim

R package for probabilistic index models
9 stars 5 forks source link

new.pim.formula completely ignores the left hand side! #16

Open JoFAM opened 6 years ago

JoFAM commented 6 years ago
myPO <- function(x){
  lx <- L(x)
  rx <- R(x)
  n <- length(lx)

  out <- rep(-2, n)
  out[lx > rx] <- 2
  return(out)
}

xx <- rnorm(20)
yy <- xx + runif(20,-0.1,0.1)

pe <- new.pim.env(environment(), compare = "unique",
                  vars = c("xx","yy"))
new.pim.formula(myPO(yy) ~ L(xx) - R(xx), pe)

returns :

PIM formula without intercept: myPO(yy) ~ L(xx) - R(xx) <environment: 0x0000000016c09a38>

Left hand side: PO(L(yy), R(yy))

JoFAM commented 6 years ago

Tracked this down to new.pim.formula not recognizing myPO as a special and hence deciding that has.funs.lhs <- FALSE in new.pim.formula.

Solving this will need a mechanism to register new specials, and tie them to the correct environment so they can find the correct L() and R() functions.

Terms object can have an attribute "specials" that is also used for splines. Might pay off to take a look at that one in order to get pim in a better shape.