【问题标题】:Avoid unseemly coefficient name when running regression运行回归时避免不恰当的系数名称
【发布时间】:2019-04-18 14:27:02
【问题描述】:

我使用map2 函数运行以下回归:

map2(listOfInvVolWeightedOtherStratPortfolioReturns,listOfValueAndMomentumFactorReturns,~lm((.y %>% select(-date) %>% as.matrix()) ~ (.x %>% select(-date) %>% as.matrix())) %>% summary())

reg输出列表中每个reg的系数名称是.x %>% select(-date) %>% as.matrix()

                                            Estimate
(Intercept)                               0.01244429
.x %>% select(-date) %>% as.matrix()     -0.81570351

当我运行回归以避免这种情况时,我如何设置系数的名称,比如factor

【问题讨论】:

  • 疯狂的想法:不要创建这些 tidyverse 绦虫之一并编写一些 (i) 更易于阅读和 (ii) 更易于调试的 R 代码,并且也很容易解决这个问题。我很欣赏有些人发现 magrittr 链更具可读性,但显然不是这样。

标签: r dplyr lm purrr


【解决方案1】:

如果没有 reprex,这很困难,但以下内容更具可读性,我相信它应该可以工作:

myFun <- function(x, y) {
  x <- x %>%
    select(-date) %>%
    as.matrix()
  y <- y %>%
    select(-date) %>%
    as.matrix()
  res <- lm(y ~ x) %>%
    summary()
  return(res)
}
map2(listOfInvVolWeightedOtherStratPortfolioReturns,
     listOfValueAndMomentumFactorReturns,
     myFun)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-30
    • 2021-09-20
    • 2018-12-15
    • 2015-06-28
    • 2021-02-26
    • 1970-01-01
    • 1970-01-01
    • 2010-10-12
    相关资源
    最近更新 更多