https://github.com/cran/aster
Raw File
Tip revision: c651dababa29dbc9b4cc34906c535a0ed860432b authored by Charles J. Geyer on 19 July 2005, 00:00:00 UTC
version 0.2
Tip revision: c651dab
aster.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
>  ncoef <- nnode + 1
> 
>  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
> 
>  modmat <- array(0, c(nind, nnode, ncoef))
>  modmat[ , , 1] <- 1
>  for (i in 2:nnode)
+      modmat[ , i, i] <- 1
>  modmat[ , , ncoef] <- rnorm(nind * nnode)
> 
>  beta <- rnorm(ncoef) / 10
> 
>  phi <- matrix(modmat, ncol = ncoef) %*% beta
>  phi <- matrix(phi, ncol = nnode)
> 
>  theta <- .C("aster_phi2theta",
+      nind = as.integer(nind),
+      nnode = as.integer(nnode),
+      pred = as.integer(pred),
+      fam = as.integer(fam),
+      phi = as.double(phi),
+      theta = matrix(as.double(0), nind, nnode))$theta
> 
>  root <- sample(1:3, nind * nnode, replace = TRUE)
>  root <- matrix(root, nind, nnode)
> 
>  x <- raster(theta, pred, fam, root)
>  
>  out1 <- aster(x, root, pred, fam, modmat, type = "unco", method = "nlm")
>  out2 <- aster(x, root, pred, fam, modmat, type = "unco", method = "CG")
>  out3 <- aster(x, root, pred, fam, modmat, type = "unco", method = "L-B")
> 
>  all.equal(out1$coefficients, out2$coefficients)
[1] TRUE
>  all.equal(out2$coefficients, out3$coefficients)
[1] "Mean relative  difference: 4.052646e-08"
>  all.equal(out3$coefficients, out1$coefficients)
[1] "Mean relative  difference: 4.059093e-08"
> 
>  print(out1$coefficients)
[1] -0.06809277 -0.30705441  0.18624357  0.07757573 -0.37636339 -0.08435995
> 
>  out1 <- aster(x, root, pred, fam, modmat, type = "cond", method = "nlm")
>  out2 <- aster(x, root, pred, fam, modmat, type = "cond", method = "CG")
>  out3 <- aster(x, root, pred, fam, modmat, type = "cond", method = "L-B")
> 
>  all.equal(out1$coefficients, out2$coefficients)
[1] TRUE
>  all.equal(out2$coefficients, out3$coefficients)
[1] TRUE
>  all.equal(out3$coefficients, out1$coefficients)
[1] TRUE
> 
>  print(out1$coefficients)
[1]  1.74295791 -1.54997014 -1.71291553 -1.72922986 -2.16895832 -0.02625205
> 
> 
back to top