Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Non Linear Maximum Likelihood Estimation

    I have a nonlinear model: Y = B_0 + B_1*(x_1) + ((B_1)^2)*(x_2) + (B_0)*(B_1)*((x_3)^2) + (B_2)*(x_4)+ e.

    Using this nonlinear model I produce data using specified values fo B_0, B_1 and B_2. The error term is normally distributed and creates the random variation in my sample data.
    All x_i values (i = 1,2,3, 4) are uniformly distributed (0,20).

    I want to find the maximum likelihood estimates for B_0, B_1 and B_2.

    I have been struggling to try to figure out how to do this. I have been trying to follow Gould, Pitblado and Poi's guide but I'm having trouble writing a program for the variables that follow the normal distribution.

    I know that my likelihood function will be dependent on an indicator function and I am not sure how to incorporate this into a program that will work for all my variables.

    Any help or guidance would be much appreciated.

  • #2
    can you show exactly what have you written in your ml program?

    Comment


    • #3
      There is already an official Stata command that will work for you, and so you don't need to create your own.
      Code:
      version 15.1
      
      clear *
      
      set seed `=strreverse("1481837")'
      quietly set obs 200
      
      // All x_i values (i = 1,2,3, 4) are uniformly distributed (0,20).
      forvalues i = 1/4 {
          generate byte x`i' = runiformint(0, 20)
      }
      
      // The error term is normally distributed . . .
      generate double e = rnormal()
      
      // I produce data using specified values fo B_0, B_1 and B_2.
      local B0 2
      local B1 3
      local B2 4
      
      // I have a nonlinear model: Y = B_0 + B_1*(x_1) + ((B_1)^2)*(x_2) + (B_0)*(B_1)*((x_3)^2) + (B_2)*(x_4)+ e
      generate double y = `B0' + `B1' * x1 + `B1' * `B1' * x2 + `B0' * `B1' * x3 * x3 + `B2' * x4 + e
      
      // I want to find the maximum likelihood estimates for B_0, B_1 and B_2.
      nl (y = {B0} + {B1} * x1 + {B1} * {B1} * x2 + {B0} * {B1} * x3 * x3 + {B2} * x4), ///
          initial(B0 1 B1 1 B2 1) nolog
      
      exit
      Be sure to use halfway-decent starting values. The least-squares solution will be maximum likelihood under normality of residuals.

      If you want an actual iterative maximum likelihood command, then you still don't need to roll your own. Rather, you can use something like menl and omit any random effects.
      I know that my likelihood function will be dependent on an indicator function . . .
      I don't follow you there. I don't see any indicator variable in the model, if that's what you mean by indicator function.

      Comment

      Working...
      X