0

I'm writing my master thesis and I'm stuck with the complexity of my data. Therefore I'd like to plot my data to see what's in there.

My dataframe looks like that: I've 333 perceivers (PID) who rated 60 target photos (TID) each, resulting in 19980 rows. Each perceiver (PID) rated every target's photo on how likeable they are (Rating) and provided multiple self-reports about themselves (SDO_mean, KSA_mean, threats_overall). The photos were either from photo type A (Dwithin = 0) or type B (Dwithin = 1), which is my within-subject factor as every perceiver saw all photos. In addition perceivers were assigned to one of two between-subject condition (Dbetween): All photos (TID) from type B (Dwithin = 1) were labeled either as people with migration background (Dbetween = 0) or as refugees (Dbetween = 1). This results in a nested design where the Ratings are nested in the PID and also in the TID. My data looks like that:

TID PID Dwithin Dbetween Rating SDO_mean KSA_mean threats_overall
1   1       0        0      5      3.1      2.3             2.2
2   1       1        0      2      3.1      2.3             2.2
3   1       0        0      5      3.1      2.3             2.2
4   1       1        0      1      3.1      2.3             2.2
5   1       0        0      3      3.1      2.3             2.2
6   1       1        0      3      3.1      2.3             2.2

Now I want to predict the likeable-rating mainly by the categorial variables Dwithin and Dbetween. As Dbetween can only be interpreted as an interaction of Dwithin*Dbetween (because the label was only for Dwitihn=1 targets), the formula would be:

model1 <- lmer(Rating~1+Dwithin+Dbetween+Dwithin*Dbetween+(1+Dwithin|PID)+(1|TID),data=df)

Now I want to plot the data which I'm using for my regression. An option could be to plot the Rating seperately for each Dwithin / Dbetween condition. Or to plot the regression as in the model1 formula. But as these are categorial predictors, I didn't manage to plot the data in the right way. I looked into lattice() but couldn't apply it on my data. Is there anyone who could help me plotting it? Thanks a lot in advance!

@SASpencer: I thought for example of something like this. But my y-scale isn't continious... it only has integer numbers from 1-5.It could also be interesting for the combination of Dwithin and Dbetween (so like in your plot)

Here is a reproducible example:

mysamp <- function(n, m, s, lwr, upr, nnorm) {
  set.seed(1)
  samp <- rnorm(nnorm, m, s)
  samp <- samp[samp >= lwr & samp <= upr]
  if (length(samp) >= n) {
    return(sample(samp, n))
  }  
} 

options(digits=2)
TID <- rep(1:60, times=333)
PID <- rep(1:333,each=60)
Dwithin <- rep(rep(0:1, times=19980/2))
Dbetween <- rep(rep(0:1, each=60),times=333)[1:19980]
Rating <-  floor(runif(19980, min=1, max=6))
SDO_mean <- rep(mysamp(n=333, m=4, s=2.5, lwr=1, upr=5, nnorm=1000000), each=60)
KSA_mean <- rep(mysamp(n=333, m=2, s=0.8, lwr=1, upr=5, nnorm=1000000), each=60)
threats_overall <- rep(mysamp(n=333, m=3, s=1.5, lwr=1, upr=5, nnorm=1000), each=60)

df <- data.frame(TID,PID,Dwithin,Dbetween, Rating, SDO_mean, KSA_mean, threats_overall)
Josh
  • 15
  • 6
  • Perhaps it would help to use pen/paper and sketch what you want, label x and y axis, and upload a photo. The following would plot rating separately for each Within/Dbetween condition: require(ggplot2); df %>% ggplot(aes(x = Rating)) + geom_histogram() + facet_wrap(Dwithin~Dbetween) – ssp3nc3r Apr 19 '17 at 13:33
  • Thanks for your reply. I posted a picture of a plot I had in mind.. But I can't quite think of a proper plot given the restraints of my data structure. I'm also asking to get ideas how to approach this multi-level structure in graphics and analyses. – Josh Apr 19 '17 at 14:38

0 Answers0