Cross Validated Asked by user4451922 on January 7, 2022

I am analyzing data from several trials where individuals were submitted to different stimuli and a biological response was measured. Some individuals participated in more than one trial where the same stimulus was used.

Here is some dummy data that mimics what I have:

```
Subject Stimulus Response
A 1 44.8
A 1 49.1
A 1 46.5
A 2 10.3
A 2 19.1
B 1 58.1
B 1 79.4
B 3 79.1
B 3 69.2
...
```

My aim is to determine if patients react differently to different stimuli, but before that, I want to know if their response to the same stimulus is consistent. If so, I am thinking of averaging the multiple observations that individuals have for the same stimulus and then find out if in general the response to different stimuli is different.

My question is: With a structure like this, how do I test if patients have a similar response to the same stimulus?

I read about test-retest reliability, but I am not sure how to do it or if it is applicable to this case. I use R for all my statistical analysis. Any suggestions are welcome.

One approach here would be a components of variance model, where you partition the total variance in the data in parts due to `Subjects`

, `Stimulus`

, and Error (`Response`

). This can be estimated as a random effects model, for example in R with the package lme4 something like:

```
mod <- lme4::lmer(Response ~ (1 | Subject / Stimulus), data=your_data_frame)
```

Then you must judge if the component of variance due to stimulus is small enough.

Here is an example with simulated data:

```
mod <- lme4::lmer(Response ~ (1 | Subject/Stimulus), data=df)
mod
Linear mixed model fit by REML ['lmerMod']
Formula: Response ~ (1 | Subject/Stimulus)
Data: df
REML criterion at convergence: 559.3188
Random effects:
Groups Name Std.Dev.
Stimulus:Subject (Intercept) 2.2841
Subject (Intercept) 12.1752
Residual 0.4322
Number of obs: 180, groups: Stimulus:Subject, 60; Subject, 20
Fixed Effects:
(Intercept)
40.09
```

Code for simulated data:

```
N_subj <- 20
N_stimu <- 3
N_repl <- 3
sd_subj <- 10
sd_stimu <- 2
sd_repl <- 0.5
set.seed(7*11*13) # My public seed
N_total <- N_subj * N_stimu * N_repl
Subject <- as.factor(rep(1:N_subj, rep(N_stimu*N_repl, N_subj)))
Stimulus <- as.factor(rep(rep(1:N_stimu, rep(N_repl, N_stimu)), N_subj))
Response <- 40+rep(rnorm(N_subj, 0, sd_subj), rep(N_stimu*N_repl, N_subj)) +
rep(rnorm(N_stimu*N_subj, 0, sd_stimu), rep(N_repl, N_stimu*N_subj)) +
rnorm(N_total, 0, sd_repl)
df <- data.frame(Response, Subject, Stimulus)
```

Answered by kjetil b halvorsen on January 7, 2022

A textbook approach here would be to use a linear model with a term for each subject and a term for each stimulus. A classical analysis of variance (ANOVA) using such a model can compare the variation *within* the same subject or stimulus to the variation *between* different subjects or stimuli.

```
my_lm = lm(Response ~ Subject + Stimulus, data = your_dataframe)
aov(my_lm)
```

If you get a significant result for the coefficients describing the effect of the stimulus, that's the smoking gun. You should make sure the size of the effect is scientifically meaningful, though. It's good practice to also check the ANOVA assumptions (constant variance, independent errors, and less importantly, rough normality).

Answered by eric_kernfeld on January 7, 2022

1 Asked on February 6, 2021 by randy-welt

1 Asked on February 5, 2021 by cherry-wu

0 Asked on February 5, 2021 by mksm1228

1 Asked on February 4, 2021 by paze

1 Asked on February 4, 2021 by gideon-j-i

0 Asked on February 4, 2021 by zesla

1 Asked on February 4, 2021 by user964689

0 Asked on February 3, 2021 by relieff

1 Asked on February 2, 2021 by user777

2 Asked on February 2, 2021

3 Asked on February 1, 2021 by mikhail

1 Asked on February 1, 2021 by user70990

1 Asked on February 1, 2021 by rafael-hernndez-salazar

generalized linear model interpretation logistic multiple regression regression coefficients

1 Asked on January 31, 2021 by user179028

1 Asked on January 30, 2021 by eddie-s

cross validation generalized linear model machine learning predictive models statistical significance

0 Asked on January 30, 2021 by virginie

confidence interval multiple regression multivariate regression r regression

1 Asked on January 29, 2021 by i-a

1 Asked on January 29, 2021

lme4 nlme mixed model multilevel analysis r treatment effect

2 Asked on January 29, 2021 by marcus-bdholm

Get help from others!

Recent Answers

- haakon.io on Why fry rice before boiling?
- Peter Machado on Why fry rice before boiling?
- Joshua Engel on Why fry rice before boiling?
- Jon Church on Why fry rice before boiling?
- Lex on Does Google Analytics track 404 page responses as valid page views?

Recent Questions

- Iv’e designed a space elevator using a series of lasers. do you know anybody i could submit the designs too that could manufacture the concept and put it to use
- Need help finding a book. Female OP protagonist, magic
- Why is the WWF pending games (“Your turn”) area replaced w/ a column of “Bonus & Reward”gift boxes?
- Does Google Analytics track 404 page responses as valid page views?
- Why fry rice before boiling?

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP