1
$\begingroup$

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];

b = glmfit(X,y,'binomial','link','logit');

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.

$\endgroup$
  • $\begingroup$ 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$? $\endgroup$ – whuber Feb 8 '16 at 13:24
  • $\begingroup$ 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! $\endgroup$ – user101051 Feb 8 '16 at 13:46
  • 1
    $\begingroup$ You are asking for something mathematically impossible, because $\exp(\eta)/(1+\exp(\eta))$ can never equal $1$ or $0$. $\endgroup$ – whuber Feb 8 '16 at 17:26
0
$\begingroup$

The linear regression does not give you the value of $0$ or $1$ but the probability of being $1$.

If you want the expected response variable to be binary, you need some kind of cutoff like :

$\frac{e^{\eta}}{(1+e^{\eta})}>0.5 = 1 $,

$\frac{e^{\eta}}{(1+e^{\eta})}<0.5 = 0 $.

$\endgroup$
  • $\begingroup$ Thanks. However, sometimes I get the same probability, say 0.57 for n=1 and n=2. Yet the initial y vector that I provide states success for n=1 (that is, y(1) = 1), but not n=2 (y(2) = 0). I would assume that values where y(n) = 1, would have a probability 1 of success. $\endgroup$ – user101051 Feb 8 '16 at 14:16
  • $\begingroup$ @user101051 I get why you would think that. But you are never gonna predict perfectly not even in the estimated sample $\endgroup$ – Repmat Feb 8 '16 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.