Module 11 Assignment
Module 11 Assignment
Question 10.1: Set up an additive model for the ashina data
Using the R ISwR package, you can build up an additive model for the ashina data. You can set up the model using the following:
library(ISwR)
data(ashina)
ashina$subject <- factor(1:16)
attach(ashina)
act <- data.frame(vas = vas.active, subject, treat = 1, period = grp)
plac <- data.frame(vas = vas.plac, subject, treat = 0, period = grp)
After preparing your data, you can now build up your additive model and evaluate the impact of subjects, periods, and treatments by comparing the outcomes with t-tests.
Question 10.3: Generate model matrices for models z ~ a*b, z ~ a:b, etc.
The task at hand involves creating model matrices for various models by utilizing the vectors a, b, x, y, and z. It is necessary to conduct out the model fits and talk about the consequences of each model. You can use the following:
a <- c(2, 2, 8)
b <- c(2, 4, 8)
x <- 1:8
y <- c(1:4, 8:5)
z <- rnorm(8)
model_matrix_a_b <- model.matrix(~a * b)
model_matrix_a_colon_b <- model.matrix(~a:b)
lm_a_b <- lm(z ~ model_matrix_a_b)
lm_a_colon_b <- lm(z ~ model_matrix_a_colon_b)
After creating model matrices for the models z ~ a * b and z ~ a:b, you have fitted linear models to the given data. These models' outputs can be compared, and their ramifications can be discussed.
Comments
Post a Comment