Re: [R] Error in integrate
On Wed, 16 Nov 2005, Vivien W. Chen wrote: > Hi! > > I am a beginner of R. I am trying to calculate integrate and draw a > graph of the output, but just kept on getting error messages. I list my > program and error message below. Please help. Many Thanks! > > === > + > a<--11 >> b<-0.1 >> c<-0.012 >> x<-0:110 This is harmless but suspicious -- this x is completely unrelated to the x in integrand() >> t<-0:15 >> integrand<-function(x) {exp(-exp(a-c*t)*(exp(b*x)-exp(c*x))/(b-c))} The problem is that x is a vector of whatever length integrate() decides to pass, but t is a vector of length 16. This mismatch of lengths is going to cause a problem. >> cal<-integrate(integrand,0,Inf) > Error in integrate(integrand, 0, Inf) : evaluation of function gave a result > of wrong length > In addition: Warning message: > longer object length >is not a multiple of shorter object length in: -exp(a - c * t) * > (exp(b * x) - exp(c * x)) >> plot(cal~t, xlab="Time", ylab="Pop at t") > Error in model.frame(formula, rownames, variables, varnames, extras, > extranames, : >invalid variable type > === > > - Vivien Chen - > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > Thomas Lumley Assoc. Professor, Biostatistics [EMAIL PROTECTED] University of Washington, Seattle __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Error in integrate
Hi! I am a beginner of R. I am trying to calculate integrate and draw a graph of the output, but just kept on getting error messages. I list my program and error message below. Please help. Many Thanks! === + > a<--11 > b<-0.1 > c<-0.012 > x<-0:110 > t<-0:15 > integrand<-function(x) {exp(-exp(a-c*t)*(exp(b*x)-exp(c*x))/(b-c))} > cal<-integrate(integrand,0,Inf) Error in integrate(integrand, 0, Inf) : evaluation of function gave a result of wrong length In addition: Warning message: longer object length is not a multiple of shorter object length in: -exp(a - c * t) * (exp(b * x) - exp(c * x)) > plot(cal~t, xlab="Time", ylab="Pop at t") Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : invalid variable type === - Vivien Chen - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Error in integrate
Murray Jorgensen <[EMAIL PROTECTED]> wrote: > I'm using R 2.0.1 under Windows XP. I get the following message when I > run the code listed below. I don't seem to have any problems using the > function "slice" outside "integrate". > > Error in integrate(slice, 0, Inf, , , , , , , a, b) * delta : > non-numeric argument to binary operator > RTFM! Integrate returns: Value: A list of class '"integrate"' with components : : You need: A[j] <- integrate(slice,0,Inf,,,a,b)$value*delta Ray __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Error in integrate
I'm using R 2.0.1 under Windows XP. I get the following message when I run the code listed below. I don't seem to have any problems using the function "slice" outside "integrate". Error in integrate(slice, 0, Inf, , , , , , , a, b) * delta : non-numeric argument to binary operator [ By the way, I'm trying to evaluate a two-dimensional integral by slicing it up into one-dimensional bits which I will loop over to evaluate.] Here's the code: mu <- 0.3 sig2 <- 0.01 alpha <- 20 beta <- 15.75 rho <- 0.1 k <- 1/(rho^2.5*gamma(rho)^2*sqrt(2*pi*sig2)) slice <- function(w,a,b) { g <- w^(1/rho) g1 <- w1^(1/rho) h <- g1^a*g^b E <- -(y-rho*mu -g1/alpha + g/beta)^2/(2*sig2*rho) k*h*exp(E- g1 - g) } hi <- 10 delta <- 0.05 grid <- seq(delta/2,hi,delta) y <- -0.3 a <- 0 b <- 0 m <- length(grid) A <- rep(0,m) j <- 0 for (w1 in grid) { j <- j+1 A[j] <- integrate(slice,0,Inf,,,a,b)*delta cat(A[j],"\n") } -- Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html Department of Statistics, University of Waikato, Hamilton, New Zealand Email: [EMAIL PROTECTED]Fax 7 838 4155 Phone +64 7 838 4773 wkHome +64 7 825 0441Mobile 021 1395 862 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html