Skip to content
Prev 313202 / 398506 Next

Vectorizing integrate()

HI,

I can see ?runif(), ?rnorm() without a set seed.
A.K.

----- Original Message -----
From: David L Carlson <dcarlson at tamu.edu>
To: 'arun' <smartpink111 at yahoo.com>; "'Doran, Harold'" <HDoran at air.org>
Cc: 'R help' <r-help at r-project.org>; 'David Winsemius' <dwinsemius at comcast.net>
Sent: Friday, December 7, 2012 11:54 AM
Subject: RE: [R] Vectorizing integrate()

Must be a cut and paste issue. All three agree on the results but they are
different from those in arun's message:
+ fun <- function(u) 1/ (1 + exp(- (B[1] + B[2] * (x[j] + u)))) * dnorm(u,
0, sem1[j])
+ eta[j] <- integrate(fun, -Inf, Inf)$value
+ }
[1] 0.6586459 0.5565611 0.5226462 0.6824012 0.6908079 0.7578524 0.4715976
[8] 0.2165210 0.2378657 0.3492133
+? ? ?  (m + u)))) * dnorm(u, 0, s)
+? ? ?  -Inf, Inf, m=x[i], s=sem1[i])$value)
[1] 0.6586459 0.5565611 0.5226462 0.6824012 0.6908079 0.7578524 0.4715976
[8] 0.2165210 0.2378657 0.3492133
[1] TRUE
integrate(fun,-Inf,Inf,m=x[i],s=sem1[i])$value,1:nrow(X))
[1] 0.6586459 0.5565611 0.5226462 0.6824012 0.6908079 0.7578524 0.4715976
[8] 0.2165210 0.2378657 0.3492133
[1] TRUE

-------
David C