Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 86 additions & 5 deletions R/predict.hmsc.R
Original file line number Diff line number Diff line change
Expand Up @@ -496,22 +496,103 @@ predict.hmsc<-function(object, newdata, type = c("response","link"), conditional
### Apply inverse link function
if(type=="response"){
if(any(class(object)=="probit")){
result<-pnorm(apply(res,1:2, mean))
#result<-pnorm(apply(res,1:2, mean))
mu <- apply(res, 1:2, mean)
q025 <- apply(res, 1:2, function(x) {
pnorm(quantile(x, .025))
})
q05 <- apply(res, 1:2, function(x) {
pnorm(quantile(x, .05))
})
q10 <- apply(res, 1:2, function(x) {
pnorm(quantile(x, .1))
})
q90 <- apply(res, 1:2, function(x) {
pnorm(quantile(x, .9))
})
q95 <- apply(res, 1:2, function(x) {
pnorm(quantile(x, .95))
})
q975 <- apply(res, 1:2, function(x) {
pnorm(quantile(x, .975))
})
result <- list(mu = mu, q025 = q025, q05=q05, q10 = q10, q90 = q90, q95 = q95, q975 = q975)
}

if(any(class(object)=="gaussian")){
result<-apply(res,1:2, mean)
#result<-apply(res,1:2, mean)
mu <- apply(res, 1:2, mean)
q025 <- apply(res, 1:2, function(x) {
quantile(x, .025)
})
q05 <- apply(res, 1:2, function(x) {
quantile(x, .05)
})
q10 <- apply(res, 1:2, function(x) {
quantile(x, .1)
})
q90 <- apply(res, 1:2, function(x) {
quantile(x, .9)
})
q95 <- apply(res, 1:2, function(x) {
quantile(x, .95)
})
q975 <- apply(res, 1:2, function(x) {
quantile(x, .975)
})
result <- list(mu = mu, q025 = q025, q05=q05, q10 = q10, q90 = q90, q95 = q95, q975 = q975)
}

if(any(class(object)=="poisson" | any(class(object)=="overPoisson"))){
result<-exp(apply(res,1:2, mean))
#result<-exp(apply(res,1:2, mean))
mu <- apply(res, 1:2, mean)
q025 <- apply(res, 1:2, function(x) {
exp(quantile(x, .025))
})
q05 <- apply(res, 1:2, function(x) {
exp(quantile(x, .05))
})
q10 <- apply(res, 1:2, function(x) {
exp(quantile(x, .1))
})
q90 <- apply(res, 1:2, function(x) {
exp(quantile(x, .9))
})
q95 <- apply(res, 1:2, function(x) {
exp(quantile(x, .95))
})
q975 <- apply(res, 1:2, function(x) {
exp(quantile(x, .975))
})
result <- list(mu = mu, q025 = q025, q05=q05, q10 = q10, q90 = q90, q95 = q95, q975 = q975)
}
}

if(type=="link"){
result<-apply(res,1:2, mean)
#result<-apply(res,1:2, mean)
mu <- apply(res, 1:2, mean)
q025 <- apply(res, 1:2, function(x) {
quantile(x, .025)
})
q05 <- apply(res, 1:2, function(x) {
quantile(x, .05)
})
q10 <- apply(res, 1:2, function(x) {
quantile(x, .1)
})
q90 <- apply(res, 1:2, function(x) {
quantile(x, .9)
})
q95 <- apply(res, 1:2, function(x) {
quantile(x, .95)
})
q975 <- apply(res, 1:2, function(x) {
quantile(x, .975)
})
result <- list(mu = mu, q025 = q025, q05=q05, q10 = q10, q90 = q90, q95 = q95, q975 = q975)
}
colnames(result)<-colnames(Y)
#colnames(result)<-colnames(Y)
## the colnames match without this
}else{
### Apply inverse link function
if(type=="response"){
Expand Down