https://github.com/cran/aster
Tip revision: aa47935123bfca8a22cbc8345d658d0c1713a289 authored by Charles J. Geyer on 14 December 2023, 15:20:02 UTC
version 1.1-3
version 1.1-3
Tip revision: aa47935
aster.Rout.save
R version 3.6.0 (2019-04-26) -- "Planting of a Tree"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
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 an HTML browser interface to help.
Type 'q()' to quit R.
>
> library(aster)
Loading required package: trust
>
> set.seed(42)
>
> # needed because of the change in R function "sample" in R-devel
> suppressWarnings(RNGversion("3.5.2"))
>
> nind <- 25
> nnode <- 5
> ncoef <- nnode + 1
>
> fam <- c(1, 1, 2, 3, 3)
> pred <- c(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.origin <- matrix(as.double(0), nind, nnode)
>
> aster:::setfam(fam.default())
>
> phi.origin <- .C(aster:::C_aster_theta2phi,
+ nind = as.integer(nind),
+ nnode = as.integer(nnode),
+ pred = as.integer(pred),
+ fam = as.integer(fam),
+ theta = as.double(theta.origin),
+ phi = matrix(as.double(0), nind, nnode))$phi
>
> theta <- .C(aster:::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)
>
> out0 <- aster(x, root, pred, fam, modmat, type = "unco", method = "trust")
> 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(out0$coefficients, out1$coefficients)
[1] TRUE
> all.equal(out1$coefficients, out2$coefficients)
[1] TRUE
> all.equal(out2$coefficients, out3$coefficients, tol = 1e-7)
[1] TRUE
> all.equal(out3$coefficients, out0$coefficients, tol = 1e-7)
[1] TRUE
>
> out4 <- aster(x, root, pred, fam, modmat, type = "unco",
+ method = "trust", origin = theta.origin)
> pout4c <- out4$coefficients
> pout0c <- out0$coefficients
>
> foo <- as.numeric(out0$origin) +
+ matrix(out0$modmat, ncol = ncoef) %*% out0$coefficients
> bar <- as.numeric(out4$origin) +
+ matrix(out4$modmat, ncol = ncoef) %*% out4$coefficients
> all.equal(foo, bar)
[1] TRUE
> all.equal(phi.origin, out0$origin)
[1] TRUE
>
> out0 <- aster(x, root, pred, fam, modmat, type = "cond", method = "trust")
> 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(out0$coefficients, out1$coefficients)
[1] TRUE
> all.equal(out1$coefficients, out2$coefficients)
[1] TRUE
> all.equal(out2$coefficients, out3$coefficients)
[1] TRUE
> all.equal(out3$coefficients, out0$coefficients)
[1] TRUE
>
> pout0c.too <- out0$coefficients
>
> foo <- new.env(parent = emptyenv())
> bar <- suppressWarnings(try(load("aster.rda", foo), silent = TRUE))
> if (inherits(bar, "try-error")) {
+ save(pout4c, pout0c, pout0c.too, file = "aster.rda")
+ } else {
+ print(all.equal(pout4c, foo$pout4c))
+ print(all.equal(pout0c, foo$pout0c))
+ print(all.equal(pout0c.too, foo$pout0c.too))
+ }
[1] TRUE
[1] TRUE
[1] TRUE
>
>
> proc.time()
user system elapsed
0.337 0.021 0.349