[Rd] bug found in predict.locfit in locfit package (PR#8057)
apipatta@colorado.edu
apipatta at colorado.edu
Mon Aug 8 21:27:34 CEST 2005
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")
More information about the R-devel
mailing list