0

enter image description here

a is {0, 1} binary variable, X dimension is 3 (first column is all-ones vector, the number of predictor is 2)

If write the expression differently, it becomes like this

y = Xb0 + aX(b1-b0) + e

= b00 + b01X1 + b02X2 + (b10-b00)a + (b11-b01)aX1 + (b12-b02)aX2 + e

What I interest is interaction between a and x so I want to know all the values for beta. \
How to code this using python??

  1. I made newX = (1, X1, X2, a, aX1, aX2) and using this,
    model = ols(formula='Y~X1+X2+a+aX1+aX2', data=data).fit() 

but I think this would be inefficient if the input dimension grew.

  1. I searched and found out 'weights' options in R,

lm(y~x1+x2, weights=(I=a))

Should I find something similar in Python and use it?

Which way is right?? If there is another way, please let me know.

imsh
  • 1
  • 1
  • AFAIU, the weight option would not be equivalent to an interaction effect. weights just means WLS instead of OLS. – Josef Oct 27 '22 at 15:13
  • in which direction would your input dimension grow? Increasing the number of observations with only 6 columns of the design matrix should not be any problem, up to nobs is several millions depending on RAM. Also, if you already have the design matrix as numpy array or pandas dataframe, then avoiding the formula is more efficient. – Josef Oct 27 '22 at 15:16

0 Answers0