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)


The additive model (additive_model) allows you to examine the effect of the subject, treatment, and period on the response variable (vas.active). It provides estimates of the coefficients for each variable and their significance levels. You can compare the results from the additive model to the t-tests you performed earlier to see if they are consistent in identifying significant effects.

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


1. ` z ~ a*b: This model includes the interaction between variables a and b. It allows you to examine how the interaction of these two factors influences the response variable z.

2. ` z ~ a:b: This model considers the interaction between variables a and b without including the main effects. It is a more specific model that focuses only on the interaction term.

Implications of these models depend on the context of your data and research questions. The first model assesses both main effects and interaction, while the second model isolates the interaction effect.

Comments

Popular posts from this blog

Final Project [LIS4317]

Module # 8 Input/Output, string manipulation and plyr package

Module # 10 Building your own R package