JeffreyRacine / R-Package-np

R package np (Nonparametric Kernel Smoothing Methods for Mixed Data Types)
https://socialsciences.mcmaster.ca/people/racinej
47 stars 18 forks source link

Asymptotic variance for npudens with categorical variables only needs correction #13

Open JeffreyRacine opened 7 years ago

JeffreyRacine commented 7 years ago

Avar should be p(x)(1-p(x))/n

set.seed(42) n <- 100 X <- sort(rbinom(n,2,0.4)) p <- as.numeric(prop.table(table(X))) Avar.p <- p*(1-p)/n

require(np)

model <- npudens(~factor(X),bws=0,ukertype="aitchisonaitken") p.hat <- unique(fitted(model)) Avar.p.hat <- unique(se(model))**2

cbind(p,Avar.p,p.hat,Avar.p.hat,p.hat/n)

Note that npudens is returning p.hat/n for the variance in this case but it ought to be p.hat*(1-p.hat)/n