> # Ensure the ISwR package is installed and loaded
> if (!require(ISwR)) {
+ install.packages("ISwR")
+ library(ISwR)
+ }
>
> # Load the ashina data
> data(ashina)
>
> # Convert the subject to a factor
> ashina$subject <- factor(1:16)
>
> # Create the 'act' and 'plac' data frames
> act <- data.frame(vas = ashina$vas.active, subject = ashina$subject, treat = 1, period = ashina$grp)
> plac <- data.frame(vas = ashina$vas.plac, subject = ashina$subject, treat = 0, period = ashina$grp)
>
> # Define the function 'g1'
> g1 <- function(x, y, z) {
+ seq(from = x, to = y, length.out = z)
+ }
>
> # Define your variables
> a <- g1(2, 2, 8)
> b <- g1(2, 4, 8)
> x <- 1:8
> y <- c(1:4, 8:5)
> z <- rnorm(8)
>
> # Generate the model matrices
> model_ab <- model.matrix(~ a*b)
> model_a_b <- model.matrix(~ a:b)
>
> # Fit the models
> fit_ab <- lm(z ~ a*b)
> fit_a_b <- lm(z ~ a:b)
>
> # Check for singularities
> kappa(model_ab)
[1] 1.447558e+17
> kappa(model_a_b)
[1] 34.07219
|
Comments
Post a Comment