[Rd] bug found in predict.locfit in locfit package ( PR#8057)

Liaw, Andy andy_liaw at merck.com
Wed Oct 5 22:17:31 CEST 2005


Apologies for the coming to this late...

1. By now I hope Somkiat has realized that R-bugs is not the place to
report problems in contributed packages.  Please direct such reports to
the package maintainer.

2. This is really user error.  predict() expect the newdata to be a data
frame containing variables with the same names as those used in the
fitting process.  E.g., you fitted the model with objects named `y',
`x1' and `x2'.  predict() will try to look for objects by those names,
first in newdata, then in the global environment.  Since you supplied
newdata as data.frame(x1new, x2new), predict() cannot find x1 and x2
there, so it ends up using the copy you have in the global environment.
You need to use newdata=data.frame(x1=x1new, x2=x2new).

FYI, thanks to help from Uwe and Brian, I now have Prof. Loader's new
version of locfit passing R CMD check (using R-2.2.0 beta).  It will be
uploaded to CRAN when Prof. Loader is OK with what I have.

Andy



> From: apipatta at colorado.edu
> 
> Full_Name: Somkiat Apipattanavis
> Version: 2.1.1
> OS: Windows
> Submission from: (NULL) (128.138.44.123)
> 
> 
> Bug found in predict.locfit for density estimation
> 
> # Example of bug found in prdict.locfit (Locfit)
> library('locfit')
> 
> # generate data
> y =c(4281,2497,4346,5588,5593,3474,4291,2542,5195,4056,
>      3114,2864,4904,7625,3377,4001,4999,7191,8062,5668)
> x1=c( 0.258729, 1.460156, 0.192323, 0.067062,-0.304291,
>      -0.420917, 0.214729, 0.239979,-0.421938,-0.571229,
>       1.310990, 2.043032, 0.449906,-0.951917,-0.077104,
>      -0.356833,-0.286042, 0.065750, 0.159677,-0.075792)
> x2=c(-0.3050, 1.0125, 0.2050, 0.1025, 0.9550,
>       0.6975, 1.5550, 0.0225, 0.2575, 0.3725,
>       2.0075, 2.1275, 0.7200, 0.2950, 0.2875,
>      -0.2800,-0.6050, 0.2125,-0.5525,-1.7850)
> 
> ndat=length(y)
> ybk=y
> x1bk=x1
> x2bk=x2
> ######## Joint probability function of y, x1 and x2
> # fit joint probability function
> fityxv=locfit(~y+x1+x2,alpha=1,deg=1)
> fyxv=predict(fityxv,where="data")
> 
> ######## Marginal distribution of gxv
> # fit marginal distribution of y
> fitxv=locfit(~x1+x2,alpha=0.5,deg=1)
> gxv=predict(fitxv,where="data")
> 
> ######## Prediction of fyxv and gxv
> # new data
> vx1=0.2
> vx2=0.7
> x1new=rep(vx1,ndat)
> x2new=rep(vx2,ndat)
> ynew=y
> 
> # marginal distribution of gxv for new data
> newdata=data.frame(x1new,x2new)
> gxvnew=predict(fitxv,newdata)   #bug!!! gave the same values as gxv
> 
> # This bug can be avoid by setting new values into old variables
> # then, we will get the new predicted values
> # for example
> x1=x1new
> x2=x2new
> gxvnew2=predict(fitxv,where="data")
> 
> # predict joint probability function of fyxv for new data
> newdat2=data.frame(ynew,x1new,x2new)
> fyxvnew=predict(fityxv,newdat2) #bug! same as 2D density
> 
> # but setting new values into old variables DOES NOT
> # work for solving this kind of problem for 3D density
> # for example
> x1=x1bk
> x2=x2bk
> fyxvnew2=predict(fityxv,where="data")
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> 
>



More information about the R-devel mailing list