Set one or more of coefficients to a specific integer

前端 未结 1 1298
借酒劲吻你
借酒劲吻你 2020-11-30 14:03

I am using a standard lm model and would like to set the coefficients of one or more of my variables to a specific integer.

For example, I would like the coefficien

相关标签:
1条回答
  • 2020-11-30 14:11

    You can use the offset term in the formula and include the desired coefficient and variable therein:

    df<-data.frame(aa=1:6,bb=2:7,cc=c(4,2,7,5,8,3))
    
    lm(cc ~ aa + offset(647*bb), data = df)
    

    So this is regressing cc on aa plus the fixed term bb * 647. For more than one given coefficient, add the appropriate additional offset() terms.

    0 讨论(0)
提交回复
热议问题