Module #11 Assignment
10.1:
# Load the ISwR package if not already installed
if (!require(ISwR)) {
install.packages("ISwR")
library(ISwR)
}
# Load the "ashina" data
data(ashina)
# Create a subject factor variable
ashina$subject <- factor(1:16)
# Attach the "ashina" dataset
attach(ashina)
# Create data frames for active and placebo treatments
act <- data.frame(vas = vas.active, subject, treat = 1, period = grp)
plac <- data.frame(vas = vas.plac, subject, treat = 0, period = grp)
# Set up the additive model
additive_model <- aov(vas ~ subject + treat + period, data = rbind(act, plac))
# Perform t-tests for treatment comparison
t_test_treat <- t.test(vas.active, vas.plac, alternative = "two.sided")
# View the ANOVA results
summary(additive_model)
# Print the t-test results
print(t_test_treat)
10.3:
# Create the objects a, b, x, y, and z as defined
a <- c(2, 2, 8)
b <- c(2, 4, 8)
x <- 1:8
y <- c(1:4, 8:5)
z <- rnorm(8)
# Generate model matrices for z ~ a*b and z ~ a:b
model_matrix_ab <- model.matrix(~ a * b)
model_matrix_a_b <- model.matrix(~ a:b)
# Display the generated model matrices
model_matrix_ab
model_matrix_a_b
# Fit the models and check for singularities
model_z_ab <- lm(z ~ model_matrix_ab)
model_z_a_b <- lm(z ~ model_matrix_a_b)
# Check for singularities in the models
is_singular_ab <- isSingular(model_z_ab)
is_singular_a_b <- isSingular(model_z_a_b)
# Print whether the models contain singularities
cat("Model z ~ a * b is singular:", is_singular_ab, "\n")
cat("Model z ~ a:b is singular:", is_singular_a_b, "\n")
Comments
Post a Comment