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

0 Asked on November 9, 2021

classification error machine learning model selection modeling

0 Asked on November 9, 2021 by atrag

0 Asked on November 9, 2021 by ryu576

descriptive statistics hypothesis testing large data order statistics

3 Asked on November 9, 2021 by sabiste

1 Asked on November 9, 2021 by moneyball

1 Asked on November 9, 2021 by thomas-richardson

0 Asked on November 9, 2021

1 Asked on November 9, 2021

1 Asked on November 9, 2021 by tshast2

1 Asked on November 9, 2021

0 Asked on November 9, 2021

0 Asked on November 9, 2021 by rob-goldstone

linear algebra markov process optimization transition matrix

1 Asked on November 9, 2021

0 Asked on November 6, 2021 by ana-pau-de-la-fuente

2 Asked on November 6, 2021

1 Asked on November 6, 2021 by rishu

1 Asked on November 6, 2021 by user235039

forecasting measurement error model evaluation out of sample

1 Asked on November 6, 2021 by yilei-huang

2 Asked on November 6, 2021 by marvdste

1 Asked on November 6, 2021

Get help from others!

Recent Questions

- How Do I Get The Ifruit App Off Of Gta 5 / Grand Theft Auto 5
- 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?

Recent Answers

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

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