Title: | Efficient Bayesian Algorithms for Binary and Categorical Data Regression Models |
---|---|
Description: | Efficient Bayesian implementations of probit, logit, multinomial logit and binomial logit models. Functions for plotting and tabulating the estimation output are available as well. Estimation is based on Gibbs sampling where the Markov chain Monte Carlo algorithms are based on the latent variable representations and marginal data augmentation algorithms described in "Gregor Zens, Sylvia Frühwirth-Schnatter & Helga Wagner (2023). Ultimate Pólya Gamma Samplers – Efficient MCMC for possibly imbalanced binary and categorical data, Journal of the American Statistical Association <doi:10.1080/01621459.2023.2259030>". |
Authors: | Gregor Zens [aut, cre], Sylvia Frühwirth-Schnatter [aut], Helga Wagner [aut] |
Maintainer: | Gregor Zens <[email protected]> |
License: | GPL-3 |
Version: | 0.3.5 |
Built: | 2024-11-19 06:55:38 UTC |
Source: | CRAN |
coef
can be used to extract posterior means and credible intervals based on posterior quantiles from UPG.Binomial
objects.
## S3 method for class 'UPG.Binomial' coef(object, ..., q = c(0.025, 0.975))
## S3 method for class 'UPG.Binomial' coef(object, ..., q = c(0.025, 0.975))
object |
an object of class |
... |
other coef parameters. |
q |
a numerical vector of length two providing the posterior quantiles to be extracted. Default are 0.025 and 0.975 quantiles. |
Returns a matrix containing posterior means and the desired credible interval.
Gregor Zens
summary.UPG.Binomial
to summarize a UPG.Binomial
object and create tables.
predict.UPG.Binomial
to predict probabilities using a UPG.Binomial
object.
plot.UPG.Binomial
to plot a UPG.Binomial
object.
# estimate a binomial logit model using example data library(UPG) data(titanic) y = titanic[,1] Ni = titanic[,2] X = titanic[,-c(1,2)] results.binomial = UPG(y = y, X = X, Ni = Ni, model = "binomial") # extract posterior means and credible interval based on 0.025 and 0.975 quantiles coef(results.binomial, q = c(0.025, 0.975))
# estimate a binomial logit model using example data library(UPG) data(titanic) y = titanic[,1] Ni = titanic[,2] X = titanic[,-c(1,2)] results.binomial = UPG(y = y, X = X, Ni = Ni, model = "binomial") # extract posterior means and credible interval based on 0.025 and 0.975 quantiles coef(results.binomial, q = c(0.025, 0.975))
coef
can be used to extract posterior means and credible intervals based on posterior quantiles from UPG.Logit
objects.
## S3 method for class 'UPG.Logit' coef(object, ..., q = c(0.025, 0.975))
## S3 method for class 'UPG.Logit' coef(object, ..., q = c(0.025, 0.975))
object |
an object of class |
... |
other coef parameters. |
q |
a numerical vector of length two providing the posterior quantiles to be extracted. Default are 0.025 and 0.975 quantiles. |
Returns a matrix containing posterior means and the desired credible interval.
Gregor Zens
summary.UPG.Logit
to summarize a UPG.Logit
object and create tables.
predict.UPG.Logit
to predict probabilities using a UPG.Logit
object.
plot.UPG.Logit
to plot a UPG.Logit
object.
# estimate a logit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.logit = UPG(y = y, X = X, model = "logit") # extract posterior means and credible interval based on 0.025 and 0.975 quantiles coef(results.logit, q = c(0.025, 0.975))
# estimate a logit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.logit = UPG(y = y, X = X, model = "logit") # extract posterior means and credible interval based on 0.025 and 0.975 quantiles coef(results.logit, q = c(0.025, 0.975))
coef
can be used to extract posterior means and credible intervals based on posterior quantiles from UPG.MNL
objects.
## S3 method for class 'UPG.MNL' coef(object, ..., q = c(0.025, 0.975))
## S3 method for class 'UPG.MNL' coef(object, ..., q = c(0.025, 0.975))
object |
an object of class |
... |
other coef parameters. |
q |
a numerical vector of length two providing the posterior quantiles to be extracted. Default are 0.025 and 0.975 quantiles. |
Returns a list containing posterior means and the desired credible interval.
Gregor Zens
summary.UPG.MNL
to summarize a UPG.MNL
object and create tables.
predict.UPG.MNL
to predict probabilities using a UPG.MNL
object.
plot.UPG.MNL
to plot a UPG.MNL
object.
# estimate a multinomial logit model using example data library(UPG) data(program) y = program[,1] X = program[,-1] results.mnl = UPG(y = y, X = X, model = "mnl") # extract posterior means and credible interval based on 0.025 and 0.975 quantiles coef(results.mnl, q = c(0.025, 0.975))
# estimate a multinomial logit model using example data library(UPG) data(program) y = program[,1] X = program[,-1] results.mnl = UPG(y = y, X = X, model = "mnl") # extract posterior means and credible interval based on 0.025 and 0.975 quantiles coef(results.mnl, q = c(0.025, 0.975))
coef
can be used to extract posterior means and credible intervals based on posterior quantiles from UPG.Probit
objects.
## S3 method for class 'UPG.Probit' coef(object, ..., q = c(0.025, 0.975))
## S3 method for class 'UPG.Probit' coef(object, ..., q = c(0.025, 0.975))
object |
an object of class |
... |
other coef parameters. |
q |
a numerical vector of length two providing the posterior quantiles to be extracted. Default are 0.025 and 0.975 quantiles. |
Returns a matrix containing posterior means and the desired credible interval.
Gregor Zens
summary.UPG.Probit
to summarize a UPG.Probit
object and create tables.
predict.UPG.Probit
to predict probabilities using a UPG.Probit
object.
plot.UPG.Probit
to plot a UPG.Probit
object.
# estimate a probit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.probit = UPG(y = y, X = X, model = "probit") # extract posterior means and credible interval based on 0.025 and 0.975 quantiles coef(results.probit, q = c(0.025, 0.975))
# estimate a probit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.probit = UPG(y = y, X = X, model = "probit") # extract posterior means and credible interval based on 0.025 and 0.975 quantiles coef(results.probit, q = c(0.025, 0.975))
A dataset containing socio-economic characteristics as well as a labor force participation dummy for 753 married women from the panel study of income dynamics.
lfp
lfp
A data frame with 753 rows and 9 variables:
binary indicator for participating in the labor force (=1) or not (=0)
intercept
number of children 5 years old or younger
number of children 6 to 18 years old
age in years
binary indicator for college education of the wife
binary indicator for college education of the husband
log expected wage rate; for women in the labor force, the actual wage rate; for women not in the labor force, an imputed value based on a regression of lwg
on the other variables
family income exclusive of wife's income
Data taken from 'carData' package. Also known as the 'Mroz' dataset. Mroz, T. A. (1987) The sensitivity of an empirical model of married women's hours of work to economic and statistical assumptions. Econometrica 55, 765-799.
logLik
can be used to compute log-likelihoods from UPG.Binomial
objects. The log-likelihood is based on the posterior mean of the coefficients.
## S3 method for class 'UPG.Binomial' logLik(object = NULL, ...)
## S3 method for class 'UPG.Binomial' logLik(object = NULL, ...)
object |
an object of class |
... |
other logLik parameters. |
Returns a numeric of class logLik
with attributes containing the number of estimated parameters and the number of observations.
Gregor Zens
summary.UPG.Binomial
to summarize a UPG.Binomial
object and create tables.
plot.UPG.Binomial
to plot a UPG.Binomial
object.
coef.UPG.Binomial
to extract coefficients from a UPG.Binomial
object.
# estimate a binomial logit model using example data library(UPG) data(titanic) y = titanic[,1] Ni = titanic[,2] X = titanic[,-c(1,2)] results.binomial = UPG(y = y, X = X, Ni = Ni, model = "binomial") # extract log-likelihood ll.binomial = logLik(results.binomial)
# estimate a binomial logit model using example data library(UPG) data(titanic) y = titanic[,1] Ni = titanic[,2] X = titanic[,-c(1,2)] results.binomial = UPG(y = y, X = X, Ni = Ni, model = "binomial") # extract log-likelihood ll.binomial = logLik(results.binomial)
logLik
can be used to compute log-likelihoods from UPG.Logit
objects. The log-likelihood is based on the posterior mean of the coefficients.
## S3 method for class 'UPG.Logit' logLik(object = NULL, ...)
## S3 method for class 'UPG.Logit' logLik(object = NULL, ...)
object |
an object of class |
... |
other logLik parameters. |
Returns a numeric of class logLik
with attributes containing the number of estimated parameters and the number of observations.
Gregor Zens
summary.UPG.Logit
to summarize a UPG.Logit
object and create tables.
plot.UPG.Logit
to plot a UPG.Logit
object.
coef.UPG.Logit
to extract coefficients from a UPG.Logit
object.
# estimate a logit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.logit = UPG(y = y, X = X, model = "logit") # extract log-likelihood ll.logit = logLik(results.logit)
# estimate a logit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.logit = UPG(y = y, X = X, model = "logit") # extract log-likelihood ll.logit = logLik(results.logit)
logLik
can be used to compute log-likelihoods from UPG.MNL
objects. The log-likelihood is based on the posterior mean of the coefficients.
## S3 method for class 'UPG.MNL' logLik(object = NULL, ...)
## S3 method for class 'UPG.MNL' logLik(object = NULL, ...)
object |
an object of class |
... |
other logLik parameters. |
Returns a numeric of class logLik
with attributes containing the number of estimated parameters and the number of observations.
Gregor Zens
summary.UPG.MNL
to summarize a UPG.MNL
object and create tables.
plot.UPG.MNL
to plot a UPG.MNL
object.
coef.UPG.MNL
to extract coefficients from a UPG.MNL
object.
# estimate a multinomial logit model using example data library(UPG) data(program) y = program[,1] X = program[,-1] results.mnl = UPG(y = y, X = X, model = "mnl") # extract log-likelihood ll.mnl = logLik(results.mnl)
# estimate a multinomial logit model using example data library(UPG) data(program) y = program[,1] X = program[,-1] results.mnl = UPG(y = y, X = X, model = "mnl") # extract log-likelihood ll.mnl = logLik(results.mnl)
logLik
can be used to compute log-likelihoods from UPG.Probit
objects. The log-likelihood is based on the posterior mean of the coefficients.
## S3 method for class 'UPG.Probit' logLik(object = NULL, ...)
## S3 method for class 'UPG.Probit' logLik(object = NULL, ...)
object |
an object of class |
... |
other logLik parameters. |
Returns a numeric of class logLik
with attributes containing the number of estimated parameters and the number of observations.
Gregor Zens
summary.UPG.Probit
to summarize a UPG.Probit
object and create tables.
plot.UPG.Probit
to plot a UPG.Probit
object.
coef.UPG.Probit
to extract coefficients from a UPG.Probit
object.
# estimate a probit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.probit = UPG(y = y, X = X, model = "probit") # extract log-likelihood ll.probit = logLik(results.probit)
# estimate a probit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.probit = UPG(y = y, X = X, model = "probit") # extract log-likelihood ll.probit = logLik(results.probit)
plot
generates plots from UPG.Binomial
objects using ggplot2
. Coefficient plots show point estimates for all coefficients as well as their credible intervals.
## S3 method for class 'UPG.Binomial' plot( x = NULL, ..., sort = FALSE, names = NULL, xlab = NULL, ylab = NULL, q = c(0.025, 0.975), include = NULL )
## S3 method for class 'UPG.Binomial' plot( x = NULL, ..., sort = FALSE, names = NULL, xlab = NULL, ylab = NULL, q = c(0.025, 0.975), include = NULL )
x |
an object of class |
... |
other plot parameters. |
sort |
a logical variable indicating whether the plotted coefficients should be sorted according to effect sizes. Default is FALSE. |
names |
a character vector indicating names for the variables used in the plots. |
xlab |
a character vector of length 1 indicating a title for the x-axis. |
ylab |
a character vector of length 1 indicating a title for the y-axis. |
q |
a numerical vector of length two providing the posterior quantiles to be extracted. Default are 0.025 and 0.975 quantiles. |
include |
can be used to plot only a subset of variables. Specify the columns of X that should be kept in the plot. See examples for further information. |
Returns a ggplot2 object.
Gregor Zens
summary.UPG.Binomial
to summarize a UPG.Binomial
object and create tables.
predict.UPG.Binomial
to predict probabilities using a UPG.Binomial
object.
coef.UPG.Binomial
to extract coefficients from a UPG.Binomial
object.
# estimate a binomial logit model using example data library(UPG) data(titanic) y = titanic[,1] Ni = titanic[,2] X = titanic[,-c(1,2)] results.binomial = UPG(y = y, X = X, Ni = Ni, model = "binomial") # plot the results and sort coefficients by effect size plot(results.binomial, sort = TRUE) # plot only variables 1 and 3 with custom names, credible intervals and axis labels plot(results.binomial, include = c(1,3), names = c("Custom 1", "Custom 2"), q = c(0.1, 0.9), xlab = c("Custom X"), ylab = c("Custom Y"))
# estimate a binomial logit model using example data library(UPG) data(titanic) y = titanic[,1] Ni = titanic[,2] X = titanic[,-c(1,2)] results.binomial = UPG(y = y, X = X, Ni = Ni, model = "binomial") # plot the results and sort coefficients by effect size plot(results.binomial, sort = TRUE) # plot only variables 1 and 3 with custom names, credible intervals and axis labels plot(results.binomial, include = c(1,3), names = c("Custom 1", "Custom 2"), q = c(0.1, 0.9), xlab = c("Custom X"), ylab = c("Custom Y"))
plot
generates plots from UPG.Logit
objects using ggplot2
. Coefficient plots show point estimates for all coefficients as well as their credible intervals.
## S3 method for class 'UPG.Logit' plot( x = NULL, ..., sort = FALSE, names = NULL, xlab = NULL, ylab = NULL, q = c(0.025, 0.975), include = NULL )
## S3 method for class 'UPG.Logit' plot( x = NULL, ..., sort = FALSE, names = NULL, xlab = NULL, ylab = NULL, q = c(0.025, 0.975), include = NULL )
x |
an object of class |
... |
other plot parameters. |
sort |
a logical variable indicating whether the plotted coefficients should be sorted according to effect sizes. Default is FALSE. |
names |
a character vector indicating names for the variables used in the plots. |
xlab |
a character vector of length 1 indicating a title for the x-axis. |
ylab |
a character vector of length 1 indicating a title for the y-axis. |
q |
a numerical vector of length two providing the posterior quantiles to be extracted. Default are 0.025 and 0.975 quantiles. |
include |
can be used to plot only a subset of variables. Specify the columns of X that should be kept in the plot. See examples for further information. |
Returns a ggplot2 object.
Gregor Zens
summary.UPG.Logit
to summarize a UPG.Logit
object and create tables.
predict.UPG.Logit
to predict probabilities using a UPG.Logit
object.
coef.UPG.Logit
to extract coefficients from a UPG.Logit
object.
# estimate a logit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.logit = UPG(y = y, X = X, model = "logit") # plot the results and sort coefficients by effect size plot(results.logit, sort = TRUE) # plot only variables 1 and 3 with custom names, credible intervals and axis labels plot(results.logit, include = c(1,3), names = c("Custom 1", "Custom 2"), q = c(0.1, 0.9), xlab = c("Custom X"), ylab = c("Custom Y"))
# estimate a logit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.logit = UPG(y = y, X = X, model = "logit") # plot the results and sort coefficients by effect size plot(results.logit, sort = TRUE) # plot only variables 1 and 3 with custom names, credible intervals and axis labels plot(results.logit, include = c(1,3), names = c("Custom 1", "Custom 2"), q = c(0.1, 0.9), xlab = c("Custom X"), ylab = c("Custom Y"))
plot
generates plots from UPG.MNL
objects using ggplot2
. Coefficient plots show point estimates for all coefficients in all groups except the baseline as well as their credible intervals.
## S3 method for class 'UPG.MNL' plot( x = NULL, ..., sort = FALSE, names = NULL, groups = NULL, xlab = NULL, ylab = NULL, q = c(0.025, 0.975), include = NULL )
## S3 method for class 'UPG.MNL' plot( x = NULL, ..., sort = FALSE, names = NULL, groups = NULL, xlab = NULL, ylab = NULL, q = c(0.025, 0.975), include = NULL )
x |
an object of class |
... |
other plot parameters. |
sort |
a logical variable indicating whether the plotted coefficients should be sorted according to average effect sizes across groups. Default is FALSE. |
names |
a character vector indicating names for the variables used in the plots. |
groups |
a character vector indicating names for the groups excluding the baseline. The group names must correspond to the ordering in the dependent variable used for estimation. |
xlab |
a character vector of length 1 indicating a title for the x-axis. |
ylab |
a character vector of length 1 indicating a title for the y-axis. |
q |
a numerical vector of length two providing the posterior quantiles to be extracted. Default are 0.025 and 0.975 quantiles. |
include |
can be used to plot only a subset of variables. Specify the columns of X that should be kept in the plot. See examples for further information. |
Returns a ggplot2 object.
Gregor Zens
summary.UPG.MNL
to summarize a UPG.MNL
object and create tables.
predict.UPG.MNL
to predict probabilities using a UPG.MNL
object.
coef.UPG.MNL
to extract coefficients from a UPG.MNL
object.
# estimate a multinomial logit model using example data library(UPG) data(program) y = program[,1] X = program[,-1] results.mnl = UPG(y = y, X = X, model = "mnl") # plot the results and sort coefficients by average effect size plot(results.mnl, sort = TRUE) # plot only variables 1 and 3 with custom group and variable names # also, customize credible intervals and axis labels plot(results.mnl, include = c(1,3), names = c("Custom 1", "Custom 2"), groups = c("Alpha", "Beta"), q = c(0.1, 0.9), xlab = c("Custom X"), ylab = c("Custom Y"))
# estimate a multinomial logit model using example data library(UPG) data(program) y = program[,1] X = program[,-1] results.mnl = UPG(y = y, X = X, model = "mnl") # plot the results and sort coefficients by average effect size plot(results.mnl, sort = TRUE) # plot only variables 1 and 3 with custom group and variable names # also, customize credible intervals and axis labels plot(results.mnl, include = c(1,3), names = c("Custom 1", "Custom 2"), groups = c("Alpha", "Beta"), q = c(0.1, 0.9), xlab = c("Custom X"), ylab = c("Custom Y"))
plot
generates plots from UPG.Probit
objects using ggplot2
. Coefficient plots show point estimates for all coefficients as well as their credible intervals.
## S3 method for class 'UPG.Probit' plot( x = NULL, ..., sort = FALSE, names = NULL, xlab = NULL, ylab = NULL, q = c(0.025, 0.975), include = NULL )
## S3 method for class 'UPG.Probit' plot( x = NULL, ..., sort = FALSE, names = NULL, xlab = NULL, ylab = NULL, q = c(0.025, 0.975), include = NULL )
x |
an object of class |
... |
other plot parameters. |
sort |
a logical variable indicating whether the plotted coefficients should be sorted according to effect sizes. Default is FALSE. |
names |
a character vector indicating names for the variables used in the plots. |
xlab |
a character vector of length 1 indicating a title for the x-axis. |
ylab |
a character vector of length 1 indicating a title for the y-axis. |
q |
a numerical vector of length two providing the posterior quantiles to be extracted. Default are 0.025 and 0.975 quantiles. |
include |
can be used to plot only a subset of variables. Specify the columns of X that should be kept in the plot. See examples for further information. |
Returns a ggplot2 object.
Gregor Zens
summary.UPG.Probit
to summarize a UPG.Probit
object and create tables.
predict.UPG.Probit
to predict probabilities using a UPG.Probit
object.
coef.UPG.Probit
to extract coefficients from a UPG.Probit
object.
# estimate a probit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.probit = UPG(y = y, X = X, model = "probit") # plot the results and sort coefficients by effect size plot(results.probit, sort = TRUE) # plot only variables 1 and 3 with custom names, credible intervals and axis labels plot(results.probit, include = c(1, 3), names = c("Custom 1", "Custom 2"), q = c(0.1, 0.9), xlab = c("Custom X"), ylab = c("Custom Y"))
# estimate a probit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.probit = UPG(y = y, X = X, model = "probit") # plot the results and sort coefficients by effect size plot(results.probit, sort = TRUE) # plot only variables 1 and 3 with custom names, credible intervals and axis labels plot(results.probit, include = c(1, 3), names = c("Custom 1", "Custom 2"), q = c(0.1, 0.9), xlab = c("Custom X"), ylab = c("Custom Y"))
predict
generates predicted probabilities from a UPG.Binomial
object. In addition, credible intervals for these probabilities are computed. Probabilities can be predicted from the data used for estimating the model or for a new data set with the same structure.
## S3 method for class 'UPG.Binomial' predict(object = NULL, ..., newdata = NULL, q = c(0.025, 0.975))
## S3 method for class 'UPG.Binomial' predict(object = NULL, ..., newdata = NULL, q = c(0.025, 0.975))
object |
an object of class |
... |
other predict parameters. |
newdata |
a matrix or a |
q |
a numerical vector of length two providing the posterior quantiles to be extracted. Default are 0.025 and 0.975 quantiles. |
Returns a list containing posterior means of predicted probabilities as well as the desired credible interval.
Gregor Zens
summary.UPG.Binomial
to summarize a UPG.Binomial
object and create tables.
plot.UPG.Binomial
to plot a UPG.Binomial
object.
coef.UPG.Binomial
to extract coefficients from a UPG.Binomial
object.
# estimate a binomial logit model using example data library(UPG) data(titanic) y = titanic[,1] Ni = titanic[,2] X = titanic[,-c(1,2)] results.binomial = UPG(y = y, X = X, Ni = Ni, model = "binomial") # extract predicted probabilities predict(results.binomial)
# estimate a binomial logit model using example data library(UPG) data(titanic) y = titanic[,1] Ni = titanic[,2] X = titanic[,-c(1,2)] results.binomial = UPG(y = y, X = X, Ni = Ni, model = "binomial") # extract predicted probabilities predict(results.binomial)
predict
generates predicted probabilities from a UPG.Logit
object. In addition, credible intervals for these probabilities are computed. Probabilities can be predicted from the data used for estimating the model or for a new data set with the same structure.
## S3 method for class 'UPG.Logit' predict(object = NULL, ..., newdata = NULL, q = c(0.025, 0.975))
## S3 method for class 'UPG.Logit' predict(object = NULL, ..., newdata = NULL, q = c(0.025, 0.975))
object |
an object of class |
... |
other predict parameters. |
newdata |
a matrix or a |
q |
a numerical vector of length two providing the posterior quantiles to be extracted. Default are 0.025 and 0.975 quantiles. |
Returns a list containing posterior means of predicted probabilities as well as the desired credible interval.
Gregor Zens
summary.UPG.Logit
to summarize a UPG.Logit
object and create tables.
plot.UPG.Logit
to plot a UPG.Logit
object.
coef.UPG.Logit
to extract coefficients from a UPG.Logit
object.
# estimate a logit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.logit = UPG(y = y, X = X, model = "logit") # extract predicted probabilities predict(results.logit)
# estimate a logit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.logit = UPG(y = y, X = X, model = "logit") # extract predicted probabilities predict(results.logit)
predict
generates predicted probabilities from a UPG.MNL
object. In addition, credible intervals for these probabilities are computed. Probabilities can be predicted from the data used for estimating the model or for a new data set with the same structure.
## S3 method for class 'UPG.MNL' predict(object = NULL, ..., newdata = NULL, q = c(0.025, 0.975))
## S3 method for class 'UPG.MNL' predict(object = NULL, ..., newdata = NULL, q = c(0.025, 0.975))
object |
an object of class |
... |
other predict parameters. |
newdata |
a matrix or a |
q |
a numerical vector of length two providing the posterior quantiles to be extracted. Default are 0.025 and 0.975 quantiles. |
Returns a list containing posterior means of predicted probabilities as well as the desired credible interval.
Gregor Zens
summary.UPG.MNL
to summarize a UPG.MNL
object and create tables.
plot.UPG.MNL
to plot a UPG.MNL
object.
coef.UPG.MNL
to extract coefficients from a UPG.MNL
object.
# estimate a multinomial logit model using example data library(UPG) data(program) y = program[,1] X = program[,-1] results.mnl = UPG(y = y, X = X, model = "mnl") # extract predicted probabilities predict(results.mnl)
# estimate a multinomial logit model using example data library(UPG) data(program) y = program[,1] X = program[,-1] results.mnl = UPG(y = y, X = X, model = "mnl") # extract predicted probabilities predict(results.mnl)
predict
generates predicted probabilities from a UPG.Probit
object. In addition, credible intervals for these probabilities are computed. Probabilities can be predicted from the data used for estimating the model or for a new data set with the same structure.
## S3 method for class 'UPG.Probit' predict(object = NULL, ..., newdata = NULL, q = c(0.025, 0.975))
## S3 method for class 'UPG.Probit' predict(object = NULL, ..., newdata = NULL, q = c(0.025, 0.975))
object |
an object of class |
... |
other predict parameters. |
newdata |
a matrix or a |
q |
a numerical vector of length two providing the posterior quantiles to be extracted. Default are 0.025 and 0.975 quantiles. |
Returns a list containing posterior means of predicted probabilities as well as the desired credible interval.
Gregor Zens
summary.UPG.Probit
to summarize a UPG.Probit
object and create tables.
plot.UPG.Probit
to plot a UPG.Probit
object.
coef.UPG.Probit
to extract coefficients from a UPG.Probit
object.
# estimate a probit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.probit = UPG(y = y, X = X, model = "probit") # extract predicted probabilities predict(results.probit)
# estimate a probit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.probit = UPG(y = y, X = X, model = "probit") # extract predicted probabilities predict(results.probit)
print
provides some basic information about a UPG.Binomial
object.
## S3 method for class 'UPG.Binomial' print(x, ...)
## S3 method for class 'UPG.Binomial' print(x, ...)
x |
an object of class |
... |
other print parameters. |
Gregor Zens
summary.UPG.Binomial
to summarize a UPG.Binomial
object and create tables.
predict.UPG.Binomial
to predict probabilities using a UPG.Binomial
object.
plot.UPG.Binomial
to plot a UPG.Binomial
object.
# estimate a binomial logit model using example data library(UPG) data(titanic) y = titanic[,1] Ni = titanic[,2] X = titanic[,-c(1,2)] results.binomial = UPG(y = y, X = X, Ni = Ni, model = "binomial") print(results.binomial)
# estimate a binomial logit model using example data library(UPG) data(titanic) y = titanic[,1] Ni = titanic[,2] X = titanic[,-c(1,2)] results.binomial = UPG(y = y, X = X, Ni = Ni, model = "binomial") print(results.binomial)
print
provides some basic information about a UPG.Logit
object.
## S3 method for class 'UPG.Logit' print(x, ...)
## S3 method for class 'UPG.Logit' print(x, ...)
x |
an object of class |
... |
other print parameters. |
Gregor Zens
summary.UPG.Logit
to summarize a UPG.Logit
object and create tables.
predict.UPG.Logit
to predict probabilities using a UPG.Logit
object.
plot.UPG.Logit
to plot a UPG.Logit
object.
# estimate a logit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.logit = UPG(y = y, X = X, model = "logit") print(results.logit)
# estimate a logit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.logit = UPG(y = y, X = X, model = "logit") print(results.logit)
print
provides some basic information about a UPG.MNL
object.
## S3 method for class 'UPG.MNL' print(x, ...)
## S3 method for class 'UPG.MNL' print(x, ...)
x |
an object of class |
... |
other print parameters. |
Gregor Zens
summary.UPG.MNL
to summarize a UPG.MNL
object and create tables.
predict.UPG.MNL
to predict probabilities using a UPG.MNL
object.
plot.UPG.MNL
to plot a UPG.MNL
object.
# estimate a multinomial logit model using example data library(UPG) data(program) y = program[,1] X = program[,-1] results.mnl = UPG(y = y, X = X, model = "mnl") print(results.mnl)
# estimate a multinomial logit model using example data library(UPG) data(program) y = program[,1] X = program[,-1] results.mnl = UPG(y = y, X = X, model = "mnl") print(results.mnl)
print
provides some basic information about a UPG.Probit
object.
## S3 method for class 'UPG.Probit' print(x, ...)
## S3 method for class 'UPG.Probit' print(x, ...)
x |
an object of class |
... |
other print parameters. |
Gregor Zens
summary.UPG.Probit
to summarize a UPG.Probit
object and create tables.
predict.UPG.Probit
to predict probabilities using a UPG.Probit
object.
plot.UPG.Probit
to plot a UPG.Probit
object.
# estimate a probit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.probit = UPG(y = y, X = X, model = "probit") print(results.probit)
# estimate a probit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.probit = UPG(y = y, X = X, model = "probit") print(results.probit)
A dataset containing the choice among general program, vocational program and academic program for 200 high school students as well as some explanatory variables.
program
program
A data frame with 200 rows and 5 variables:
a vector of program choices
an intercept term
binary indicator for female students
socioeconomic status, 1 is lowest
writing score of student
Original dataset is known as 'hsbdemo' and has been sourced from https://stats.oarc.ucla.edu/stat/data/hsbdemo.dta.
summary
generates a summary of estimation results for UPG.Binomial
objects. Point estimates, estimated standard deviation as well as credible intervals for each variable are tabulated. In addition, an indicator quickly shows whether the credible interval includes zero or not. Moreover, LaTeX, HTML and pandoc tables can be quickly generated via knitr
.
## S3 method for class 'UPG.Binomial' summary( object = NULL, ..., q = c(0.025, 0.975), names = NULL, digits = 2, include = NULL, table = NULL, cap = NULL )
## S3 method for class 'UPG.Binomial' summary( object = NULL, ..., q = c(0.025, 0.975), names = NULL, digits = 2, include = NULL, table = NULL, cap = NULL )
object |
an object of class |
... |
other summary parameters. |
q |
a numerical vector of length two providing the posterior quantiles to be extracted. Default are 0.025 and 0.975 quantiles. |
names |
a character vector indicating names for the variables used in the output. |
digits |
number of digits to be included in output. Last digit will be rounded using |
include |
can be used to summarize and tabulate only a subset of variables. Specify the columns of X that should be kept in the plot. See examples for further information. |
table |
can be used to return a LaTeX table ( |
cap |
character vector that can be used to specify the table caption. |
Returns a knitr_kable
object containing the summary table.
Gregor Zens
plot.UPG.Binomial
to plot a UPG.Binomial
object.
predict.UPG.Binomial
to predict probabilities using a UPG.Binomial
object.
coef.UPG.Binomial
to extract coefficients from a UPG.Binomial
object.
# estimate a binomial logit model using example data library(UPG) data(titanic) y = titanic[,1] Ni = titanic[,2] X = titanic[,-c(1,2)] results.binomial = UPG(y = y, X = X, Ni = Ni, model = "binomial") # basic summary of regression results summary(results.binomial) # generate a LaTeX table with subset of variables and custom names summary(results.binomial, include=c(1,3), names=c("V. kept 1", "V. kept 3"), table="latex")
# estimate a binomial logit model using example data library(UPG) data(titanic) y = titanic[,1] Ni = titanic[,2] X = titanic[,-c(1,2)] results.binomial = UPG(y = y, X = X, Ni = Ni, model = "binomial") # basic summary of regression results summary(results.binomial) # generate a LaTeX table with subset of variables and custom names summary(results.binomial, include=c(1,3), names=c("V. kept 1", "V. kept 3"), table="latex")
summary
generates a summary of estimation results for UPG.Logit
objects. Point estimates, estimated standard deviation as well as credible intervals for each variable are tabulated. In addition, an indicator quickly shows whether the credible interval includes zero or not. Moreover, LaTeX, HTML and pandoc tables can be quickly generated via knitr
.
## S3 method for class 'UPG.Logit' summary( object = NULL, ..., q = c(0.025, 0.975), names = NULL, digits = 2, include = NULL, table = NULL, cap = NULL )
## S3 method for class 'UPG.Logit' summary( object = NULL, ..., q = c(0.025, 0.975), names = NULL, digits = 2, include = NULL, table = NULL, cap = NULL )
object |
an object of class |
... |
other summary parameters. |
q |
a numerical vector of length two providing the posterior quantiles to be extracted. Default are 0.025 and 0.975 quantiles. |
names |
a character vector indicating names for the variables used in the output. |
digits |
number of digits to be included in output. Last digit will be rounded using |
include |
can be used to summarize and tabulate only a subset of variables. Specify the columns of X that should be kept in the plot. See examples for further information. |
table |
can be used to return a LaTeX table ( |
cap |
character vector that can be used to specify the table caption. |
Returns a knitr_kable
object containing the summary table.
Gregor Zens
plot.UPG.Logit
to plot a UPG.Logit
object.
predict.UPG.Logit
to predict probabilities using a UPG.Logit
object.
coef.UPG.Logit
to extract coefficients from a UPG.Logit
object.
# estimate a logit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.logit = UPG(y = y, X = X, model = "logit") # basic summary of regression results summary(results.logit) # generate a LaTeX table with subset of variables and custom names summary(results.logit, include=c(1,3), names=c("V. kept 1", "V. kept 3"), table="latex")
# estimate a logit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.logit = UPG(y = y, X = X, model = "logit") # basic summary of regression results summary(results.logit) # generate a LaTeX table with subset of variables and custom names summary(results.logit, include=c(1,3), names=c("V. kept 1", "V. kept 3"), table="latex")
summary
generates a summary of estimation results for UPG.MNL
objects. Point estimates, estimated standard deviation as well as credible intervals for each variable are tabulated. In addition, an indicator quickly shows whether the credible interval includes zero or not. Moreover, LaTeX, HTML and pandoc tables can be quickly generated via knitr
.
## S3 method for class 'UPG.MNL' summary( object = NULL, ..., q = c(0.025, 0.975), groups = NULL, names = NULL, digits = 2, include = NULL, table = NULL, cap = NULL )
## S3 method for class 'UPG.MNL' summary( object = NULL, ..., q = c(0.025, 0.975), groups = NULL, names = NULL, digits = 2, include = NULL, table = NULL, cap = NULL )
object |
an object of class |
... |
other summary parameters. |
q |
a numerical vector of length two providing the posterior quantiles to be extracted. Default are 0.025 and 0.975 quantiles. |
groups |
a character vector indicating names for the groups, excluding the baseline. The group names must correspond to the ordering in the dependent variable used for estimation. |
names |
a character vector indicating names for the variables used in the output. |
digits |
number of digits to be included in output. Last digit will be rounded using |
include |
can be used to summarize and tabulate only a subset of variables. Specify the columns of X that should be kept in the plot. See examples for further information. |
table |
can be used to return a LaTeX table ( |
cap |
character vector that can be used to specify the table caption. |
Returns a knitr_kable
object containing the summary table.
Gregor Zens
plot.UPG.MNL
to plot a UPG.MNL
object.
predict.UPG.MNL
to predict probabilities using a UPG.MNL
object.
coef.UPG.MNL
to extract coefficients from a UPG.MNL
object.
# estimate a multinomial logit model using example data library(UPG) data(program) y = program[,1] X = program[,-1] results.mnl = UPG(y = y, X = X, model = "mnl") # basic summary of regression results summary(results.mnl) # generate a LaTeX table with subset of variables and custom names summary(results.mnl, include=c(1,3), groups=c("Alpha","Beta"), names=c("V. kept 1", "V. kept 3"), table="latex")
# estimate a multinomial logit model using example data library(UPG) data(program) y = program[,1] X = program[,-1] results.mnl = UPG(y = y, X = X, model = "mnl") # basic summary of regression results summary(results.mnl) # generate a LaTeX table with subset of variables and custom names summary(results.mnl, include=c(1,3), groups=c("Alpha","Beta"), names=c("V. kept 1", "V. kept 3"), table="latex")
summary
generates a summary of estimation results for UPG.Probit
objects. Point estimates, estimated standard deviation as well as credible intervals for each variable are tabulated. In addition, an indicator quickly shows whether the credible interval includes zero or not. Moreover, LaTeX, HTML and pandoc tables can be quickly generated via knitr
.
## S3 method for class 'UPG.Probit' summary( object = NULL, ..., q = c(0.025, 0.975), names = NULL, digits = 2, include = NULL, table = NULL, cap = NULL )
## S3 method for class 'UPG.Probit' summary( object = NULL, ..., q = c(0.025, 0.975), names = NULL, digits = 2, include = NULL, table = NULL, cap = NULL )
object |
an object of class |
... |
other summary parameters. |
q |
a numerical vector of length two providing the posterior quantiles to be extracted. Default are 0.025 and 0.975 quantiles. |
names |
a character vector indicating names for the variables used in the output. |
digits |
number of digits to be included in output. Last digit will be rounded using |
include |
can be used to summarize and tabulate only a subset of variables. Specify the columns of X that should be kept in the plot. See examples for further information. |
table |
can be used to return a LaTeX table ( |
cap |
character vector that can be used to specify the table caption. |
Returns a knitr_kable
object containing the summary table.
Gregor Zens
plot.UPG.Probit
to plot a UPG.Probit
object.
predict.UPG.Probit
to predict probabilities using a UPG.Probit
object.
coef.UPG.Probit
to extract coefficients from a UPG.Probit
object.
# estimate a probit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.probit = UPG(y = y, X = X, model = "probit") # basic summary of regression results summary(results.probit) # generate a LaTeX table with subset of variables and custom names summary(results.probit, include=c(1,3), names=c("V. kept 1", "V. kept 3"), table="latex")
# estimate a probit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.probit = UPG(y = y, X = X, model = "probit") # basic summary of regression results summary(results.probit) # generate a LaTeX table with subset of variables and custom names summary(results.probit, include=c(1,3), names=c("V. kept 1", "V. kept 3"), table="latex")
A dataset containing the number of survivals and the total number of persons by passenger class, age group and gender.
titanic
titanic
A data frame with 78 rows and 6 variables:
number of passengers that survived
number of total passengers
an intercept term
passenger class (3 is lowest)
binary indicator for female passenger groups
age group indicator (0-5yrs, 5-10yrs, ...)
Data originally sourced from https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv. See also https://towardsdatascience.com/the-binomial-regression-model-everything-you-need-to-know-5216f1a483d3.
UPG
estimates Bayesian regression models for binary or categorical outcomes using samplers based on marginal data augmentation.
UPG(y, X, model, Ni = NULL, baseline = NULL, draws = 1000, burnin = 1000, A0 = 4, B0 = 4, d0 = 2.5, D0 = 1.5, G0 = 100, verbose = TRUE, gamma.boost = TRUE, delta.boost = TRUE, beta.start = NULL)
UPG(y, X, model, Ni = NULL, baseline = NULL, draws = 1000, burnin = 1000, A0 = 4, B0 = 4, d0 = 2.5, D0 = 1.5, G0 = 100, verbose = TRUE, gamma.boost = TRUE, delta.boost = TRUE, beta.start = NULL)
y |
a binary vector for probit and logit models. A character, factor or numeric vector for multinomial logit models. A numerical vector of the number of successes for the binomial model. |
X |
a matrix of explanatory variables including an intercept in the first column. Rows are individuals, columns are variables. |
model |
indicates the model to be estimated. |
Ni |
a vector containing the number of trials when estimating a binomial logit model. |
baseline |
a string that can be used to change the baseline category in MNL models. Default baseline is the most commonly observed category. |
draws |
number of saved Gibbs sampler iterations. Default is 1000 for illustration purposes, you should use more when estimating a model (e.g. 10,000). |
burnin |
number of burned Gibbs sampler iterations. Default is 1000 for illustration purposes, you should use more when estimating a model (e.g. 2,000). |
A0 |
prior variance for the intercept, 4 is the default. |
B0 |
prior variance for the coefficients, 4 is the default. |
d0 |
prior shape for working parameter delta, 2.5 is the default. |
D0 |
prior rate for working parameter delta, 1.5 is the default. |
G0 |
prior variance for working parameter gamma, 100 is the default. |
verbose |
logical variable indicating whether progress should be printed during estimation. |
gamma.boost |
logical variable indicating whether location-based parameter expansion boosting should be used. |
delta.boost |
logical variable indicating whether scale-based parameter expansion boosting should be used. |
beta.start |
provides starting values for beta (e.g. for use within Gibbs sampler). Baseline coefficients need to be zero for multinomial model. |
Depending on the estimated model, UPG()
returns a UPG.Probit
, UPG.Logit
, UPG.MNL
or UPG.Binomial
object.
Gregor Zens
summary.UPG.Probit
to summarize a UPG.Probit
object and to create tables.
predict.UPG.Logit
to predict probabilities using a UPG.Logit
object.
plot.UPG.MNL
to plot a UPG.MNL
object.
# load package library(UPG) # estimate a probit model using example data # warning: use more burn-ins, burnin = 100 is just used for demonstration purposes data(lfp) y = lfp[,1] X = lfp[,-1] results.probit = UPG(y = y, X = X, model = "probit", burnin = 100) # estimate a logit model using example data # warning: use more burn-ins, burnin = 100 is just used for demonstration purposes data(lfp) y = lfp[,1] X = lfp[,-1] results.logit = UPG(y = y, X = X, model = "logit", burnin = 100) # estimate a MNL model using example data # warning: use more burn-ins, burnin = 100 is just used for demonstration purposes data(program) y = program[,1] X = program[,-1] results.mnl = UPG(y = y, X = X, model = "mnl", burnin = 100) # estimate a binomial logit model using example data # warning: use more burn-ins, burnin = 100 is just used for demonstration purposes data(titanic) y = titanic[,1] Ni = titanic[,2] X = titanic[,-c(1,2)] results.binomial = UPG(y = y, X = X, Ni = Ni, model = "binomial", burnin = 100)
# load package library(UPG) # estimate a probit model using example data # warning: use more burn-ins, burnin = 100 is just used for demonstration purposes data(lfp) y = lfp[,1] X = lfp[,-1] results.probit = UPG(y = y, X = X, model = "probit", burnin = 100) # estimate a logit model using example data # warning: use more burn-ins, burnin = 100 is just used for demonstration purposes data(lfp) y = lfp[,1] X = lfp[,-1] results.logit = UPG(y = y, X = X, model = "logit", burnin = 100) # estimate a MNL model using example data # warning: use more burn-ins, burnin = 100 is just used for demonstration purposes data(program) y = program[,1] X = program[,-1] results.mnl = UPG(y = y, X = X, model = "mnl", burnin = 100) # estimate a binomial logit model using example data # warning: use more burn-ins, burnin = 100 is just used for demonstration purposes data(titanic) y = titanic[,1] Ni = titanic[,2] X = titanic[,-c(1,2)] results.binomial = UPG(y = y, X = X, Ni = Ni, model = "binomial", burnin = 100)
UPG.Probit
, UPG.Logit
, UPG.MNL
and UPG.Binomial
objects using coda
UPG.Diag
computes a number of MCMC diagnostics based on the Markov chains that are contained in the model output returned by UPG
.
UPG.Diag(object = NULL)
UPG.Diag(object = NULL)
object |
an object of class |
Returns a list containing effective sample size, effective sampling rate and inefficiency factors for each coefficient. In addition, maximum, minimum and median of these measures are returned.
Gregor Zens
# estimate a probit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.probit = UPG(y = y, X = X, model = "probit") # compute MCMC diagnostics UPG.Diag(results.probit)
# estimate a probit model using example data library(UPG) data(lfp) y = lfp[,1] X = lfp[,-1] results.probit = UPG(y = y, X = X, model = "probit") # compute MCMC diagnostics UPG.Diag(results.probit)
UPG.Binomial
objectsUPG.Diag.Binomial
computes inefficiency factors, effective sample size and effective sampling rate based on the posterior distributions in a UPG.Binomial
object.
UPG.Diag.Binomial(object = NULL)
UPG.Diag.Binomial(object = NULL)
object |
an object of class |
Returns a list containing effective sample size, effective sampling rate and inefficiency factors for each coefficient.
Gregor Zens
UPG.Logit
objectsUPG.Diag.Logit
computes inefficiency factors, effective sample size and effective sampling rate based on the posterior distributions in a UPG.Logit
object.
UPG.Diag.Logit(object = NULL)
UPG.Diag.Logit(object = NULL)
object |
an object of class |
Returns a list containing effective sample size, effective sampling rate and inefficiency factors for each coefficient.
Gregor Zens
UPG.MNL
objectsUPG.Diag.MNL
computes inefficiency factors, effective sample size and effective sampling rate based on the posterior distributions in a UPG.MNL
object.
UPG.Diag.MNL(object = NULL)
UPG.Diag.MNL(object = NULL)
object |
an object of class |
Returns a list containing effective sample size, effective sampling rate and inefficiency factors for each coefficient.
Gregor Zens
UPG.Diag.Probit
computes inefficiency factors, effective sample size and effective sampling rate based on the posterior distributions in a UPG.Probit
object.
UPG.Diag.Probit(object = NULL)
UPG.Diag.Probit(object = NULL)
object |
an object of class |
Returns a list containing effective sample size, effective sampling rate and inefficiency factors for each coefficient.
Gregor Zens