Hello everyone. I am quite new to R and I would appreciate some help in figuring out what I am doing wrong. For the following code:> #with cost > > m.control=c(1.45,9.40,9.96,4.2,1.86,0.2) > m.sham=c(3.39,23.94,23.62,10.08,2.99,1.09) > > t.control=function(m, a){(1-exp(-a*m)*(1-(1/30)*m))} > t.sham=function(m, a, d){(1-exp(-a*(1-d)*m)*(1-(1/30)*m))} > > t.sham(2, 2, 0.1)[1] 0.9744979> t.control(2, 2)[1] 0.9829054> > #without cost > > m.control=c(1.45,9.40,9.96,4.2,1.86,0.2) > m.sham=c(3.39,23.94,23.62,10.08,2.99,1.09) > > t.control=function(m, a){(1-exp(-a*m))} > t.sham=function(m, a, d){(1-exp(-a*(1-d)*m))} > > t.sham(2, 2, 0.1)[1] 0.9726763> t.control(2, 2)[1] 0.9816844 As you can see the values I am getting for t.control and t.sham are larger in the "with cost" scenario and this shouldn't be the case. (the cost is 1-1/30*m). Is there something wrong I did when defining t.sham and t.control in the "with cost" section that I am failing to see? [[alternative HTML version deleted]]
On 31/01/2014 12:29 PM, Mathew Nagendran wrote:> Hello everyone. I am quite new to R and I would appreciate some help in figuring out what I am doing wrong. > > For the following code: > > > #with cost > > > > m.control=c(1.45,9.40,9.96,4.2,1.86,0.2) > > m.sham=c(3.39,23.94,23.62,10.08,2.99,1.09) > > > > t.control=function(m, a){(1-exp(-a*m)*(1-(1/30)*m))} > > t.sham=function(m, a, d){(1-exp(-a*(1-d)*m)*(1-(1/30)*m))} > > > > t.sham(2, 2, 0.1) > [1] 0.9744979 > > t.control(2, 2) > [1] 0.9829054 > > > > #without cost > > > > m.control=c(1.45,9.40,9.96,4.2,1.86,0.2) > > m.sham=c(3.39,23.94,23.62,10.08,2.99,1.09) > > > > t.control=function(m, a){(1-exp(-a*m))} > > t.sham=function(m, a, d){(1-exp(-a*(1-d)*m))} > > > > t.sham(2, 2, 0.1) > [1] 0.9726763 > > t.control(2, 2) > [1] 0.9816844 > > As you can see the values I am getting for t.control and t.sham are larger in the "with cost" scenario and this shouldn't be the case. (the cost is 1-1/30*m). Is there something wrong I did when defining t.sham and t.control in the "with cost" section that I am failing to see?You aren't reading your parentheses correctly. In the first case you're multipling only the exp() part by the cost, so you are subtracting a smaller number from 1, hence you get a larger result. Duncan Murdoch
Hi, Not sure if this is what you wanted: t.control=function(m, a){(1-exp(-a*m)*((1-(1/30))*m))} ? t.sham=function(m, a, d){(1-exp(-a*(1-d)*m)*((1-(1/30))*m))} t.control(2,2) #[1] 0.9645898 t.sham(2,2,0.1) #[1] 0.9471741 A.K. On Friday, January 31, 2014 12:29 PM, Mathew Nagendran <mathew.nagendran at mail.utoronto.ca> wrote: Hello everyone. I am quite new to R and I would appreciate some help in figuring out what I am doing wrong. For the following code:> #with cost > > m.control=c(1.45,9.40,9.96,4.2,1.86,0.2) > m.sham=c(3.39,23.94,23.62,10.08,2.99,1.09) > > t.control=function(m, a){(1-exp(-a*m)*(1-(1/30)*m))} > t.sham=function(m, a, d){(1-exp(-a*(1-d)*m)*(1-(1/30)*m))} > > t.sham(2, 2, 0.1)[1] 0.9744979> t.control(2, 2)[1] 0.9829054> > #without cost > > m.control=c(1.45,9.40,9.96,4.2,1.86,0.2) > m.sham=c(3.39,23.94,23.62,10.08,2.99,1.09) > > t.control=function(m, a){(1-exp(-a*m))} > t.sham=function(m, a, d){(1-exp(-a*(1-d)*m))} > > t.sham(2, 2, 0.1)[1] 0.9726763> t.control(2, 2)[1] 0.9816844 As you can see the values I am getting for t.control and t.sham are larger in the "with cost" scenario and this shouldn't be the case. (the cost is 1-1/30*m). Is there something wrong I did when defining t.sham and t.control in the "with cost" section that I am failing to see? ??? [[alternative HTML version deleted]] ______________________________________________ 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.