原文链接： http://tecdat.cn/?p=6851

`dat <- data.frame(x = rbinom(300, 1, .5)) # Outcome ys = intercept of -0.5, the coefficient of x is 1 and there is logistic error dat\$yc <- -.5 + dat\$x + rlogis(nrow(dat))`

`hist(dat\$yc, main = "")`

`coef(glm((yc > -2) ~ x, binomial, dat))["x"] # Cut it at extreme -2 x 0.9619012 coef(glm((yc > 0) ~ x, binomial, dat))["x"] # Cut it at midpoint 0 x 1.002632 coef(glm((yc > 2) ~ x, binomial, dat))["x"] # Cut it at extreme 2 x 0.8382662`

`# First, we create an equation to extract the coefficients and # transform them using the transform to logit formula above. trans <- function (fit, scale = pi / sqrt(3)) { scale * coef(fit) / sigma(fit) } trans(lm(yc ~ x, dat))["x"] x 1.157362`

`colMeans(res <- t(replicate(2500, { dat <- data.frame(x = rbinom(300, 1, .5)) dat\$yc <- -.5 + dat\$x + rlogis(nrow(dat)) # v for very; l/m/h for low/middle/high; and t for threshold; ols for regular regression c(vlt = coef(glm((yc > -2) ~ x, binomial, dat))["x"], lt = coef(glm((yc > -1) ~ x, binomial, dat))["x"], mt = coef(glm((yc > 0) ~ x, binomial, dat))["x"], ht = coef(glm((yc > 1) ~ x, binomial, dat))["x"], vht = coef(glm((yc > 2) ~ x, binomial, dat))["x"], ols = trans(lm(yc ~ x, dat))["x"]) }))) vlt.x lt.x mt.x ht.x vht.x ols.x 1.0252116 1.0020822 1.0049156 1.0101613 1.0267511 0.9983772`

`boxplot(res)`

`ggpairs(as.data.frame(res))`