How to Implement a Mixed Effect Model for Nested Data in R?


Data sample below.


I’m working on an analysis involving a complex nested dataset and I need to implement a mixed effect model in R. Here’s a brief overview of my situation:

  • Objective: Determine the effect of personality traits (OCEAN), emotional states, situational perception, and emotional perception on the evaluation of valence of images generated by artificial intelligence.
  • Problem: I’ve previously run regression models without fully accounting for the nested structure in the data. The regression coefficients from these models are extremely small, and I’m not confident in their accuracy.
  • Data Structure: The data is nested, with images nested within participants, and participants nested within surveys.

Data Details:

  1. I conducted 60 surveys, each containing 20 different images, and applied these surveys to 20 participants.
  2. The surveys also include 5 additional images that are common across all surveys.
  3. For the analysis, my dataset is structured so that the first 20 rows correspond to the first participant’s reactions to the 20 images of the survey. The next 20 rows correspond to the next participant, and so on. The participant’s personality and emotional states are repeated 20 times, since they are constant for the same person. This repetition is the repeated measures part, while the situational and emotional perceptions vary.

Here is a sample of the data with not repeated images, in case the explanation of the data is unclear.

What I’ve Tried:

  1. Separating the analysis of the 5 common images and the uncommon images.
  2. Analyzing each of the common images separately.
  3. Computing the mean of the 5 common images to account for repeated measures, reducing the data to one row per participant for these images.
  4. Running simpler regression models that only have the participant as a higher level.

Here is the code for the not repeated images:

# Define the formula for the model for valence
valence_formula <- as.formula(paste("valence ~ water + ground + mountain + tree + snow + O + C + E + A + N + angry + good + bad + happy + sad + nice + unfriendly + tense + relaxed + curiosity + rage + fear + sexy + careness + sadness + playfulness + work + intellectual + threat + romance + positive + negative + deceit + communication + (1 | survey_index/image_name)", collapse = " + "))

# Fit the regression model for valence using lmer
valence_model <- lmer(valence_formula, data = df)

Here is the code for the common images:

# Define the formula for the model for valence
valence_formula <- as.formula(paste("valence ~ water + ground + mountain + tree + O + C + E + A + N + angry + good + bad + happy + sad + nice + unfriendly + tense + relaxed + curiosity + rage + fear + sexy + careness + sadness + playfulness + work + intellectual + threat + romance + positive + negative + deceit + communication + (1 | image_name) + (1 | participant_id)", collapse = " + "))

# Fit the regression model for valence using lmer
valence_model <- lmer(valence_formula, data = df)

As you can see from the data, I recognize a nested design for the not repeated images model and a crossed design for the common images. More on that here.

Questions:

  1. How can I properly implement a mixed effect model in R to account for the nested structure of my data (images within participants within surveys)?
  2. What packages and functions should I use for this type of analysis?

Any guidance or example code snippets would be greatly appreciated!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật