1
$\begingroup$

I've read other similar questions on the site about logistic regression and I've read some articles/book chapters on this, but still I'm a little bit confused about that. I'll try to be as clearer as I can.

I have a medical case-control study, with many variables which could be used as predictors of the binary output variable, thus logistic regression is the best fit.

I have made some code in R, based on a previous question I made, like this:

model<-glm(Case ~ X + Y, data=data,    
family=binomial(logit));

where Case is the output variable, thus being 0 or 1 if it is a control or a case, respectively; X and Y are the input variables. I then use the output model to compute the area under the curve like this:

aucCP=auc(Case~predict(model), data=data);

Okay, now the troubles begin. First, I understand that the object "model" is the output of the logistic regression model, thus being the log(odds) of the probability that model is Case for each couple of data in X and Y. Am I right? Then, I know I can express the object model with an equation, being model:

Coefficients:
(Intercept)         X            Y      
  -1.142005    -0.047981     0.020145     

thus being model=-1.14- 0.05X+ 0.02Y. Right? Now the biggest problem: could "model" be considered as new variable, a combined predictor of X and Y, using which I predict Case?

$\endgroup$
2
  • $\begingroup$ In this case output produced by the predict function is logit. You can also output probability. $\endgroup$
    – Analyst
    Commented Aug 13, 2015 at 12:15
  • $\begingroup$ Okay, thus aucCP are logit. But what is really cant get is if this object "model" is some sort of new variable or not. $\endgroup$
    – Ciochi
    Commented Aug 13, 2015 at 12:44

1 Answer 1

3
$\begingroup$

If you call the function 'glm', then this function returns a new R-object that contains information on the result of the estimation. This returned object is then stored into a new R-variable that you have called 'model' (you can give it any name you want).

If you want to know all the details on what is contained in this variable, then you can ask for help on the function 'glm', in R you type '?glm' and under 'value' you can see all the attributed of your variable named 'model'. You could also use the R-instruction 'str(model)' to find out about the attributes of the variable 'model'.

The logistic regression estimates three coefficients in your case, these are also kept in the container model.

One of the attributes of your variable model (see ?glm) is 'coefficients, so you can ask for the values of the coefficients that the function 'glm' has estimated for you by typing 'model$coefficients'.

The variable model contains all information (like the coefficients but many other things) to make predictions.

All this is not about statistics but about programming in R.

To compute the AUC one has to compute rthe ROC-curve. For computing the ROC curve you need two things: (a) the observed values for your binary outcom and (b) the predicted outcomes by the logistic regression model.

Added because of your comments:

The binary outcome that you observe can be found in 'Case' therefore the function 'predict' has to compute the prediction by the estimated model. As the variable 'model' contains a.o. the coefficients, it can compute these predictions. So the function 'predict' uses information contained in the container (as you call it) 'model' to predict the outcomes using the estimated coefficients.

Then these observed outcomes (Case) and predicted outcomes ( predict (model) ) are used to compute the ROC and then from the ROC-curve to compute the area under the curve. The ROC curve is the set of couples (hit rate, false alarm rate) for different values of a choosen decision threshold.

So the instruction 'auc(Case~predict(model), data=data)' means 'use observed outcome 'case' and the predicted outcomes 'predict(model)' to compute the AUC.

The technique of logistic regression estimates value for the coefficients, in your case these are estimated at: -1.142005 (intercept), -0.047981 (coefficient of X), 0.020145 (coeficient of Y).

For each subject that you study, you have a value for case (0 or 1) and a value for x (let's note it $x_i$) and y (notation $y_i$). With the coefficients from the container object 'model', the function predict can then compute $-1.14 - 0.0479 x_i + 0.020 y_i$ for each subject $i$. The result will be a number for each subject in your sample. So with three coeffcients the function 'predict' can compute a number for each and every subject that you have in your sample.

This is not yet a prediction, the prediction should be either 0 or 1. So the number computed above is 'transformed' into 0 or 1 by choosing a threshold, e.g. if the number for subject $i$ is smaller than zero, then make it a zero, else make it 1.

So by choosing a threshold you can, using three estimated coefficient, predict whether a subject $i$ is zero or 1. You can do this for different values of the threshold (above I choose zero as threshod but one may also decide that it is transformed into 0 when the number is smaller than 5 e.g.). And by choosing different thresholds you can draw the ROC curve.

$\endgroup$
8
  • $\begingroup$ don't know if it's an R issue, maybe it's just a language issue, since i'm not a native english speaker. Indeed, i consider "variables" the input predictors X and Y, which, to me, are just....vectors of values, i don't know how else i could explain this. According to your answer, "model" is still a variable, but i see it as a sort of container, since i can extract different type of values, like coefficients, linear predictors and much more. What i cant understand is what is used, among all the available fields of "model", as the input for the auc prediction, and what this represents. $\endgroup$
    – Ciochi
    Commented Aug 13, 2015 at 13:11
  • $\begingroup$ @Ciochi: I added a section at the bottom of my answer $\endgroup$
    – user83346
    Commented Aug 13, 2015 at 13:19
  • $\begingroup$ Okay, thanks for the added content. I know this may seem dumb, but i'm kinda noob on these topics. Try to follow these steps: 1) i have observed values (0 and 1) for the output variable; 2) i have predictors X and Y, which are the input variables of the model; 3) i compute a logistic regression model. The logistic regression is a technique used to combine two or more independent variables; 4) The resulting variable-container "model" has various fields, among which the coefficients. Now, as i guess these coefficients are nothing more than...a vector of values, right? (continues) $\endgroup$
    – Ciochi
    Commented Aug 13, 2015 at 13:33
  • $\begingroup$ (continue from the previous) Then, suppose Case are N observations. Then i expect N coefficients as well. Having then a vector of N coefficients, could i think of it as a new variable, calling maybe combined predictor, since it is the result of the estimation through the model which combines two input variables? In other words, can i state: " The logistic regression model was used to estimate a new combined predictor, which was then used to predict the outcome variable Case, obtaining an AUC 0.71" ? $\endgroup$
    – Ciochi
    Commented Aug 13, 2015 at 13:36
  • $\begingroup$ @Ciochi: seet at the bottom of my answer, I will add it $\endgroup$
    – user83346
    Commented Aug 13, 2015 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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