osofr / simcausal

Simulating Longitudinal and Network Data with Causal Inference Applications
64 stars 11 forks source link

fix dependency for rmvnorm #9

Closed jangorecki closed 8 years ago

jangorecki commented 8 years ago

There is an attempt to load mvtnorm namespace in examples - https://github.com/osofr/simcausal/blob/d0c5d8b721358b38cb1db1bca78621ea8ead2f33/man/node.Rd#L285 As mvtnorm is suggested dependency, it should not be required to run examples according to R-exts. This can be conditionally escaped with requireNamespace. It is possible there are other cases of that issue in other examples, this one was to first that fails.

> #---------------------------------------------------------------------------------------
> # EXAMPLE 7: Multivariate random variables
> #---------------------------------------------------------------------------------------
> require("mvtnorm")
Loading required package: mvtnorm
Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘mvtnorm’
> D <- DAG.empty()
> 
> # 3 dimensional normal (uncorrelated), using rmvnorm function from rmvnorm package:
> D <- D +
+   node(c("X1","X2","X3"), distr = "rmvnorm", mean = c(0,1,2))
Error in node(c("X1", "X2", "X3"), distr = "rmvnorm", mean = c(0, 1, 2)) : 
  rmvnorm: this node distribution function could not be located
Execution halted
jangorecki commented 8 years ago

Also copula package:

> # Bivariate uniform copula using copula package (correlation coef 0.75):
> require("copula")
Loading required package: copula
Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘copula’
jangorecki commented 8 years ago

Also bindata package:

> # Same as "A.Bin1" and "A.Bin2", but directly using rmvbin function in bindata package:
> require("bindata")
Loading required package: bindata
Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘bindata’
> D <- DAG.empty()
> D <- D +
+   node(c("B.Bin1","B.Bin2"), distr = "rmvbin",
+     margprob = c(0.5, 0.5),
+     bincorr = matrix(c(1,0.75,0.75,1), ncol=2))
Error in node(c("B.Bin1", "B.Bin2"), distr = "rmvbin", margprob = c(0.5,  : 
  rmvbin: this node distribution function could not be located
Execution halted
osofr commented 8 years ago

Indeed, thanks for bringing this up. Fixed now.