Formula: total ~ known + childage_days + prop_known
MODEL_FORMULA <- "total ~ known + childage_days + prop_known"
# coefficient function
get_word_beta <- function(word, mod_formula, df){
relevant_df <- df %>%
filter(item == word)
model <- lm(mod_formula, relevant_df)
summary(model)$coefficients %>%
data.frame() %>%
rownames_to_column("predictor") %>%
filter(predictor == 'known') %>%
mutate(item = word)
}
ache <- get_word_beta('ache',as.formula(MODEL_FORMULA),seed_control_words)
#### DO THE THING ####
word_coeffs <- map_df(paste("",unique(seed_control_words$item),"",sep=""),
get_word_beta,
as.formula(MODEL_FORMULA),
seed_control_words) %>%
select(item,Estimate,SE=Std..Error, tval=t.value, p=Pr...t..) %>%
arrange(tval)
word_coeffs_by_type <- word_coeffs %>%
left_join(types_only, by="item")
## Warning: Column `item` joining character vector and factor, coercing into
## character vector
ggplot(word_coeffs_by_type, aes(tval, fill=type))+
geom_density(alpha = .2)+
theme_classic()
categories <- read.csv("C:/Users/Christina/Dropbox/UW Madison/Grant/AOA parent survey/survey_words_categories_2.csv") %>%
rename(item = Word) %>%
select(-MCDI_Cat)
word_coeffs_with_cat <- left_join(word_coeffs_by_type, categories, by="item")
## Warning: Column `item` joining character vector and factor, coercing into
## character vector
word_coeffs_with_cat$CatName <- as.factor(word_coeffs_with_cat$CatName)
DT::datatable(word_coeffs_with_cat)
ggplot(filter(word_coeffs_with_cat, !(is.na(CatName)) & type=="seed"), aes(tval, fill = CatName))+
geom_density(alpha = .5)+
facet_wrap(~CatName)+
theme_classic()
## Warning: Groups with fewer than two data points have been dropped.
## Warning: Groups with fewer than two data points have been dropped.
ggplot(filter(word_coeffs_with_cat, type=="control" & !(is.na(CatName))), aes(tval, fill = CatName))+
geom_density(alpha = .5)+
facet_wrap(~CatName)+
theme_classic()
ggplot(filter(word_coeffs_with_cat, CatName=="prepositions and locations" | CatName=="people" | CatName=="body parts"), aes(tval, fill = CatName))+
geom_density(alpha = .5)+
facet_wrap(~CatName)+
theme_classic()
ggplot(filter(word_coeffs_with_cat, !(is.na(CatName)) & CatName != "prepositions and locations"), aes(tval, fill = type))+
geom_density(alpha = .5)+
facet_wrap(~CatName)+
theme_classic()
## Warning: Groups with fewer than two data points have been dropped.
## Warning: Groups with fewer than two data points have been dropped.
specific_words <- word_coeffs_with_cat %>% filter(CatName == "small household items" | CatName == "descriptive words" | CatName == "mental states and attributes")
helpfulcats <- c("mental states and attributes", "places to go", "small household items", "words about time")
helpful_seed <- filter(word_coeffs_with_cat, type == "seed" & (CatName %in% helpfulcats))
DT::datatable(helpful_seed)
seed_larger_t <- filter(word_coeffs_with_cat, type=="seed" & tval > 5.5)
DT::datatable(seed_larger_t)