Skip to main content
edited body
Source Link
kjetil b halvorsen
  • 82.8k
  • 32
  • 201
  • 663

As @Scortchi notes, you can also use orthogonal polynomials. Here is a quick demonstration in R:

set.seed(3406)
N      = 50
real.x = runif(N, 0, 10)
ord.x  = cut(real.x, breaks=c(0,2,4,6,8,10), labels=FALSE)
ord.x  = factor(ord.x, levels=1:5, ordered=TRUE)
lo.lin = -3 + .5*real.x
p.lin  = exp(lo.lin)/(1 + exp(lo.lin))
y.lin  = rbinom(N, 1, prob=p.lin)

mod.lin = glm(y.lin~ordlin ~ ord.x, family=binomial)
summary(mod.lin)
# ...
# Coefficients:
#             Estimate Std. Error z value Pr(>|z|)   
# (Intercept)  0.05754    0.36635   0.157  0.87520   
# ord.x.L      2.94083    0.90304   3.257  0.00113 **
# ord.x.Q      0.94049    0.85724   1.097  0.27260   
# ord.x.C     -0.67049    0.77171  -0.869  0.38494   
# ord.x^4     -0.09155    0.73376  -0.125  0.90071   
# ...

As @Scortchi notes, you can also use orthogonal polynomials. Here is a quick demonstration in R:

set.seed(3406)
N      = 50
real.x = runif(N, 0, 10)
ord.x  = cut(real.x, breaks=c(0,2,4,6,8,10), labels=FALSE)
ord.x  = factor(ord.x, levels=1:5, ordered=TRUE)
lo.lin = -3 + .5*real.x
p.lin  = exp(lo.lin)/(1 + exp(lo.lin))
y.lin  = rbinom(N, 1, prob=p.lin)

mod.lin = glm(y.lin~ord.x, family=binomial)
summary(mod.lin)
# ...
# Coefficients:
#             Estimate Std. Error z value Pr(>|z|)   
# (Intercept)  0.05754    0.36635   0.157  0.87520   
# ord.x.L      2.94083    0.90304   3.257  0.00113 **
# ord.x.Q      0.94049    0.85724   1.097  0.27260   
# ord.x.C     -0.67049    0.77171  -0.869  0.38494   
# ord.x^4     -0.09155    0.73376  -0.125  0.90071   
# ...

As @Scortchi notes, you can also use orthogonal polynomials. Here is a quick demonstration in R:

set.seed(3406)
N      = 50
real.x = runif(N, 0, 10)
ord.x  = cut(real.x, breaks=c(0,2,4,6,8,10), labels=FALSE)
ord.x  = factor(ord.x, levels=1:5, ordered=TRUE)
lo.lin = -3 + .5*real.x
p.lin  = exp(lo.lin)/(1 + exp(lo.lin))
y.lin  = rbinom(N, 1, prob=p.lin)

mod.lin = glm(y.lin ~ ord.x, family=binomial)
summary(mod.lin)
# ...
# Coefficients:
#             Estimate Std. Error z value Pr(>|z|)   
# (Intercept)  0.05754    0.36635   0.157  0.87520   
# ord.x.L      2.94083    0.90304   3.257  0.00113 **
# ord.x.Q      0.94049    0.85724   1.097  0.27260   
# ord.x.C     -0.67049    0.77171  -0.869  0.38494   
# ord.x^4     -0.09155    0.73376  -0.125  0.90071   
# ...
replaced http://stats.stackexchange.com/ with https://stats.stackexchange.com/
Source Link

As @Scortchi notesnotes, you can also use orthogonal polynomials. Here is a quick demonstration in R:

set.seed(3406)
N      = 50
real.x = runif(N, 0, 10)
ord.x  = cut(real.x, breaks=c(0,2,4,6,8,10), labels=FALSE)
ord.x  = factor(ord.x, levels=1:5, ordered=TRUE)
lo.lin = -3 + .5*real.x
p.lin  = exp(lo.lin)/(1 + exp(lo.lin))
y.lin  = rbinom(N, 1, prob=p.lin)

mod.lin = glm(y.lin~ord.x, family=binomial)
summary(mod.lin)
# ...
# Coefficients:
#             Estimate Std. Error z value Pr(>|z|)   
# (Intercept)  0.05754    0.36635   0.157  0.87520   
# ord.x.L      2.94083    0.90304   3.257  0.00113 **
# ord.x.Q      0.94049    0.85724   1.097  0.27260   
# ord.x.C     -0.67049    0.77171  -0.869  0.38494   
# ord.x^4     -0.09155    0.73376  -0.125  0.90071   
# ...

As @Scortchi notes, you can also use orthogonal polynomials. Here is a quick demonstration in R:

set.seed(3406)
N      = 50
real.x = runif(N, 0, 10)
ord.x  = cut(real.x, breaks=c(0,2,4,6,8,10), labels=FALSE)
ord.x  = factor(ord.x, levels=1:5, ordered=TRUE)
lo.lin = -3 + .5*real.x
p.lin  = exp(lo.lin)/(1 + exp(lo.lin))
y.lin  = rbinom(N, 1, prob=p.lin)

mod.lin = glm(y.lin~ord.x, family=binomial)
summary(mod.lin)
# ...
# Coefficients:
#             Estimate Std. Error z value Pr(>|z|)   
# (Intercept)  0.05754    0.36635   0.157  0.87520   
# ord.x.L      2.94083    0.90304   3.257  0.00113 **
# ord.x.Q      0.94049    0.85724   1.097  0.27260   
# ord.x.C     -0.67049    0.77171  -0.869  0.38494   
# ord.x^4     -0.09155    0.73376  -0.125  0.90071   
# ...

As @Scortchi notes, you can also use orthogonal polynomials. Here is a quick demonstration in R:

set.seed(3406)
N      = 50
real.x = runif(N, 0, 10)
ord.x  = cut(real.x, breaks=c(0,2,4,6,8,10), labels=FALSE)
ord.x  = factor(ord.x, levels=1:5, ordered=TRUE)
lo.lin = -3 + .5*real.x
p.lin  = exp(lo.lin)/(1 + exp(lo.lin))
y.lin  = rbinom(N, 1, prob=p.lin)

mod.lin = glm(y.lin~ord.x, family=binomial)
summary(mod.lin)
# ...
# Coefficients:
#             Estimate Std. Error z value Pr(>|z|)   
# (Intercept)  0.05754    0.36635   0.157  0.87520   
# ord.x.L      2.94083    0.90304   3.257  0.00113 **
# ord.x.Q      0.94049    0.85724   1.097  0.27260   
# ord.x.C     -0.67049    0.77171  -0.869  0.38494   
# ord.x^4     -0.09155    0.73376  -0.125  0.90071   
# ...
added 14 characters in body
Source Link
gung - Reinstate Monica
  • 147.5k
  • 89
  • 406
  • 717

As @Scortchi notes, you can also use orthogonal polynomials. Here is a quick demonstration in R:

set.seed(3406)
N      = 50
real.x = runif(N, 0, 10)
ord.x  = cut(real.x, breaks=c(0,2,4,6,8,10), labels=FALSE)
ord.x  = factor(ord.x, levels=1:5, ordered=TRUE)
lo.lin = -3 + .5*real.x
p.lin  = exp(lo.lin)/(1 + exp(lo.lin))
y.lin  = rbinom(N, 1, prob=p.lin)

mod.lin = glm(y.lin~ord.x, family=binomial)
summary(mod.lin)
# ...
# Coefficients:
#              Estimate Std. Error z value Pr(>|z|)   
# (Intercept)   -0.152405754  1259  0.381136635   0.000157  0.87520  1.000 
# ord.x.L       142.193894083  2570.7009   0.00690304   3.257  0.99600113 **
# ord.x.Q       200.2398 94049 3365.8375   0.00685724   1.097  0.99527260   
# ord.x.C     -0.67049    40.286177171  1285-0.3508 869  0.003 38494   0.997
# ord.x^4      -110.985109155  3483.0049  -0.00373376  -0.125  0.99790071   
# ...

As @Scortchi notes, you can also use orthogonal polynomials. Here is a quick demonstration in R:

set.seed(3406)
N      = 50
real.x = runif(N, 0, 10)
ord.x  = cut(real.x, breaks=c(0,2,4,6,8,10), labels=FALSE)
ord.x  = factor(ord.x, levels=1:5, ordered=TRUE)
lo.lin = -3 + .5*real.x
p.lin  = exp(lo.lin)/(1 + exp(lo.lin))
y.lin  = rbinom(N, 1, prob=p.lin)

mod.lin = glm(y.lin~ord.x, family=binomial)
summary(mod.lin)
# ...
# Coefficients:
#              Estimate Std. Error z value Pr(>|z|)
# (Intercept)   -0.1524  1259.3811   0.000    1.000
# ord.x.L       14.1938  2570.7009   0.006    0.996
# ord.x.Q       20.2398  3365.8375   0.006    0.995
# ord.x.C        4.2861  1285.3508   0.003    0.997
# ord.x^4      -11.9851  3483.0049  -0.003    0.997
# ...

As @Scortchi notes, you can also use orthogonal polynomials. Here is a quick demonstration in R:

set.seed(3406)
N      = 50
real.x = runif(N, 0, 10)
ord.x  = cut(real.x, breaks=c(0,2,4,6,8,10), labels=FALSE)
ord.x  = factor(ord.x, levels=1:5, ordered=TRUE)
lo.lin = -3 + .5*real.x
p.lin  = exp(lo.lin)/(1 + exp(lo.lin))
y.lin  = rbinom(N, 1, prob=p.lin)

mod.lin = glm(y.lin~ord.x, family=binomial)
summary(mod.lin)
# ...
# Coefficients:
#             Estimate Std. Error z value Pr(>|z|)   
# (Intercept)  0.05754    0.36635   0.157  0.87520   
# ord.x.L      2.94083    0.90304   3.257  0.00113 **
# ord.x.Q      0.94049    0.85724   1.097  0.27260   
# ord.x.C     -0.67049    0.77171  -0.869  0.38494   
# ord.x^4     -0.09155    0.73376  -0.125  0.90071   
# ...
Source Link
gung - Reinstate Monica
  • 147.5k
  • 89
  • 406
  • 717
Loading