Question: Unused argument in R
0
gravatar for paria.alipour
4 weeks ago by
paria.alipour0 wrote:

I am calling two function repeatedly (Nrep times) and save the results using the below code:

repeat.gendat <- function(Nreps,N, quantilelist=c(0,1,5,50,95,99,100),
                          distrib='norm',n.mean=5, n.stdev=3,e.lambda=0.1,
                          qq=0.5,M=1) {
  for (j in 1:Nreps) {
    if (j==1) {
      if (distrib=='norm') { output.data <- gen.norm.dat(N,n.mean,n.stdev,quantilelist)}
      if (distrib=='exp')  { output.data <- gen.exp.dat(N,e.lambda,quantilelist)}
      if (distrib=='binom')  { output.data <- 
        gen.binom.dat(N,qq, M,quantilelist)}
    }
    if (j>1) {
      if (distrib=='norm') { output.data <- rbind(output.data,
                                 gen.norm.dat(N,n.mean,n.stdev,quantilelist)) }
      if (distrib=='exp') { output.data <- rbind(output.data,
                                 gen.exp.dat(N,e.lambda,quantilelist)) }
      if (distrib=='binom') { output.data <- rbind(output.data,
                                 gen.binom.dat(N,qq,M,quantilelist)) }
      }
  } 
return(output.data)
}

And then to generate the normally distributed data I run the below code in Rstudio:

data1 <- repeat.gendat(100, 50,quantilelist=c(0,1,5,50,95,99,100),
                       distrib='norm', n.mean = 5, n.stdev = 3)

But I am getting this error: Error in rnorm(Nreps, N, n.mean, n.stdev) : unused argument (n.stdev) I don't know where am I wrong. Any help would be appreciated

R • 175 views
ADD COMMENTlink modified 4 weeks ago • written 4 weeks ago by paria.alipour0
1

Paria, please use "code sample" option to indicate your code lines.

ADD REPLYlink written 4 weeks ago by Hamid Ghaedi460
1

Is the function gen.norm.dat from a library, or did you define it elsewhere? This function is likely calling rnorm incorrectly, but I wouldn't be able to help without knowing the origin of the function.

ADD REPLYlink written 4 weeks ago by rpolicastro1.9k
1

The parameters for rnorm is rnorm(N, mean, sd). I guess what you are trying to do here is to generate multiple normally distributed values. For that you will need to do replicate(Nreps, rnorm(N, n.mean, n.stdev)) in the gen.norm.dat function.

ADD REPLYlink written 4 weeks ago by Sam3.2k
0
gravatar for paria.alipour
4 weeks ago by
paria.alipour0 wrote:

The problem was solved. That is right I did not run gen.norm.data before this code. Thank you all

ADD COMMENTlink written 4 weeks ago by paria.alipour0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1489 users visited in the last hour