Home > other >  Linear model with some forced / preset coefficients in R
Linear model with some forced / preset coefficients in R

Time:01-26

I am using a simple 3-variable model like this:

0 = b0 b1x b2y b3z b4xy b5xz b6yz b7xyz

This is being used to describe synergism/antagonism between chemicals. b0 represents overall effect, b1-b3 are individual active effects of the chemicals, and b4-b7 are interactive effects.

I can get accurate coefficients using some pre-constructed data:

x1 <- c(0,1,2,3,4,1,2,3,4,1,2,3,4,5,6,7,8)
y1 <- c(0,2,1,5,4,3,7,5,8,6,2,1,5,5,3,5,7)
z1 <- c(0,1,-0.66667,-6,-7.25,-0.66667,-5.55556,-6,-6.125,-4,-2.5,-6,-6.8,-7.3913,-11.1429,-8.2069,-6.83333)

q <- c(-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)

model <- lm(q ~ x1*y1*z1)

However, using some other tests (e.g. including noise) the results aren't as accurate as I would like. The good thing is that for this application it's easy enough to get values for b1, b2, and b3 (and set b0 as -1).

Is there a way in R to run this linear model, forcing values for b0-b3, and only solving for b4-b7?

Thanks!

CodePudding user response:

Remove the columns not wanted by subtracting them and use 0 or - 1 to remove the intercept. Then use offset to set the fixed values.

lm(q ~ x1 * y1 * z1 - x1 - y1 - z1   offset(- x1 - y1 - z1 - 1)   0)

It can also be expressed like this:

DF <- data.frame(x1, y1, z1)
lm(q ~ .^3 - .   offset(- rowSums(DF) - 1)   0, DF)
  •  Tags:  
  • Related