Re: [R] simulation of PowerGARCH,Threshold GARCH,and GJR GARCH

2019-03-25 Thread Eric Berger
Doing a web search on R CRAN GJR GARCH brought up the rugarch package. The models you mentioned are discussed in the documentation to that package https://cran.r-project.org/web/packages/rugarch/vignettes/Introduction_to_the_rugarch_package.pdf On Mon, Mar 25, 2019 at 2:06 PM Amon kiregu wrot

Re: [R] Simulation based on runif to get mean

2018-01-30 Thread ruipbarradas
Hello, Right. Missed that one. Rui Barradas Enviado a partir do meu smartphone Samsung Galaxy. Mensagem original De: Eric Berger Data: 30/01/2018 10:12 (GMT+00:00) Para: Rui Barradas Cc: Daniel Nordlund , smart hendsome , r-help@r-project.org Assunto: Re: [R] Simulation

Re: [R] Simulation based on runif to get mean

2018-01-30 Thread Eric Berger
Or a shorter version of Rui's approach: set.seed(2511)# Make the results reproducible fun <- function(n){ f <- function(){ c(mean(runif(5,1,10)),mean(runif(5,10,20))) } replicate(n, f()) } fun(10) On Tue, Jan 30, 2018 at 12:03 PM, Rui Barradas wrote: > Hello, > > Another way would

Re: [R] Simulation based on runif to get mean

2018-01-30 Thread Rui Barradas
Hello, Another way would be to use ?replicate and ?colMeans. set.seed(2511)# Make the results reproducible fun <- function(n){ f <- function(){ a <- runif(5, 1, 10) b <- runif(5, 10, 20) colMeans(cbind(a, b)) } replicate(n, f()) } fun(10) Hope this hel

Re: [R] Simulation based on runif to get mean

2018-01-30 Thread Daniel Nordlund
On 1/29/2018 9:03 PM, smart hendsome via R-help wrote: Hello everyone, I have a question regarding simulating based on runif.  Let say I have generated matrix A and B based on runif. Then I find mean for each matrix A and matrix B.  I want this process to be done let say 10 times. Anyone can he

Re: [R] simulation in R

2016-04-22 Thread David L Carlson
I don't think we have enough information to help you with this. Do you intent the simulated values for growthrate to be selected from the values in daT$growthrate? Or do these values define a distribution of values (perhaps ranging between 0 and 1) and the simulation should use that empirical

Re: [R] simulation in vector autoregressive model (VAR)

2015-09-04 Thread David Winsemius
Before you post on Rhelp you should first read the Posting Guide. It tells you that requests for statistical advice might be answered but are not really on-topic. Furthermore requests for tutorials or extended worked examples should probably be accompanied by evidence of searching using Google o

Re: [R] simulation data in SEM

2014-09-14 Thread PO SU
PLZ mke sure the package installed which contains "mvrnorm" function. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-14 09:56:34, "thanoon younis" wrote: >Dear R members >I want to simulate data depending on SEM and when i applied the code below >i found

Re: [R] simulation data in SEM

2014-09-14 Thread David Winsemius
Adding back the list address: On Sep 14, 2014, at 9:53 AM, thanoon younis wrote: > thank you for your help but i still have error after putting semicolon > "Error: unexpected symbol in: > "Ro<-matrix(data=c(7.0,2.1,2.1,7.0), ncol=2) > yo<-matrix(data=NA,nrow=N,ncol=P) p"" The error message sho

Re: [R] simulation data in SEM

2014-09-14 Thread David Winsemius
On Sep 14, 2014, at 8:48 AM, Don McKenzie wrote: cc’ing to list, as requested in the posting guide, so that others may be able to help you. On Sep 14, 2014, at 8:45 AM, thanoon younis > wrote: Thank you very much for your reply the output is #Do simulation for 100 replications N<-1000;

Re: [R] simulation data in SEM

2014-09-14 Thread Don McKenzie
cc�ing to list, as requested in the posting guide, so that others may be able to help you. On Sep 14, 2014, at 8:45 AM, thanoon younis wrote: > Thank you very much for your reply > > the output is > > > #Do simulation for 100 replications > > N<-1000; P<-10 > > > > phi<-matrix(data=c(1.0,0.3

Re: [R] simulation data in SEM

2014-09-14 Thread Don McKenzie
What errors? What is your output? What output did you expect? On Sep 14, 2014, at 6:56 AM, thanoon younis wrote: > Dear R members > I want to simulate data depending on SEM and when i applied the code below > i found some errors and i still cannot run it. > many thanks in advance > > > Thano

Re: [R] simulation data with dichotomous varuables

2014-08-10 Thread William Revelle
Dear Thanoon, You might look at the various item simulation functions in the psych package. In particular, for your problem: R1 <- sim.irt(10,1000,a=3,low = -2, high=2) R2 <- sim.irt(10,1000,a=3,low = -2, high=2) R12 <- data.frame(R1$items,R2$items) #this gives you 20 items, grouped with high c

Re: [R] simulation dichotomous data

2014-08-01 Thread Charles Determan Jr
Please remember the 'reply all' for the r-help page. First Question: How can i use Pearson correlation with dichotomous data? i want to use a correlation between dichotomous variables like spearman correlation in ordered categorical variables? cor(variable1, variable2, *method = "pearson"*) Seco

Re: [R] simulation dichotomous data

2014-07-31 Thread Charles Determan Jr
Thanoon, You should still send the question to the R help list even when I helped you with the code you are currently using. I will not always know the best way or even how to proceed with some questions. As for to your question with the code below. Firstly, there is no 'phi' method for cor in

Re: [R] simulation data

2014-04-10 Thread Charles Determan Jr
Thanoon, My reply to your previous post should be more than enough for you to accomplish your goal. Please look over that script again: ords <- seq(4) p <- 10 N <- 1000 percent_change <- 0.9 R <- as.data.frame(replicate(p, sample(ords, N, replace = T))) or alternatively as Mr. Barradas suggest

Re: [R] simulation data

2014-04-10 Thread Rui Barradas
Hello, At an R prompt type ?rbinom ?replicate Hope this helps, Rui Barradas Em 10-04-2014 02:28, thanoon younis escreveu: hi i want to simulate multivariate dichotomous data matrix with categories (0,1) and n=1000 and p=10. thanks alot in advance [[alternative HTML version deleted

Re: [R] simulation data

2014-04-09 Thread Rolf Turner
On 10/04/14 09:28, thanoon younis wrote: hi i want to simulate multivariate dichotomous data matrix with categories (0,1) and n=1000 and p=10. Nobody's stopping you! :-) cheers, Rolf Turner __ R-help@r-project.org mailing list https://stat.ethz.ch

Re: [R] simulation data

2014-04-05 Thread Charles Determan Jr
Thanoon, Firstly, please remember to reply to the R help list as well so that other may benefit from your questions as well. Regarding your second request, I have written the following as a very naive way of inducing correlations. Hopefully this makes it perfectly clear what you change for diffe

Re: [R] simulation data

2014-04-04 Thread Charles Determan Jr
Hi Thanoon, How about this? # replicate p=10 times random sampling n=1000 from a vector containing your ordinal categories (1,2,3,4) R <- replicate(10, sample(as.vector(seq(4)), 1000, replace = T)) Cheers, Charles On Fri, Apr 4, 2014 at 7:10 AM, thanoon younis wrote: > dear sir > i want to si

Re: [R] simulation of Hierarchical design

2014-02-24 Thread Greg Snow
So can the same student be associated with multiple instructors? only within the same school? or more general? by repeated student ID's do you mean that a student in school A and a student in school B can both have ID 1, but they are different students? or do you mean that instructor #1 and Instr

Re: [R] Simulation in R

2013-08-04 Thread Prof Brian Ripley
On 04/08/2013 09:30, Rui Barradas wrote: Hello, See the help page for ?sample. X <- sample(0:1, 1, replace = TRUE, prob = c(0.25, 0.75)) Hope this helps, ?rbinom would have been a better answer since simpler, faster, algorithms are available in that case. Or even as.integer(runif(100

Re: [R] Simulation in R

2013-08-04 Thread Preetam Pal
Thank you very much guys On Sun, Aug 4, 2013 at 3:51 PM, Prof Brian Ripley wrote: > On 04/08/2013 09:30, Rui Barradas wrote: > >> Hello, >> >> See the help page for ?sample. >> >> X <- sample(0:1, 1, replace = TRUE, prob = c(0.25, 0.75)) >> >> Hope this helps, >> > > ?rbinom would have been

Re: [R] Simulation in R

2013-08-04 Thread Jeff Newmiller
So you looked at some unspecified help pages online and tried some unspecified stuff? Try being more specific next time you post. For example, try reading the footer of any R-help email. Note that it says read the Posting Guide, and provide a reproducible example (at least of what you tried that

Re: [R] Simulation in R

2013-08-04 Thread Rui Barradas
Hello, See the help page for ?sample. X <- sample(0:1, 1, replace = TRUE, prob = c(0.25, 0.75)) Hope this helps, Rui Barradas Em 04-08-2013 08:51, Preetam Pal escreveu: Hi All, I want to simulate a random variable X which takes values 1 and 0 with probabilities 75% and 25% respectively

Re: [R] simulation from truncated skew normal

2013-06-12 Thread Mikhail Umorin
I am not aware of any such command so, I think, you may have to write one yourself: invert the CDF and use uniform random variable (runif) to sample Mikhail On Tuesday, June 11, 2013 16:18:59 cassie jones wrote: > Hello R-users, > > I am trying to simulate from truncated skew normal distributi

Re: [R] simulation\bootstrap of list factors

2013-04-18 Thread Adams, Jean
Tobias, I'm not sure if this is what you're after, but perhaps it will help. # create a list of 5 vectors n <- 5 subsets <- lapply(1:n, function(x) rnorm(5, mean=80, sd=1)) # create another list that takes 2 bootstrap samples from each of the 5 vectors and puts them in a matrix nbootstrap <- 2 t

Re: [R] simulation

2013-01-03 Thread Berend Hasselman
On 03-01-2013, at 17:40, Simone Gogna wrote: > Dear R users, > suppose we have a random walk such as: > > v_t+1 = v_t + e_t+1 > > where e_t is a normal IID noise pocess with mean = m and standard deviation = > sd and v_t is the fundamental value of a stock. > > Now suppose I want a trading s

Re: [R] simulation

2013-01-03 Thread Berend Hasselman
On 03-01-2013, at 17:40, Simone Gogna wrote: > Dear R users, > suppose we have a random walk such as: > > v_t+1 = v_t + e_t+1 > > where e_t is a normal IID noise pocess with mean = m and standard deviation = > sd and v_t is the fundamental value of a stock. > > Now suppose I want a trading s

Re: [R] Simulation in R

2012-12-01 Thread Greg Snow
look at functions replicate and mvrnorm functions (the later in the MASS package). On Sat, Dec 1, 2012 at 12:02 PM, mboricgs wrote: > Hello! > > How can I do 100 simulations of length 17 from bivariate bivariate normal > distribution, if I know all 5 parameters? > > > > -- > View this message

Re: [R] Simulation with cpm package

2012-11-19 Thread Uwe Ligges
On 13.11.2012 15:45, Christopher Desjardins wrote: Hi, I am running the following code based on the cpm vignette's code. I believe the code is syntactically correct but it just seems to hang R. I can get this to run if I set the sims to 100 but with 2000 it just hangs. Any ideas why? No: Work

Re: [R] simulation of levene's test

2012-05-28 Thread R. Michael Weylandt
On Mon, May 28, 2012 at 12:14 PM, Özgür Asar wrote: > Dear Dila, > > Try the following: > > library(Rcmdr) Or avoid the unncessary overhead of Rcmdr and use library(car) to provide levenTest instead. > asim <- 1000 > pv<-NULL It's also many orders of magnitude more efficient to preallocate "

Re: [R] simulation of levene's test

2012-05-28 Thread Özgür Asar
Dear Dila, Try the following: library(Rcmdr) asim <- 1000 pv<-NULL for(i in 1:asim) { print(i) set.seed(i) g1 <- rnorm(20,0,2) g2 <- rnorm(20,0,2) g3 <- rnorm(20,0,2) x <- c(g1,g2,g3) group<-as.factor(c(rep(1,20),rep(2,20),rep(3,20))) pv<-c(pv,leveneTest(x,group)$"Pr(>F)"[1]) } Best Ozgur

Re: [R] simulation

2012-04-05 Thread David Winsemius
On Apr 5, 2012, at 10:57 PM, Christopher Kelvin wrote: Hello, i need to simulate 100 times, n=40 , the distribution has 90% from X~N(0,1) + 10% from X~N(20,10) Is my loop below correct? Thank you n=40 for(i in 1:100){ x<-rnorm(40,0,1) # 90% of n You are overwriting x and y and at the end o

Re: [R] simulation

2011-12-16 Thread Bert Gunter
Suggestions? -- Yes. 1) Wrong list.. Post on R-sig-mixed-models, not here. 2) Follow the posting guide and provide the modelformula, which may well be the source of the difficulties (overfitting). -- Bert On Fri, Dec 16, 2011 at 1:56 PM, Scott Raynaud wrote: > I'm using an R program (which I d

Re: [R] Simulation over data repeatedly for four loops

2011-11-13 Thread R. Michael Weylandt
Perhaps you might want to abstract your code a bit and try something like: X = rnorm(500) # Some Data replicate(1e4, mean(sample(X, 500, replace = T))) Obviously you can set up a loop over your data sets as needed. Michael On Sat, Nov 12, 2011 at 6:46 PM, Francesca wrote: > Dear Contributors,

Re: [R] Simulation from discrete uniform

2011-10-26 Thread Mehmet Suzen
Why don't you use sample; > sample(1:10,10,replace=TRUE) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of BSanders Sent: 26 October 2011 08:49 To: r-help@r-project.org Subject: Re: [R] Simulation from discrete uniform If yo

Re: [R] Simulation from discrete uniform

2011-10-26 Thread BSanders
If you wanted a discrete uniform from 1-10 use: ceiling(10*runif(1)) if you wanted from 0-12, use: ceiling(13*runif(1))-1 -- View this message in context: http://r.789695.n4.nabble.com/Simulation-from-discrete-uniform-tp3434980p3939694.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] simulation for equation with two variables

2011-07-21 Thread David Winsemius
On Jul 21, 2011, at 1:42 PM, Benjamin Caldwell wrote: That is, run all possible combinations of the two vectors through the equation. *Ben * For "all combinations" the usual route is data preparation with either expand.grid() or outer() On Thu, Jul 21, 2011 at 10:04 AM, Benjamin Caldwel

Re: [R] simulation for equation with two variables

2011-07-21 Thread Benjamin Caldwell
That is, run all possible combinations of the two vectors through the equation. *Ben * On Thu, Jul 21, 2011 at 10:04 AM, Benjamin Caldwell wrote: > Hi, > I'm trying to run a basic simulation and sensitivity test by running an > equation with two variables and then plotting the results against

Re: [R] simulation

2011-06-06 Thread Petr Savicky
On Mon, Jun 06, 2011 at 04:50:57PM +1000, Stat Consult wrote: > Dear ALL > I want to simulate data from Multivariate normal distribution. > GE.N<-mvrnorm(25,mu,S) > S <-matrix(rep(0,1),nrow=100) > for( i in 1:100){sigma<-runif(100,0.1,10);S > [i,i]=sigma[i];mu<-runif(100,0,10)} > for (i in 1:20

Re: [R] Simulation from discrete uniform

2011-05-29 Thread Jorge Ivan Velez
Hi Serdar, Take a look at the following: > sample(0:9, 100, replace = FALSE) Error in sample(0:9, 100, replace = FALSE) : cannot take a sample larger than the population when 'replace = FALSE' > sample(0:9, 100, replace = TRUE) [1] 5 6 5 7 3 0 8 4 8 2 2 4 7 6 0 7 0 0 0 7 5 6 3 6 0 9 6 1 2 6 9

Re: [R] Simulation from discrete uniform

2011-05-29 Thread SERDAR NESLIHANOGLU
Hi Also , same problem to create discrete uniform Distribution , But sample () and runif() not useful to generate discrete uniform . Ex: > u<-round(runif(10*10,min=1,max=10),0) > table(u) u 1 2 3 4 5 6 7 8 9 10 6 10 9 10 14 6 11 14 12 8 Not useful for large number OR

Re: [R] simulation from truncated poisson

2011-05-16 Thread cassie jones
It is truncated from left. On Mon, May 16, 2011 at 6:33 PM, Greg Snow wrote: > Which direction is it truncated? (only values less than a allowed or only > greater?). > > One simple approach is rejection sampling, just generate from a regular > poisson distribution, then throw away any values in

Re: [R] simulation from truncated poisson

2011-05-16 Thread cassie jones
uniform between that value and 1, then feed that > uniform into the qpois function. > > > > *From:* cassie jones [mailto:cassiejone...@gmail.com] > *Sent:* Monday, May 16, 2011 7:46 PM > *To:* Greg Snow > *Cc:* r-help@r-project.org > *Subject:* Re: [R] simulation from tr

Re: [R] simulation from truncated poisson

2011-05-16 Thread Greg Snow
l.com] Sent: Monday, May 16, 2011 7:46 PM To: Greg Snow Cc: r-help@r-project.org Subject: Re: [R] simulation from truncated poisson It is truncated from left. On Mon, May 16, 2011 at 6:33 PM, Greg Snow mailto:greg.s...@imail.org>> wrote: Which direction is it truncated? (only values

Re: [R] simulation from truncated poisson

2011-05-16 Thread Greg Snow
Which direction is it truncated? (only values less than a allowed or only greater?). One simple approach is rejection sampling, just generate from a regular poisson distribution, then throw away any values in the truncated region. Another approach if the legal values are those from 0 to a, so

Re: [R] Simulation Questions

2011-05-02 Thread Andrew Robinson
Hi Shane, it sounds to me as though you have a fairly well-defined problem. You want to generate random numbers with a specific mean, variance, and correlation with another random varaible. I would reverse-enginerr the fuinctions for simple linear regression to get a result like y = beta_0 + be

Re: [R] Simulation from discrete uniform

2011-04-07 Thread Søren Højsgaard
?sample -Oprindelig meddelelse- Fra: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] På vegne af cassie jones Sendt: 8. april 2011 03:16 Til: r-help@r-project.org Emne: [R] Simulation from discrete uniform Dear all, I am trying to simulate from discrete uniform distrib

Re: [R] Simulation from discrete uniform

2011-04-07 Thread Dennis Murphy
Hi: Suppose X has a discrete uniform distribution on the sample space S = {0, 1, 2, ..., 9}. Then a random sample of size 100 from this distribution, for example, would be dus <- sample(0:9, 100, replace = TRUE) # Checks: table(dus) lattice::barchart( ~ table(dus), xlim = c(0, 20)) The sample sp

Re: [R] Simulation

2011-03-01 Thread Mike Marchywka
> Date: Mon, 28 Feb 2011 19:18:18 -0800 > From: kadodamb...@hotmail.com > To: r-help@r-project.org > Subject: [R] Simulation > > I tried looking for help but I couldn't locate the exact solution. > I have data that has several variables. I want to do se

Re: [R] Simulation

2011-03-01 Thread Ivan Calandra
Well, knowing how your data looks like would definitely help! Say your data object is called "mydata", just paste the output from dput(mydata) into the email you want to send to the list. Ivan Le 3/1/2011 04:18, bwaxxlo a écrit : I tried looking for help but I couldn't locate the exact solutio

Re: [R] Simulation of Multivariate Fractional Gaussian Noise and Fractional Brownian Motion

2011-02-11 Thread Wonsang You
Dear Kjetil, Thank you so much for your advice on my question. Best Regards, Wonsang 2011/2/10 Kjetil Halvorsen > What you can do to find out is to type into your R session > RSiteSearch("multivariate fractional gaussian") > > That seems to give some usefull results. > > Kjetil > > On Tue, F

Re: [R] Simulation of Multivariate Fractional Gaussian Noise and Fractional Brownian Motion

2011-02-10 Thread Kjetil Halvorsen
What you can do to find out is to type into your R session RSiteSearch("multivariate fractional gaussian") That seems to give some usefull results. Kjetil On Tue, Feb 8, 2011 at 1:51 PM, Wonsang You wrote: > > Dear R Helpers, > > I have searched for any R package or code for simulating multivar

Re: [R] Simulation - Natrual Selection

2011-01-05 Thread Ben Ward
On 05/01/2011 17:40, Bert Gunter wrote: My hypothesis was specified before I did my experiment. Whilst far from perfect, I've tried to do the best I can to assess rise in resistance, without going into genetics as it's not possible. (Although may be at the next institution I've applied for MSc).

Re: [R] Simulation - Natrual Selection

2011-01-05 Thread Ben Ward
On 05/01/2011 16:37, Mike Marchywka wrote: Date: Wed, 5 Jan 2011 15:48:46 + From: benjamin.w...@bathspa.org To: r-help@r-project.org Subject: [R] Simulation - Natrual Selection Hi, I've been modelling some data over the past few days, of my work, repeatedly challenging microbes to a ce

Re: [R] Simulation - Natrual Selection

2011-01-05 Thread Mike Marchywka
> Date: Wed, 5 Jan 2011 15:48:46 + > From: benjamin.w...@bathspa.org > To: r-help@r-project.org > Subject: [R] Simulation - Natrual Selection > > Hi, > > I've been modelling some data over the past few days, of my work, > repeatedly challenging microbes to a certain concentration of cleane

Re: [R] simulation from pareto distn

2010-11-10 Thread Giovanni Petris
For a Pareto distribution, even a truncated one, the inverse CDF method should be straightforward to implement. Giovanni Petris On Tue, 2010-11-09 at 10:50 -0600, cassie jones wrote: > Dear all, > > I am trying to simulate from truncated Pareto distribution. I know there is > a package called P

Re: [R] simulation from pareto distn

2010-11-09 Thread Dennis Murphy
Hi: library(sos) findFn('truncated Pareto') On my system, it scared up 17 matches. It looks like the VGAM package would be a reasonable place to start looking. HTH, Dennis On Tue, Nov 9, 2010 at 8:50 AM, cassie jones wrote: > Dear all, > > I am trying to simulate from truncated Pareto distribu

Re: [R] Simulation

2010-09-10 Thread Greg Snow
Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Jim Silverton > Sent: Friday, September 10, 2010 1:03 AM > To: r-help@r-project.org > Subject:

Re: [R] Simulation

2010-09-10 Thread Jim Silverton
I have two questions: (1) How do you 'create' an 2 x 2 table in R using say an Odd ratio of 3 or even 0.5 (2) If I have several 2 x 2 tables, how can I 'implement' dependence in the tables with say 25 of the Tables having an odds ratio of 1 and 75 of the tables having an odds ratio of 4? Jim

Re: [R] Simulation problem.

2010-04-14 Thread Greg Snow
This looks like homework. If it is, you should really tell us along with what your teacher's policy is on getting help over the internet is (and note that many teachers monitor this list and can see if you are getting help). You have done the first part yourself, much better than some who have

Re: [R] Simulation of VAR

2010-03-29 Thread Ron_M
Yes I looked into "dse" package. Here I have implemented two approach for simulation like following : library(dse) A1 <- matrix(rnorm(16),4) A2 <- matrix(rnorm(16),4) mu <- rnorm(4) sigma <- matrix(c(0.006594712, 0.006467731, -0.000254914, 0.005939934, 0.006467731, 0.006654184, -0.000384097, 0.00

Re: [R] Simulation of VAR

2010-03-29 Thread Pfaff, Bernhard Dr.
Dear Ron, have you had a look at the package dse? Here, ARMA models can be specified and simulated. The only exercise left for you, is to transform the VECM coefficients into their level-VAR values. Best, Bernhard |> -Original Message- |> From: r-help-boun...@r-project.org |> [m

Re: [R] simulation of binary data

2010-01-23 Thread Juliet Hannah
Check out the help page of the lrm function in the rms library. To show how lrm is used, the examples simulate data for logistic regression. This may give you some ideas. On Wed, Jan 20, 2010 at 10:41 AM, omar kairan wrote: > Hi, > > could someone help me with dilemma on the simulation of logisti

Re: [R] simulation of binary data

2010-01-20 Thread Rolf Turner
On 21/01/2010, at 4:41 AM, omar kairan wrote: Hi, could someone help me with dilemma on the simulation of logistic regressiondata with multicollinearity effect and high leverage point.. If that is the clearest way in which you can phrase your question then I doubt that *anyone* can help you.

Re: [R] Simulation numbers from a probability table

2010-01-13 Thread Peter Ehlers
Try this: dat <- data.frame(x=11:14, pa=1:4/10, pb=4:1/10) f <- function(numreps, data){ pmat <- as.matrix(data[-1]) x <- data[,1] result <- matrix(0, nrow=numreps, ncol=ncol(pmat)) colnames(result) <- c("A", "B") for(i in seq_len(numreps)){ result[i,] <- apply(pmat, 2, function(p)

Re: [R] Simulation numbers from a probability table

2010-01-13 Thread Tal Galili
If the trials are not connected then I would consider melting the table using melt() from the reshape package. And then using lapply() with the function random.function <- function(my.prob, number.of.observations = 10) { sum(rbinom(number.of.observations, 1, my.prob)) } in case the trials are con

Re: [R] Simulation function

2009-08-18 Thread jim holtman
You need to store your results in a list and then access the information in the list to get the values: > boot<-function(a,b,c){ + media<-(a+b+c)/3 + var_app<-var(a) + list(media=media,var_app=var_app) + } > boot(2,4,10) $media [1] 5.33 $var_app [1] NA > > simul<-function(S){ +

Re: [R] Simulation Function - Save results

2009-08-18 Thread David Winsemius
On Aug 17, 2009, at 1:40 PM, MarcioRibeiro wrote: Ok, the LIST function I understood... I didn't see how you got a "random" input to that function. Would seem to need one of the r functions as input. What I would like now is to simulate this Function A many times (S) in order to get S

Re: [R] Simulation Function - Save results

2009-08-18 Thread MarcioRibeiro
Ok, the LIST function I understood... What I would like now is to simulate this Function A many times (S) in order to get S results for the MEAN and for the VARIANCE... Zhiliang Ma wrote: > > in order to return more multiple variables, you can put them in a list > and then return this list. >

Re: [R] Simulation Function - Save results

2009-08-14 Thread Zhiliang Ma
in order to return more multiple variables, you can put them in a list and then return this list. e.g. #Function A boot<-function(a,b,c){ mean_boot<-(a+b)/2 var_boot<-c list(mean_boot = mean_boot, var_boot = var_boot) } out <- boot(1,2,3) out $mean_boot [1] 1.5 $var_boot [1] 3 On Fri, Aug 1

Re: [R] Simulation code error

2009-07-15 Thread Roger Bivand
This message is one of a number of identical copies, also cross-posted to R-sig-geo, and in fact with an obvious solution that the author gives at the end. The thread will be continued on R-sig-geo. Cross posting is advised against expressly in e.g. http://en.wikipedia.org/wiki/Crossposting, and

Re: [R] Simulation functions for underdispered Poisson and binomial distributions

2009-07-15 Thread Charles C. Berry
On Wed, 15 Jul 2009, Shinichi Nakagawa wrote: Dear R users I would like to simulate underdispersed Poisson and binomial distributions somehow. I know you can do this for overdispersed counterparts - using rnbinom() for Poisson and rbetabinom() for binomial. Could anyone share functions to

Re: [R] Simulation from a multivariate normal distribution

2009-05-18 Thread Peter Dalgaard
Liaw, Andy wrote: Check out the help page for replicate(). Andy Or the 'n' argument to mvrnorm (or mvtnorm::rmvnorm for that matter)... From: barbara.r...@uniroma1.it I must to create an array with dimensions 120x8x500. Better I have to make 500 simulations of 8 series of return from a mul

Re: [R] Simulation from a multivariate normal distribution

2009-05-18 Thread Uwe Ligges
barbara.r...@uniroma1.it wrote: I must to create an array with dimensions 120x8x500. Better I have to make 500 simulations of 8 series of return from a multivariate normal distribution. there's the command "mvrnorm" but how I can do this repeating the simulation 500 times?" ?replicate Uwe

Re: [R] Simulation from a multivariate normal distribution

2009-05-18 Thread Liaw, Andy
Check out the help page for replicate(). Andy From: barbara.r...@uniroma1.it > > I must to create an array with dimensions 120x8x500. Better I > have to make 500 simulations of 8 series of return from a multivariate > normal distribution. there's the command "mvrnorm" but how I > can do this

Re: [R] Simulation

2009-05-18 Thread Kon Knafelman
gt; Date: Thu, 14 May 2009 12:05:30 +0100 > From: b.rowling...@lancaster.ac.uk > To: peterflomconsult...@mindspring.com > CC: waclaw.marcin.kusnierc...@idi.ntnu.no; r-help@r-project.org > Subject: Re: [R] Simulation > > > As a beginner, I agree the for loop is much clea

Re: [R] Simulation

2009-05-18 Thread Kon Knafelman
first place, your input is highly appreciated using your method, im getting a bit confused. > Date: Fri, 15 May 2009 12:16:45 +0100 > From: s.elli...@lgc.co.uk > To: konk2...@hotmail.com > Subject: Re: [R] Simulation > > The tidiest way of doing something 'simple' with a se

Re: [R] Simulation

2009-05-15 Thread Wacek Kusnierczyk
Greg Snow wrote: > Another possibility (maybe more readable, gives the option of a list, > probably not faster): > > Replicate(1000, rexp(15,1) ) > > provided that simplify=FALSE: is(replicate(10, rexp(15, 1))) # "matrix" ... is(replicate(10, rexp(15, 1), simplify=FALSE)) # "

Re: [R] Simulation

2009-05-15 Thread Greg Snow
(Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -Original Message- > From: Ben Bolker [mailto:bol...@ufl.edu] > Sent: Friday, May 15, 2009 10:19 AM > To: Greg Snow > Cc: r-help@r-project.org > Subject: Re: [R] Simula

Re: [R] Simulation

2009-05-15 Thread Ben Bolker
Greg Snow wrote: > Another possibility (maybe more readable, gives the option of a list, > probably not faster): > > Replicate(1000, rexp(15,1) ) > I think that should be "replicate" The matrix form is quite a bit faster, but don't know if that will matter -- times below are for doing this

Re: [R] Simulation

2009-05-15 Thread Greg Snow
n...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Ben Bolker > Sent: Friday, May 15, 2009 6:37 AM > To: r-help@r-project.org > Subject: Re: [R] Simulation > > > > On Fri, 15 May 2009 19:17:37 +1000 Kon Knafelman > wrote: > > KK> I hve the

Re: [R] Simulation

2009-05-15 Thread Ben Bolker
On Fri, 15 May 2009 19:17:37 +1000 Kon Knafelman wrote: KK> I hve the same problem as the initial one, except i need 1000 KK> samples of size 15, and my distribution is Exp(1). I've adjusted KK> some of the loop formulas for my n=15, but im unsure how to proceed KK> in the quickest way. KK> Ca

Re: [R] Simulation

2009-05-15 Thread Stefan Grosse
On Fri, 15 May 2009 19:17:37 +1000 Kon Knafelman wrote: KK> I hve the same problem as the initial one, except i need 1000 KK> samples of size 15, and my distribution is Exp(1). I've adjusted KK> some of the loop formulas for my n=15, but im unsure how to proceed KK> in the quickest way. KK> Can

Re: [R] Simulation

2009-05-15 Thread Kon Knafelman
rmulas for my n=15, but im unsure how to proceed in the quickest way. Can someone please help? Much appreciated :) > From: r.tur...@auckland.ac.nz > Date: Thu, 14 May 2009 10:26:38 +1200 > To: c...@witthoft.com > CC: r-help@r-project.org > Subject: Re: [R] Simulation >

Re: [R] Simulation

2009-05-14 Thread Wacek Kusnierczyk
Stefan Grosse wrote: > Debbie Zhang schrieb: > >> Now, I am trying to obtain the sample variance (S^2) of the 1000 samples >> that I have generated before. >> >> I am wondering what command I should use in order to get the sample variance >> for all the 1000 samples. >> >> >> >> What I am ca

Re: [R] Simulation

2009-05-14 Thread Linlin Yan
Since you got the most suitable way to get x, why can't you get the variances in the same way? Just like: v = vector() for (i in 1:length(x)) v[i] = var(x[[i]]) BTW, it is much better to use lapply, like this: lapply(x, var) On Thu, May 14, 2009 at 8:26 PM, Debbie Zhang wrote: > > Thanks f

Re: [R] Simulation

2009-05-14 Thread Stefan Grosse
Debbie Zhang schrieb: > Now, I am trying to obtain the sample variance (S^2) of the 1000 samples that > I have generated before. > > I am wondering what command I should use in order to get the sample variance > for all the 1000 samples. > > > > What I am capable of doing now is just typing in

Re: [R] Simulation

2009-05-14 Thread Debbie Zhang
ierc...@idi.ntnu.no > To: b.rowling...@lancaster.ac.uk > CC: r-help@r-project.org > Subject: Re: [R] Simulation > > Barry Rowlingson wrote: > > On Wed, May 13, 2009 at 9:56 PM, Wacek Kusnierczyk > > wrote: > > > >> Barry Rowlingson wrote: > >> >

Re: [R] Simulation

2009-05-14 Thread Wacek Kusnierczyk
Barry Rowlingson wrote: > > Computer scientists will write their beautiful manuscripts, but how > many people who come to R because they want to do a t-test or fit a > GLM will read them? That's the R-help audience now. > don't forget that r seems to take, maybe undeserved, the pride of being

Re: [R] Simulation

2009-05-14 Thread Ted Harding
On 14-May-09 11:28:17, Wacek Kusnierczyk wrote: > Barry Rowlingson wrote: >>> As a beginner, I agree the for loop is much clearer to me. >> >> [Warning: Contains mostly philosophy] >> > maybe quasi ;) > >> To me, the world and how I interact with it is procedural. When I want >> to break

Re: [R] Simulation

2009-05-14 Thread Wacek Kusnierczyk
Barry Rowlingson wrote: >> As a beginner, I agree the for loop is much clearer to me. >> >> > > [Warning: Contains mostly philosophy] > maybe quasi ;) > To me, the world and how I interact with it is procedural. When I want > to break six eggs I do 'get six eggs, repeat "break egg"

Re: [R] Simulation)

2009-05-14 Thread Wacek Kusnierczyk
Peter Flom wrote: > As a beginner, I agree the for loop is much clearer to me. > > >> well, that's quite likely. especially given that typical courses in >> programming, afaik, include for looping but not necessarily functional >> stuff -- are you an r beginner, or a programming beginne

Re: [R] Simulation

2009-05-14 Thread Barry Rowlingson
> As a beginner, I agree the for loop is much clearer to me. > [Warning: Contains mostly philosophy] To me, the world and how I interact with it is procedural. When I want to break six eggs I do 'get six eggs, repeat "break egg" until all eggs broken'. I don't apply an instance of the break

Re: [R] Simulation)

2009-05-14 Thread Peter Flom
I wrote As a beginner, I agree the for loop is much clearer to me. Wacek Kusnierczyk replied > >well, that's quite likely. especially given that typical courses in >programming, afaik, include for looping but not necessarily functional >stuff -- are you an r beginner, or a programming

Re: [R] Simulation

2009-05-14 Thread Wacek Kusnierczyk
Peter Flom wrote: > >>> Seriously? You think: >>> >>> lapply(1:n, rnorm, 0, 1) >>> >>> is 'clearer' than: >>> >>> x=list() >>> for(i in 1:n){ >>> x[[i]]=rnorm(i,0,1) >>> } >>> >>> for beginners? >>> >>> Firstly, using 'lapply' introduces a function (lapply) that doesn't >>> have an intuitive n

Re: [R] Simulation

2009-05-14 Thread Peter Flom
Wacek Kusnierczyk wrote >> Seriously? You think: >> >> lapply(1:n, rnorm, 0, 1) >> >> is 'clearer' than: >> >> x=list() >> for(i in 1:n){ >> x[[i]]=rnorm(i,0,1) >> } >> >> for beginners? >> >> Firstly, using 'lapply' introduces a function (lapply) that doesn't >> have an intuitive name. Also,

Re: [R] Simulation

2009-05-14 Thread Wacek Kusnierczyk
Dimitris Rizopoulos wrote: > Wacek Kusnierczyk wrote: >> Barry Rowlingson wrote: >>> On Wed, May 13, 2009 at 5:36 PM, Wacek Kusnierczyk >>> wrote: Barry Rowlingson wrote: > Soln - "for" loop: > > > z=list() > > for(i in 1:1000){z[[i]]=rnorm(100,0,1)} > > now inspect

Re: [R] Simulation

2009-05-13 Thread Wacek Kusnierczyk
Barry Rowlingson wrote: [...] >>> Yes, you can probably vectorize this with lapply or something, but I >>> prefer clarity over concision when dealing with beginners... >>> >> but where's the preferred clarity in the for loop solution? >> > > Seriously? You think: > > lapply(1:n, rno

  1   2   >