組み合わせの差 ax-yb
例 x=(1,2,3); y=(4,5,6); a=1 ;b=2
a<-1;b<-2;log(outer(exp(1:3)^a,exp(4:6)^-b))
出力
[,1] [,2] [,3]
[1,] -7 -9 -11
[2,] -6 -8 -10
[3,] -5 -7 -9
応用例:2つのポアソン分布の差の確率
Z=0.4X-0.3Y
mul_pdf2<-function(x,c,sdsd,n1b){ q<-as.vector(outer(dpois(0:30,lambda=c),dpois(0:30,lambda=c))) p_x<-as.vector(log(outer(exp(0:30)^0.4,exp(0:30)^-0.3) )) f<-unique(sort(round(p_x,digits=3))) pp_x<-round(p_x,digits=5) xx<-0 yy<-0 for(i in 1:length(f)){ xx[i]<-f[i] yy[i]<-sum(q[which(f[i]==pp_x)]) } data.frame(xx,yy) } j<-mul_pdf2(1,1,sdsd,n1b) z<-0.4*rpois(100000,lambda=1)-0.3*rpois(100000,lambda=1) plot(table(z)/100000) points(j,col=3)