############################################################# ## the response y has a Poisson disitribution ## but a Poisson regression is not appropriate ## a plain linear regression with Gaussian residual is fine n=1000 x = rpois(n=n,lambda=5) eps = rnorm(n,sd=.1) y = x+eps par(mfrow=c(2,2)) hist(y,breaks=seq(-.5,15.5,1),prob=TRUE) title(sub='Red: Poisson mass distrib.') h=0:15 lines(h,dpois(h,lambda=5),col=2,type='h') points(h,dpois(h,lambda=5),col=2,pch=16) hist(x,breaks=seq(-.5,15.5,1),prob=TRUE) lines(h,dpois(h,lambda=5),col=2,type='h') points(h,dpois(h,lambda=5),col=2,pch=16) plot(x,y) hist(eps,prob=TRUE) h=seq(-.5,.5,.01) lines(h,dnorm(h,sd=0.1),col=2,sub='Red: normal desnity') plot(lm(y~x)) ####################################################### ## now the opposite situation (a bit more artificial) n=1000 x = rnorm(n=n,mean=3,sd=.001) y = rpois(n=n,lambda=exp(x)) par(mfrow=c(2,2)) hist(y,breaks=40,prob=TRUE) # title(sub='Red: Poisson mass distrib.') h=(0:400)/10 lines(h,dnorm(h,mean=mean(y),sd=sd(y)),col=2) # points(h,dpois(h,lambda=5),col=2,pch=16) hist(x) # lines(h,dpois(h,lambda=5),col=2,type='h') # points(h,dpois(h,lambda=5),col=2,pch=16) plot(x,y) hist(eps,prob=TRUE)