-1

I'm trying to calculate my logit regression from the OLS. So in the first step I used the lm() function, then I calculated yhat and the probability. Then comes the error message that NaNs are produced. What did I do wrong?

start<-lm(invest~profit+gender,data=data)
summary(start)

data$yhat<-intercept+b1*data$profit+b2*data$gender

data$w<-sqrt(1/(data$yhat*(1-data$yhat)))

logit_2<-lm(w~profit+gender,data=data)
summary(logit_2)

Thank you for your help!

Anna
  • 1
  • You know you can do that inside of `lm` or `glm` with the `binomial` family option, right? Also, please also for code debugging please always ask with a [reproducible](https://stackoverflow.com/q/5963269/1422451) example per the [MCVE](https://stackoverflow.com/help/mcve) and [`r`](https://stackoverflow.com/tags/r/info) tag description, with the desired output. You can use `dput()`, `reprex::reprex()` or built-in data sets for reproducible data. – Hack-R Jul 08 '18 at 20:52

1 Answers1

0

I feel it should be as follow, not the sqrt. Try it.

data$w<-ln(1/(data$yhat*(1-data$yhat)))

Note:

p = a0 + a1X1 + a2X2 + … + akXk    (linear)
ln[p/(1-p)] = b0 + b1X1 + b2X2 + … + bkXk       (logistic)