broom

loess regression on each group with dplyr::group_by()

梦想的初衷 提交于 2020-05-07 05:53:58
问题 Alright, I'm waving my white flag. I'm trying to compute a loess regression on my dataset. I want loess to compute a different set of points that plots as a smooth line for each group. The problem is that the loess calculation is escaping the dplyr::group_by function, so the loess regression is calculated on the whole dataset. Internet searching leads me to believe this is because dplyr::group_by wasn't meant to work this way. I just can't figure out how to make this work on a per-group basis

loess regression on each group with dplyr::group_by()

邮差的信 提交于 2020-05-07 05:50:48
问题 Alright, I'm waving my white flag. I'm trying to compute a loess regression on my dataset. I want loess to compute a different set of points that plots as a smooth line for each group. The problem is that the loess calculation is escaping the dplyr::group_by function, so the loess regression is calculated on the whole dataset. Internet searching leads me to believe this is because dplyr::group_by wasn't meant to work this way. I just can't figure out how to make this work on a per-group basis

Iterating over multiple regression models and data subsets in R

北慕城南 提交于 2020-02-03 12:16:08
问题 I am trying to learn how to automate running 3 or more regression models over subsets of a dataset using the purrr and broom packages in R. I am doing this with the nest %>% mutate(map()) %>% unnest() flow in mind. I am able to replicate examples online when there is only one regression model that is applied to several data subsets. However, I am running into problems when I have more than one regression model in my function. What I tried to do library(tidyverse) library(broom) estimate_model

Iterating over multiple regression models and data subsets in R

允我心安 提交于 2020-02-03 12:15:27
问题 I am trying to learn how to automate running 3 or more regression models over subsets of a dataset using the purrr and broom packages in R. I am doing this with the nest %>% mutate(map()) %>% unnest() flow in mind. I am able to replicate examples online when there is only one regression model that is applied to several data subsets. However, I am running into problems when I have more than one regression model in my function. What I tried to do library(tidyverse) library(broom) estimate_model

R2 values - dplyr and broom

ε祈祈猫儿з 提交于 2020-01-22 19:41:27
问题 I am using the dplyr and broom combination (per below) and following Fitting several regression models with dplyr to extract the regression coefficients of regressions by group. However - i am also interested in the R2 value of each individual regression (not only for the total model). i have tried to play wiht the augment and glance functions - but have not been able to extract the R2 values. is there an easy way to do this? Many thanks in advance! library(dplyr) library(broom) df.h = data

tidy from broom not finding method for LDA from topicmodels

拜拜、爱过 提交于 2020-01-16 15:26:51
问题 Running this script, straight from 'Text mining with R', library(topicmodels) library(broom) data("AssociatedPress") ap_lda <- LDA(AssociatedPress, k = 2, control = list(seed = 1234)) tidy(ap_lda) I get this error message: Error in as.data.frame.default(x) : cannot coerce class "structure("LDA_VEM", package = "topicmodels")" to a >data.frame In addition: Warning message: In tidy.default(ap_lda) : No method for tidying an S3 object of class LDA_VEM , using as.data.frame packageVersion("broom")

tidy from broom not finding method for LDA from topicmodels

走远了吗. 提交于 2020-01-16 15:26:11
问题 Running this script, straight from 'Text mining with R', library(topicmodels) library(broom) data("AssociatedPress") ap_lda <- LDA(AssociatedPress, k = 2, control = list(seed = 1234)) tidy(ap_lda) I get this error message: Error in as.data.frame.default(x) : cannot coerce class "structure("LDA_VEM", package = "topicmodels")" to a >data.frame In addition: Warning message: In tidy.default(ap_lda) : No method for tidying an S3 object of class LDA_VEM , using as.data.frame packageVersion("broom")

Trying to unnest broom::augment data, but R “can't cast”

给你一囗甜甜゛ 提交于 2020-01-06 05:17:46
问题 I can't reproduce the data here, but I'm hoping I'm making an obvious mistake. I am trying to get residuals from all the of the models I fit with purrr::map. My code looks like this: df %>% group_by(group) %>% nest() %>% mutate(model = map(data, fit_mod), model_data = map(model, broom::augment)) %>% ungroup()%>% unnest(c(data, model_data)) I get an error related to the title of one of the coefficients in my model: Error: Can't cast model_data$poly.Actual_Population..2..raw...TRUE. to model

How can I apply grouped data to grouped models using broom and dplyr?

邮差的信 提交于 2020-01-03 20:05:08
问题 I'd like to do the equivalent of fitting a model of gpm (gallons per mile = 1/mpg) to wt in the mtcars data set. That seems easy: data(mtcars) library(dplyr) library(tidyr) library(broom) library(ggplot2) library(scales) mtcars2 <- mtcars %>% mutate(gpm = 1 / mpg) %>% group_by(cyl, am) lm1 <- mtcars2 %>% do(fit = lm(gpm ~ wt, data = .)) That gets me a rowwise data frame with 6 rows, as expected. This graph confirms that there are six groups: p1 <- qplot(wt, gpm, data = mtcars2) + facet_grid

How can I apply grouped data to grouped models using broom and dplyr?

元气小坏坏 提交于 2020-01-03 20:04:43
问题 I'd like to do the equivalent of fitting a model of gpm (gallons per mile = 1/mpg) to wt in the mtcars data set. That seems easy: data(mtcars) library(dplyr) library(tidyr) library(broom) library(ggplot2) library(scales) mtcars2 <- mtcars %>% mutate(gpm = 1 / mpg) %>% group_by(cyl, am) lm1 <- mtcars2 %>% do(fit = lm(gpm ~ wt, data = .)) That gets me a rowwise data frame with 6 rows, as expected. This graph confirms that there are six groups: p1 <- qplot(wt, gpm, data = mtcars2) + facet_grid