From: Philipp Benner <pbenner_at_uos.de>

Date: Sat, 16 Jun 2007 00:59:22 +0200

Date: Sat, 16 Jun 2007 00:59:22 +0200

> With this in mind, either of the following might do what you want:

*>
**> badFunction <- function(mydata, myformula) {
**> mydata$myweight <- abs(rnorm(nrow(mydata)))
**> hyp <-
**> rpart(myformula,
**> data=mydata,
**> weights=myweight,
**> method="class")
**> prev <- hyp
**> }
**>
**>
**> badFunction <- function(mydata, myformula) {
**> myweight <- abs(rnorm(nrow(mydata)))
**> environment(myformula) <- environment()
**> hyp <-
**> rpart(myformula,
**> data=mydata,
**> weights=myweight,
**> method="class")
**> prev <- hyp
**> }
*

OK, this is what I have now:

adaboostBad <- function(formula, data) {
## local definition of the weight vector (won't work because pima.formula is not defined within this function)
w <- abs(rnorm(nrow(data)))

rpart(formula, data=data, weights=w)

}

adaboostGood <- function(formula, data) {
## create weight vector in the data object
data$w <- abs(rnorm(nrow(data)))

rpart(formula, data=data, weights=w)

}

adaboostBest <- function(formula, data) {
## associate the current environment (this function's one) with the object `formula'
environment(formula) <- environment()

w <- abs(rnorm(nrow(data)))

rpart(formula, data=data, weights=w)

}

-- Philipp Benner ______________________________________________ R-help_at_stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.Received on Fri 15 Jun 2007 - 23:06:14 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Sat 16 Jun 2007 - 00:31:58 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*