How can I minimize the sum of absolute deviations from the residuals using the function optim() with the Nelder-Mead algorithm for creating the estimation in R?

enter image description here

tlad <- function(y = "farm", x = "land", data="FarmLandArea.csv")
  dat <- read.csv(data)
  #....what is func

  • $\begingroup$ Is this a class assignment? $\endgroup$
    – Glen_b
    Apr 25 '14 at 23:25
  • 1
    $\begingroup$ Where are you stuck? What have you tried so far? $\endgroup$
    – QuantIbex
    Apr 26 '14 at 10:16
  • $\begingroup$ @QuantIbex What are the beta1 and beta2 that I should feed into optim() function? $\endgroup$
    – Mona Jalal
    May 1 '14 at 10:34
  • $\begingroup$ The parameters fed into optim are starting values for the optimization. The OLS estimates as you did are probably not a bad choice. $\endgroup$
    – QuantIbex
    May 1 '14 at 14:39

This question seems to be a self-study question so for the moment I'll just provide hints.

  1. Write a function, say sum.abs.dev, taylored for optim that computes the sum of absolute deviations for a given set of parameter values (and data). Note that the function's first argument should be the vector of parameters you're willing to minimize, that is $(\beta_0, \beta_1)$. It should return a scalar with the sum of absolute deviations (see ?optim).
  2. Use the optim function with appropriate parameters, including your sum.abs.dev function, initial values for the vector of regression parameters, the data, and the optimization method.

Please explain where you're stuck and show what you've done so far if you would like additional information.

  • $\begingroup$ My problem is that I am unsure what is the function I should feed into optim() to have beta1 and beta2 as result. Please take a look at updated question. $\endgroup$
    – Mona Jalal
    May 1 '14 at 11:17
  • $\begingroup$ The function fed into optim is the one I called sum.abs.dev in my answer. It should return the value of $Q(\beta_0, \beta_1)$ for inputs $\boldsymbol{\beta} =(\beta_0$, $\beta_1)$, $\boldsymbol{x} = (x_1, \ldots, x_n)$, and $\boldsymbol{y} = (y_1, \ldots, y_n)$. $\endgroup$
    – QuantIbex
    May 1 '14 at 14:47
  • $\begingroup$ ok now I guess it's more clear. I work on it and let you know $\endgroup$
    – Mona Jalal
    May 1 '14 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.