Re: [R] generate random number

From: Odette Gaston <odette.gaston_at_gmail.com>
Date: Fri, 21 Nov 2008 18:58:36 +0900

Hi Dimitris,

Appreciate for your reply with detailed information, many thanks!

I realize that generating random number won't be so simple more than I expected, but got some hints from the advice. I am actually hoping to do a parametric bootstrap likelihood test, because this is the way of testing for glmm result what I understood. Following is what I would like to do:

# settings

n <- number of samples
y <- c(2 2 1 0 0 2 0 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 0 2 0 2 2)
x <- c(22 22 24 21 26 18 23 21 17 15 22 24 21 17 26 15 16 13 22 15 15 23 16
23 18 37 22 30) #dependent=y
#independent=x

 Then, I would like to generate random number on glmm = random.y <- rbinom (num,n,p) to do this test. However, this only hypothesized binomial distribution, not include normal one. In this case, how would you be able to do? Apologize if I didn't understand correctly what you wrote and make confuse you. Greatly appreciated if you help me. Any advice would be wonderful!

Best reagards,
Odette

On Thu, Nov 20, 2008 at 8:24 PM, Dimitris Rizopoulos < d.rizopoulos_at_erasmusmc.nl> wrote:

> check the following code:
>
> # settings
> n <- 100 # number of sample units
> p <- 10 # number of repeated measurements
> N <- n * p # total number of measurements
> t.max <- 3
>
> # parameter values
> betas <- c(0.5, 0.4, -0.5, -0.8) # fixed effects (check also 'X' below)
> sigma.b <- 2 # random effects variance
>
> # id, treatment & time
> id <- rep(1:n, each = p)
> treat <- rep(0:1, each = n/2)
> time <- seq(0, t.max, length.out = p)
>
> # simulate random effects
> b <- rnorm(n, sd = sigma.b)
>
> # simulate longitudinal process conditionally on random effects
> time.rep <- rep(time, n)
> treat.rep <- rep(treat, each = p)
> X <- cbind(1, treat.rep,
> time.rep, treat.rep * time.rep) # fixed effects design matrix
> muY <- plogis(c(X %*% betas) + b[id]) # conditional probabilities
> y <- rbinom(N, 1, muY) # simulate binary responses
>
> # put the simulated data in a data.frame
> simulData <- data.frame(
> id = id,
> y = y,
> treat = treat.rep,
> time = time.rep
> )
>
> # fit the model
> library(glmmML)
> fit <- glmmML(y ~ treat * time, data = simulData, cluster = id)
> summary(fit)
>
>
> I hope it helps.
>
> Best,
> Dimitris
>
>
> Odette Gaston wrote:
>
>> Hi everybody,
>>
>> I am currently working on glmmML() and wish to generate random number to
>> do
>> some tests, however, glmm was hypothesized the mixed distributions with
>> normal and binomial in terms of having a random effect. How would you be
>> able to generate random number in this case? Is there a function in R to
>> generate random number of mixed distribution (normal+binomial)? Any
>> comments would be appreciated.
>>
>> Many thanks,
>> Odette
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help_at_r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
> --
> Dimitris Rizopoulos
> Assistant Professor
> Department of Biostatistics
> Erasmus Medical Center
>
> Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
> Tel: +31/(0)10/7043478
> Fax: +31/(0)10/7043014
>
>

        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 21 Nov 2008 - 10:02:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 21 Nov 2008 - 10:30:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive