Skip to content

pairwise combinations of subjects

5 messages · Stevens, Hank, David Duffy, Thierry Onkelinx +1 more

#
I was hoping someone might point to information or examples of this type of
problem.

I sometimes encounter data that are derived from interactions between all
pairwise interactions of subjects (e.g., subject a vs. subject b, subject a
vs. subject c, subject b vs. subject c). The response is the result of the
interaction between subjects, and observations are likely to show
correlations within subject. We are interested in the relation between a
fixed effect predictor and the response, and not the effects of subject per
se. For instance,

subj_1   subj_2 . pred  resp
  a        b       1      5
  a        c       1.1 .  4
  b        c       2.5 .  1

where the subj 1 and subj 2 are all the same individuals, but are paired
with a different partner. It seems as though this might be crossed random
effects of subj_1 and subj_2. E.g.,
lmer( resp ~ pred + (1|subj1) + (1|subj2) )

This seems like a design that might be common in breeding....

Many thanks for your thoughts and leads.

Hank Stevens

A more thorough worked example:

library(lme4)
df <- expand.grid(gl())
n <- 5
l <- n*(n-1)/2
x <- data.frame( matrix(NA, nr=1, nc=2) )
names(x) <- c("sp1", "sp2")

r <- 1
for(i in 1:(n-1)){
  for(j in (i+1):n){
    x[r,1:2] <- c(i,j)
    r <- r+1
  }
}

set.seed(4)
x$y <- (x$sp1 + x$sp2) / (n*2) + runif(l)
set.seed(3)
x$c <- - (x$sp1 + x$sp2) / (n*2) + runif(l)

## which design, if any?
summary( lm(y ~ c, data=x))
summary( lmer(y ~ c + (1|sp1) + (1|sp2), data=x))
1 day later
#
[...]
Yes, we fit this flavour of model as SEMs - for example, not exactly the same but just as mechanistically plausible, you have a reciprocal causative pairwise relationship
    ----->
X1      X2
   <-----
|           |
v         v
Y1      Y2

detectable by its effects on total variance (correlated with values of X - so 'ware those variance stabilising transformations ;)), and distribution of the Y's.  The coefficients can be negative, so members of each pair rub each other the wrong way _OR_ if the measurement is say a rating by an external observer, then the ratings may be biased away from each other ("contrast effect"). I don't know how to do this in lme4, but on page 9 of 

https://peerj.com/preprints/3354.pdf

you can see them fitting such a model using the R umx package.

Cheers, David Duffy
#
Dear Hank,

Here is a solution using the INLA package. This model has two random
effects with identical estimates for each level.

# make sure that sp1 contains each level
old <- x$sp1[n - 1]
x$sp1[n - 1] <- x$sp2[n - 1]
x$sp2[n - 1] <- old

# fit the model
library(INLA)
m <- inla(y ~ c + f(sp1, model = "iid", n = n) + f(sp2, copy = "sp1"), data
= x)
summary(m)
plot(m)

Best regards,


ir. Thierry Onkelinx
Statisticus / Statistician

Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND
FOREST
Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
thierry.onkelinx at inbo.be
Havenlaan 88 bus 73, 1000 Brussel
www.inbo.be

///////////////////////////////////////////////////////////////////////////////////////////
To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
///////////////////////////////////////////////////////////////////////////////////////////

<https://www.inbo.be>


Op ma 15 jul. 2019 om 15:33 schreef Stevens, Hank <hank.stevens at miamioh.edu

  
  
#
Thanks David! That looks like a great solution, and a great SEM package. I
plan on spreading the word about umx.
Best,
Hank

On Tue, Jul 16, 2019 at 12:27 AM David Duffy <
David.Duffy at qimrberghofer.edu.au> wrote:

            

  
    
#
I am currently out of the office until July 5th. I will respond to your email upon my return.
On Jul 16, 2019, at 1:35 AM, Thierry Onkelinx via R-sig-mixed-models <r-sig-mixed-models at r-project.org> wrote:

            
[[alternative text/enriched version deleted]]