https://github.com/cran/aster
Tip revision: d150687fca407ce91f0fbdb5abd5b7fc6a66ad63 authored by Charles J. Geyer on 06 September 2005, 00:00:00 UTC
version 0.3-1
version 0.3-1
Tip revision: d150687
raster.Rout.save
R : Copyright 2004, The R Foundation for Statistical Computing
Version 2.0.1 (2004-11-15), ISBN 3-900051-07-0
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for a HTML browser interface to help.
Type 'q()' to quit R.
>
> library(aster)
>
> set.seed(42)
> nind <- 25
> nnode <- 5
>
> theta <- rnorm(nind * nnode) / 10
> theta <- matrix(theta, nind, nnode)
>
> root <- sample(1:3, nind * nnode, replace = TRUE)
> root <- matrix(root, nind, nnode)
>
> famnam <- families()
> fam <- c(1, 1, 2, 3, 3)
> print(famnam[fam])
[1] "bernoulli" "bernoulli" "poisson" "non.zero.poisson"
[5] "non.zero.poisson"
>
> pred <- c(0, 1, 1, 2, 3)
> print(pred)
[1] 0 1 1 2 3
>
> save.seed <- .Random.seed
> x <- raster(theta, pred, fam, root)
>
> .Random.seed <- save.seed
> my.x <- NaN * x
>
> for (i in 1:nnode) {
+ ipred <- pred[i]
+ if (ipred == 0) {
+ xpred <- root[ , i]
+ } else {
+ xpred <- my.x[ , ipred]
+ }
+ if (famnam[fam[i]] == "bernoulli") {
+ p <- 1 / (1 + exp(- theta[ , i]))
+ xi <- rep(0, nind)
+ ii <- xpred > 0
+ xi[ii] <- rbinom(sum(ii), xpred[ii], p[ii])
+ my.x[ , i] <- xi
+ }
+ if (famnam[fam[i]] == "poisson") {
+ mu <- exp(theta[ , i])
+ xi <- rep(0, nind)
+ ii <- xpred > 0
+ xi[ii] <- rpois(sum(ii), xpred[ii] * mu[ii])
+ my.x[ , i] <- xi
+ }
+ if (famnam[fam[i]] == "non.zero.poisson") {
+ mu <- exp(theta[ , i])
+ my.x[ , i] <- rnzp(nind, mu, xpred)
+ }
+ }
>
> all.equal(x, my.x)
[1] TRUE
>
>