Association rule in R - removing redundant rule (arules)
<p>Assume we have 3 rules:</p>

<pre><code>[1] {A,B,D} -&gt; {C}

[2] {A,B} -&gt; {C}

[3] Whatever it is
</code></pre>

<p>Rule <code>[2]</code> is a subset of rule <code>[1]</code> (because rule <code>[1]</code> contains all the items in rule <code>[2]</code>), so rule <code>[1]</code> should be eliminated (because rule <code>[1]</code> is too specific and its information is included in rule <code>[2]</code> )</p>

<p>I searched through the internet and everyone is using these code to remove redundant rules:</p>

<pre><code>subset.matrix &lt;- is.subset(rules.sorted, rules.sorted)
subset.matrix[lower.tri(subset.matrix, diag=T)] &lt;- NA
redundant &lt;- colSums(subset.matrix, na.rm=T) &gt;= 1
which(redundant)
rules.pruned &lt;- rules.sorted[!redundant]
</code></pre>

<p>I dont understand how the code work. </p>

<p>After line 2 of the code, the subset.matrix will become:</p>

<pre><code>      [,1] [,2] [,3]
[1,]   NA    1    0
[2,]   NA   NA    0
[3,]   NA   NA   NA
</code></pre>

<p>The cells in the lower triangle are set to be NA and since rule <code>[2]</code> is a subset of rule <code>[1]</code>, the corresponding cell is set to 1. So I have 2 questions:</p>

<ol>
<li><p>Why do we have to set the lower triangle as NA? If we do so then how can we check whether rule <code>[2]</code> is subset of rule <code>[3]</code> or not? (the cell has been set as NA)</p></li>
<li><p>In our case, rule <code>[1]</code> should be the one to be eliminated, but these code eliminate rule <code>[2]</code> instead of rule <code>[1]</code>. (Because the first cell in column 2 is 1, and according to line 3 of the code, the column sums of column 2 >= 1, therefore will be treated as redundant)</p></li>
</ol>

<p>Any help would be appreciated !! </p>