Announcement

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

  • Nonparametric regression: lpoly vs npgress

    Both commands perform local-linear kernel estimation and allow for visulizing estimates, but what are their main differences?

  • #2
    Hi David
    There are at least 3 differences:
    1. Lpoly estimates the relationship using local polynomials. You can choose if you want local constant (degree(0)) local linear, local quadratic, etc.
    NPregress only does local constant or local linear
    2. lpoly can estimate the relationships only between 2 variables. One dependent and one independent variable.
    npregress allows you to have multiple independent variables.
    3. lpoly uses a "plug in" bandwidth estimator. Whereas npregress uses Cross validation to obtain the optimal BW.
    HTH
    Fernando

    Comment


    • #3
      Fernando Rios makes the main points well.

      I want to add that I found lpoly disappointing in its defaults, for the perhaps personal reason that the results were under-smoothed for my data examples and my tastes. I played a bit with this and worked out some different defaults and coded them up in localp (SSC).

      https://www.statalist.org/forums/for...ial-regression

      I just remembered a small bug in localp so here is fixed code, which will be posted on SSC in due course.

      Code:
      *! 1.0.3 NJC 13 November 2020 
      *! 1.0.2 NJC 11 April 2015
      * 1.0.1 NJC 9 April 2015
      * 1.0.0 NJC 19 March 2015
      program localp 
          version 10 
          syntax varlist(min=2 max=2 numeric) [fweight aweight] [if] [in] ///
          [, Kernel(str) BWidth(str) DEGree(int 1) AT(str) Msymbol(str)   ///
          GENerate(passthru) * ] 
      
          tokenize "`varlist'"
          args yvar xvar 
      
          if "`kernel'" == "" local kernel "biweight"
          
          if "`bwidth'" == "" { 
              su `xvar' `if' `in', meanonly
              local bwidth = 0.2 * (r(max) - r(min))
              local factor = 10^floor(log10(`bwidth')) 
              local bwidth = floor(`bwidth' / `factor') * `factor' 
          } 
      
          if "`at'" == "" local at `xvar' 
      
          quietly { 
              tempvar ypred
      
              lpoly `yvar' `xvar' `if' `in' [`weight' `exp'], ///
              k(`kernel') bw(`bwidth') at(`at') deg(`degree') ///
              nograph gen(`ypred') 
      
              reg `yvar' `ypred' [`weight' `exp'] `if' `in' 
              local rsq  : di %04.3f `e(r2)'
              local rmse : di %5.4g `e(rmse)' 
              if c(stata_version) < 11 {
                  local text "R-sq = `rsq', RMSE = `rmse'" 
              }
              else local text "{it:R}{sup:2} = `rsq', RMSE = `rmse'"
          } 
      
          if "`msymbol'" == "" local msymbol "Oh" 
      
          local word : word `= `degree' + 1' of ///
          mean linear quadratic cubic quartic quintic 
          if "`word'" != "" local title "local `word' smooth" 
          else local title "local polynomial smooth" 
      
          lpoly `yvar' `xvar' `if' `in' [`weight' `exp'],           ///
          k(`kernel') bw(`bwidth') at(`at') deg(`degree')           ///
          msymbol(`msymbol') `generate'                             ///
          subtitle("`text'", size(medsmall) place(w))               ///
          title(`title', size(medium) place(w)) yla(, ang(h)) `options' 
      end
      Code:
      
      
      Last edited by Nick Cox; 13 Nov 2020, 04:52.

      Comment


      • #4
        Hi Nick Cox ,

        is there a way to use clustered standard errors in localp / lpolyci ?
        I want to smooth data over time but have multiple observations per individual (at different times).
        Thanks!

        Michael

        Comment


        • #5
          localp doesn't add anything to what lpoly provides in that direction. I'd be surprised to find any such support there, but am not confident that there is none.

          Comment

          Working...
          X