Last active
September 8, 2021 12:56
-
-
Save msallin/06f0227d6468a252e270ca7f72992cc2 to your computer and use it in GitHub Desktop.
example_annik
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
participant_id <- c(1,1,2,2,3,3,3,4,4) | |
answer1 <- c(12,123,33,333,3,22,11,32,12) | |
answer2 <- c(12,123,33,333,3,22,11,22,11) | |
results <- data.frame(participant_id, answer1, answer2) | |
# Results looks like this: | |
# participantId answer1 answer2 | |
# 1 1 12 12 | |
# 2 1 123 123 | |
unique_participant_ids <- unique(results$participant_id) | |
# unique_participant_ids looks like "[1] 1 2 3 4" | |
intercept_per_participant <- c() | |
for (participantId in unique_participant_ids) { # Iterate over all participants | |
all_answers_for_participant <- subset(results, participant_id == participantId) # Get only the answers from the current participant | |
# fit here your model with "all_answers_for_participant" | |
# E.g. https://stackoverflow.com/questions/23240182/deciding-threshold-for-glm-logistic-regression-model-in-r | |
model <- lm(all_answers_for_participant$answer1 ~ all_answers_for_participant$answer2) # I use LM as an example | |
model_summary <- summary(model) | |
intercept_value <- model_summary$coefficients[1,1] | |
intercept_per_participant <- c(intercept_per_participant, intercept_value) # Append the interesting things to a list (here intercept) | |
} | |
# Now do something with your data | |
# E.g. get the man of all intercepts.. | |
mean(intercept_per_participant) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment