s-news
[Top] [All Lists]

Re: simulation

Subject: Re: simulation
From: "Martin H. H. Stevens" <hstevens@rci.rutgers.edu>
Date: Fri, 17 Nov 2000 08:47:14 -0500
Cc: Daikwon Han <dhan@acsu.buffalo.edu>, s-news@lists.biostat.wustl.edu
References: <Pine.GSO.4.05.10011161952360.15441-100000@lucia.acsu.buffalo.edu>
There are a zillion ways on this one, but how about:
sum.fun <- function(n,cutoff) {
a <- runif(n, 0, 1)
sum(as.numeric(a < cutoff))
}

length <- 100
x <- numeric(length)

for( i in 1:length) x[i] <- sum.fun(1000,0.01)
x

Daikwon Han wrote:

> Dear all,
>
>  Can anyone help me to create 100 numbers from the below program ?
> I'm doing simulation to pick up random numbers and calculate the change of
> total values over time. The first thing I did is to pick up the 1000
> numbers between 0 and 1 under the uniform distribution and add all the
> values less than .01 as follows.
>
>  x<-runif(1000,0,1)
>  x<-sum(as.numeric(x<.01))
>
>  Let's say, I got 9 as x value at the first trial, then I want to repeat
> it 100 times so that I can get 100 different numbers.
>  I've tried "for(i in 1:100)" and "while(i<101)" loop, but it doesn't work
> well. I also tried matrix, append command, I only got the same number
> repeated 100 times, probably the first one(same 100 numbers in the table).
>
>  My question is how to make a loop to keep each value at each trial(should
> be 100 different numbers at 100 trials). Any help would be appreciated.
>  Thank you.
>
> -----------------------------
>  Daikwon Han, Ph.D Candidate
>  Department of Geography
>  SUNY at Buffalo
>  Buffalo, NY 14226
> -----------------------------
>
>
> ---------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu.  To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message:  unsubscribe s-news

--
Dr. M. Henry H. Stevens
Postdoctoral Associate
Department of Ecology, Evolution, & Natural Resources
14 College Farm Road
Cook College, Rutgers University
New Brunswick, NJ 08901-8551

email: hstevens@rci.rutgers.edu
phone: 732-932-9631
fax: 732-932-8746



<Prev in Thread] Current Thread [Next in Thread>