Re: [R] Error message: object of type 'closure' is not subsettable
Hi If you want sensible response you need to ask sensible question and more importantly provide working example or at least an example that produces the error you want get rid of. with test.functional.t(res.em1,res.em2,mint,maxt,se.m=0,points=300) I get Error in seq(mint, maxt, length.out = points) : object 'mint' not found obviously because I do not have any mint on my computer. Quite surprising is that your t (which I recommend you to call differently as t is function transpose In base R) ends as a list. At the first glance I do not see any reason for t to be a list from your code. Regards Petr Hi Josh, Petr I checked that testStatistics is a function but it is not defined in the code anywhere else. But if I am able to remove it and give the input by my own to the function which calls testStatistics, it might work. The hurdle here for me is that the input is a set* of values and each value has 2 attributes. Each variable is generated per iteration and has the numerator, denominator as its attributes and a value. But when I read it in a loop, i face two problems: 1. only the last i value is stored and the rest are NULL. 2. the one stored does not contain the attribute values. Each value looks like this: t [1] 3.897434 attr(,numerator) [1] 0.0002134457 attr(,denominator) [1] 5.47657e-05 Eg: for (i in 1:5) { t- test.functional.t(res.em1,res.em2,mint,maxt,se.m=0,points=300) ### function calling } t [[1]] NULL [[2]] NULL [[3]] NULL [[4]] NULL [1] 3.897434 Any suggestions. Thanks for all the help. :) Regards Aparna On Tue, Feb 28, 2012 at 11:01 PM, Petr PIKAL petr.pi...@precheza.cz wrote: Hi Difficult to without knowing what objects you are operating your functions. I get test.functional.t(1:10,1:10,3,4) Error in res.em1$eta : $ operator is invalid for atomic vectors moderated.functional.t(1:10) Error in testStatistics[numerator, ] : incorrect number of dimensions And without suitable objects for those functions to operate it is impossible to come with reasonable suggestion. Anyway there is a function on your system which is called testStatistics and you can not subset functions, hence your error. I did not find this function in R pacages but I can not say that it is really not there. You can get rid of this function by rm(testStatistics) Regards Petr Kindly find below the code as it is executed: test.functional.t - function(res.em1,res.em2,mint,maxt,se.m=0,points=300) { at - seq(mint,maxt,length.out=points) by - at[2] - at[1] mu1 - spline(x=res.em1$tau,y=res.em1$eta,xout=at,method=natural)$y l2 - functional.norm(mu1,mu2,by=by) s1 - mean(sapply(1:res.em1$n, function(i) { v - spline(x=res.em1$tau,y=res.em1$vi[[i]],xout=at,method=natural)$y functional.norm(v,by=by)^2 })) denominator - sqrt(s1 / res.em1$n + s2 / res.em2$n) ### formula for se returnValue - l2 / (denominator + se.m) attr(returnValue,numerator) - l2 attr(returnValue,denominator) - denominator returnValue } moderated.functional.t - function(testStatistics,alpha.step=0.05,quantile.step=0.01) { numerators - unlist(testStatistics[numerator,]) denominators - unlist(testStatistics[denominator,]) } I get my error in the function above moderated.functional.t. testStatistics is shown to be a function(x) when I type it in R console. But there is no function definition for testStatistics in the code. My R understanding is still elementary. Thanks Aparna On Tue, Feb 28, 2012 at 5:25 PM, Joshua Wiley jwiley.ps...@gmail.comwrote: Hi Aparna, Can you please post a reproducible example? It is difficult to provide much concrete help without having testStatistics. One thing you might try is looking at: str(testStatistics[numerator,]) is it actually a list? If it is not (most likely given the error) and it is supposed to be, you need to figure out what aspect of the generation of it is going awry. Cheers, Josh On Tue, Feb 28, 2012 at 12:23 AM, Aparna Sampath aparna.sampat...@gmail.com wrote: Hi All I am trying to use the unlist() in R to a list variable. The following statements are within a function. { denominator - sqrt(s1 / res.em1$n + s2 / res.em2$n) returnValue - l2 / (denominator + 11) attr(returnValue,numerator) - l2 attr(returnValue,denominator) - denominator returnValue } And when I try to unlist the variable returnValue numerators - unlist(testStatistics[numerator,]) denominators - unlist(testStatistics[denominator,]) I get the following error: Error in testStatistics[numerator, ] : object of type 'closure' is not subsettable I read some threads in R help on this error and they had asked to check if we are using
[R] Two plots with two different Y labels
Dear all, I would like to place into a same plot two plots. Their y values though are different a lot (first series has around -100 y values and the second one slightly over 1). The x value are the same. I would like to have in the same plot (under the same x,y axis the two plots). Is it possible then to have two y labels, one for example in the left side and an extra y label at the right. Each y label will have its own labeling and its own Font type line. CAn I do something like that in R with the normal plots and lines? I would like to thank you in advance for your help B.R Alex [[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] User defined link function with extra parameters
Bernardo Powaga bspowaga at gmail.com writes: I would like to fit a generalized linear model for the binomial family with some non standard link functions. For instance, this is the Aranda-Ordaz link: η = ln( ( (1 - π)^-α - 1 )/α) snip Is there any way to tell glm() to add this parameter in the estimation or do I have to write my own estimator with optim()? If the parameter cannot be made into a coefficient of the linear predictor, then I'm afraid that you will have to roll your own. Thanks, BP -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ 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] Two plots with two different Y labels
Try this: set.seed(123) x - 1:5 y1 - rnorm(5) y2 - rnorm(5) par(mar = c(5,4,5,4)) plot(x, y1, xlab = x-axis, ylab = y-axis, type = l) par(new = TRUE) plot(x, y2, axes = FALSE, yaxs = i, type = l, ann = FALSE, col = 2) axis(4, las = 2) mtext(z-axis, 4, 2) I hope it helps. Best, Dimitris On 3/1/2012 9:13 AM, Alaios wrote: Dear all, I would like to place into a same plot two plots. Their y values though are different a lot (first series has around -100 y values and the second one slightly over 1). The x value are the same. I would like to have in the same plot (under the same x,y axis the two plots). Is it possible then to have two y labels, one for example in the left side and an extra y label at the right. Each y label will have its own labeling and its own Font type line. CAn I do something like that in R with the normal plots and lines? I would like to thank you in advance for your help B.R Alex [[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. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ __ 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] Error message: object of type 'closure' is not subsettable
Dear Petr I am sorry about the code being incomplete. I also take note of not using R keywords and functions as variable names. I was able to overcome my problem using unlist(). Thanks. Regards Aparna On Thu, Mar 1, 2012 at 3:57 PM, Petr PIKAL petr.pi...@precheza.cz wrote: Hi If you want sensible response you need to ask sensible question and more importantly provide working example or at least an example that produces the error you want get rid of. with test.functional.t(res.em1,res.em2,mint,maxt,se.m=0,points=300) I get Error in seq(mint, maxt, length.out = points) : object 'mint' not found obviously because I do not have any mint on my computer. Quite surprising is that your t (which I recommend you to call differently as t is function transpose In base R) ends as a list. At the first glance I do not see any reason for t to be a list from your code. Regards Petr Hi Josh, Petr I checked that testStatistics is a function but it is not defined in the code anywhere else. But if I am able to remove it and give the input by my own to the function which calls testStatistics, it might work. The hurdle here for me is that the input is a set* of values and each value has 2 attributes. Each variable is generated per iteration and has the numerator, denominator as its attributes and a value. But when I read it in a loop, i face two problems: 1. only the last i value is stored and the rest are NULL. 2. the one stored does not contain the attribute values. Each value looks like this: t [1] 3.897434 attr(,numerator) [1] 0.0002134457 attr(,denominator) [1] 5.47657e-05 Eg: for (i in 1:5) { t- test.functional.t(res.em1,res.em2,mint,maxt,se.m=0,points=300) ### function calling } t [[1]] NULL [[2]] NULL [[3]] NULL [[4]] NULL [1] 3.897434 Any suggestions. Thanks for all the help. :) Regards Aparna On Tue, Feb 28, 2012 at 11:01 PM, Petr PIKAL petr.pi...@precheza.cz wrote: Hi Difficult to without knowing what objects you are operating your functions. I get test.functional.t(1:10,1:10,3,4) Error in res.em1$eta : $ operator is invalid for atomic vectors moderated.functional.t(1:10) Error in testStatistics[numerator, ] : incorrect number of dimensions And without suitable objects for those functions to operate it is impossible to come with reasonable suggestion. Anyway there is a function on your system which is called testStatistics and you can not subset functions, hence your error. I did not find this function in R pacages but I can not say that it is really not there. You can get rid of this function by rm(testStatistics) Regards Petr Kindly find below the code as it is executed: test.functional.t - function(res.em1,res.em2,mint,maxt,se.m=0,points=300) { at - seq(mint,maxt,length.out=points) by - at[2] - at[1] mu1 - spline(x=res.em1$tau,y=res.em1$eta,xout=at,method=natural)$y l2 - functional.norm(mu1,mu2,by=by) s1 - mean(sapply(1:res.em1$n, function(i) { v - spline(x=res.em1$tau,y=res.em1$vi[[i]],xout=at,method=natural)$y functional.norm(v,by=by)^2 })) denominator - sqrt(s1 / res.em1$n + s2 / res.em2$n) ### formula for se returnValue - l2 / (denominator + se.m) attr(returnValue,numerator) - l2 attr(returnValue,denominator) - denominator returnValue } moderated.functional.t - function(testStatistics,alpha.step=0.05,quantile.step=0.01) { numerators - unlist(testStatistics[numerator,]) denominators - unlist(testStatistics[denominator,]) } I get my error in the function above moderated.functional.t. testStatistics is shown to be a function(x) when I type it in R console. But there is no function definition for testStatistics in the code. My R understanding is still elementary. Thanks Aparna On Tue, Feb 28, 2012 at 5:25 PM, Joshua Wiley jwiley.ps...@gmail.comwrote: Hi Aparna, Can you please post a reproducible example? It is difficult to provide much concrete help without having testStatistics. One thing you might try is looking at: str(testStatistics[numerator,]) is it actually a list? If it is not (most likely given the error) and it is supposed to be, you need to figure out what aspect of the generation of it is going awry. Cheers, Josh On Tue, Feb 28, 2012 at 12:23 AM, Aparna Sampath aparna.sampat...@gmail.com wrote: Hi All I am trying to use the unlist() in R to a list variable. The following statements are within a function. { denominator - sqrt(s1 / res.em1$n + s2 / res.em2$n) returnValue - l2 / (denominator + 11) attr(returnValue,numerator) - l2 attr(returnValue,denominator) - denominator returnValue
[R] Trend predictions using R projects!!
Hi, We are exploring to integrate a solution that can analyse data from MySql, and generate graphical reports showing trends/future predictions. I have just started to look into R-Project. Please let me know if R-Project provides this functionality. If yes please direct me to any tutorial/example. Regards, Neeraj [[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] How are the coefficients for the ur.ers, type DF-GLS calculated?
Ackbar: have a look at ur.ers directly. The coefficients can be recovered from the slot 'testreg', i.e., example(ur.ers) slotNames(ers.gnp) coef(ers.gnp@testreg) RTFM: help(ur.ers) and help(ur.ers-class) Best, Bernhard -Ursprüngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von ackbar03 Gesendet: Mittwoch, 29. Februar 2012 17:20 An: r-help@r-project.org Betreff: [R] How are the coefficients for the ur.ers, type DF-GLS calculated? I need some real help on this, really stuck how are the coefficients for ur.ers(y, type = c(DF-GLS, P-test), model = c(constant, trend), lag.max = 0) The max lag is set at zero, so the regression should simply be Diff(zt) = a*z(t-1) where a is the value i'm trying to find and z(t)'s are the detrended values. but through performing my own regression on the two time series I get different values. This could only mean 1) Its not just a simple regression or 2) I'm detrending my data incorrectly. However, i've followed the instructions I've seen in research papers and it doesn't seem to be right. Basically I take Y*t = Yt-(1-(1-7/T)*Y(t-1) and regress that on 1-(1-7/T) for all t1 and leave the values at T=1 unchanged. Then I take Yt and subtract the coefficient of the regression to get the detrended value. I'm really stuck on this and its really frustrating. I think the easiest thing would be if someone can tell me exactly how R carries out the calculations for the functions. Help will be highly appreciated!! -- View this message in context: http://r.789695.n4.nabble.com/How-are-the-coefficients-for-the-ur-ers-type-DF-GLS-calculated-tp4432015p4432015.html Sent from the R help mailing list archive at Nabble.com. __ 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. * Confidentiality Note: The information contained in this ...{{dropped:10}} __ 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] Simulate values from VAR
Hello Keith, see ?Acoef for retrieving the coefficients. Incidentally, in the package dse simulation methods are made available. Best, Bernhard Dr. Bernhard Pfaff Director Global Asset Allocation Invesco Asset Management Deutschland GmbH An der Welle 5 D-60322 Frankfurt am Main Tel: +49 (0)69 29807 230 Fax: +49 (0)69 29807 178 www.institutional.invesco.com Email: bernhard_pf...@fra.invesco.com Geschäftsführer: Karl Georg Bayer, Bernhard Langer, Dr. Jens Langewand, Alexander Lehmann, Christian Puschmann Handelsregister: Frankfurt am Main, HRB 28469 Sitz der Gesellschaft: Frankfurt am Main * Confidentiality Note: The information contained in this ...{{dropped:10}} __ 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] Trend predictions using R projects!!
Hi Neeraj Check out the task view of some of the many options for trending, time series analysis and visualisation at http://cran.r-project.org/web/views/TimeSeries.html Best wishes Chris Chris Campbell MANGO SOLUTIONS Data Analysis that Delivers +44 1249 705450 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of AGGARWAL, NEERAJ (NEERAJ) Sent: 01 March 2012 08:32 To: R help Subject: [R] Trend predictions using R projects!! Hi, We are exploring to integrate a solution that can analyse data from MySql, and generate graphical reports showing trends/future predictions. I have just started to look into R-Project. Please let me know if R-Project provides this functionality. If yes please direct me to any tutorial/example. Regards, Neeraj [[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. LEGAL NOTICE This message is intended for the use o...{{dropped:10}} __ 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] Two plots with two different Y labels
On 03/01/2012 07:13 PM, Alaios wrote: Dear all, I would like to place into a same plot two plots. Their y values though are different a lot (first series has around -100 y values and the second one slightly over 1). The x value are the same. I would like to have in the same plot (under the same x,y axis the two plots). Is it possible then to have two y labels, one for example in the left side and an extra y label at the right. Each y label will have its own labeling and its own Font type line. CAn I do something like that in R with the normal plots and lines? Hi Alex, Have a look at the twoord.plot function (plotrix). Jim __ 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] select rows by criteria
Hello, I am stuck with selecting the right rows from a data frame. I think the problem is rather how to select them then how to implement the R code. Consider the following data frame: df - data.frame(ID = c(1,2,3,4,5,6,7,8,9,10), value = c(34,12,23,25,34,42,48,29,30,27)) What I want to achieve is to select 7 rows (values) so that the mean value of those rows are closest to the value of 35 and the remaining 3 rows (values) are closest to 45. However, each value is only allowed to be sampled once! Any ideas, how to achieve that? Cheers -- View this message in context: http://r.789695.n4.nabble.com/select-rows-by-criteria-tp4434812p4434812.html Sent from the R help mailing list archive at Nabble.com. __ 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] convert list to text file
Dear R users, Is it possible to write the following list to a text-file? List: [[1]] [1] 500 [[2]] [1] 1 [[3]] [,1] [,2] [,3] [,4] [,5] FID12345 Var20211 I would like to have the textfile look like this: 500 1 FID 1 2 3 4 5 Var 2 0 2 1 1 Thank you very much in advance for your help! Kind regards, Tessel Galesloot Department of Epidemiology, Biostatistics and HTA (133) Radboud University Nijmegen Medical Centre Het UMC St Radboud staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 41055629. The Radboud University Nijmegen Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629. __ 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] User defined link function with extra parameters
On Mar 1, 2012, at 12:52 AM, Bernardo Powaga wrote: Hello R users, I would like to fit a generalized linear model for the binomial family with some non standard link functions. For instance, this is the Aranda-Ordaz link: η = ln( ( (1 - π)^-α - 1 )/α) I know how to define a new link function to use with glm(), but I my problem is that I have an extra parameter to estimate and I have no clue how to incorporate that. Is there any way to tell glm() to add this parameter in the estimation or do I have to write my own estimator with optim()? Bernardo; Let me introduce you to a new friend. You very own link to a search engine to r-help. That way you won't need to repeat questions that have been asked answered and even incorported into announced packages: http://www.googlesyndicatedsearch.com/u/newcastlemaths?q=Aranda-Ordaz+linksa=Google+Search The Newcastle site is just one of several that you could have used. MarkMail is another popular one and the venerable Baron maintained finzi site to which RSiteSearch has in the past directed you to. It, however, no longer is being maintained for rhelp or rdevel searches. Enjoy the company of your new friends. -- David Winsemius, MD West Hartford, CT __ 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] Cleaning up messy Excel data
But there are some important reasons to use Excel. In my work there are a lot of people that I have to send the equivalent of a data.frame to who want to look at the data and possibly slice/dice the data differently and then send back to me updates. These folks do not know how to use R, but do have Microsoft Office installed on their computers and know how to use the different products. I have been very successful in conveying what I am doing for them by communicating via Excel spreadsheets. It is also an important medium in dealing with some international companies who provide data via Excel and expect responses back via Excel. When dealing with data in a tabular form, Excel does provide a way for a majority of the people I work with to understand the data. Yes, there are problems with some of the ways that people use Excel, and yes I have had to invest time in scrubbing some of the data that I get from them, but if I did not, then I would probably not have a job working for them. I use R exclusively for the analysis that I do, but find it convenient to use Excel to provide a communication mechanism to the majority of the non-R users that I have to deal with. It is a convenient work-around because I would never get them to invest the time to learn R. So in the real world these is a need to Excel and we are not going to cause it to go away; we have to learn how to live with it, and from my standpoint, it has definitely benefited me in being able to communicate with my users and continuing to provide them with results that they are happy with. They refer to letting me work my magic on the data; all they know is they see the result via Excel and in the background R is doing the heavy lifting that they do not have to know about. On Wed, Feb 29, 2012 at 4:41 PM, Rolf Turner rolf.tur...@xtra.co.nz wrote: On 01/03/12 04:43, John Kane wrote: (mydata- as.factor(c(1,2,3, 2, 5, 2))) str(mydata) newdata- as.character(mydata) newdata[newdata==2]- 0 newdata- as.numeric(newdata) str(newdata) We really need to keep Excel (and other spreadsheets) out of peoples hands. Amen, bro'!!! cheers, Rolf Turner __ 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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ 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] convert list to text file
Perhaps something like sink(outtext.txt) lapply(LIST, print) sink() You could replace print with cat and friends if you wanted more detailed control over the look of the output. Michael On Thu, Mar 1, 2012 at 5:28 AM, t.galesl...@ebh.umcn.nl wrote: Dear R users, Is it possible to write the following list to a text-file? List: [[1]] [1] 500 [[2]] [1] 1 [[3]] [,1] [,2] [,3] [,4] [,5] FID 1 2 3 4 5 Var 2 0 2 1 1 I would like to have the textfile look like this: 500 1 FID 1 2 3 4 5 Var 2 0 2 1 1 Thank you very much in advance for your help! Kind regards, Tessel Galesloot Department of Epidemiology, Biostatistics and HTA (133) Radboud University Nijmegen Medical Centre Het UMC St Radboud staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 41055629. The Radboud University Nijmegen Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629. __ 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-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] Re : Create a function automatically from lm formula and coefficients?
yes, e.g. require(rms) f - ols( ) # ols is a wrapper for lm g - Function(f) g(age=30) # get predicted mean at age=30 and defaults for other variables (medians modes) Frank Pascal Oettli-2 wrote Hi Keith, Do you mean as predict.lm can do? Regards, Pascal De : Keith Weintraub lt;kw1958@gt; À : r-help@ Envoyé le : Jeudi 1 mars 2012 11h41 Objet : [R] Create a function automatically from lm formula and coefficients? I hope the subject says it all. I want to be able to use an lm object and the associated coefficients to create function that can produce expected y values given inputs. Thanks, KW -- [[alternative HTML version deleted]] __ R-help@ 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-help@ 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. - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/Create-a-function-automatically-from-lm-formula-and-coefficients-tp4433854p4434981.html Sent from the R help mailing list archive at Nabble.com. __ 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] linear regression by column
Thank everyone for your help. Problem solved. I'm getting more used with vectorization with your help, Regards, Phil -- View this message in context: http://r.789695.n4.nabble.com/linear-regression-by-column-tp4432564p4434937.html Sent from the R help mailing list archive at Nabble.com. __ 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] 'break' function in loop
Dear R helpers, I have some difficulties in using 'break' function with loop, and the followings are my script. What I try to do is (1) permute 'or' first; (2) doing t-test if this 'or' pass criteria 1 (k=1); (3) end the loop when I get 10 permutations; (4) redo everything again but this time use criteria 2 (k=2) (I have more criteria 1:n). Somehow using my script, the final dataset (results1) only contains the result from criteria 1 (twice!) but not the result from criteria 2. I guess probably I put the break function under the wrong loop but I cannot fix it. Sorry if the whole script looks quite messy, I will be very appreciate if someone can help me fix this problem or probably give me some advices to write it in a smart way. My attempt: controlall - rbeta(1,1.5,6) caseall - rbeta(1,1.6,6) results - NULL results1 - NULL or -vector(list,length=10) criteria - matrix(data=c(1.05,1.15,1.15,1.25),ncol=2,nrow=2) for (k in 1:2) { for (i in 1:1000) { control - sample(controlall,100) case - sample(caseall,100) or[i] - round(mean(case)*(1-mean(control))/(mean(control)*(1-mean(case))),digit=2) if (or[i]criteria[k,2]or[i]=criteria[k,1]) { group - c(rep(1,100),rep(0,100)) value - c(case,control) ttest - (t.test(case,control,alternative=two.sided,paired=F))$p.value all - c(or[i],ttest) results - rbind(results,all) } ifelse(nrow(results)==5,break,1) } results1 - rbind(results1,results) } Thank you so much in advance, Amber [[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] Execution of Rprofile.site
Hi everyone. I have recently installed R 2.14.1 on my 64-bit Windows 7 laptop. I am attempting to include some favourite functions in the Rprofile.site file to run at R start-up as I did with my previous 32-bit XP machine. I have edited the Rprofile.site file in C:\Program Files\R\R-2.14.1\etc\ but the added code doesn't seem to be executed when I run R, whether through Tinn-R or independently. Any ideas please on what's going wrong? I've searched my laptop and there is only one Rprofile.site file. Also Sys.getenv(R_HOME) returns: [1] C:/PROGRA~1/R/R-214~1.1 so R should be able to find the Rprofile.site file. Note that Rprofile.site has been modified by Tinn-R. Many thanks Ross Bowden PhD Candidate, Maths Department, Murdoch University. __ 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] 'break' function in loop
I have never seen 'break' used in an 'ifelse'; you probably meant to use an 'if' statement there. On Thu, Mar 1, 2012 at 8:24 AM, Tsai, Pei-Chien pei-chien.t...@kcl.ac.uk wrote: Dear R helpers, I have some difficulties in using 'break' function with loop, and the followings are my script. What I try to do is (1) permute 'or' first; (2) doing t-test if this 'or' pass criteria 1 (k=1); (3) end the loop when I get 10 permutations; (4) redo everything again but this time use criteria 2 (k=2) (I have more criteria 1:n). Somehow using my script, the final dataset (results1) only contains the result from criteria 1 (twice!) but not the result from criteria 2. I guess probably I put the break function under the wrong loop but I cannot fix it. Sorry if the whole script looks quite messy, I will be very appreciate if someone can help me fix this problem or probably give me some advices to write it in a smart way. My attempt: controlall - rbeta(1,1.5,6) caseall - rbeta(1,1.6,6) results - NULL results1 - NULL or -vector(list,length=10) criteria - matrix(data=c(1.05,1.15,1.15,1.25),ncol=2,nrow=2) for (k in 1:2) { for (i in 1:1000) { control - sample(controlall,100) case - sample(caseall,100) or[i] - round(mean(case)*(1-mean(control))/(mean(control)*(1-mean(case))),digit=2) if (or[i]criteria[k,2]or[i]=criteria[k,1]) { group - c(rep(1,100),rep(0,100)) value - c(case,control) ttest - (t.test(case,control,alternative=two.sided,paired=F))$p.value all - c(or[i],ttest) results - rbind(results,all) } ifelse(nrow(results)==5,break,1) } results1 - rbind(results1,results) } Thank you so much in advance, Amber [[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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ 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] update.formula has 512 char buffer?
On 12-02-28 2:11 PM, Chris Hane wrote: Hello, I am trying to paste together a formula to use in the mob function of party. This means the formula will be of the form y ~ x1+ ...+xM | z1+..zN. I am doing some preliminary fits of y ~ x1+ ...+xM, then want to add the conditional part of the equation using update(). Here's the test code: var1- 1:78 x1- paste(x, var1, sep=) f1- paste(f, var1[1:10], sep=) # use first 77 variables fmla- as.formula( paste(y ~ , paste(x1[1:77], collapse= + , sep=), sep=)) fmla2- update(fmla, paste(. ~ . | , paste(f1, collapse= + ), sep=)) # CHANGE x to all 78 variables fmla- as.formula( paste(y ~ , paste(x1, collapse= + , sep=), sep=)) fmla2- update(fmla, paste(. ~ . | , paste(f1, collapse= + ), sep=)) I have run this in Windows and Linux (64 bit) and both fail when using all 78 terms (and anything more than 78 terms). The error message contains Error in parse(text = x) : :1:514: unexpected ')'. Changing the length of the names of the x variables will break the update() with fewer variables, but always with an error referring to just more than 512 characters. There is nothing special about 77 or 78 variables here; I want to do this with hundreds of variables. Is there a workaround to this? I've just committed code to R-devel (to become 2.15.0 at the end of the month) to remove the truncation. I don't know any workaround that will address this in earlier versions, other than don't use very long formulas. It also affects as.character() applied to a formula object, and some other cases where very long language objects are displayed. Please test R-devel or one of the alpha/beta versions once they are built; this fix went into revision 58544. Duncan Murdoch [[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-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] 'break' function in loop
On 12-03-01 8:24 AM, Tsai, Pei-Chien wrote: Dear R helpers, I have some difficulties in using 'break' function with loop, and the followings are my script. What I try to do is (1) permute 'or' first; (2) doing t-test if this 'or' pass criteria 1 (k=1); (3) end the loop when I get 10 permutations; (4) redo everything again but this time use criteria 2 (k=2) (I have more criteria 1:n). Somehow using my script, the final dataset (results1) only contains the result from criteria 1 (twice!) but not the result from criteria 2. I guess probably I put the break function under the wrong loop but I cannot fix it. Sorry if the whole script looks quite messy, I will be very appreciate if someone can help me fix this problem or probably give me some advices to write it in a smart way. My attempt: controlall- rbeta(1,1.5,6) caseall- rbeta(1,1.6,6) results- NULL results1- NULL or-vector(list,length=10) criteria- matrix(data=c(1.05,1.15,1.15,1.25),ncol=2,nrow=2) for (k in 1:2) { for (i in 1:1000) { control- sample(controlall,100) case- sample(caseall,100) or[i]- round(mean(case)*(1-mean(control))/(mean(control)*(1-mean(case))),digit=2) if (or[i]criteria[k,2]or[i]=criteria[k,1]) { group- c(rep(1,100),rep(0,100)) value- c(case,control) ttest- (t.test(case,control,alternative=two.sided,paired=F))$p.value all- c(or[i],ttest) results- rbind(results,all) } ifelse(nrow(results)==5,break,1) Jim was right, this line doesn't make sense. Use if(nrow(results)==5) break instead. Duncan Murdoch } results1- rbind(results1,results) } Thank you so much in advance, Amber [[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-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] Error in solve.default(res$hessian * n.used) :Lapack routine dgesv: system is exactly singular
Vinicius, Vinicius Magalhães wrote + n - length(*x.ts*) + for (p in 0:maxord[1]) for (d in 0:maxord[2]) for (q in 0:maxord[3]) + for (P in 0:maxord[4]) for (D in 0:maxord[5]) for (Q in 0:maxord[6]) + { + fit - arima(*x.ts*, order=c(p,d,q), + seas = list(order=c(P,D,Q), + frequency(x.ts)), method = CSS) + fit.aic - -2 * fit$loglik + (log(n) + 1) * length(fit$coef) I think you are using 'x.ts' instead 's.ts'. Is it correct?! Maybe you can also put here objects likely 'x', 'x.ts' to help us give feedback to you routine. Best regards. - Victor Delgado cedeplar.ufmg.br P.H.D. student www.fjp.mg.gov.br reseacher -- View this message in context: http://r.789695.n4.nabble.com/Error-in-solve-default-res-hessian-n-used-Lapack-routine-dgesv-system-is-exactly-singular-tp4428273p4435054.html Sent from the R help mailing list archive at Nabble.com. __ 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] barplots of several variables with different number of categories
If I have two factors, v1 and v2 and I want to have a stacked bar graph of the two variables side by side I could do barplot(cbind(table(v1),table(v2))) if v1 and v2 have the same number of categories. If they don't have the same number of categories this won't work. I'm sure there's a simple solution? Thanks, Jon -- View this message in context: http://r.789695.n4.nabble.com/barplots-of-several-variables-with-different-number-of-categories-tp4435092p4435092.html Sent from the R help mailing list archive at Nabble.com. __ 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] 'break' function in loop
Hello, jholtman wrote I have never seen 'break' used in an 'ifelse'; you probably meant to use an 'if' statement there. On Thu, Mar 1, 2012 at 8:24 AM, Tsai, Pei-Chien lt;pei-chien.tsai@.acgt; wrote: Dear R helpers, I have some difficulties in using 'break' function with loop, and the followings are my script. What I try to do is (1) permute 'or' first; (2) doing t-test if this 'or' pass criteria 1 (k=1); (3) end the loop when I get 10 permutations; (4) redo everything again but this time use criteria 2 (k=2) (I have more criteria 1:n). Somehow using my script, the final dataset (results1) only contains the result from criteria 1 (twice!) but not the result from criteria 2. I guess probably I put the break function under the wrong loop but I cannot fix it. Sorry if the whole script looks quite messy, I will be very appreciate if someone can help me fix this problem or probably give me some advices to write it in a smart way. My attempt: controlall - rbeta(1,1.5,6) caseall - rbeta(1,1.6,6) results - NULL results1 - NULL or -vector(list,length=10) criteria - matrix(data=c(1.05,1.15,1.15,1.25),ncol=2,nrow=2) for (k in 1:2) { for (i in 1:1000) { control - sample(controlall,100) case - sample(caseall,100) or[i] - round(mean(case)*(1-mean(control))/(mean(control)*(1-mean(case))),digit=2) if (or[i]lt;criteria[k,2]amp;or[i]gt;=criteria[k,1]) { group - c(rep(1,100),rep(0,100)) value - c(case,control) ttest - (t.test(case,control,alternative=two.sided,paired=F))$p.value all - c(or[i],ttest) results - rbind(results,all) } ifelse(nrow(results)==5,break,1) } results1 - rbind(results1,results) } Thank you so much in advance, Amber [[alternative HTML version deleted]] __ R-help@ 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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ R-help@ 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. Right. There are other things I'd like to note: 1. When debugging, if you use random number generators, also use 'set.seed'. And get reproducible conditions for the code tests. 2. Your first 'if' has the short conjunction ''. This is a vectorized version, you only want 1 result. See ?. (Jim's statement is another 'vectorized' vs. '1 result' case. You want the latter on both cases.) 3. Now the bug. You don't reinitialize 'results' to NULL and it therefore reuses the first one. It's a good pratice to always put 'var - NULL' as the instruction just before the loop that forms it. Is this what you want? set.seed(1) # Note 1 above results1 - NULL for (k in 1:2) { results - NULL # Note 3 above. for (i in 1:1000) { control - sample(controlall, 100) case - sample(caseall, 100) or[i] - round(mean(case)*(1-mean(control))/(mean(control)*(1-mean(case))), digit=2) if (or[i] criteria[k,2] or[i] = criteria[k, 1]) # Note 2 above { group - c(rep(1,100),rep(0,100)) value - c(case,control) ttest - (t.test(case,control,alternative=two.sided,paired=F))$p.value all - c(or[i], ttest) results - rbind(results, all) } if(!is.null(results) nrow(results) == 5) break # Note 2 above } results1 - rbind(results1, results) } results results1 Hope this helps Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/break-function-in-loop-tp4435033p4435151.html Sent from the R help mailing list archive at Nabble.com. __ 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] Problems downloading file
I am running the following line to download data from the US Energy Information Administration. This function has worked successfully for me in the past but yesterday gave the error/warning messages below. If I simply type http://ir.eia.gov/wpsr/psw09.xls; (no quotes) into a browser, the file is available to download. I am running R 2.13.0 on Windows XP. # Download File Attempt download.file(http://ir.eia.gov/wpsr/psw09.xls,c:\\temp\\psw09.xls,mode=wb;) # Error Warning Messages trying URL 'http://ir.eia.gov/wpsr/psw09.xls' Error in download.file(http://ir.eia.gov/wpsr/psw09.xls;, c:\\temp\\psw09.xls, : cannot open URL 'http://ir.eia.gov/wpsr/psw09.xls' In addition: Warning message: In download.file(http://ir.eia.gov/wpsr/psw09.xls;, c:\\temp\\psw09.xls, : InternetOpenUrl failed: 'The operation timed out' Thanks for any insights. Pete Brecknock -- View this message in context: http://r.789695.n4.nabble.com/Problems-downloading-file-tp4435186p4435186.html Sent from the R help mailing list archive at Nabble.com. __ 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] Problems downloading file
It might be a local network or OS issue: this works fine for me on my personal Mac download.file(url = http://ir.eia.gov/wpsr/psw09.xls;, destfile = ~/herewego.xls, mode = wb) Someone with more Windows knowledge may have to help you out, but often using IE settings (activated by the setInternet2 command if I recall correctly) is a good first move. Michael On Thu, Mar 1, 2012 at 9:47 AM, Pete Brecknock peter.breckn...@bp.com wrote: I am running the following line to download data from the US Energy Information Administration. This function has worked successfully for me in the past but yesterday gave the error/warning messages below. If I simply type http://ir.eia.gov/wpsr/psw09.xls; (no quotes) into a browser, the file is available to download. I am running R 2.13.0 on Windows XP. # Download File Attempt download.file(http://ir.eia.gov/wpsr/psw09.xls,c:\\temp\\psw09.xls,mode=wb;) # Error Warning Messages trying URL 'http://ir.eia.gov/wpsr/psw09.xls' Error in download.file(http://ir.eia.gov/wpsr/psw09.xls;, c:\\temp\\psw09.xls, : cannot open URL 'http://ir.eia.gov/wpsr/psw09.xls' In addition: Warning message: In download.file(http://ir.eia.gov/wpsr/psw09.xls;, c:\\temp\\psw09.xls, : InternetOpenUrl failed: 'The operation timed out' Thanks for any insights. Pete Brecknock -- View this message in context: http://r.789695.n4.nabble.com/Problems-downloading-file-tp4435186p4435186.html Sent from the R help mailing list archive at Nabble.com. __ 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-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] How to remove an object that is loaded every time R is opened?
Many thanks Jim and Chris for your helpful answers! J On Wed, Feb 29, 2012 at 11:48 AM, Chris Campbell ccampb...@mango-solutions.com wrote: Hi Jason If you close an R session and save without choosing a filename, a file called .RData will be created. Open a new session and type getwd(). Then have a look in the named file with your folder options set to Show Hidden Files. Deleting or renaming this file should remove the imported object. Hope this helps Chris Chris Campbell MANGO SOLUTIONS Data Analysis that Delivers +44 1249 705450 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jason Love Sent: 29 February 2012 15:10 To: r-help@r-project.org Subject: [R] How to remove an object that is loaded every time R is opened? Dear R users, I'm a newbie and have another basic question that you guys can answer for me. So, I've been noticing that an object (data frame) called FossilFuel is loaded as default when I first open up the R (see below). I created this data frame a while ago which is a data set for tutorial and I don't need this any more. I'm not sure why this happens and wonder if there is any way to remove this object. Let me know. -Jason --- R version 2.14.1 (2011-12-22) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. [R.app GUI 1.43 (5989) x86_64-apple-darwin9.8.0] [Workspace restored from /R/.RData] [History restored from /R/.Rapp.history] ls() [1] fossilfuel [[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. LEGAL NOTICE This message is intended for the use of the named recipient(s) only and may contain confidential and / or privileged information. If you are not the intended recipient, please contact the sender and delete this message. Any unauthorised use of the information contained in this message is prohibited. Mango Business Solutions Limited is registered in England under No. 4560258 with its registered office at Suite 3, Middlesex House, Rutherford Close, Stevenage, Herts, SG1 2EF, UK. PLEASE CONSIDER THE ENVIRONMENT BEFORE PRINTING THIS EMAIL [[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] 'break' function in loop
Thank you so much Jim, Duncan, and special thanks to Rui!! The modified script from Rui works perfectly and I really learned a lot from all your suggestions. Regards, Amber -- View this message in context: http://r.789695.n4.nabble.com/break-function-in-loop-tp4435033p4435399.html Sent from the R help mailing list archive at Nabble.com. __ 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] barplots of several variables with different number of categories
Jon, You could create new variables with the combined levels just for the purpose of plotting. Assume I have data.frame bpt str(bpt) 'data.frame': 12 obs. of 2 variables: $ V1: Factor w/ 3 levels low,med,high: 1 1 1 1 2 2 2 2 3 3 ... $ V2: Factor w/ 6 levels 1,2,3,4,..: 1 1 2 2 3 3 4 4 5 5 ... bpt$V3 - factor(bpt$V1,c(levels(bpt$V1),levels(bpt$V2))) bpt$V4 - factor(bpt$V2,c(levels(bpt$V1),levels(bpt$V2))) with(bpt,barplot(cbind(table(V3),table(V4 Hope this helps Elai On Thu, Mar 1, 2012 at 7:19 AM, jon waterhouse jonwaterho...@gov.nl.ca wrote: If I have two factors, v1 and v2 and I want to have a stacked bar graph of the two variables side by side I could do barplot(cbind(table(v1),table(v2))) if v1 and v2 have the same number of categories. If they don't have the same number of categories this won't work. I'm sure there's a simple solution? Thanks, Jon -- View this message in context: http://r.789695.n4.nabble.com/barplots-of-several-variables-with-different-number-of-categories-tp4435092p4435092.html Sent from the R help mailing list archive at Nabble.com. __ 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-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] select rows by criteria
On Thu, Mar 01, 2012 at 04:27:45AM -0800, syrvn wrote: Hello, I am stuck with selecting the right rows from a data frame. I think the problem is rather how to select them then how to implement the R code. Consider the following data frame: df - data.frame(ID = c(1,2,3,4,5,6,7,8,9,10), value = c(34,12,23,25,34,42,48,29,30,27)) What I want to achieve is to select 7 rows (values) so that the mean value of those rows are closest to the value of 35 and the remaining 3 rows (values) are closest to 45. However, each value is only allowed to be sampled once! Hi. If some 3 rows have mean close to 45, then they have sum close to 3*45, so the remaining 7 rows have sum close to sum(df$value) - 3*45 # [1] 169 and they have mean close to 169/7 = 24.14286. In other words, the two criteria cannot be optimized together. For this reason, let me choose the criterion on 3 rows. The closest solution may be found as follows. # generate all triples and compute their means tripleMeans - colMeans(combn(df$value, 3)) # select the index of the triple with mean closest to 35 indClosest - which.min(abs(tripleMeans - 35)) # generate the indices, which form the closest triple in df$value tripleInd - combn(1:length(df$value), 3)[, indClosest] tripleInd # [1] 1 3 7 # check the mean of the triple mean(df$value[tripleInd]) # [1] 35 This code constructs all triples. If it is used for k-tuples for a larger k and for a set of n values, its complexity will be proportional to choose(n, k), so it will be large even for moderate n, k. It is hard to provide a significant speed up, since some variants of knapsack problem, which is NP-complete, may be reduced to your question. Consequently, it is, in general, NP-complete. Hope this helps. Petr Savicky. __ 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] select rows by criteria
On Thu, Mar 01, 2012 at 05:42:48PM +0100, Petr Savicky wrote: On Thu, Mar 01, 2012 at 04:27:45AM -0800, syrvn wrote: Hello, I am stuck with selecting the right rows from a data frame. I think the problem is rather how to select them then how to implement the R code. Consider the following data frame: df - data.frame(ID = c(1,2,3,4,5,6,7,8,9,10), value = c(34,12,23,25,34,42,48,29,30,27)) What I want to achieve is to select 7 rows (values) so that the mean value of those rows are closest to the value of 35 and the remaining 3 rows (values) are closest to 45. However, each value is only allowed to be sampled once! Hi. If some 3 rows have mean close to 45, then they have sum close to 3*45, so the remaining 7 rows have sum close to sum(df$value) - 3*45 # [1] 169 and they have mean close to 169/7 = 24.14286. In other words, the two criteria cannot be optimized together. For this reason, let me choose the criterion on 3 rows. The closest solution may be found as follows. # generate all triples and compute their means tripleMeans - colMeans(combn(df$value, 3)) # select the index of the triple with mean closest to 35 indClosest - which.min(abs(tripleMeans - 35)) I am sorry. There should be 45 and not 35. indClosest - which.min(abs(tripleMeans - 45)) # generate the indices, which form the closest triple in df$value tripleInd - combn(1:length(df$value), 3)[, indClosest] tripleInd # [1] 1 6 7 # check the mean of the triple mean(df$value[tripleInd]) # [1] 41.3 Petr Savicky. __ 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] Parameterization of Inverse Wishart distribution available in MCMCpack and bayesm libraries
Hello Everyone Both the MCMCpack and the bayesm libraries allow us to make draws from the Inverse Wishart distribution. But I wanted to find out how exactly is the Inverse Wishart distribution parameterized in these libraries. The reason I ask is the following: Now its generally standard to express Inverse Wishart as IW(0.5 * DOF,0.5* Scale).(DOF- Degree of freedom, Scale - Scale parameter). If we follow standard usage when we refer to the Degree of Freedom of the above IW distribution it is = DOF (and not 0.5* DOF). Similarly the Scale parameters of the above IW it is= Scale (and not 0.5*Scale). For the MCMCpack the IW draws are made by riwish(v,S). *Question:* Does this compute IW( v,S) or IW(0.5*v,0.5*S) ? This is the reason I want to find out the way these libraries parameterize the Inverted Wishart distribution. Best Shantanu [[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] TM reader with text
Hi Richard, clearly there is a problem with latin ligature because the word resulting from my ask with findFreqTerms give me some wordsU+FB01n U+FB01nancement U+FB01nancier U+FB01nancièreU+FB01nancières U+FB01nanciersU+FB01xe where U+FB01 is a code for latin ligature. The problem is well identified ok. Now, how can I tretaed it. The package TAU seems to offer a solution for text but not for corpus. quoation TAU translate Translate Unicode Latin Ligatures Description Translate Unicode “Latin ligature” characters to their respective constituents. Usage translate_Unicode_latin_ligatures(x) Arguments x a character vector in UTF-8 encoding. Details In typography, a ligature occurs where two or more graphemes are joined as a single glyph. (See http://en.wikipedia.org/wiki/Typographic_ligature for more information.) Unicode (http://www.unicode.org/) lists the following “Latin” ligatures: Code Name 0132 LATIN CAPITAL LIGATURE IJ 0133 LATIN SMALL LIGATURE IJ 0152 LATIN CAPITAL LIGATURE OE 0153 LATIN SMALL LIGATURE OE FB00 LATIN SMALL LIGATURE FF util 9 FB01 LATIN SMALL LIGATURE FI FB02 LATIN SMALL LIGATURE FL FB03 LATIN SMALL LIGATURE FFI FB04 LATIN SMALL LIGATURE FFL FB05 LATIN SMALL LIGATURE LONG S T FB06 LATIN SMALL LIGATURE ST translate_Unicode_latin_ligatures translates these to their respective constituent characters. I need this king of fonction for corpus not only text or characters. Any ideas ? Thank's for comments and your answers. We are in progress! Mickaël -- View this message in context: http://r.789695.n4.nabble.com/TM-reader-with-text-tp4433394p4435229.html Sent from the R help mailing list archive at Nabble.com. __ 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] select rows by criteria
Hello, syrvn wrote Hello, I am stuck with selecting the right rows from a data frame. I think the problem is rather how to select them then how to implement the R code. Consider the following data frame: df - data.frame(ID = c(1,2,3,4,5,6,7,8,9,10), value = c(34,12,23,25,34,42,48,29,30,27)) What I want to achieve is to select 7 rows (values) so that the mean value of those rows are closest to the value of 35 and the remaining 3 rows (values) are closest to 45. However, each value is only allowed to be sampled once! Any ideas, how to achieve that? Cheers See ?combn It gives all possible combinations as a matrix (default) or list. Then, 'apply'. #--- # Name changed to 'DF', # 'df' is the R function for the F distribution density # (and a frequent choice for example data in R-help!) # DF - data.frame(ID = c(1,2,3,4,5,6,7,8,9,10), value = c(34,12,23,25,34,42,48,29,30,27)) f - function(j, v, const) abs(mean(v[j]) - const) inxmat - with(DF, combn(ID, 7)) meansDist1 - apply(inxmat, 2, function(jnx) f(jnx, DF$value, 35)) (i1 - which(meansDist1 == min(meansDist1))) inxmat - with(DF, combn(ID, 3)) meansDist2 - apply(inxmat, 2, function(jnx) f(jnx, DF$value, 45)) (i2 - which(meansDist2 == min(meansDist2))) meansDist3 - meansDist1 + meansDist2 # Compromise of both criteria? (i3 - which(meansDist3 == min(meansDist3))) Maybe it's combn(1:10, 3)[, 101] you want, or maybe there's another way to compromise the two criteria. Hope this helps, Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/select-rows-by-criteria-tp4434812p4435257.html Sent from the R help mailing list archive at Nabble.com. __ 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] Connecting points on a line with arcs/curves
Hello, I have a spreadsheet of pairs of coordinates and I would like to plot a line along which curves/arcs connect each pair of coordinates. The aim is to visualise the pattern of point connections. Thanks! Ian -- View this message in context: http://r.789695.n4.nabble.com/Connecting-points-on-a-line-with-arcs-curves-tp4435247p4435247.html Sent from the R help mailing list archive at Nabble.com. __ 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] how to change or copy to another the names of models
Hi I would like to know how I can change the name of a model for each trainning cycle of a model. I work with the RSNNS package and to build a neural network, I used : for (i in 5:30) model_ANN - mlp(X, Y, size=n,) # where size is the number of neurons in the hidden layer but I need to save each time that the model that is build (the end of each cycle), e.g., when i = 5, I need to save the model with a especific name, when i = 6, also I need to save the model with another name How i am doing, i am saving only the last model with n = 30 and with the name model_ANN Question how can I change the name of the model (model_ANN) at each end of cycle of i values? I have already tryied copy, save, rename,.. but unsuccessfully thanks for any answer -- Waldir de Carvalho Junior Pedologia/Pedologue Pesquisador/Chercheur Embrapa Solos/INRA - UMR- LISAH [[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] select rows by criteria
Sorry, correction: The second index matrix is the matrix of elements not in the first, not another combination, this time 3 out of 10. Change this in my first post inxmat - with(DF, combn(ID, 3)) meansDist2 - apply(inxmat, 2, function(jnx) f(jnx, DF$value, 45)) (i2 - which(meansDist2 == min(meansDist2))) to this inxmat2 - with(DF, apply(inxmat, 2, function(x) setdiff(ID, x))) meansDist2 - apply(inxmat2, 2, function(jnx) f(jnx, DF$value, 45)) (i2 - which(meansDist2 == min(meansDist2))) Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/select-rows-by-criteria-tp4434812p4435408.html Sent from the R help mailing list archive at Nabble.com. __ 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] Help with segmented package
Hi everyone. I'm using segmented package to find break point in a bi-linear relationship. In a particular case, I find 1 pointcut (so 2 slopes). I would like to know if it is possible to retrieve information in the segmented object that could let me to plot 1 particular segment with a different color. For example, in that folowing example, I would like to plot the second segment in red. library(segmented) set.seed(1234) z-runif(100) y-rpois(100,exp(2+1.8*pmax(z-.6,0))) o-glm(y~z,family=poisson) o.seg-segmented(o,seg.Z=~z,psi=list(z=.5)) plot(o.seg) Thank in advance, Phil -- View this message in context: http://r.789695.n4.nabble.com/Help-with-segmented-package-tp4435550p4435550.html Sent from the R help mailing list archive at Nabble.com. __ 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] Delete rows from data.frame matching a certain criteria
Hello, consider the following data.frame: test - data.frame(n = c(1,2,3,4,5), v = c(6,5,7,5,3), pattern = c(1,1,NA,1,NA)) test n v pattern 1 1 6 1 2 2 5 1 3 3 7 NA 4 4 5 1 5 5 3 NA I tried to use apply and the adply function to set v to NA where pattern = 1 and v to v where pattern = 1 So basically the result should look like this: test n v pattern 1 1 NA 1 2 2 NA 1 3 3 7 NA 4 4 NA 1 5 5 3 NA So far, I solved it by creating subsets and using merge but it turns out to be super slow. Is there a way to do that with the apply function? Any help/hint is appreciated Thanks -- View this message in context: http://r.789695.n4.nabble.com/Delete-rows-from-data-frame-matching-a-certain-criteria-tp4435414p4435414.html Sent from the R help mailing list archive at Nabble.com. __ 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] Need help using Melt and cast to compute correlation for a cross tabulation
I have a data frame with a number of observed and predicted values by classification as shown below: Count Volume FCLASS 1 55000 6 Grade Separated 2 43000 39000 Grade Separated 3 26000 26500 Major Arterial 4 19500 2 Major Arterial ... There are four classes here: Grade Separated, Major Arterial, Minor Arterial, and Collector I am looking to compute the following information FCLASS cor(Count,Volume) Grade Separated 0.999 Major Arterial 0.999 Minor Arterial 0.999 Collector 0.999 I am attempting to use the following commands to achieve this: library(reshape) tmp - melt(dataframe) cast(tmp, FCLASS ~ variable, function(Count, Volume) cor(Count, Volume)) but this is generating: Error in is.data.frame(y) : argument Volume is missing, with no default Any suggestions? Walter Anderson __ 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] select rows by criteria
On Thu, Mar 01, 2012 at 05:42:48PM +0100, Petr Savicky wrote: On Thu, Mar 01, 2012 at 04:27:45AM -0800, syrvn wrote: Hello, I am stuck with selecting the right rows from a data frame. I think the problem is rather how to select them then how to implement the R code. Consider the following data frame: df - data.frame(ID = c(1,2,3,4,5,6,7,8,9,10), value = c(34,12,23,25,34,42,48,29,30,27)) What I want to achieve is to select 7 rows (values) so that the mean value of those rows are closest to the value of 35 and the remaining 3 rows (values) are closest to 45. However, each value is only allowed to be sampled once! Hi. If some 3 rows have mean close to 45, then they have sum close to 3*45, so the remaining 7 rows have sum close to sum(df$value) - 3*45 # [1] 169 and they have mean close to 169/7 = 24.14286. In other words, the two criteria cannot be optimized together. For this reason, let me choose the criterion on 3 rows. The closest solution may be found as follows. # generate all triples and compute their means tripleMeans - colMeans(combn(df$value, 3)) # select the index of the triple with mean closest to 35 indClosest - which.min(abs(tripleMeans - 35)) # generate the indices, which form the closest triple in df$value tripleInd - combn(1:length(df$value), 3)[, indClosest] tripleInd # [1] 1 3 7 # check the mean of the triple mean(df$value[tripleInd]) # [1] 35 This code constructs all triples. If it is used for k-tuples for a larger k and for a set of n values, its complexity will be proportional to choose(n, k), so it will be large even for moderate n, k. It is hard to provide a significant speed up, since some variants of knapsack problem, which is NP-complete, may be reduced to your question. Consequently, it is, in general, NP-complete. Hi. Also this statement requires a correction. It applies to the search of an exact optimum if the numbers in df$value are large. There are efficient algorithms, which find an approximate solution. Also, if the numbers in df$value are integers (or may be rounded to integers after an appropriate scaling), then there is an algorithm, whose complexity is O(k*n*max(df$value)). This may be significantly less than choose(n, k). CRAN task view Optimization and Mathematical Programming http://cran.at.r-project.org/web/views/Optimization.html may suggest also other solutions. Petr Savicky. __ 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] Standard variance / devistion clarification
Dear gurus, Im a newbie, and I want to ask a very general question. Assume that I have a set of numbers as follows, 1, 1, 2, 10, 100, 10,1 From these, I need to identify which number is the most different as compared to others. (in this case, it will be 100, since its way larger than the other numbers). It doesnt have to be specifically this way, but I need to identify which number(s) are most different compared to the others. Any idea as to what I need to do this ? Im a math noob, so I'm also going to need to ask it this is called 'standard deviation' or 'variance' :-) -- Best Regards, Suranga [[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] Delete rows from data.frame matching a certain criteria
Hi, On Thu, Mar 1, 2012 at 11:11 AM, mails mails00...@gmail.com wrote: Hello, consider the following data.frame: test - data.frame(n = c(1,2,3,4,5), v = c(6,5,7,5,3), pattern = c(1,1,NA,1,NA)) test n v pattern 1 1 6 1 2 2 5 1 3 3 7 NA 4 4 5 1 5 5 3 NA Thanks for the reproducible example. I tried to use apply and the adply function to set v to NA where pattern = 1 and v to v where pattern = 1 Presumably that should be set v to NA where pattern == 1 and v to v where pattern != 1 So basically the result should look like this: test n v pattern 1 1 NA 1 2 2 NA 1 3 3 7 NA 4 4 NA 1 5 5 3 NA So far, I solved it by creating subsets and using merge but it turns out to be super slow. Is there a way to do that with the apply function? Far too much work. What about: test$v - ifelse(test$pattern == 1, NA, v) test n v pattern 1 1 NA 1 2 2 NA 1 3 3 NA NA 4 4 NA 1 5 5 NA NA -- 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.
Re: [R] Delete rows from data.frame matching a certain criteria
Your criteria did not make sense since in both cases pattern == 1, so I chose to set to NA if pattern == 1 test - data.frame(n = c(1,2,3,4,5), v = c(6,5,7,5,3), pattern = + c(1,1,NA,1,NA)) test n v pattern 1 1 6 1 2 2 5 1 3 3 7 NA 4 4 5 1 5 5 3 NA # set v to NA when pattern = 1 test$v[!is.na(test$pattern) (test$pattern == 1)] - NA test n v pattern 1 1 NA 1 2 2 NA 1 3 3 7 NA 4 4 NA 1 5 5 3 NA On Thu, Mar 1, 2012 at 11:11 AM, mails mails00...@gmail.com wrote: Hello, consider the following data.frame: test - data.frame(n = c(1,2,3,4,5), v = c(6,5,7,5,3), pattern = c(1,1,NA,1,NA)) test n v pattern 1 1 6 1 2 2 5 1 3 3 7 NA 4 4 5 1 5 5 3 NA I tried to use apply and the adply function to set v to NA where pattern = 1 and v to v where pattern = 1 So basically the result should look like this: test n v pattern 1 1 NA 1 2 2 NA 1 3 3 7 NA 4 4 NA 1 5 5 3 NA So far, I solved it by creating subsets and using merge but it turns out to be super slow. Is there a way to do that with the apply function? Any help/hint is appreciated Thanks -- View this message in context: http://r.789695.n4.nabble.com/Delete-rows-from-data-frame-matching-a-certain-criteria-tp4435414p4435414.html Sent from the R help mailing list archive at Nabble.com. __ 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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ 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] Need help using Melt and cast to compute correlation for a cross tabulation
Here is another way of doing it: x - read.table(text =Count Volume FCLASS + 1 55000 6 'Grade Separated' + 2 43000 39000 'Grade Separated' + 3 26000 26500 'Major Arterial' + 4 19500 2 'Major Arterial', as.is = TRUE) result - sapply(split(x, x$FCLASS), function(.grp) cor(.grp$Count, .grp$Volume)) result Grade Separated Major Arterial 1 1 On Thu, Mar 1, 2012 at 12:23 PM, Walter Anderson wandrso...@gmail.comwrote: I have a data frame with a number of observed and predicted values by classification as shown below: Count Volume FCLASS 1 55000 6 Grade Separated 2 43000 39000 Grade Separated 3 26000 26500 Major Arterial 4 19500 2 Major Arterial ... There are four classes here: Grade Separated, Major Arterial, Minor Arterial, and Collector I am looking to compute the following information FCLASS cor(Count,Volume) Grade Separated 0.999 Major Arterial 0.999 Minor Arterial 0.999 Collector 0.999 I am attempting to use the following commands to achieve this: library(reshape) tmp - melt(dataframe) cast(tmp, FCLASS ~ variable, function(Count, Volume) cor(Count, Volume)) but this is generating: Error in is.data.frame(y) : argument Volume is missing, with no default Any suggestions? Walter Anderson __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. [[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] Standard variance / devistion clarification
On Mar 1, 2012, at 12:30 PM, Suranga Kasthurirathne wrote: Dear gurus, Im a newbie, and I want to ask a very general question. Assume that I have a set of numbers as follows, 1, 1, 2, 10, 100, 10,1 From these, I need to identify which number is the most different as compared to others. (in this case, it will be 100, since its way larger than the other numbers). It doesnt have to be specifically this way, but I need to identify which number(s) are most different compared to the others. Any idea as to what I need to do this ? Im a math noob, so I'm also going to need to ask it this is called 'standard deviation' or 'variance' :-) You are requested not to use rhelp as a statistics QA list. It was not set up to remediate gaps in statistics education. There are other websites and perhaps mailing list whose purposes would be a better fit for this question. -- David Winsemius, MD West Hartford, CT __ 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] GLM with regularization
Google is your friend! -- as usual. If you had searched on glm with regularization you would have bumped into the glmnet R package, which I think is what you're looking for. -- Bert On Wed, Feb 29, 2012 at 6:22 PM, Dmitriy Lyubimov dlie...@gmail.com wrote: Hello, Thank you for probably not so new question, but i am new to R. Does any of packages have something like glm+regularization? So far i see probably something close to that as a ridge regression in MASS but I think i need something like GLM, in particular binomial regularized versions of polynomial regression. Also I am not sure how some of the K-fold crossvalidation helpers out there (cv.glm) could be used to adjust reg rate as there seems to be no way to apply them over data not used for training (or i am not seeing a solution here as training is completely separated from crossvalidation error computation here) . The example here in cv.glm doesn't look right to me since it computes cv error over model trained on 100% of data. (e.g. wikipedia crossvalidation article lists this as an example of misuse of K-fold CV). - doc quote # leave-one-out and 6-fold cross-validation prediction error for # the mammals data set. data(mammals, package=MASS) mammals.glm - glm(log(brain)~log(body),data=mammals) cv.err - cv.glm(mammals,mammals.glm) cv.err.6 - cv.glm(mammals, mammals.glm, K=6) end of quote --- Those seem to be pretty common techniques, any poniter in the right direction (package) will be greatly appreciated. thank you very much. -Dmitriy __ 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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ 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] Delete rows from data.frame matching a certain criteria
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of mails Sent: Thursday, March 01, 2012 8:11 AM To: r-help@r-project.org Subject: [R] Delete rows from data.frame matching a certain criteria Hello, consider the following data.frame: test - data.frame(n = c(1,2,3,4,5), v = c(6,5,7,5,3), pattern = c(1,1,NA,1,NA)) test n v pattern 1 1 6 1 2 2 5 1 3 3 7 NA 4 4 5 1 5 5 3 NA I tried to use apply and the adply function to set v to NA where pattern = 1 and v to v where pattern = 1 So basically the result should look like this: test n v pattern 1 1 NA 1 2 2 NA 1 3 3 7 NA 4 4 NA 1 5 5 3 NA So far, I solved it by creating subsets and using merge but it turns out to be super slow. Is there a way to do that with the apply function? Any help/hint is appreciated Thanks There is no need for apply here, this is a simple indexing problem. Something like this should work test$v - ifelse(is.na(test$pattern), test$v, NA) Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Delete rows from data.frame matching a certain criteria
Hi, On Mar 1, 2012, at 12:38 PM, Sarah Goslee wrote: Hi, On Thu, Mar 1, 2012 at 11:11 AM, mails mails00...@gmail.com wrote: Hello, consider the following data.frame: test - data.frame(n = c(1,2,3,4,5), v = c(6,5,7,5,3), pattern = c(1,1,NA,1,NA)) snip So basically the result should look like this: test n v pattern 1 1 NA 1 2 2 NA 1 3 3 7 NA 4 4 NA 1 5 5 3 NA So far, I solved it by creating subsets and using merge but it turns out to be super slow. Is there a way to do that with the apply function? Far too much work. What about: test$v - ifelse(test$pattern == 1, NA, v) test n v pattern 1 1 NA 1 2 2 NA 1 3 3 NA NA 4 4 NA 1 5 5 NA NA Actually that doesn't work because of those pesky missing values. You need test - transform(test, v = ifelse(pattern == 1 !is.na(pattern), NA, v)) Best, Ista -- 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. __ 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] Robust ARMA Fitting in R?
Hello, BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; } Does any one know if there are any functions/packages available in R for robust fitting of ARMA time series models (e.g., similar to the function arima.rob() in S-PLUS)? Many thanks and kind regards, Isabella Isabella R. Ghement, Ph.D. Ghement Statistical Consulting Company 301-7031 Blundell Road, Richmond, B.C., Canada, V6Y 1J5 Tel: 604-767-1250 Fax: 604-270-3922 E-mail: isabe...@ghement.ca Web: www.ghement.ca [[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] Delete rows from data.frame matching a certain criteria
You're all correct: I copied in the wrong thing. My apologies! On Thu, Mar 1, 2012 at 1:00 PM, Ista Zahn istaz...@gmail.com wrote: Hi, On Mar 1, 2012, at 12:38 PM, Sarah Goslee wrote: Hi, On Thu, Mar 1, 2012 at 11:11 AM, mails mails00...@gmail.com wrote: Hello, consider the following data.frame: test - data.frame(n = c(1,2,3,4,5), v = c(6,5,7,5,3), pattern = c(1,1,NA,1,NA)) snip So basically the result should look like this: test n v pattern 1 1 NA 1 2 2 NA 1 3 3 7 NA 4 4 NA 1 5 5 3 NA So far, I solved it by creating subsets and using merge but it turns out to be super slow. Is there a way to do that with the apply function? Far too much work. What about: test$v - ifelse(test$pattern == 1, NA, v) test n v pattern 1 1 NA 1 2 2 NA 1 3 3 NA NA 4 4 NA 1 5 5 NA NA Actually that doesn't work because of those pesky missing values. You need test - transform(test, v = ifelse(pattern == 1 !is.na(pattern), NA, v)) Best, Ista __ 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] GLM with regularization
Thank you. On Thu, Mar 1, 2012 at 9:58 AM, Bert Gunter gunter.ber...@gene.com wrote: Google is your friend! -- as usual. If you had searched on glm with regularization you would have bumped into the glmnet R package, which I think is what you're looking for. -- Bert On Wed, Feb 29, 2012 at 6:22 PM, Dmitriy Lyubimov dlie...@gmail.com wrote: Hello, Thank you for probably not so new question, but i am new to R. Does any of packages have something like glm+regularization? So far i see probably something close to that as a ridge regression in MASS but I think i need something like GLM, in particular binomial regularized versions of polynomial regression. Also I am not sure how some of the K-fold crossvalidation helpers out there (cv.glm) could be used to adjust reg rate as there seems to be no way to apply them over data not used for training (or i am not seeing a solution here as training is completely separated from crossvalidation error computation here) . The example here in cv.glm doesn't look right to me since it computes cv error over model trained on 100% of data. (e.g. wikipedia crossvalidation article lists this as an example of misuse of K-fold CV). - doc quote # leave-one-out and 6-fold cross-validation prediction error for # the mammals data set. data(mammals, package=MASS) mammals.glm - glm(log(brain)~log(body),data=mammals) cv.err - cv.glm(mammals,mammals.glm) cv.err.6 - cv.glm(mammals, mammals.glm, K=6) end of quote --- Those seem to be pretty common techniques, any poniter in the right direction (package) will be greatly appreciated. thank you very much. -Dmitriy __ 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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ 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] Delete rows from data.frame matching a certain criteria
On Mar 1, 2012, at 1:02 PM, Sarah Goslee wrote: You're all correct: I copied in the wrong thing. My apologies! On Thu, Mar 1, 2012 at 1:00 PM, Ista Zahn istaz...@gmail.com wrote: Hi, On Mar 1, 2012, at 12:38 PM, Sarah Goslee wrote: Hi, On Thu, Mar 1, 2012 at 11:11 AM, mails mails00...@gmail.com wrote: Hello, consider the following data.frame: test - data.frame(n = c(1,2,3,4,5), v = c(6,5,7,5,3), pattern = c(1,1,NA,1,NA)) snip So basically the result should look like this: test n v pattern 1 1 NA 1 2 2 NA 1 3 3 7 NA 4 4 NA 1 5 5 3 NA So far, I solved it by creating subsets and using merge but it turns out to be super slow. Is there a way to do that with the apply function? Far too much work. What about: test$v - ifelse(test$pattern == 1, NA, v) test n v pattern 1 1 NA 1 2 2 NA 1 3 3 NA NA 4 4 NA 1 5 5 NA NA Actually that doesn't work because of those pesky missing values. You need test - transform(test, v = ifelse(pattern == 1 !is.na(pattern), NA, v)) What about just using `is.na-`: is.na(test$v) - test$pattern==1 -- David Winsemius, MD West Hartford, CT __ 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] 6 different errors while using glm.nb
Hello to everyone. I need your help. I´m trying to fit the same *glm.nb* to a different data set and i am getting these errors in some of the data. Sometimes, one data set has two of these errors when fitting the model. 1.- Error en while ((it - it + 1) limit abs(del) eps) { : valor ausente donde TRUE/FALSE es necesario 2.- Mensajes de aviso perdidos 1: In sqrt(1/i) : Se han producido NaNs2: In sqrt(1/i) : Se han producido NaNs 3.- glm.fit: fitted rates numerically 0 occurred 4.- glm.fit : algorithm did not converge 5.- Error: no valid set of coefficients has been found: please supply starting values 6.- Error en glm.fitter(x = X, y = Y, w = w, etastart = eta, offset = offset, : NA/NaN/Inf en llamada a una función externa (arg 1) I don´t know why i have this errors. If someone could help me to understand what´s going on i would appreciate. thank you. [[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] Robust ARMA Fitting in R?
On 01-03-2012, at 19:03, isabe...@ghement.ca wrote: Hello, BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; } Does any one know if there are any functions/packages available in R for robust fitting of ARMA time series models (e.g., similar to the function arima.rob() in S-PLUS)? CRAN: http://cran.r-project.org/ In Task Views (left side) goto TimeSeries. And search for arima on that page. Berend __ 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] Robust ARMA Fitting in R?
BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; } Hi Berend, Many thanks for your prompt reply. I followed your instructions but couldn't find what I was looking for. I was hoping that someone who's already worked with such a function could be able to point it out to me. My Google searches came up empty handed. Kind regards, Isabella Isabella R. Ghement, Ph.D. Ghement Statistical Consulting Company 301-7031 Blundell Road, Richmond, B.C., Canada, V6Y 1J5 Tel: 604-767-1250 Fax: 604-270-3922 E-mail: isabe...@ghement.ca Web: www.ghement.ca On Thu 01/03/12 10:29 AM , Berend Hasselman b...@xs4all.nl sent: On 01-03-2012, at 19:03, wrote: Hello, BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; } Does any one know if there are any functions/packages available in R for robust fitting of ARMA time series models (e.g., similar to the function arima.rob() in S-PLUS)? CRAN: http://cran.r-project.org/ [2] In Task Views (left side) goto TimeSeries. And search for arima on that page. Berend Links: -- [2] http://sitemail.netnation.com/parse.php?redirect=http%3A%2F%2Fcran.r-project.org%2F [[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] Execution of Rprofile.site
On 01.03.2012 14:39, Ross Bowden wrote: Hi everyone. I have recently installed R 2.14.1 on my 64-bit Windows 7 laptop. I am attempting to include some favourite functions in the Rprofile.site file to run at R start-up as I did with my previous 32-bit XP machine. I have edited the Rprofile.site file in C:\Program Files\R\R-2.14.1\etc\ but the added code doesn't seem to be executed when I run R, whether through Tinn-R or independently. Any ideas please on what's going wrong? I've searched my laptop and there is only one Rprofile.site file. Also Sys.getenv(R_HOME) returns: [1] C:/PROGRA~1/R/R-214~1.1 so R should be able to find the Rprofile.site file. Note that Rprofile.site has been modified by Tinn-R. Have you disabled the Rprofile.site? What makes you think code is not executed? Uwe Ligges Many thanks Ross Bowden PhD Candidate, Maths Department, Murdoch University. __ 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-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] Robust ARMA Fitting in R?
On 01-03-2012, at 19:33, isabe...@ghement.ca wrote: Hi Berend, Many thanks for your prompt reply. I followed your instructions but couldn't find what I was looking for. I was hoping that someone who's already worked with such a function could be able to point it out to me. My Google searches came up empty handed. I just tried searching in Google for arima R (without the quotes) and got http://stat.ethz.ch/R-manual/R-patched/library/stats/html/arima.html and a lot more. And then searched for arima R robust It appears there is a package TSA which might bw of use to you. Berend __ 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] Connecting points on a line with arcs/curves
?plot On 01.03.2012 16:15, hendersi wrote: Hello, I have a spreadsheet of pairs of coordinates and I would like to plot a line along which curves/arcs connect each pair of coordinates. The aim is to visualise the pattern of point connections. Thanks! Ian -- View this message in context: http://r.789695.n4.nabble.com/Connecting-points-on-a-line-with-arcs-curves-tp4435247p4435247.html Sent from the R help mailing list archive at Nabble.com. __ 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-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] TM reader with text
Le jeudi 01 mars 2012 à 07:07 -0800, Mickael R problem a écrit : Hi Richard, clearly there is a problem with latin ligature because the word resulting from my ask with findFreqTerms give me some wordsU+FB01n U+FB01nancement U+FB01nancier U+FB01nancièreU+FB01nancières U+FB01nanciersU+FB01xe where U+FB01 is a code for latin ligature. The problem is well identified ok. Now, how can I tretaed it. The package TAU seems to offer a solution for text but not for corpus. quoation TAU translate Translate Unicode Latin Ligatures Description Translate Unicode “Latin ligature” characters to their respective constituents. Usage translate_Unicode_latin_ligatures(x) Arguments x a character vector in UTF-8 encoding. Details In typography, a ligature occurs where two or more graphemes are joined as a single glyph. (See http://en.wikipedia.org/wiki/Typographic_ligature for more information.) Unicode (http://www.unicode.org/) lists the following “Latin” ligatures: Code Name 0132 LATIN CAPITAL LIGATURE IJ 0133 LATIN SMALL LIGATURE IJ 0152 LATIN CAPITAL LIGATURE OE 0153 LATIN SMALL LIGATURE OE FB00 LATIN SMALL LIGATURE FF util 9 FB01 LATIN SMALL LIGATURE FI FB02 LATIN SMALL LIGATURE FL FB03 LATIN SMALL LIGATURE FFI FB04 LATIN SMALL LIGATURE FFL FB05 LATIN SMALL LIGATURE LONG S T FB06 LATIN SMALL LIGATURE ST translate_Unicode_latin_ligatures translates these to their respective constituent characters. I need this king of fonction for corpus not only text or characters. Any ideas ? Try: corpus - tm_map(corpus, translate_Unicode_latin_ligatures) (with 'corpus' your corpus, of course ;-) __ 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] Plotting a registered sign
R 2.14.0 OS X Marc's proposed solution (appearing at the end of this email) is perfect -- thanks so much However, some questions remain: 1. The following works: plot(1, type=n) text(1, 1, expression(symbol(\342))) but this does not work (TEXT appears in a symbol font) plot(1, type=n) TEXT- \342 text(1, 1, expression(symbol(TEXT))) nor does this work (it yields: Error: could not find function symbol) plot(1, type=n) TEXT- symbol(\342) text(1, 1, expression(TEXT)) Clearly, I do not understand the subtleties of plotmath. Could someone explain? 2. How would one learn that \342 corresponds to the copyright sign in the symbol font? (i.e., is there a list of all possible characters) Dennis Fisher MD P (The P Less Than Company) Phone: 1-866-PLessThan (1-866-753-7784) Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com On Feb 29, 2012, at 6:55 PM, Marc Schwartz wrote: Dennis, Depending upon some additional fine tuning, here is a generic example: plot(1) legend(topright, pch = 1, legend = expression(SOMETEXT ^ symbol(\342))) See ?plotmath for more information. The above works on my MBP running Lion. HTH, Marc Schwartz [[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] Quantile scores as dependent variables.. an R and general method question
On Thu, Mar 1, 2012 at 12:07 PM, Doran, Harold hdo...@air.org wrote: Typically this list doesn't support general statistical questions and unfortunately I don't have a better recommendation. It may be more helpful for you to work with a statistician than seek help here. My point is simply that quantile regression is not for modeling outcomes that are quantiles. The fact that you have a dependent variables expressed as a percentile doesn't mean that quantile regression is the appropriate approach. It's fairly widely true that percentiles or ranks behave probabilistically as if they were independent uniform random variables (though unfortunately it can be quite hard to prove in individual cases) so that might be where to start. -thomas -- Thomas Lumley Professor of Biostatistics University of Auckland __ 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] select rows by criteria
Hello, again. Petr Savicky wrote On Thu, Mar 01, 2012 at 05:42:48PM +0100, Petr Savicky wrote: On Thu, Mar 01, 2012 at 04:27:45AM -0800, syrvn wrote: Hello, I am stuck with selecting the right rows from a data frame. I think the problem is rather how to select them then how to implement the R code. Consider the following data frame: df - data.frame(ID = c(1,2,3,4,5,6,7,8,9,10), value = c(34,12,23,25,34,42,48,29,30,27)) What I want to achieve is to select 7 rows (values) so that the mean value of those rows are closest to the value of 35 and the remaining 3 rows (values) are closest to 45. However, each value is only allowed to be sampled once! Hi. If some 3 rows have mean close to 45, then they have sum close to 3*45, so the remaining 7 rows have sum close to sum(df$value) - 3*45 # [1] 169 and they have mean close to 169/7 = 24.14286. In other words, the two criteria cannot be optimized together. For this reason, let me choose the criterion on 3 rows. The closest solution may be found as follows. # generate all triples and compute their means tripleMeans - colMeans(combn(df$value, 3)) # select the index of the triple with mean closest to 35 indClosest - which.min(abs(tripleMeans - 35)) I am sorry. There should be 45 and not 35. indClosest - which.min(abs(tripleMeans - 45)) # generate the indices, which form the closest triple in df$value tripleInd - combn(1:length(df$value), 3)[, indClosest] tripleInd # [1] 1 6 7 # check the mean of the triple mean(df$value[tripleInd]) # [1] 41.3 Petr Savicky. __ R-help@ 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. There are two solutions for the 3 rows criterion, 'which.min' only finds one, the first in the order given by 'combn'. (And I've corrected my first post but still with an error) # Forgot to change the index matrix meansDist2 - apply(inxmat2, 2, function(jnx) f(jnx, DF$value, 45)) # Two solutions (i2 - which(meansDist2 == min(meansDist2))) inxmat2[, i2] mean(DF$value[inxmat2[, i2][, 1]]) [1] 41.3 Petr's solution and mine give the same mean value. But use for small values of (n, k) only. Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/select-rows-by-criteria-tp4434812p4435760.html Sent from the R help mailing list archive at Nabble.com. __ 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] How to deal with missing values when using Random Forrest
Hi, Thanks for your help, This worked very well: na.action=na.roughfix Kevin On Sun, Feb 26, 2012 at 3:10 PM, Weidong Gu anopheles...@gmail.com wrote: Hi, You can set na.action=na.roughfix which fills NAs with the mean or mode of the missing variable. Other option is to impute missing values using rfImpute, then run randomForest on the complete data set. Weidong Gu On Sat, Feb 25, 2012 at 6:24 PM, kevin123 kevincorry...@gmail.com wrote: I am using the package Random Forrest to test and train a model, I aim to predict (LengthOfStay.days),: library(randomForest) model - randomForest( LengthOfStay.days~.,data = training, + importance=TRUE, + keep.forest=TRUE + ) *This is a small portion of the data frame: * *data(training)* LengthOfStay.days CharlsonIndex.numeric DSFS.months 1 0 0.0 8.5 6 0 0.0 3.5 7 0 0.0 0.5 8 0 0.0 0.5 9 0 0.0 1.5 11 0 1.5 NaN *Error message* Error in na.fail.default(list(LengthOfStay.days = c(0, 0, 0, 0, 0, 0, : missing values in object, I would greatly appreciate any help Thanks Kevin -- View this message in context: http://r.789695.n4.nabble.com/How-to-deal-with-missing-values-when-using-Random-Forrest-tp4421254p4421254.html Sent from the R help mailing list archive at Nabble.com. __ 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] Rscript example
Hi there, I am trying to find an example how to use Rscript Let's suppose I want to pass 3 arguments (I don't want [options] and -e [expressions] as described in help) *on the command line myRscript.R -arg1=value1 -arg2=value2 -arg3=value3 *In the script #! /path/to/Rscript args = commandArgs(TRUE); From what I see args is just a string, do I do things correctly ? -- View this message in context: http://r.789695.n4.nabble.com/Rscript-example-tp4436130p4436130.html Sent from the R help mailing list archive at Nabble.com. __ 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] fridays date to date
Hello, How do I get the dates of all Fridays between two dates? thanks, Ben [[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] Plotting a registered sign
Hi Dennis, There are some subtleties in the way that 'symbol' is handled in plotmath. There is no symbol() function, per se, though there is an as.symbol() function, which is used differently. 'symbol' as used in plotmath, is telling R to plot the character using a symbol font, which is the same as 'font = 5'. If you look at some of the examples in ?plotmath and ?bquote, you can see that there is the use of the syntax: .(VarName) where VarName is the name of a scalar that contains the value/character that is desired to be plotted. Thus, to do the sort of thing you desire: TEXT - \342 plot(1, type = n) text(1, 1, bquote(symbol(.(TEXT or: plot(1, type = n) text(1, 1, bquote(.(TEXT)), font = 5) Also, with respect to a listing of the symbols, see the References section of ?plotmath, which leads you to pages such as: http://www.stat.auckland.ac.nz/~paul/R/CM/AdobeSym.html HTH, Marc On Mar 1, 2012, at 1:40 PM, Dennis Fisher wrote: R 2.14.0 OS X Marc's proposed solution (appearing at the end of this email) is perfect -- thanks so much However, some questions remain: 1. The following works: plot(1, type=n) text(1, 1, expression(symbol(\342))) but this does not work (TEXT appears in a symbol font) plot(1, type=n) TEXT- \342 text(1, 1, expression(symbol(TEXT))) nor does this work (it yields:Error: could not find function symbol) plot(1, type=n) TEXT- symbol(\342) text(1, 1, expression(TEXT)) Clearly, I do not understand the subtleties of plotmath. Could someone explain? 2. How would one learn that \342 corresponds to the copyright sign in the symbol font? (i.e., is there a list of all possible characters) Dennis Fisher MD P (The P Less Than Company) Phone: 1-866-PLessThan (1-866-753-7784) Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com On Feb 29, 2012, at 6:55 PM, Marc Schwartz wrote: Dennis, Depending upon some additional fine tuning, here is a generic example: plot(1) legend(topright, pch = 1, legend = expression(SOMETEXT ^ symbol(\342))) See ?plotmath for more information. The above works on my MBP running Lion. HTH, Marc Schwartz [[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] function for filtering and deleting vector entries
Thank you Rui, that helped a lot. The correct values show up when I'm using the following code. Now fun(Temp,v) returns a matrix, and Temp and v stay the same. But I'd like to use the reduced vectors in some calculations..can they be extracted in some way so that I have them separately again? fun - function(Temp, v){ unwanted - Temp = 16 | Temp = 38.5 Temp - Temp[!unwanted] v - v[!unwanted] list(Temp=Temp, v=v) } fun(Temp,v) PS: thank you too,andrija..but it's not what I'm looking for -- View this message in context: http://r.789695.n4.nabble.com/function-for-filtering-and-deleting-vector-entries-tp4432410p4436217.html Sent from the R help mailing list archive at Nabble.com. __ 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] function for filtering and deleting vector entries
Of course, just use x - fun(Temp, v) x$Temp # To get back temp x[[Temp]] x$v # To get back v x[[v]] Michael On Thu, Mar 1, 2012 at 3:15 PM, babyluck madr...@gmx.ch wrote: Thank you Rui, that helped a lot. The correct values show up when I'm using the following code. Now fun(Temp,v) returns a matrix, and Temp and v stay the same. But I'd like to use the reduced vectors in some calculations..can they be extracted in some way so that I have them separately again? fun - function(Temp, v){ unwanted - Temp = 16 | Temp = 38.5 Temp - Temp[!unwanted] v - v[!unwanted] list(Temp=Temp, v=v) } fun(Temp,v) PS: thank you too,andrija..but it's not what I'm looking for -- View this message in context: http://r.789695.n4.nabble.com/function-for-filtering-and-deleting-vector-entries-tp4432410p4436217.html Sent from the R help mailing list archive at Nabble.com. __ 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-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] fridays date to date
Inelegant, but here's one way: d1 - Sys.Date() d2 - Sys.Date() + 100 library(lubridate) d - seq(d1, d2, by = day) d[wday(d)==6] Michael On Thu, Mar 1, 2012 at 3:02 PM, Ben quant ccqu...@gmail.com wrote: Hello, How do I get the dates of all Fridays between two dates? thanks, Ben [[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-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] Converting a string vector with names to a numeric vector with names
Not paying close attention to detail, I entered the equivalent of pstr-c(b1=200, b2=50, b3=0.3) when what I wanted was pnum-c(b1=200, b2=50, b3=0.3) There was a list thread in 2010 that shows how to deal with un-named vectors, but the same lapply solution doesn't seem to work here i.e., pnum-lapply(pstr, as.numeric) or similar vapply version. The names and = signs seem to mess things up. This is clearly not critical, but it would be nice to know an appropriate transformation. JN __ 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] fridays date to date
On Mar 1, 2012, at 2:02 PM, Ben quant wrote: Hello, How do I get the dates of all Fridays between two dates? thanks, Ben Days - seq(from = as.Date(2012-03-01), to = as.Date(2012-07-31), by = day) str(Days) Date[1:153], format: 2012-03-01 2012-03-02 2012-03-03 2012-03-04 ... # See ?weekdays Days[weekdays(Days) == Friday] [1] 2012-03-02 2012-03-09 2012-03-16 2012-03-23 2012-03-30 [6] 2012-04-06 2012-04-13 2012-04-20 2012-04-27 2012-05-04 [11] 2012-05-11 2012-05-18 2012-05-25 2012-06-01 2012-06-08 [16] 2012-06-15 2012-06-22 2012-06-29 2012-07-06 2012-07-13 [21] 2012-07-20 2012-07-27 HTH, Marc Schwartz __ 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] function for filtering and deleting vector entries
Thank you very much!! Exactly how I wanted it :) -- View this message in context: http://r.789695.n4.nabble.com/function-for-filtering-and-deleting-vector-entries-tp4432410p4436303.html Sent from the R help mailing list archive at Nabble.com. __ 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] fridays date to date
Great thanks! ben On Thu, Mar 1, 2012 at 1:30 PM, Marc Schwartz marc_schwa...@me.com wrote: On Mar 1, 2012, at 2:02 PM, Ben quant wrote: Hello, How do I get the dates of all Fridays between two dates? thanks, Ben Days - seq(from = as.Date(2012-03-01), to = as.Date(2012-07-31), by = day) str(Days) Date[1:153], format: 2012-03-01 2012-03-02 2012-03-03 2012-03-04 ... # See ?weekdays Days[weekdays(Days) == Friday] [1] 2012-03-02 2012-03-09 2012-03-16 2012-03-23 2012-03-30 [6] 2012-04-06 2012-04-13 2012-04-20 2012-04-27 2012-05-04 [11] 2012-05-11 2012-05-18 2012-05-25 2012-06-01 2012-06-08 [16] 2012-06-15 2012-06-22 2012-06-29 2012-07-06 2012-07-13 [21] 2012-07-20 2012-07-27 HTH, Marc Schwartz [[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] Plotting a registered sign
On Mar 1, 2012, at 2:40 PM, Dennis Fisher wrote: R 2.14.0 OS X Marc's proposed solution (appearing at the end of this email) is perfect -- thanks so much However, some questions remain: 1. The following works: plot(1, type=n) text(1, 1, expression(symbol(\342))) but this does not work (TEXT appears in a symbol font) plot(1, type=n) TEXT- \342 text(1, 1, expression(symbol(TEXT))) ?substitute text(1, 1, substitute( symbol(TEXT), list(TEXT=TEXT) ) ) ?bquote text(1, 1, bquote( symbol( .(TEXT ) ) ) ) nor does this work (it yields: Error: could not find function symbol) plot(1, type=n) TEXT- symbol(\342) text(1, 1, expression(TEXT)) Clearly, I do not understand the subtleties of plotmath. expression() does not evaluate names within its arguments. Similar issues arise with the use of $ as a function. That's why it's often the answer to programming questions that one should use obj[[colnam]] than it is to use obj$colnam. [[ does evaluate its argument. Could someone explain? Try instead: plot(1, type=n) TEXT- expression(symbol(\342)) text(1, 1, TEXT) If you want to build up from character-type components then you can use paste and wrap the whole think in as.expression(). bquote() is much better, though. -- David. 2. How would one learn that \342 corresponds to the copyright sign in the symbol font? (i.e., is there a list of all possible characters) Dennis Fisher MD P (The P Less Than Company) Phone: 1-866-PLessThan (1-866-753-7784) Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com On Feb 29, 2012, at 6:55 PM, Marc Schwartz wrote: Dennis, Depending upon some additional fine tuning, here is a generic example: plot(1) legend(topright, pch = 1, legend = expression(SOMETEXT ^ symbol(\342))) See ?plotmath for more information. The above works on my MBP running Lion. HTH, Marc Schwartz [[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. David Winsemius, MD West Hartford, CT __ 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] Rscript example
On Thu, Mar 01, 2012 at 11:53:00AM -0800, statquant2 wrote: Hi there, I am trying to find an example how to use Rscript Let's suppose I want to pass 3 arguments (I don't want [options] and -e [expressions] as described in help) *on the command line myRscript.R -arg1=value1 -arg2=value2 -arg3=value3 *In the script #! /path/to/Rscript args = commandArgs(TRUE); From what I see args is just a string, do I do things correctly ? Hi. Extending your example with print(args), i obtained ./myRscript.R -arg1=value1 -arg2=value2 -arg3=value3 [1] -arg1=value1 -arg2=value2 -arg3=value3 If you can use a fixed order of the arguments, then you need not use the -arg[i]= parts. The arguments are strings on the command line, so they are also passed to R as strings, but you can convert them inside the script. For example, with the above script, i get ./myRscript.R 23 45 78 [1] 23 45 78 However, if the script contains args - as.numeric(args) , then i get ./myRscript.R 23 45 78 [1] 23 45 78 which is a numeric vector. If you want to keep the arg[i]= structure, you can have in the script x - strsplit(args, =) print(x) and a call produces ./myRscript.R -arg1=value1 -arg2=value2 -arg3=value3 [[1]] [1] -arg1 value1 [[2]] [1] -arg2 value2 [[3]] [1] -arg3 value3 The list x may then be further analyzed. Hope this helps. Petr Savicky. __ 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] Converting a string vector with names to a numeric vector with names
On Thu, Mar 1, 2012 at 12:28 PM, John C Nash nas...@uottawa.ca wrote: Not paying close attention to detail, I entered the equivalent of pstr-c(b1=200, b2=50, b3=0.3) when what I wanted was pnum-c(b1=200, b2=50, b3=0.3) There was a list thread in 2010 that shows how to deal with un-named vectors, but the same lapply solution doesn't seem to work here i.e., pnum-lapply(pstr, as.numeric) or similar vapply version. The names and = signs seem to mess things up. This is clearly not critical, but it would be nice to know an appropriate transformation. Here's one: split = sapply(strsplit(pstr, split = =), I); pnum = as.numeric(split[2, ]); names(pnum) = split[1, ]; pnum b1b2b3 200.0 50.0 0.3 HTH Peter __ 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] fill data forward in data frame.
Hello, My direct desire is a good (fast) way to fill values forward until there is another value then fill that value foward in the data xx (at the bottom of this email). For example, from row 1 to row 45 should be NA (no change), but from row 46 row 136 the value should be 12649, and from row 137 to the next value should be 13039.00. The last line of code is all you need for this part. If you are so inclined, my goal is this: I want to create a weekly time series out of some data based on the report date. The report date is 'rd' below, and is the correct date for the time series. My idea (in part seen below) is to align rd and ua via the incorrect date (the time series date), then merge that using the report date (rd) and a daily series (so I capture all of the dates) of dates (dt). That gets the data in the right start period. I've done all of this so far below and it looks fine. Then I plan to roll all of those values forward to the next value (see question above), then I'll do something like this: xx[weekdays(xx[,1]) == Friday,] ...to get a weekly series of Friday values. I'm thinking someone probably has a faster way of doing this. I have to do this many times, so speed is important. Thanks! Here is what I have done so far: dt - seq(from =as.Date(2009-06-01), to = Sys.Date(), by = day) nms [1] 2009-06-30 2009-09-30 2009-12-31 2010-03-31 2010-06-30 2010-09-30 2010-12-31 2011-03-31 2011-06-30 2011-09-30 [11] 2011-12-31 rd 2009-06-30 2009-09-30 2009-12-31 2010-03-31 2010-06-30 2010-09-30 2010-12-31 2011-03-31 2011-06-30 2011-09-30 2009-07-16 2009-10-15 2010-01-19 2010-04-19 2010-07-19 2010-10-18 2011-01-18 2011-04-19 2011-07-18 2011-10-17 2011-12-31 2012-01-19 ua 2009-06-30 2009-09-30 2009-12-31 2010-03-31 2010-06-30 2010-09-30 2010-12-31 2011-03-31 2011-06-30 2011-09-30 2011-12-31 12649.00 13039.00 13425.00 13731.00 14014.00 14389.00 14833.00 15095.00 15481.43 15846.43 16186.43 x = merge(ua,rd,by='row.names') names(x) = c('z.date','val','rt_date') xx = merge(dt,x,by.y= 'rt_date',by.x=1,all.x=T) xx x z.date val 1 2009-06-01 NANA 2 2009-06-02 NANA 3 2009-06-03 NANA 4 2009-06-04 NANA 5 2009-06-05 NANA ...ect 36 2009-07-06 NANA 37 2009-07-07 NANA 38 2009-07-08 NANA 39 2009-07-09 NANA 40 2009-07-10 NANA 41 2009-07-11 NANA 42 2009-07-12 NANA 43 2009-07-13 NANA 44 2009-07-14 NANA 45 2009-07-15 NANA 46 2009-07-16 2009-06-30 12649 47 2009-07-17 NANA 48 2009-07-18 NANA 49 2009-07-19 NANA 50 2009-07-20 NANA 51 2009-07-21 NANA 52 2009-07-22 NANA 53 2009-07-23 NANA 54 2009-07-24 NANA 55 2009-07-25 NANA 56 2009-07-26 NANA 57 2009-07-27 NANA 58 2009-07-28 NANA ...ect 129 2009-10-07 NA NA 130 2009-10-08 NA NA 131 2009-10-09 NA NA 132 2009-10-10 NA NA 133 2009-10-11 NA NA 134 2009-10-12 NA NA 135 2009-10-13 NA NA 136 2009-10-14 NA NA 137 2009-10-15 2009-09-30 13039.00 138 2009-10-16 NA NA 139 2009-10-17 NA NA 140 2009-10-18 NA NA 141 2009-10-19 NA NA 142 2009-10-20 NA NA 143 2009-10-21 NA NA ...ect [[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] Converting a string vector with names to a numeric vector with names
On Thu, Mar 01, 2012 at 03:28:31PM -0500, John C Nash wrote: Not paying close attention to detail, I entered the equivalent of pstr-c(b1=200, b2=50, b3=0.3) when what I wanted was pnum-c(b1=200, b2=50, b3=0.3) There was a list thread in 2010 that shows how to deal with un-named vectors, but the same lapply solution doesn't seem to work here i.e., pnum-lapply(pstr, as.numeric) or similar vapply version. The names and = signs seem to mess things up. This is clearly not critical, but it would be nice to know an appropriate transformation. Hi. Try the following. mat - sapply(strsplit(pstr, =), identity) x - as.numeric(mat[2, ]) names(x) - mat[1, ] x b1b2b3 200.0 50.0 0.3 Hope this helps. Petr Savicky. __ 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] Converting a string vector with names to a numeric vector with names
Gotta love R. Thanks to Bill Dunlap, Peter Langfelder and Jim Holtman for no less than 3 different solutions. JN On 12-03-01 04:25 PM, Peter Langfelder wrote: pstr-c(b1=200, b2=50, b3=0.3) split = sapply(strsplit(pstr, split = =), I); pnum = as.numeric(split[2, ]); names(pnum) = split[1, ]; __ 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] Connecting points on a line with arcs/curves
That's nice. Please read the posting guidelines and get back to us with some information on what the data looks like an what you are doing. For example do you just want lines or do you want a smoother, etc? John Kane Kingston ON Canada -Original Message- From: ir...@cam.ac.uk Sent: Thu, 1 Mar 2012 07:15:52 -0800 (PST) To: r-help@r-project.org Subject: [R] Connecting points on a line with arcs/curves Hello, I have a spreadsheet of pairs of coordinates and I would like to plot a line along which curves/arcs connect each pair of coordinates. The aim is to visualise the pattern of point connections. Thanks! Ian -- View this message in context: http://r.789695.n4.nabble.com/Connecting-points-on-a-line-with-arcs-curves-tp4435247p4435247.html Sent from the R help mailing list archive at Nabble.com. __ 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. FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! __ 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] Help with segmented package
dear Phil, plot.segmented() accepts vectorized 'col', 'lty' and 'lwd' arguments. Then, par(mfrow=c(1,2)) plot(o.seg,col=2:3,lty=2:3,lwd=c(1,2)) plot(z,y) plot(o.seg,col=2:3,lty=1,linkinv=T,add=T,lwd=2) hope this helps you, vito On Thu, 1 Mar 2012 08:57:39 -0800 (PST), Filoche wrote Hi everyone. I'm using segmented package to find break point in a bi-linear relationship. In a particular case, I find 1 pointcut (so 2 slopes). I would like to know if it is possible to retrieve information in the segmented object that could let me to plot 1 particular segment with a different color. For example, in that folowing example, I would like to plot the second segment in red. library(segmented) set.seed(1234) z-runif(100) y-rpois(100,exp(2+1.8*pmax(z-.6,0))) o-glm(y~z,family=poisson) o.seg-segmented(o,seg.Z=~z,psi=list(z=.5)) plot(o.seg) Thank in advance, Phil -- View this message in context: http://r.789695.n4.nabble.com/Help-with- segmented-package-tp4435550p4435550.html Sent from the R help mailing list archive at Nabble.com. __ 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. -- Open WebMail Project (http://openwebmail.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.
[R] problem with sum function
Hi! I'm running R version 2.13.0 (2011-04-13) Platform: i386-pc-mingw32/i386 (32-bit) When i type in the command: sum(c(-0.2, 0.8, 0.8, -3.2, 1.8)) R returns the value: -5.551115e-17 Why doesn't R return zero in this case? There shouldn't be any rounding error in a simple sum. Thanks, Mark __ 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] Standard variance / devistion clarification
No it's an outlier problem, I think. If you have a fairly small number of sets of these numbers simple visual inspection of a boxplot for each set would probably acomplish what you want. Try this in R for an example. Just paste the next two lines into R xx - c(1, 1, 2, 10, 100, 10,1) boxplot(xx) After this it gets more complicated, but it you're new here let's take it one step at a time John Kane Kingston ON Canada -Original Message- From: suranga...@gmail.com Sent: Thu, 1 Mar 2012 09:30:59 -0800 To: r-help@r-project.org Subject: [R] Standard variance / devistion clarification Dear gurus, Im a newbie, and I want to ask a very general question. Assume that I have a set of numbers as follows, 1, 1, 2, 10, 100, 10,1 From these, I need to identify which number is the most different as compared to others. (in this case, it will be 100, since its way larger than the other numbers). It doesnt have to be specifically this way, but I need to identify which number(s) are most different compared to the others. Any idea as to what I need to do this ? Im a math noob, so I'm also going to need to ask it this is called 'standard deviation' or 'variance' :-) -- Best Regards, Suranga [[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. Send your photos by email in seconds... TRY FREE IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if3 Works in all emails, instant messengers, blogs, forums and social networks. __ 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] problem with sum function
Of course there's rounding error: your computer can't store those decimal numbers precisely. See R FAQ 7.31 for details. See also: sum(10*c(-0.2, 0.8, 0.8, -3.2, 1.8)) / 10 Sarah On Thu, Mar 1, 2012 at 4:49 PM, Mark A. Albins kamoko...@gmail.com wrote: Hi! I'm running R version 2.13.0 (2011-04-13) Platform: i386-pc-mingw32/i386 (32-bit) When i type in the command: sum(c(-0.2, 0.8, 0.8, -3.2, 1.8)) R returns the value: -5.551115e-17 Why doesn't R return zero in this case? There shouldn't be any rounding error in a simple sum. Thanks, Mark -- 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.
Re: [R] fill data forward in data frame.
On Thu, Mar 01, 2012 at 02:31:01PM -0700, Ben quant wrote: Hello, My direct desire is a good (fast) way to fill values forward until there is another value then fill that value foward in the data xx (at the bottom of this email). For example, from row 1 to row 45 should be NA (no change), but from row 46 row 136 the value should be 12649, and from row 137 to the next value should be 13039.00. The last line of code is all you need for this part. If you are so inclined, my goal is this: I want to create a weekly time series out of some data based on the report date. The report date is 'rd' below, and is the correct date for the time series. My idea (in part seen below) is to align rd and ua via the incorrect date (the time series date), then merge that using the report date (rd) and a daily series (so I capture all of the dates) of dates (dt). That gets the data in the right start period. I've done all of this so far below and it looks fine. Then I plan to roll all of those values forward to the next value (see question above), then I'll do something like this: xx[weekdays(xx[,1]) == Friday,] ...to get a weekly series of Friday values. I'm thinking someone probably has a faster way of doing this. I have to do this many times, so speed is important. Thanks! Here is what I have done so far: dt - seq(from =as.Date(2009-06-01), to = Sys.Date(), by = day) nms [1] 2009-06-30 2009-09-30 2009-12-31 2010-03-31 2010-06-30 2010-09-30 2010-12-31 2011-03-31 2011-06-30 2011-09-30 [11] 2011-12-31 rd 2009-06-30 2009-09-30 2009-12-31 2010-03-31 2010-06-30 2010-09-30 2010-12-31 2011-03-31 2011-06-30 2011-09-30 2009-07-16 2009-10-15 2010-01-19 2010-04-19 2010-07-19 2010-10-18 2011-01-18 2011-04-19 2011-07-18 2011-10-17 2011-12-31 2012-01-19 ua 2009-06-30 2009-09-30 2009-12-31 2010-03-31 2010-06-30 2010-09-30 2010-12-31 2011-03-31 2011-06-30 2011-09-30 2011-12-31 12649.00 13039.00 13425.00 13731.00 14014.00 14389.00 14833.00 15095.00 15481.43 15846.43 16186.43 x = merge(ua,rd,by='row.names') names(x) = c('z.date','val','rt_date') xx = merge(dt,x,by.y= 'rt_date',by.x=1,all.x=T) xx x z.date val 1 2009-06-01 NANA 2 2009-06-02 NANA 3 2009-06-03 NANA 4 2009-06-04 NANA 5 2009-06-05 NANA ...ect 36 2009-07-06 NANA 37 2009-07-07 NANA 38 2009-07-08 NANA 39 2009-07-09 NANA 40 2009-07-10 NANA 41 2009-07-11 NANA 42 2009-07-12 NANA 43 2009-07-13 NANA 44 2009-07-14 NANA 45 2009-07-15 NANA 46 2009-07-16 2009-06-30 12649 47 2009-07-17 NANA 48 2009-07-18 NANA 49 2009-07-19 NANA 50 2009-07-20 NANA 51 2009-07-21 NANA 52 2009-07-22 NANA 53 2009-07-23 NANA 54 2009-07-24 NANA 55 2009-07-25 NANA 56 2009-07-26 NANA 57 2009-07-27 NANA 58 2009-07-28 NANA ...ect 129 2009-10-07 NA NA 130 2009-10-08 NA NA 131 2009-10-09 NA NA 132 2009-10-10 NA NA 133 2009-10-11 NA NA 134 2009-10-12 NA NA 135 2009-10-13 NA NA 136 2009-10-14 NA NA 137 2009-10-15 2009-09-30 13039.00 138 2009-10-16 NA NA 139 2009-10-17 NA NA 140 2009-10-18 NA NA 141 2009-10-19 NA NA 142 2009-10-20 NA NA 143 2009-10-21 NA NA Hi. Try first the following simpler version. # an input vector x - rep(NA, times=20) x[4] - A x[9] - B x[17] - C # extending the values forward values - c(NA, x[!is.na(x)]) ind - cumsum(!is.na(x)) + 1 y - values[ind] # compare with the original cbind(x, y) x y [1,] NA NA [2,] NA NA [3,] NA NA [4,] A A [5,] NA A [6,] NA A [7,] NA A [8,] NA A [9,] B B [10,] NA B [11,] NA B [12,] NA B [13,] NA B [14,] NA B [15,] NA B [16,] NA B [17,] C C [18,] NA C [19,] NA C [20,] NA C This could be applied directly to the last two columns of your data frame xx. However, it may be more natural to obtain the vector values from the input data and not from their sparse form, which is the data frame. Also, the logical vector !is.na(x) is the same for the last two columns of your data frame, so it may be computed only once. Hope this helps. Petr Savicky. __ 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] problem with sum function
In base ten, using any fixed number of digits, compute 1/3 + 1/3 + 1/3 (doing the divisions before the additions). Why isn't it 1? 1/5 has the same sort of problem in base two. 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 Mark A. Albins Sent: Thursday, March 01, 2012 1:50 PM To: r-help@r-project.org Subject: [R] problem with sum function Hi! I'm running R version 2.13.0 (2011-04-13) Platform: i386-pc-mingw32/i386 (32-bit) When i type in the command: sum(c(-0.2, 0.8, 0.8, -3.2, 1.8)) R returns the value: -5.551115e-17 Why doesn't R return zero in this case? There shouldn't be any rounding error in a simple sum. Thanks, Mark __ 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-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] problem with sum function
On Thu, Mar 01, 2012 at 01:49:44PM -0800, Mark A. Albins wrote: Hi! I'm running R version 2.13.0 (2011-04-13) Platform: i386-pc-mingw32/i386 (32-bit) When i type in the command: sum(c(-0.2, 0.8, 0.8, -3.2, 1.8)) R returns the value: -5.551115e-17 Why doesn't R return zero in this case? There shouldn't be any rounding error in a simple sum. Hi. There is a rounding error, since numerical values are represented in binary system and, for example, 0.2 = 1/5 cannot be represented in binary exactly. A simpler version is 0.1 + 0.2 - 0.3 [1] 5.551115e-17 Use round(), for example round(sum(c(-0.2, 0.8, 0.8, -3.2, 1.8)), digits=7) [1] 0 See FAQ 7.31 and/or http://rwiki.sciviews.org/doku.php?id=misc:r_accuracy for further hints. Hope this helps. Petr Savicky. __ 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] Memory problem in R
Hi all, I am running an -MNP- multinomial probit model package using R. It gives me the following objection instead of giving me the results: Erreur : impossible d'allouer un vecteur de taille 137.9 Mo (in english: cannot allocate a 137.9 Mb vector memory). I have already increased the memory size upto 2047Mb. This problem has been discussed in 2008 (archives) but no profitable answers were delievered. I am sending the programming and bit of data. Thanks in advance for your help. model-mnp(choice~1+Asso+FP+BEV+IAA+CER+FrtVeg+Meat+Others+lnADH+lnTO+Emp+LT50inReg+lnEXinEU+lnEXoutEU+GDist+RET+WS+LT50SC+Others_hotel, base=4, n.draws=1, burnin=2000, thin=3, verbose=TRUE, trace=FALSE, p.scale=1, coef.start=0, invcdf=FALSE, cov.start=1) AssoFPCGIAABEVCERFrtVegMeatMilkOilOtherslnADHlnTOEmpLT50inReglnEXinEUlnEXoutEUGDistRETWSLT50SCOthers_hotelchoice 0001103,68897,55331,,0,010004 0001104,86759,01681,,0,14 0001104,90538,98720,,0,010004 0001104,41888,03530,,0,000104 0001105,634815,19545,,69310,000101 10100010003,401214,59170,0010,0,001001 0001104,499815,12016,,0,14 1101103,784213,49204,,0,6931001001 1001101,38638,86052,,0,02 Saqlain RAZA PhD Student [[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] fill data forward in data frame.
That is great! Thank you very much. Ben On Thu, Mar 1, 2012 at 2:57 PM, Petr Savicky savi...@cs.cas.cz wrote: On Thu, Mar 01, 2012 at 02:31:01PM -0700, Ben quant wrote: Hello, My direct desire is a good (fast) way to fill values forward until there is another value then fill that value foward in the data xx (at the bottom of this email). For example, from row 1 to row 45 should be NA (no change), but from row 46 row 136 the value should be 12649, and from row 137 to the next value should be 13039.00. The last line of code is all you need for this part. If you are so inclined, my goal is this: I want to create a weekly time series out of some data based on the report date. The report date is 'rd' below, and is the correct date for the time series. My idea (in part seen below) is to align rd and ua via the incorrect date (the time series date), then merge that using the report date (rd) and a daily series (so I capture all of the dates) of dates (dt). That gets the data in the right start period. I've done all of this so far below and it looks fine. Then I plan to roll all of those values forward to the next value (see question above), then I'll do something like this: xx[weekdays(xx[,1]) == Friday,] ...to get a weekly series of Friday values. I'm thinking someone probably has a faster way of doing this. I have to do this many times, so speed is important. Thanks! Here is what I have done so far: dt - seq(from =as.Date(2009-06-01), to = Sys.Date(), by = day) nms [1] 2009-06-30 2009-09-30 2009-12-31 2010-03-31 2010-06-30 2010-09-30 2010-12-31 2011-03-31 2011-06-30 2011-09-30 [11] 2011-12-31 rd 2009-06-30 2009-09-30 2009-12-31 2010-03-31 2010-06-30 2010-09-30 2010-12-31 2011-03-31 2011-06-30 2011-09-30 2009-07-16 2009-10-15 2010-01-19 2010-04-19 2010-07-19 2010-10-18 2011-01-18 2011-04-19 2011-07-18 2011-10-17 2011-12-31 2012-01-19 ua 2009-06-30 2009-09-30 2009-12-31 2010-03-31 2010-06-30 2010-09-30 2010-12-31 2011-03-31 2011-06-30 2011-09-30 2011-12-31 12649.00 13039.00 13425.00 13731.00 14014.00 14389.00 14833.00 15095.00 15481.43 15846.43 16186.43 x = merge(ua,rd,by='row.names') names(x) = c('z.date','val','rt_date') xx = merge(dt,x,by.y= 'rt_date',by.x=1,all.x=T) xx x z.date val 1 2009-06-01 NANA 2 2009-06-02 NANA 3 2009-06-03 NANA 4 2009-06-04 NANA 5 2009-06-05 NANA ...ect 36 2009-07-06 NANA 37 2009-07-07 NANA 38 2009-07-08 NANA 39 2009-07-09 NANA 40 2009-07-10 NANA 41 2009-07-11 NANA 42 2009-07-12 NANA 43 2009-07-13 NANA 44 2009-07-14 NANA 45 2009-07-15 NANA 46 2009-07-16 2009-06-30 12649 47 2009-07-17 NANA 48 2009-07-18 NANA 49 2009-07-19 NANA 50 2009-07-20 NANA 51 2009-07-21 NANA 52 2009-07-22 NANA 53 2009-07-23 NANA 54 2009-07-24 NANA 55 2009-07-25 NANA 56 2009-07-26 NANA 57 2009-07-27 NANA 58 2009-07-28 NANA ...ect 129 2009-10-07 NA NA 130 2009-10-08 NA NA 131 2009-10-09 NA NA 132 2009-10-10 NA NA 133 2009-10-11 NA NA 134 2009-10-12 NA NA 135 2009-10-13 NA NA 136 2009-10-14 NA NA 137 2009-10-15 2009-09-30 13039.00 138 2009-10-16 NA NA 139 2009-10-17 NA NA 140 2009-10-18 NA NA 141 2009-10-19 NA NA 142 2009-10-20 NA NA 143 2009-10-21 NA NA Hi. Try first the following simpler version. # an input vector x - rep(NA, times=20) x[4] - A x[9] - B x[17] - C # extending the values forward values - c(NA, x[!is.na(x)]) ind - cumsum(!is.na(x)) + 1 y - values[ind] # compare with the original cbind(x, y) x y [1,] NA NA [2,] NA NA [3,] NA NA [4,] A A [5,] NA A [6,] NA A [7,] NA A [8,] NA A [9,] B B [10,] NA B [11,] NA B [12,] NA B [13,] NA B [14,] NA B [15,] NA B [16,] NA B [17,] C C [18,] NA C [19,] NA C [20,] NA C This could be applied directly to the last two columns of your data frame xx. However, it may be more natural to obtain the vector values from the input data and not from their sparse form, which is the data frame. Also, the logical vector !is.na(x) is the same for the last two columns of your data frame, so it may be computed only once. Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting
Re: [R] how to change or copy to another the names of models
A) you will generally get a better response when your question includes reproducible code/sample data, and a clear identification of the desired final result. B) in most cases like this, a proliferation of names is not as useful as the OP (you) thinks it is. Much better is to build a list of results that can be indexed by position or by name. mymodel - vector( list, 30 ) for (i in 5:30) { mymodel[[i]] - mlp(X, Y, size=n,) } --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Waldir de Carvalho Junior waldi...@gmail.com wrote: Hi I would like to know how I can change the name of a model for each trainning cycle of a model. I work with the RSNNS package and to build a neural network, I used : for (i in 5:30) model_ANN - mlp(X, Y, size=n,) # where size is the number of neurons in the hidden layer but I need to save each time that the model that is build (the end of each cycle), e.g., when i = 5, I need to save the model with a especific name, when i = 6, also I need to save the model with another name How i am doing, i am saving only the last model with n = 30 and with the name model_ANN Question how can I change the name of the model (model_ANN) at each end of cycle of i values? I have already tryied copy, save, rename,.. but unsuccessfully thanks for any answer -- Waldir de Carvalho Junior Pedologia/Pedologue Pesquisador/Chercheur Embrapa Solos/INRA - UMR- LISAH [[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-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] problem with sum function
On Thu, Mar 01, 2012 at 04:55:55PM -0500, Sarah Goslee wrote: Of course there's rounding error: your computer can't store those decimal numbers precisely. See R FAQ 7.31 for details. See also: sum(10*c(-0.2, 0.8, 0.8, -3.2, 1.8)) / 10 Hi. This is 0. This works without rounding for one digit precision, since we always have i == 10*(i/10). Already for two digits, we may have i != 100*(i/100). So, for example sum(100*c(0.28, -0.21, 0.66, -0.73))/100 [1] 3.552714e-17 Rounding the multiples to be integers yields the expected result sum(round(100*c(0.28, -0.21, 0.66, -0.73)))/100 [1] 0 Petr Savicky. __ 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] ggplot2: formula for bar width in geom_bar?
Hi, I'm trying to figure out the formula used by ggplot2 to calculate the width of a bar in geom_bar so that I can use that elsewhere in the plot. My code looks like this: ggplot(xAll, aes(Date)) + geom_bar(subset = .(Direction == Up), aes(y = Change, fill = Time), stat = identity) + geom_bar(subset = .(Direction == Down), aes(y = Change, fill = Time), stat = identity) + geom_segment(data = xline, aes(Date, Total, xend = Date, yend = (Total - (sign(Total) * (mean(Total)/25, size = 5, # this is where I need to substitute in the geom_bar width color = white) Right now, I have to manually adjust (i.e. guess) the size of geom_segment so that it matches the width of geom_bar. Can someone point me to the formula used by geom_bar to calculate bar width? I've attached an example plot for reference. Thanks, James attachment: bar_plot.png__ 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] Standard variance / devistion clarification
On 2012-03-01 13:52, John Kane wrote: No it's an outlier problem, I think. If you have a fairly small number of sets of these numbers simple visual inspection of a boxplot for each set would probably acomplish what you want. Try this in R for an example. Just paste the next two lines into R xx- c(1, 1, 2, 10, 100, 10,1) boxplot(xx) For graphical analysis, I would prefer plot(xx, type=h). But most different as compared to the others is not well-defined. Possibly something like scale(xx) would help. Peter Ehlers After this it gets more complicated, but it you're new here let's take it one step at a time John Kane Kingston ON Canada -Original Message- From: suranga...@gmail.com Sent: Thu, 1 Mar 2012 09:30:59 -0800 To: r-help@r-project.org Subject: [R] Standard variance / devistion clarification Dear gurus, Im a newbie, and I want to ask a very general question. Assume that I have a set of numbers as follows, 1, 1, 2, 10, 100, 10,1 From these, I need to identify which number is the most different as compared to others. (in this case, it will be 100, since its way larger than the other numbers). It doesnt have to be specifically this way, but I need to identify which number(s) are most different compared to the others. Any idea as to what I need to do this ? Im a math noob, so I'm also going to need to ask it this is called 'standard deviation' or 'variance' :-) -- Best Regards, Suranga [[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. Send your photos by email in seconds... TRY FREE IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if3 Works in all emails, instant messengers, blogs, forums and social networks. __ 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-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] How to colorize the panel backgrounds of pairs()?
Dear expeRts, I would like to colorize the backgrounds of a pairs plot according to the respective panel number. Here is what I tried (without success): count - 0 mypanel - function(x, y, ...){ count - count+1 bg. - if(count %in% c(1,4,9,12)) #FDFF65 else NA points(x, y, cex=0.5, bg=bg) } U - matrix(runif(4*500), ncol=4) pairs(U, panel=mypanel) I also tried to set par(bg=bg.) before the call to points(), but that didn't work either. The only thing I found is that bg= can be used to fill certain plot symbols, but I would like to colorize the background of each panel, not the drawn circles. Cheers, Marius __ 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] Computing line= for mtext
Rich's pointers deals with lattice/grid graphics. Does anyone have a solution for base graphics? Thanks Frank Richard M. Heiberger wrote Frank, This can be done directly with a variant of the panel.axis function. See function panel.axis.right in the HH package. This was provided for me by David Winsemius in response to my query on this list in October 2011 https://stat.ethz.ch/pipermail/r-help/2011-October/292806.html The email thread also includes comments by Deepayan Sarkar and Paul Murrell. Rich On Wed, Feb 29, 2012 at 8:48 AM, Frank Harrell lt;f.harrell@gt;wrote: I want to right-justify a vector of numbers in the right margin of a low-level plot. For this I need to compute the line parameter to give to mtext. Is this the correct scalable calculation? par(mar=c(4,3,1,5)); plot(1:20) s - 'abcde'; w=strwidth(s, units='inches')/par('cin')[1] mtext(s, side=4, las=1, at=5, adj=1, line=w-.5, cex=1) mtext(s, side=4, las=1, at=7, adj=1, line=2*(w-.5), cex=2) Thanks Frank - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/Computing-line-for-mtext-tp4431554p4431554.html Sent from the R help mailing list archive at Nabble.com. __ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmllt;http://www.r-project.org/posting-guide.htmlgt; and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@ 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. - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/Computing-line-for-mtext-tp4431554p4436923.html Sent from the R help mailing list archive at Nabble.com. __ 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] downloading Excel files
Dear R People: I have been using xlsReadWrite to read Excel files and am very pleased with it. Thank you xlsReadWrite People! My question is: is there a function, similar to get.hist.quote, to download Excel files from the web, please? Thanks, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com __ 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] downloading Excel files
On Thu, Mar 1, 2012 at 6:43 PM, Erin Hodgess erinm.hodg...@gmail.com wrote: Dear R People: I have been using xlsReadWrite to read Excel files and am very pleased with it. Thank you xlsReadWrite People! My question is: is there a function, similar to get.hist.quote, to download Excel files from the web, please? If you just need to download then you could try download.file() from utils. Otherwise read.xls from gdata might work for you. It supports http://;, https://;, and ftp://; URLS. HTH James Thanks, Erin __ 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] downloading Excel files
Thanks J! I was thinking about the url, download.file functions too Just wanted to make sure that there wasn't something special for Excel. Thanks, Erin On Thu, Mar 1, 2012 at 6:53 PM, J Toll jct...@gmail.com wrote: On Thu, Mar 1, 2012 at 6:43 PM, Erin Hodgess erinm.hodg...@gmail.com wrote: Dear R People: I have been using xlsReadWrite to read Excel files and am very pleased with it. Thank you xlsReadWrite People! My question is: is there a function, similar to get.hist.quote, to download Excel files from the web, please? If you just need to download then you could try download.file() from utils. Otherwise read.xls from gdata might work for you. It supports http://;, https://;, and ftp://; URLS. HTH James Thanks, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com __ 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.