| Title: | Design of Experiments and Factorial Plans Utilities |
|---|---|
| Description: | A number of functions to create and analyze factorial plans according to the Design of Experiments (DoE) approach, with the addition of some utility function to perform some statistical analyses. DoE approach follows the approach in "Design and Analysis of Experiments" by Douglas C. Montgomery (2019, ISBN:978-1-119-49244-3). The package also provides utilities used in the course "Analysis of Data and Statistics" at the University of Trento, Italy. |
| Authors: | Paolo Bosetti [aut, cre] |
| Maintainer: | Paolo Bosetti <[email protected]> |
| License: | CC BY 4.0 |
| Version: | 1.4.0 |
| Built: | 2026-05-24 07:13:56 UTC |
| Source: | https://github.com/pbosetti/adas.utils |
Add predictions to a data frame
add_predictions(data, model, var = "pred", type = NULL, ...) spread_predictions(data, ..., type = NULL) gather_predictions(data, ..., .pred = "pred", .model = "model", type = NULL)add_predictions(data, model, var = "pred", type = NULL, ...) spread_predictions(data, ..., type = NULL) gather_predictions(data, ..., .pred = "pred", .model = "model", type = NULL)
data |
A data frame used to generate the predictions. |
model |
|
var |
The name of the output column, default value is |
type |
Prediction type, passed on to |
... |
|
.pred, .model
|
The variable names used by |
A data frame. add_prediction adds a single new column,
with default name pred, to the input data.
spread_predictions adds one column for each model. gather_predictions
adds two columns .model and .pred, and repeats the input rows for each
model.
df <- tibble::tibble( x = sort(runif(100)), y = 5 * x + 0.5 * x ^ 2 + 3 + rnorm(length(x)) ) plot(df) m1 <- lm(y ~ x, data = df) grid <- data.frame(x = seq(0, 1, length = 10)) grid %>% add_predictions(m1) # To also get confidence bands: grid %>% add_predictions(m1, interval="confidence", level=0.99) m2 <- lm(y ~ poly(x, 2), data = df) grid %>% spread_predictions(m1, m2) grid %>% gather_predictions(m1, m2)df <- tibble::tibble( x = sort(runif(100)), y = 5 * x + 0.5 * x ^ 2 + 3 + rnorm(length(x)) ) plot(df) m1 <- lm(y ~ x, data = df) grid <- data.frame(x = seq(0, 1, length = 10)) grid %>% add_predictions(m1) # To also get confidence bands: grid %>% add_predictions(m1, interval="confidence", level=0.99) m2 <- lm(y ~ poly(x, 2), data = df) grid %>% spread_predictions(m1, m2) grid %>% gather_predictions(m1, m2)
Add residuals to a data frame
add_residuals(data, model, var = "resid") spread_residuals(data, ...) gather_residuals(data, ..., .resid = "resid", .model = "model")add_residuals(data, model, var = "resid") spread_residuals(data, ...) gather_residuals(data, ..., .resid = "resid", .model = "model")
data |
A data frame used to generate the residuals |
model, var
|
|
... |
|
.resid, .model
|
The variable names used by |
A data frame. add_residuals adds a single new column,
.resid, to the input data. spread_residuals adds
one column for each model. gather_predictions adds two columns
.model and .resid, and repeats the input rows for
each model.
df <- tibble::tibble( x = sort(runif(100)), y = 5 * x + 0.5 * x ^ 2 + 3 + rnorm(length(x)) ) plot(df) m1 <- lm(y ~ x, data = df) df %>% add_residuals(m1) m2 <- lm(y ~ poly(x, 2), data = df) df %>% spread_residuals(m1, m2) df %>% gather_residuals(m1, m2)df <- tibble::tibble( x = sort(runif(100)), y = 5 * x + 0.5 * x ^ 2 + 3 + rnorm(length(x)) ) plot(df) m1 <- lm(y ~ x, data = df) df %>% add_residuals(m1) m2 <- lm(y ~ poly(x, 2), data = df) df %>% spread_residuals(m1, m2) df %>% gather_residuals(m1, m2)
Given an alias matrix, this function returns a tidy tibble of the
alias structures, with the added generator column containing the generator
(i.e. right-hand side) of the defining relationship that generates each
alias.
## S3 method for class 'alias.matrix' as_tibble(x, ..., compact = TRUE)## S3 method for class 'alias.matrix' as_tibble(x, ..., compact = TRUE)
x |
the alias matrix object. |
... |
additional arguments to |
compact |
a logical: if TRUE, it reports all possible effects combinations, even those with no alias. |
a tibble representation of the alias matrix
tibble::as_tibble(fp_alias_matrix(~A*B*C, ~B*C*D))tibble::as_tibble(fp_alias_matrix(~A*B*C, ~B*C*D))
Battery life in hour of a factorial experiment with 2 factors and 3 levels each. Factors are:
batterybattery
A data frame with 36 rows and 6 columns
Temperature: of the battery during the discharge experiment
Material: Plate material for the battery
Other columns are:
StandardOrder: Yate's standard order
RunOrder: randomized order, in which tests have been executed
Repeat: repeat number
Response: battery life in hours
Douglas C. Montgomery, "Design and Analysis of Experiments", 8th edition, Wiley, 2019
Yield data for a two factor CCD experiment
ccd_experiment_yieldccd_experiment_yield
A list with three vectors:
base: the yield for a 2^2 factorial design, replicated 3 times
center: the yield for the center points, replicated 4 times
axial: the yield for the axial points, replicated 2 times
Applies the Chauvenet's criterion to a sample, identifying a possible outlier.
chauvenet(x, threshold = 0.5)chauvenet(x, threshold = 0.5)
x |
the sample vector. |
threshold |
the threshold for the frequency of the suspect outlier. |
an object of class chauvenet with the following components:
samplethe name of the sample
s0the maximum difference
indexthe index of the suspect outlier
valuethe value of the suspect outlier
expectedthe expected frequency of the suspect outlier
rejecta logical value indicating whether the suspect outlier should be rejected
x <- rnorm(100) chauvenet(x) chauvenet(x, threshold=0.1)x <- rnorm(100) chauvenet(x) chauvenet(x, threshold=0.1)
Yarn tensile strength in a completely randomized experiment with 5 different levels of cotton fiber.
cottoncotton
A data frame with 25 rows and 3 columns. Columns represent:
Run: run order
Cotton: cotton content in mass percentage
Strength: yarn tensile strength in N
Douglas C. Montgomery, "Design and Analysis of Experiments", 8th edition, Wiley, 2019
Given a non-replicated model of a factorial plan, this function provides a half-normal plot of the effects of the model, labeling the main n effects.
daniel_plot_hn(model, label_n = 6, line.p = c(0, 0.4), ...)daniel_plot_hn(model, label_n = 6, line.p = c(0, 0.4), ...)
model |
a linear model |
label_n |
plot the labels of the highest n values |
line.p |
vector of quantiles to use when fitting the Q-Q line, defaults defaults to 0.25 that corresponds to c(0.25, 0.75) on the full set of quantiles. If you pass a vector of two elements (first MUST be 0), then the line is fitted through the origin and up to 1 minus the second element quantile |
... |
further arguments to |
a half-normal plot (GGPlot2 object) with the effects of the model
daniel_plot_hn(lm(Y~A*B*C*D, data=filtration))daniel_plot_hn(lm(Y~A*B*C*D, data=filtration))
Given a non-replicated model of a factorial plan, this function provides a QQ plot of the effects of the model, labeling all the effects.
daniel_plot_qq(model, alpha = 0.5, xlim = c(-3, 3))daniel_plot_qq(model, alpha = 0.5, xlim = c(-3, 3))
model |
a linear model |
alpha |
the transparency of the horizontal lines |
xlim |
the limits of the x-axis |
a QQ plot (GGPlot2 object) with the effects of the model
daniel_plot_qq(lm(Y~A*B*C*D, data=filtration))daniel_plot_qq(lm(Y~A*B*C*D, data=filtration))
Provides the URL for the desired example data, so that it can be more easily downloaded.
examples_url(example)examples_url(example)
example |
data file name |
the full URL for the desired example
examples_url("battery.dat") |> read.table(header=TRUE)examples_url("battery.dat") |> read.table(header=TRUE)
Expand a formula
expand_formula(f)expand_formula(f)
f |
a formula |
a formula after expansion, e.g. Y ~ A + B becomes Y ~ A + B + A:B
expand_formula(Y ~ (A + B)^3)expand_formula(Y ~ (A + B)^3)
Non-replicated factorial plan for a slurry filtration process.
filtrationfiltration
Factors are:
A: Temperature
B: Pressure
C: Concentration of solid phase
D: Agitation speed
The yield is in column Y and represents the filtration speed
Store factor names in the factorial.plan object, as a list within the
factor.names attribute.
fp_add_names(dm, ...)fp_add_names(dm, ...)
dm |
the design matrix. |
... |
a set of factors to name, with their respective names, e.g.
|
the design matrix with the named factors.
fp_design_matrix(3, rep=2) %>% fp_add_names(A="Temperature", B="Pressure")fp_design_matrix(3, rep=2) %>% fp_add_names(A="Temperature", B="Pressure")
This function allows to add columns to a design matrix with scaled factor, i.e. factors reported in real units rather in coded units (e.g. -1, 1).
fp_add_scale(dm, ..., suffix = "_s")fp_add_scale(dm, ..., suffix = "_s")
dm |
the design matrix to scale. |
... |
a set of factors to scale, with their respective ranges, e.g.
|
suffix |
the suffix to add to the scaled factor name in creating new columns. If the suffix is the empty string, factors are replaced. |
the design matrix with the scaled factors.
fp_design_matrix(3, rep=2) %>% fp_add_scale(A=c(10, 30), B=c(0, 1), suffix=".scaled")fp_design_matrix(3, rep=2) %>% fp_add_scale(A=c(10, 30), B=c(0, 1), suffix=".scaled")
Given a Defining relationship or a number of factors, this function builds a matrix of aliases.
fp_alias(arg)fp_alias(arg)
arg |
A formula or a number of factors. |
Defining relationships are represented as one side formulas, e.g. $I=ABC$
becomes ~A*B*C.
A matrix of logical values.
fp_alias(~A*B*C*D) fp_alias(3)fp_alias(~A*B*C*D) fp_alias(3)
Given a defining relationship, as a one side firmula,, this function lists all the aliases for a fractional factorial plan.
fp_alias_list(arg)fp_alias_list(arg)
arg |
A formula for the defining relationship, or the number of factors. |
Defining relationships are represented as one side formulas, e.g. $I=ABC$
becomes ~A*B*C.
a list of aliases (as formulas).
fp_alias_list(~A*B*C*D)fp_alias_list(~A*B*C*D)
Given a list of formulas (defining relationships), this function returns a matrix of all possible aliases.
fp_alias_matrix(...)fp_alias_matrix(...)
... |
one or more formulas, or a single list of formulas, or a fractional factorial plan. |
It is also possible to pass a fractional factorial plan, in which case the defining relationships will be extracted from it.
a square matrix: each cell is 0 if there is no alias, or an
integer representing the index of the generator that produced that alias
in the list of generators.
# with formulas: fp_alias_matrix(~A*B*C, ~B*C*D) # with a fractional factorial plan: fp_design_matrix(5) %>% fp_fraction(~A*B*C*D) %>% fp_fraction(~B*C*D*E) %>% fp_alias_matrix() %>% plot()# with formulas: fp_alias_matrix(~A*B*C, ~B*C*D) # with a fractional factorial plan: fp_design_matrix(5) %>% fp_fraction(~A*B*C*D) %>% fp_fraction(~B*C*D*E) %>% fp_alias_matrix() %>% plot()
Given two or more independent refining relationships, represented as one side formulas,, this function returns a list of all possible defining relationships, including the dependent ones.
fp_all_drs(...)fp_all_drs(...)
... |
formulas, or a single list of formulas. |
Defining relationships are represented as one side formulas, e.g. $I=ABC$
becomes ~A*B*C.
a list of formulas.
fp_all_drs(~A*B*C, ~B*C*D)fp_all_drs(~A*B*C, ~B*C*D)
Adds the axial points to a $2^n$ centered factorial plan.
fp_augment_axial(dm, rep = 1)fp_augment_axial(dm, rep = 1)
dm |
A factorial plan table, with central points. |
rep |
The number of replications. |
A central composite design (a factorial.plan object).
fp_design_matrix(3) %>% fp_augment_center(rep=4) %>% fp_augment_axial()fp_design_matrix(3) %>% fp_augment_center(rep=4) %>% fp_augment_axial()
Add the central points to an existing $2^n$ factorial plan.
fp_augment_center(dm, rep = 5)fp_augment_center(dm, rep = 5)
dm |
A factorial plan table. |
rep |
The number of replications. |
A central composite design (a factorial.plan object).
fp_design_matrix(3) %>% fp_augment_center()fp_design_matrix(3) %>% fp_augment_center()
Builds a formula from a number of factors
fp_defrel(arg)fp_defrel(arg)
arg |
If it is a formula, it is returned verbatim. If it is a number, a formula is built with the number of factors. If it is neither a formula nor a number, an error is thrown. |
A formula.
# Defining relationships with three factors fp_defrel(3) # Defining relationship I=ABC fp_defrel(~A*B*C)# Defining relationships with three factors fp_defrel(3) # Defining relationship I=ABC fp_defrel(~A*B*C)
Builds a design matrix from a one side formula or a number of factors.
fp_design_matrix(arg, rep = 1, levels = c(-1, 1))fp_design_matrix(arg, rep = 1, levels = c(-1, 1))
arg |
Either a formula or a number of factors. If it is a formula, the
factors are extracted from it. If it is a number, the factors are the first
|
rep |
Number of replications. |
levels |
Levels of the factors. |
Defining relationships are represented as one side formulas, e.g. $I=ABC$
becomes ~A*B*C.
A design matrix: a subclass of a tibble of class factorial.plan.
The class has the following attributes:
def.relThe defining relationship (a formula).
generatorsThe list of generators (formulas) if the factorial plan is fractional.
fractionThe list of fractions (character vectors) if the factorial plan is fractional.
levelsThe levels of the factors (all equal), in coded units.
scalesA list: for each factor, a vector of two values corresponding to the extreme values in coded units.
fp_design_matrix(3, rep=2, levels=c("-", "+"))fp_design_matrix(3, rep=2, levels=c("-", "+"))
Returns the effect names from a formula, according to Yates' convention.
fp_effect_names(arg)fp_effect_names(arg)
arg |
A formula. |
Defining relationships are represented as one side formulas, e.g. $I=ABC$
becomes ~A*B*C.
An ordered factor with the effect names.
fp_effect_names(~A*B*C)fp_effect_names(~A*B*C)
Reduce a Factorial Plan by 1/2 Fraction
fp_fraction(dm, formula, remove = TRUE)fp_fraction(dm, formula, remove = TRUE)
dm |
A factorial plan table. |
formula |
A formula for the defining relationship. |
remove |
A logical value indicating if the removed columns should be
removed. This setting is sticky: if it is FALSE and you pipe the result of
this function to another |
A reduced factorial plan table (a factorial.plan object).
# build a 2^5-2 fractional factorial plan with defining relationships # I=ABCD and I=BCDE fp_design_matrix(5) %>% fp_fraction(~A*B*C*D) %>% fp_fraction(~B*C*D*E)# build a 2^5-2 fractional factorial plan with defining relationships # I=ABCD and I=BCDE fp_design_matrix(5) %>% fp_fraction(~A*B*C*D) %>% fp_fraction(~B*C*D*E)
Given a generator and an effect, this function returns the alias.
fp_gen2alias(generator, effect)fp_gen2alias(generator, effect)
generator |
a generator, in the form of |
effect |
an effect, in the form of |
Generators and aliases are strings of capital letters.
An effect (string).
fp_gen2alias("ABCD", "BD")fp_gen2alias("ABCD", "BD")
Print information about the factorial plan.
fp_info(x, file = "", comment = "")fp_info(x, file = "", comment = "")
x |
the factorial plan. |
file |
the file to write the information to. Use console if empty. |
comment |
a comment mark to add before each line of the information. |
No return value, just prints the fp information.
fp_design_matrix(3, rep=2) %>% fp_info()fp_design_matrix(3, rep=2) %>% fp_info()
This function, given one or more independent refining relationships, returns the most complete relationship, i.e. that which includes all the factors.
fp_merge_drs(f1, ...)fp_merge_drs(f1, ...)
f1 |
a formula. |
... |
other formulas. |
Defining relationships are represented as one side formulas, e.g. $I=ABC$
becomes ~A*B*C.
a formula.
fp_merge_drs(~A*B*C, ~B*C*D)fp_merge_drs(~A*B*C, ~B*C*D)
This is a utility function mostly for internal use.
fp_name(fp, fct)fp_name(fp, fct)
fp |
The factorial plan object |
fct |
The standard name of the factor as a string (e.g. |
A string with the factor full name, if available (must have been
added with fp_add_names). If not, it returns fct ditto.
df <- fp_design_matrix(2) %>% fp_add_names(A="Temperature", B="Pressure") fp_name(df, "A")df <- fp_design_matrix(2) %>% fp_add_names(A="Temperature", B="Pressure") fp_name(df, "A")
Load from a CSV file the design matrix that has previously been saved with
fp_write_csv(). It is an error if the loaded data frame has different
dimensions or column names than the original design matrix.
fp_read_csv(dm, file, type = c(1, 2), yield = "Y", comment = "#")fp_read_csv(dm, file, type = c(1, 2), yield = "Y", comment = "#")
dm |
the design matrix. |
file |
the file to read the design matrix from. |
type |
the CSV version (1 or 2). |
yield |
the yield column name. |
comment |
the comment mark. |
Note that the design matrix is sorted by the StdOrder column after loading.
the design matrix with the new values.
This is a utility function mostly for internal use.
fp_scale(fp, fct)fp_scale(fp, fct)
fp |
The factorial plan object |
fct |
The standard name of the factor as a string (e.g. |
A vector representing the factor range in scaled units; scales
must have been added with fp_add_scale. If scales are not
available, the range in coded units is returned (i.e. c(-1,1))
df <- fp_design_matrix(2) %>% fp_add_names(A="Temperature", B="Pressure") %>% fp_add_scale(A=c(20,30), B=c(3, 7)) fp_scale(df, "A")df <- fp_design_matrix(2) %>% fp_add_names(A="Temperature", B="Pressure") %>% fp_add_scale(A=c(20,30), B=c(3, 7)) fp_scale(df, "A")
This is useful when creating contour plots for the FP response surface or factors interaction plots. It allows to add secondary axes that use the scaled factor units rather than the coded units (in range -1, 1).
fp_scaled_axis(fp, fct)fp_scaled_axis(fp, fct)
fp |
The factorial plan object |
fct |
The standard name of the factor as a string (e.g. |
A ggplot2::sec_axis object
library(tidyverse) fp <- fp_design_matrix(2, rep=3) %>% fp_add_names(A="Temperature (°C)", B="Pressure (bar)") %>% fp_add_scale(A=c(20,30), B=c(2, 3)) fp$Y <- ccd_experiment_yield$base fp.lm <- lm(Y~A*B, data=fp) # Interaction plot: fp %>% mutate( pred = predict(fp.lm), B=factor(B) ) %>% ggplot(aes(x=A, y=pred, color=B)) + geom_line() + scale_x_continuous(sec.axis = fp_scaled_axis(fp, "A"))+ scale_color_discrete(labels = fp_scale(fp, "B")) + labs(color=fp_name(fp, "B"), y="Yield") expand.grid( A = seq(-1, 1, length.out=100), B = seq(-1, 1, length.out=100) ) %>% { mutate(., Y=predict(fp.lm, newdata=.)) } %>% ggplot(aes(x=A, y=B, z=Y)) + geom_contour_filled() + scale_x_continuous(sec.axis = fp_scaled_axis(fp, "A")) + scale_y_continuous(sec.axis = fp_scaled_axis(fp, "B")) + labs(fill="Yield")library(tidyverse) fp <- fp_design_matrix(2, rep=3) %>% fp_add_names(A="Temperature (°C)", B="Pressure (bar)") %>% fp_add_scale(A=c(20,30), B=c(2, 3)) fp$Y <- ccd_experiment_yield$base fp.lm <- lm(Y~A*B, data=fp) # Interaction plot: fp %>% mutate( pred = predict(fp.lm), B=factor(B) ) %>% ggplot(aes(x=A, y=pred, color=B)) + geom_line() + scale_x_continuous(sec.axis = fp_scaled_axis(fp, "A"))+ scale_color_discrete(labels = fp_scale(fp, "B")) + labs(color=fp_name(fp, "B"), y="Yield") expand.grid( A = seq(-1, 1, length.out=100), B = seq(-1, 1, length.out=100) ) %>% { mutate(., Y=predict(fp.lm, newdata=.)) } %>% ggplot(aes(x=A, y=B, z=Y)) + geom_contour_filled() + scale_x_continuous(sec.axis = fp_scaled_axis(fp, "A")) + scale_y_continuous(sec.axis = fp_scaled_axis(fp, "B")) + labs(fill="Yield")
Builds a list of treatments from a formula, or from a number of factors.
fp_treatments(arg)fp_treatments(arg)
arg |
Either a formula or a number of factors. If it is a formula, the
factors are extracted from it. If it is a number, the factors are the first
|
Defining relationships are represented as one side formulas, e.g. $I=ABC$
becomes ~A*B*C.
A list of treatments (character vector).
fp_treatments(3)fp_treatments(3)
Writes the design matrix to a CSV file, with a timestamp and comment lines.
fp_write_csv(dm, file, comment = "# ", timestamp = TRUE, type = c(1, 2), ...)fp_write_csv(dm, file, comment = "# ", timestamp = TRUE, type = c(1, 2), ...)
dm |
the design matrix. |
file |
the file to write the design matrix to. |
comment |
a comment mark to add before each line of the information. |
timestamp |
whether to add a timestamp to the file. |
type |
the CSV version (1 or 2). |
... |
other parameters passed to write_csv(). |
Note that the design matrix is saved in the same order of the RunOrder
column, i.e. random.
Invisibly return the design matrix, unchanged, for further piping.
geom_pareto_bars() draws a Pareto-style bar layer:
values are sorted by decreasing absolute y, bars are drawn with absolute
heights, and a computed fill indicates the original sign ("positive" or
"negative").
geom_pareto_bars( mapping = NULL, data = NULL, stat = "pareto_bars", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) stat_pareto_bars( mapping = NULL, data = NULL, geom = "col", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )geom_pareto_bars( mapping = NULL, data = NULL, stat = "pareto_bars", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) stat_pareto_bars( mapping = NULL, data = NULL, geom = "col", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the layer. |
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom |
The geometric object to use display the data. |
geom_pareto_line() computes cumulative totals from absolute values sorted by
decreasing magnitude and draws the resulting path.
geom_pareto_point() computes cumulative totals from absolute values sorted
by decreasing magnitude and draws the resulting points.
geom_pareto_line( mapping = NULL, data = NULL, stat = "pareto_line", position = "identity", ..., cumulative = c("raw", "proportion"), na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_pareto_point( mapping = NULL, data = NULL, stat = "pareto_line", position = "identity", ..., cumulative = c("raw", "proportion"), na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) stat_pareto_line( mapping = NULL, data = NULL, geom = "path", position = "identity", ..., cumulative = c("raw", "proportion"), na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )geom_pareto_line( mapping = NULL, data = NULL, stat = "pareto_line", position = "identity", ..., cumulative = c("raw", "proportion"), na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_pareto_point( mapping = NULL, data = NULL, stat = "pareto_line", position = "identity", ..., cumulative = c("raw", "proportion"), na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) stat_pareto_line( mapping = NULL, data = NULL, geom = "path", position = "identity", ..., cumulative = c("raw", "proportion"), na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the layer. |
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
cumulative |
|
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom |
The geometric object to use display the data. |
geom_qqhn() draws a half-normal QQ plot using absolute sample values.
Theoretical quantiles are from the half-normal distribution, i.e.
qnorm((p + 1) / 2).
geom_qqhn( mapping = NULL, data = NULL, stat = "qqhn", position = "identity", ..., abs_sample = TRUE, label_n = 0, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) stat_qqhn( mapping = NULL, data = NULL, geom = "point", position = "identity", ..., abs_sample = TRUE, label_n = 0, labels_var = NULL, output = c("all", "points", "labels"), na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )geom_qqhn( mapping = NULL, data = NULL, stat = "qqhn", position = "identity", ..., abs_sample = TRUE, label_n = 0, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) stat_qqhn( mapping = NULL, data = NULL, geom = "point", position = "identity", ..., abs_sample = TRUE, label_n = 0, labels_var = NULL, output = c("all", "points", "labels"), na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the layer. |
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
abs_sample |
Should the sample be converted to absolute values. Defaults
to |
label_n |
Number of largest points to label. These labeled points are
removed from the point layer and drawn as text labels. Label text is taken
from the |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom |
The geometric object to use display the data. |
labels_var |
Internal parameter used to forward label-column mappings. |
output |
Internal parameter controlling whether |
geom_qqhn_band() adds a confidence envelope around the half-normal QQ
reference line. The envelope is built from order-statistic probabilities
mapped through half-normal quantiles and then transformed by the fitted QQHN
line.
geom_qqhn_band( mapping = NULL, data = NULL, stat = "qqhn_band", position = "identity", ..., line.p = 0.25, abs_sample = TRUE, conf.level = 0.95, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) stat_qqhn_band( mapping = NULL, data = NULL, geom = "ribbon", position = "identity", ..., line.p = 0.25, abs_sample = TRUE, conf.level = 0.95, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )geom_qqhn_band( mapping = NULL, data = NULL, stat = "qqhn_band", position = "identity", ..., line.p = 0.25, abs_sample = TRUE, conf.level = 0.95, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) stat_qqhn_band( mapping = NULL, data = NULL, geom = "ribbon", position = "identity", ..., line.p = 0.25, abs_sample = TRUE, conf.level = 0.95, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the layer. |
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
line.p |
A single probability |
abs_sample |
Should the sample be converted to absolute values. Defaults
to |
conf.level |
Confidence level for the envelope. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom |
The geometric object to use display the data. |
Use conf.level to control envelope coverage (for example 0.95); alpha
only controls ribbon transparency.
geom_qqhn_line() adds a reference line for a half-normal QQ plot.
It mirrors geom_qq_line() but uses half-normal theoretical quantiles.
geom_qqhn_line( mapping = NULL, data = NULL, stat = "qqhn_line", position = "identity", ..., line.p = 0.25, abs_sample = TRUE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) stat_qqhn_line( mapping = NULL, data = NULL, geom = "path", position = "identity", ..., line.p = 0.25, abs_sample = TRUE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )geom_qqhn_line( mapping = NULL, data = NULL, stat = "qqhn_line", position = "identity", ..., line.p = 0.25, abs_sample = TRUE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) stat_qqhn_line( mapping = NULL, data = NULL, geom = "path", position = "identity", ..., line.p = 0.25, abs_sample = TRUE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the layer. |
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
line.p |
A single probability |
abs_sample |
Should the sample be converted to absolute values. Defaults
to |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom |
The geometric object to use display the data. |
This is a generic function for plotting Tukey's HSD test via GGplot2.
ggTukey(obj, ...)ggTukey(obj, ...)
obj |
an object to plot: either a TukeyHSD object or a data frame |
... |
Other parameters passed to the specialized functions |
a GGPlot2 object
ggTukey for data.frame
## S3 method for class 'data.frame' ggTukey(obj, formula, which = 1, splt = NULL, ...)## S3 method for class 'data.frame' ggTukey(obj, formula, which = 1, splt = NULL, ...)
obj |
a data frame |
formula |
a formula to be used in the aov call |
which |
the index of the comparison. Used when the formula in the undelying aov call has more than one term. |
splt |
a formula to split the data frame |
... |
further parameters passed to |
a GGPlot2 object
library(tidyverse) battery %>% ggTukey(Response~Material, splt=~Temperature, conf.level=0.99)library(tidyverse) battery %>% ggTukey(Response~Material, splt=~Temperature, conf.level=0.99)
Plot Tukey's HSD test via GGplot2.
## S3 method for class 'TukeyHSD' ggTukey(obj, which = 1, ...)## S3 method for class 'TukeyHSD' ggTukey(obj, which = 1, ...)
obj |
a TukeyHSD object |
which |
the index of the comparison. Used when the formula in the undelying aov call has more than one term. |
... |
further parameters (currently unused) |
a GGPlot2 object
TukeyHSD() ggTukey.data.frame() ggTukey.TukeyHSD()]]
library(tidyverse) cotton %>% aov(Strength~Cotton, data=.) %>% TukeyHSD() %>% ggTukey()library(tidyverse) cotton %>% aov(Strength~Cotton, data=.) %>% TukeyHSD() %>% ggTukey()
Normal probability plot
normplot(data, var, breaks = seq(0.1, 0.9, 0.1), linecolor = "red")normplot(data, var, breaks = seq(0.1, 0.9, 0.1), linecolor = "red")
data |
a data frame |
var |
the variable to plot ( |
breaks |
the breaks for the y-axis |
linecolor |
the color of the normal probability line |
a normal probability plot (GGPlot2 object)
library(tibble) df <- tibble( xn = rnorm(100, mean=20, sd=5), xu = runif(100, min=0, max=40) ) df %>% normplot(xn) df %>% normplot(xu)library(tibble) df <- tibble( xn = rnorm(100, mean=20, sd=5), xu = runif(100, min=0, max=40) ) df %>% normplot(xn) df %>% normplot(xu)
This is a generic function for Pareto's chart.
pareto_chart(obj, ...)pareto_chart(obj, ...)
obj |
an object |
... |
further parameters to specialized functions |
a Pareto chart of the effects of the model
pareto_chart.data.frame() pareto_chart.lm()
# For a data frame: library(tibble) set.seed(1) tibble( val=rnorm(10, sd=5), cat=LETTERS[1:length(val)] ) %>% pareto_chart(labels=cat, values=val) # For a linear model: pareto_chart(lm(Y~A*B*C*D, data=filtration))# For a data frame: library(tibble) set.seed(1) tibble( val=rnorm(10, sd=5), cat=LETTERS[1:length(val)] ) %>% pareto_chart(labels=cat, values=val) # For a linear model: pareto_chart(lm(Y~A*B*C*D, data=filtration))
Create a Pareto chart for a data frame.
## S3 method for class 'data.frame' pareto_chart(obj, labels, values, ...)## S3 method for class 'data.frame' pareto_chart(obj, labels, values, ...)
obj |
a data frame |
labels |
the column with the labels of the data frame |
values |
the column with the values of the data frame |
... |
further parameters (currently unused) |
a Pareto chart (GGPlot2 object) of the data frame
Invisibly returns a data frame with the absolute values of the data frame, their sign, and the cumulative value.
library(tibble) set.seed(1) tibble( val=rnorm(10, sd=5), cat=LETTERS[1:length(val)] ) %>% pareto_chart(labels=cat, values=val)library(tibble) set.seed(1) tibble( val=rnorm(10, sd=5), cat=LETTERS[1:length(val)] ) %>% pareto_chart(labels=cat, values=val)
Creates a Pareto chart for the effects of a linear model.
## S3 method for class 'lm' pareto_chart(obj, ...)## S3 method for class 'lm' pareto_chart(obj, ...)
obj |
a linear model |
... |
further parameters (currently unused) |
a Pareto chart (GGPlot2 object) of the effects of the model
Invisibly returns a data frame with the absolute effects of the model, their sign, and the cumulative effect.
pareto_chart(lm(Y~A*B*C*D, data=filtration))pareto_chart(lm(Y~A*B*C*D, data=filtration))
Produces a tile plot of the alias matrix.
## S3 method for class 'alias.matrix' plot(x, ..., compact = TRUE)## S3 method for class 'alias.matrix' plot(x, ..., compact = TRUE)
x |
an alias matrix. |
... |
additional arguments to |
compact |
logical, if TRUE only positive aliases are shown, omitting empty rows and columns. |
a ggplot object.
fp_alias_matrix(~A*B*C, ~B*C*D) %>% plot()fp_alias_matrix(~A*B*C, ~B*C*D) %>% plot()
scale_y_pareto() configures a primary y-axis for absolute values and a
secondary right-side axis that maps cumulative totals to percentages.
scale_y_pareto( sum_abs = NULL, name = ggplot2::waiver(), percent_name = "Cumulative (%)", ... )scale_y_pareto( sum_abs = NULL, name = ggplot2::waiver(), percent_name = "Cumulative (%)", ... )
sum_abs |
Total absolute value used for percentage conversion, typically
|
name |
Primary y-axis label. |
percent_name |
Secondary y-axis label. |
... |
Additional arguments passed to |
Use this with geom_pareto_line(cumulative = "raw") so the cumulative line
ends at 100% on the secondary axis.