“397 is conjectured to be the largest prime that can be represented uniquely as the sum of three positive squares”
+
+
+
That is, 3^2 + 8^2 + 18^2 = 397
+
+
This led to some confusion in the comments as people found other prime numbers that can be created as the sum of three squares. But the wording is sloppy; better wording would be:
+
+
+
“397 is conjectured to be the largest prime that can be represented as the sum of three positive squares of integers in exactly one way”
+
+
+
Let’s confirm that. The only method I know for something like this is brute force. I can make a data frame with three columns, each with all the squares of positive integers up to some maximum point - so the data frame has every combination of those, discarding duplicate combinations by making the order of the columns strictly non-decreasing. Then we sum those three squares, and store the results:
+
+
+
+
This gets us our one combination that adds up to 397:
Next step is to count the number of times each result appears.
+
+
+
+
So for example we see that 54 (which of course is not a prime - we haven’t yet filtered to primes) can be made 3 ways: as the sum of the squares of 1, 2, 7; of 2, 5, 5; and 3, 3, 6:
Then it’s a simple matter of joining that summary (of counts of the number of ways to get a given total of three squares) to a data frame of the prime numbers, and drawing a plot of the results:
+
+
+
+
There’s a bit of fiddling there to make the charts look nice for low values of k (where k is the maximum number I square). In my real life code the above is surrounded by a loop of different values of k, with the results saved as SVG and PNG images for use in this blog. All of which gets me this result:
+
+
+
+
And here we see for some larger results of k:
+
+
+
As k gets bigger of course the program gets slower to run. This method doesn’t scale well; for primes above about 250,000 the step of making a data frame of all the combinations of three squares starts taking too long. If I wanted to extend this further I’d have to find some ways to do this more efficiently, or put that step into a database that can handle bigger-than-memory data objects.
+
+
I’m sure there’s some interesting maths behind why this is just a “conjecture” and no-one has been able to prove it!
diff --git a/feed.r.xml b/feed.r.xml
index 064921d1f..602f7b13b 100644
--- a/feed.r.xml
+++ b/feed.r.xml
@@ -6,6 +6,109 @@
https://freerangestats.info
+
+ Prime numbers as sums of three squares. by @ellis2013nz
+ <p>I was interested by a <a href="https://www.linkedin.com/posts/fermatslibrary_397-is-conjectured-to-be-the-largest-prime-activity-7242947116719915008-BRz7?utm_source=share&utm_medium=member_desktop">LinkedIn post about the number 397</a>:</p>
+
+<blockquote>
+ <p>“397 is conjectured to be the largest prime that can be represented uniquely as the sum of three positive squares”</p>
+</blockquote>
+
+<p>That is, 3^2 + 8^2 + 18^2 = 397</p>
+
+<p>This led to some confusion in the comments as people found other prime numbers that can be created as the sum of three squares. But the wording is sloppy; better wording would be:</p>
+
+<blockquote>
+ <p>“397 is conjectured to be the largest prime that can be represented as the sum of three positive squares of integers in exactly one way”</p>
+</blockquote>
+
+<p>Let’s confirm that. The only method I know for something like this is brute force. I can make a data frame with three columns, each with all the squares of positive integers up to some maximum point - so the data frame has every combination of those, discarding duplicate combinations by making the order of the columns strictly non-decreasing. Then we sum those three squares, and store the results:</p>
+
+<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="n">library</span><span class="p">(</span><span class="n">primes</span><span class="p">)</span><span class="w">
+</span><span class="n">library</span><span class="p">(</span><span class="n">tidyverse</span><span class="p">)</span><span class="w">
+</span><span class="n">library</span><span class="p">(</span><span class="n">glue</span><span class="p">)</span><span class="w">
+
+</span><span class="n">k</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="m">30</span><span class="w">
+</span><span class="n">squares</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="p">(</span><span class="m">1</span><span class="o">:</span><span class="n">k</span><span class="p">)</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">primes</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">tibble</span><span class="p">(</span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">generate_primes</span><span class="p">(</span><span class="n">max</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">k</span><span class="o">^</span><span class="m">2</span><span class="p">))</span><span class="w">
+
+</span><span class="c1"># This is the part that gets slower with larger k as you make k^3 combinations</span><span class="w">
+</span><span class="n">s3s</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">expand_grid</span><span class="p">(</span><span class="n">s1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">squares</span><span class="p">,</span><span class="w"> </span><span class="n">s2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">squares</span><span class="p">,</span><span class="w"> </span><span class="n">s3</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">squares</span><span class="p">)</span><span class="w"> </span><span class="o">|></span><span class="w">
+ </span><span class="n">filter</span><span class="p">(</span><span class="n">s2</span><span class="w"> </span><span class="o">>=</span><span class="w"> </span><span class="n">s1</span><span class="w"> </span><span class="o">&</span><span class="w"> </span><span class="n">s3</span><span class="w"> </span><span class="o">>=</span><span class="w"> </span><span class="n">s2</span><span class="p">)</span><span class="w"> </span><span class="o">|></span><span class="w">
+ </span><span class="n">mutate</span><span class="p">(</span><span class="n">sum_3_sq</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">s1</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">s2</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">s3</span><span class="p">)</span><span class="w">
+
+</span><span class="c1"># example:</span><span class="w">
+</span><span class="n">filter</span><span class="p">(</span><span class="n">s3s</span><span class="p">,</span><span class="w"> </span><span class="n">sum_3_sq</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="m">397</span><span class="p">)</span></code></pre></figure>
+
+<p>This gets us our one combination that adds up to 397:</p>
+<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> s1 s2 s3 sum_3_sq
+ <dbl> <dbl> <dbl> <dbl>
+1 9 64 324 397
+</code></pre></div></div>
+
+<p>Next step is to count the number of times each result appears.</p>
+
+<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="n">s3s_sum</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">s3s</span><span class="w"> </span><span class="o">|></span><span class="w">
+ </span><span class="n">group_by</span><span class="p">(</span><span class="n">sum_3_sq</span><span class="p">)</span><span class="w"> </span><span class="o">|></span><span class="w">
+ </span><span class="n">summarise</span><span class="p">(</span><span class="n">number_3_square_sums</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">n</span><span class="p">())</span><span class="w">
+
+</span><span class="c1"># example:</span><span class="w">
+</span><span class="n">s3s_sum</span><span class="w"> </span><span class="o">|></span><span class="w">
+ </span><span class="n">filter</span><span class="p">(</span><span class="n">number_3_square_sums</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="m">3</span><span class="p">)</span><span class="w"> </span><span class="o">|></span><span class="w">
+ </span><span class="n">slice</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="n">left_join</span><span class="p">(</span><span class="n">s3s</span><span class="p">,</span><span class="w"> </span><span class="n">by</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"sum_3_sq"</span><span class="p">)</span></code></pre></figure>
+
+<p>So for example we see that 54 (which of course is not a prime - we haven’t yet filtered to primes) can be made 3 ways: as the sum of the squares of 1, 2, 7; of 2, 5, 5; and 3, 3, 6:</p>
+
+<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> sum_3_sq number_3_square_sums s1 s2 s3
+ <dbl> <int> <dbl> <dbl> <dbl>
+1 54 3 1 4 49
+2 54 3 4 25 25
+3 54 3 9 9 36
+</code></pre></div></div>
+
+<p>Then it’s a simple matter of joining that summary (of counts of the number of ways to get a given total of three squares) to a data frame of the prime numbers, and drawing a plot of the results:</p>
+
+<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="n">res</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">primes</span><span class="w"> </span><span class="o">|></span><span class="w">
+ </span><span class="n">left_join</span><span class="p">(</span><span class="n">s3s_sum</span><span class="p">,</span><span class="w"> </span><span class="n">by</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="s2">"p"</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"sum_3_sq"</span><span class="p">))</span><span class="w"> </span><span class="o">|></span><span class="w">
+ </span><span class="n">mutate</span><span class="p">(</span><span class="n">number_3_square_sums</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">replace_na</span><span class="p">(</span><span class="n">number_3_square_sums</span><span class="p">,</span><span class="w"> </span><span class="m">0</span><span class="p">))</span><span class="w">
+
+</span><span class="n">ggplot</span><span class="p">(</span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="n">aes</span><span class="w"> </span><span class="p">(</span><span class="n">x</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">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">number_3_square_sums</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
+ </span><span class="n">geom_point</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w">
+ </span><span class="n">annotate</span><span class="p">(</span><span class="s2">"point"</span><span class="p">,</span><span class="w"> </span><span class="n">colour</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"red"</span><span class="p">,</span><span class="w"> </span><span class="n">shape</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">4</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="m">397</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="m">1</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
+ </span><span class="n">annotate</span><span class="p">(</span><span class="s2">"text"</span><span class="p">,</span><span class="w"> </span><span class="n">colour</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"red"</span><span class="p">,</span><span class="w"> </span><span class="n">label</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"397"</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="m">500</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="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">hjust</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">0</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
+ </span><span class="n">scale_x_continuous</span><span class="p">(</span><span class="n">label</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">comma</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
+ </span><span class="n">labs</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Prime number"</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="s2">"Number of ways"</span><span class="p">,</span><span class="w">
+ </span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Number of ways to make a prime number as sum of three positive squares of integers"</span><span class="p">,</span><span class="w">
+ </span><span class="n">subtitle</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">glue</span><span class="p">(</span><span class="s2">"397 (circled) is the largest with exactly one way, of primes up to {comma(k^2)}."</span><span class="p">))</span><span class="w">
+
+</span><span class="k">if</span><span class="p">(</span><span class="nf">max</span><span class="p">(</span><span class="n">res</span><span class="o">$</span><span class="n">number_3_square_sums</span><span class="p">)</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="m">11</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="w"> </span><span class="o">+</span><span class="w">
+ </span><span class="n">scale_y_continuous</span><span class="p">(</span><span class="n">breaks</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">0</span><span class="o">:</span><span class="m">10</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
+ </span><span class="n">theme</span><span class="p">(</span><span class="n">panel.grid.minor.y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">element_blank</span><span class="p">())</span><span class="w">
+</span><span class="p">}</span></code></pre></figure>
+
+<p>There’s a bit of fiddling there to make the charts look nice for low values of k (where k is the maximum number I square). In my real life code the above is surrounded by a loop of different values of k, with the results saved as SVG and PNG images for use in this blog. All of which gets me this result:</p>
+
+<object type="image/svg+xml" data="https://freerangestats.info/img/0280-primes-squares-k30.svg" width="100%"><img src="https://freerangestats.info/img/0280-primes-squares-k30.png" width="100%" /></object>
+
+<p>And here we see for some larger results of k:</p>
+<object type="image/svg+xml" data="https://freerangestats.info/img/0280-primes-squares-k100.svg" width="100%"><img src="https://freerangestats.info/img/0280-primes-squares-k100.png" width="100%" /></object>
+
+<p>As k gets bigger of course the program gets slower to run. This method doesn’t scale well; for primes above about 250,000 the step of making a data frame of all the combinations of three squares starts taking too long. If I wanted to extend this further I’d have to find some ways to do this more efficiently, or put that step into a database that can handle bigger-than-memory data objects.</p>
+
+<p>I’m sure there’s some interesting maths behind why this is just a “conjecture” and no-one has been able to prove it!</p>
+
+<object type="image/svg+xml" data="https://freerangestats.info/img/0280-primes-squares-k300.svg" width="100%"><img src="https://freerangestats.info/img/0280-primes-squares-k300.png" width="100%" /></object>
+
+<p>That’s all for today.</p>
+
+ Sat, 21 Sep 2024 00:00:00 +1100
+ https://freerangestats.info/blog/2024/09/21/primes-squares
+ https://freerangestats.info/blog/2024/09/21/primes-squares
+
+
Stepwise selection of variables in regression is Evil. by @ellis2013nz<p>I’ve recently noticed that stepwise regression is still fairly popular, despite being well and truly frowned upon by well-informed statisticians. By stepwise regression, I mean any modelling strategy that involves adding or subtracting variables from a regression model on the basis that they are “significant”, reduce the Akaike Information Criterion, or increase adjusted R-squared, or in fact any other data-driven statistics.</p>
@@ -2297,162 +2400,5 @@ Black squares indicate situations where Player 2 should decline an offered doubl
https://freerangestats.info/blog/2024/05/05/pop-projections
-
- The 'V20' group of vulnerable countries and the MVI by @ellis2013nz
- <p>Just a brief blog post that is basically an addendum to <a href="/blog/2023/09/30/mvi">the one I wrote a few weeks ago</a> on the United Nations Multidimensional Vulnerability Index. I found myself wondering about the <a href="https://www.v-20.org/about">Vulnerable Twenty (V20) Group of Ministers of Finance of the Climate Vulnerable Forum</a>, which is now (despite the ‘20’ in its name) a collection of 68 economies.</p>
-
-<p>How vulnerable do these 68 economies look on the proposed MVI? I imagine they and others will be interested. After all, while ‘vulnerable to climate change’ (for the V20) is not the same as ‘vulnerable to anything’ (for the MVI), they are both using the same word. Given how prominently and frequently ‘climate change’ and ‘vulnerability’ are connected in this context, I suspect some stakeholders would be expecting the two approaches to have a similar set of vulnerable countries</p>
-
-<p>It turns out that the V20 economies are (according to the MVI) only slightly more ‘vulnerable’ than the average of the 142 countries that have an MVI score. On the other hand, they are materially poorer.</p>
-
-<p>Consider this table of median values:</p>
-
-<table class="table" style="margin-left: auto; margin-right: auto;">
- <thead>
- <tr>
- <th style="text-align:left;"> </th>
- <th style="text-align:right;"> Structural vulnerability </th>
- <th style="text-align:right;"> Lack of structural resilience </th>
- <th style="text-align:right;"> Multidimensional vulnerability </th>
- <th style="text-align:right;"> GDP per capita, PPP </th>
- </tr>
- </thead>
-<tbody>
- <tr>
- <td style="text-align:left;"> Member of V20 </td>
- <td style="text-align:right;"> 49.2 </td>
- <td style="text-align:right;"> 57.1 </td>
- <td style="text-align:right;"> 54.4 </td>
- <td style="text-align:right;"> $5,500 </td>
- </tr>
- <tr>
- <td style="text-align:left;"> Not a member of V20 </td>
- <td style="text-align:right;"> 48.4 </td>
- <td style="text-align:right;"> 55.0 </td>
- <td style="text-align:right;"> 52.4 </td>
- <td style="text-align:right;"> $13,700 </td>
- </tr>
-</tbody>
-</table>
-
-<p>In fact, many countries in the V20 have below-average MVI scores; and there are also countries that aren’t in the V20 but have notably above-average MVI scores. Consider this chart:</p>
-
-<object type="image/svg+xml" data="https://freerangestats.info/img/0257-discrepancies.svg" width="100%"><img src="https://freerangestats.info/img/0257-discrepancies.png" width="100%" /></object>
-
-<p>The blue labelled countries are non-members of the V20 with an MVI of above 65. The red labelled countries are members of the V20 with an MVI below 50 (by construction, 50 is the average MVI score, so below 50 means below average). The GDP per capita, in purchasing power parity (PPP) terms in 2017 international dollars, is just for contextual information; it isn’t used for determining which countries are labelled or not.</p>
-
-<p>So clearly the countries that have self-identified as ‘vulnerable’ to climate change are not the same as the set you would choose based on the new Multidimensional Vulnerability Index with its broader concept of vulnerability. I’m not going to say which is right and which wrong, or whether both are right in their own way; just pointing out the fact.</p>
-
-<p>That’s really all for today.</p>
-
-<p>Here’s the R code that does this analysis. You can’t just copy it and run it in a fresh R session however, contrary to my usual practice; you need to have run the code for the last post’s analysis first, or be running this in a clone of my whole <a href="https://github.com/ellisp/blog-source">blog source repository</a>.</p>
-
-<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="c1"># This is a comparison of membership of the V20 with the MVI and GDP per capita</span><span class="w">
-
-</span><span class="c1">#------------Data prep-----------</span><span class="w">
-</span><span class="n">library</span><span class="p">(</span><span class="n">WDI</span><span class="p">)</span><span class="w">
-</span><span class="n">library</span><span class="p">(</span><span class="n">kableExtra</span><span class="p">)</span><span class="w">
-</span><span class="n">library</span><span class="p">(</span><span class="n">clipr</span><span class="p">)</span><span class="w">
-
-</span><span class="c1"># run the script from the previous blog, to load in the MVI data in particular,</span><span class="w">
-</span><span class="c1"># and to load in all the standard R packages (tidyverse in particular)</span><span class="w">
-</span><span class="n">source</span><span class="p">(</span><span class="s2">"0255-mvi-pacific.R"</span><span class="p">)</span><span class="w">
-
-</span><span class="c1"># get the world Banks' GDP data</span><span class="w">
-
-</span><span class="c1"># "GDP per capita, PPP (constant 2017 international $)":</span><span class="w">
-</span><span class="n">gdp_ppp_pc</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">WDI</span><span class="p">(</span><span class="n">indicator</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"NY.GDP.PCAP.PP.KD"</span><span class="p">,</span><span class="w"> </span><span class="n">start</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">2000</span><span class="p">)</span><span class="w"> </span><span class="o">|></span><span class="w">
- </span><span class="n">drop_na</span><span class="p">()</span><span class="w"> </span><span class="o">|></span><span class="w">
- </span><span class="n">group_by</span><span class="p">(</span><span class="n">iso3c</span><span class="p">)</span><span class="w"> </span><span class="o">|></span><span class="w">
- </span><span class="c1"># just get the latest year for each country:</span><span class="w">
- </span><span class="n">arrange</span><span class="p">(</span><span class="n">desc</span><span class="p">(</span><span class="n">year</span><span class="p">))</span><span class="w"> </span><span class="o">|></span><span class="w">
- </span><span class="n">slice</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="n">ungroup</span><span class="p">()</span><span class="w"> </span><span class="o">|></span><span class="w">
- </span><span class="n">select</span><span class="p">(</span><span class="n">iso3c</span><span class="p">,</span><span class="w">
- </span><span class="n">gdp_year</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">year</span><span class="p">,</span><span class="w">
- </span><span class="n">gdp_pc</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">NY.GDP.PCAP.PP.KD</span><span class="p">)</span><span class="w">
-
-</span><span class="c1"># List of members of the V20 taken from</span><span class="w">
-</span><span class="c1"># https://www.v-20.org/v20-ministerial-dialogue-xi-communique#_ftnref5</span><span class="w">
-</span><span class="n">v20</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="s2">"Afghanistan"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Bangladesh"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Barbados"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Benin"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Bhutan"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Burkina Faso"</span><span class="p">,</span><span class="w">
- </span><span class="s2">"Cambodia"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Chad"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Colombia"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Comoros"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Costa Rica"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Côte D'Ivoire"</span><span class="p">,</span><span class="w">
- </span><span class="s2">"Democratic Republic of the Congo"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Dominica"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Dominican Republic"</span><span class="p">,</span><span class="w">
- </span><span class="s2">"Eswatini"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Ethiopia"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Fiji"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Gambia"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Ghana"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Grenada"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Guatemala"</span><span class="p">,</span><span class="w">
- </span><span class="s2">"Guinea"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Guyana"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Haiti"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Honduras"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Jordan"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Kenya"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Kiribati"</span><span class="p">,</span><span class="w">
- </span><span class="s2">"Kyrgyzstan"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Lebanon"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Liberia"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Madagascar"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Malawi"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Maldives"</span><span class="p">,</span><span class="w">
- </span><span class="s2">"Marshall Islands"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Mongolia"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Morocco"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Mozambique"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Namibia"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Nepal"</span><span class="p">,</span><span class="w">
- </span><span class="s2">"Nicaragua"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Niger"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Pakistan"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Palau"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Palestine**"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Papua New Guinea"</span><span class="p">,</span><span class="w">
- </span><span class="s2">"Paraguay"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Philippines"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Rwanda"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Saint Lucia"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Samoa"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Senegal"</span><span class="p">,</span><span class="w">
- </span><span class="s2">"Sierra Leone"</span><span class="p">,</span><span class="w"> </span><span class="s2">"South Sudan"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Sri Lanka"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Sudan"</span><span class="p">,</span><span class="w"> </span><span class="s2">"United Republic of Tanzania"</span><span class="p">,</span><span class="w">
- </span><span class="s2">"Timor-Leste"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Togo"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Tonga"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Trinidad and Tobago"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Tunisia"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Tuvalu"</span><span class="p">,</span><span class="w">
- </span><span class="s2">"Uganda"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Vanuatu"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Viet Nam"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Yemen"</span><span class="p">)</span><span class="w">
-</span><span class="c1"># A few hand edits were made so country names match those in the MVI (eg</span><span class="w">
-</span><span class="c1"># D'Ivoire rather than d'Ivoire, etc)</span><span class="w">
-
-</span><span class="c1"># any non-matches? Yes, Palestine:</span><span class="w">
-</span><span class="n">v20</span><span class="p">[</span><span class="o">!</span><span class="n">v20</span><span class="w"> </span><span class="o">%in%</span><span class="w"> </span><span class="n">mvi</span><span class="o">$</span><span class="n">Country</span><span class="p">]</span><span class="w">
-</span><span class="c1"># Palestine not in the mvi.</span><span class="w">
-
-</span><span class="c1"># Mark which countries are in the V20, and join to the GDP data:</span><span class="w">
-</span><span class="n">mvi2</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">mvi</span><span class="w"> </span><span class="o">|></span><span class="w">
- </span><span class="n">mutate</span><span class="p">(</span><span class="n">type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ifelse</span><span class="p">(</span><span class="n">Country</span><span class="w"> </span><span class="o">%in%</span><span class="w"> </span><span class="n">v20</span><span class="p">,</span><span class="w"> </span><span class="s2">"Member of V20"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Not a member of V20"</span><span class="p">))</span><span class="w"> </span><span class="o">|></span><span class="w">
- </span><span class="n">left_join</span><span class="p">(</span><span class="n">gdp_ppp_pc</span><span class="p">,</span><span class="w"> </span><span class="n">by</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="s2">"ISO"</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"iso3c"</span><span class="p">))</span><span class="w">
-
-</span><span class="c1"># note there are seven countries with no GDP PPP per capita values:</span><span class="w">
-</span><span class="n">filter</span><span class="p">(</span><span class="n">mvi2</span><span class="p">,</span><span class="w"> </span><span class="nf">is.na</span><span class="p">(</span><span class="n">gdp_pc</span><span class="p">))</span><span class="w">
-
-</span><span class="c1">#===============comparisons============</span><span class="w">
-
-
-</span><span class="c1">#---------Table------------</span><span class="w">
-</span><span class="c1"># Average values by v20 membership or not:</span><span class="w">
-</span><span class="n">mvi2</span><span class="w"> </span><span class="o">|></span><span class="w">
- </span><span class="n">group_by</span><span class="p">(</span><span class="n">type</span><span class="p">)</span><span class="w"> </span><span class="o">|></span><span class="w">
- </span><span class="n">summarise</span><span class="p">(</span><span class="n">`Structural vulnerability`</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">median</span><span class="p">(</span><span class="n">svi</span><span class="p">),</span><span class="w">
- </span><span class="n">`Lack of structural resilience`</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">median</span><span class="p">(</span><span class="n">lsri</span><span class="p">),</span><span class="w">
- </span><span class="n">`Multidimensional vulnerability`</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">median</span><span class="p">(</span><span class="n">`MVI - Score`</span><span class="p">),</span><span class="w">
- </span><span class="n">`GDP per capita, PPP`</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dollar</span><span class="p">(</span><span class="n">median</span><span class="p">(</span><span class="n">gdp_pc</span><span class="p">,</span><span class="w"> </span><span class="n">na.rm</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">TRUE</span><span class="p">),</span><span class="w"> </span><span class="n">accuracy</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">100</span><span class="p">))</span><span class="w"> </span><span class="o">|></span><span class="w">
- </span><span class="n">rename</span><span class="p">(</span><span class="n">` `</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">type</span><span class="p">)</span><span class="w"> </span><span class="o">|></span><span class="w">
- </span><span class="n">kable</span><span class="p">(</span><span class="n">digits</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="n">format.args</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">list</span><span class="p">(</span><span class="n">big.mark</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">","</span><span class="p">),</span><span class="w"> </span><span class="n">align</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="s2">"l"</span><span class="p">,</span><span class="w"> </span><span class="s2">"r"</span><span class="p">,</span><span class="w"> </span><span class="s2">"r"</span><span class="p">,</span><span class="w"> </span><span class="s2">"r"</span><span class="p">,</span><span class="w"> </span><span class="s2">"r"</span><span class="p">))</span><span class="w"> </span><span class="o">|></span><span class="w">
- </span><span class="n">kable_styling</span><span class="p">()</span><span class="w"> </span><span class="o">|></span><span class="w">
- </span><span class="n">write_clip</span><span class="p">()</span><span class="w">
-
-</span><span class="c1"># V20 members are very slightly more vulnerable, and notably poorer,</span><span class="w">
-</span><span class="c1"># than non-members</span><span class="w">
-
-
-</span><span class="c1">#-------------Plot-------------------</span><span class="w">
-</span><span class="n">pal</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="s2">"Member of V20"</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"darkred"</span><span class="p">,</span><span class="s2">"Not a member of V20"</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"darkblue"</span><span class="p">)</span><span class="w">
-
-</span><span class="n">p3</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">mvi2</span><span class="w"> </span><span class="o">|></span><span class="w">
- </span><span class="n">ggplot</span><span class="p">(</span><span class="n">aes</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">gdp_pc</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">`MVI - Score`</span><span class="p">,</span><span class="w"> </span><span class="n">colour</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">type</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
- </span><span class="n">geom_point</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w">
- </span><span class="n">geom_text_repel</span><span class="p">(</span><span class="n">data</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">filter</span><span class="p">(</span><span class="n">mvi2</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">`MVI - Score`</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="m">50</span><span class="w"> </span><span class="o">&</span><span class="w"> </span><span class="n">type</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">"Member of V20"</span><span class="p">)</span><span class="o">|</span><span class="w">
- </span><span class="p">(</span><span class="n">`MVI - Score`</span><span class="w"> </span><span class="o">></span><span class="w"> </span><span class="m">60</span><span class="w"> </span><span class="o">&</span><span class="w"> </span><span class="n">type</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="s2">"Member of V20"</span><span class="p">)),</span><span class="w">
- </span><span class="n">aes</span><span class="p">(</span><span class="n">label</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Country</span><span class="p">),</span><span class="w"> </span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">2.8</span><span class="p">,</span><span class="w"> </span><span class="n">seed</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">123</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
- </span><span class="n">annotate</span><span class="p">(</span><span class="s2">"label"</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="m">800</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="m">37</span><span class="p">,</span><span class="w"> </span><span class="n">colour</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">pal</span><span class="p">[</span><span class="m">1</span><span class="p">],</span><span class="w"> </span><span class="n">fontface</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"italic"</span><span class="p">,</span><span class="w">
- </span><span class="n">label.size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">0</span><span class="p">,</span><span class="w"> </span><span class="n">fill</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"grey90"</span><span class="p">,</span><span class="w"> </span><span class="n">hjust</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">0</span><span class="p">,</span><span class="w">
- </span><span class="n">label</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Member of V20 but lower than average vulnerability according to MVI"</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
- </span><span class="n">annotate</span><span class="p">(</span><span class="s2">"label"</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="m">800</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="m">73</span><span class="p">,</span><span class="w"> </span><span class="n">colour</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">pal</span><span class="p">[</span><span class="m">2</span><span class="p">],</span><span class="w"> </span><span class="n">fontface</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"italic"</span><span class="p">,</span><span class="w">
- </span><span class="n">label.size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">0</span><span class="p">,</span><span class="w"> </span><span class="n">fill</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"grey90"</span><span class="p">,</span><span class="w"> </span><span class="n">hjust</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">0</span><span class="p">,</span><span class="w">
- </span><span class="n">label</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Not a member of V20 but high vulnerability according to MVI"</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
- </span><span class="n">scale_x_log10</span><span class="p">(</span><span class="n">label</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dollar</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
- </span><span class="n">scale_colour_manual</span><span class="p">(</span><span class="n">values</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">pal</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
- </span><span class="n">labs</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"GDP per capita, PPP, 2017 prices"</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="s2">"Multidimensional Vulnerability Index"</span><span class="p">,</span><span class="w">
- </span><span class="n">colour</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">""</span><span class="p">,</span><span class="w">
- </span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Membership of the 'V20' group of vulnerable coutries"</span><span class="p">,</span><span class="w">
- </span><span class="n">subtitle</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Compared to scores on the UN's Multidimensional Vulnerability Index (MVI)"</span><span class="p">,</span><span class="w">
- </span><span class="n">caption</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Source: UN https://www.un.org/ohrlls/mvi (MVI), World Bank World Development Indicators (GDP), analysis by freerangestats.info
-Palestine is a member of V20 but does not have a MVI. Seven countries have an MVI but are missing GDP data."</span><span class="p">)</span><span class="w">
-
-</span><span class="n">print</span><span class="p">(</span><span class="n">p3</span><span class="p">)</span></code></pre></figure>
-
-
- Tue, 17 Oct 2023 00:00:00 +1100
- https://freerangestats.info/blog/2023/10/17/mvi-and-v20
- https://freerangestats.info/blog/2023/10/17/mvi-and-v20
-
-
diff --git a/feed.xml b/feed.xml
index e24f60d7c..67eebe3c6 100644
--- a/feed.xml
+++ b/feed.xml
@@ -6,6 +6,22 @@
https://freerangestats.info
+
+ Prime numbers as sums of three squares.
+
+
+
+ I explore the number of ways to make a prime number as the sum of squares of three positive integers.
+
+
+ Sat, 21 Sep 2024 00:00:00 +1100
+ https://freerangestats.info/blog/2024/09/21/primes-squares
+ https://freerangestats.info/blog/2024/09/21/primes-squares
+
+
+
+
+
Stepwise selection of variables in regression is Evil.
@@ -148,22 +164,6 @@
-
-
-
- The 'V20' group of vulnerable countries and the MVI
-
-
-
- I compare the GDP per capita and scores on the UN Multidimensional Vulnerability Index (MVI) of the 68 economies in the 'V20' group with other countries that aren't part of the V20.
-
-
- Tue, 17 Oct 2023 00:00:00 +1100
- https://freerangestats.info/blog/2023/10/17/mvi-and-v20
- https://freerangestats.info/blog/2023/10/17/mvi-and-v20
-
-
-
diff --git a/img/0280-primes-squares-k100.png b/img/0280-primes-squares-k100.png
new file mode 100644
index 000000000..51187d0c4
Binary files /dev/null and b/img/0280-primes-squares-k100.png differ
diff --git a/img/0280-primes-squares-k100.svg b/img/0280-primes-squares-k100.svg
new file mode 100644
index 000000000..723587e52
--- /dev/null
+++ b/img/0280-primes-squares-k100.svg
@@ -0,0 +1,1314 @@
+
+
diff --git a/img/0280-primes-squares-k30.png b/img/0280-primes-squares-k30.png
new file mode 100644
index 000000000..b73350c3e
Binary files /dev/null and b/img/0280-primes-squares-k30.png differ
diff --git a/img/0280-primes-squares-k30.svg b/img/0280-primes-squares-k30.svg
new file mode 100644
index 000000000..b50426bc2
--- /dev/null
+++ b/img/0280-primes-squares-k30.svg
@@ -0,0 +1,250 @@
+
+
diff --git a/img/0280-primes-squares-k300.png b/img/0280-primes-squares-k300.png
new file mode 100644
index 000000000..c932620bf
Binary files /dev/null and b/img/0280-primes-squares-k300.png differ
diff --git a/img/0280-primes-squares-k300.svg b/img/0280-primes-squares-k300.svg
new file mode 100644
index 000000000..4211bcab3
--- /dev/null
+++ b/img/0280-primes-squares-k300.svg
@@ -0,0 +1,8788 @@
+
+
diff --git a/index.html b/index.html
index 5383283e2..ba1451151 100644
--- a/index.html
+++ b/index.html
@@ -113,7 +113,7 @@
I compare the GDP per capita and scores on the UN Multidimensional Vulnerability Index (MVI) of the 68 economies in the 'V20' group with other countries that aren't part of the V20.