Skip to content

Commit

Permalink
version 0.1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiao Lu authored and cran-robot committed Dec 13, 2019
0 parents commit 3262e6a
Show file tree
Hide file tree
Showing 52 changed files with 5,458 additions and 0 deletions.
20 changes: 20 additions & 0 deletions DESCRIPTION
@@ -0,0 +1,20 @@
Package: qmix
Title: Finite Quantile Mixture Models
Version: 0.1.2.0
Author: Xiao Lu
Maintainer: Xiao Lu <xiao.lu.research@gmail.com>
Description: Estimates finite quantile mixture models using Markov chain Monte Carlo methods. The finite quantile mixture models include both fixed- and random-quantile specifications that are applicable to both continuous and binary dependent variables. Tools are available to assess convergence and summarize the estimation results.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Biarch: true
Depends: R (>= 3.4.0)
Imports: methods, Formula, Rcpp (>= 0.12.0), rstan (>= 2.18.1),
LinkingTo: BH (>= 1.66.0), Rcpp (>= 0.12.0), RcppEigen (>= 0.3.3.3.0),
rstan (>= 2.18.1), StanHeaders (>= 2.18.0)
SystemRequirements: GNU make
RoxygenNote: 6.1.1
NeedsCompilation: yes
Packaged: 2019-12-04 13:23:20 UTC; xiaolu
Repository: CRAN
Date/Publication: 2019-12-13 15:10:02 UTC
2 changes: 2 additions & 0 deletions LICENSE
@@ -0,0 +1,2 @@
YEAR: 2019
COPYRIGHT HOLDER: Xiao Lu
51 changes: 51 additions & 0 deletions MD5
@@ -0,0 +1,51 @@
6531bac7865dc399c3497eb743adc15a *DESCRIPTION
3a1cdf3a8255e0fa57bee3760d61f003 *LICENSE
4a1b47bc1507b548ee0016ad069da598 *NAMESPACE
b79a53817bcc34ddd5c46396cd86eabe *R/plotfun.R
8a70cf5f1aedb4f38540eb710125b0d3 *R/printfun.R
fe799daae96ec89ad894590d7bf01ccc *R/qmix-package.R
3b4aecffaf33b6ef990a8d5204c62d8c *R/qmix.R
cf35ba5b0d07ee26324f2dde79d93ca4 *R/source_fun.R
4c52bcddb916f93377c807122a8616bf *R/stanmodels.R
bb1dde5ce5f10edaa9bd4fc25ecbff75 *README.md
1cc60bdd8610449d30184e0bb374bf46 *configure
6bea7bdbd44ffa386677bfdec2d1984b *configure.win
855c064dbf8deaff96c8dc8a87169109 *inst/include/stan_meta_header.hpp
e7b21b5964860bb09cef4919a34d568d *inst/stan/include/license.stan
78854431245e87b4d87ba346bfd820ce *inst/stan/qmixbf.stan
2a9078c536ddc5e8c0b4e1fc110da1e1 *inst/stan/qmixbfv.stan
9fbe2ab2920afab2ef152cc69fb1a9d8 *inst/stan/qmixbr.stan
719a297f5143602c8d58ea8a5338ef89 *inst/stan/qmixbrv.stan
b48c0cd17c8b67217cf2d4a6d31a3feb *inst/stan/qmixcf.stan
6e8fbb6b0d0135b44db0d595bee5d448 *inst/stan/qmixcr.stan
dcb33bd35691fd6b66a17569dd71b04c *man/coef.qmix.Rd
325523d4cfca8b9b731e1109e2880a21 *man/dald.Rd
d237379f648a3453586f70eadfa5205a *man/inverse.Rd
427ac64bbca26fe5a956c04c9c3c0643 *man/is.dichotomous.Rd
d6d45ef62e373ba624c483d719a7974e *man/pald.Rd
ed03614dbd9ff1ccfc3e16c2e5790c12 *man/plot.qmix.Rd
608a78f4eac6f571b22f65b1c8342706 *man/plot_coef.qmix.Rd
33f4f3b2040f517424876031b3f5d0da *man/plot_trace.qmix.Rd
b3e7503405df14cd138d846ae46f680d *man/print.qmix.Rd
ca64e295661588e768281f4d7419294e *man/print_coef.qmix.Rd
4865b3444530b651746efc1e6cafeebe *man/print_mcmc.qmix.Rd
fc9a2d842cf5d0dd9243272985007ffd *man/print_text.qmix.Rd
fefec487e33822c01c9e8ae79ad158c6 *man/qald.Rd
e6b6eae3f018b75965ae91d9d0d5d083 *man/qmix-package.Rd
eee78c3d7e6b279c27a40a30bc6d6ef8 *man/qmix.Rd
5205f0132f1f53cc189cc407ab4a5404 *man/rald.Rd
16c4d03477156c810d4d7b09ea5bc5e9 *src/Makevars
390f45417fa4e4ba6b16f8ccf2bf9752 *src/Makevars.win
6091a2574423ad657e63450a3e7eaa67 *src/RcppExports.cpp
7929fb44344f41722562fad9e64c16fa *src/stanExports_qmixbf.cc
d69aef6c9419ec6737e437cde32cdbc7 *src/stanExports_qmixbf.h
7cdc1ba580f8aba44c5d8f9b8f814887 *src/stanExports_qmixbfv.cc
8bced10d6b7719f8a7843f69c19dbbbf *src/stanExports_qmixbfv.h
b07e0905f73a4cd376f92716740d345c *src/stanExports_qmixbr.cc
38542f00471630aa6e920260f9aeea82 *src/stanExports_qmixbr.h
efa062733cd3a6cf8d6c301c6ce71dc8 *src/stanExports_qmixbrv.cc
721e44423a767f53815ba3943ab1ac4d *src/stanExports_qmixbrv.h
6633725a645bf5a4a24778adb8d53e39 *src/stanExports_qmixcf.cc
9d20b4999125f26a24c3eda526899ad8 *src/stanExports_qmixcf.h
f3809ea0fab8abc4226371eaf22fd842 *src/stanExports_qmixcr.cc
672ca00df2321b2e2caa5cabad46f9d6 *src/stanExports_qmixcr.h
25 changes: 25 additions & 0 deletions NAMESPACE
@@ -0,0 +1,25 @@
# Generated by roxygen2: do not edit by hand

S3method(coef,qmix)
S3method(plot,qmix)
S3method(print,qmix)
export(dald)
export(pald)
export(plot_coef.qmix)
export(plot_trace.qmix)
export(print_coef.qmix)
export(print_mcmc.qmix)
export(print_text.qmix)
export(qald)
export(qmix)
export(rald)
import(Rcpp)
import(methods)
importFrom(rstan,sampling)
importFrom(stats,coef)
importFrom(stats,model.frame)
importFrom(stats,model.matrix)
importFrom(stats,quantile)
importFrom(stats,runif)
importFrom(stats,uniroot)
useDynLib(qmix, .registration = TRUE)
136 changes: 136 additions & 0 deletions R/plotfun.R
@@ -0,0 +1,136 @@
#' Plot qmix object
#'
#' General plot function for \code{qmix} objects, which dispatches the chosen
#' type of plotting to the corresponding function.
#'
#' @param x A \code{qmix} object to be plotted.
#' @param type Character string giving the type of plotting. The options are
#' \code{"trace"} for trace plots, \code{"coef"} for coefficient plots. The default is "coef".
#' @param ... Additional arguments to be passed to subsequent plot functions (check the See Also section).
#'
#'
#' @return None.
#'
#' @seealso \code{\link{plot_trace.qmix}} and \code{\link{plot_coef.qmix}}.
#' @export
#'
#'
#'
plot.qmix <- function(x, type = "coef", ...) {
printFunName <- paste0("plot_", type, ".qmix")
do.call(printFunName, args = c(list(object = x), list(...)))
}



#' Trace plots for qmix
#'
#' \code{plot_trace.qmix} is used to produce trace plots from a \code{qmix} object from the main function \code{\link{qmix}}.
#'
#' @param object A \code{qmix} object from running the main function \code{\link{qmix}}.
#' @param ... Additional parameters to be passed to \code{\link[rstan]{traceplot}}.
#'
#' @return None.
#' @export
#'
#'
plot_trace.qmix <- function(object, ...) {
if (object$binarylogic == TRUE & object$design == "fixed") {
names(object$stanfit)[-length(names(object$stanfit))] <-
c(paste0(
rep(paste0("C", 1:object$nmix, ": "), object$nmix),
rep(object$xnames, each = object$nmix)
),
paste0("C", 1:object$nmix, ": proportion"))
} else if (object$binarylogic == FALSE &
object$design == "fixed") {
names(object$stanfit)[-length(names(object$stanfit))] <-
c(
paste0(
rep(paste0("C", 1:object$nmix, ": "), object$nmix),
rep(object$xnames, each = object$nmix)
),
paste0("C", 1:object$nmix, ": proportion"),
paste0("C", 1:object$nmix, ": sigma")
)
} else if (object$binarylogic == TRUE &
object$design == "random") {
names(object$stanfit)[-length(names(object$stanfit))] <-
c(
paste0(
rep(paste0("C", 1:object$nmix, ": "), object$nmix),
rep(object$xnames, each = object$nmix)
),
paste0("C", 1:object$nmix, ": proportion"),
paste0("C", 1:object$nmix, ": quantile")
)
} else {
names(object$stanfit)[-length(names(object$stanfit))] <-
c(
paste0(
rep(paste0("C", 1:object$nmix, ": "), object$nmix),
rep(object$xnames, each = object$nmix)
),
paste0("C", 1:object$nmix, ": proportion"),
paste0("C", 1:object$nmix, ": sigma"),
paste0("C", 1:object$nmix, ": quantile")
)
}
rstan::traceplot(object$stanfit, ...)
}

#' Make coefficient plots for a \code{qmix} object
#'
#' \code{plot_coef.qmix} is used to produce coefficient plots from a \code{qmix} object.
#'
#' @param object A \code{qmix} object from running the main function \code{\link{qmix}}.
#' @param ... Additional parameters to be passed to \code{\link[rstan]{stan_plot}}.
#'
#' @return None.
#' @export
#'
#'
plot_coef.qmix <- function(object, ...) {
if (object$binarylogic == TRUE & object$design == "fixed") {
names(object$stanfit)[-length(names(object$stanfit))] <-
c(paste0(
rep(paste0("C", 1:object$nmix, ": "), object$nmix),
rep(object$xnames, each = object$nmix)
),
paste0("C", 1:object$nmix, ": proportion"))
} else if (object$binarylogic == FALSE &
object$design == "fixed") {
names(object$stanfit)[-length(names(object$stanfit))] <-
c(
paste0(
rep(paste0("C", 1:object$nmix, ": "), object$nmix),
rep(object$xnames, each = object$nmix)
),
paste0("C", 1:object$nmix, ": proportion"),
paste0("C", 1:object$nmix, ": sigma")
)
} else if (object$binarylogic == TRUE &
object$design == "random") {
names(object$stanfit)[-length(names(object$stanfit))] <-
c(
paste0(
rep(paste0("C", 1:object$nmix, ": "), object$nmix),
rep(object$xnames, each = object$nmix)
),
paste0("C", 1:object$nmix, ": proportion"),
paste0("C", 1:object$nmix, ": quantile")
)
} else {
names(object$stanfit)[-length(names(object$stanfit))] <-
c(
paste0(
rep(paste0("C", 1:object$nmix, ": "), object$nmix),
rep(object$xnames, each = object$nmix)
),
paste0("C", 1:object$nmix, ": proportion"),
paste0("C", 1:object$nmix, ": sigma"),
paste0("C", 1:object$nmix, ": quantile")
)
}
rstan::plot(object$stanfit, ...)
}
148 changes: 148 additions & 0 deletions R/printfun.R
@@ -0,0 +1,148 @@
#' Extract coefficients from a \code{qmix} object
#'
#' Create a table of coefficient results from a \code{qmix} object.
#'
#' @param object A \code{qmix} object from running the main function \code{\link{qmix}}.
#' @param ... Further arguments to be passed according to \code{\link[stats]{coef}}.
#'
#' @return A table of coefficients with their corresponding lower and upper bounds.
#' @export
#'
#' @method coef qmix
#'
#'
coef.qmix <- coefficients.qmix <- function(object, ...) {
coefmat <-
cbind(matrix(object$means[1:(object$npars * object$nmix)], nrow = object$npars * object$nmix),
t(object$ulbs[, 1:(object$npars * object$nmix)]))
row.names(coefmat) <-
paste0(rep(paste0("C", 1:object$nmix, ": "), object$nmix),
rep(object$xnames, each = object$nmix))
coef_theta <-
cbind(matrix(object$means[(object$npars * object$nmix + 1):(object$npars * object$nmix + object$nmix)], nrow = object$nmix), t(object$ulbs[, (object$npars * object$nmix + 1):(object$npars * object$nmix + object$nmix)]))
row.names(coef_theta) <-
paste0("C", 1:object$nmix, ": proportion")
coefmat <- rbind(coefmat, coef_theta)
if (object$binarylogic == FALSE) {
coef_sigma <-
cbind(matrix(object$means[(object$npars * object$nmix + object$nmix + 1):(object$npars * object$nmix + 2 *
object$nmix)], nrow = object$nmix), t(object$ulbs[, (object$npars * object$nmix + object$nmix + 1):(object$npars * object$nmix + 2 *
object$nmix)]))
row.names(coef_sigma) <- paste0("C", 1:object$nmix, ": sigma")
coefmat <- rbind(coefmat, coef_sigma)
}

if (object$binarylogic == FALSE & object$design == "random") {
coef_p <-
cbind(matrix(object$means[(object$npars * object$nmix + 2 * object$nmix + 1):(object$npars * object$nmix + 3 *
object$nmix)], nrow = object$nmix), t(object$ulbs[, (object$npars * object$nmix + 2 *
object$nmix + 1):(object$npars * object$nmix + 3 * object$nmix)]))
row.names(coef_p) <- paste0("C", 1:object$nmix, ": quantile")
coefmat <- rbind(coefmat, coef_p)
}

if (object$binarylogic == TRUE & object$design == "random") {
coef_p <-
cbind(matrix(object$means[(object$npars * object$nmix + object$nmix + 1):(object$npars * object$nmix + 2 *
object$nmix)], nrow = object$nmix), t(object$ulbs[, (object$npars * object$nmix + object$nmix + 1):(object$npars * object$nmix + 2 *
object$nmix)]))
row.names(coef_p) <- paste0("C", 1:object$nmix, ": quantile")
coefmat <- rbind(coefmat, coef_p)
}

colnames(coefmat) <- c("Estimate", "LB", "UB")
return(coefmat)
}


#' Print returns from a \code{qmix} object
#'
#' General print function for \code{qmix} objects, which dispatches the chosen type
#' of printing to the corresponding function.
#'
#' @param x A \code{qmix} object to be printed.
#' @param type Character string giving the type of printing, such as
#' \code{"text"}, \code{"mcmc"}, \code{"coef"}.
#' @param ... Additional arguments to be passed to print functions (check the See Also section).
#'
#' @return None.
#' @seealso \code{\link{print_text.qmix}}, \code{\link{print_mcmc.qmix}}, \code{\link{print_coef.qmix}}.
#' @export
#'
#'
#'
print.qmix <- function(x, type = "text", ...) {
printFunName <- paste0("print_", type, ".qmix")
do.call(printFunName, args = c(list(object = x), list(...)))
}


#' Print the main results from a \code{qmix} object.
#'
#' @param object A \code{qmix} object.
#' @param digits Number of digits to display.
#'
#' @return None.
#' @export
#'
#'
#'
print_text.qmix <- function(object, digits = 3) {
cat("Finite Quantile Mixture with",
object$design,
"quantile specification \n")
cat("\nCall:\n",
paste(deparse(object$Call), sep = "\n", collapse = "\n"),
"\n\n",
sep = "")
cat(
"MCMC run for",
object$nsim,
"iterations, with",
object$stanfit@sim$warmup2,
"used. \n\n"
)
cat("Coefficients:\n")
print(round(coef(object), digits))
cat("\n")
names(object$thetas) = paste0("C", 1:object$nmix)
cat("Estimated proportions of each mixture component: ",
object$thetas)
cat("\n")
}


#' Print convergence diagnostics from a \code{qmix} object
#'
#' \code{print_mcmc.qmix} prints a number of diagnostics about the convergence of a \code{qmix} objects.
#'
#'
#' @param object A \code{qmix} object.
#' @param ... Additional arguments to be passed to the \code{print} function.
#'
#' @return None.
#' @export
#'
#'
#'
print_mcmc.qmix <- function(object, ...) {
print(object$stanfit, ...)
}



#' Print coefficients of a \code{qmix} object
#'
#' \code{print_coef.qmix} prints out coefficients from a \code{qmix} object from running the main function \code{\link{qmix}}.
#'
#' @param object A \code{qmix} object.
#' @param digits Number of digits to display.
#'
#' @return None.
#' @export
#'
#'
#'
print_coef.qmix <- function(object, digits = 3) {
print(round(coef(object), digits))
}

0 comments on commit 3262e6a

Please sign in to comment.