Description Usage Arguments Value Author(s) See Also Examples
Obtain gradients of the Z variables in non-parametric Smooth Coefficient Kernel Regression models by numeric finite-difference differenciation.
| 1 |    npscoefGrad( x, eps = 1e-3, ... )
 | 
| x | an object of class  | 
| eps | the step size for the numeric finite-difference differentiation. | 
| ... | further arguments are currently ignored. | 
a three-dimensional array that contains the gradients of the (smooth) coefficients and the predicted values with respect to the Z variables. The first dimension of the array corresponds to the observations. The second dimension of the array corresponds to the (smooth) intercept, the (smooth) coefficients of the X variables, and the predicted values of the dependent (Y) variable (in that order). The third dimension of the array corresponds to the Z variables.
Arne Henningsen (with significant help from Jeff Racine who provided the idea of obtaining these gradients)
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |    n <- 250
   x1 <- runif(n)
   x2 <- rnorm(n)
   z1 <- runif(n)
   z2 <- runif(n, min=-2, max=2)
   y <- sin( 5 * z1 ) + x1 * exp( z2 ) + x2 * ( z1^2 + z2 ) + rnorm( n, sd = 0.2 )
   model <- npscoef( y ~ x1 + x2 | z1 + z2, beta = TRUE )
   
   print( model )
   summary( model )
   round( coef( model ), 3 )
   
   grad <- npscoefGrad( model )
   round( grad, 3 )
   
   all.equal( grad[ , 1, ] + grad[ , 2, ] * x1 + grad[ , 3, ] * x2, grad[ , 4, ] )
   
   ## Not run: 
      for( j in 1:2 ) {
         for( i in 1:3 ) {
            plot( zData[,j], grad[ , i, j ],
               main = paste( "d b", i-1, " / d z", j, sep = "" ) )
            points(  zData[,j], gradTrue[ , i, j ], col = "red" )
            cat( "Press <enter>\n")
            readLines( n = 1 )
         }
      }
   
## End(Not run)
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.