[R] Error in integrate
Thomas Lumley
tlumley at u.washington.edu
Wed Nov 16 16:08:26 CET 2005
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 at 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
tlumley at u.washington.edu University of Washington, Seattle
More information about the R-help
mailing list