# How to insert a constraint on coefficients of logistic regression model?

I want to build a logistic regression model on my data, which contains three continuous predictors and a logical response. I need to constrain the regression coefficients to be not less than 0 and sum up to a constant, i.e.,

$$y=\frac {1}{1+e^{-(\beta_1\times x_1+\beta_2 \times x_2+\beta_3 \times x_3)}}$$

$$s.t. \beta_j \geq 0(j=1,2,3)$$

$$\beta_1+\beta_2+\beta_3=1$$

Is there anyone who knows how to add such constraint in theory? And how can this be done in MATLAB? The following is my test code using the function 'glmfit' which did not have an option to introduce a constraint:

dsa = hospital;

Age = dsa.Age;
Weight = dsa.Weight;
Blood = dsa.BloodPressure(:, 1);

Smoker = dsa.Smoker;

mdl = fitglm([Age, Weight, Blood], Smoker, 'Distribution', 'binomial', 'Intercept', false)
• Sounds like nonlinear programming? In any event, we are all curious as to why you want to do this. Jan 25 at 11:57
• I want to use the fitted weights to weighing multiple models in model averaging of classifiers, in which the weights I assume to be nonnegative and constrained in the simplex space. Jan 25 at 12:57
• Ok, I guess you realize that classification will probably be worse when you constrain, but depending on sample size, perhaps not. Jan 25 at 13:57
• Thank you. I also guess the performance will decline if constraint was considered. But what does you mean by "...but depending on sample size, perhaps not"? It is not clear to me. Jan 25 at 14:59
• With small sample sizes, reasonable constraints often reduce variability and thus can provide more accurate estimates. Jan 25 at 15:35