# linear regression matlab

I have three predictor variables

A: binary (A = vector of length N containing 0 and 1)

B: three categories 1, 2, 3 (B = vector of length N containing 1,2 or 3)

C: continuous (C = vector of length N containing real, positive integers)

and one response variable

y: binary (y = vector of length N, where half entries are 0 and other half are 1).

Bcat = dummyvar(B);

Bcat = Bcat(:,2:3); % remove the first column

X = [A Bcat C];

So for a particular n (n=1..N) then the probability of y(n) being 1 is given by

eta = b(1) + X(n,1)*b(2) + X(n,2)*b(3) + X(n,3)*b(4) + X(n,4)*b(5);

Prob(n) = exp(eta)/(1+exp(eta));

But this gives a range around 0.5 for all values, where I would like it to be 1 where the initial input y vector stated it is 1 for certain.

• It's a little unclear what your question is. Are you asking why the predicted probabilities are not exactly the same as the values in $y$? – whuber Feb 8 '16 at 13:24
• Firstly, thank you for your help. Yes. I'm trying to predict the probability of a success in N different events. I already have a success for half the events, given in y. I'm trying to make predictions for the other half. I would expect entries in Prob to be 1 where the y vector is 1. For example, if y(n) = 1, then wouldn't Prob(n) = 1 since we already know a success occurred here? Thanks again! – user101051 Feb 8 '16 at 13:46
• You are asking for something mathematically impossible, because $\exp(\eta)/(1+\exp(\eta))$ can never equal $1$ or $0$. – whuber Feb 8 '16 at 17:26

The linear regression does not give you the value of $0$ or $1$ but the probability of being $1$.
$\frac{e^{\eta}}{(1+e^{\eta})}>0.5 = 1$,
$\frac{e^{\eta}}{(1+e^{\eta})}<0.5 = 0$.