Main Content

maineffectsplot

Main effects plot for grouped data

Description

maineffectsplot(Y,group) creates a main effect plot for the group means of Y with groups defined by the entries in group. Each subplot shows the group means of Y as a function of one grouping variable.

maineffectsplot(Y,group,Name=Value) specifies additional options using one or more name-value arguments. For example, you can specify the grouping variable names, and the statistic to plot.

example

[h,ax]=maineffectsplot(___) returns graphics handles to the figure window in h and the individual plots in ax, using any of the input argument combinations in the previous syntaxes.

example

Examples

collapse all

Load the carsmall data set.

load carsmall;

Create a main effects plot for car weight with two grouping variables: model year and number of cylinders.

maineffectsplot(Weight,{Model_Year,Cylinders}, ...
               VarNames=["Model Year","# of Cylinders"])

Figure contains 2 axes objects. Axes object 1 with xlabel Model Year, ylabel mean contains an object of type line. Axes object 2 with xlabel # of Cylinders contains an object of type line.

The first subplot shows that mean car weight decreases with increasing model year. The second subplot shows that mean car weight sharply increases with the number of cylinders.

Load the carsmall data set.

load carsmall;

Create a matrix Y that contains the Weight predictor data and four simulated sets of noisy Weight observations.

rng(0,"twister") % For reproducibility
noise_std = 10;
Y = [Weight, ...
    Weight+noise_std*randn(size(Weight)), ...
    Weight+noise_std*randn(size(Weight)), ...
    Weight+noise_std*randn(size(Weight)), ...
    Weight+noise_std*randn(size(Weight))];

Create a main effects plot for the car weight observations with two grouping variables, model year and number of cylinders. Plot the standard deviation of the observations.

maineffectsplot(Y,{Model_Year,Cylinders},Statistic="std", ...
               VarNames=["Model Year","# of Cylinders"])

Figure contains 2 axes objects. Axes object 1 with xlabel Model Year, ylabel standard deviation contains an object of type line. Axes object 2 with xlabel # of Cylinders contains an object of type line.

The subplots show that the standard deviation of the car weight decreases with both the model year and number of cylinders.

Input Arguments

collapse all

Input data, specified as a numeric vector or numeric matrix. If Y is a matrix, the rows represent different observations, and the columns represent replications of each observation.

Data Types: single | double

Grouping variables, specified as a cell array or numeric matrix. If group is a cell array, then each cell of group must contain a grouping variable that is a categorical variable, numeric vector, character matrix, string array, or single-column cell array of character vectors. If group is a numeric matrix, then its columns represent different grouping variables, and its rows correspond to the rows in Y. Each grouping variable must have the same number of elements as Y. The number of grouping variables must be greater than 1.

Example: {Smoker,Gender}

Data Types: categorical | single | double | char | string | cell

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: maineffectsplot(Y,group,VarNames=["Weight","MPG"}) creates a main effects plot for the group means of the matrix Y with groups defined in group, and grouping variables named "Weight" and "MPG".

Grouping variable names, specified as a character matrix, string array, or cell array of character vectors. If VarNames is a character matrix, it must have size(group,2) rows. Otherwise, Varnames must have size(group,2) elements. If you do not specify VarNames, the default names are "X1", "X2", ... .

Example: VarNames=["A","B","C","D"]

Data Types: char | string | cell

Axes handle of the plot, specified as an axes handle. If Parent is [] (the default), the function creates the plot in a new figure.

Statistic to plot, specified as "mean" or "std". When Statistic is "mean" (the default), the function plots the group means. When Statistic is "std", the function plots the group standard deviation. Y must have more than one column if you want to specify "std".

Example: Statistic="std"

Data Types: char | string

Output Arguments

collapse all

Handle to the figure window, returned as a figure handle.

Axes handles to the individual plots, returned as an array of Axes objects.

Version History

Introduced in R2006b