为帮助大家理解Tweedie's formula,来一个R code吧。
library(splines)
z = c(rnorm(10000), rnorm(500,2,1),rnorm(500,-2,1))
bins = seq(min(z)-.1,max(z)+.1, len = 100)
h = hist(z, bins, plot = F)
x = h$m
g = glm(h$c~ns(x,df=7),family = poisson)
ss = splinefun(x,log(dnorm(x)/g$fit),method = "natural")
mu = -ss(z,deriv=1)
plot(z,mu)