Skip to main content
formatting
Source Link
BioLeal
  • 175
  • 8

I need to analyze one dataset that contain two variables measured in the same subject and one across subjects.

The variables are:
id = subject id, factor with 83 levels
tissue = factor with 2 levels (within-subj)
time = factor with 2 levels (within-subj) group = factor with 2 levels (between-subj)
batch = factor with 2 levels (partially confounded with time).

  • id = subject id, factor with 83 levels
  • tissue = factor with 2 levels (within-subj)
  • time = factor with 2 levels (within-subj)
  • group = factor with 2 levels (between-subj)
  • batch = factor with 2 levels (partially confounded with time).

Would the following model allow me to test specific contrasts correctly? I worry about the degrees of freedom for the emmeans.

Would a random intercept only model (1|id) be enough?

I tried something like:

set.seed(10)
library("lme4")
library("emmeans")

# download dataset into df1 object
source("https://pastebin.com/raw/inQJ2kXy")

fit1 <- lmer(value~batch+group*tissue+time + (1|id:time) + (1|id:tissue),
               data = df1)  

# alternatively

fit2 <- lmer(value~batch+group*tissue+time + (1|id) + (1|id:time) 
+ (1|id:tissue), data = df1)  

# Get speficific contrasts with emmeans

cont.matrix <- data.frame(
            "tub-other_lung_BF" = c(0, 0, 0, 0, 1, -1, 0, 0),
            "tub-other_blood_BF" = c(0, 0, 0, 0, 0, 0, 1, -1),
            "lung-blood_tuber_BF" = c(0, 0, 0, 0, 1, -1, 0, 0),
            "lung-blood_other_BF" = c(0, 0, 0, 0, 0, 1, 0, -1),
            "AT-BT_blood_tub" = c(0, 0, 1, 0, 0, 0, -1, 0)
    )

fit1 %>% 
    emmeans(., ~group*tissue+time, 
            data = df1,
            contr = cont.matrix, adjust = "mvt")

I need to analyze one dataset that contain two variables measured in the same subject and one across subjects.

The variables are:
id = subject id, factor with 83 levels
tissue = factor with 2 levels (within-subj)
time = factor with 2 levels (within-subj) group = factor with 2 levels (between-subj)
batch = factor with 2 levels (partially confounded with time).

Would the following model allow me to test specific contrasts correctly? I worry about the degrees of freedom for the emmeans.

Would a random intercept only model (1|id) be enough?

I tried something like:

set.seed(10)
library("lme4")
library("emmeans")

# download dataset into df1 object
source("https://pastebin.com/raw/inQJ2kXy")

fit1 <- lmer(value~batch+group*tissue+time + (1|id:time) + (1|id:tissue),
               data = df1)  

# alternatively

fit2 <- lmer(value~batch+group*tissue+time + (1|id) + (1|id:time) 
+ (1|id:tissue), data = df1)  

# Get speficific contrasts with emmeans

cont.matrix <- data.frame(
            "tub-other_lung_BF" = c(0, 0, 0, 0, 1, -1, 0, 0),
            "tub-other_blood_BF" = c(0, 0, 0, 0, 0, 0, 1, -1),
            "lung-blood_tuber_BF" = c(0, 0, 0, 0, 1, -1, 0, 0),
            "lung-blood_other_BF" = c(0, 0, 0, 0, 0, 1, 0, -1),
            "AT-BT_blood_tub" = c(0, 0, 1, 0, 0, 0, -1, 0)
    )

fit1 %>% 
    emmeans(., ~group*tissue+time, 
            data = df1,
            contr = cont.matrix, adjust = "mvt")

I need to analyze one dataset that contain two variables measured in the same subject and one across subjects.

The variables are:

  • id = subject id, factor with 83 levels
  • tissue = factor with 2 levels (within-subj)
  • time = factor with 2 levels (within-subj)
  • group = factor with 2 levels (between-subj)
  • batch = factor with 2 levels (partially confounded with time).

Would the following model allow me to test specific contrasts correctly? I worry about the degrees of freedom for the emmeans.

Would a random intercept only model (1|id) be enough?

I tried something like:

set.seed(10)
library("lme4")
library("emmeans")

# download dataset into df1 object
source("https://pastebin.com/raw/inQJ2kXy")

fit1 <- lmer(value~batch+group*tissue+time + (1|id:time) + (1|id:tissue),
               data = df1)  

# alternatively

fit2 <- lmer(value~batch+group*tissue+time + (1|id) + (1|id:time) 
+ (1|id:tissue), data = df1)  

# Get speficific contrasts with emmeans

cont.matrix <- data.frame(
            "tub-other_lung_BF" = c(0, 0, 0, 0, 1, -1, 0, 0),
            "tub-other_blood_BF" = c(0, 0, 0, 0, 0, 0, 1, -1),
            "lung-blood_tuber_BF" = c(0, 0, 0, 0, 1, -1, 0, 0),
            "lung-blood_other_BF" = c(0, 0, 0, 0, 0, 1, 0, -1),
            "AT-BT_blood_tub" = c(0, 0, 1, 0, 0, 0, -1, 0)
    )

fit1 %>% 
    emmeans(., ~group*tissue+time, 
            data = df1,
            contr = cont.matrix, adjust = "mvt")
added 133 characters in body
Source Link
BioLeal
  • 175
  • 8

I need to analyze one dataset that contain two variables measured in the same subject and one across subjects.

The variables are:
id = subject id, factor with 83 levels
tissue = factor with 2 levels (within-subj)
time = factor with 2 levels (within-subj) group = factor with 2 levels (between-subj)
batch = factor with 2 levels (partially confounded with time).

Would the following model allow me to test specific contrasts correctly? I worry about the degrees of freedom for the emmeans.

Would a random intercept only model (1|id) be enough?

I tried something like:

set.seed(10)
library("lme4")
library("emmeans")

# download dataset into df1 object
source("https://pastebin.com/raw/inQJ2kXy")

fit1 <- lmer(value~batch+group*tissue+time + (1|id:time) + (1|id:tissue),
               data = df1)  

# alternatively

fit2 <- lmer(value~batch+group*tissue+time + (1|id) + (1|id:time) 
+ (1|id:tissue), data = df1)  

# Get speficific contrasts with emmeans

cont.matrix <- data.frame(
            "tub-other_lung_BF" = c(0, 0, 0, 0, 1, -1, 0, 0),
            "tub-other_blood_BF" = c(0, 0, 0, 0, 0, 0, 1, -1),
            "lung-blood_tuber_BF" = c(0, 0, 0, 0, 1, -1, 0, 0),
            "lung-blood_other_BF" = c(0, 0, 0, 0, 0, 1, 0, -1),
            "AT-BT_blood_tub" = c(0, 0, 1, 0, 0, 0, -1, 0)
    )

fit1 %>% 
    emmeans(., ~group*tissue+time, 
            data = df1,
            contr = cont.matrix, adjust = "mvt")

I need to analyze one dataset that contain two variables measured in the same subject and one across subjects.

The variables are:
id = subject id, factor with 83 levels
tissue = factor with 2 levels (within-subj)
time = factor with 2 levels (within-subj) group = factor with 2 levels (between-subj)
batch = factor with 2 levels (partially confounded with time).

Would the following model allow me to test specific contrasts correctly? I worry about the degrees of freedom for the emmeans.

Would a random intercept only model (1|id) be enough?

I tried something like:

set.seed(10)
library("lme4")
library("emmeans")

# download dataset into df1 object
source("https://pastebin.com/raw/inQJ2kXy")

fit1 <- lmer(value~batch+group*tissue+time + (1|id:time) + (1|id:tissue),
               data = df1)  

# Get speficific contrasts with emmeans

cont.matrix <- data.frame(
            "tub-other_lung_BF" = c(0, 0, 0, 0, 1, -1, 0, 0),
            "tub-other_blood_BF" = c(0, 0, 0, 0, 0, 0, 1, -1),
            "lung-blood_tuber_BF" = c(0, 0, 0, 0, 1, -1, 0, 0),
            "lung-blood_other_BF" = c(0, 0, 0, 0, 0, 1, 0, -1),
            "AT-BT_blood_tub" = c(0, 0, 1, 0, 0, 0, -1, 0)
    )

fit1 %>% 
    emmeans(., ~group*tissue+time, 
            data = df1,
            contr = cont.matrix, adjust = "mvt")

I need to analyze one dataset that contain two variables measured in the same subject and one across subjects.

The variables are:
id = subject id, factor with 83 levels
tissue = factor with 2 levels (within-subj)
time = factor with 2 levels (within-subj) group = factor with 2 levels (between-subj)
batch = factor with 2 levels (partially confounded with time).

Would the following model allow me to test specific contrasts correctly? I worry about the degrees of freedom for the emmeans.

Would a random intercept only model (1|id) be enough?

I tried something like:

set.seed(10)
library("lme4")
library("emmeans")

# download dataset into df1 object
source("https://pastebin.com/raw/inQJ2kXy")

fit1 <- lmer(value~batch+group*tissue+time + (1|id:time) + (1|id:tissue),
               data = df1)  

# alternatively

fit2 <- lmer(value~batch+group*tissue+time + (1|id) + (1|id:time) 
+ (1|id:tissue), data = df1)  

# Get speficific contrasts with emmeans

cont.matrix <- data.frame(
            "tub-other_lung_BF" = c(0, 0, 0, 0, 1, -1, 0, 0),
            "tub-other_blood_BF" = c(0, 0, 0, 0, 0, 0, 1, -1),
            "lung-blood_tuber_BF" = c(0, 0, 0, 0, 1, -1, 0, 0),
            "lung-blood_other_BF" = c(0, 0, 0, 0, 0, 1, 0, -1),
            "AT-BT_blood_tub" = c(0, 0, 1, 0, 0, 0, -1, 0)
    )

fit1 %>% 
    emmeans(., ~group*tissue+time, 
            data = df1,
            contr = cont.matrix, adjust = "mvt")
Source Link
BioLeal
  • 175
  • 8

Experiment with two within-subjects and one between-subject with linear mixed models?

I need to analyze one dataset that contain two variables measured in the same subject and one across subjects.

The variables are:
id = subject id, factor with 83 levels
tissue = factor with 2 levels (within-subj)
time = factor with 2 levels (within-subj) group = factor with 2 levels (between-subj)
batch = factor with 2 levels (partially confounded with time).

Would the following model allow me to test specific contrasts correctly? I worry about the degrees of freedom for the emmeans.

Would a random intercept only model (1|id) be enough?

I tried something like:

set.seed(10)
library("lme4")
library("emmeans")

# download dataset into df1 object
source("https://pastebin.com/raw/inQJ2kXy")

fit1 <- lmer(value~batch+group*tissue+time + (1|id:time) + (1|id:tissue),
               data = df1)  

# Get speficific contrasts with emmeans

cont.matrix <- data.frame(
            "tub-other_lung_BF" = c(0, 0, 0, 0, 1, -1, 0, 0),
            "tub-other_blood_BF" = c(0, 0, 0, 0, 0, 0, 1, -1),
            "lung-blood_tuber_BF" = c(0, 0, 0, 0, 1, -1, 0, 0),
            "lung-blood_other_BF" = c(0, 0, 0, 0, 0, 1, 0, -1),
            "AT-BT_blood_tub" = c(0, 0, 1, 0, 0, 0, -1, 0)
    )

fit1 %>% 
    emmeans(., ~group*tissue+time, 
            data = df1,
            contr = cont.matrix, adjust = "mvt")