Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing simple scoring function with permutation test in R
    primarykey
    data
    text
    <p>I'm new in R, and I want to calculate some specific score for bunch of genes in biology. can somebody help me to implement this ? :-)</p> <p>I have following two vectors: </p> <pre><code>vector 1: (0.01,0.02,0.04,0.5,0.9,0.002,0.07,0.008) vector 2: (1,0,0,1,0,0,0,0) </code></pre> <p><code>vector 2</code> shows the membership of <code>vector 1</code> elements in specific set <strong>c</strong></p> <p>I want to implement a scoring function which would do the following steps :</p> <p>1) takes <code>vector 1</code> and <code>vector 2</code> as inputs.</p> <p>2) sort the <code>vector 1</code> with decreasing values and then sort the <code>vector 2</code> with corresponding <code>vector 1</code></p> <p>3) it's go through the sorted <code>vector 1</code> and if for the element <code>i</code> of the <code>vector 1</code> the corresponding element of sorted <code>vector 2</code> is <strong>1</strong>, then the score should be increased by <code>(m-l)</code>, else it should be decreased by <code>l</code> .</p> <p>m= length of <code>vector 1</code></p> <p>l= # of non-zero elements in <code>vector 2</code></p> <p>4) finally do the permutation on the <code>vectors 1</code> and <code>vector 2</code> and re-calculate the score of step 3. the permutation should preserve the true membership of <code>vector 1</code> element in <code>vector 2</code> . for example : <code>vector 1</code>: (10,7,4), <code>vector 2</code>: (0,0,1), after one possible permutation : <code>vector 1</code>: (4,7,10), <code>vector2</code>: (1,0,0)</p> <p>here is my attempt :</p> <pre><code> vector1&lt;- c(0.01,0.02,0.04,0.5,0.9,0.002,0.07,0.008) vector2&lt;- c(1,0,0,1,0,0,0,0) m&lt;-length(vector1) l&lt;-nnzero(vector2, na.counted = NA) score=0 score_function&lt;-function (a,b){ a&lt;-sort(a,decreasing = T) for (i in a){ if (b[i]==1) { score= + m-1 } else{ score= score-l } } score } </code></pre> <p>but I couldn't sort the <code>b</code> (vector 2) according to <code>vector 1</code> (a)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload