Two versions of the same function

5 views
Skip to first unread message

Asaf Weinstein

unread,
Sep 26, 2017, 11:39:10 AM9/26/17
to israel-r-user-group
Shalom,

This might be a silly question, but here it goes. 

I have a function "ratio" which I'm calling inside another function as follows:

ratio_normal <- function(w,delta,epsilon,sigma,rho=1){
  Fstar <- function(mu) w[1] * pnorm( mu,0,.1 ) + w[2] * pnorm( mu,0,1 ) + w[3] * pnorm( mu,0,3 )
  ratio(Fstar,delta,epsilon,sigma,rho=1)
}

The version above is working fine, but when I replace it with the more convenient form

ratio_normal <- function(w,delta,epsilon,sigma,rho=1){
  Fstar <- function(mu) sum( w * pnorm(mu,0,c(.1,1,3)) )
  ratio(Fstar,delta,epsilon,sigma,rho=1)
}

I get an error when I run it. Any idea why?

Thanks a lot and hope this was clear,

Asaf

Jonathan Rosenblatt

unread,
Sep 26, 2017, 12:38:20 PM9/26/17
to israel-r-user-group
Any chance w is not of length 3?

Also, here is a starter on debugging in R:




--
You received this message because you are subscribed to the Google Groups "Israel R User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-group+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
--
Jonathan Rosenblatt
Dept. of Industrial Engineering and Management
Ben Gurion University of the Negev

amit gal

unread,
Sep 26, 2017, 1:02:25 PM9/26/17
to israel-r-...@googlegroups.com
should have worked with longer and shorter w as well.
the code works for me (I used a very trivial ratio function that just calls F
maybe give us the error message or a bit more details on the definition of ratio

also, the call to ratio() wtih rho=1 is probably not what you mean, but rather you want rho=rho to pass the parameter from ratio_normal()




On Tue, Sep 26, 2017 at 7:37 PM, Jonathan Rosenblatt <joh...@bgu.ac.il> wrote:
Any chance w is not of length 3?

Also, here is a starter on debugging in R:



On Tue, Sep 26, 2017 at 6:39 PM, Asaf Weinstein <assafwe...@gmail.com> wrote:
Shalom,

This might be a silly question, but here it goes. 

I have a function "ratio" which I'm calling inside another function as follows:

ratio_normal <- function(w,delta,epsilon,sigma,rho=1){
  Fstar <- function(mu) w[1] * pnorm( mu,0,.1 ) + w[2] * pnorm( mu,0,1 ) + w[3] * pnorm( mu,0,3 )
  ratio(Fstar,delta,epsilon,sigma,rho=1)
}

The version above is working fine, but when I replace it with the more convenient form

ratio_normal <- function(w,delta,epsilon,sigma,rho=1){
  Fstar <- function(mu) sum( w * pnorm(mu,0,c(.1,1,3)) )
  ratio(Fstar,delta,epsilon,sigma,rho=1)
}

I get an error when I run it. Any idea why?

Thanks a lot and hope this was clear,

Asaf

--
You received this message because you are subscribed to the Google Groups "Israel R User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-group+unsubscribe...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
--
Jonathan Rosenblatt
Dept. of Industrial Engineering and Management
Ben Gurion University of the Negev

Asaf Weinstein

unread,
Sep 26, 2017, 8:12:27 PM9/26/17
to israel-r-user-group
I see. Thank you very much, Amit and Jonathan. 
("ratio" is a complicated function which involved numerical integration and root finding, so I guess it might be the source of problem)

Asaf

Reply all
Reply to author
Forward
0 new messages