title: Growth rate in student abilities
body: <p>I am struggling with writing code to calculate and then plot the growth rate. My data frame <code>df</code> looks like this</p>
  <pre><code>ID  Jan_Score  Dec_Score  Cluster
  A   0          5          1
  B   19         14         2
  F   13         21         3
  D   12         10         2
  M   27         33         4
  P   54         54         4
  </code></pre>
  <ul>
  <li>The scores column in the above data frame reflects students' scores in an abilities test. Therefore, zero (0) does not mean a lack of that ability, it just means that those students could not provide sufficient evidence to demonstrate that ability.</li>
  <li>The values in the scores column are, therefore, never negative.</li>
  <li>Also, when students' assessments show identical scores in January (at the start of the year) and December (at the end of the year), it does not mean that students haven't grown in their capabilities because the content on which assessment was done in January is lesser than the content in December. Therefore, the growth cannot be Infinity (such as for ID <strong>A</strong> when <strong>January</strong> score is <strong>zero</strong>) or negative (such as for ID <strong>D</strong> when <strong>January</strong> score is higher than the <strong>December</strong> score).</li>
  </ul>
  <p>My question is, how can we calculate (and if possible plot) the growth per student ID and then per cluster?</p>
  <p>Any help would be greatly appreciated.</p>
  <h3>Partial solution</h3>
  <p>I am using the following formula for calculating growth per person (i.e., per ID)</p>
  <pre><code>df$growth = (df$Dec_Score - df$Jan_Score) / df$Jan_Score
  </code></pre>
  <ul>
  <li>But this formula needs to be changed to accommodate for the corner cases such as:</li>
  <li>
  <ol>
  <li>When <em>Jan_Score</em> is zero, it replaces the <em>Jan_Score</em> value of 0 with 0.1 (that's an arbitrary decision that I took).</li>
  </ol>
  </li>
  <li>
  <ol start="2">
  <li>Address the cases when <em>Dec_score</em> is less than the <em>Jan_Score</em>. Perhaps add an offset value in all <em>Dec_Score</em> so that they are always more than <em>Jan_Score</em>. If the maximum value is 54 and the minimum value is 0, what could be a good offset value to be added in Dec_Score?</li>
  </ol>
  </li>
  </ul>
  <p>Any help would be greatly appreciated!</p>
  <p>The following posts are related but do not address my problem:</p>
  <p><a href="https://stackoverflow.com/questions/12515043/how-to-calculate-growth-with-a-positive-and-negative-number">How to calculate growth with a positive and negative number?</a>,</p>
  <p><a href="https://stackoverflow.com/questions/19908431/how-to-calculate-percentage-when-old-value-is-zero">How to calculate percentage when old value is ZERO</a>,</p>
  <p><a href="https://stackoverflow.com/questions/46231927/what-is-my-increment-percentage-from-0-to-20">what is my increment percentage from 0 to 20?</a>,</p>
  <p><a href="https://stackoverflow.com/questions/61763131/growth-calculation-nan-with-0-value">Growth calculation NaN with 0 value</a></p>
  <p>For reference, the <strong>dput(df)</strong> is</p>
  <pre><code>dput(df)
  structure(list(ID = c(&quot;A&quot;, &quot;B&quot;, &quot;F&quot;, &quot;D&quot;, &quot;M&quot;, &quot;P&quot;), Jan_Score = c(0L, 
  19L, 13L, 12L, 27L, 54L), Dec_Score = c(5L, 14L, 21L, 10L, 33L, 
  54L), Cluster = structure(c(1L, 2L, 3L, 2L, 4L, 4L), .Label = c(&quot;1&quot;, 
  &quot;2&quot;, &quot;3&quot;, &quot;4&quot;), class = &quot;factor&quot;)), row.names = c(NA, -6L), class = &quot;data.frame&quot;)```
  </code></pre>