1

I am using PC algorithm function, in which Conditional Independence is one of the attribute. Facing error in the following code. Note that 'data' here is the data that I have been using, and 1,6,2 in gaussCItest are the node positions in my adjacency matrix x and y of the data.

code:

library(pcalg)   
suffstat <- list(C = cor(data), n = nrow(data))    
pc.data <- pc(suffstat,
              indepTest=gaussCItest(1,6,2,suffstat),  
              p=ncol(data),alpha=0.01)

Error:

Error in indepTest(x, y, nbrs[S], suffStat) :
could not find function "indepTest"

user20650
  • 24,654
  • 5
  • 56
  • 91
  • from the help page of `?pc` is that `indepTest` is to be a function. The examples seem to point to `indepTest=gaussCItest` (i.e. no argument to evaluate the function). If you just want to run one test, I think you'd just use `gaussCItest(1,6,2, suffstat)` and not pass it to the pc algorithm – user20650 Jan 22 '20 at 22:59
  • No, i actually need to use PC algorithm , to see the causal structure . I tried other algorithms as well, like FCI, RFCI. but every algorithm, has the attribute of conditional independence test, hence failing the indepTest part . – Divya Athyala Jan 23 '20 at 10:50
  • The pc algorithm learns the DAG by searching associations between many variables. It does this by using some test of association -- in your case it uses the function `gaussCItest` to test these associations. You do not need to pass any arguments to it in this case. When you pass `gaussCItest(1,6,2, suffstat)` this is no longer a function but an evaluated test of association between the requested variables i.e. it is not learning a DAG but only a test of a single association. As the examples in `?pc` to learn the DAG use `pc(suffstat,indepTest=gaussCItest,p=ncol(data),alpha=0.01)`. – user20650 Jan 23 '20 at 11:11
  • Thanks .It got resolved – Divya Athyala Jan 24 '20 at 11:26

1 Answers1

1

Below is the code that worked.removed the parameters for gaussCItest as its a function, which can be used directly.

library(pcalg)   
suffstat <- list(C = cor(data), n = nrow(data))    
pc.data <- pc(suffstat,indepTest=gaussCItest, p=ncol(data),alpha=0.01)
user20650
  • 24,654
  • 5
  • 56
  • 91