An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111027/5f29f4e2/attachment.pl>
2 x 3 Probability under the null
8 messages · Jim Silverton, John Sorkin, (Ted Harding) +3 more
Windows XP
R 2.12
I am trying to understand how I can take a subroutine (i.e. function) I have written in Fortran, and call the function in R. I need to know (1) where I should store the Fortran subroutine (2) how to prepare the function for use in R, and (3) how to load and call the function.
There's a large literature that describes how to construct packages (including S Programming by Venables and Ripley, which I have referenced), but everything I have seen appears overly complex and generally geared to R running under Linux where as I run R under Windows XP.
I want to put R functions and Fortran routines in a library so they can be easily accessed. If, for example, I write a subroutine in Fortran called sqrtvector (n, vector), I want to compile it (to a .dll ?) and then put it in a library so subsequently I can code y <= sqrtvector(nn, x) in my R programs.
Thanks!
John
John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)
Confidentiality Statement:
This email message, including any attachments, is for th...{{dropped:6}}
On 27-Oct-11 04:09:46, Jim Silverton wrote:
I have a 2 x 3 matrix called snp and I want to compute the following probability: choose(sum(snp[,1]), snp[1,1]) * choose(sum(snp[,2]), snp[1,2]) * choose(sum(snp[,3]), snp[1,3])/choose(sum(snp), sum(snp[1,])) but I keep getting Infs and NaNs. Is there a function that can do this in R? -- Thanks, Jim.
Since 1/0 --> Inf, and 0/0 --> NaN, it seems likely that your data lead to zero denominators. However, true diagnosis needs to see what your data really are. What is a typical 2x3 matrix that gives such results? If this guess is correct, then no possible function in R can resolve the problem! For data where the problem does not arise, then you can of course write your own function to implement your code above for an arbitrary 2x3 matrix. Hoping this helps, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.harding at wlandres.net> Fax-to-email: +44 (0)870 094 0861 Date: 27-Oct-11 Time: 07:32:30 ------------------------------ XFMail ------------------------------
On 11-10-27 12:09 AM, Jim Silverton wrote:
I have a 2 x 3 matrix called snp and I want to compute the following probability: choose(sum(snp[,1]), snp[1,1]) * choose(sum(snp[,2]), snp[1,2]) * choose(sum(snp[,3]), snp[1,3])/choose(sum(snp), sum(snp[1,])) but I keep getting Infs and NaNs. Is there a function that can do this in R?
Work in the log scale. You're probably getting overflows. lchoose() calculates the log of choose(). Duncan Murdoch
On 10/27/2011 04:24 AM, John Sorkin wrote:
Windows XP R 2.12 I am trying to understand how I can take a subroutine (i.e. function) I have written in Fortran, and call the function in R. I need to know (1) where I should store the Fortran subroutine (2) how to prepare the function for use in R, and (3) how to load and call the function. There's a large literature that describes how to construct packages (including S Programming by Venables and Ripley, which I have referenced), but everything I have seen appears overly complex and generally geared to R running under Linux where as I run R under Windows XP.
Hi, I'm afraid that to some degree running Fortran code from R is complex. Take a look at the .Fortran functions. Another good tip is to take a look at an R package which includes a lot of Fortran and see how they organise their code. Linux is much more ready for these kinds of solutions, but probably you could get it to work under Windows. You need a compiler, set all kinds of enviroment variables etc. Running R under cygwin should make it possible to use the tutorials/books that are geared towards Linux, for Windows. good luck, Paul
I want to put R functions and Fortran routines in a library so they can be easily accessed. If, for example, I write a subroutine in Fortran called sqrtvector (n, vector), I want to compile it (to a .dll ?) and then put it in a library so subsequently I can code y <= sqrtvector(nn, x) in my R programs.
Thanks!
John
John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)
Confidentiality Statement:
This email message, including any attachments, is for ...{{dropped:20}}
On 11-10-27 8:02 AM, Paul Hiemstra wrote:
On 10/27/2011 04:24 AM, John Sorkin wrote:
Windows XP R 2.12 I am trying to understand how I can take a subroutine (i.e. function) I have written in Fortran, and call the function in R. I need to know (1) where I should store the Fortran subroutine (2) how to prepare the function for use in R, and (3) how to load and call the function. There's a large literature that describes how to construct packages (including S Programming by Venables and Ripley, which I have referenced), but everything I have seen appears overly complex and generally geared to R running under Linux where as I run R under Windows XP.
Hi, I'm afraid that to some degree running Fortran code from R is complex. Take a look at the .Fortran functions. Another good tip is to take a look at an R package which includes a lot of Fortran and see how they organise their code. Linux is much more ready for these kinds of solutions, but probably you could get it to work under Windows. You need a compiler, set all kinds of enviroment variables etc. Running R under cygwin should make it possible to use the tutorials/books that are geared towards Linux, for Windows.
I think nowadays many Linux distros are no more ready than Windows for this. On Linux, you'll likely need to install development libraries and tools; on Windows, the same. The advantage of Windows is that the tools have all been collected in one place (www.murdoch-sutherland.com/Rtools), so it's pretty easy to get everything going. Duncan Murdoch
good luck, Paul
I want to put R functions and Fortran routines in a library so they can be easily accessed. If, for example, I write a subroutine in Fortran called sqrtvector (n, vector), I want to compile it (to a .dll ?) and then put it in a library so subsequently I can code y<= sqrtvector(nn, x) in my R programs.
Thanks!
John
John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)
Confidentiality Statement:
This email message, including any attachments, is for ...{{dropped:20}}
______________________________________________ R-help at r-project.org mailing list 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.
On 10/27/2011 12:13 PM, Duncan Murdoch wrote:
On 11-10-27 8:02 AM, Paul Hiemstra wrote:
On 10/27/2011 04:24 AM, John Sorkin wrote:
Windows XP R 2.12 I am trying to understand how I can take a subroutine (i.e. function) I have written in Fortran, and call the function in R. I need to know (1) where I should store the Fortran subroutine (2) how to prepare the function for use in R, and (3) how to load and call the function. There's a large literature that describes how to construct packages (including S Programming by Venables and Ripley, which I have referenced), but everything I have seen appears overly complex and generally geared to R running under Linux where as I run R under Windows XP.
Hi, I'm afraid that to some degree running Fortran code from R is complex. Take a look at the .Fortran functions. Another good tip is to take a look at an R package which includes a lot of Fortran and see how they organise their code. Linux is much more ready for these kinds of solutions, but probably you could get it to work under Windows. You need a compiler, set all kinds of enviroment variables etc. Running R under cygwin should make it possible to use the tutorials/books that are geared towards Linux, for Windows.
I think nowadays many Linux distros are no more ready than Windows for this. On Linux, you'll likely need to install development libraries and tools; on Windows, the same. The advantage of Windows is that the tools have all been collected in one place (www.murdoch-sutherland.com/Rtools), so it's pretty easy to get everything going.
You are right. This might be my Linux heart and predjudice towards Windows speaking too loudly :)...altough I was really happy switching from Windows XP to Debian Linux during my PhD (couldn't resist promoting linux ;)). Paul
Duncan Murdoch
good luck, Paul
I want to put R functions and Fortran routines in a library so they
can be easily accessed. If, for example, I write a subroutine in
Fortran called sqrtvector (n, vector), I want to compile it (to a
.dll ?) and then put it in a library so subsequently I can code y<=
sqrtvector(nn, x) in my R programs.
Thanks!
John
John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)
Confidentiality Statement:
This email message, including any attachments, is for ...{{dropped:20}}
______________________________________________ R-help at r-project.org mailing list 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.
Paul Hiemstra, Ph.D. Global Climate Division Royal Netherlands Meteorological Institute (KNMI) Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39 P.O. Box 201 | 3730 AE | De Bilt tel: +31 30 2206 494 http://intamap.geo.uu.nl/~paul http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770
On 28/10/11 01:13, Duncan Murdoch wrote:
<SNIP>
I think nowadays many Linux distros are no more ready than Windows for this. On Linux, you'll likely need to install development libraries and tools; on Windows, the same. The advantage of Windows is that the tools have all been collected in one place (www.murdoch-sutherland.com/Rtools), so it's pretty easy to get everything going.
<SNIP>
Then how come Uwe Ligges provides a win.builder facility for Linux users to
build packages for Windoze, but there is no corresponding linux.builder
facility
for Windoze users to build packages for Linux? :-)
[Answer: There is no need, because package building is a breeze on Linux.
Even I can do it.]
cheers,
Rolf
P. S. And if Duncan hadn't gone to all the trouble and effort of
collecting the tools
in one place, building packages on Windoze would be impossible for
ordinary mortals.
R.