I am using a lmer model (https://fhernanb.github.io/libro_modelos_mixtos/pac-lme4.html) to model the price elasticity of different products in different countries. After training the model with the historical data, sometimes for some of these products the elasticity is positive (by definition it should be negative or simply due to business restrictions). So I need to adjust some of the coefficients manually, only those that don't make sense. My model is:
model_str = """
log(units)~
log(price_usd) + (log(price_usd)|sku/country)
"""
model = lmerTest.lmer(model_str, data = df)
In this question Replace lmer coefficients in R the same question is solved, but in this case I'm using rpy2. So, I would like to know how to change the coefficients of a lmer model when using rpy2.
In order to change the coefficients with R:
library(lme4)
fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
summary(fm1)$coef
# Estimate Std. Error t value
#(Intercept) 251.40510 6.823773 36.842535
#Days 10.46729 1.545958 6.770744
fm1@beta[names(fixef(fm1)) == "Days"] <- 0
summary(fm1)$coef
# Estimate Std. Error t value
#(Intercept) 251.4051 6.823773 36.84253
#Days 0.0000 1.545958 0.00000