inst/doc/adas.utils.R

## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.dim=c(8, 4),
  out.width="100%"
)
library(adas.utils)
library(tidyverse)

## -----------------------------------------------------------------------------
(dm <- fp_design_matrix(2, rep=2) %>% 
  mutate(Y=rnorm(n())))

## -----------------------------------------------------------------------------
fp_design_matrix(~Speed*Weight)

## -----------------------------------------------------------------------------
fp_design_matrix(2) %>% 
  fp_add_names(A="Temperature", B="Pressure") %>%
  fp_add_scale(A=c(20, 25), B=c(75, 125), suffix=".scaled")

## -----------------------------------------------------------------------------
fp_design_matrix(2, levels=-1:1)

## -----------------------------------------------------------------------------
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)

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")

## -----------------------------------------------------------------------------
fp_design_matrix(3) %>%
  fp_augment_center(rep=4)

## -----------------------------------------------------------------------------
fp_design_matrix(3) %>% 
  fp_augment_center(rep=3) %>% 
  fp_augment_axial(rep=2)

## -----------------------------------------------------------------------------
fp <- fp_design_matrix(2, rep=3)

## -----------------------------------------------------------------------------
fp$Y <- ccd_experiment_yield$base

## -----------------------------------------------------------------------------
fp %>% 
  lm(Y ~ A*B, data=.) %>% 
  anova()

## -----------------------------------------------------------------------------
fpc <- fp %>% 
  fp_augment_center(rep=4)

fpc$Y[fpc$.treat == "center"] <- ccd_experiment_yield$center

## -----------------------------------------------------------------------------
fpc %>% 
  lm(Y ~ A*B+I(A^2), data=.) %>% 
  anova()

## -----------------------------------------------------------------------------
fpccd <- fpc %>% 
  fp_augment_axial(rep=2)

fpccd$Y[fpccd$.treat == "axial"] <- ccd_experiment_yield$axial

fpccd %>% 
  lm(Y ~ A*B*I(A^2)*I(B^2), data=.) %>% 
  anova()

## -----------------------------------------------------------------------------
fpccd %>% 
  lm(Y ~ A*B+I(A^2), data=.) %>% 
  summary()

## ----eval=FALSE---------------------------------------------------------------
# dm <-  fp_design_matrix(2) %>%
#   fp_add_names(A="Temperature", B="Pressure") %>%
#   fp_add_scale(A=c(2, 12), B=c(40, 60), suffix="_s") %>%
#   fp_write_csv("design_matrix.csv")

## ----eval=FALSE---------------------------------------------------------------
# dm <- dm %>%
#   fp_read_csv("design_matrix.csv")

## -----------------------------------------------------------------------------
fp_design_matrix(5) %>% 
  fp_fraction(~A*B*C*D) %>% 
  fp_fraction(~B*C*D*E)

## -----------------------------------------------------------------------------
fp_design_matrix(3) %>% 
  fp_fraction(~A*B*C, remove=FALSE)

## -----------------------------------------------------------------------------
(am <- fp_alias_matrix(~A*B*C, ~B*C*D))

## -----------------------------------------------------------------------------
am %>% plot()

## -----------------------------------------------------------------------------
am %>% as_tibble()

## ----warning=FALSE------------------------------------------------------------
df <- tibble(
  xn = rnorm(100, mean=20, sd=5),
  xu = runif(100, min=0, max=40)
)

df %>% normplot(xn)
df %>% normplot(xu)

## -----------------------------------------------------------------------------
set.seed(1)
tibble(
  val=rnorm(10, sd=5),
  cat=LETTERS[1:length(val)]
  ) %>%
  pareto_chart(labels=cat, values=val)

## -----------------------------------------------------------------------------
filtration %>% 
  lm(Y~A*B*C*D, data=.) %>%
  pareto_chart()

## -----------------------------------------------------------------------------
daniel_plot_qq(lm(Y~A*B*C*D, data=filtration))

## -----------------------------------------------------------------------------
filtration %>% 
  lm(Y~A*B*C*D, data=.) %>%
  daniel_plot_hn(nlab=6, repel=TRUE)


## -----------------------------------------------------------------------------
filtration %>% 
  lm(Y~A*C*D, data=.) %>%
  anova()

## -----------------------------------------------------------------------------
data <- battery %>%
  mutate(Material = LETTERS[Material])

data.t <- data %>%
  filter(Material == "A") %>%
  aov(Response~Temperature, data=.) %>%
  TukeyHSD()

data.t

data.t %>% plot()

## -----------------------------------------------------------------------------
data.t %>%
  ggTukey()

## -----------------------------------------------------------------------------
data %>%
  filter(Material == "A") %>%
  ggTukey(Response~Temperature)

## -----------------------------------------------------------------------------
data %>% 
  ggTukey(Response~Temperature, splt=~Material)

## -----------------------------------------------------------------------------
examples_url("battery.dat") %>%  read.table(header=TRUE)

## -----------------------------------------------------------------------------
p <- 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)

fp %>% 
  add_predictions(fp.lm, interval="confidence") %>% 
  mutate(B=factor(B)) %>% 
  ggplot(aes(x=A, y=fit, color=B)) + 
  geom_ribbon(aes(ymin=lwr, ymax=upr), alpha=1/3) +
  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")

Try the adas.utils package in your browser

Any scripts or data that you put into this service are public.

adas.utils documentation built on Nov. 15, 2025, 1:08 a.m.