broom

Correlation matrix with dplyr, tidyverse and broom - P-value matrix

ぃ、小莉子 提交于 2019-12-06 04:11:36
all. I want to obtain the p-value from a correlation matrix using dplyr and/or broom packages and testing multiple variables at the same time . I'm aware of other methods, but dplyr seems easier and more intuitive for me. In addition, dplyr will need to correlate each variable to obtain the specific p-value, what makes the process easier and faster. I checked other links, but they did not work for this question ( example 1 , example 2 , example 3 ) When I use this code, the correlation coefficients are reported. However, the P-values are not. agreg_base_tipo_a %>% dplyr::select(S2.RT, BIS

Error when using broom (augment) and dplyr with loess fit

匆匆过客 提交于 2019-12-06 01:54:24
I am trying to use augment on a loess fit, but I receive the following error: Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 32, 11 In the error message, 11 happens to equal the number of observations in one segment and 32 is the total number of observations. The code is below. require(broom) require(dplyr) # This example uses the lm method and it works regressions <- mtcars %>% group_by(cyl) %>% do(fit = lm(wt ~ mpg, .)) regressions %>% augment(fit) # This example uses the loess method and it generates the error regressions2 <- mtcars %>% group_by

keep region names when tidying a map using broom package

橙三吉。 提交于 2019-12-06 00:06:06
I am using the getData function from the raster package to retrieve the map of Argentina. I would like to plot the resulting map using ggplot2, so I am converting to a dataframe using the tidy function from the broom package. This works fine, but I can't figure out how to preserve the names of the federal districts so that I can use them on the map. Here is my original code that does not preserve the district names: # Original code: ################################## # get the map data from GADM.org and then simplify it arg_map_1 <- raster::getData(country = "ARG", level = 1, path = "./data/")

Handling vectors of different lengths in purrr

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 02:08:50
问题 I currently have the following R code that runs multiple regression models with different predictors, across different subsets, and returns tidied output using the broom package. library(dplyr) library(purrr) library(broom) cars <- mtcars preds<-c("disp", "drat", "wt") model_fits <- map_df(preds, function(pred) { model_formula <- sprintf("mpg ~ %s", pred) cars %>% group_by(cyl) %>% do(tidy(lm(model_formula, data = .), conf.int = T)) %>% filter(term == pred) %>% mutate(outcome = "mpg") %>%

Comparing models with dplyr and broom::glance: How to continue if error is produced?

陌路散爱 提交于 2019-12-04 22:38:10
I would like to run each variable in a dataset as a univariate glmer model using the lme4 package in R. I would like to prepare the data with the dplyr/tidyr packages, and organize the results from each model with the broom package (i.e. do(glance(glmer...). I would most appreciate help that stuck within that framework. I'm not that great in R, but was able to produce a dataset that throws an error and has the same structure as the data I'm using: library(lme4) library(dplyr) library(tidyr) library(broom) Bird<-c(rep(c(0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0),10)) Stop<-c(rep(seq(1,10), 20))

R: How to apply a function that outputs a dataframe for multiple columns (using dplyr)?

百般思念 提交于 2019-12-04 11:55:35
I want to find correlations, p-values and 95% CI between one specific column and all other columns in a dataframe. The 'broom' package provides an example how to do that between two columns using cor.test with dplyr and pipes. For mtcars and, say, mpg column we can run a correlation with another column: library(dplyr) library(broom) mtcars %>% do(tidy(cor.test(.$mpg, .$cyl))) estimate statistic p.value parameter conf.low conf.high 1 -0.852162 -8.919699 6.112687e-10 30 -0.9257694 -0.7163171 The output is a single-row dataframe. I'd like to run cor.test for mpg with each column and send the

Using tidytext and broom but not finding tidier for LDA_VEM

梦想的初衷 提交于 2019-12-04 04:52:24
问题 The tidytext book has examples with a tidier for topicmodels: library(tidyverse) library(tidytext) library(topicmodels) library(broom) year_word_counts <- tibble(year = c("2007", "2008", "2009"), + word = c("dog", "cat", "chicken"), + n = c(1753L, 1157L, 1057L)) animal_dtm <- cast_dtm(data = year_word_counts, document = year, term = word, value = n) animal_lda <- LDA(animal_dtm, k = 5, control = list( seed = 1234)) animal_lda <- tidy(animal_lda, matrix = "beta") # Console output Error in as

Function for Tidy chisq.test Output for Visualizing or Filtering P-Values

旧时模样 提交于 2019-12-04 02:11:22
问题 For data... library(productplots) library(ggmosaic) For code... library(tidyverse) library(broom) I'm trying to create tidy chisq.test output so that I can easily filter or visualize p-values. I'm using the "happy" dataset (which is included with either of the packages listed above) For this example, if I wanted to condition the "happy" variable on all other variables,I would isolate the categorical variables (I'm not going to create factor groupings out of age, year, etc, for this example),

Handling vectors of different lengths in purrr

我与影子孤独终老i 提交于 2019-12-03 17:30:52
I currently have the following R code that runs multiple regression models with different predictors, across different subsets, and returns tidied output using the broom package. library(dplyr) library(purrr) library(broom) cars <- mtcars preds<-c("disp", "drat", "wt") model_fits <- map_df(preds, function(pred) { model_formula <- sprintf("mpg ~ %s", pred) cars %>% group_by(cyl) %>% do(tidy(lm(model_formula, data = .), conf.int = T)) %>% filter(term == pred) %>% mutate(outcome = "mpg") %>% select(outcome, cyl:estimate, starts_with("conf.")) }) This results in the following data frame: > model

Using tidytext and broom but not finding tidier for LDA_VEM

空扰寡人 提交于 2019-12-02 02:17:38
The tidytext book has examples with a tidier for topicmodels: library(tidyverse) library(tidytext) library(topicmodels) library(broom) year_word_counts <- tibble(year = c("2007", "2008", "2009"), + word = c("dog", "cat", "chicken"), + n = c(1753L, 1157L, 1057L)) animal_dtm <- cast_dtm(data = year_word_counts, document = year, term = word, value = n) animal_lda <- LDA(animal_dtm, k = 5, control = list( seed = 1234)) animal_lda <- tidy(animal_lda, matrix = "beta") # Console output Error in as.data.frame.default(x) : cannot coerce class "structure("LDA_VEM", package = "topicmodels")" to a data