knitr::opts_chunk$set(echo = TRUE)
s_bwbr_path <- "https://charlotte-ngs.github.io/asmss2022/data/asm_bw_flem.csv"
s_bwbr_path <- file.path(here::here(), "docs", "data", "asm_bw_flem.csv")
tbl_bwbr <- readr::read_csv(file = s_bwbr_path)

mat_X <- model.matrix(lm(`Body Weight` ~ 0 + Breed, data = tbl_bwbr))
mat_X <- cbind(matrix(1, nrow = nrow(tbl_bwbr), ncol = 1), mat_X)
dimnames(mat_X) <- NULL
mat_xtx <- crossprod(mat_X)
mat_xtx_ginv <- MASS::ginv(mat_xtx)
vec_y <- tbl_bwbr$`Body Weight`
mat_xty <- crossprod(mat_X, vec_y)
mat_b0 <- crossprod(mat_xtx_ginv, mat_xty)

Three Topics

  1. Contrasts in R
  2. Plots
  3. Simulation

Contrasts in R

Contrasts and Estimable Functions

s_bwbr_path <- "https://charlotte-ngs.github.io/asmss2022/data/asm_bw_flem.csv"
s_bwbr_path <- file.path(here::here(), "docs", "data", "asm_bw_flem.csv")
tbl_bwbr <- readr::read_csv(file = s_bwbr_path)
(cm_treat <- contrasts(as.factor(tbl_bwbr$Breed)))

Estimable Functions

(cm_treat <- cbind(matrix(1, 
                     nrow = nrow(cm_treat),
                     ncol = 1), 
                   cm_treat))

Estimable Functions II

(em_treat <- solve(cm_treat))

Intercept

n_mean_angus <- mean(tbl_bwbr[tbl_bwbr$Breed == "Angus", ]$`Body Weight`)
n_mean_limousin <- mean(tbl_bwbr[tbl_bwbr$Breed == "Limousin", ]$`Body Weight`)
n_mean_simmental <- mean(tbl_bwbr[tbl_bwbr$Breed == "Simmental", ]$`Body Weight`)
m <- c(n_mean_angus, n_mean_limousin, n_mean_simmental)
vec_m <- c("E(y_{1.})", "E(y_{2.})", "E(y_{3.})")
cat("$$\n")
cat(paste0(rmdhelp::bcolumn_vector(pvec = vec_m, ps_name = "m"), collapse = "\n"), "\n")
cat(" = \n")
cat(paste0(rmdhelp::bcolumn_vector(pvec = round(m, digits = 3)), collapse = "\n"), "\n")
cat("$$\n")
em_treat[1,] %*% m

Effects

vec_alpha <- c("\\alpha_1", "\\alpha_2", "\\alpha_3")
cat("$$\n")
cat(paste0(rmdhelp::bcolumn_vector(pvec = vec_alpha, ps_name = "\\alpha"), collapse = "\n"), "\n")
cat(" = \n")
cat(paste0(rmdhelp::bcolumn_vector(pvec = round(mat_b0[2:(nrow(mat_b0)),], digits = 3)), collapse = "\n"), "\n")
cat("$$\n")
em_treat[2,] %*% mat_b0[2:(nrow(mat_b0)),]
em_treat[3,] %*% mat_b0[2:(nrow(mat_b0)),]


charlotte-ngs/asmss2022 documentation built on June 7, 2022, 1:33 p.m.