? data=read.table("http://statcourse.com/research/boston.csv", , sep=",", header = TRUE) ? library(rpart) ? fit=rpart (MV~ CRIM+ZN+INDUS+CHAS+NOX+RM+AGE+DIS+RAD+TAX+ PT+B+LSTAT) Please: Show me the tree. Mark -------- Original Message -------- Subject: Re: [R] help with rpart From: "Stephen Milborrow" <[1]milbo at sonic.net> Date: Fri, July 29, 2011 7:54 am To: <[2]mark at statcourse.com> Cc: <[3]sarah.goslee at gmail.com> Mark, check out my rpart.plot package. See also the PDF vignette that comes with the package. Steve [4]www.milbo.users.sonic.net ------------------------------------------------------------------ Message: 69 Date: Thu, 28 Jul 2011 16:10:35 -0400 From: Sarah Goslee <[5]sarah.goslee at gmail.com> To: [6]mark at statcourse.com Cc: [7]r-help at r-project.org Subject: Re: [R] help with rpart Message-ID: <[8]CAM_vjukbUphEmRDs231LpiZwS7xdKMMK3_7s5mz=yDtTVhthog at mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Why repost after receiving a reply? Reposting is unnecessary. If the first reply was unsatisfactory, why? More detail in your question leads to a more useful and informative reply. Just in case you didn't get it: On Thu, Jul 28, 2011 at 11:52 AM, <[9]mark at statcourse.com> wrote: > 1. How can I plot the entire tree produced by rpart? What is plot() not doing that you need? > 2. How can I submit a vector of values to a tree produced by rpart and > have > it make an assignment? What is predict() not doing that you need? -- Sarah Goslee [10]http://www.functionaldiversity.org References 1. mailto:milbo at sonic.net 2. mailto:mark at statcourse.com 3. mailto:sarah.goslee at gmail.com 4. http://www.milbo.users.sonic.net/ 5. mailto:sarah.goslee at gmail.com 6. mailto:mark at statcourse.com 7. mailto:r-help at r-project.org 8. mailto:CAM_vjukbUphEmRDs231LpiZwS7xdKMMK3_7s5mz=yDtTVhthog at mail.gmail.com 9. mailto:mark at statcourse.com 10. http://www.functionaldiversity.org/
Ah, now we're getting somewhere. Think how easy this would be if you'd provided this information initially. On Fri, Jul 29, 2011 at 11:11 AM, <mark at statcourse.com> wrote:> ?? data=read.table("http://statcourse.com/research/boston.csv", , sep=",", > header = TRUE) > ?? library(rpart) > ?? fit=rpart (MV~ CRIM+ZN+INDUS+CHAS+NOX+RM+AGE+DIS+RAD+TAX+ PT+B+LSTAT) > Please: Show me the tree. > MarkWell, your rpart() statement won't run, so obviously you can't see the tree. There's no data argument, and the variable names don't match the column headers in the data you provided. Here's a revised version, that prints and plots the tree, and predicts some test data. # corrected rpart(), guessing at what you meant markdata <- read.table("http://statcourse.com/research/boston.csv", , sep=",", header = TRUE) fit <- rpart (MEDV~ CRIM+ZN+INDUS+CHAS+NOX+RM+AGE+DIS+RAD+TAX+ PTRATIO+B+LSTAT, data=markdata) # two ways of looking at the complete tree fit plot(fit) text(fit) # predicting a few values mark.subsample <- markdata[1:5,] predict(fit, mark.subsample, type="vector") If this is your actual code, your problem was far more basic than plotting and predicting. Sharing your error messages would have been a good start. Sarah -- Sarah Goslee http://www.functionaldiversity.org
Mark, The below is not directly reproducible. There is no "MV" or "PT" variable in the dataset you reference. I am assuming you meant: dat <- read.table("http://statcourse.com/research/boston.csv", , sep=",", header = TRUE) fit <- rpart(MEDV ~ CRIM + ZN + INDUS + CHAS + NOX + RM + AGE + DIS + RAD + TAX + PTRATIO + B + LSTAT, data = dat) plot(fit) which creates the plot I attached. Cheers, Josh On Fri, Jul 29, 2011 at 8:11 AM, <mark at statcourse.com> wrote:> > ? ? ?data=read.table("http://statcourse.com/research/boston.csv", , sep=",", > ? header = TRUE) > > ? ? ?library(rpart) > > ? ? ?fit=rpart (MV~ CRIM+ZN+INDUS+CHAS+NOX+RM+AGE+DIS+RAD+TAX+ PT+B+LSTAT) > > ? Please: Show me the tree. > > ? Mark > > ? -------- Original Message -------- > ? Subject: Re: [R] help with rpart > ? From: "Stephen Milborrow" <[1]milbo at sonic.net> > ? Date: Fri, July 29, 2011 7:54 am > ? To: <[2]mark at statcourse.com> > ? Cc: <[3]sarah.goslee at gmail.com> > ? Mark, check out my rpart.plot package. See also the PDF vignette that comes > ? with the package. > ? Steve > ? [4]www.milbo.users.sonic.net > ? ------------------------------------------------------------------ > ? Message: 69 > ? Date: Thu, 28 Jul 2011 16:10:35 -0400 > ? From: Sarah Goslee <[5]sarah.goslee at gmail.com> > ? To: [6]mark at statcourse.com > ? Cc: [7]r-help at r-project.org > ? Subject: Re: [R] help with rpart > ? Message-ID: > ? <[8]CAM_vjukbUphEmRDs231LpiZwS7xdKMMK3_7s5mz=yDtTVhthog at mail.gmail.com> > ? Content-Type: text/plain; charset=ISO-8859-1 > ? Why repost after receiving a reply? Reposting is unnecessary. If the > ? first reply was unsatisfactory, why? More detail in your question > ? leads to a more useful and informative reply. > ? Just in case you didn't get it: > ? On Thu, Jul 28, 2011 at 11:52 AM, <[9]mark at statcourse.com> wrote: > ? > 1. How can I plot the entire tree produced by rpart? > ? What is plot() not doing that you need? > ? > 2. How can I submit a vector of values to a tree produced by rpart and > ? > have > ? > it make an assignment? > ? What is predict() not doing that you need? > ? -- > ? Sarah Goslee > ? [10]http://www.functionaldiversity.org > > References > > ? 1. mailto:milbo at sonic.net > ? 2. mailto:mark at statcourse.com > ? 3. mailto:sarah.goslee at gmail.com > ? 4. http://www.milbo.users.sonic.net/ > ? 5. mailto:sarah.goslee at gmail.com > ? 6. mailto:mark at statcourse.com > ? 7. mailto:r-help at r-project.org > ? 8. mailto:CAM_vjukbUphEmRDs231LpiZwS7xdKMMK3_7s5mz=yDtTVhthog at mail.gmail.com > ? 9. mailto:mark at statcourse.com > ?10. http://www.functionaldiversity.org/ > ______________________________________________ > R-help at r-project.org 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. >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles https://joshuawiley.com/ -------------- next part -------------- A non-text attachment was scrubbed... Name: tree.pdf Type: application/pdf Size: 4244 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110729/c28b399a/attachment.pdf>
Your plot only shows part of the tree provided by print(fit). I would like to plot the entire tree. -------- Original Message -------- Subject: Re: [R] help with plot.rpart From: Joshua Wiley <[1]jwiley.psych at gmail.com> Date: Fri, July 29, 2011 8:25 am To: [2]mark at statcourse.com Cc: [3]r-help at r-project.org Mark, The below is not directly reproducible. There is no "MV" or "PT" variable in the dataset you reference. I am assuming you meant: dat <- read.table("http://statcourse.com/research/boston.csv", , sep=",", header = TRUE) fit ><- rpart(MEDV ~ CRIM + ZN + INDUS + CHAS + NOX + RM + AGE + DIS + RAD + TAX + PTRATIO + B + LSTAT, data = dat) plot(fit) which creates the plot I attached. Cheers, Josh On Fri, Jul 29, 2011 at 8:11 AM, ><[4]mark at statcourse.com> wrote: > > ? data=read.table("http://statcourse.com/research/boston.csv", , sep=",", > header = TRUE) > > ? library(rpart) > > ? fit=rpart (MV~ CRIM+ZN+INDUS+CHAS+NOX+RM+AGE+DIS+RAD+TAX+ PT+B+LSTAT) > > Please: Show me the tree. > > Mark > > -------- Original Message -------- > Subject: Re: [R] help with rpart > From: "Stephen Milborrow" <[1][5]milbo at sonic.net> > Date: Fri, July 29, 2011 7:54 am > To: <[2][6]mark at statcourse.com> > Cc: <[3][7]sarah.goslee at gmail.com> > Mark, check out my rpart.plot package. See also the PDF vignette that comes > with the package. > Steve > [4][8]www.milbo.users.sonic.net > ------------------------------------------------------------------ > Message: 69 > Date: Thu, 28 Jul 2011 16:10:35 -0400 > From: Sarah Goslee <[5][9]sarah.goslee at gmail.com> > To: [6][10]mark at statcourse.com > Cc: [7][11]r-help at r-project.org > Subject: Re: [R] help with rpart > Message-ID: > <[8][12]CAM_vjukbUphEmRDs231LpiZwS7xdKMMK3_7s5mz=yDtTVhthog at mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1 > Why repost after receiving a reply? Reposting is unnecessary. If the > first reply was unsatisfactory, why? More detail in your question > leads to a more useful and informative reply. > Just in case you didn't get it: > On Thu, Jul 28, 2011 at 11:52 AM, <[9][13]mark at statcourse.com> wrote: > > 1. How can I plot the entire tree produced by rpart? > What is plot() not doing that you need? > > 2. How can I submit a vector of values to a tree produced by rpart and > > have > > it make an assignment? > What is predict() not doing that you need? > -- > Sarah Goslee > [10][14]http://www.functionaldiversity.org > > References > > 1. [15]mailto:milbo at sonic.net > 2. [16]mailto:mark at statcourse.com > 3. [17]mailto:sarah.goslee at gmail.com > 4. [18]http://www.milbo.users.sonic.net/ > 5. [19]mailto:sarah.goslee at gmail.com > 6. [20]mailto:mark at statcourse.com > 7. [21]mailto:r-help at r-project.org > 8. [22]mailto:CAM_vjukbUphEmRDs231LpiZwS7xdKMMK3_7s5mz=yDtTVhthog at mail.gmail.co m > 9. [23]mailto:mark at statcourse.com > 10. [24]http://www.functionaldiversity.org/ > ______________________________________________ > [25]R-help at r-project.org mailing list > [26]https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide [27]http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles [28]https://joshuawiley.com/ References 1. http://jwiley.psych at gmail.com/ 2. mailto:mark at statcourse.com 3. mailto:r-help at r-project.org 4. mailto:mark at statcourse.com 5. mailto:milbo at sonic.net 6. mailto:mark at statcourse.com 7. mailto:sarah.goslee at gmail.com 8. http://www.milbo.users.sonic.net/ 9. mailto:sarah.goslee at gmail.com 10. mailto:mark at statcourse.com 11. mailto:r-help at r-project.org 12. mailto:CAM_vjukbUphEmRDs231LpiZwS7xdKMMK3_7s5mz=yDtTVhthog at mail.gmail.com 13. mailto:mark at statcourse.com 14. http://www.functionaldiversity.org/ 15. mailto:milbo at sonic.net 16. mailto:mark at statcourse.com 17. mailto:sarah.goslee at gmail.com 18. http://www.milbo.users.sonic.net/ 19. mailto:sarah.goslee at gmail.com 20. mailto:mark at statcourse.com 21. mailto:r-help at r-project.org 22. mailto:CAM_vjukbUphEmRDs231LpiZwS7xdKMMK3_7s5mz=yDtTVhthog at mail.gmail.com 23. mailto:mark at statcourse.com 24. http://www.functionaldiversity.org/ 25. mailto:R-help at r-project.org 26. https://stat.ethz.ch/mailman/listinfo/r-help 27. http://www.R-project.org/posting-guide.html 28. https://joshuawiley.com/