I'm trying to run a simple OLS regression with a restriction that the sum of the coefficients of two variables add up to 1.

I want:

```Y = α + β1 * x1 + β2 * x2 + β3 * x3,
where β1 + β2 = 1
```

I have found how to make a relation between coefficients like:

```β1 = 2* β2
```

But I haven't found how to make restrictions like:

```β1 = 1 - β2
```

How would I do it in this simple example?

```data <- data.frame(
A = c(1,2,3,4),
B = c(3,2,2,3),
C = c(3,3,2,3),
D = c(5,3,3,4)
)

lm(formula = 'D ~ A + B + C', data = data)```
Mar 10, 2022 462 views

## 1 answer to this question.

b1 + b2 = 1
Let us fit this to the model

`result <- lm(Y ~  offset(x1) + I(x2 - x1) + x3, data = data_frame)`

This means
Y = a +x1+b2*(x2-x1)+b3*x3

after substituting b1 = 1- b2
new_x = x2-x1 and the coefficient for x1 is 1
b1+b2+b3 = 1

`result <-  lm(Y ~ offset(x1) + I(x2 - x1) + I(x3 - x1), data = data_frame)`

Y = a +x1 + b2*(x2-x1)+b3*(x3-x1)

after substituting b1 =1-b2-b3

b1+b2+b3+..... = 1

I believe the pattern is obvious... all you have to do is subtract one variable, x1, from the other variables (x2, x3, etc.) and set the coefficient of that variable, x1, to 1.

Example:  b1 + b2 = 1

```# Data
data_frame<- iris[, 1:4]
colnames(data_frame) <- c("Y", paste0("x", 1:3, collaapse=""))
# b1 + b2 = 1
result <- lm(Y ~  offset(x1) + I(x2 - x1) + x3, data = data_frame)
coeff_2 <- coef(result)
b_1 <- 1 - coeff_2
b_2 <- coeff_2
```
• 5,480 points

## Is there a way to force the coefficient of the independent variable to be a positive coefficient in the linear regression model used in R?

A Few Constraints This is an example of ...READ MORE

## How to add random and/or fixed effects into cloglog regression in R

Update question on treatment of one variable ...READ MORE

## How to resolve heteroscedasticity in Multiple Linear Regression in R?

Try to use a different form of ...READ MORE

## How to get a regression summary in scikit-learn like R does?

In sklearn, there is no R type ...READ MORE

## How to export regression equations for grouped data?

First, you'll need a linear model with ...READ MORE

## Selecting only p-value and r.squared value from linear regression result

You can use the \$ symbol to ...READ MORE

## How to add regression line equation and R2 on graph?

Below is one solution: # GET EQUATION AND ...READ MORE

## Steps to evaluate Linear Regression in R

These are sequential steps which need to ...READ MORE