Re: [R] error in an univariate integration involving a bivariate normal CDF

2017-01-10 Thread William Dunlap via R-help
  integrand=function(xx,y=1,MU=MU,Sigma=Sigma)
{
  
dnorm(xx,mean=MU[1],sd=sqrt(Sigma[1,1]))*pmvnorm(lower=c(-Inf,-Inf),upper=c(xx,y),mean=MU,sigma=Sigma)

}

The integrand must be a function that returns a vector the length of
its first argument (integrate will pass it a short vector of input
values).  It looks like your function expects 'xx' to be a scalar.
You can use the Vectorize function to fix things up.


Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Jan 9, 2017 at 3:28 PM, Jingqin luo via R-help
 wrote:
> R users,I encountered some error message when trying a univariate integration 
> involving a bivariate normal CDF with mean MU and variance matrix Sigma. 
> Below are my code:MU=c(1,3)
> Sigma=matrix(c(1,0.5,0.5,1.5),2,2)
> integrand=function(xx,y=1,MU=MU,Sigma=Sigma)
>   {
> 
> dnorm(xx,mean=MU[1],sd=sqrt(Sigma[1,1]))*pmvnorm(lower=c(-Inf,-Inf),upper=c(xx,y),mean=MU,sigma=Sigma)
>
>   }
>   
> integrate(integrand,y=1,MU=MU,Sigma=Sigma,lower=-Inf,upper=Inf,subdivisions=1000)gave
>  : Error in checkmvArgs(lower = lower, upper = upper, mean = mean, corr = 
> corr, : ‘diag(sigma)’ and ‘lower’ are of different length.The error came from 
> the pmvnorm() part. I will appreciate any hints to this error.> sessionInfo()
> R version 3.3.1 (2016-06-21)
> Platform: x86_64-redhat-linux-gnu (64-bit)
> Running under: Red Hat Enterprise Linux Server release 6.2 (Santiago)
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>  [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
>  [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
>  [9] LC_ADDRESS=C   LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
>
> other attached packages:
>  [1] pbivnorm_0.6.0 ggplot2_1.0.0  pROC_1.8   copula_0.999-11
>  [5] mvtnorm_1.0-0  lcmix_0.3  nnls_1.4   MASS_7.3-45
>  [9] matrixStats_0.10.0 R.methodsS3_1.6.1  psych_1.6.9
>
> loaded via a namespace (and not attached):
>  [1] Rcpp_0.12.1  munsell_0.4.2mnormt_1.5-1 ADGofTest_0.3
>  [5] colorspace_1.2-4 pspline_1.0-16   lattice_0.20-29  stringr_0.6.2
>  [9] plyr_1.8.1   tcltk_3.3.1  tools_3.3.1  parallel_3.3.1
> [13] grid_3.3.1   gtable_0.1.2 digest_0.6.4 Matrix_1.1-4
> [17] reshape2_1.4 labeling_0.3 scales_0.2.4 gsl_1.9-10
> [21] stats4_3.3.1 stabledist_0.6-6 foreign_0.8-66   proto_0.3-10
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] error in an univariate integration involving a bivariate normal CDF

2017-01-10 Thread Jingqin luo via R-help
R users,I encountered some error message when trying a univariate integration 
involving a bivariate normal CDF with mean MU and variance matrix Sigma. Below 
are my code:MU=c(1,3)
Sigma=matrix(c(1,0.5,0.5,1.5),2,2)
integrand=function(xx,y=1,MU=MU,Sigma=Sigma)
  {

dnorm(xx,mean=MU[1],sd=sqrt(Sigma[1,1]))*pmvnorm(lower=c(-Inf,-Inf),upper=c(xx,y),mean=MU,sigma=Sigma)

  }
  
integrate(integrand,y=1,MU=MU,Sigma=Sigma,lower=-Inf,upper=Inf,subdivisions=1000)gave
 : Error in checkmvArgs(lower = lower, upper = upper, mean = mean, corr = corr, 
: ‘diag(sigma)’ and ‘lower’ are of different length.The error came from the 
pmvnorm() part. I will appreciate any hints to this error.> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server release 6.2 (Santiago)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C  
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C 
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C   

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 

other attached packages:
 [1] pbivnorm_0.6.0 ggplot2_1.0.0  pROC_1.8   copula_0.999-11   
 [5] mvtnorm_1.0-0  lcmix_0.3  nnls_1.4   MASS_7.3-45   
 [9] matrixStats_0.10.0 R.methodsS3_1.6.1  psych_1.6.9   

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.1  munsell_0.4.2mnormt_1.5-1 ADGofTest_0.3   
 [5] colorspace_1.2-4 pspline_1.0-16   lattice_0.20-29  stringr_0.6.2   
 [9] plyr_1.8.1   tcltk_3.3.1  tools_3.3.1  parallel_3.3.1  
[13] grid_3.3.1   gtable_0.1.2 digest_0.6.4 Matrix_1.1-4
[17] reshape2_1.4 labeling_0.3 scales_0.2.4 gsl_1.9-10  
[21] stats4_3.3.1 stabledist_0.6-6 foreign_0.8-66   proto_0.3-10

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.