<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Incorrect Values for Standard Deviation on Market Page]]></title><description><![CDATA[<p>THe values shown on the market page when you hover over a comodity is the average price and standard deviaton over the last 14 days . But It seems like the standard deviation calculation is absolutely wrong. The standard deviation is just a weighted average over the 14 days which is the wrong way to calculate standard deviaton over a series.</p>
<p><strong>Here is the proof</strong></p>
<p><img src="/forum/assets/uploads/files/1633932204871-f14bb65c-b38c-4bd0-9d39-5c8e86c46336-image-resized.png" alt="0_1633932204191_f14bb65c-b38c-4bd0-9d39-5c8e86c46336-image.png" class="img-responsive img-markdown" /></p>
<p>Here is the function whose output is shown above</p>
<pre><code class="language-js">const misc = (resourceType?: ResourceConstant) =&gt; {
    const data = Game.market.getHistory().filter(o =&gt; o.resourceType === resourceType);
    const totalVolume = data.reduce((sum, d) =&gt; sum + d.volume, 0);
    const avg = data.map(d =&gt; d.avgPrice * d.volume).reduce((sum, x) =&gt; sum + x, 0) / totalVolume;
    const wrongStd = data.map(d =&gt; d.stddevPrice * d.volume).reduce((sum, x) =&gt; sum + x, 0) / totalVolume;
    // This is the correct way to calculate standard deviation : https://stats.stackexchange.com/a/442050/143357
    const correctStd = Math.sqrt(data.map(d =&gt; (d.stddevPrice ** 2) * (d.volume - 1) + d.volume * ((avg - d.avgPrice) ** 2)).reduce((sum, x) =&gt; sum + x, 0) / (totalVolume - 1));
    console.log(`${avg.toFixed(3)} ± ${correctStd.toFixed(3)} | Wrong STD = ${wrongStd.toFixed(3)}`);
};
</code></pre>
<p>I believe this is a bug. You can take a look at this stackexchange question on the correct formulas to calculate standard deviation : <a href="https://stats.stackexchange.com/a/442050/143357" rel="nofollow">https://stats.stackexchange.com/a/442050/143357</a></p>
]]></description><link>http://screeps.com/forum/topic/3209/incorrect-values-for-standard-deviation-on-market-page</link><generator>RSS for Node</generator><lastBuildDate>Tue, 11 Aug 2026 08:24:52 GMT</lastBuildDate><atom:link href="http://screeps.com/forum/topic/3209.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 11 Oct 2021 06:04:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Incorrect Values for Standard Deviation on Market Page on Mon, 11 Oct 2021 06:04:41 GMT]]></title><description><![CDATA[<p>THe values shown on the market page when you hover over a comodity is the average price and standard deviaton over the last 14 days . But It seems like the standard deviation calculation is absolutely wrong. The standard deviation is just a weighted average over the 14 days which is the wrong way to calculate standard deviaton over a series.</p>
<p><strong>Here is the proof</strong></p>
<p><img src="/forum/assets/uploads/files/1633932204871-f14bb65c-b38c-4bd0-9d39-5c8e86c46336-image-resized.png" alt="0_1633932204191_f14bb65c-b38c-4bd0-9d39-5c8e86c46336-image.png" class="img-responsive img-markdown" /></p>
<p>Here is the function whose output is shown above</p>
<pre><code class="language-js">const misc = (resourceType?: ResourceConstant) =&gt; {
    const data = Game.market.getHistory().filter(o =&gt; o.resourceType === resourceType);
    const totalVolume = data.reduce((sum, d) =&gt; sum + d.volume, 0);
    const avg = data.map(d =&gt; d.avgPrice * d.volume).reduce((sum, x) =&gt; sum + x, 0) / totalVolume;
    const wrongStd = data.map(d =&gt; d.stddevPrice * d.volume).reduce((sum, x) =&gt; sum + x, 0) / totalVolume;
    // This is the correct way to calculate standard deviation : https://stats.stackexchange.com/a/442050/143357
    const correctStd = Math.sqrt(data.map(d =&gt; (d.stddevPrice ** 2) * (d.volume - 1) + d.volume * ((avg - d.avgPrice) ** 2)).reduce((sum, x) =&gt; sum + x, 0) / (totalVolume - 1));
    console.log(`${avg.toFixed(3)} ± ${correctStd.toFixed(3)} | Wrong STD = ${wrongStd.toFixed(3)}`);
};
</code></pre>
<p>I believe this is a bug. You can take a look at this stackexchange question on the correct formulas to calculate standard deviation : <a href="https://stats.stackexchange.com/a/442050/143357" rel="nofollow">https://stats.stackexchange.com/a/442050/143357</a></p>
]]></description><link>http://screeps.com/forum/post/16525</link><guid isPermaLink="true">http://screeps.com/forum/post/16525</guid><dc:creator><![CDATA[DollarAkshay]]></dc:creator><pubDate>Mon, 11 Oct 2021 06:04:41 GMT</pubDate></item></channel></rss>