Closed padilla410 closed 6 years ago
update. This works: `my_lm_p_labs <- function(dat_in) {
summary <- dat_in %>% group_by(season) %>% summarise(count = sum(is.na(min)))
dat_in <- dat_in[complete.cases(dat_in), ]
lm_results <- dat_in %>% group_by(.data$season) %>% do(reg_min = lm(.data$min ~ .data$year, data = .data, na.action = 'na.omit') , reg_mean = lm(.data$mean ~ .data$year, data = .data, na.action = 'na.omit') , reg_max = lm(.data$max ~ .data$year), data = .data, na.action = 'na.omit')
lm_min_tidy <- tidy(lm_results, reg_min) %>% filter(.data$term == '.data$year') lm_mean_tidy <- tidy(lm_results, reg_mean) %>% filter(.data$term == '.data$year') lm_max_tidy <- tidy(lm_results, reg_max) %>% filter(.data$term == '.data$year')
lm_min_tidy$lab <- ifelse(lm_min_tidy$p.value < 0.05, 'p < 0.05', 'p > 0.05') lm_mean_tidy$lab <- ifelse(lm_mean_tidy$p.value < 0.05, 'p < 0.05', 'p > 0.05') lm_max_tidy$lab <- ifelse(lm_max_tidy$p.value < 0.05, 'p < 0.05', 'p > 0.05')
df_lab <- data.frame(season = lm_min_tidy$season, min = lm_min_tidy$lab, mean = lm_mean_tidy$lab, max = lm_max_tidy$lab, stringsAsFactors = F)
df_lab <- tidyr::complete(df_lab, season)#!! seas)
df_lab[is.na(df_lab)] <- ''
return(df_lab) }`
Right now it fails when a season is missing `my_lm_p_labs <- function(dat_in) {
remove seasons with out results
dat_in <- dat_in[complete.cases(dat_in), ]
lm_results <- dat_in %>% group_by(.data$season) %>% do(reg_min = lm(.data$min ~ .data$year, data = .data, na.action = 'na.omit') , reg_mean = lm(.data$mean ~ .data$year, data = .data, na.action = 'na.omit') , reg_max = lm(.data$max ~ .data$year), data = .data, na.action = 'na.omit')
lm_min_tidy <- tidy(lm_results, reg_min) %>% filter(.data$term == '.data$year') lm_mean_tidy <- tidy(lm_results, reg_mean) %>% filter(.data$term == '.data$year') lm_max_tidy <- tidy(lm_results, reg_max) %>% filter(.data$term == '.data$year')
lm_min_tidy$lab <- ifelse(lm_min_tidy$p.value < 0.05, 'p < 0.05', 'p > 0.05') lm_mean_tidy$lab <- ifelse(lm_mean_tidy$p.value < 0.05, 'p < 0.05', 'p > 0.05') lm_max_tidy$lab <- ifelse(lm_max_tidy$p.value < 0.05, 'p < 0.05', 'p > 0.05')
df_lab <- data.frame(min = lm_min_tidy$lab, mean = lm_mean_tidy$lab, max = lm_max_tidy$lab, stringsAsFactors = F)
return(df_lab) }`