When running npregivderiv
on a very small (100 obs) provisory dataset, after 229 iterations (10-15 min. on netbook), I receive the error:
Error in if (!any(mean.loo == maxPenalty)) { :missing value, where TRUE/FALSE is necessary
Apparently for up to ~ 20 observations, it does not give an error.
What does this mean? How can I make the function run?
Here is the code I used:
install.packages('np', dependencies = TRUE)
library(np)
mop = read.csv("c:/.../sht.csv")
trim <- 0.005
v <- mop$z
eps <- mop$w
u <- -0.5*v + eps
w <- mop$x
fun1 <- function(z) { z^2 }
fun2 <- function(z) { exp(-abs(z)) }
z <- 0.2*w + v
y1 <- fun1(z) + u
y2 <- fun2(z) + u
y <- y1
phi <- fun1
ivdata <- data.frame(y,z,w,u,v)
ivdata <- ivdata[order(ivdata$z),]
rm(y,z,w,u,v)
attach(ivdata)
model.ivderiv <- npregivderiv(y=y,z=z,w=w)
ylim <-c(quantile(model.ivderiv$phi.prime,trim),
quantile(model.ivderiv$phi.prime,1-trim))
plot(z,model.ivderiv$phi.prime,
xlim=quantile(z,c(trim,1-trim)),
main="",
ylim=ylim,
xlab="Z",
ylab="Derivative",
type="l",
lwd=2)
rug(z)
## End(Not run)
And here is the full subsample dataset (100 obs.):
structure(list(y = c(855.52914, 1.1283515, 908.51758, 0.7514782,
661.73008, 1.0657453, 890.40141, 869.96992, 0.6273609, 778.90695,
1.1568432, 700.16383, 656.48211, 0.3734502, 1.0547463, 703.97711,
833.33609, 1.1071179, 952.82203, 615.92148, 375.02961, 1.2113513,
1.1327123, 904.69453, 598.49734, 798.16117, 1.1865938, 574.36656,
789.65438, 1.012672, 909.95234, 349.57699, 372.64508, 0.4520109,
878.43656, 1.2991395, 1.1184094, 678.41758, 751.22055, 480.62234,
897.70094, 800.21281, 0.5323266, 1.537357, 805.63383, 527.56363,
938.26156, 924.51289, 1.3786252, 0.5548848, 532.18199, 867.58539,
1.2738473, 614.92715, 250.03736, 387.20566, 902.57727, 0.6784175,
0.5328116, 750.59086, 923.70094, 413.46332, 1.2695937, 0.6762907,
451.50113, 513.00297, 445.88805, 0.8880168, 823.90359, 0.6558593,
474.56914, 351.70363, 1.0155759, 349.57707, 516.12414, 850.27523,
798.08602, 935.69398, 914.74375, 385.07863, 518.25098, 1.1459232,
712.15711, 992.94234, 823.53852, 620.17516, 0.5328116, 824.85336,
1.3809344, 407.81934, 926.82211, 518.50863, 901.43523, 880.83109,
701.15813, 613.79461, 830.76875, 1.0250023, 1.1362391), z = c(0.60875082,
0.10875082, 0.60875082, 0.60875082, 0.60875082, 0.20875082, 0.60875082,
0.60875082, 0.60875082, 0.60875082, 0.60875082, 0.90875082, 0.60875082,
0.30875082, 0.60875082, 0.60875082, 0.60875082, 0.6, 0.60875082,
0.60875082, 0.60875082, 0.602989, 0.60875082, 0.60875082, 0.60875082,
0.2350875082, 0.60875082, 0.60875082, 0.60875082, 0.60875082,
0.60875082, 0.60875082, 0.5543875082, 0.60875082, 0.60875082,
0.60875082, 0.60875082, 0.60875082, 0.60875082, 0.60875082, 0.60875082,
0.60875082, 0.60875082, 0.60875082, 0.60875082, 0.60875082, 0.60875082,
0.60875082, 0.60875082, 0.60875082, 0.60875082, 0.12, 0.60875082,
0.60875082, 0.60875082, 0.60875082, 0.60875082, 0.60875082, 0.60875082,
0.60875082, 0.60875082, 0.12, 0.60875082, 0.60875082, 0.60875082,
0.60875082, 0.60875082, 0.60875082, 0.60875082, 0.60875082, 0.60875082,
0.60875082, 0.60875082, 0.60875082, 0.60875082, 0.60875082, 0.60875082,
0.60875082, 0.60875082, 0.60875082, 0.60875082, 0.60875082, 0.60875082,
0.60875082, 0.60875082, 0.60875082, 0.60875082, 0.60875082, 0.60875082,
0.60875082, 0.88888, 0.60875082, 0.60875082, 0.60875082, 0.60875082,
0.60875082, 0.60875082, 0.60875082, 0.60875082), w = c(83L, 80L,
51L, 79L, 63L, 61L, 75L, 64L, 60L, 55L, 81L, 65L, 62L, 52L, 70L,
53L, 71L, 64L, 63L, 63L, 50L, 71L, 67L, 64L, 71L, 66L, 84L, 57L,
68L, 84L, 64L, 51L, 40L, 39L, 53L, 49L, 79L, 61L, 66L, 60L, 63L,
53L, 35L, 66L, 48L, 50L, 62L, 65L, 68L, 43L, 50L, 54L, 69L, 56L,
54L, 41L, 66L, 61L, 51L, 65L, 61L, 52L, 75L, 64L, 58L, 49L, 61L,
65L, 51L, 53L, 47L, 48L, 74L, 51L, 53L, 47L, 56L, 59L, 58L, 44L,
50L, 64L, 63L, 56L, 55L, 57L, 51L, 48L, 68L, 55L, 65L, 63L, 77L,
62L, 72L, 66L, 68L, 59L, 66L), x = c(74.067852, 52.955316, 56.225129,
74.879164, 74.463844, 62.743391, 62.965547, 50.187594, 66.421305,
62.171621, 0.05881477, 69.880313, 67.804906, 71.622492, 68.570344,
64.366551, 70.452563, 59.251387, 63.727793, 78.042359, 51.238469,
69.661391, 62.171656, 35.919395, 0.06695618, 64.695395, 55.722531,
70.313039, 68.377156, 64.069473, 68.397813, 76.897836, 0.05497393,
52.692496, 44.930246, 28.247617, 63.398324, 69.501711, 72.960695,
83.124023, 73.273414, 0.06834432, 34.502906, 45.975348, 41.471199,
55.924777, 63.035965, 69.089609, 50.538238, 41.626965, 67.059602,
53.923043, 61.120734, 60.075582, 68.319789, 55.665734, 67.392844,
69.501727, 62.583723, 77.436594, 62.344168, 46.654945, 0.07242857,
75.155633, 0.08174043, 55.232992, 71.572727, 66.701008, 0.05184766,
62.377672, 59.816539, 71.243953, 57.105574, 0.07689782, 67.545852,
53.457934, 73.998234, 74.484039, 0.04600057, 61.319688, 61.891926,
67.207391, 82.020125, 59.284391, 48.338883, 66.734516, 62.583719,
35.939527, 56.105645, 79.665039, 74.657023, 63.810398, 65.194012,
67.014219, 87.847086, 83.696281, 81.900594, 61.759531, 60.634988
)), .Names = c("y", "z", "w", "x"), row.names = c(NA, 99L), class = "data.frame")