[R] Managing axis labels
Dear R-users, I would like to ask probably a silly thing. For some reason, I need x-axis and y-axis labels to be of different size. Here is a little example where I want "ϑ" to appear bigger than "Concentration". I have tried in the following way, but it is not working. x<-seq(1,10,1) y<-seq(2,20,2) plot(x, y, xlab=expression(vartheta), ylab="Concentration", cex.axis=1.5) axis(1, cex.lab=3.0) axis(2, cex.lab=2.0) Any suggestion will be much appreciated. Kind Regards, Jamil. [[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.
Re: [R] No visible binding for global variable
Dear Prof John, I have got the points now. Many thanks for your suggestions. Regards, Jamil. On 28 January 2017 at 00:27, Fox, John <j...@mcmaster.ca> wrote: > Dear Jamil, > > Presumably, the variables alloc.dose, r0, r1, and r2 will exist in the > global environment when you call the compiled function lf1.c(), but didn’t > exist when you compiled the function. If so, then lf1.c() should work > properly despite the notes (not errors, or even warnings) that was printed. > > On the other hand, relying on global data in a function is poor > programming style — it would be better to make alloc.dose, etc., arguments > to the function. As well, if you’re compiling the function to improve > efficiency, then you probably also want to compile psi0(), etc. > > I hope that this helps, > John > > John Fox > Sen. William McMaster Professor of Social Statistics > McMaster University > Hamilton, Ontario, Canada > Web: http::/socserv.mcmaster.ca/jfox > > > On Jan 27, 2017, at 10:43 AM, Naser Jamil <jamilnase...@gmail.com> > wrote: > > > > Dear R-users, > > I would like to seek your suggestion. I have the following code which > runs > > smoothly. But when I compile the function (lf1.c), it shows "no visible > > binding for global variable" for some of the arguments. > > > > ### > > > > library(compiler) > > > > > > psi0<-function(theta1,theta2,theta3,theta4,x){ > > z1<-exp(theta1+theta2*x) > > z2<-exp(theta3+theta4*x) > > 1/((1+z1)*(1+z2)) > > } > > > > psi1<-function(theta1,theta2,theta3,theta4,x){ > > z1<-exp(theta1+theta2*x) > > z2<-exp(theta3+theta4*x) > > z1/((1+z1)*(1+z2)) > > } > > psi2<-function(theta3,theta4,x) { > > z2<-exp(theta3+theta4*x) > > z2/(1+z2) > >} > > > > > > > > lf1<-function(w) { > > v<-1 > > w1<-w[1] > > w2<-w[2] > > w3<-w[3] > > w4<-w[4] > > for (i in 1:length(alloc.dose)) { > > dose.i<-alloc.dose[i] > > r0.i<-r0[i] > > r1.i<-r1[i] > > r2.i<-r2[i] > > z1<-exp(w1+w2*dose.i) > > z2<-exp(w3+w4*dose.i) > > psi0<-1/((1+z1)*(1+z2)) > > psi1<-z1*psi0 > > v<-v*(psi0^r0.i)*(psi1^r1.i)*((1-psi0-psi1)^r2.i) > > } > > return(v) > > } > > > > > > lf1.c<-cmpfun(lf1) > > > > ### > > > > May I know how to avoid this message? If I leave the code as it is, will > > that affect the result anyway? > > > > Thanks in advance. > > > > > > Regards, > > Jamil. > > > > [[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. > > > > > > [[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] No visible binding for global variable
Dear R-users, I would like to seek your suggestion. I have the following code which runs smoothly. But when I compile the function (lf1.c), it shows "no visible binding for global variable" for some of the arguments. ### library(compiler) psi0<-function(theta1,theta2,theta3,theta4,x){ z1<-exp(theta1+theta2*x) z2<-exp(theta3+theta4*x) 1/((1+z1)*(1+z2)) } psi1<-function(theta1,theta2,theta3,theta4,x){ z1<-exp(theta1+theta2*x) z2<-exp(theta3+theta4*x) z1/((1+z1)*(1+z2)) } psi2<-function(theta3,theta4,x) { z2<-exp(theta3+theta4*x) z2/(1+z2) } lf1<-function(w) { v<-1 w1<-w[1] w2<-w[2] w3<-w[3] w4<-w[4] for (i in 1:length(alloc.dose)) { dose.i<-alloc.dose[i] r0.i<-r0[i] r1.i<-r1[i] r2.i<-r2[i] z1<-exp(w1+w2*dose.i) z2<-exp(w3+w4*dose.i) psi0<-1/((1+z1)*(1+z2)) psi1<-z1*psi0 v<-v*(psi0^r0.i)*(psi1^r1.i)*((1-psi0-psi1)^r2.i) } return(v) } lf1.c<-cmpfun(lf1) ### May I know how to avoid this message? If I leave the code as it is, will that affect the result anyway? Thanks in advance. Regards, Jamil. [[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.
Re: [R] Superimposing graphs
Dear Richard and Duncan, your suggestions are absolutely serving what I need. But I would like to see x-axis to be up to 30 instead of 20. Do you have any suggestion on that? Many thanks for your kind help. Regards, Jamil. On 12 August 2014 01:22, Duncan Mackay dulca...@bigpond.com wrote: Hi If you want a 1 package and 1 function approach try this xyplot(conc ~ time | factor(subject, levels = c(2,1,3)), data = data.d, par.settings = list(strip.background = list(col = transparent)), layout = c(3,1), aspect = 1, type = c(b,g), scales = list(alternating = FALSE), panel = function(x,y,...){ panel.xyplot(x,y,...) # f1-function(x,v,cl,t) # (x/v)*exp(-(cl/v)*t) f1(0.5,0.5,0.06,t), panel.curve((0.5/0.5)*exp(-(0.06/0.5)*x),0,30) } ) # par.settings ... if you are publishing show text better # with factor if you want 1:3 omit the levels # has advantage of doing more things than in groupedData as Doug Bates has said Regards Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Naser Jamil Sent: Monday, 11 August 2014 19:06 To: R help Subject: [R] Superimposing graphs Dear R-user, May I seek your help to sort out a little problem. I have the following codes to draw two graphs. I want to superimpose the second one on each of the first one. library(nlme) subject-c(1,1,1,2,2,2,3,3,3) time-c(0.0,5.4,21.0,0.0,5.4,21.0,0.0,5.4,21.0) con.cohort-c(1.10971703,0.54535512,0.07176724,0.75912539,0.47825282, 0.10593292,1.20808375,0.47638394,0.02808967) data.d=data.frame(subject=subject,time=time,conc=con.cohort) grouped.data-groupedData(formula=conc~time | subject, data =data.d) plot(grouped.data) ## f1-function(x,v,cl,t) { (x/v)*exp(-(cl/v)*t) } t-seq(0,30, .01) plot(t,f1(0.5,0.5,0.06,t),type=l,pch=18, ylim=c(), xlab=time, ylab=conc) ### Any suggestion will really be helpful. Regards, Jamil. [[alternative HTML version deleted]] __ R-help@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. [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Superimposing graphs
That's perfect! Many thanks. On 12 August 2014 14:32, Richard M. Heiberger r...@temple.edu wrote: Yes, use xlim=c(0, 30) in your definition of P1 On Tue, Aug 12, 2014 at 7:26 AM, Naser Jamil jamilnase...@gmail.com wrote: Dear Richard and Duncan, your suggestions are absolutely serving what I need. But I would like to see x-axis to be up to 30 instead of 20. Do you have any suggestion on that? Many thanks for your kind help. Regards, Jamil. On 12 August 2014 01:22, Duncan Mackay dulca...@bigpond.com wrote: Hi If you want a 1 package and 1 function approach try this xyplot(conc ~ time | factor(subject, levels = c(2,1,3)), data = data.d, par.settings = list(strip.background = list(col = transparent)), layout = c(3,1), aspect = 1, type = c(b,g), scales = list(alternating = FALSE), panel = function(x,y,...){ panel.xyplot(x,y,...) # f1-function(x,v,cl,t) # (x/v)*exp(-(cl/v)*t) f1(0.5,0.5,0.06,t), panel.curve((0.5/0.5)*exp(-(0.06/0.5)*x),0,30) } ) # par.settings ... if you are publishing show text better # with factor if you want 1:3 omit the levels # has advantage of doing more things than in groupedData as Doug Bates has said Regards Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org ] On Behalf Of Naser Jamil Sent: Monday, 11 August 2014 19:06 To: R help Subject: [R] Superimposing graphs Dear R-user, May I seek your help to sort out a little problem. I have the following codes to draw two graphs. I want to superimpose the second one on each of the first one. library(nlme) subject-c(1,1,1,2,2,2,3,3,3) time-c(0.0,5.4,21.0,0.0,5.4,21.0,0.0,5.4,21.0) con.cohort-c(1.10971703,0.54535512,0.07176724,0.75912539,0.47825282, 0.10593292,1.20808375,0.47638394,0.02808967) data.d=data.frame(subject=subject,time=time,conc=con.cohort) grouped.data-groupedData(formula=conc~time | subject, data =data.d) plot(grouped.data) ## f1-function(x,v,cl,t) { (x/v)*exp(-(cl/v)*t) } t-seq(0,30, .01) plot(t,f1(0.5,0.5,0.06,t),type=l,pch=18, ylim=c(), xlab=time, ylab=conc) ### Any suggestion will really be helpful. Regards, Jamil. [[alternative HTML version deleted]] __ R-help@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. [[alternative HTML version deleted]] __ R-help@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. [[alternative HTML version deleted]] __ R-help@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.
[R] Superimposing graphs
Dear R-user, May I seek your help to sort out a little problem. I have the following codes to draw two graphs. I want to superimpose the second one on each of the first one. library(nlme) subject-c(1,1,1,2,2,2,3,3,3) time-c(0.0,5.4,21.0,0.0,5.4,21.0,0.0,5.4,21.0) con.cohort-c(1.10971703,0.54535512,0.07176724,0.75912539,0.47825282, 0.10593292,1.20808375,0.47638394,0.02808967) data.d=data.frame(subject=subject,time=time,conc=con.cohort) grouped.data-groupedData(formula=conc~time | subject, data =data.d) plot(grouped.data) ## f1-function(x,v,cl,t) { (x/v)*exp(-(cl/v)*t) } t-seq(0,30, .01) plot(t,f1(0.5,0.5,0.06,t),type=l,pch=18, ylim=c(), xlab=time, ylab=conc) ### Any suggestion will really be helpful. Regards, Jamil. [[alternative HTML version deleted]] __ R-help@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.
Re: [R] skipping an error message
Hi Jim, Thanks for the suggestion. What I understand is trying something like tryCatch(nlme(conc~f2(dose,Theta1,Theta 2,Theta3,t), fixed=Theta1+Theta2+Theta3~1, data=grouped.data, random=Theta1+Theta2+Theta3~1, start=list(fixed=ini.pkpara)) ) Is that correct? Once again thanks. Regards, Jamil. On 6 April 2014 23:51, Jim Lemon j...@bitwrit.com.au wrote: On 04/06/2014 08:21 PM, Naser Jamil wrote: Dear R-user, May I seek your suggestion on an issue. I'm fitting non-linear mixed effects model as a part of my large R program. But sometimes I get error messages from it and the code stops working. In such cases, I want to skip the iterations and want to move to the next iteration ignoring all the subsequent computations. The following is only that part of the code which fits the mixed effects model. I tried with tryCatch as shown below, but it's not serving my purpose. I guess something is wrong in my approach. ### grouped.data-groupedData(formula = conc ~ t | subject, data = data.d) model.d-nlme(conc~f2(dose,Theta1,Theta2,Theta3,t), fixed=Theta1+Theta2+Theta3~1, data=grouped.data, random=Theta1+Theta2+Theta3~1, start=list(fixed=ini.pkpara)) summ-summary(model.d) # summary of the model tryCatch(summ, error = function() next) ### Hi Jamil, I think you have to pass the expression: nlme(conc~f2(dose,Theta1,Theta2,Theta3,t), fixed=Theta1+Theta2+Theta3~1, data=grouped.data, random=Theta1+Theta2+Theta3~1, start=list(fixed=ini.pkpara)) not the result of the expression. Jim [[alternative HTML version deleted]] __ R-help@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.
Re: [R] skipping an error message
Hi Bill, Many thanks for such a nice illustration. I tried the first option and it's working. More specifically, model.d - tryCatch(nlme(blah blah blah), error=function(e)NULL) if(!is.null(model.d)) { furtherProcessTheModel(model.d) } But instead of !is.null, I want something so that when 'model.d' under tryCatch is OK, I can do further computations based on its results. Once again thanks. Regards, Jamil On 7 April 2014 16:35, William Dunlap wdun...@tibco.com wrote: Thanks for the suggestion. What I understand is trying something like tryCatch(nlme(conc~f2(dose,Theta1,Theta 2,Theta3,t), fixed=Theta1+Theta2+Theta3~1, data=grouped.data, random=Theta1+Theta2+Theta3~1, start=list(fixed=ini.pkpara)) ) Is that correct? No. Executing tryCatch(someExpression) is equivalent to executing just someExpression because you haven't set up any condition handlers. If you did something like model.d - tryCatch(nlme(blah blah blah), error=function(e)NULL) then model.d would contain the return value of the call to nlme if all went well and NULL otherwise. You could then use if(!is.null(model.d)) { furtherProcessTheModel(model.d) } to do things that only make sense when the model could be fitted. Now NULL may be a legitimate return value from a function and it also doesn't give you any hint about what went wrong, so you could have the error handler return an object of a class that no normal function would return and have it contain the error message. E.g., model.d - tryCatch(nlme(notAFormula), error=function(e)structure(conditionMessage(e),class=ERROR)) and then you can test for errors with if (inherits(model.d, ERROR)) { message(Iteration , i, failed with error: , model.d) } else { furtherProcessTheModel(model.d) } You could also look at the error message that model.d contains in that case. The try() function is essentially that call to tryCatch: it gives its error output the class 'try-error'. Bill Dunlap TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Naser Jamil Sent: Monday, April 07, 2014 1:46 AM To: Jim Lemon Cc: R help Subject: Re: [R] skipping an error message Hi Jim, Thanks for the suggestion. What I understand is trying something like tryCatch(nlme(conc~f2(dose,Theta1,Theta 2,Theta3,t), fixed=Theta1+Theta2+Theta3~1, data=grouped.data, random=Theta1+Theta2+Theta3~1, start=list(fixed=ini.pkpara)) ) Is that correct? Once again thanks. Regards, Jamil. On 6 April 2014 23:51, Jim Lemon j...@bitwrit.com.au wrote: On 04/06/2014 08:21 PM, Naser Jamil wrote: Dear R-user, May I seek your suggestion on an issue. I'm fitting non-linear mixed effects model as a part of my large R program. But sometimes I get error messages from it and the code stops working. In such cases, I want to skip the iterations and want to move to the next iteration ignoring all the subsequent computations. The following is only that part of the code which fits the mixed effects model. I tried with tryCatch as shown below, but it's not serving my purpose. I guess something is wrong in my approach. ### grouped.data-groupedData(formula = conc ~ t | subject, data = data.d) model.d-nlme(conc~f2(dose,Theta1,Theta2,Theta3,t), fixed=Theta1+Theta2+Theta3~1, data=grouped.data, random=Theta1+Theta2+Theta3~1, start=list(fixed=ini.pkpara)) summ-summary(model.d) # summary of the model tryCatch(summ, error = function() next) ### Hi Jamil, I think you have to pass the expression: nlme(conc~f2(dose,Theta1,Theta2,Theta3,t), fixed=Theta1+Theta2+Theta3~1, data=grouped.data, random=Theta1+Theta2+Theta3~1, start=list(fixed=ini.pkpara)) not the result of the expression. Jim [[alternative HTML version deleted]] __ R-help@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. [[alternative HTML version deleted]] __ R-help@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.
[R] skipping an error message
Dear R-user, May I seek your suggestion on an issue. I'm fitting non-linear mixed effects model as a part of my large R program. But sometimes I get error messages from it and the code stops working. In such cases, I want to skip the iterations and want to move to the next iteration ignoring all the subsequent computations. The following is only that part of the code which fits the mixed effects model. I tried with tryCatch as shown below, but it's not serving my purpose. I guess something is wrong in my approach. ### grouped.data-groupedData(formula = conc ~ t | subject, data = data.d) model.d-nlme(conc~f2(dose,Theta1,Theta2,Theta3,t), fixed=Theta1+Theta2+Theta3~1, data=grouped.data, random=Theta1+Theta2+Theta3~1, start=list(fixed=ini.pkpara)) summ-summary(model.d) # summary of the model tryCatch(summ, error = function() next) ### Any suggestion will be more than great. Thank you very much. Regards, Jamil [[alternative HTML version deleted]] __ R-help@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.
Re: [R] functions and matrices
Thanks to everyone for such nice illustrations. It will guide me for sure. On 2 July 2013 02:56, David Winsemius dwinsem...@comcast.net wrote: With permission I offer this exchange. Rolf and I have different notions of what u %*% v should mean, but the arbiter is obviously the original poster: Begin forwarded message: From: David Winsemius dwinsem...@comcast.net Subject: Re: [R] functions and matrices Date: July 1, 2013 6:21:09 PM PDT To: Rolf Turner rolf.tur...@xtra.co.nz On Jul 1, 2013, at 5:09 PM, Rolf Turner wrote: On 02/07/13 11:37, David Winsemius wrote: On Jul 1, 2013, at 3:32 PM, Rolf Turner wrote: Basically R does things *numerically* and what you want to do really amounts to symbolic manipulation. Of course R could be cajoled into doing it --- see fortune(Yoda) --- but probably only with a great deal of effort and code-writing. OTOH you could quite easily write a function that would calculate det(u%*%v)(x) for any given numerical value of x: foo - function(a,b,x){ a1 - apply(a,c(1,2),function(m,x){m[[1]](x)},x=x) b1 - apply(b,c(1,2),function(m,x){m[[1]](x)},x=x) det(a1%*%b1) } Then doing foo(u,v,2) I would have thought that (u %*% v) would be: u[1,1]( v[1,1](x) ) + u[1,2]( v[2,1](x) ) u[1,1]( v[1,2](x) ) + u[1,2]( v[2,2](x) ) u[2,1]( v[1,1](x) ) + u[2,2]( v[2,1](x) ) u[2,1]( v[2,1](x) ) + u[2,2]( v[2,2](x) ) (Crossing my fingers that I got the row and column conventions correct for matrix multiplication.) SNIP Not quite sure what you're getting at here. It looks to me that you are calculating the *composition* of the functions rather than their *product*. Exactly. That is how I understood successive application of functions embedded in matrices . The symbol used in my differential topology course lo those 40 years ago was an open circle, but I assumed the OP wanted something along those lines to perform a composite mapping: compose - function(u, v, x) matrix( c( u[1,1][[1]]( v[1,1][[1]](x) ) + u[1,2][[1]]( v[2,1][[1]](x) ) , u[1,1][[1]]( v[1,2][[1]](x) ) + u[1,2][[1]]( v[2,2][[1]](x) ), u[2,1][[1]]( v[1,1][[1]](x) ) + u[2,2][[1]]( v[2,1][[1]](x) ), u[2,1][[1]]( v[2,1][[1]](x) ) + u[2,2][[1]]( v[2,2][[1]](x) ) ), 2,2,byrow=TRUE) compose(u,v,2) [,1][,2] [1,] 751332 [2,] 5427 1680128 (Noting that I may have reversed the roles of u and v.) I.e. you are taking the (i,j)th entry of u%*%v (evaluated at x) to be the sum over k of u[i,k](v[k,j](x)) This is not what I understood the OP to want. I assumed he wanted the product of the function values rather than the composition of the functions, i.e. that he wanted the (i,j)th entry to be the sum over k of u[i,k](x) * v[k,j](x) which is what my function provides. This seems to me to be the most reasonable interpretation, but I could be wrong. BTW --- you cannot actually do u[i,k](x). E.g. u[1,2](2) gives Error: attempt to apply non-function. One needs to do u[1,2][[1]](2) (which gives 4, as it should). Yes. I was playing fast and loose with notation. I didn't think the code would really run as offered.I was a bit surprise that this worked, but I suppose you bear credit (and blame?) for pushing my program closer to completion. v[1,1][[1]]( u[1,1][[1]]( 2 )) [1] 11 Any problem with me copying this to the list? cheers, Rolf Best; David Winsemius Alameda, CA, USA David Winsemius Alameda, CA, USA [[alternative HTML version deleted]] __ R-help@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.
[R] functions and matrices
Dear R-user, May I seek your help, please. I have two matrices, u and v, elements of which are some functions of x. I just want to multiply them and express the determinant of the resulting matrix as a function of x and of course, this is for some reason. Actually the original problem has more matrices to multiply and I'm just wondering whether I can simplify it anyway through the R codes. It may even be non-sense, but just want to hear from you. The below is the code. - f1-function(x) {x} f2-function(x) {x^2} f3-function(x) {x^3} f4-function(x) {x^4} f5-function(x) {x^2+7} f6-function(x) {x^3+14*x} f7-function(x) {x^2+2*x} f8-function(x) {x^4+10*x} u-matrix(c(f1,f2,f3,f4), nrow=2, ncol=2, byrow=TRUE) v-matrix(c(f5,f6,f7,f8), nrow=2, ncol=2, byrow=TRUE) det(u %*% v) # Is that possible? Any suggestion will be more than great! Regards, Jamil. [[alternative HTML version deleted]] __ R-help@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.
[R] R for windows GUI front-end has stopped working
Dear R-users, May I seek your attention please! I have a long R code, which runs most of the time quite nicely and provides necessary results. However, often it provides a message like R for windows GUI front-end has stopped working and just stops working. I'm running the program in Windows 2007. Is there any way out? Any suggestion in this regard will be more than great!! Many thanks for your time. Regards, Jamil. [[alternative HTML version deleted]] __ R-help@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.
[R] scan in R
Dear R-user, May I seek your help over a issue, probably a simple one. I just one to scan the following numbers, avoiding [1]s, [2]. By the way, I know how to scan numbers in the absence of such [1] and [2]. -- [1] 18 18 17 14 17 13 13 18 13 16 16 14 [1] 12 19 15 21 13 17 10 13 18 14 17 13 [2] 13 15 20 14 18 15 10 12 20 17 17 17 -- Any suggestion would be more than great! Regards, Jamil. [[alternative HTML version deleted]] __ R-help@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.
[R] scanning data in R
Dear R-user, May I seek your suggestion. I have a data file 'stop' to be scanned in R. But I want to ignore one specific number '21' there. Putting differently, I want to get all numbers in the file except 21. Is there any command to achieve it? -- b-scan(F:\\stop.txt) -- Many thanks for your kind attention. Regards, Jamil. 15 15 16 15 17 16 16 15 17 15 16 17 19 17 19 15 16 16 19 18 19 17 17 19 16 17 16 20 15 16 16 15 18 19 17 18 16 18 16 17 21 21 17 15 15 20 16 20 17 21 19 15 15 15 18 20 16 17 16 15 16 15 16 16 18 16 15 21 20 15 16 17 18 18 20 17 18 18 21 16 15 16 20 17 19 17 18 19 17 21 21 16 15 19 21 15 20 20 16 16 20 18 21 21 15 15 19 15 16 15 17 15 21 20 16 15 16 16 18 17 16 18 16 16 16 21 16 15 20 16 19 17 14 17 15 16 15 17 16 15 15 20 15 16 15 15 16 15 20 19 15 15 17 17 15 18 16 15 14 21 19 20 15 17 15 15 17 19 15 15 16 18 17 16 16 16 16 18 21 15 16 16 21 19 17 15 16 15 18 16 20 17 16 16 21 15 17 20 21 16 16 17 21 16 16 20 19 17 15 16 18 16 16 15 16 18 19 16 15 21 20 19 20 20 20 16 18 16 15 20 16 16 18 19 16 18 21 16 21 19 19 17 18 15 18 16 19 17 20 20 16 18 16 19 20 21 15 16 18 19 16 17 16 15 17 16 15 21 16 15 18 18 15 21 19 16 19 15 15 17 18 17 16 15 16 18 18 19 17 16 21 16 19 16 15 16 20 17 17 21 21 20 16 17 19 16 15 19 18 17 15 15 15 19 20 18 21 16 15 15 20 20 17 19 15 19 16 15 15 19 16 16 19 15 15 19 18 21 15 15 18 21 16 16 17 17 16 15 18 16 15 20 17 20 15 16 15 15 20 15 16 17 16 17 16 21 17 18 17 15 20 18 16 17 16 17 15 15 17 20 17 18 15 16 20 16 15 15 18 16 18 16 18 15 16 18 15 17 18 18 16 15 19 16 19 21 15 20 17 18 15 16 19 17 16 18 18 15 19 15 15 17 15 19 19 16 20 16 16 15 19 15 16 15 16 15 15 17 20 15 20 16 20 15 17 16 15 16 16 16 17 16 16 21 21 15 15 17 16 16 19 20 16 16 16 16 15 16 16 20 16 16 20 18 19 15 21 16 15 15 21 20 20 19 17
Re: [R] scanning data in R
Many thanks, Prof. David. It's exactly what I wanted! On 3 April 2013 17:26, David L Carlson dcarl...@tamu.edu wrote: You can certainly do it after scanning all the numbers in with b - scan(F:\\stop.txt, what=integer()) b - b[b!=21] -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Naser Jamil Sent: Wednesday, April 03, 2013 4:33 AM To: R help Subject: [R] scanning data in R Dear R-user, May I seek your suggestion. I have a data file 'stop' to be scanned in R. But I want to ignore one specific number '21' there. Putting differently, I want to get all numbers in the file except 21. Is there any command to achieve it? -- b-scan(F:\\stop.txt) -- Many thanks for your kind attention. Regards, Jamil. [[alternative HTML version deleted]] __ R-help@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.
[R] vertical lines in R plot
Dear All, May I seek your suggestion on a simple issue. I want to draw vertical lines at some positions in the following R plot. To be more specific, I wish to draw vertical lines at d=c(5.0,5.5,6) and they should go till p=c(0.12,0.60,0.20) . I haven't found any way out, though made several attempts. Please run the following commands first if you are interested in! ### psi1-function(alpha1,beta1,alpha2,beta2,d){ exp(alpha1+beta1*d)/((1+exp(alpha1+beta1*d))*(1+exp(alpha2+beta2*d))) } alpha1--3.5 beta1-1 alpha2--6 beta2-0.72 d-seq(0.5,10,0.01) plot(d,psi1(alpha1,beta1,alpha2,beta2,d),type=l,pch=18, ylim=c(0,1), xlab=Dose, ylab=Probabilitty) ## Many thanks for the help! Regards, Jamil. [[alternative HTML version deleted]] __ R-help@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.
Re: [R] vertical lines in R plot
Thank you guys. It was really worthy! On 11 March 2013 16:10, William Dunlap wdun...@tibco.com wrote: Also, type=h, in plot(), points(), or lines() draws vertical line segments between (x,y) and (x,0). E.g., points(x=c(5.0,5.5,6), y=c(0.12,0.60,0.20), type=h) does the same as segments(x0=c(5.0,5.5,6), y0=c(0,0,0), x1=c(5.0,5.5,6), y1=c(0.12,0.60,0.20)) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Sarah Goslee Sent: Monday, March 11, 2013 8:49 AM To: Naser Jamil Cc: R help Subject: Re: [R] vertical lines in R plot Like this: segments(x0=c(5.0,5.5,6), y0=c(0,0,0), x1=c(5.0,5.5,6), y1=c(0.12,0.60,0.20)) If you wanted them to extend the entire height of the plot, abline(v=c(5.0,5.5,6)) is simpler. Thanks for the reproducible example, Sarah On Mon, Mar 11, 2013 at 10:10 AM, Naser Jamil jamilnase...@gmail.com wrote: Dear All, May I seek your suggestion on a simple issue. I want to draw vertical lines at some positions in the following R plot. To be more specific, I wish to draw vertical lines at d=c(5.0,5.5,6) and they should go till p=c(0.12,0.60,0.20) . I haven't found any way out, though made several attempts. Please run the following commands first if you are interested in! ### psi1-function(alpha1,beta1,alpha2,beta2,d){ exp(alpha1+beta1*d)/((1+exp(alpha1+beta1*d))*(1+exp(alpha2+beta2*d))) } alpha1--3.5 beta1-1 alpha2--6 beta2-0.72 d-seq(0.5,10,0.01) plot(d,psi1(alpha1,beta1,alpha2,beta2,d),type=l,pch=18, ylim=c(0,1), xlab=Dose, ylab=Probabilitty) ## Many thanks for the help! Regards, Jamil. -- Sarah Goslee http://www.functionaldiversity.org __ R-help@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. [[alternative HTML version deleted]] __ R-help@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.
[R] Percentages in bar plot
Dear R-users, Though it's a silly thing to ask, but I'm not getting a way out. I wish to find the percentage distribution for a data vector 'stop'. The coomand below is giving the frequency distribution. May I know the option to see the percentages instead of frequencies. Similarly, what option I should put in a histogram plot to see the percentages instead of frequencies? - stop-c(8,6,6,6,8,6,6,8,8,6,6,6,8,8,8) barplot(table(stop)) Many thanks for your time. Regards, Jamil. [[alternative HTML version deleted]] __ R-help@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.
[R] Integration in R
Hi R-users. I'm having difficulty with an integration in R via the package cubature. I'm putting it with a simple example here. I wish to integrate a function like: f(x1,x2)=2/3*(x1+x2) in the interval 0x1x27. To be sure I tried it by hand and got 114.33, but the following R code is giving me 102.6667. --- library(cubature) f-function(x) { 2/3 * (x[1] + x[2] ) } adaptIntegrate(f, lowerLimit = c(0, 0), upperLimit = c(x[2],7)) --- I guess something is wrong with the way I have assigned limits in my codes. May I seek some advice from you. Many thanks. Regards, Jamil. [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Integration in R
Thanks. But then how to implement condition like 0x1x27? I would be happy to know that. On 8 January 2013 18:41, David Winsemius dwinsem...@comcast.net wrote: Please reply on list. On Jan 8, 2013, at 10:27 AM, Naser Jamil wrote: Hi David, x[2] is the second variable, x2. It comes from the condition 0x1x27. No, it doesn't come from those conditions. It is being grabbed from some x-named object that exists in your workspace. If your limits were 7 in both dimensions, then the code should be: adaptIntegrate(f, lowerLimit = c(0, 0), upperLimit = c(7,7)) # $integral [1] 228.6667 (At this point I was trusting R's calculus abilities more than yours. I wasn't too trusting of mine either, and so tried seeing if Wolfram Alpha would accept this expression: integrate 2/3 (x+y) over 0 x7, 0y7 ; which it did and calculating the decimal expansion of the exact fraction: 686/3 [1] 228.6667 -- David. Thanks. On 8 January 2013 18:11, David Winsemius dwinsem...@comcast.net wrote: On Jan 8, 2013, at 9:43 AM, Naser Jamil wrote: Hi R-users. I'm having difficulty with an integration in R via the package cubature. I'm putting it with a simple example here. I wish to integrate a function like: f(x1,x2)=2/3*(x1+x2) in the interval 0x1x27. To be sure I tried it by hand and got 114.33, but the following R code is giving me 102.6667. --**--**--- library(cubature) f-function(x) { 2/3 * (x[1] + x[2] ) } adaptIntegrate(f, lowerLimit = c(0, 0), upperLimit = c(x[2],7)) What is x[2]? On my machine it was 0.0761, so I obviously got a different answer. -- David Winsemius, MD Alameda, CA, USA David Winsemius, MD Alameda, CA, USA [[alternative HTML version deleted]] __ R-help@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.
[R] Minimizing Computational Time
Dear R-users, May I seek some suggestions from you. I have a long programme written in R with several 'for' loops inside. I just want to get them out by any elegant way (if there is!) to reduce the computational time of the main programme. For instance, is there any smart way for the following programme that will lessen time? --- dose-seq(0,10,.5) alpha1--4 beta1-0.5 alpha2--6 beta2--.7 psi1-function(alpha1,beta1,alpha2,beta2,d){ z1-exp(alpha1+beta1*d) z2-exp(alpha2+beta2*d) z1/((1+z1)*(1+z2)) } psi2-function(alpha2,beta2,d) { z2-exp(alpha2+beta2*d) z2/(1+z2) } psi1.hat=c() psi2.hat=c() for (i in 1:length(dose)){ # just want to avoid this 'for' loop d-dose[i] psi1.hat[i]-psi1(alpha1,beta1,alpha2,beta2,d) psi2.hat[i]-psi2(alpha2,beta2,d) } print(psi1.hat) print(psi2.hat) Many thanks for your kind attention. Regards, Jamil. [[alternative HTML version deleted]] __ R-help@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.
[R] PFIM 3.2
Dear R-user, I'm having some difficulty with working PFIM 3.2, a package for implementing population PK/PD in R. I wish to evaluate the determinant of Fisher information matrix each time with successive dose from a pre defined sequence of doses and want to store those values in a vector. It's important to note that in my 'stdin.r' file, dose-c(u) and each time u is to be replaced as I said. I think a quick look on the following R codes will give a more clearer picture of the objective: --- directory-F:\\PFIM3.2_examples\\experiment # working directory directory.program-F:\\PFIM3.2.2\\PFIM3.2.2\\PFIM3.2.2\\Program # program directory true.dose-seq(0,10,0.5) # predefined sequence of doses deter=c() # to store determinant values for (i in 1:length(true.dose) { u-true.dose[i] source(F:\\PFIM3.2.2\\PFIM3.2.2\\PFIM3.2.2\\Program\\LibraryPK.r) source(F:\\PFIM3.2_examples\\experiment\\model.r) source(F:\\PFIM3.2_examples\\experiment\\stdin.r) source(F:\\PFIM3.2_examples\\experiment\\PFIM3.2.r) res-PFIM() deter[i]-res$determinant } --- But it's not working anyway and of course showing some error messages. I have attached the the associated files. Any suggestion in this regard will help me a lot. Thank you very much for the patience! Regards, Jamil. __ R-help@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.
[R] Integration in R
Dear R-users, I am facing problem with integrating in R a likelihood function which is a function of four parameters. It's giving me the result at the end but taking more than half an hour to run. I'm wondering is there any other efficient way deal with. The following is my code. I am ready to provide any other description of my function if you need to move forward. library(cubature) dose-c(2,3,5) y0-c(2,1,0) y1-c(1,1,1) y2-c(0,1,2) lf-function (x) { v-1 for (i in 1:length(dose)) { psi0-1/((1+exp(x[1]+x[2]*dose[i]))*(1+exp(x[3]+x[4]*dose[i]))) psi1-exp(x[1]+x[2]*dose[i])/((1+exp(x[1]+x[2]*dose[i]))*(1+exp(x[3]+x[4]*dose[i]))) v-v*(psi0^y0[i])*(psi1^y1[i])*((1-psi0-psi1)^y2[i]) } return(v) } adaptIntegrate(lf, lowerLimit = c(-20, 0,-20,0), upperLimit = c(0,10,0,10)) - Thanks for your attention. Kind regards, Jamil. [[alternative HTML version deleted]] __ R-help@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.