samedi 1 juillet 2017

Achieving t random variables with each different df and ncp in R?

I'm trying to generate 5 random t variates using rt(), with each of the 5 having a particular df (from 1 to 5) and a particular ncp (seq(0, 1, l = 5)). So, 5 random t-variables each having a different df and a different ncp.

To achieve the above, I tried the below with no success. What could be the efficient R code to achieve what I described above?

vec.rt = Vectorize(function(n, df, ncp) rt(n, df, ncp), c("n", "df", "ncp"))

vec.rt(n = 5, df = 1:5, ncp = seq(0, 1, l = 5))

Or

mapply(FUN = rt, n = 5 , df = 1:5, ncp = seq(0, 1, l = 5))




Aucun commentaire:

Enregistrer un commentaire