Capturing individual graphs from multi-line output in R

I am trying to capture one plot from multi-line output. for instance

library(mboost); mod=gamboost(Ozone~.,data=airquality[complete.cases(airquality),]); plot(mod) 

The above example creates a graph for each partial effect variable. The same can be said about the residual graphs created during the construction of the linear model ( lm ). I tried to save the output in a list close to how ggplot can be saved and spent several hours searching how to extract only one plot, but failed. Any tips?

As for the context of the question, I am trying to put graphs in a brilliant application and have a variable number of graphs displayed as output.

The session information is as follows: R version 2.15.2 (2012-10-26) Platform: i386-redhat-linux-gnu (32-bit version)

+4
source share
3 answers

Many functions that produce multiple graphs also have an argument for selecting a subset of graphs. In the case of plot.lm this is the argument of which . So plot(fit, which=1) produce only one plot.

You can check the mboost documentation to see if there is a similar argument for this build function.

+4
source

Essentially, @ greg-snow gave the right solution. I’ll clarify something.

In mboost you can use

 plot(mod, which = "Day") 

to effect only Day . Since we use regular expressions, you can do much more by using the which argument. In a model with linear and smooth effects, you can, for example, extract all the smooth effects to build:

 airquality$Month <- as.factor(airquality$Month) mod <- mod <- gamboost(Ozone ~ bbs(Solar.R) + bbs(Wind) + bbs(Temp) + bols(Month) + bbs(Day), data=airquality[complete.cases(airquality),]) ## now plot bbs effects, ie, smooth effects: par(mfrow = c(2,2)) plot(mod, which = "bbs") ## or the linear effect only par(mfrow = c(1,1)) plot(mod, which = "bols") 

You can use any part of the name (see, for example, names(coef(mod)) ) to determine the effect that will be displayed. You can also use integer values ​​to determine which effect to plot:

 plot(mod, which = 1:2) 

Please note that this can also be used for certain extraction ratios. For instance.

 coef(mod, which = 1) coef(mod, which = "Solar") coef(mod, which = "bbs(Solar.R)") 

all are the same. For more information on how to specify which , both in coef and plot , see our tutorial (Hofner et al. (2014)), Boosting based on the model in R - a practical tutorial using the mboost R-package. Computational Statistics, 29: 3-35. DOI 10.1007 / s00180-012-0382-5).

We confirm that this is not currently described in mboost , but that it is on our list of tasks (see github issue 14 ).

+2
source

(I am not familiar with GAMboost.)

Looking for documentation on ? plot.GAMBoost , I see that there is a select argument. I suppose you would set this argument to the variable you are interested in, and then you will get only one plot that you want. This is similar to which argument in plot.lm , which @GregSnow notes.

+1
source

Source: https://habr.com/ru/post/1484241/


All Articles