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)
contrasts
getOption("contrasts")
to find which contrasts are usedoptions(contrasts = c("<contast_unordered>", "<contrast_ordered"))
to change contrastss_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)))
(cm_treat <- cbind(matrix(1, nrow = nrow(cm_treat), ncol = 1), cm_treat))
(em_treat <- solve(cm_treat))
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)
em_treat
shows computation of estimate for interceptBody Weight
for all breedsvec_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
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)),]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.