{"id":142,"date":"2014-07-10T16:32:56","date_gmt":"2014-07-10T14:32:56","guid":{"rendered":"http:\/\/candrea.ch\/blog\/?p=142"},"modified":"2014-07-23T13:04:35","modified_gmt":"2014-07-23T11:04:35","slug":"robust-standardized-beta-coefficients","status":"publish","type":"post","link":"https:\/\/candrea.ch\/blog\/robust-standardized-beta-coefficients\/","title":{"rendered":"Robust Standardized Beta Coefficients"},"content":{"rendered":"<p>Standardized beta coefficients are definded as<\/p>\n<p>beta = b * sd_x\/sd_y<\/p>\n<p>where b are the coefficients from OLS linear regression, and sd_x and sd_y are standard deviations of each x variable and of y.<\/p>\n<p>In the case where you performe a robust linear regression, sd_x and sd_y seems not be very meanigfull anymore, because variances and hence standard deviations are not robust. The R package &#8220;robust&#8221; provides the function covRob() to compute a robust covariance estimator.<\/p>\n<p>I have written the following function to compute standardized beta coefficients for a robust linear regression. Setting the parameter classic=TRUE gives you the classic estimation of the beta coefficients. For very bad data, the covRob() function cannot compute the covariance due singularities. In\u00a0this case the classical estimator is returned.<\/p>\n<pre class=\"lang:r decode:true \" title=\"Robust Standardized Beta Coefficients\">my.lmr.beta &lt;- function (object, classic = FALSE) {\r\n  if(class(object) != \"lmRob\")\r\n    stop(\"Object must be of class 'lmRob'\")\r\n  model &lt;- object$model\r\n  num &lt;- sapply(model, is.numeric)  # numeric vars only\r\n  b &lt;- object$coefficients[num][-1]  # final coefficients w\/o intercept\r\n  ## compute robust covariance\r\n  covr &lt;- NULL\r\n  try(covr &lt;- diag(covRob(model[num])$cov), silent = TRUE)\r\n  if(is.null(covr) &amp; classic == FALSE)\r\n    warning(\"covRob() coud not be computed, instead covClassic() was applied.\")\r\n  ## compute classic covariance if robust failed\r\n  if(is.null(covr) | classic == TRUE)\r\n    covr &lt;- diag(covClassic(model[num])$cov)\r\n  sx &lt;- sqrt(covr[-1])  # standard deviation of x's\r\n  sy &lt;- sqrt(covr[1])  # standard deviation of y\r\n  beta &lt;- b * sx\/sy\r\n  return(beta)\r\n}<\/pre>\n<p><strong>\u00a0UPDATE &#8212; 2014-07-23<\/p>\n<p><\/strong>Computing standard deviations for factors makes sense, because variance\u00a0is definded for the binomial distribution. \u00a0So I have removed the num variable.<\/p>\n<pre class=\"lang:r decode:true \">my.lmr.beta &lt;- function (object, classic = FALSE) {\r\n  if(class(object) != \"lmRob\")\r\n    stop(\"Object must be of class 'lmRob'\")\r\n  model &lt;- object$model\r\n  #num &lt;- sapply(model, is.numeric)  # numeric vars only\r\n  b &lt;- object$coefficients[-1]  # final coefficients w\/o intercept\r\n  ## compute robust covariance\r\n  covr &lt;- NULL\r\n  try(covr &lt;- diag(covRob(model)$cov), silent = TRUE)\r\n  if(is.null(covr) &amp; classic == FALSE)\r\n    warning(\"covRob() coud not be computed, instead covClassic() was applied.\")\r\n  ## compute classic covariance if robust failed\r\n  if(is.null(covr) | classic == TRUE)\r\n    covr &lt;- diag(covClassic(sapply(model, as.numeric))$cov)\r\n  sx &lt;- sqrt(covr[-1])  # standard deviation of x's\r\n  sy &lt;- sqrt(covr[1])  # standard deviation of y\r\n  beta &lt;- b * sx\/sy\r\n  return(beta)\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Standardized beta coefficients are definded as beta = b * sd_x\/sd_y where b are the coefficients from OLS linear regression, and sd_x and sd_y are standard deviations of each x variable and of y. In the case where you performe a robust linear regression, sd_x and sd_y seems not be very meanigfull anymore, because variances &hellip; <a href=\"https:\/\/candrea.ch\/blog\/robust-standardized-beta-coefficients\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Robust Standardized Beta Coefficients<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-142","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/posts\/142"}],"collection":[{"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/comments?post=142"}],"version-history":[{"count":3,"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/posts\/142\/revisions"}],"predecessor-version":[{"id":146,"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/posts\/142\/revisions\/146"}],"wp:attachment":[{"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/media?parent=142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/categories?post=142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/candrea.ch\/blog\/wp-json\/wp\/v2\/tags?post=142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}