运行回归时避免系数名称过高

时间:2018-11-15 13:09:41

标签: r dplyr lm purrr

我使用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

1 个答案:

答案 0 :(得分: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)