I am trying to determine how to output a list of the variable names that yield significant (p < 0.05) interactions in a series of regressions.
I have a dataframe that looks like the following:
behavior condition attitude1 attitude2 attitude3
1 0 4 5 7
6 1 3 7 2
5 0 2 1 4
3 1 4 2 6
In reality, I have several more attitudes than displayed here. To run several regressions simultaneously and test for interaction terms, I would typically use the following code:
attitudes <- colnames(df[,3:5])
form <- paste("behavior ~ condition*",attitudes)
model <- form %>%
set_names(attitudes) %>%
map(~lm(.x, data = df))
map(model, summary)
The output is a list of each of the following regressions:
lm(behavior ~ condition * attitude1)
lm(behavior ~ condition * attitude2)
lm(behavior ~ condition * attitude3)
I would like to find a way to output a list of all the variable names with a significant condition*attitude interaction. For example, if p<0.05 for attitude1 and attitude3, the output I would be looking for would be:
attitude1, attitude3
This question is related to what I am trying to do, but it does not show me how I can do this when I am running the models simultaneously using map().