-
-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updates for Regression and Other Stories #432
Changes from 23 commits
8d43c7f
8bfe1d2
0973436
dd800ab
76a3806
fa19d13
7add53f
90d49bc
b469f1e
92d10a6
fef4102
dfd7d33
6ebfa90
cc050a0
64126fc
c5b67a4
f97753c
eb5cbd4
4c3b8e2
dcf587a
5a43cad
27e9988
efc6d16
781a131
3a412a9
8708832
5e8f452
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,22 +15,24 @@ | |
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
#' Posterior distribution of the linear predictor | ||
#' Posterior distribution of the (possibly transformed) linear predictor | ||
#' | ||
#' Extract the posterior draws of the linear predictor, possibly transformed by | ||
#' the inverse-link function. This function is occasionally useful, but it | ||
#' should be used sparingly. Inference and model checking should generally be | ||
#' carried out using the posterior predictive distribution (i.e., using | ||
#' \code{\link{posterior_predict}}). | ||
#' | ||
#' @aliases posterior_linpred | ||
#' @aliases posterior_linpred posterior_epred | ||
#' @export | ||
#' | ||
#' @templateVar stanregArg object | ||
#' @template args-stanreg-object | ||
#' @param transform Should the linear predictor be transformed using the | ||
#' inverse-link function? The default is \code{FALSE}, in which case the | ||
#' untransformed linear predictor is returned. | ||
#' untransformed linear predictor is returned. The non-default behavior | ||
#' of \code{TRUE} is somewhat deprecated since \code{posterior_epred} | ||
#' should be called instead. | ||
#' @param newdata,draws,re.form,offset Same as for \code{\link{posterior_predict}}. | ||
#' @param XZ If \code{TRUE} then instead of computing the linear predictor the | ||
#' design matrix \code{X} (or \code{cbind(X,Z)} for models with group-specific | ||
|
@@ -43,6 +45,14 @@ | |
#' transformed) linear predictor. The exception is if the argument \code{XZ} | ||
#' is set to \code{TRUE} (see the \code{XZ} argument description above). | ||
#' | ||
#' @details The \code{posterior_linpred} function returns the posterior | ||
#' distribution of the linear predictor, while the \code{posterior_epred} | ||
#' function returns the posterior distribution of the conditional expectation. | ||
#' In the special case of a Gaussian likelihood with an identity link | ||
#' function, these two concepts are the same. The \code{posterior_epred} | ||
#' function is a less noisy way obtain averages over the output of | ||
jgabry marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#' \code{\link{posterior_predict}}. | ||
#' | ||
#' @note For models estimated with \code{\link{stan_clogit}}, the number of | ||
#' successes per stratum is ostensibly fixed by the research design. Thus, | ||
#' when calling \code{posterior_linpred} with new data and \code{transform = | ||
|
@@ -63,11 +73,11 @@ | |
#' colMeans(linpred) | ||
#' | ||
#' # probabilities | ||
#' probs <- posterior_linpred(example_model, transform = TRUE) | ||
#' probs <- posterior_epred(example_model) | ||
#' colMeans(probs) | ||
#' | ||
#' # not conditioning on any group-level parameters | ||
#' probs2 <- posterior_linpred(example_model, transform = TRUE, re.form = NA) | ||
#' probs2 <- posterior_epred(example_model, re.form = NA) | ||
#' apply(probs2, 2, median) | ||
#' | ||
posterior_linpred.stanreg <- | ||
|
@@ -102,6 +112,11 @@ posterior_linpred.stanreg <- | |
} else { | ||
colnames(eta) <- rownames(newdata) | ||
} | ||
|
||
if (isTRUE(transform)) { | ||
message("transform = TRUE is somewhat deprecated. ", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like use of "somewhat" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah "somewhat" is a bit strange. I think the idea was to distinguish between a message and warning, but I'm not sure. @bgoodri Are you ok if we change this message to a warning and get rid of "somewhat"? |
||
"Please call posterior_epred(), which provides equivalent functionality.") | ||
} | ||
|
||
if (!transform || is.nlmer(object)) { | ||
return(eta) | ||
|
@@ -115,7 +130,19 @@ posterior_linpred.stanreg <- | |
return(g(eta)) | ||
} | ||
|
||
|
||
#' @rdname posterior_linpred.stanreg | ||
#' @export | ||
posterior_epred.stanreg <- | ||
function(object, | ||
newdata = NULL, | ||
draws = NULL, | ||
re.form = NULL, | ||
offset = NULL, | ||
XZ = FALSE, | ||
...) { | ||
return(suppressMessages(posterior_linpred(object, transform = TRUE, newdata, | ||
draws, re.form, offset, XZ, ...))) | ||
} | ||
|
||
# internal ---------------------------------------------------------------- | ||
clogit_linpred_transform <- function(object, newdata = NULL, eta = NULL) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "somewhat deprecated" mean? Is it possible to be more specific?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. @bgoodri by "somewhat deprecated" did you just mean that we don't recommend it anymore but we're not going to throw a warning (I think it's just a message currently not a warning)? Is there a reason not to deprecate it with a proper warning?