<p>As Devon said, removing the <code>which</code> will give you <code>W</code> as a logical vector that can be used to index the <em>sorted</em> p-values. To get a logical vector that can be used to subset the original (unsorted) values you’ll need to go a step further:</p>

<pre><code>candidates = is.element(1 : L, order(adjusted.p.values)[W])
</code></pre>

<p>However, I’m not sure this will work with your data: the name <code>adjusted.p.values</code> suggests that these values are <em>already</em> FDR-adjusted. So you cannot/should not perform additional correction on them. If they are already adjusted, then you can get candidate loci simply by</p>

<pre><code>candidates = adjusted.p.values &lt; q
</code></pre>

CC BY-SA 3.0
2018-02-28T16:49:04.953Z
Thanks@Konrad Rudolph.candidates = is.element(1 : L, order(adjusted.p.values)[W]) did exactly what I wanted.
Anna1364
CC BY-SA 3.0
2018-02-28T10:45:20.370Z
2018-02-28T10:45:20.370Z
Konrad Rudolph
<p>Remove the <code>which()</code>, which is converting the boolean vector to a vector if indices to <code>TRUE</code>.</p>

CC BY-SA 3.0
2018-02-28T07:57:37.930Z
2018-02-28T07:57:37.930Z
Devon Ryan
<p>I have done some genome scan analysis and I want to identify the outlier loci. For an expected value of the FRD equal to q = 10, a list of candidate loci can be obtained by using the Benjamin-Hochberg procedure as follows:</p>

<pre><code>q=0.1
L = length(adjusted.p.values)
W = which(sort(adjusted.p.values) &lt; q * (1:L) / L)
candidates = order (adjusted.p.values)[w]
</code></pre>

<p>and this is part of the outliers and my output</p>

<pre><code>head(candidates)
 [1]  3  4  9   10  13 
</code></pre>

<p>But I need the output in a different type.
I want to assign TRUE if a locus has been chosen as outlier and FALSE if it has not </p>

<pre><code>  head (desired_output)

  [1] FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE FALSE TRUE
</code></pre>

<p>Any idea how can I modify the Code?</p>

<r>
Identifying outlier loci in R
# Identifying outlier loci in R

(Asked by: username_0 on 2018-02-27)

I have done some genome scan analysis and I want to identify the outlier loci. For an expected value of the FRD equal to q = 10, a list of candidate loci can be obtained by using the Benjamin-Hochberg procedure as follows:
q=0.1
L = length(adjusted.p.values)
W = which(sort(adjusted.p.values) < q * (1:L) / L)
candidates = order (adjusted.p.values)[w]

and this is part of the outliers and my output
head(candidates)
 [1]  3  4  9   10  13 

But I need the output in a different type.
I want to assign TRUE if a locus has been chosen as outlier and FALSE if it has not 
  head (desired_output)

  [1] FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE FALSE TRUE

Any idea how can I modify the Code?

**Tags:** r

---

## 2 answers

### Answer by username_1 on 2018-02-28. Score: 3 | Accepted answer

As Devon said, removing the which will give you W as a logical vector that can be used to index the sorted p-values. To get a logical vector that can be used to subset the original (unsorted) values you’ll need to go a step further:
candidates = is.element(1 : L, order(adjusted.p.values)[W])

However, I’m not sure this will work with your data: the name adjusted.p.values suggests that these values are already FDR-adjusted. So you cannot/should not perform additional correction on them. If they are already adjusted, then you can get candidate loci simply by
candidates = adjusted.p.values < q

> **Comments:**
> **username_0**: Thanks@Konrad Rudolph.candidates = is.element(1 : L, order(adjusted.p.values)[W]) did exactly what I wanted.  

---

### Answer by username_2 on 2018-02-28. Score: -1

Remove the `which()`, which is converting the boolean vector to a vector if indices to `TRUE`.


---

