Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
179 views

Ordered Probit and Logit Models R Program and Output

The document describes using ordered probit and logit models in R. It loads data on health status, age, income and diseases, then fits an ordered logit model and examines the coefficients, odds ratios and predicted probabilities.

Uploaded by

SeyChell Norinha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
179 views

Ordered Probit and Logit Models R Program and Output

The document describes using ordered probit and logit models in R. It loads data on health status, age, income and diseases, then fits an ordered logit model and examines the coefficients, odds ratios and predicted probabilities.

Uploaded by

SeyChell Norinha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

# Ordered Probit and Logit Models in R

# Copyright 2013 by Ani Katchova

# install.packages("rms")
library(rms)

mydata<- read.csv("C:/Econometrics/Data/ordered_health.csv")
attach(mydata)

Y <- cbind(healthstatus1)
X <- cbind(age, logincome, numberdiseases)
Xvar <- c("age", "logincome", "numberdiseases")

# Descriptive statistics
summary(Y)
summary(X)
table(Y)

# Ordered logit model coefficients


ddist<- datadist(Xvar)
options(datadist='ddist')

ologit<- lrm(Y ~ X, data=mydata)


print(ologit)

# Ordered logit model odds ratio


# summary(ologit)

# Ordered logit predicted probabilities


# xmeans <- colMeans(X)
# newdata1 <- data.frame(t(xmeans))
fitted <- predict(ologit, newdata=mydata, type="fitted.ind")
colMeans(fitted)
> # Ordered Probit and Logit Models in R
> # Copyright 2013 by Ani Katchova
>
> # install.packages("rms")
> library(rms)
Loading required package: Hmisc
Loading required package: survival
Loading required package: splines
Hmisc library by Frank E Harrell Jr

Type library(help='Hmisc'), ?Overview, or ?Hmisc.Overview')


to see overall documentation.

NOTE:Hmisc no longer redefines [.factor to drop unused levels when


subsetting. To get the old behavior of Hmisc type dropUnusedLevels().

Attaching package: Hmisc

The following object(s) are masked from package:survival:

untangle.specials

The following object(s) are masked from package:base:

format.pval, round.POSIXt, trunc.POSIXt, units

Attaching package: rms

The following object(s) are masked from package:survival:

Surv

>
> mydata<- read.csv("C:/Econometrics/Data/ordered_health.csv")
> attach(mydata)
>
> Y <- cbind(healthstatus1)
> X <- cbind(age, logincome, numberdiseases)
> Xvar <- c("age", "logincome", "numberdiseases")
>
> # Descriptive statistics
> summary(Y)
healthstatus1
Min. :1.000
1st Qu.:2.000
Median :3.000
Mean :2.447
3rd Qu.:3.000
Max. :3.000
> summary(X)
age logincome numberdiseases
Min. : 0.02533 Min. : 0.000 Min. : 0.00
1st Qu.:11.34086 1st Qu.: 8.570 1st Qu.: 6.90
Median :24.13210 Median : 8.976 Median :10.58
Mean :25.57613 Mean : 8.697 Mean :11.21
3rd Qu.:37.19781 3rd Qu.: 9.251 3rd Qu.:13.73
Max. :63.27515 Max. :10.283 Max. :58.60
> table(Y)
Y
1 2 3
523 2034 3017
>
> # Ordered logit model coefficients
> ddist<- datadist(Xvar)
> options(datadist='ddist')
>
> ologit<- lrm(Y ~ X, data=mydata)
> print(ologit)

Logistic Regression Model

lrm(formula = Y ~ X, data = mydata)

Model Likelihood Discrimination Rank Discrim.


Ratio Test Indexes Indexes
Obs 5574 LR chi2 740.39 R2 0.148 C 0.675
1 523 d.f. 3 g 0.799 Dxy 0.350
2 2034 Pr(> chi2) <0.0001 gr 2.224 gamma 0.357
3 3017 gp 0.075 tau-a 0.198
max |deriv| 2e-11 Brier 0.077

Coef S.E. Wald Z Pr(>|Z|)


y>=2 1.3960 0.2061 6.77 <0.0001
y>=3 -0.9513 0.2054 -4.63 <0.0001
age -0.0293 0.0017 -17.43 <0.0001
logincome 0.2837 0.0231 12.27 <0.0001
numberdiseases -0.0550 0.0041 -13.51 <0.0001

>
> # Ordered logit model odds ratio
> # summary(ologit)
>
> # Ordered logit predicted probabilities
> # xmeans <- colMeans(X)
> # newdata1 <- data.frame(t(xmeans))
> fitted <- predict(ologit, newdata=mydata, type="fitted.ind")
> colMeans(fitted)
Y=1 Y=2 Y=3
0.09469033 0.36516716 0.54014250

You might also like