{
  "id": 1369,
  "title": "Some R code",
  "url": "/competitions/benchmark-bond-trade-price-challenge/discussion/1369",
  "author_name": "",
  "post_date": "2012-02-16T09:52:14.370Z",
  "votes": null,
  "comment_count": 2,
  "views": 3010,
  "content": "<p>Hi all,</p>\r\n<p>it's basic, but anyway. Just to make sure, that I got the error measure right, here is my R code for the WMAE:</p>\r\n<pre>wmae &lt;- function(pred, actu, weig) {\r\n\t\r\n\tsum(abs(pred - actu) * weig) / length(pred)\r\n\t\r\n}\r\n</pre>\r\n<p>So calling it for some rows on the training set, I receive the following result:</p>\r\n<pre>wmae(train$trade_price_last1, train$trade_price, train$weight)\r\n[1] 1.099453\r\n</pre>\r\n<p>Can someone please verify this as being the correct way to calculate the error?</p>\r\n<p>Thanks in advance.</p>",
  "messages": [
    {
      "id": "8593",
      "postDate": "02/16/2012 09:52:14",
      "content": "<p>Hi all,</p>\r\n<p>it's basic, but anyway. Just to make sure, that I got the error measure right, here is my R code for the WMAE:</p>\r\n<pre>wmae &lt;- function(pred, actu, weig) {\r\n\t\r\n\tsum(abs(pred - actu) * weig) / length(pred)\r\n\t\r\n}\r\n</pre>\r\n<p>So calling it for some rows on the training set, I receive the following result:</p>\r\n<pre>wmae(train$trade_price_last1, train$trade_price, train$weight)\r\n[1] 1.099453\r\n</pre>\r\n<p>Can someone please verify this as being the correct way to calculate the error?</p>\r\n<p>Thanks in advance.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "8594",
      "postDate": "02/16/2012 10:19:46",
      "content": "<p>That's not much of a difference but there is a function weighted.mean. I use something like this</p>\r\n<p><code>weighted.mean(abs(prediction - trade_price),weight)</code></p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "8596",
      "postDate": "02/16/2012 16:34:41",
      "content": "<p>I use, </p>\r\n<p>wmae = sum(abs(prediction - actual) * weight) / sum(weight) </p>\r\n<p>I don't think there is any difference if the mean of the weights is 1, but if you are modelling subsets of the data, the mean weight for the subset might not be 1, and it might be better to renormalize by dividing by sum(weight).</p>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 8594,
      "author_name": "paweljankiewicz",
      "author_url": "",
      "post_date": "02/16/2012 10:19:46",
      "content": "<p>That's not much of a difference but there is a function weighted.mean. I use something like this</p>\r\n<p><code>weighted.mean(abs(prediction - trade_price),weight)</code></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 8596,
      "author_name": "roseyland",
      "author_url": "",
      "post_date": "02/16/2012 16:34:41",
      "content": "<p>I use, </p>\r\n<p>wmae = sum(abs(prediction - actual) * weight) / sum(weight) </p>\r\n<p>I don't think there is any difference if the mean of the weights is 1, but if you are modelling subsets of the data, the mean weight for the subset might not be 1, and it might be better to renormalize by dividing by sum(weight).</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "8593": "",
    "8594": "",
    "8596": ""
  },
  "source": "meta"
}