Here is some example code on how to estimate claim amounts etc. using Bayesian Credibility Theory for the 2 different models.

**model 1:**

dat =c()

totclam=matrix(dat,n,N)

totclam

n =ncol(totclam)

Expmth = mean(rowMeans(totclam))

Expsth = mean(apply(totclam,1,var))

v = var(rowMeans(totclam))-mean(apply(totclam,1,var))/n

z=n/(n+Expsth/v)

premium = z*rowMeans(totclam)+(1-z)*Expmth

**model 2:**

dat =c()

datp=c()

totclam=matrix(dat,n,N)

volume=matrix(datp,n,N)

n =ncol(totclam)

N=nrow(totclam)

X=totclam/volume

Xibar=rowSums(totclam)/rowSums(volume)

Pi=rowSums(volume)

P=sum(Pi)

Pstar=sum(Pi*(1-Pi/P))/(N*n-1)
m=sum(totclam)/P
s=mean(rowSums(volume*(X-Xibar)^2)/(n-1))

v=(sum(rowSums(volume*(X-m)^2))/(n

*N-1)-s)/Pstar*

Zi=Pi/(Pi+s/v)

premium=ZiXibar+(1-Zi)*m

Zi=Pi/(Pi+s/v)

premium=Zi

Enjoy!