objfun.pmtree: Objective function of a given pmtree

Description Usage Arguments Value Examples

View source: R/pmtree-methods.R

Description

Returns the contributions to the objective function or the sum thereof (if sum = TRUE).

Usage

1
2
3
## S3 method for class 'pmtree'
objfun(x, newdata = NULL, weights = NULL,
  perm = NULL, sum = FALSE, ...)

Arguments

x

pmtree object.

newdata

an optional new data frame for which to compute the sum of objective functions.

weights

weights.

perm

the number of permutations performed (see varimp).

sum

should the sum of objective functions be computed.

...

passed on to predict.party.

Note that objfun.pmtree(x, sum = TRUE) is much faster than sum(objfun.pmtree(x)).

Value

objective function or the sum thereof

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
## generate data
set.seed(2)
n <- 1000
trt <- factor(rep(1:2, each = n/2))
age <- sample(40:60, size = n, replace = TRUE)
eff <- -1 + I(trt == 2) + 1 * I(trt == 2) * I(age > 50)
expit <- function(x) 1/(1 + exp(-x))
success <- rbinom(n = n, size = 1, prob = expit(eff))
dat <- data.frame(success, trt, age)

## compute base model
bmod1 <- glm(success ~ trt, data = dat, family = binomial)

## copmute tree
(tr1 <- pmtree(bmod1, data = dat))

## compute log-Likelihood
logLik(tr1)
objfun(tr1, newdata = dat, sum = TRUE)
objfun(tr1, sum = TRUE)

## log-Likelihood contributions of first 
## 5 observations
nd <- dat[1:5, ]
objfun(tr1, newdata = nd)

model4you documentation built on Dec. 6, 2019, 3 p.m.