[R] locpoly is returning NaN if bandwidth is small

Xu Wang xuwang762 at gmail.com
Tue Mar 18 03:16:44 CET 2014


The following call to locpoly gives a 'NaN' on one computer and a
number on a different computer:

library(KernSmooth)

x <- c(5.84155992364115, 1.55292112974119, 0.0349665318792623,
3.93053647398094, 3.42790577684633, 2.9715553006801,
0.837108410045353, 2.872476865277, 3.89232548092257,
0.206399650539628)

y <- c(0.141415317472329, 1.34799648955049, 0.0297566221758204,
-0.966736679061812, 0.246306732122746, 0.557982376254723,
0.740542828791083, 0.162336127802977, -0.428804158514744,
0.691280978689863)

locpoly(x, y, bandwidth = 0.4821232, gridsize = 12, degree = 1)[['y']]

[1]  0.3030137  0.6456624  0.9530586  1.1121106  0.8120947  0.4441603
[7]  0.1425592 -0.3600028 -0.7840411 -1.0517612 -1.2690134        NaN

and on a different computer, I get the same but -0.7270521 instead of NaN.

on both computers, I have:

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)

My unfounded guess is that this has to do with floating point
calculation because the weights on the local regression are so small
because the normal density so far outside of the bandwidth is going to
be small.

I understand that using such a small bandwidth in this situation is a
horrible idea. My goal is to understand how locpoly can behave
differently on different computers and how I can solve that.

Thank you and kind regards,

Xu



More information about the R-help mailing list