<p>The difference between PC and PC Stable is a change to the Skeleton phase of the algorithm, implemented by the <code>skeleton()</code> function in <code>pcalg</code>. The <code>pcSelect()</code> function is only trying to learn the adjacency set of one particular variable, not the whole structure of the graph, so it does not call <code>skeleton()</code>. It looks like you're trying to copy the parts of <code>skeleton</code> that have the Stable modification directly into <code>pcSelect</code>. However, in <code>skeleton</code>, G is a matrix, and in <code>pcSelect</code>, G is a vector. That's giving you an error when you try to apply the <code>split()</code> function, which works on the matrix but not on the vector.</p>

<p>So what do you need to achieve the Stable modification in <code>pcSelect</code>? From the R documentation, it looks like <code>pcSelect</code> is an implementation of the PC-simple algorithm, published in Buehlmann, P., Kalisch, M. and Maathuis, M.H. (2010). 'Variable selection for high-dimensional linear models: partially faithful distributions and the PC-simple algorithm.' <em>Biometrika 97</em>, 261–278. The paper is on Arxiv here: <a href="http://arxiv.org/abs/0906.3204" rel="nofollow">http://arxiv.org/abs/0906.3204</a> . </p>

<p>In line 278 of the Arxiv version, the authors describe how edges are to be removed, by creating a new "active set" of regressors at each stage. As written, the conditioning sets in the correlation tests range over <em>all</em> variables in the active set, before the new active set is created. In other words, variables are not removed from the active set after each test; a group of them are removed at the end of each stage, so there is no dependence on the order of tests within each stage. This is equivalent to the Stable modification to PC. </p>

<p>If the <code>pcSelect</code> implementation follows its published description, then you needn't worry: it already has the Stable modification built in. The <a href="https://github.com/rforge/pcalg/blob/master/pkg/R/pcalg.R" rel="nofollow">source code of pcSelect</a> is a bit opaque, but I think that's what it's doing. So you don't need to change anything in <code>pcSelect</code>! </p>
How to write stable method in pcSelect as similar as pc_stable
<p>In R code,pcalg package. How to write stable method in pcSelect as similar as pc_stable? I just want to write stable method into pcSelect as follows:</p>

<pre><code>while (!done &amp;&amp; any(G)) {
  n.edgetests[ord+1] &lt;- 0
  done &lt;- TRUE
  ind &lt;- which(G)
  remainingEdgeTests &lt;- length(ind)
  if(verbose&gt;=1)
  cat("Order=",ord,"; remaining edges:",remainingEdgeTests,"\n", sep='')
  if(method == "stable") {
     #View(G)
     ## Order-independent version: Compute the adjacency sets for any vertex
     ## Then don't update when edges are deleted
     G.l &lt;- split(G, gl(p,p))
     #View(G.l)
  }
</code></pre>

<p>However, <code>G.l&lt;-split(G,gl(p,p))</code> is not success in here, could you please help me ,thanks. </p>