Quantcast
Channel: Functions through Poisson distribution in R? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Functions through Poisson distribution in R?

$
0
0

I am trying to run a trial that runs a couple of changing variables through a poisson distribution and gives an output. It goes through three years and there are 12 clusters. All of the groups 1-6 are control and 7 to 12 are intervention.

Year one would have clusters 1-12. with 6 control and 6 intervention. same for year two and three. So in year one you get a v and that v is the same for each cluster but each cluster has a different lambda.

This is the basic code and equation.

mu=3.4lambda=rnorm(1,0,.27)v=rnorm(1,0,.53)e=rnorm(1,0,.74)x=rpois(1, exp(mu+lambda+v+e))

Lambda and v are normally distributed with those st. deviations for each group. I would like in say year 1 for it to take v=rnorm(1,0,.53) and run that through the equation. At the same time I want it to take lambda=rnorm(1,0,.27) and run that for each of the 12 clusters with the same v from year one. So basically one v and 12 lambdas per year. I believe this can be done with functions but I am having a difficult time with it. I tried using for loops but I don't think it is doing exactly what I want. Here is the code with the for loops:

mu=3.4lambda=numeric(length=12)v=numeric(length=3)for (i in 1:120{lambda[i]=rnorm(1,0,.27)}for (j in 1:3){v[j]=rnorm(1,0,.53)}e=rnorm(1,0,.74)x=rpois(1, exp(mu+lambda+v+e))

I am not really sure if this is doing that correct thing or not so if someone with more experience could explain what my code is doing and how to make it do what I want with functions for lambda and v I would greatly appreciate it. Thanks for the help.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images