christian-za.keller@ubs.com
2002-Feb-15 15:27 UTC
[R] Bug(?) in predict.tree() --- Evaluation order of Boolean operators
Dear R users I have a problem with predict.tree() when I want the fitted values of a tree object to be returned (i.e. argument 'newdata' is missing). Whatever I specify for argument 'type' the fitted model object is returned. Example: library(tree) data(kyphosis) fit.tree <- tree(Kyphosis ~ Age + Number + Start, data=kyphosis) p <- predict(fit.tree, type="class") class(p) [1] "tree" I expected p to be a factor with levels absent or present. Note that S-Plus has (almost) the same code for predict.tree() and gives > class(p) [1] "factor" > p [1] absent absent present absent absent absent absent absent [...] [79] absent present absent I think the source of the problem is located in the following lines of predict.tree(): if (missing(newdata) || is.null(newdata) & type == "tree") return(object) When missing(newdata) is TRUE the logical expression missing(newdata) || is.null(newdata) & type == "tree" is always TRUE, whatever is.null(newdata) or type == "tree" are: TRUE || FALSE & FALSE [1] TRUE Note that S-Plus 6 for Windows gives TRUE || FALSE & FALSE [1] F I don't want to judge which one is correct. Btw. I use> version_ platform i386-pc-mingw32 arch x86 os Win32 system x86, Win32 status major 1 minor 4.1 year 2002 month 01 day 30 language R ------------------------------------------ Christian Keller ===============UBS AG Analytical CRM UBS CH N?schelerstrasse 22, CH-8098 Z?rich Tel. +41-1-234 51 48, Fax. +41-1-234 26 83 christian-za.keller at ubs.com -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
2002-Feb-15 15:54 UTC
[R] Bug(?) in predict.tree() --- Evaluation order of Boolean operators
christian-za.keller at ubs.com writes:> I think the source of the problem is located in the following lines > of predict.tree(): > if (missing(newdata) || is.null(newdata) & type == "tree") > return(object) > > When missing(newdata) is TRUE the logical expression > missing(newdata) || is.null(newdata) & type == "tree" > is always TRUE, whatever is.null(newdata) or type == "tree" are: > TRUE || FALSE & FALSE > [1] TRUE > > Note that S-Plus 6 for Windows gives > TRUE || FALSE & FALSE > [1] F > > I don't want to judge which one is correct.It's an operator precedence issue. || has higher precedence than & in S (-plus, 6.0 and 3.4), but lower in R. Try substitute(T||F&F)[[1]] I think we want to be compatible, but we'll not likely change it in the 1.4.x series. However, a set of parentheses should help... -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
christian-za.keller@ubs.com
2002-Feb-15 16:32 UTC
[R] Bug(?) in predict.tree() --- Evaluation order of Boolean operators
Dear Peter Thank you for your help.>> It's an operator precedence issue. || has higher precedence than & in >> S (-plus, 6.0 and 3.4), but lower in R. >> >> Try substitute(T||F&F)[[1]] >> >> I think we want to be compatible, but we'll not likely change it in >> the 1.4.x series. However, a set of parentheses should help...Note also that in R: > T || F & F [1] TRUE > F & F || T [1] TRUE > substitute(T || F & F)[[1]] || > substitute(F & F || T)[[1]] || while in S-Plus: > T || F & F [1] F > F & F || T [1] T > substitute(T || F & F)[[1]] & > substitute(F & F || T)[[1]] || Christian ------------------------------------------ Christian Keller ===============UBS AG Analytical CRM UBS CH N?schelerstrasse 22, CH-8098 Z?rich Tel. +41-1-234 51 48, Fax. +41-1-234 26 83 christian-za.keller at ubs.com -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
David Smith
2002-Feb-15 18:53 UTC
[R] Bug(?) in predict.tree() --- Evaluation order of Boolean operators
> || has higher precedence than & in S (-plus, 6.0 and 3.4), but lowerin R. Actually, in all versions of S-PLUS (as documented in ?Syntax and following the Blue Book), ||, |, & and && all have the same precedence and hence are evaluated left to right. This explains Christian's results. -- David M Smith <dsmith at insightful.com> S-PLUS Product Marketing Manager, Insightful Corp, Seattle WA Tel: +1 (206) 802 2360 Fax: +1 (206) 283 6310 Insightful Corporation provides analytical solutions leveraging S-PLUS, StatServer, S-PLUS Analytic Server and consulting services. See www.insightful.com for details.> -----Original Message----- > From: christian-za.keller at ubs.com [mailto:christian-za.keller at ubs.com] > Sent: Friday, February 15, 2002 08:32 > To: p.dalgaard at biostat.ku.dk > Cc: r-help at stat.math.ethz.ch > Subject: RE: Re: [R] Bug(?) in predict.tree() --- Evaluation order of > Boolean operators > > > Dear Peter > > Thank you for your help. > > >> It's an operator precedence issue. || has higher > precedence than & in > >> S (-plus, 6.0 and 3.4), but lower in R. > >> > >> Try substitute(T||F&F)[[1]] > >> > >> I think we want to be compatible, but we'll not likely change it in > >> the 1.4.x series. However, a set of parentheses should help... > > Note also that in R: > > T || F & F > [1] TRUE > > F & F || T > [1] TRUE > > substitute(T || F & F)[[1]] > || > > substitute(F & F || T)[[1]] > || > > while in S-Plus: > > T || F & F > [1] F > > F & F || T > [1] T > > substitute(T || F & F)[[1]] > & > > substitute(F & F || T)[[1]] > || > > > Christian > > ------------------------------------------ > Christian Keller > ===============> UBS AG > Analytical CRM UBS CH > N?schelerstrasse 22, CH-8098 Z?rich > Tel. +41-1-234 51 48, Fax. +41-1-234 26 83 > christian-za.keller at ubs.com > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. > -.-.-.-.-.-.-.-.- > r-help mailing list -- Read > http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: > r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. > _._._._._._._._._ >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._