# This is a function that calls a Fortran function that runs a local # linear regression. It takes a dependent variable vector "y" and # a matrix of regressors X and additional points X2 and COMPUTES FITTED VALUES # AND RESIDUALS ONLY AT THE ADDITIONAL X2 POINTS. # according to Fan's algorithm--equations 2.2 - 2.4 # This returns resid and mhat--the residuals and fitted values at X2 points. # n2 is the length of X2 # h refers to the bandwith parameter (scalar) # Need to run linker.static to link to Fortran before running any program # that calls this function. locreg4 <- function(X,y,X2,h){ X <- as.vector(X) X2 <- as.vector(X2) n <- length(X) n2 <- length(X2) mhat <- vector("numeric",n2) denom2 <- vector("numeric",n2) storage.mode(X) <- "double" storage.mode(y) <- "double" storage.mode(X2) <- "double" storage.mode(mhat) <- "double" results <- .Fortran("locreg4", X, y, as.integer(n),X2, as.integer(n2), as.double(h), mhat=mhat,denom2=denom2) # set the estimates for which denominator equalled zero equal to NA cutoff <- (1/(n*n)) ind1 <- abs(results$denom2)