PValues, Sample Size and Data Mining
Want to share your content on Rbloggers? click here if you have a blog, or here if you don't.
Recently, a paper was presented at our university that showed a significant effect for a variable of interest but had a relatively small number of observations. One colleague suggested that we should consider the significance of the results with care since the number of observations was fairly small.
This ignited some discussion. Given that the significance test computed exact pvalues, why should the significance of the results be less convincing than if we had a larger sample? Independent of the sample size the probability to find a result significant at a 5% level if there is actually no effect should be 5%.
The discussion turned to the question whether small sample sizes could sometimes be problematic because they may magnify possible biases if some data mining takes place. Indeed the dangers of data mining and ‘phacking’ are a regular theme in statistics literature and on statistics blogs. To get a better gut feeling of the relationship between sample size and possible biases from data mining, I just have run different MonteCarlo simulations in R that are shown below.
Freedman’s simulation study
I am currently reading the very nice book Counterfactuals and Causal Inference by Stephen Morgan and Christopher Winship. They cite a classical simulation study by Freedman (1983) that had a result that I found quite surprising and can be related to the question above.
Let us replicate the study with slightly modified numbers in R.
<span class="n">set.seed</span><span class="p">(</span><span class="m">123456789</span><span class="p">)</span><span class="w">
</span><span class="n">vars</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">100</span><span class="w"> </span><span class="c1"># Number of explanatory variables</span><span class="w">
</span><span class="n">obs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">150</span><span class="w"> </span><span class="c1"># Number of observations</span><span class="w">
</span><span class="c1"># Create 100 random iid explanatory variables</span><span class="w">
</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">matrix</span><span class="p">(</span><span class="n">rnorm</span><span class="p">(</span><span class="n">obs</span><span class="o">*</span><span class="n">vars</span><span class="p">),</span><span class="w"> </span><span class="n">obs</span><span class="p">,</span><span class="w"> </span><span class="n">vars</span><span class="p">)</span><span class="w">
</span><span class="n">colnames</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">paste0</span><span class="p">(</span><span class="s2">"x"</span><span class="p">,</span><span class="m">1</span><span class="o">:</span><span class="n">vars</span><span class="p">)</span><span class="w">
</span><span class="c1"># A dependent variable that is independent of all x</span><span class="w">
</span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">rnorm</span><span class="p">(</span><span class="n">obs</span><span class="p">)</span><span class="w">
</span><span class="c1"># Combine to data frame</span><span class="w">
</span><span class="n">dat</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cbind</span><span class="p">(</span><span class="n">data.frame</span><span class="p">(</span><span class="n">y</span><span class="o">=</span><span class="n">y</span><span class="p">),</span><span class="n">x</span><span class="p">)</span><span class="w">
</span><span class="c1"># Regress y on all 100 explanatory variables</span><span class="w">
</span><span class="n">reg1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lm</span><span class="p">(</span><span class="n">y</span><span class="o">~</span><span class="n">.</span><span class="p">,</span><span class="w"> </span><span class="n">data</span><span class="o">=</span><span class="n">dat</span><span class="p">)</span><span class="w">
</span><span class="c1"># Collect regression results in a data frame</span><span class="w">
</span><span class="c1"># and extract pvalues</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">broom</span><span class="p">)</span><span class="w">
</span><span class="n">res1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">broom</span><span class="o">::</span><span class="n">tidy</span><span class="p">(</span><span class="n">reg1</span><span class="p">)</span><span class="w">
</span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">res1</span><span class="o">$</span><span class="n">p.value</span><span class="p">[</span><span class="m">1</span><span class="p">]</span><span class="w">
</span><span class="c1"># Count the number of significant variables</span><span class="w">
</span><span class="c1"># at different significance levels</span><span class="w">
</span><span class="nf">sum</span><span class="p">(</span><span class="n">p</span><span class="w"> </span><span class="o"><=</span><span class="w"> </span><span class="m">0.01</span><span class="p">)</span><span class="w">
</span>
## [1] 1
<span class="nf">sum</span><span class="p">(</span><span class="n">p</span><span class="w"> </span><span class="o"><=</span><span class="w"> </span><span class="m">0.05</span><span class="p">)</span><span class="w">
</span>
## [1] 5
<span class="nf">sum</span><span class="p">(</span><span class="n">p</span><span class="w"> </span><span class="o"><=</span><span class="w"> </span><span class="m">0.10</span><span class="p">)</span><span class="w">
</span>
## [1] 13
We have 100 explanatory variables that are completely independent from each other and from the dependent variable y. We run a regression of y on all x and find that 1 of the 100 explanatory variables is significant at a 1% level, 5 at a 5% level and 13 at a 10% level. Nothing surprising so far.
Now we select the subset of variables that has a pvalue below 0.25. This can roughly reflect some data driven selection of variables, which unfortunately may well happen in some research papers. We run the regression again with the subset of the 37 selected variables.
<span class="c1"># Select variables with pvalue below 25%</span><span class="w">
</span><span class="n">used.vars</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">which</span><span class="p">(</span><span class="n">res1</span><span class="o">$</span><span class="n">p.value</span><span class="p">[</span><span class="m">1</span><span class="p">]</span><span class="w"> </span><span class="o"><=</span><span class="w"> </span><span class="m">0.25</span><span class="p">)</span><span class="w">
</span><span class="nf">length</span><span class="p">(</span><span class="n">used.vars</span><span class="p">)</span><span class="w">
</span>
## [1] 37
<span class="n">dat2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dat</span><span class="p">[,</span><span class="nf">c</span><span class="p">(</span><span class="m">1</span><span class="p">,</span><span class="n">used.vars</span><span class="m">+1</span><span class="p">)]</span><span class="w">
</span><span class="c1"># Regress y on selected explanatory variables</span><span class="w">
</span><span class="c1"># that had pvalue below 25% in first regression</span><span class="w">
</span><span class="n">reg2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lm</span><span class="p">(</span><span class="n">y</span><span class="o">~</span><span class="n">.</span><span class="p">,</span><span class="w"> </span><span class="n">data</span><span class="o">=</span><span class="n">dat2</span><span class="p">)</span><span class="w">
</span><span class="c1"># Collect regression results in a data frame</span><span class="w">
</span><span class="c1"># and extract pvalues</span><span class="w">
</span><span class="n">res2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">broom</span><span class="o">::</span><span class="n">tidy</span><span class="p">(</span><span class="n">reg2</span><span class="p">)</span><span class="w">
</span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">res2</span><span class="o">$</span><span class="n">p.value</span><span class="p">[</span><span class="m">1</span><span class="p">]</span><span class="w">
</span><span class="c1"># Count the number of significant variables</span><span class="w">
</span><span class="c1"># at different significance levels</span><span class="w">
</span><span class="nf">sum</span><span class="p">(</span><span class="n">p</span><span class="w"> </span><span class="o"><=</span><span class="w"> </span><span class="m">0.01</span><span class="p">)</span><span class="w">
</span>
## [1] 7
<span class="nf">sum</span><span class="p">(</span><span class="n">p</span><span class="w"> </span><span class="o"><=</span><span class="w"> </span><span class="m">0.05</span><span class="p">)</span><span class="w">
</span>
## [1] 19
<span class="nf">sum</span><span class="p">(</span><span class="n">p</span><span class="w"> </span><span class="o"><=</span><span class="w"> </span><span class="m">0.10</span><span class="p">)</span><span class="w">
</span>
## [1] 25
The absolute number of significant variables has strongly risen! Now 7 variables are significant at the 1% level compared to the one variable in the original regression, and 19 variables are significant at the 5% level, compared to 5 in the original regression.
So the problem of preselection is worse than just the obvious effect that the relative share of significant variables in the 37 selected variables increases compared to the share in the 100 original variables. Also the absolute number of significant variables increases by large factors.
The following graph shows the results of a systematic MonteCarlo study. I have repeated the simulation above for different combinations of number of variables and number of observations. For each combination I have run the simulation 200 times and computed the average share of coefficients that is significant at the 1% in the second regression. To be clear, the share is computed by dividing the number of significant variables after preselection by the original number of variables before preselection.
The share of significant variables only seems to depend on the ratio of observations to the original number of variables. The share of 1% significant coefficients is maximized at a level above 5% for a ratio of around 1.5, and goes down, converging to 1%, as the number of observations grows large.
Interestingly, if the ratio of observations to variables falls below 1.5, the share of significant variables also goes down. I must admit that my intuition for the geometry of OLS estimators is not good enough to grasp why we have this nonmonotonicity.
Yet, even though there is no monotone relationship, having a low number of observations may make it more likely to be in a range where variable preselection can substantially increases the absolute number of significant variables.
The following plot illustrates another issue of small sample sizes. It plots the mean absolute size of those coefficients that are significant at a 5% (before variable selections) against the number of observations:
Not surprisingly, we see that for a smaller number of observations, the coefficients of the spuriously significant variables have larger absolute values. Hence, also effect sizes may be taken with some grain of salt when the number of observations is small. Of course this should typically already be reflected, at least to some extend, in larger standard errors.
The greedy phacker
Let us now consider a variation of the study above. Assume a phacker systematically eliminates explanatory variables of a regression with the goal to find a significant effect of the explanatory variable x1
on the dependent variable y
. As in our initial example, assume we have obs=150
observations of one dependent variable y
and of vars=100
explanatory variables that are all independently drawn from each other and not related to y
.
The phacker proceeds according to the following greedy algorithm:

The phacker first runs the regression of y on all 100 explanatory variables and notes the pvalue for x1.

He then runs a regression in which he omits explanatory variable x2. If the resulting pvalue for x1 gets smaller, he permanently removes x2 from all future regression, otherwise he keeps x2.

He then moves on in the same fashion through all other explanatory variables x3, x4, x5, … and restarts the loop after reaching the last explanatory variable.

He repeats the process until he can no longer improve the pvalue of x1 by removing any more explanatory variable.
The R function greedy.phack
below simulates values and implements this greedy phacking algorithm. To speed up computations, we use the function fastLmPure
from the package RcppEigen. (Actually, the help for RcppEigen recommends to use lm.fit
for quick regressions instead, but fastLmPure
also directly returns standard errors which is convenient for computing pvalues).
<span class="n">compute.p.value</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">function</span><span class="p">(</span><span class="n">reg</span><span class="p">,</span><span class="n">vars</span><span class="p">,</span><span class="w"> </span><span class="n">obs</span><span class="p">,</span><span class="w"> </span><span class="n">row</span><span class="o">=</span><span class="m">2</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="c1">#restore.point("fastLm.p")</span><span class="w">
</span><span class="n">df</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">obs</span><span class="o"></span><span class="n">vars</span><span class="m">1</span><span class="w">
</span><span class="n">t</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">reg</span><span class="o">$</span><span class="n">coefficients</span><span class="p">[</span><span class="n">row</span><span class="p">]</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="n">reg</span><span class="o">$</span><span class="n">se</span><span class="p">[</span><span class="n">row</span><span class="p">]</span><span class="w">
</span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">pt</span><span class="p">(</span><span class="n">t</span><span class="p">,</span><span class="n">df</span><span class="p">)</span><span class="w">
</span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">2</span><span class="o">*</span><span class="p">(</span><span class="n">pmin</span><span class="p">(</span><span class="n">p</span><span class="p">,</span><span class="m">1</span><span class="o"></span><span class="n">p</span><span class="p">))</span><span class="w">
</span><span class="n">p</span><span class="w">
</span><span class="p">}</span><span class="w">
</span><span class="n">greedy.phack</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">function</span><span class="p">(</span><span class="n">vars</span><span class="o">=</span><span class="m">100</span><span class="p">,</span><span class="w"> </span><span class="n">obs</span><span class="o">=</span><span class="nf">round</span><span class="p">(</span><span class="n">vars</span><span class="o">*</span><span class="n">factor</span><span class="p">),</span><span class="w"> </span><span class="n">factor</span><span class="o">=</span><span class="n">obs</span><span class="o">/</span><span class="n">vars</span><span class="p">,</span><span class="w"> </span><span class="n">verbose</span><span class="o">=</span><span class="kc">FALSE</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">rnorm</span><span class="p">(</span><span class="n">obs</span><span class="p">)</span><span class="w">
</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">matrix</span><span class="p">(</span><span class="n">rnorm</span><span class="p">(</span><span class="n">obs</span><span class="o">*</span><span class="n">vars</span><span class="p">),</span><span class="w"> </span><span class="n">obs</span><span class="p">,</span><span class="w"> </span><span class="n">vars</span><span class="p">)</span><span class="w">
</span><span class="n">X</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cbind</span><span class="p">(</span><span class="m">1</span><span class="p">,</span><span class="n">x</span><span class="p">)</span><span class="w">
</span><span class="n">reg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">RcppEigen</span><span class="o">::</span><span class="n">fastLmPure</span><span class="p">(</span><span class="n">y</span><span class="o">=</span><span class="n">y</span><span class="p">,</span><span class="n">X</span><span class="o">=</span><span class="n">X</span><span class="p">)</span><span class="w">
</span><span class="n">p.org</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">compute.p.value</span><span class="p">(</span><span class="n">reg</span><span class="p">,</span><span class="w"> </span><span class="n">vars</span><span class="p">,</span><span class="w"> </span><span class="n">obs</span><span class="p">,</span><span class="w"> </span><span class="n">row</span><span class="o">=</span><span class="m">2</span><span class="p">)</span><span class="w">
</span><span class="n">coef.org</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">reg</span><span class="o">$</span><span class="n">coefficients</span><span class="p">[</span><span class="m">2</span><span class="p">]</span><span class="w">
</span><span class="n">ind</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">2</span><span class="w">
</span><span class="n">steps</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">0</span><span class="w">
</span><span class="n">deletions</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">0</span><span class="w">
</span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="kc">TRUE</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="n">ind</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ind</span><span class="m">+1</span><span class="w">
</span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">ind</span><span class="w"> </span><span class="o">></span><span class="w"> </span><span class="n">NCOL</span><span class="p">(</span><span class="n">X</span><span class="p">))</span><span class="w">
</span><span class="n">ind</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">3</span><span class="w">
</span><span class="n">steps</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">steps</span><span class="m">+1</span><span class="w">
</span><span class="n">reg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">RcppEigen</span><span class="o">::</span><span class="n">fastLmPure</span><span class="p">(</span><span class="n">y</span><span class="o">=</span><span class="n">y</span><span class="p">,</span><span class="n">X</span><span class="o">=</span><span class="n">X</span><span class="p">[,</span><span class="o"></span><span class="n">ind</span><span class="p">])</span><span class="w">
</span><span class="n">p.cur</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">compute.p.value</span><span class="p">(</span><span class="n">reg</span><span class="p">,</span><span class="w"> </span><span class="n">vars</span><span class="p">,</span><span class="w"> </span><span class="n">obs</span><span class="p">,</span><span class="w"> </span><span class="n">row</span><span class="o">=</span><span class="m">2</span><span class="p">)</span><span class="w">
</span><span class="c1"># Did the ommission reduce the pvalue?</span><span class="w">
</span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">p.cur</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">p</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="n">deletions</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">deletions</span><span class="m">+1</span><span class="w">
</span><span class="n">X</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">X</span><span class="p">[,</span><span class="o"></span><span class="n">ind</span><span class="p">]</span><span class="w">
</span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">verbose</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="n">cat</span><span class="p">(</span><span class="n">paste0</span><span class="p">(</span><span class="s2">"\n"</span><span class="p">,</span><span class="w"> </span><span class="n">deletions</span><span class="p">,</span><span class="s2">". p from "</span><span class="p">,</span><span class="w"> </span><span class="nf">round</span><span class="p">(</span><span class="n">p</span><span class="o">*</span><span class="m">100</span><span class="p">,</span><span class="m">2</span><span class="p">)</span><span class="w"> </span><span class="p">,</span><span class="w"> </span><span class="s2">"% to "</span><span class="p">,</span><span class="w"> </span><span class="nf">round</span><span class="p">(</span><span class="n">p.cur</span><span class="o">*</span><span class="m">100</span><span class="p">,</span><span class="m">2</span><span class="p">),</span><span class="s2">"%"</span><span class="p">))</span><span class="w">
</span><span class="p">}</span><span class="w">
</span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">p.cur</span><span class="w">
</span><span class="n">steps</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">0</span><span class="w">
</span><span class="c1"># Stop in case that only x1 remains</span><span class="w">
</span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">NCOL</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="o"><=</span><span class="m">2</span><span class="p">)</span><span class="w"> </span><span class="k">break</span><span class="w">
</span><span class="p">}</span><span class="w">
</span><span class="c1"># Stop if p valued could not be reduced</span><span class="w">
</span><span class="c1"># during a loop through all variables</span><span class="w">
</span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">steps</span><span class="w"> </span><span class="o">></span><span class="w"> </span><span class="n">NCOL</span><span class="p">(</span><span class="n">X</span><span class="p">)</span><span class="m">2</span><span class="p">)</span><span class="w"> </span><span class="k">break</span><span class="w">
</span><span class="p">}</span><span class="w">
</span><span class="nf">list</span><span class="p">(</span><span class="w">
</span><span class="n">vars</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">vars</span><span class="p">,</span><span class="w">
</span><span class="n">obs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">obs</span><span class="p">,</span><span class="w">
</span><span class="n">factor</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">factor</span><span class="p">,</span><span class="w">
</span><span class="n">p.org</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">p.org</span><span class="p">,</span><span class="w">
</span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">p</span><span class="p">,</span><span class="w">
</span><span class="n">coef.org</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">coef.org</span><span class="p">,</span><span class="w">
</span><span class="n">coef</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">reg</span><span class="o">$</span><span class="n">coefficients</span><span class="p">[</span><span class="m">2</span><span class="p">],</span><span class="w">
</span><span class="n">deletions</span><span class="o">=</span><span class="n">deletions</span><span class="w">
</span><span class="p">)</span><span class="w">
</span><span class="p">}</span><span class="w">
</span>
Let us run the simulation one time…
<span class="n">set.seed</span><span class="p">(</span><span class="m">123456789</span><span class="p">)</span><span class="w">
</span><span class="n">greedy.phack</span><span class="p">(</span><span class="n">vars</span><span class="o">=</span><span class="m">100</span><span class="p">,</span><span class="w"> </span><span class="n">obs</span><span class="o">=</span><span class="m">150</span><span class="p">)</span><span class="w">
</span>
## $vars
## [1] 100
##
## $obs
## [1] 150
##
## $factor
## [1] 1.5
##
## $p.org
## [1] 0.6996701
##
## $p
## [1] 0.002898235
##
## $coef.org
## [1] 0.04955448
##
## $coef
## [1] 0.2287564
##
## $deletions
## [1] 49
We can interpret the output as follows. In the initial regression, x1 was clearly insignificant with a pvalue of 70%. The algorithm then iteratively deleted a total of 49 variables. In the final regression with 51 remaining explanatory variables, x1 became highly significant with a pvalue of 0.29%. Also the regression coefficient of x1 increased more than 4fold from an original 0.05 to 0.23 in the final regression.
Let us now repeat the simulation with 10000 instead of only 150 observations:
<span class="n">set.seed</span><span class="p">(</span><span class="m">123456789</span><span class="p">)</span><span class="w">
</span><span class="n">greedy.phack</span><span class="p">(</span><span class="n">vars</span><span class="o">=</span><span class="m">100</span><span class="p">,</span><span class="w"> </span><span class="n">obs</span><span class="o">=</span><span class="m">10000</span><span class="p">)</span><span class="w">
</span>
## $vars
## [1] 100
##
## $obs
## [1] 10000
##
## $factor
## [1] 100
##
## $p.org
## [1] 0.6100959
##
## $p
## [1] 0.3679074
##
## $coef.org
## [1] 0.005237386
##
## $coef
## [1] 0.009142232
##
## $deletions
## [1] 52
In the original regression, the coefficient of x1 was insignificant with a pvalue of 61%. In total 52 variables variables were deleted. Yet, the resulting coefficient of x1 remains insignificant with a pvalue of 37%. The coefficient size after selection has a level of 0.009, which is much lower than in our small sample example.
I have also run a MonteCarlo study where I repeated the simulation above a 1000 times each for different combinations of numbers of variables and observations. The following plot shows the percentage of simulations in which the phacker was able to achieve a pvalue for x1 below 1%.
For the case of 100 variables and 150 observations, the phacker managed to a get pvalue for x1 below 1% in 94% of the simulations. Personally, I am indeed surprised by this large percentage given that the “only” thing the phacker does is to remove variables from the original regression.
We see how this percentage decreases with more observations. This suggests that a very large number of observations may provide some safeguard against phacking. Also, not surprisingly, this form of phacking gets harder if the set of candidate variables that can be removed is smaller.
Rbloggers.com offers daily email updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/datascience job.
Want to share your content on Rbloggers? click here if you have a blog, or here if you don't.