Announcement

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

  • Out-of-sample predictions for non-parametric regression

    I'm trying to use a nonparametric regression on some observations to make predictions for other observations, but the "predict" command doesn't make give a value for observations not included in the initial regression. Using the below example, you can see that the prediction ("preval") is left blank for the first observation, because the first observation wasn't included in the regression. Is there some way I can make a prediction for these observations?

    Code:
    clear
    sysuse auto
    npregress kernel price length weight if _n!=1
    predict preval
    list in 1/3

  • #2
    Hi Jeff
    Unfortunately, I dont think there is a way to use predict straight forward to make the predictions with npregress, however you can do it manually, with a bit of work:
    Code:
    sysuse auto, clear
    gen d=runiform()<.5
    npregress kernel price length weight  if d==1, kernel(gaussian) noderiv
    matrix b=e(bwidth)
    
    gen ph=.
    forvalues i  = 1/74 {
        
        capture drop aux1 aux2 ww
        gen aux1 = length-length[`i']
        gen aux2 = weight-weight[`i']
        gen ww=normalden(aux1/b[1,1])*normalden(aux2/b[1,2])
        reg price c.aux1 c.aux2 if d==1 [w=ww]
        replace ph = _b[_cons] in `i'
    }
    HTH

    Comment


    • #3
      Originally posted by FernandoRios View Post
      Hi Jeff
      Unfortunately, I dont think there is a way to use predict straight forward to make the predictions with npregress, however you can do it manually, with a bit of work:
      Code:
      sysuse auto, clear
      gen d=runiform()<.5
      npregress kernel price length weight if d==1, kernel(gaussian) noderiv
      matrix b=e(bwidth)
      
      gen ph=.
      forvalues i = 1/74 {
      
      capture drop aux1 aux2 ww
      gen aux1 = length-length[`i']
      gen aux2 = weight-weight[`i']
      gen ww=normalden(aux1/b[1,1])*normalden(aux2/b[1,2])
      reg price c.aux1 c.aux2 if d==1 [w=ww]
      replace ph = _b[_cons] in `i'
      }
      HTH
      Hi Fernando, thank you so much for the code. Just one more question: does your code apply to situations when some of the independent variables (in npregress) are categorical?

      Comment


      • #4
        It should,
        One needs only to adjust the kernel weights for discrete variables.
        Fernando

        Comment

        Working...
        X