Ramsey
Ramsey

Reputation: 31

What is the meaning of this error?

Code:

pvalue <- matrix(nrow = 9, ncol = 10000)

for(i in 1:9) {
   for(j in 1:10000) {
    pvalue[i,j]=integrate(dnorm,0,1)    
   }
}

Error:

Error in pvalue[i, j] <- integrate(dnorm, 0, 1) : number of items to
replace is not a multiple of replacement length`

Upvotes: 1

Views: 67

Answers (1)

Marco Sandri
Marco Sandri

Reputation: 24252

The output of the integrate(dnorm,0,1) is a list, not a number.

str(integrate(dnorm,0,1))

List of 5
 $ value       : num 0.341
 $ abs.error   : num 3.79e-15
 $ subdivisions: int 1
 $ message     : chr "OK"
 $ call        : language integrate(f = dnorm, lower = 0, upper = 1)
 - attr(*, "class")= chr "integrate"

A working code is:

pvalue <- matrix(nrow = 9, ncol = 10000)

for(i in 1:9) {
   for(j in 1:10000) {
    pvalue[i,j] <- integrate(dnorm,0,1)$value    
   }
}

Upvotes: 1

Related Questions