[r-cran-mnp] 10/51: Import Upstream version 2.3-1
Andreas Tille
tille at debian.org
Fri Sep 8 14:14:45 UTC 2017
This is an automated email from the git hooks/post-receive script.
tille pushed a commit to branch master
in repository r-cran-mnp.
commit e3c5ce00116f49b0b97f0dcca369f6b057efd79e
Author: Andreas Tille <tille at debian.org>
Date: Fri Sep 8 15:54:44 2017 +0200
Import Upstream version 2.3-1
---
DESCRIPTION | 8 ++++----
NAMESPACE | 3 ++-
R/coef.mnp.R | 12 ++++++++++++
R/cov.mnp.R | 30 ++++++++++++++++++++++++++++++
R/predict.mnp.R | 15 ++++-----------
man/coef.mnp.Rd | 45 +++++++++++++++++++++++++++++++++++++++++++++
man/cov.mnp.Rd | 42 ++++++++++++++++++++++++++++++++++++++++++
man/mnp.Rd | 5 +++--
8 files changed, 142 insertions(+), 18 deletions(-)
diff --git a/DESCRIPTION b/DESCRIPTION
index 7657218..d0aafe9 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,7 +1,7 @@
Package: MNP
-Version: 2.2-2
-Date: 2005-05-09
-Title: R Package for the Fitting the Multinomial Probit Model
+Version: 2.3-1
+Date: 2005-05-27
+Title: R Package for Fitting the Multinomial Probit Model
Author: Kosuke Imai <kimai at princeton.edu>,
David A. van Dyk <dvd at uci.edu>.
Maintainer: Kosuke Imai <kimai at princeton.edu>
@@ -22,4 +22,4 @@ Description: MNP is a publicly available R package that fits the Bayesian
of Econometrics, Vol. 124, No. 2 (February), pp. 311-334.
License: GPL (version 2 or later)
URL: http://www.princeton.edu/~kimai/research/MNP.html
-Packaged: Mon May 9 11:13:50 2005; kimai
+Packaged: Fri May 27 11:32:22 2005; kimai
diff --git a/NAMESPACE b/NAMESPACE
index d0a80a1..b18e7d4 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,7 +1,8 @@
useDynLib(MNP)
-export(mnp, summary.mnp, print.summary.mnp)
+export(mnp, coef.mnp, cov.mnp, predict.mnp, summary.mnp, print.summary.mnp)
+S3method(coef, mnp)
S3method(summary, mnp)
S3method(predict, mnp)
S3method(print, mnp)
diff --git a/R/coef.mnp.R b/R/coef.mnp.R
new file mode 100644
index 0000000..2266860
--- /dev/null
+++ b/R/coef.mnp.R
@@ -0,0 +1,12 @@
+coef.mnp <- function(object, subset = NULL, ...) {
+ param <- object$param
+ p <- object$n.alt
+ n.cov <- ncol(param) - p*(p-1)/2
+ n <- nrow(param)
+ if (is.null(subset))
+ return(param[,1:n.cov])
+ else if (subset > n)
+ stop(paste("invalid input for `subset.' only", nrow(param), "draws are stored."))
+ else
+ return(param[subset, 1:n.cov])
+}
diff --git a/R/cov.mnp.R b/R/cov.mnp.R
new file mode 100644
index 0000000..d789179
--- /dev/null
+++ b/R/cov.mnp.R
@@ -0,0 +1,30 @@
+cov.mnp <- function(object, subset = NULL, ...) {
+ if (is.null(subset))
+ subset <- 1:nrow(object$param)
+ else if (max(subset) > nrow(object$param))
+ stop(paste("invalid input for `subset.' only", nrow(param), "draws are stored."))
+
+ p <- object$n.alt
+ n <- length(subset)
+ Sigma <- array(0, c(p-1, p-1, n))
+ param <- object$param
+ n.cov <- ncol(param) - p*(p-1)/2
+ cov <- param[,(n.cov+1):ncol(param)]
+ for (i in 1:n) {
+ count <- 1
+ for (j in 1:(p-1)) {
+ Sigma[j,j:(p-1),i] <- cov[subset[i],count:(count+p-j-1)]
+ count <- count + p - j
+ }
+ diag(Sigma[,,i]) <- diag(Sigma[,,i]/2)
+ Sigma[,,i] <- Sigma[,,i] + t(Sigma[,,i])
+ }
+ tmp <- list()
+ tmp[[1]] <- tmp[[2]] <- object$alt[-pmatch(object$base, object$alt)]
+ tmp[[3]] <- as.character(subset)
+ dimnames(Sigma) <- tmp
+ if (n > 1)
+ return(Sigma)
+ else
+ return(Sigma[,,1])
+}
diff --git a/R/predict.mnp.R b/R/predict.mnp.R
index a2af611..1508a26 100644
--- a/R/predict.mnp.R
+++ b/R/predict.mnp.R
@@ -10,9 +10,9 @@ predict.mnp <- function(object, newdata = NULL, newdraw = NULL,
param <- object$param
else
param <- newdraw
- n.cov <- ncol(param) - p*(p-1)/2
+ coef <- coef(object)
+ n.cov <- ncol(coef)
n.draws <- nrow(param)
- coef <- param[,1:n.cov]
cov <- param[,(n.cov+1):ncol(param)]
## get X matrix ready
@@ -49,18 +49,11 @@ predict.mnp <- function(object, newdata = NULL, newdraw = NULL,
NULL, 1:n.draws))
tmp <- floor(n.draws/10)
inc <- 1
+ Sigma <- cov.mnp(object)
for (i in 1:n.draws) {
- Sigma <- matrix(0, p-1, p-1)
- count <- 1
- for (j in 1:(p-1)) {
- Sigma[j,j:(p-1)] <- cov[i,count:(count+p-j-1)]
- count <- count + p - j
- }
- diag(Sigma) <- diag(Sigma)/2
- Sigma <- Sigma + t(Sigma)
for (j in 1:n.obs)
W[,j,i] <- matrix(x[j,], ncol=n.cov) %*% matrix(coef[i,]) +
- mvrnorm(1, mu = rep(0, p-1), Sigma = Sigma)
+ mvrnorm(1, mu = rep(0, p-1), Sigma = Sigma[,,i])
if (i == inc*tmp & verbose) {
cat("", inc*10, "percent done.\n")
inc <- inc + 1
diff --git a/man/coef.mnp.Rd b/man/coef.mnp.Rd
new file mode 100644
index 0000000..882f308
--- /dev/null
+++ b/man/coef.mnp.Rd
@@ -0,0 +1,45 @@
+\name{coef.mnp}
+
+\alias{coef.mnp}
+\alias{coefficients.mnp}
+
+\title{Extract Multinomial Probit Model Coefficients}
+
+\description{
+ \code{coef.mnp} is a function which extracts multinomial probit model
+ coefficients from ojbects returned by
+ \code{mnp}. \code{coefficients.mnp} is an alias for it. \code{coef}
+ method for class \code{mnp}.
+}
+
+\usage{
+ \method{coef}{mnp}(object, subset = NULL, ...)
+}
+
+\arguments{
+ \item{object}{An output object from \code{mnp}.}
+ \item{subset}{A scalar or a numerical vector specifying the row
+ number(s) of \code{param} in the output object from \code{mnp}. If
+ specified, the posterior draws of coefficients for those rows are
+ extracted. The default is \code{NULL} where all the posterior draws
+ are extracted.
+ }
+ \item{...}{further arguments passed to or from other methods.}
+}
+
+\value{
+ \code{coef.mnp} returns a matrix (when a numerical vector or
+ \code{NULL} is specified for \code{subset} argument) or a vector (when
+ a scalar is specified for \code{subset} arugment) of multinomila
+ probit model coefficients.
+}
+
+\seealso{\code{mnp}, \code{cov.mnp}; MNP home page at
+ \url{http://www.princeton.edu/~kimai/research/MNP.html}}
+
+\author{
+ Kosuke Imai, Department of Politics, Princeton University
+ \email{kimai at Princeton.Edu}
+}
+
+\keyword{methods}
diff --git a/man/cov.mnp.Rd b/man/cov.mnp.Rd
new file mode 100644
index 0000000..a86053f
--- /dev/null
+++ b/man/cov.mnp.Rd
@@ -0,0 +1,42 @@
+\name{cov.mnp}
+
+\alias{cov.mnp}
+
+\title{Extract Multinomial Probit Model Covariance Matrix}
+
+\description{
+ \code{cov.mnp} is a function which extracts the posterior draws of
+ covariance matrix from objects returned by \code{mnp}.
+}
+
+\usage{
+ cov.mnp(object, subset = NULL, ...)
+}
+
+\arguments{
+ \item{object}{An output object from \code{mnp}.}
+ \item{subset}{A scalar or a numerical vector specifying the row
+ number(s) of \code{param} in the output object from \code{mnp}. If
+ specified, the posterior draws of covariance matrix for those rows are
+ extracted. The default is \code{NULL} where all the posterior draws
+ are extracted.
+ }
+ \item{...}{further arguments passed to or from other methods.}
+}
+
+\value{
+ When a numerical vector or \code{NULL} is specified for \code{subset}
+ argument, \code{cov.mnp} returns a three dimensional array where the
+ third dimension indexes posterior draws. When a scalar is
+ specified for \code{subset} arugment, \code{cov.mnp} returns a matrix.
+}
+
+\seealso{\code{mnp}, \code{coef.mnp}; MNP home page at
+ \url{http://www.princeton.edu/~kimai/research/MNP.html}}
+
+\author{
+ Kosuke Imai, Department of Politics, Princeton University
+ \email{kimai at Princeton.Edu}
+}
+
+\keyword{methods}
diff --git a/man/mnp.Rd b/man/mnp.Rd
index 669281e..f58a378 100644
--- a/man/mnp.Rd
+++ b/man/mnp.Rd
@@ -203,7 +203,7 @@ predict(res2, newdata = japan[10,], type = "prob")
Imai, Kosuke and David A. van Dyk. (2005b) \dQuote{MNP: R Package for
Fitting the Multinomial Probit Models,} \emph{Journal of Statistical
- Software}, Vol. 14, No. 2.
+ Software}, Vol. 14, No. 3 (May), pp.1-32.
}
\author{
@@ -214,7 +214,8 @@ predict(res2, newdata = japan[10,], type = "prob")
\url{http://www.ics.uci.edu/~dvd}.
}
-\seealso{\code{summary.mnp}; MNP home page at
+\seealso{\code{coef.mnp}, \code{cov.mnp}, \code{predict.mnp},
+\code{summary.mnp}; MNP home page at
\url{http://www.princeton.edu/~kimai/research/MNP.html}}
\keyword{models}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/r-cran-mnp.git
More information about the debian-science-commits
mailing list