问题标签 [broom]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
237 浏览

r - R broom 包中的通货膨胀功能未按预期工作

我希望下面的代码

给我一个 12 x 4 的数据框,如下所示:

但它给了我这个:

似乎d被忽略了。这是怎么回事?

0 投票
1 回答
74 浏览

r - 每组构建多个模型

我想对我的数据进行分组,然后每组构建两个线性模型,收集结果,并使用扫帚来总结模型参数,但是我遇到了一个我似乎无法理解的无限递归错误。这是代码:

导致此错误:

Error: evaluation nested too deeply: infinite recursion / options(expressions=)?

这个例子中只有 4 个模型,所以我不明白为什么我会遇到这么深的嵌套循环?

0 投票
2 回答
574 浏览

r - 带有统计测试的 dplyr

我有以下数据设置

我想在 my.group 上分组并应用 binom.test

收到错误消息,找不到成功我在这里做错了什么?

0 投票
1 回答
443 浏览

r - Is there a way to catch both Coefficient and R-squared using Broom?

I'm looping trough several regressions and aim to have a final result with different models, their respective coefficients and statistics, and some general results, as adjusted r squared, AIC and etc. This looping is done considering some subgroups in the database.

As I am using the plm to estimate the results, the broom package produce some nice results to package everything in a neat database. However, their options are kind of limiting. Or do you get the coefficients and their statistics (using tidy - provide p-values, t-statistics etc), or you get the overal model statistics (using glance - provide R-squared, adjusted R-squared, AIC etc).

-Is there a way to have both data without recalculating the regression?

I know I can merge the final result, but this would involve double calculation of each regression, and this is computationally costly. I know that the end result would repeat the aggregated statistics for each line of the coefficients, but I don't mind.

-Also see that my code kind of repeat the estimations of each regression to provide robust estimations, does anyone know a workaround for this?

A MWE follows:

0 投票
1 回答
468 浏览

r - 在具有 purrr map2 函数的线性模型中使用多个预测变量

我的问题与类似,但现在我正在尝试使用具有多个预测变量的模型,但我不知道如何将新数据放入预测函数中。

首先,我创建了几周的序列

然后我抓住当前年份

在这里,我创建了一个带有虚拟数据的数据框

接下来,我创建一个嵌套数据框,其中包含一年中每周的数据作为一组。

在这里,我将今年的数据按一年中的一周加入到前几年的数据中。

这会将线性模型添加到一年中每周的数据框中

现在我想使用每周的模型来预测使用今年的数据。我尝试了以下方法:

这给出了以下错误:

然后我尝试将我的预测器嵌套在我的数据框中......

仅使用今年的数据创建一个数据框并嵌套预测变量

将此加入我的主数据框中

现在我再次尝试预测:

我得到与以前相同的错误:

我认为答案可能涉及对预测变量执行 flatten() ,但我无法弄清楚它在我的工作流程中的位置。

对比

在这一点上,我已经没有想法了。

0 投票
1 回答
218 浏览

r - 如何按条件从(嵌套)回归模型中绘制回归系数(或模型参数的其他估计)?

我正在尝试从(嵌套)数据帧(按条件)绘制回归系数,为此我针对每个条件内的嵌套数据的四个条件(具有多个预测变量)运行四个回归模型。根据条件绘制每个模型的 R 平方值(参见示例)是可行的,但现在我想先按条件绘制 x1 的回归系数(x1 的 b 以降序排列),然后再绘制 x2 的回归系数(甚至由预测器编号),有人可以帮我解决代码吗?

绘制多个模型的 R - Squared 值的示例:

所以这个例子有效,但我不知道如何单独提取系数并在类似的图表中按条件按降序绘制这些系数。谢谢

0 投票
1 回答
62 浏览

r - Access the estimate inside a model object in R

I am running a simulation and would like to know if there was a way to access the "x" estimate inside of my model using broom, dplyr, modelr, or purrr.

This gives me exactly what I want, but I don't want to use [[1]] in the last chunk of code.

0 投票
0 回答
702 浏览

r - 无法使用扫帚为具有 sigma.formula 项的 gamlss 模型获得置信区间

我正在通过调用拟合 gamlss 模型:

但是,在尝试使用以下方法获取置信区间时出现错误broom::confint_tidy

消息是:

但是,尝试使用时出现不同的错误broom::tidy

消息是:

但是,当我在没有术语的情况下拟合此模型sigma.formula时,我能够获得置信区间。

可重现的例子

示例输出

错误输出的屏幕截图

0 投票
1 回答
155 浏览

r - 如何在 dplyr 的常规变异中创建基于 lm 的变量?

考虑这个简单的例子:

在这里,我想分组group并创建两列。

一个是value(我可以使用dplyr::n_distinct)中不同值的数量,另一个是来自向量 1 的回归的常数项value。也就是说,

这里的困难是将这两个简单的输出组合成一个mutate保留分组的语句。

我试过类似的东西:

但这不起作用。我在这里缺少什么?谢谢!

0 投票
1 回答
323 浏览

r - 如何编写一个使用 broom、dplyr 和 lm 的函数?

考虑这个非常简单的例子

在这里,我想编写一个函数,输出 的均值的置信估计上限value。那是,

现在,这很容易

这也有效(注意 a 之后的调用group_by

这非常有效

...但这失败了

我不明白这里有什么问题。我真的需要一个适用于上述四种情况的解决方案。

有任何想法吗?非常感谢!!