Learn R Programming

condvis (version 0.5-1)

plotxs: Visualise a section in data space

Description

Visualise a section in data space, showing fitted models where they intersect the section, and nearby observations. The weights for observations can be calculated with similarityweight. This function is mainly for use in ceplot and condtour.

Usage

plotxs(xs, y, xc.cond, model, model.colour = NULL, model.lwd = NULL,
  model.lty = NULL, model.name = NULL, yhat = NULL, mar = NULL,
  col = "black", weights = NULL, view3d = FALSE, theta3d = 45,
  phi3d = 20, xs.grid = NULL, prednew = NULL, conf = FALSE,
  probs = FALSE, pch = 1, residuals = FALSE, main = NULL, xlim = NULL,
  ylim = NULL)

Arguments

xs

A dataframe with one or two columns.

y

A dataframe with one column.

xc.cond

A dataframe with a single row, with all columns required for passing to predict methods of models in model.

model

A fitted model object, or a list of such objects.

model.colour

Colours for fitted models. If model is a list, this should be of same length as model.

model.lwd

Line weight for fitted models. If model is a list, this should be of same length as model.

model.lty

Line style for fitted models. If model is a list, this should be of same length as model.

model.name

Character labels for models, for legend.

yhat

Fitted values for the observations in y. Calculated if needed and not provided. Only used if showing residuals, or xs has two columns.

mar

Margins for plot.

col

Colours for observed data. Should be of length nrow(xs).

weights

Similarity weights for observed data. Should be of length nrow(xs). Usually calculated with similarityweight.

view3d

Logical; if TRUE plots a three-dimensional regression surface if possible.

theta3d, phi3d

Angles defining the viewing direction. theta3d gives the azimuthal direction and phi3d the colatitude. See persp.

xs.grid

The grid of values defining the part of the section to visualise. Calculated if not provided.

prednew

The y values where the models in model intersect the section. Useful when providing theta3d, phi3d, or weights, where the predict methods have been called elsewhere.

conf

Logical; if TRUE plots confidence bounds (or equivalent) for models which provide this.

probs

Logical; if TRUE, shows predicted class probabilities instead of just predicted classes. Only available if xs contains two numeric predictors and the model's predict method provides this.

pch

Plot symbols for observed data

residuals

Logical; if TRUE, plots a residual versus predictor plot instead of the usual scale of raw response.

main

Character title for plot, default is "Conditional expectation".

xlim

Graphical parameter passed to plotting functions.

ylim

Graphical parameter passed to plotting functions.

Value

A list containing relevant information for updating the plot.

References

O'Connell M, Hurley CB and Domijan K (2017). ``Conditional Visualization for Statistical Models: An Introduction to the condvis Package in R.''Journal of Statistical Software, 81(5), pp. 1-20. <URL:http://dx.doi.org/10.18637/jss.v081.i05>.

See Also

plotxc, ceplot, condtour

Examples

Run this code
# NOT RUN {
data(mtcars)
model <- lm(mpg ~ ., data = mtcars)
plotxs(xs = mtcars[, "wt", drop = FALSE], y = mtcars[, "mpg", drop = FALSE],
  xc.cond = mtcars[1, ], model = list(model))

# }

Run the code above in your browser using DataLab