Skip to content

R-code for binormla distribution

6 messages · Spencer Graves, Jonathan Baron, Brian Ripley +1 more

#
What are you trying to do that requires binormal probabilities other 
than pmvnorm?

	  spencer graves
Nabil Channouf wrote:

            

  
    
#
Why do you say "we do not have the package that contains pmvnorm"? 
It is in library(mvtnorm), which you can get via CRAN (the Comprehensive 
R Archive Network).  If you are using Windows or a standard Linux of 
MacOS, "install.packages('mvtnorm')" should install it on your computer 
(unless you are using a computer with special protection that makes this 
difficult;  if you are using XEmacs, you should exit R under XEmacs and 
run "install.packages" from Rgui).  Then "library('mvtnorm')" should 
make it available to your R session.  If you are using some other 
operating system, you may need to access the source, but that's 
available via CRAN alse.

	  If you have not tried "install.packages", please do so.  If you have 
tried "install.packages" and can't make it work, please describe your 
operating system, etc., as explained in the posting guide! 
"www.R-project.org/posting-guide.html".

	  spencer graves
Nabil Channouf wrote:
> Dear  Mr. Graves,
 > i'm trying to write my own function with R, because we do not have the
 > package that contains pmvnorm and i need to compute the upper quadrant
 > area of the bivariate standard normal, or at least to know the details
 > of the function pmvnorm written in Splus or in R.
 > Thanks
Spencer Graves wrote:

  
    
#
There probably is a way under Linux to install a contributed package 
in your local directory.  I don't know how, but if you read the 
documentation on "download.packages" and "install.packages", you might 
be able to do it without bothering your Info Tech department.  I know 
there is a way, and with luck someone who knows will respond to this 
email.  If you try something with "download.packages" and 
"install.packages", and you can't make it work, please tell us what you 
try and what doesn't work.  Maybe someone who uses R on Linux will 
respond.  If not, ask your Info Tech department.

	  Spencer Graves
Nabil Channouf wrote:
> Mr Graves,
 > we are working with linux and it is so complicated to install any thing,
 > it should be via the informaticians of the department and we have to
 > make a request and wait. I will ask them to do it on monday.
 > Thank you so much
Spencer Graves wrote:

            

  
    
#
On Sun, 2 Oct 2005, Jonathan Baron wrote:

            
But you still need to ensure that library() can find the packages.


I think the simplest way is that we have set up by default for new R 
users:

1) Set the environment variable R_LIBS.  For a site in 
R_HOME/etc/Renviron.site, or for a user in ~/.Renviron.  For example,
include the line

R_LIBS=~/R/library

2) Ensure that this directory exists, e.g.

mkdir -p ~/R/library

(If it does not exist the setting will be ignored, so it is safe to set it 
for all users.)

3) Use install.packages() inside R.  This will by default use the first 
element in .libPaths(), which will be ~/R/library.  Suggest to users that 
they use would do best to use

install.packages(pkgs, .libPaths()[1], dependencies = TRUE)

when they want to add packages, and update.packages(.libPaths()[1]) to 
update the packages they have installed.

Note that this works for Windows users too (although using ~ is perhaps 
dependent on setting HOME:  our Windows default use the network drive P: 
instead).
#
Jon> Try
    Jon> R CMD INSTALL -l lib pkgs

    Jon> The help file is in the utils package.  I'm sure this is
    Jon> documented in the manual too.

yes, and yes.

The other thing people like the original poster often "forget" is
to subsequently *use* the local library {remember: a library is
directory (aka "folder") of installed packages}:

Either use
       library("mvtnorm", lib.loc = <path.to.local.library>)

every time you use the locally installed package, or rather
add the  local library to the libraries that are always searched
through.  There are several ways to do so in unix-alikes:
- Setting R_LIBS in (one of) the Renviron files;
- Calling .libPaths() in (one of) your Rprofile (files) or in
  other startup code
- <<more ways, but these are less recommended>>

Read ?Startup , ?.libPaths (and ?library) for more info.

Regards,
Martin Maechler