Last active
November 30, 2015 20:22
-
-
Save infotroph/3b21bb6cc561783ac507 to your computer and use it in GitHub Desktop.
This is a visual approach to evaluating whether my logistic regression estimates are close to the simulated values. Can I instead compute scale and location directly from glm estimates?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(254469) | |
n=100 | |
xlo=0 | |
xhi=20 | |
loc_logis=5 | |
scale_logis=3 | |
x = runif(n, xlo, xhi) | |
p_detect = plogis(x, location=loc_logis, scale=scale_logis) | |
y = rbinom(n, size=1, prob=p_detect) | |
model = glm(y~x, family=binomial) | |
lo2p = function(x, int, slope){ | |
1/(1+exp(-(int+slope*x))) | |
} | |
plot(y~x) | |
lines(xlo:xhi, plogis(xlo:xhi, loc_logis, scale_logis), col="red") | |
lines(xlo:xhi, lo2p(xlo:xhi, coef(model)[1], coef(model)[2]), col="blue") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment