-
Notifications
You must be signed in to change notification settings - Fork 2
/
mr_mash_rss_predict.R
47 lines (44 loc) · 1.13 KB
/
mr_mash_rss_predict.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#' @title Predict future observations from mr.mash.rss fit.
#'
#' @param object a mr.mash.rss fit.
#'
#' @param newx a new value for X at which to do predictions.
#'
#' @param \dots Additional arguments (not used).
#'
#' @return Matrix of predicted values.
#'
#' @export
#' @export predict.mr.mash.rss
#'
predict.mr.mash.rss <- function(object, newx, ...){
if(!is.matrix(newx))
stop("X must be a matrix.")
if (any(is.na(newx)))
stop("X must not contain missing values.")
if(any(!is.na(object$intercept)))
return(with(object,addtocols(newx %*% mu1,intercept)))
else
return(with(object,newx %*% mu1))
}
#' @title Extract coefficients from mr.mash.rss fit.
#'
#' @param object a mr.mash fit.
#'
#' @param \dots Other arguments (not used).
#'
#' @return p x r or (p+1) x r matrix of coefficients,
#' depending on whether an intercept was computed.
#'
#' @export
#' @export coef.mr.mash.rss
#'
coef.mr.mash.rss <- function(object, ...){
if(any(!is.na(object$intercept))){
coeffs <- rbind(object$intercept, object$mu1)
rownames(coeffs)[1] <- "(Intercept)"
} else {
coeffs <- object$mu1
}
return(coeffs)
}