I am trying to create a multilevel model to investigate this question, but I can't come up with a solution (it's the first time I do multi-level modeling, and my statistics skills are rather elementary). 135 teachers were given 35 sentences and they rated them for perceived difficulty on a continuous 1-100 scale. Each sentence had some characteristics, such as length in words, number of commas, number of subjects, number of verbs and a few more, 7 predictive factors altogether. Each participant was scored for two characteristics, school level where they teach (4 values, nominal) + years of experience. I would like to model how these factors predict their responses about item difficulty. My data are organized in two spreadsheets: one contains the 35 sentences and, for each of them, the values for their characteristics (e.g. sentence 1 has 35 words, 2 commas, 6 verbs, 5 subjects etc); the other contains the participants' responses (e.g. participant 1 rated sentence 1 35.3, sentence 2 28.9, sentence 3 67.1 etc.) + participants' characteristics. Now I don't know if and how I should merge all this information into a single data matrix or whether I can conduct the analysis with two different matrices, and how to practically run the analysis. I would say it's a multivariate, repeated measures, multilevel model with a single, continuous response variable. I've tried to look for information on the web about how to practically conduct this type of analysis with R, but I could not find anything specifically addressing this research design. I would really appreciate if anyone could direct me to some introductory tutorial, or give me some hints on how I should proceed. Thank you very much


1 Answer 1


After some searching and advice from colleagues, I managed to solve my problem. It's rather elementary, but perhaps this may help someone else. Conceptually, what I needed was to transform everything into a long format and this is how it looked. enter image description here

The first 3 columns indicate the participant's ID, what type of school they teach, and the years they've been teaching; these are the participants' characteristics that were in one file; after that, one finds the 35 items they respond to, first with the value of the response (14.61 in the first line), then with the characteristics of that item. So each line contains info about both participant and item. You repeat this 35 times per participant (the items each answered) and this is for 135 participants. You get 4725 lines and 10 columns, which is a long format. All this can be done automatically using the tidyR package. A friend of mine wrote this code which did the trick. The original files were partecipanti.xlsx and periodi.xlsx



partecipanti <- read_excel("partecipanti.xlsx", na = "NA")

periodi <- read_excel("periodi.xlsx")

partecipanti <- partecipanti %>%
  pivot_longer(names(partecipanti[4:38]), names_to = "frase", values_to = "risposta")

fusione <- full_join(partecipanti, periodi, by = "frase")

#this line deletes linew containing NA; use if needed
fusione <- fusione %>% filter(risposta != "NA")

write_tsv(fusione, "fusione.txt")

#this may be used to check if everything went fine
fusione %>% filter(partic == "ID001", frase == "Q01") %>% as.data.frame()

I hope this may help others solve similar problems.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.