Would it be possible to have a predict/fitted methods for the output of a feols call with multiple left-hand side variable, of class fixest_multi, such as feols(c(y1, y2) ~ x1 + x2, base)? For now, there are two issues:
predict(feols(c(y1, y2) ~ x1 + x2, base)) returns error: _no applicable method for 'predict' applied to an object of class "fixestmulti"
Admittedly, naming the columns of the predict/fitted when there are multiple X combos would be a bit tricky (and even more complicated to define which x-combination to use with newdata in predict), but maybe at least the case with multiple-Y single X-combo could be covered?
Thanks!
library(fixest)
library(lfe)
#> Loading required package: Matrix
base = iris
names(base) = c("y1", "y2", "x1", "x2", "species")
res_feols = feols(c(y1, y2) ~ x1 + x2, base)
res_mlm = lm(cbind(y1, y2) ~ x1 + x2, base)
res_lfe = felm(y1+ y2 ~ x1 + x2, base)
fitted(res_mlm)|>head()
#> y1 y2
#> 1 4.885160 3.299865
#> 2 4.885160 3.299865
#> 3 4.830983 3.325579
#> 4 4.939338 3.274151
#> 5 4.885160 3.299865
#> 6 4.983783 3.295532
predict(res_mlm)|>head()
#> y1 y2
#> 1 4.885160 3.299865
#> 2 4.885160 3.299865
#> 3 4.830983 3.325579
#> 4 4.939338 3.274151
#> 5 4.885160 3.299865
#> 6 4.983783 3.295532
fitted(res_feols)|>head()
#> NULL
predict(res_feols)|>head()
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'head': no applicable method for 'predict' applied to an object of class "fixest_multi"
fitted(res_lfe)|>head()
#> y1 y2
#> [1,] 4.885160 3.299865
#> [2,] 4.885160 3.299865
#> [3,] 4.830983 3.325579
#> [4,] 4.939338 3.274151
#> [5,] 4.885160 3.299865
#> [6,] 4.983783 3.295532
predict(res_lfe)|>head()
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'head': no applicable method for 'predict' applied to an object of class "felm"
Would it be possible to have a
predict
/fitted
methods for the output of afeols
call with multiple left-hand side variable, of classfixest_multi
, such asfeols(c(y1, y2) ~ x1 + x2, base)
? For now, there are two issues:fitted(feols(c(y1, y2) ~ x1 + x2, base))
returnsNULL
predict(feols(c(y1, y2) ~ x1 + x2, base))
returns error: _no applicable method for 'predict' applied to an object of class "fixestmulti"Admittedly, naming the columns of the predict/fitted when there are multiple X combos would be a bit tricky (and even more complicated to define which x-combination to use with
newdata
in predict), but maybe at least the case with multiple-Y single X-combo could be covered?Thanks!
Created on 2022-11-16 with reprex v2.0.2