In R, ggnostic()
is a ggduo()
display wrapper that shows all model diagnostics for each explanatory variable. To each explanatory variable, ggduo()
presents the residuals, leave-one-out model sigma value, leverage points, and Cook’s distance by default. Fitted values, standard error of the fitted values, standardized residuals, and response variables can be added to the plot matrix’s rows. If the model is linear, stars are added to each explanatory variable based on its stats::anova
significance.
ggnostic(
model,
...,
columnsX = attr(data, "var_x"),
columnsY = c(".resid", ".sigma", ".hat", ".cooksd"),
continuous = list(default = ggally_points, .fitted = ggally_points,
.se.fit =ggally_nostic_se_fit, .resid = ggally_nostic_resid,
.hat = ggally_nostic_hat, .sigma= ggally_nostic_sigma,
.cooksd = ggally_nostic_cooksd,.std.resid=ggally_nostic_std_resid),
combo = list(default = ggally_box_no_facet,fitted=
ggally_box_no_facet, .se.fit =ggally_nostic_se_fit,
.resid = ggally_nostic_resid,
.hat = ggally_nostic_hat, .sigma= ggally_nostic_sigma,
.cooksd = ggally_nostic_cooksd,.std.resid=ggally_nostic_std_resid),
discrete = list(default = ggally_ratio, .fitted = ggally_ratio,
.se.fit =ggally_ratio, .resid = ggally_ratio,.hat=ggally_ratio,
.sigma = ggally_ratio,.cooksd = ggally_ratio, .std.resid =
ggally_ratio),
data = broomify(model)
)
model
: This is the statistical model’s object. For example, states::lm, states::glm.
...
: These are the arguments passed directly to ggduo.
ColumnX
: This represents the columns to be displayed in the plot matrix. It defaults to the prediction column of the model
.
ColumnY
: This represents the rows in the plot matrix to be presented Defaults to residuals, leave-one-out sigma value, hat matrix diagonal, and Cook’s Distance. The response variables in the model, as well as the additional columns given by broom:: augment(model)
.
continuous, combo, discrete
: These are the list of functions for each y variable.
data
: The default data is a broomified model object. This object has information about the variables X and Y. It also contains information about the multiple broom outputs.
ColumnsY
: broom: augment
collects the data from the model and returns a DataFrame with the following columns.
.resid
: Residuals are the difference between the observed and predicted values of data.
.hat
: This is the diagonal of the hat matrix (converts values from the observed variable into estimations obtained with the least-squares method).
.sigma
: This is the estimate of the residual standard deviation, when the model drops the corresponding observation.
.cooksd
: This is Cook’s distance, which is the scaled change in fitted values.
.fitted
: These are the fitted values of the model.
se.fit
: These are the standard errors of the fitted values.
std.resid
: These are the standardized residuals.
Continous, combo, discrete
: Different functions can be supplied to display the different column types. Because the Y rows are fixed, each row in each of the plot types (continuous, combo, and discrete) has its associated function.
.fitted
, .resid
, .std.resid
, .sigma
, .se.fit
, .hat
, and .cooksd
are some of the keys that correspond to the broom::augment()
output in each plot type list: .fitted
, .resid
, .std.resid
, .sigma
, .se.fit
, .hat
, .co
.
If the model’s response variables are included, an additional key called “default” is used to plot them. The diagnostics plot matrix may be fine-tuned by having a function for each diagnosis. Each type list’s functions are wrapped in a switch function that calls the function that corresponds to the plotted y variable. These switch routines are then immediately supplied to ggduo
types argument.
# Loading the packagelibrary(GGally)#estimate OLS model and create output objectmodel1 <- lm(logy ~ open + loglab + logland, data=final.85)# show model outputggnostic(model1)
Line 2: We import the required package GGally
that contains the ggnostic
function.
Line 5: We use a linear function and pass the columns of the data.85
.
Line 7: We call the ggnostic
function with all default values.
Free Resources