inst/doc/netReg.R

## -----------------------------------------------------------------------------
library(tensorflow)
library(tfprobability)
library(netReg)

## -----------------------------------------------------------------------------
# parameters
n <- 100
p <- 10
q <- 10

# affinity matrices
G.X <- abs(rWishart(1, 10, diag(p))[,,1])
G.Y <- abs(rWishart(1, 10, diag(q))[,,1])

## -----------------------------------------------------------------------------
# data
X <- matrix(rnorm(n * p), n)
B <- matrix(rnorm(p * q), p)
Y <- X %*% B + matrix(rnorm(n * q, 0, 0.1), n)

fit <- edgenet(X=X, Y=Y, G.X=G.X, G.Y=G.Y, family=gaussian, maxit=10)
summary(fit)

## -----------------------------------------------------------------------------
coef(fit)[,1:5]

## -----------------------------------------------------------------------------
pred  <- predict(fit, X)
pred[1:5, 1:5]

## ---- echo=FALSE, error=FALSE, warning=FALSE, message=FALSE, results=FALSE----
try({
  edgenet(X=X, Y=Y, G.X=G.X, G.Y=G.Y, family=binomial, maxit=11)  
})

## -----------------------------------------------------------------------------
# data
X <- matrix(rnorm(n * p), n)
B <- matrix(rnorm(p * q), p)

eta <- 1 / (1 + exp(-X %*% B))
Y.binom <- do.call("cbind", lapply(seq(10), function(.) rbinom(n, 1, eta[,.])))

fit <- edgenet(X=X, Y=Y, G.X=G.X, G.Y=G.Y, family=binomial, maxit=10)
summary(fit)

## -----------------------------------------------------------------------------
# data
X <- matrix(rnorm(n * p), n)
B <- matrix(rnorm(p * q), p)

eta <- exp(-X %*% B)
Y.pois <- do.call("cbind", lapply(seq(10), function(.) rpois(n, eta[,.])))

fit <- edgenet(X=X, Y=Y.pois, G.X=G.X, G.Y=G.Y, family=poisson, maxit=10)
summary(fit)

## -----------------------------------------------------------------------------
cv <- cv.edgenet(X=X, Y=Y, G.X=G.Y, G.Y, family=gaussian, optim.maxit=10, maxit=10)
summary(cv)

## -----------------------------------------------------------------------------
summary(cv$fit)

## -----------------------------------------------------------------------------
coef(cv)[,1:5]

## -----------------------------------------------------------------------------
pred  <- predict(cv, X)
pred[1:5, 1:5]

## ---- eval=FALSE--------------------------------------------------------------
#  library(netReg)
#  data("yeast")
#  
#  ls(yeast)
#  
#  X <- yeast$X
#  Y <- yeast$Y
#  G.Y <- yeast$GY

## -----------------------------------------------------------------------------
fit <- edgenet(X=X, Y=Y, G.Y=G.Y, lambda=5, family=gaussian, maxit=10, thresh=1e-3)
summary(fit)

## -----------------------------------------------------------------------------
X.new <- matrix(rnorm(10 * ncol(X)), 10)
pred  <- predict(fit, X.new)
pred[1:10, 1:5]

Try the netReg package in your browser

Any scripts or data that you put into this service are public.

netReg documentation built on Nov. 8, 2020, 5:17 p.m.