Re: [R] using R for online course/distance ed
Hi Erin, I'm not a teacher, and I don't have any experience in teaching, but I have been working on the demonstration of statistical ideas via animations (I think they will effectively prevent students from sleeping in class ^o^). I hope this would be of some help to you: http://animation.yihui.name Best, Yihui On Thu, Sep 11, 2008 at 7:11 AM, Erin Hodgess [EMAIL PROTECTED] wrote: Hi R People! I'm going to be putting together a completely online undergrad business stats course (a second semester course) and was going to use R and Rcmdr. My question: has anyone else used R for an online course, please? If so, did it go well, please? Thanks in advance, Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: [EMAIL PROTECTED] -- Yihui Xie [EMAIL PROTECTED] Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China __ 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] All possible pairs of two variables
Just simple loops as follows: z = NULL for (y in 0:10) { for (x in 0:y) { z = rbind(z, c(x, y)) } } z Yihui On Thu, Sep 11, 2008 at 12:34 PM, Ron Michael [EMAIL PROTECTED] wrote: I have two variables (x,y) : x : it takes all integer values from 0 to y and, y : takes all values from 0, 10 I am looking for some R code to find all possible pairs of (x,y). Can anyone please help me? -- Yihui Xie [EMAIL PROTECTED] Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China __ 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] binomial(link=inverse)
On Wed, 10 Sep 2008, Thomas Lumley wrote: On Wed, 10 Sep 2008, Prof Brian Ripley wrote: As to why the list of links known by name is as it is, that seems history. in part the White Book history of S. I've always thought it an error that 'log' was a standard link for binomial, as the range does not match the specification of probabilities (and S did not do so, MASS Table 7.1 ). I think I added binomial(log): log-binomial regression is quite popular and useful in epidemiology (where effect sizes are small enough that keeping away from the boundary may be less of a problem than people's inability to understand odds ratios). Yes. My comment was about being standard and so easy to use unthinkingly. Where a Poisson approximation to the binomial would be good, a log link is also going to be appropriate. Had we then the infrastructure in place we have now, I would have been suggesting (like identity) that it be available via an (easy) user extension. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ 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 way clustering
Hi, I am trying to do two-way clustering (using information of both observation and variables). Is there any package available in R. There is a package for biclustering in development on R-Forge http://r-forge.r-project.org/projects/biclust/ Slides from a recent presentation of the package at useR!2008 can be found at http://www.statistik.uni-dortmund.de/useR-2008//slides/Kaiser+Leisch.pdf Another querry, if somebody can provide related information (website) regarding this statistics, it will be great. You can find a nice review by Iven Van Mechelen et al. at http://ppw.kuleuven.be/okp/_pdf/VanMechelen2004TMCMA.pdf HTH, Tobias __ 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] RSiteSearch for words ``as one entity''.
If firefox is involved on a Mac, that is one difference. My Mac is using 'open' (the default, I believe) and that is calling Safari (the default, I believe). Yes, it would be the job of browseURL to encode URLs where required. But at least on Windows and using the -remoteURL mechanism (as on Linux) it is not. R itself does have URLencode. On Thu, 11 Sep 2008, Rolf Turner wrote: On 11/09/2008, at 10:09 AM, Marc Schwartz wrote: snip As Prof. Ripley noted, try using debug(RSiteSearch) and then step through the code to see where $HOME is being added to the URL variable. That can help pin it down further. If the URL is not corrupted by the time browseURL() is called, then use debug(browseURL) to trace within that function to see if something is happening there. I have done some digging. When I do: RSiteSearch(logistic regression) the RSiteSearch() function calls browseURL(qstring) where qstring is qs1 equal to http://search.r-project.org/cgi-bin/namazu.cgi?query=logistic+regressionmax=20result=normalsort=scoreidxname=Rhelp02aidxname=functionsidxname=docs; Similarly when I do RSiteSearch({logistic regression}) qstring is qs2 equal to http://search.r-project.org/cgi-bin/namazu.cgi?query={logistic+regression}max=20result=normalsort=scoreidxname=Rhelp02aidxname=functionsidxname=docs; i.e. the same except for the braces. If I do browseURL(qs1) outside of RSiteSearch() it works as expected. If I do browseURL(qs2) I get the error. Inside browseURL I find that it calls system(paste(browser, remoteCmd, /dev/null 21 ||, browser, quotedUrl, )) and browser is /usr/bin/open, remoteCmd is the qstring with the opening and closing quote marks attached (escaped with a ``\'') amd quotedUrl is the same. This is true irrespective of which qstring (qs1 or qs2 is used). Note that the double backslash shows up in remoteCmd == quotedUrl at this stage. Finally I put the system command into a file ``junk'' and from the command window (outside R) executed ``sh junk''. With the braces around ``logistic regression'' I can the same error message that I got in R. When I simply edited out the braces, the Firefox window opened at the appropriate URL. So the problem is in those braces and the single/double backslash at the start was a red herring. Finally, while I was doing all this I got Henrik Bengtsson's message, and tried his suggestion: library(R.utils) browseURL(toUrl(qs2)) and BINGO!!! that worked. (Thanks very much, Henrik.) It's still mysterious why the braces have their deleterious impact on my Mac but do not have that impact on Professor Ripley's machine. (But that's the story of my life: THEY always pick on ***me***! :-) ) So my problem is solved --- via a workaround --- but there's still some vestigial strangeness. Thanks to all who helped me, especially (again) to Henrik Bengtsson cheers, Rolf ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ 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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ 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] request: most repeated component of a list
May be i could not explain properly. Actually there are components of list i.e. [[1]] to [[500]]. Each component containing r-rows (may be different for each [[ k ]] and c-columns same for all). I have to compare all the [[ k ]] components of that list and found the one appearing maximum no of times. e.g. from three components [[1]] to [[3]] given below. The most repeated is [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]43400 [3,]43400 [4,]43000Please help to find it. Thanks and best regards Muhammad Azam - Original Message From: jim holtman [EMAIL PROTECTED] To: Muhammad Azam [EMAIL PROTECTED] Cc: R-help request [EMAIL PROTECTED]; R Help r-help@r-project.org Sent: Wednesday, September 10, 2008 5:59:28 PM Subject: Re: [R] request: most repeated component of a list If want you want is the summary from all of them, then 'rbind' the data together into one matrix and analyze it: totalMat - do.call(rbind, listOfMatrices) On Wed, Sep 10, 2008 at 11:49 AM, Muhammad Azam [EMAIL PROTECTED] wrote: Dear R community I have stored the results of arrays in a list consist of J-components (say 200 components). Each component containing same no of columns but may be different no of rows. e.g [[1]] [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]43400 [3,]43400 [4,]43000 [[2]] [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]43400 [3,]43400 [4,]43000 [[3]] [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]44100 [3,]44100 [4,]44000 [5,]44000 For 200 components i want to make a frequency table. How can i make a frequency table of these components or the most repeated component out of all? Any help in this regard will be appreciated. Muhammad Azam [[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 Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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] All possible pairs of two variables
take a look at the code of the function pairwise.table. It shows a way using function outer. hth, Matthias Yihui Xie wrote: Just simple loops as follows: z = NULL for (y in 0:10) { for (x in 0:y) { z = rbind(z, c(x, y)) } } z Yihui On Thu, Sep 11, 2008 at 12:34 PM, Ron Michael [EMAIL PROTECTED] wrote: I have two variables (x,y) : x : it takes all integer values from 0 to y and, y : takes all values from 0, 10 I am looking for some R code to find all possible pairs of (x,y). Can anyone please help me? -- Dr. Matthias Kohl www.stamats.de __ 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] Handling time-series-Data
Dear List, I ran into some problems with time-series-Data. Imagine a data-structure where observations (x) of test attendants (i) are made a four times (q) a year (y). The data is orderd the following way: I y q x 1 20061 1 1 20063 1 1 20064 1 1 20071 1 1 20072 1 1 20073 1 1 20074 1 2 20061 1 3 20071 1 3 20072 1 I am looking for a way to count the attendants that at least have attendend one time a year. In this case 2 persons, because i=2 has no observation in 2007. I thought about creating a subset with the duplicate function. But I can't find a way to control (i) and (y). subset(data, !duplicated(i[y])) Thanx so much Andreas Kunzler Bundeszahnärztekammer (BZÄK) Chausseestraße 13 10115 Berlin Tel.: 030 40005-113 Fax: 030 40005-119 E-Mail: [EMAIL PROTECTED] __ 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] data import
Dear All, I have a data set containing 2,122,164 records and 38198952 fields. I can not import this data due to momory problem. Is there a way to solve this problem? Thanks [[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] WG: Re: WG: Re: NMDS and varimax rotation
hello Gavin, yes, you might be right. I performed a comparison of a normal NMDS (with metaMDS) and a subsequent rotation with varimax. The rotation didn't seem to improve significantly the the alignment of the former ordination output. Thanks for your hint greetings. Bernd Panassiti __ 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] data import
I have a data set containing 2,122,164 records and 38198952 fields. I can not import this data due to momory problem. Is there a way to solve this problem? 1. Filter the data before you import it. Do you really need all 38 million fields? Can you ignore some of the 2 million records? Chapter 4 of the R Data Import/Export Manual may help. 2. Failing that, buy more memory for your PC. Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} __ 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] request: most repeated component of a list
That is indeed different from what I thought the first time. x - sapply(1:length(l), function(x) { sum(sapply(l, function(y) { if ( nrow(l[[x]]) != nrow(y) | ncol(l[[x]]) != ncol(y) ) FALSE else sum(y != l[[x]]) == 0 })) } ) names(x) - names(l) Then, x has the same names as l, and x[i] is the number of matches that l[[i]] has...so you want the index or indices of max(x). --Adam On Thu, 11 Sep 2008, Muhammad Azam wrote: May be i could not explain properly. Actually there are components of list i.e. [[1]] to [[500]]. Each component containing r-rows (may be different for each [[ k ]] and c-columns same for all). I have to compare all the [[ k ]] components of that list and found the one appearing maximum no of times. e.g. from three components [[1]] to [[3]] given below. The most repeated is [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]43400 [3,]43400 [4,]43000Please help to find it. Thanks and best regards Muhammad Azam - Original Message From: jim holtman [EMAIL PROTECTED] To: Muhammad Azam [EMAIL PROTECTED] Cc: R-help request [EMAIL PROTECTED]; R Help r-help@r-project.org Sent: Wednesday, September 10, 2008 5:59:28 PM Subject: Re: [R] request: most repeated component of a list If want you want is the summary from all of them, then 'rbind' the data together into one matrix and analyze it: totalMat - do.call(rbind, listOfMatrices) On Wed, Sep 10, 2008 at 11:49 AM, Muhammad Azam [EMAIL PROTECTED] wrote: Dear R community I have stored the results of arrays in a list consist of J-components (say 200 components). Each component containing same no of columns but may be different no of rows. e.g [[1]] [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]43400 [3,]43400 [4,]43000 [[2]] [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]43400 [3,]43400 [4,]43000 [[3]] [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]44100 [3,]44100 [4,]44000 [5,]44000 For 200 components i want to make a frequency table. How can i make a frequency table of these components or the most repeated component out of all? Any help in this regard will be appreciated. Muhammad Azam [[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 Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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] RSiteSearch for words ``as one entity''.
It transpires that this is really messy: Namazu does not in general accept encoded URLs. (They seem to work for query= but not for sort= !) So RSiteSearch(URLencode({logistic regression})) might be a solution, but toUrl(qs2) is not (in general). On Thu, 11 Sep 2008, Prof Brian Ripley wrote: If firefox is involved on a Mac, that is one difference. My Mac is using 'open' (the default, I believe) and that is calling Safari (the default, I believe). Yes, it would be the job of browseURL to encode URLs where required. But at least on Windows and using the -remoteURL mechanism (as on Linux) it is not. R itself does have URLencode. On Thu, 11 Sep 2008, Rolf Turner wrote: On 11/09/2008, at 10:09 AM, Marc Schwartz wrote: snip As Prof. Ripley noted, try using debug(RSiteSearch) and then step through the code to see where $HOME is being added to the URL variable. That can help pin it down further. If the URL is not corrupted by the time browseURL() is called, then use debug(browseURL) to trace within that function to see if something is happening there. I have done some digging. When I do: RSiteSearch(logistic regression) the RSiteSearch() function calls browseURL(qstring) where qstring is qs1 equal to http://search.r-project.org/cgi-bin/namazu.cgi?query=logistic+regressionmax=20result=normalsort=scoreidxname=Rhelp02aidxname=functionsidxname=docs; Similarly when I do RSiteSearch({logistic regression}) qstring is qs2 equal to http://search.r-project.org/cgi-bin/namazu.cgi?query={logistic+regression}max=20result=normalsort=scoreidxname=Rhelp02aidxname=functionsidxname=docs; i.e. the same except for the braces. If I do browseURL(qs1) outside of RSiteSearch() it works as expected. If I do browseURL(qs2) I get the error. Inside browseURL I find that it calls system(paste(browser, remoteCmd, /dev/null 21 ||, browser, quotedUrl, )) and browser is /usr/bin/open, remoteCmd is the qstring with the opening and closing quote marks attached (escaped with a ``\'') amd quotedUrl is the same. This is true irrespective of which qstring (qs1 or qs2 is used). Note that the double backslash shows up in remoteCmd == quotedUrl at this stage. Finally I put the system command into a file ``junk'' and from the command window (outside R) executed ``sh junk''. With the braces around ``logistic regression'' I can the same error message that I got in R. When I simply edited out the braces, the Firefox window opened at the appropriate URL. So the problem is in those braces and the single/double backslash at the start was a red herring. Finally, while I was doing all this I got Henrik Bengtsson's message, and tried his suggestion: library(R.utils) browseURL(toUrl(qs2)) and BINGO!!! that worked. (Thanks very much, Henrik.) It's still mysterious why the braces have their deleterious impact on my Mac but do not have that impact on Professor Ripley's machine. (But that's the story of my life: THEY always pick on ***me***! :-) ) So my problem is solved --- via a workaround --- but there's still some vestigial strangeness. Thanks to all who helped me, especially (again) to Henrik Bengtsson cheers, Rolf ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ 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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ 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] RSiteSearch for words ``as one entity''.
Brian, open will call whatever program is defined for a certain extension. You can set this with a plug in to System Preferences called Default Apps for example. So on my Mac(s) Firefox is the default. el On 11 Sep 2008, at 08:33 , Prof Brian Ripley wrote: If firefox is involved on a Mac, that is one difference. My Mac is using 'open' (the default, I believe) and that is calling Safari (the default, I believe). Yes, it would be the job of browseURL to encode URLs where required. But at least on Windows and using the -remoteURL mechanism (as on Linux) it is not. R itself does have URLencode. On Thu, 11 Sep 2008, Rolf Turner wrote: On 11/09/2008, at 10:09 AM, Marc Schwartz wrote: snip As Prof. Ripley noted, try using debug(RSiteSearch) and then step through the code to see where $HOME is being added to the URL variable. That can help pin it down further. If the URL is not corrupted by the time browseURL() is called, then use debug(browseURL) to trace within that function to see if something is happening there. __ 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] relsurv package
Thank you. But the problem with the relsurv package remains: when I try to use the function rsmul following the package example, it give me an error (Error in nrow(x) : object x not found). There are perhaps others packages to fit relative survival models ? Giulia - Original Message From: Prof Brian Ripley [EMAIL PROTECTED] To: Yihui Xie [EMAIL PROTECTED] Cc: Giulia Barbati [EMAIL PROTECTED]; r-help@r-project.org Sent: Wednesday, September 10, 2008 11:44:43 AM Subject: Re: [R] relsurv package On Wed, 10 Sep 2008, Yihui Xie wrote: For the second question, try something like: strptime('12/4/1996','%M/%d/%Y') [1] 1996-09-04 00:12:00 # only date? as.Date(strptime('12/4/1996','%M/%d/%Y')) [1] 1996-09-04 Why not as.Date('12/4/1996', format = '%m/%d/%Y') [1] 1996-12-04 ? (And note the typo in your solution and hence incorrect answer.) Yihui On Wed, Sep 10, 2008 at 4:22 PM, Giulia Barbati [EMAIL PROTECTED] wrote: Dear R-users, I have a couple of questions about the relsurv package: 1) when I try to run the example: fit - rsmul(Surv(time,cens)~sex+as.factor(agegr)+ratetable(age=age*365.24,sex=sex,year=year),ratetable=slopop,data=rdata) with the datasets in the package (rdata and slopop) it gives me an error: Error in nrow(x) : object x not found 2) If I have a date format like:6/17/1997 9/10/1990 12/4/1996 how to convert it in the Rdate format required by ratetable? Thank you very much for help, Giulia -- Yihui Xie [EMAIL PROTECTED] Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China __ 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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 [[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] arima and xreg
On Sep 11, 6:24 am, David Stoffer [EMAIL PROTECTED] wrote: Your model is close, but not correct... there are no t's on the parameters and the U's aren't lagged. You can find an ARMAX example on our quick fix page:http://www.stat.pitt.edu/stoffer/tsa2/R_time_series_quick_fix.htm. The example is near the bottom and just above the spectral analysis example, but you may want to read the regression with autocorrelated errors example first to get some background. Ok. so arima of R can only deal with unlagged inputs (thus xreg has the latest value in the equation). Your example was an ARX (no moving averages) here is the code of yoru example : armax.fit = arima(mort, order=c(2,0,0), xreg=cbind(trend, part)) I guess I can change it to ARMAX if I use order=c(p,0,q) =) Now theres one thing that might be worth mentioning here though. The above can only work (I am guessing) if the input values (the columns of xreg) are uncorrelated (or what word do use for that, sorry Im a pure mathematician, not a statistician :p ). What I mean is that the matrix in which optim of R must be singular (otherwise I think, from my last try when using two equal valued columns in xreg, arima will complain that optim returns an infinity value). Is there a way to check if the xreg matrix have uncorrelated inputs and then just discard the column until xreg becomes uncorrelated? I'll do a few more experiment with xreg and report here.. Im doing this because the documentation (as many of us already know.. ) do not really explain xreg very well. Sincerely, Jose Capco __ 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 obtain a sequence of dates consisting of only weekdays
Dear R-users, How do I obtain a sequence of dates consisting of only weekdays without the weekends in R? In S, I can do the following: timeSeq(from=12/17/2007, to=8/25/2008, by=weekdays) I tried using looking at timeSequence (fSeries package) and seq.Date (base package) but I do not know if I can specify weekdays rather than day. Hope to have some assistance. Thank you! Regards, wy ** The information provided in this e-mail is confidential and is for the sole use of the recipient. It may not be disclosed, copied or distributed in any form without the express permission of Henderson Global Investors and to the extent that it is passed on, care must be taken to ensure that this is in a form which accurately reflects the information presented here. Whilst Henderson Global Investors believe that the information is correct at the date of this e-mail, no warranty or representation is given to this effect and no responsibility can be accepted by Henderson Global Investors to any end users for any action taken on the basis of this information. Henderson Global Investors is the name under which Henderson Global Investors Limited (registered no. 906355), Henderson Fund Management plc (registered no. 2607112), Henderson Investment Funds Limited (registered no. 2678531), Henderson Investment Management Limited (registered no. 1795354) Henderson Alternative Investment Advisor Limited (registered no. 962757) and Henderson Equity Partners Limited (registered no.2606646) (each incorporated and registered in England and Wales with registered office at 4 Broadgate, London EC2M 2DA and authorised and regulated by the Financial Services Authority) provide investment products and services. Henderson Secretarial Services Limited (incorporated and registered in England and Wales, registered no. 1471624, registered office 4 Broadgate, London EC2M 2DA) is the name under which company secretarial services are provided. All these companies are wholly owned subsidiaries of Henderson Group plc (incorporated and registered in England ! and Wales, registered no. 2072534, registered office 4 Broadgate, London EC2M 2DA). We may record telephone calls or email for our mutual protection and to improve customer service. ** [[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] request: most repeated component of a list
Thanks for the effort but still we are far from the desired result. May be this example will help you to understand the situation. Example a1=c(1:12); a1=array(a1,dim=c(3,4)); a2=c(1:12); a2=array(a2,dim=c(3,4)); a3=c(1:16) a3=array(a3,dim=c(4,4)); a=list(a1,a2,a3); a [[1]] [,1] [,2] [,3] [,4] [1,]147 10 [2,]258 11 [3,]369 12 [[2]] [,1] [,2] [,3] [,4] [1,]147 10 [2,]258 11 [3,]369 12 [[3]] [,1] [,2] [,3] [,4] [1,]159 13 [2,]26 10 14 [3,]37 11 15 [4,]48 12 16 Here [[1]] and [[2]] are same out of three (internal values wise). The whole array [[1]] or [[2]] is in majority. So i want to get the whole array or component of list which is in majority. The result should be like this [,1] [,2] [,3] [,4] [1,]147 10 [2,]258 11 [3,]369 12 Hope it is much more clear as before. best regards Muhammad Azam - Original Message From: Adam D. I. Kramer [EMAIL PROTECTED] To: Muhammad Azam [EMAIL PROTECTED] Cc: R Help r-help@r-project.org Sent: Thursday, September 11, 2008 9:53:40 AM Subject: Re: [R] request: most repeated component of a list That is indeed different from what I thought the first time. x - sapply(1:length(l), function(x) { sum(sapply(l, function(y) { if ( nrow(l[[x]]) != nrow(y) | ncol(l[[x]]) != ncol(y) ) FALSE else sum(y != l[[x]]) == 0 })) } ) names(x) - names(l) Then, x has the same names as l, and x[i] is the number of matches that l[[i]] has...so you want the index or indices of max(x). --Adam On Thu, 11 Sep 2008, Muhammad Azam wrote: May be i could not explain properly. Actually there are components of list i.e. [[1]] to [[500]]. Each component containing r-rows (may be different for each [[ k ]] and c-columns same for all). I have to compare all the [[ k ]] components of that list and found the one appearing maximum no of times. e.g. from three components [[1]] to [[3]] given below. The most repeated is [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]43400 [3,]43400 [4,]43000Please help to find it. Thanks and best regards Muhammad Azam - Original Message From: jim holtman [EMAIL PROTECTED] To: Muhammad Azam [EMAIL PROTECTED] Cc: R-help request [EMAIL PROTECTED]; R Help r-help@r-project.org Sent: Wednesday, September 10, 2008 5:59:28 PM Subject: Re: [R] request: most repeated component of a list If want you want is the summary from all of them, then 'rbind' the data together into one matrix and analyze it: totalMat - do.call(rbind, listOfMatrices) On Wed, Sep 10, 2008 at 11:49 AM, Muhammad Azam [EMAIL PROTECTED] wrote: Dear R community I have stored the results of arrays in a list consist of J-components (say 200 components). Each component containing same no of columns but may be different no of rows. e.g [[1]] [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]43400 [3,]43400 [4,]43000 [[2]] [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]43400 [3,]43400 [4,]43000 [[3]] [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]44100 [3,]44100 [4,]44000 [5,]44000 For 200 components i want to make a frequency table. How can i make a frequency table of these components or the most repeated component out of all? Any help in this regard will be appreciated. Muhammad Azam [[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 Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Handling time-series-Data
On Thu, 11 Sep 2008, Kunzler, Andreas wrote: Dear List, I ran into some problems with time-series-Data. Imagine a data-structure where observations (x) of test attendants (i) are made a four times (q) a year (y). The data is orderd the following way: I y q x 1 20061 1 1 20063 1 1 20064 1 1 20071 1 1 20072 1 1 20073 1 1 20074 1 2 20061 1 3 20071 1 3 20072 1 I am looking for a way to count the attendants that at least have attendend one time a year. In this case 2 persons, because i=2 has no observation in 2007. You might want to turn your data into an actual time series with one series per attendend and then aggregate. I've written a few short transformations based on the data above and using the zoo package. It's somewhat lengthy but might give you a few useful pointers. hth, Z ## read data x - read.table(textConnection(I y q x 1 20061 1 1 20063 1 1 20064 1 1 20071 1 1 20072 1 1 20073 1 1 20074 1 2 20061 1 3 20071 1 3 20072 1), header = TRUE) ## store year/qtr as yearqtr object library(zoo) x$yq - as.yearqtr(x$y + (x$q-1)/4) x - x[,-(2:3)] ## reshape data into wide format (one series per individual) x - reshape(x, timevar = I, idvar = yq, direction = wide) ## turn data into zoo series with zeros in quarters without observation z - zoo(as.matrix(x[,-1]), x[,1]) z - merge(zoo(,seq(from = start(z), to = end(z), by = 0.25)), z) z[is.na(z)] - 0 ## aggregate from quarterly to annual observations zy - aggregate(z, function(x) as.numeric(floor(x)), sum) ## aggregate over individuals rollapply(zy, 1, function(x) sum(x 0), by.column = FALSE) I thought about creating a subset with the duplicate function. But I can't find a way to control (i) and (y). subset(data, !duplicated(i[y])) Thanx so much Andreas Kunzler Bundeszahnärztekammer (BZÄK) Chausseestraße 13 10115 Berlin Tel.: 030 40005-113 Fax: 030 40005-119 E-Mail: [EMAIL PROTECTED] __ 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] Package for financial options calculation
Hi all, Is there any R package on European/American oprions pricing? And on calculation of it's sensitivities? Regards, [[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] relsurv package
On Thu, 11 Sep 2008, Giulia Barbati wrote: Thank you. But the problem with the relsurv package remains: when I try to use the function rsmul following the package example, it give me an error (Error in nrow(x) : object x not found). What did the maintainer say when you asked (see the posting guide)? You didn't give a reproducible example: here is my attempt to make yours reproducible in a legible way): library(relsurv) data(rdata); data(slopop) fit -rsmul(Surv(time,cens) ~ sex + as.factor(agegr) + ratetable(age=age*365.24,sex=sex,year=year), ratetable = slopop, data = rdata) And that works in sessionInfo() R version 2.7.2 (2008-08-25) x86_64-unknown-linux-gnu locale: LC_CTYPE=en_GB.UTF-8;LC_NUMERIC=C;LC_TIME=en_GB.UTF-8;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=en_GB.UTF-8;LC_PAPER=en_GB.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_GB.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] splines stats graphics grDevices utils datasets methods [8] base other attached packages: [1] relsurv_1.4 survival_2.34-1 loaded via a namespace (and not attached): [1] tools_2.7.2 So, please do follow the posting guide: it looks like the problem is local to you. There are perhaps others packages to fit relative survival models ? Giulia - Original Message From: Prof Brian Ripley [EMAIL PROTECTED] To: Yihui Xie [EMAIL PROTECTED] Cc: Giulia Barbati [EMAIL PROTECTED]; r-help@r-project.org Sent: Wednesday, September 10, 2008 11:44:43 AM Subject: Re: [R] relsurv package On Wed, 10 Sep 2008, Yihui Xie wrote: For the second question, try something like: strptime('12/4/1996','%M/%d/%Y') [1] 1996-09-04 00:12:00 # only date? as.Date(strptime('12/4/1996','%M/%d/%Y')) [1] 1996-09-04 Why not as.Date('12/4/1996', format = '%m/%d/%Y') [1] 1996-12-04 ? (And note the typo in your solution and hence incorrect answer.) Yihui On Wed, Sep 10, 2008 at 4:22 PM, Giulia Barbati [EMAIL PROTECTED] wrote: Dear R-users, I have a couple of questions about the relsurv package: 1) when I try to run the example: fit -rsmul(Surv(time,cens)~sex+as.factor(agegr)+ratetable(age=age*365.24,sex=sex,year =year),ratetable=slopop,data=rdata) with the datasets in the package (rdata and slopop) it gives me an error: Error in nrow(x) : object x not found 2) If I have a date format like:6/17/1997 9/10/1990 12/4/1996 how to convert it in the Rdate format required by ratetable? Thank you very much for help, Giulia -- Yihui Xie [EMAIL PROTECTED] Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China __ 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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ 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] request: most repeated component of a list
try the following: ff - function (x) { do.call(paste, c(as.data.frame(x), sep = \r, collapse = )) } pats - sapply(a, ff) ind - which.max(table(pats)) a[[ind]] I hope it helps. Best, Dimitris Thanks for the effort but still we are far from the desired result. May be this example will help you to understand the situation. Example a1=c(1:12); a1=array(a1,dim=c(3,4)); a2=c(1:12); a2=array(a2,dim=c(3,4)); a3=c(1:16) a3=array(a3,dim=c(4,4)); a=list(a1,a2,a3); a [[1]] [,1] [,2] [,3] [,4] [1,]147 10 [2,]258 11 [3,]369 12 [[2]] [,1] [,2] [,3] [,4] [1,]147 10 [2,]258 11 [3,]369 12 [[3]] [,1] [,2] [,3] [,4] [1,]159 13 [2,]26 10 14 [3,]37 11 15 [4,]48 12 16 Here [[1]] and [[2]] are same out of three (internal values wise). The whole array [[1]] or [[2]] is in majority. So i want to get the whole array or component of list which is in majority. The result should be like this [,1] [,2] [,3] [,4] [1,]147 10 [2,]258 11 [3,]369 12 Hope it is much more clear as before. best regards Muhammad Azam - Original Message From: Adam D. I. Kramer [EMAIL PROTECTED] To: Muhammad Azam [EMAIL PROTECTED] Cc: R Help r-help@r-project.org Sent: Thursday, September 11, 2008 9:53:40 AM Subject: Re: [R] request: most repeated component of a list That is indeed different from what I thought the first time. x - sapply(1:length(l), function(x) { sum(sapply(l, function(y) { if ( nrow(l[[x]]) != nrow(y) | ncol(l[[x]]) != ncol(y) ) FALSE else sum(y != l[[x]]) == 0 })) } ) names(x) - names(l) Then, x has the same names as l, and x[i] is the number of matches that l[[i]] has...so you want the index or indices of max(x). --Adam On Thu, 11 Sep 2008, Muhammad Azam wrote: May be i could not explain properly. Actually there are components of list i.e. [[1]] to [[500]]. Each component containing r-rows (may be different for each [[ k ]] and c-columns same for all). I have to compare all the [[ k ]] components of that list and found the one appearing maximum no of times. e.g. from three components [[1]] to [[3]] given below. The most repeated is [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]43400 [3,]43400 [4,]43000Please help to find it. Thanks and best regards Muhammad Azam - Original Message From: jim holtman [EMAIL PROTECTED] To: Muhammad Azam [EMAIL PROTECTED] Cc: R-help request [EMAIL PROTECTED]; R Help r-help@r-project.org Sent: Wednesday, September 10, 2008 5:59:28 PM Subject: Re: [R] request: most repeated component of a list If want you want is the summary from all of them, then 'rbind' the data together into one matrix and analyze it: totalMat - do.call(rbind, listOfMatrices) On Wed, Sep 10, 2008 at 11:49 AM, Muhammad Azam [EMAIL PROTECTED] wrote: Dear R community I have stored the results of arrays in a list consist of J-components (say 200 components). Each component containing same no of columns but may be different no of rows. e.g [[1]] [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]43400 [3,]43400 [4,]43000 [[2]] [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]43400 [3,]43400 [4,]43000 [[3]] [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]44100 [3,]44100 [4,]44000 [5,]44000 For 200 components i want to make a frequency table. How can i make a frequency table of these components or the most repeated component out of all? Any help in this regard will be appreciated. Muhammad Azam [[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 Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
Re: [R] How to obtain a sequence of dates consisting of only weekdays
draw a subset of your data using a logical vector like this: # for 50 weeks rep(c(rep(TRUE, 5), rep(FALSE, 2)), 50) Yihui On Thu, Sep 11, 2008 at 4:31 PM, Weiyang Lim [EMAIL PROTECTED] wrote: Dear R-users, How do I obtain a sequence of dates consisting of only weekdays without the weekends in R? In S, I can do the following: timeSeq(from=12/17/2007, to=8/25/2008, by=weekdays) I tried using looking at timeSequence (fSeries package) and seq.Date (base package) but I do not know if I can specify weekdays rather than day. Hope to have some assistance. Thank you! Regards, wy -- Yihui Xie [EMAIL PROTECTED] Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China __ 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] Difference in p-values between R and SPSS
My apologies for asking slightly about SPSS in addition to R... Could not find an exact answer in the archives on whether R and SPSS may give different p-vals when output for coeffs and conf-intervals are the same. Amyway, a colleague and I are doing a very simple coxreg analyses and get the same results for the coefficient and confidence interval, exp(coef) exp(-coef) lower .95 upper .95 age_at_entry 1.02 0.98 1.01 1.03 but in R we get p = 0.00011, and SPSS gives p 0.0001 Should we worry about this difference in p-value or do R and SPSS sometime differ? All the best, Kare __ 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] request: most repeated component of a list
Thanks a lot for this effort. - Original Message From: Dimitris Rizopoulos [EMAIL PROTECTED] To: Muhammad Azam [EMAIL PROTECTED] Cc: [EMAIL PROTECTED]; R Help r-help@r-project.org Sent: Thursday, September 11, 2008 10:52:16 AM Subject: Re: [R] request: most repeated component of a list try the following: ff - function (x) { do.call(paste, c(as.data.frame(x), sep = \r, collapse = )) } pats - sapply(a, ff) ind - which.max(table(pats)) a[[ind]] I hope it helps. Best, Dimitris Thanks for the effort but still we are far from the desired result. May be this example will help you to understand the situation. Example a1=c(1:12); a1=array(a1,dim=c(3,4)); a2=c(1:12); a2=array(a2,dim=c(3,4)); a3=c(1:16) a3=array(a3,dim=c(4,4)); a=list(a1,a2,a3); a [[1]] [,1] [,2] [,3] [,4] [1,]147 10 [2,]258 11 [3,]369 12 [[2]] [,1] [,2] [,3] [,4] [1,]147 10 [2,]258 11 [3,]369 12 [[3]] [,1] [,2] [,3] [,4] [1,]159 13 [2,]26 10 14 [3,]37 11 15 [4,]48 12 16 Here [[1]] and [[2]] are same out of three (internal values wise). The whole array [[1]] or [[2]] is in majority. So i want to get the whole array or component of list which is in majority. The result should be like this [,1] [,2] [,3] [,4] [1,]147 10 [2,]258 11 [3,]369 12 Hope it is much more clear as before. best regards Muhammad Azam - Original Message From: Adam D. I. Kramer [EMAIL PROTECTED] To: Muhammad Azam [EMAIL PROTECTED] Cc: R Help r-help@r-project.org Sent: Thursday, September 11, 2008 9:53:40 AM Subject: Re: [R] request: most repeated component of a list That is indeed different from what I thought the first time. x - sapply(1:length(l), function(x) { sum(sapply(l, function(y) { if ( nrow(l[[x]]) != nrow(y) | ncol(l[[x]]) != ncol(y) ) FALSE else sum(y != l[[x]]) == 0 })) } ) names(x) - names(l) Then, x has the same names as l, and x[i] is the number of matches that l[[i]] has...so you want the index or indices of max(x). --Adam On Thu, 11 Sep 2008, Muhammad Azam wrote: May be i could not explain properly. Actually there are components of list i.e. [[1]] to [[500]]. Each component containing r-rows (may be different for each [[ k ]] and c-columns same for all). I have to compare all the [[ k ]] components of that list and found the one appearing maximum no of times. e.g. from three components [[1]] to [[3]] given below. The most repeated is [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]43400 [3,]43400 [4,]43000Please help to find it. Thanks and best regards Muhammad Azam - Original Message From: jim holtman [EMAIL PROTECTED] To: Muhammad Azam [EMAIL PROTECTED] Cc: R-help request [EMAIL PROTECTED]; R Help r-help@r-project.org Sent: Wednesday, September 10, 2008 5:59:28 PM Subject: Re: [R] request: most repeated component of a list If want you want is the summary from all of them, then 'rbind' the data together into one matrix and analyze it: totalMat - do.call(rbind, listOfMatrices) On Wed, Sep 10, 2008 at 11:49 AM, Muhammad Azam [EMAIL PROTECTED] wrote: Dear R community I have stored the results of arrays in a list consist of J-components (say 200 components). Each component containing same no of columns but may be different no of rows. e.g [[1]] [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]43400 [3,]43400 [4,]43000 [[2]] [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]43400 [3,]43400 [4,]43000 [[3]] [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]44100 [3,]44100 [4,]44000 [5,]44000 For 200 components i want to make a frequency table. How can i make a frequency table of these components or the most repeated component out of all? Any help in this regard will be appreciated. Muhammad Azam [[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 Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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
Re: [R] How to obtain a sequence of dates consisting of only weekdays
Then you can use c() to add the indices of those weeks which are not complete, or use something like this # from Tuesday to next Wedsday !(2:10 %% 7) %in% c(0,6) [1] TRUE TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE Yihui On Thu, Sep 11, 2008 at 5:08 PM, Weiyang Lim [EMAIL PROTECTED] wrote: Hi, Thanks for the reply. I also thought of your method. But it will not be quite right if my starting day is not on a Monday. Then, it will include weekends? Hope to have flexibility in that the starting day can be any day of the week not just monday. wy -- Yihui Xie [EMAIL PROTECTED] Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China __ 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] boxplot
Sorry, I have some troubles with the graph device. How can I draw the whiskers in a boxplot? Thank's so much. Daniela [[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 on executing R from java
Hello, I've installed Rserve and I've run it. I've installed the JRclient-RF503.jar. I've installed JDK 1.4.2 and R language version 2.7.1. Now when I compile the Jrclient exeamples from JBUILDER 9? an error appreas: package org.rosuda.JRclient does not exist ... could you please help me? Thank you in advance [[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] Difference in p-values between R and SPSS
Kåre Edvardsen wrote: My apologies for asking slightly about SPSS in addition to R... Could not find an exact answer in the archives on whether R and SPSS may give different p-vals when output for coeffs and conf-intervals are the same. Amyway, a colleague and I are doing a very simple coxreg analyses and get the same results for the coefficient and confidence interval, exp(coef) exp(-coef) lower .95 upper .95 age_at_entry 1.02 0.98 1.01 1.03 but in R we get p = 0.00011, and SPSS gives p 0.0001 This might happen due to numerical differences in the algorithms for computing on the distributions. Both p values are not that different ... For I would not worry if the difference is that small and practically identical. Uwe Ligges Should we worry about this difference in p-value or do R and SPSS sometime differ? All the best, Kare __ 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] boxplot
Daniela Garavaglia wrote: Sorry, I have some troubles with the graph device. How can I draw the whiskers in a boxplot? 1. Whiskers in a boxplot are independent of the device. 2. I do see whiskers, e.g. in boxplot(1:10) so I do not undertsnad your question at all. Uwe Ligges Thank's so much. Daniela [[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] Convex optimization in R?
Hesen Peng hesen.peng at gmail.com writes: Hi my R buddies, I'm trying to solve a specific group of convex optimization in R. The admissible region is the inside and surface of a multi-dimensional eclipse area and the goal function is the sum of absolution values of the variables. Could any one please tell me whether there's a package in R to do this? Thank you very much, To my knowledge there does not exist a designated R package for convex optimization. Also, in the Optimization task view the AMS nomenclature 90C25 for Convex programming (CP) is not mentioned. On the other hand, this task view may give you some ideas on how to solve your problem with one of the available optimization packages. For instance, a problem including sums of absolute values can be modeled as a linear program with mixed integer variables (MILP). There is a free module for 'disciplined' convex optimization, CVX, that can be integrated with Matlab or Python. Hopefully, there will be a CVX R package in the future (as has been announced/promised). Hans Werner Borchers ABB Corporate Research Best wishes, -- Hesen Peng http://hesen.peng.googlepages.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] Error: bad value
Dear R Users, I am getting a strange error, also relayed by Jose Quesada about a year ago. As below, in his message, I get Error: bad value to whatever I enter into the R console. My configuration is: - Windows XP SP2 - R 2.7.2 Has this problem been tracked down to a specific package ? I am using the following packages: library(strucchange) library(car) library(lmtest) library(nlme) library(corrgram) library(RODBC) library(MSBVAR) library(xtable) library(vars) library(tseries) library(PerformanceAnalytics) library(fArma) library(snow) Thanks in advance, Tolga Uzuner message from a year ago Hi, I'm finding a very strange error. For no good reason my R console (Rgui.exe, R 2.5.0, under win XP) stops producing anything meaningful, and just returns: Error: bad value to _whatever_ I enter. It starts doing this after a while, not immediately when launched. I have to restart R when this happens. No idea why. I didn't change anything in the R config that I remenber. Any thoughts? Thanks. -- Jose Quesada, PhD. http://www.andrew.cmu.edu/~jquesada __ R-help_at_stat.math.ethz.ch 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. Received on Thu 14 Jun 2007 - 21:45:51 GMT Generally, this communication is for informational purposes only and it is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. In the event you are receiving the offering materials attached below related to your interest in hedge funds or private equity, this communication may be intended as an offer or solicitation for the purchase or sale of such fund(s). All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to UK legal entities. [[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] data import
You can use a connection and read a portion of the data in at a time and process it. Do you need all the data at once? If so, I would agree that you either need more memory (and possibly a 64-bit version of the system), or you come up with a different approach to your processing. You have not indicated what problem you are trying to solve with the data. On Thu, Sep 11, 2008 at 3:32 AM, afshin fallah [EMAIL PROTECTED] wrote: Dear All, I have a data set containing 2,122,164 records and 38198952 fields. I can not import this data due to momory problem. Is there a way to solve this problem? Thanks [[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 Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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 obtain a sequence of dates consisting of only weekdays
See ?is.holiday in chron, e.g. library(chron) s - seq(from = chron(12/17/2007), to = chron(8/25/2008)) s.weekday - s[!is.holiday(s)] As discussed there one can also optionally define a .Holidays vector containing dates which will also be excluded. It also works with any class for which there is an as.chron method. R News 4/1 discusses various date classes. On Thu, Sep 11, 2008 at 4:31 AM, Weiyang Lim [EMAIL PROTECTED] wrote: Dear R-users, How do I obtain a sequence of dates consisting of only weekdays without the weekends in R? In S, I can do the following: timeSeq(from=12/17/2007, to=8/25/2008, by=weekdays) I tried using looking at timeSequence (fSeries package) and seq.Date (base package) but I do not know if I can specify weekdays rather than day. Hope to have some assistance. Thank you! Regards, wy ** The information provided in this e-mail is confidential and is for the sole use of the recipient. It may not be disclosed, copied or distributed in any form without the express permission of Henderson Global Investors and to the extent that it is passed on, care must be taken to ensure that this is in a form which accurately reflects the information presented here. Whilst Henderson Global Investors believe that the information is correct at the date of this e-mail, no warranty or representation is given to this effect and no responsibility can be accepted by Henderson Global Investors to any end users for any action taken on the basis of this information. Henderson Global Investors is the name under which Henderson Global Investors Limited (registered no. 906355), Henderson Fund Management plc (registered no. 2607112), Henderson Investment Funds Limited (registered no. 2678531), Henderson Investment Management Limited (registered no. 1795354) Henderson Alternative Investment Advisor Limited (registered no. 962757) and Henderson Equity Partners Limited (registered no.2606646) (each incorporated and registered in England and Wales with registered office at 4 Broadgate, London EC2M 2DA and authorised and regulated by the Financial Services Authority) provide investment products and services. Henderson Secretarial Services Limited (incorporated and registered in England and Wales, registered no. 1471624, registered office 4 Broadgate, London EC2M 2DA) is the name under which company secretarial services are provided. All these companies are wholly owned subsidiaries of Henderson Group plc (incorporated and registered in Englan! d ! and Wales, registered no. 2072534, registered office 4 Broadgate, London EC2M 2DA). We may record telephone calls or email for our mutual protection and to improve customer service. ** [[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] periodicity validation
all of the functions that I listed are time series tools for looking at what I think you want. this can be done you just have to understand the methodology. So, look at some of the things that I suggested, If these don't help then I don't understand what you want, and it is necissary for you to help me figure out what it is that you want. good luck 2008/9/11 yk [EMAIL PROTECTED]: The data I mentioned above is oscilating vs time,but there are not obersevable fixed cycle if I just plot this data. How to get the average cycle,or the most probable range of cycle with statistical methods? I don't know how to achieve it by R, is there any command? On Sep 11, 10:52 am, stephen sefick [EMAIL PROTECTED] wrote: ?spectrum ?acf ?ccf library(wmtsa) ?wavCWT library(sowas) ?wsp you could also look at lagged plots to look for periodicity. if you elaborate on the problem and include executable sample code you will probably recieve more help. On Wed, Sep 10, 2008 at 10:02 PM, yk [EMAIL PROTECTED] wrote: There is a series of data contains time in fixed step and energy varying with time, how to test its periodicity?In R, it seems there is no direct tools since I have search the R manual with periodic and I have not found any related topic. Thanks a lot __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Stephen Sefick Research Scientist Southeastern Natural Sciences Academy Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis __ [EMAIL PROTECTED] mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://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. -- Stephen Sefick Research Scientist Southeastern Natural Sciences Academy Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis __ 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] count value
Hi, I've this data.frame: dia X1006109F X1006110F X1006111F X1006112F X1006113F X1006114F X1006115F 1NANANANANA45NA X1006116F X1006117F X1006118F X1006119F X1006120F X1006122F X1006123F 145NANANA40NANA X1006124F X1006125F X1006126F X1006128F X1006203F X1006209F X1006210F 1NANANANA55NANA X1006211F X1006212F X1006213F X1006215F X1006217F X1006218F X1006219F 1NANANANANANANA X1006222F X1006223F X1006224F X1006225F X1006226F X1006227F X1006228F 1NANANANANANANA X1006301F X1006302F X1006304F X1006307F X1006308F X1006321F X1006401F 1NANA40NANANANA X1006402F X1006406F X1006407F X1006408F X1006421F X1006605F 1NA65NANANA45 How can I count the field =! NA?? Alfredo __ 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] count value
On 9/11/2008 8:11 AM, Alfredo Alessandrini wrote: Hi, I've this data.frame: dia X1006109F X1006110F X1006111F X1006112F X1006113F X1006114F X1006115F 1NANANANANA45NA X1006116F X1006117F X1006118F X1006119F X1006120F X1006122F X1006123F 145NANANA40NANA X1006124F X1006125F X1006126F X1006128F X1006203F X1006209F X1006210F 1NANANANA55NANA X1006211F X1006212F X1006213F X1006215F X1006217F X1006218F X1006219F 1NANANANANANANA X1006222F X1006223F X1006224F X1006225F X1006226F X1006227F X1006228F 1NANANANANANANA X1006301F X1006302F X1006304F X1006307F X1006308F X1006321F X1006401F 1NANA40NANANANA X1006402F X1006406F X1006407F X1006408F X1006421F X1006605F 1NA65NANANA45 How can I count the field =! NA?? colSums(!is.na(dia)) rowSums(!is.na(dia)) Alfredo __ 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. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ 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] count value
Try this: sum(!is.na(dia)) On Thu, Sep 11, 2008 at 9:11 AM, Alfredo Alessandrini [EMAIL PROTECTED]wrote: Hi, I've this data.frame: dia X1006109F X1006110F X1006111F X1006112F X1006113F X1006114F X1006115F 1NANANANANA45NA X1006116F X1006117F X1006118F X1006119F X1006120F X1006122F X1006123F 145NANANA40NANA X1006124F X1006125F X1006126F X1006128F X1006203F X1006209F X1006210F 1NANANANA55NANA X1006211F X1006212F X1006213F X1006215F X1006217F X1006218F X1006219F 1NANANANANANANA X1006222F X1006223F X1006224F X1006225F X1006226F X1006227F X1006228F 1NANANANANANANA X1006301F X1006302F X1006304F X1006307F X1006308F X1006321F X1006401F 1NANA40NANANANA X1006402F X1006406F X1006407F X1006408F X1006421F X1006605F 1NA65NANANA45 How can I count the field =! NA?? Alfredo __ 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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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] periodicity validation
Take a look at the xts package. ?periodicity HTH Jeff yk-4 wrote: There is a series of data contains time in fixed step and energy varying with time, how to test its periodicity?In R, it seems there is no direct tools since I have search the R manual with periodic and I have not found any related topic. Thanks a lot __ 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. -- View this message in context: http://www.nabble.com/periodicity-validation-tp19426522p19433896.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] Package for financial options calculation
Take a look at the fOptions package, as well as all the packages in Rmetrics (see www.rmetrics.org). There is also a wrapper to QuantLib called RQuantLib. Also, your question would have a better chance of being answered on the R-sig-finance mailing list. HTH Jeff Arun Kumar Saha wrote: Hi all, Is there any R package on European/American oprions pricing? And on calculation of it's sensitivities? Regards, [[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. -- View this message in context: http://www.nabble.com/Package-for-financial-options-calculation-tp19430481p19433943.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] yahoo finance into R
Take a look at quantmod. http://www.quantmod.com http://www.quantmod.com ?getSymbols.yahoo (called by getSymbols) ?getQuote ?yahooQF ?getFin ?getFX HTH Jeff thomastos wrote: Hi R, I am familiar with the basics of R. To learn more I would like how to get data from Yahoo!finance directly into R. So basically I want a data frame or matrix to do some data analysis. How do I do this? Thank you very much. Thomas -- View this message in context: http://www.nabble.com/yahoo-finance-into-R-tp19385481p19434000.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] All possible pairs of two variables
On Wed, Sep 10, 2008 at 11:34 PM, Ron Michael [EMAIL PROTECTED] wrote: I have two variables (x,y) : x : it takes all integer values from 0 to y and, y : takes all values from 0, 10 I am looking for some R code to find all possible pairs of (x,y). Can anyone please help me? ?expand.grid Hadley -- http://had.co.nz/ __ 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] Handling time-series-Data
On Thu, Sep 11, 2008 at 3:37 AM, Kunzler, Andreas [EMAIL PROTECTED] wrote: Dear List, I ran into some problems with time-series-Data. Imagine a data-structure where observations (x) of test attendants (i) are made a four times (q) a year (y). The data is orderd the following way: I y q x 1 20061 1 1 20063 1 1 20064 1 1 20071 1 1 20072 1 1 20073 1 1 20074 1 2 20061 1 3 20071 1 3 20072 1 I am looking for a way to count the attendants that at least have attendend one time a year. In this case 2 persons, because i=2 has no observation in 2007. Don't you mean 1 person, not 2 persons, since - attendant 1 appears in both years but - attendant 2 appears only in 2006 - attendant 3 appears only in 2007 so only attendant 1 appears in both years, i.e. 1 person. Assuming DF is your data frame: u - unique(DF[1:2]) with(u, sum(tapply(y, I, length) == length(unique(y # 1 I thought about creating a subset with the duplicate function. But I can't find a way to control (i) and (y). subset(data, !duplicated(i[y])) Thanx so much Andreas Kunzler Bundeszahnärztekammer (BZÄK) Chausseestraße 13 10115 Berlin Tel.: 030 40005-113 Fax: 030 40005-119 E-Mail: [EMAIL PROTECTED] __ 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] All possible pairs of two variables
But x is from 0 to y instead of a fixed number (say, 10)... If we are to use expand.grid(), we should filter out half of rows in the result: z = expand.grid(0:10, 0:10) z[z[,1] = z[,2], ] Var1 Var2 1 00 12 01 13 11 23 02 24 12 25 22 34 03 35 13 36 23 37 33 Yihui On Thu, Sep 11, 2008 at 8:53 PM, hadley wickham [EMAIL PROTECTED] wrote: On Wed, Sep 10, 2008 at 11:34 PM, Ron Michael [EMAIL PROTECTED] wrote: I have two variables (x,y) : x : it takes all integer values from 0 to y and, y : takes all values from 0, 10 I am looking for some R code to find all possible pairs of (x,y). Can anyone please help me? ?expand.grid Hadley -- http://had.co.nz/ -- Yihui Xie [EMAIL PROTECTED] Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China __ 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] fft: from characteristic funtion to density function
Hello all! I've posted the question before but I am still struggling for an answer, please help if you can;-) Suppose a discrete series of data is generated by the following equation: CF=exp(-(t^2)/2) which is the characteristic function of a random variable X with standard normal distribution, how do I *numerically* solve for its probability density function? i.e., obtain a series of data that plots a well know bell-shape curve? Or, find x such that Pr(Xx)=0.05? I have no problem to derive the forward and inverse Fourier equation pair, but just no clue on numerical method. A working code on this simplest exercise would clear off many, many of my confusions I have generated CF with t of 256 points equally spaced between -4 to 4 in Excel, but don't know how to proceed. Thanks for your help! Jindan __ 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 load functions in R
Hello, I am trying to use self created functions in other scripts than the one where they are stored. For the moment I am using the following structure of commands to do that: 1. Load the text file with the functions in the current script: x=parse(path) 2. transform the tex in a function: f1=eval(x[1]), f2=eval(x[2]) if more than one function is stored in the text file 3. use the functions as normal Is there another possibility to do the same? Thank you, Mihai Mirauta [[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 to load functions in R
Take a look at ?source Mihai.Mirauta wrote: Hello, I am trying to use self created functions in other scripts than the one where they are stored. For the moment I am using the following structure of commands to do that: 1. Load the text file with the functions in the current script: x=parse(path) 2. transform the tex in a function: f1=eval(x[1]), f2=eval(x[2]) if more than one function is stored in the text file 3. use the functions as normal Is there another possibility to do the same? Thank you, Mihai Mirauta [[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. -- View this message in context: http://www.nabble.com/How-to-load-functions-in-R-tp19434909p19434944.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 load functions in R
Hi, you may save your functions somewhere on your disk using save() and load them next time when you want to use them. See ?save and ?load Yihui On Thu, Sep 11, 2008 at 9:30 PM, [EMAIL PROTECTED] wrote: Hello, I am trying to use self created functions in other scripts than the one where they are stored. For the moment I am using the following structure of commands to do that: 1. Load the text file with the functions in the current script: x=parse(path) 2. transform the tex in a function: f1=eval(x[1]), f2=eval(x[2]) if more than one function is stored in the text file 3. use the functions as normal Is there another possibility to do the same? Thank you, Mihai Mirauta [[alternative HTML version deleted]] -- Yihui Xie [EMAIL PROTECTED] Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China __ 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] different results form summarization by loop and sum or rowMeans function
Hi, I found different results calculating the rowMeans by the function rowMeans() and a simple for-loop. The differences are very low. But after this calculation I will start some optimization algorithms (BFGS or CG) and there I get huge differences (from the small changes in the beginning or start values, I changed nothing else in the code). How I can avoid these differences between sum-loops and sum-functions? Attached a small testcode using data form Bioconductor. Best Markus library(affy) data(affybatch.example) mat - exprs(affybatch.example)[1:100,1:3] mat - exp(1)*mat mat - asinh(mat) rowM1- rowMeans(mat) t=rep(0,100) # Vektor mit 0en for(i in 1:100){ for(j in 1:3) t[i] - t[i] + mat[i,j] } rowM2 - t/3 m1 - mat - rowM1 m2 - mat -rowM2 print(m1-m2) sessionInfo() R version 2.7.1 (2008-06-23) i386-pc-mingw32 locale: LC_COLLATE=German_Germany.1252;LC_CTYPE=German_Germany.1252;LC_MONETARY=German_Germany.1252;LC_NUMERIC=C;LC_TIME=German_Germany.1252 attached base packages: [1] tools stats graphics grDevices utils datasets methods [8] base other attached packages: [1] affy_1.18.2 preprocessCore_1.2.0 affyio_1.8.0 [4] Biobase_2.0.1 -- Dipl.-Tech. Math. Markus Schmidberger Ludwig-Maximilians-Universität München IBE - Institut für medizinische Informationsverarbeitung, Biometrie und Epidemiologie Marchioninistr. 15, D-81377 Muenchen URL: http://ibe.web.med.uni-muenchen.de Mail: Markus.Schmidberger [at] ibe.med.uni-muenchen.de Tel: +49 (089) 7095 - 4599 __ 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] different results form summarization by loop and sum or rowMeans function
How low is very low? This is probably answered by FAQ 7.31 On Thu, Sep 11, 2008 at 9:49 AM, Markus Schmidberger [EMAIL PROTECTED] wrote: Hi, I found different results calculating the rowMeans by the function rowMeans() and a simple for-loop. The differences are very low. But after this calculation I will start some optimization algorithms (BFGS or CG) and there I get huge differences (from the small changes in the beginning or start values, I changed nothing else in the code). How I can avoid these differences between sum-loops and sum-functions? Attached a small testcode using data form Bioconductor. Best Markus library(affy) data(affybatch.example) mat - exprs(affybatch.example)[1:100,1:3] mat - exp(1)*mat mat - asinh(mat) rowM1- rowMeans(mat) t=rep(0,100) # Vektor mit 0en for(i in 1:100){ for(j in 1:3) t[i] - t[i] + mat[i,j] } rowM2 - t/3 m1 - mat - rowM1 m2 - mat -rowM2 print(m1-m2) sessionInfo() R version 2.7.1 (2008-06-23) i386-pc-mingw32 locale: LC_COLLATE=German_Germany.1252;LC_CTYPE=German_Germany.1252;LC_MONETARY=German_Germany.1252;LC_NUMERIC=C;LC_TIME=German_Germany.1252 attached base packages: [1] tools stats graphics grDevices utils datasets methods [8] base other attached packages: [1] affy_1.18.2 preprocessCore_1.2.0 affyio_1.8.0 [4] Biobase_2.0.1 -- Dipl.-Tech. Math. Markus Schmidberger Ludwig-Maximilians-Universität München IBE - Institut für medizinische Informationsverarbeitung, Biometrie und Epidemiologie Marchioninistr. 15, D-81377 Muenchen URL: http://ibe.web.med.uni-muenchen.de Mail: Markus.Schmidberger [at] ibe.med.uni-muenchen.de Tel: +49 (089) 7095 - 4599 __ 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 Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] Convex optimization in R?
Ken Lange's MM `algorithm' is a possibility for these non-smooth,, convex problems. It has been implemented in `constrOptim' for handling linear inequality constraints in the minimization of smooth objective functions. I have extended this to nonlinear inequalities. It can be further extended for convex functions, if one can come up with a smooth function that majorizes the convex objective function. This can be easily done for the absolute value function. Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: [EMAIL PROTECTED] Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hans W. Borchers Sent: Thursday, September 11, 2008 7:19 AM To: [EMAIL PROTECTED] Subject: Re: [R] Convex optimization in R? Hesen Peng hesen.peng at gmail.com writes: Hi my R buddies, I'm trying to solve a specific group of convex optimization in R. The admissible region is the inside and surface of a multi-dimensional eclipse area and the goal function is the sum of absolution values of the variables. Could any one please tell me whether there's a package in R to do this? Thank you very much, To my knowledge there does not exist a designated R package for convex optimization. Also, in the Optimization task view the AMS nomenclature 90C25 for Convex programming (CP) is not mentioned. On the other hand, this task view may give you some ideas on how to solve your problem with one of the available optimization packages. For instance, a problem including sums of absolute values can be modeled as a linear program with mixed integer variables (MILP). There is a free module for 'disciplined' convex optimization, CVX, that can be integrated with Matlab or Python. Hopefully, there will be a CVX R package in the future (as has been announced/promised). Hans Werner Borchers ABB Corporate Research Best wishes, -- Hesen Peng http://hesen.peng.googlepages.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] Mixed effects model with binomial errors - problem
ok... the model now runs properly (say, without errors). Now about the result. These are the averages per treatments tapply(VecesArbolCo.VecesCo.C1,T2,mean) a b c d 0.49 0.56 0.45 0.58 I run this very simple model summary(model1-lmer(cbind(VisitsExpTree,TotalVisits-VisitsExpTree)~ treatment +(1|Individual), family=binomial, data=r)) Generalized linear mixed model fit by the Laplace approximation Formula: cbind(VisitsExpTree,TotalVisits-VisitsExpTree)~ treatment +(1|Individual) Data: r AIC BIC logLik deviance 242.3 255.9 -116.2232.3 Random effects: GroupsNameVariance Std.Dev. Individuo (Intercept) 0.14075 0.37517 Number of obs: 112, groups: Individuo, 37 Fixed effects: Estimate Std. Error z value Pr(|z|) (Intercept) 0.372280.19031 1.9562 0.05044 . treatmentb 0.033670.24520 0.1373 0.89079 treatmentc -0.606060.23330 -2.5978 0.00938 ** treatmentd -0.255040.22790 -1.1191 0.26311 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Correlation of Fixed Effects: (Intr) T2bT2c T2b -0.675 T2c -0.697 0.543 T2d -0.720 0.544 0.581 wouldnt we expect the intercept to be roughtly the mean of treatment a? and thus the estimate of treatmentb to be +0.07, c: -0.04 and d: +0.09 roughly? Is this model just completely not estimating well, or are the estimates not the 'real values'. I tried to get teh predict function to give me the 4 predicted values based on the model, but i havent succeeded in doing so. maybe someone can help me on that one too (predict(model1,type=response) doesnt work) thnx -- View this message in context: http://www.nabble.com/Mixed-effects-model-with-binomial-errorsproblem-tp19413327p19436083.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] different results form summarization by loop and sum or rowMeans function
On Thu, 11 Sep 2008, Markus Schmidberger wrote: Hi, I found different results calculating the rowMeans by the function rowMeans() and a simple for-loop. The differences are very low. But after this Indeed, but the C code (rowMeans) is likely to be more accurate as it uses an extended-precision accumulator. calculation I will start some optimization algorithms (BFGS or CG) and there I get huge differences (from the small changes in the beginning or start values, I changed nothing else in the code). How I can avoid these differences between sum-loops and sum-functions? You cannot. What you can do is work on making what you do with these inputs numerically stable: unless you do so your end results will have very little value. (For example, are you finding different local minima, in which case you need to decide how to treat that possibility?) I suggest reading an introductory book on Numerical Analysis, or Monahan, J. F. (2001) Numerical Methods of Statistics. Cambridge: Cambridge. Chapter 2. or Press,W. H., Teukolsky, S. A., Vetterling, W. T. and Flannery, B. P. (2007) Numerical Recipes. The Art of Scientific Programming. Third Edition. Cambridge. Section 1.1 (I think). Attached a small testcode using data form Bioconductor. Best Markus library(affy) data(affybatch.example) mat - exprs(affybatch.example)[1:100,1:3] mat - exp(1)*mat mat - asinh(mat) rowM1- rowMeans(mat) t=rep(0,100) # Vektor mit 0en for(i in 1:100){ for(j in 1:3) t[i] - t[i] + mat[i,j] } rowM2 - t/3 m1 - mat - rowM1 m2 - mat -rowM2 print(m1-m2) sessionInfo() R version 2.7.1 (2008-06-23) i386-pc-mingw32 locale: LC_COLLATE=German_Germany.1252;LC_CTYPE=German_Germany.1252;LC_MONETARY=German_Germany.1252;LC_NUMERIC=C;LC_TIME=German_Germany.1252 attached base packages: [1] tools stats graphics grDevices utils datasets methods [8] base other attached packages: [1] affy_1.18.2 preprocessCore_1.2.0 affyio_1.8.0 [4] Biobase_2.0.1 -- Dipl.-Tech. Math. Markus Schmidberger Ludwig-Maximilians-Universität München IBE - Institut für medizinische Informationsverarbeitung, Biometrie und Epidemiologie Marchioninistr. 15, D-81377 Muenchen URL: http://ibe.web.med.uni-muenchen.de Mail: Markus.Schmidberger [at] ibe.med.uni-muenchen.de Tel: +49 (089) 7095 - 4599 __ 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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ 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 load functions in R
I would recommend saving the functions into a separate file and then using source() as bartjoosen suggested. I do not recommend using save() here because the output is non-readable (even when using ascii=TRUE option). Which means that you have to load() it, then copy-and-paste into an editor before making changes and then running it again in R and then save() again. Another better option is to consider making your own package. It may sound complicated but once you mastered it, it makes your functions more portable and encourages you to document it. Further, the function package.skeleton() simplifies much of it. Regards, Adai Yihui Xie wrote: Hi, you may save your functions somewhere on your disk using save() and load them next time when you want to use them. See ?save and ?load Yihui On Thu, Sep 11, 2008 at 9:30 PM, [EMAIL PROTECTED] wrote: Hello, I am trying to use self created functions in other scripts than the one where they are stored. For the moment I am using the following structure of commands to do that: 1. Load the text file with the functions in the current script: x=parse(path) 2. transform the tex in a function: f1=eval(x[1]), f2=eval(x[2]) if more than one function is stored in the text file 3. use the functions as normal Is there another possibility to do the same? Thank you, Mihai Mirauta [[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] plotCI -- multiple plots on same graph
I have a bunch of lines I want to plot using plotCI() What Id like to know is, how can I connect the points with a line and how can I print multiple lines on the same graph? -- View this message in context: http://www.nabble.com/plotCImultiple-plots-on-same-graph-tp19435198p19435198.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] writing simple function through script
Hi Benoit, If you are in the directory that contains your data, you can use NC60 = read.table(NC60.DATA) # there are some arguments you can use in read.table OR NC60 = read.table(path to your data/NV60.DATA) yo(NC60) By the way, I do not know your LgmFormula. I think you already defined it. Rao Fu Ph.D Yale University Department of Statistics Email: [EMAIL PROTECTED] Date: Wed, 10 Sep 2008 15:22:37 +0200 From: Benoit Boulinguiez [EMAIL PROTECTED] Subject: [R] writing simple function through script To: r-help@r-project.org Message-ID: 001601c91348$4b505a20$[EMAIL PROTECTED] Content-Type: text/plain Hi all, I try to write a simple function in a script. The script is as follows yo-function(Xdata) { n-length(Xdata[,1]) Lgm-nls(formula=LgmFormula, data=Xdata, start=list(a=1500,b=0.1),weights=Xdata$Qe) return(Lgm) } After the execution of the script, when I call the function yo on data called NC60.DATA I get an error. #yo(NC60.DATA) Erreur dans eval(expr, envir, enclos) : objet Xdata not found The object Xdata isn't found. Why? Is that possible to debug a function with R? Regards/Cordialement --- Benoit Boulinguiez Ph.D Ecole de Chimie de Rennes (ENSCR) Bureau 1.20 Equipe CIP UMR CNRS 6226 Sciences Chimiques de Rennes Campus de Beaulieu, 263 Avenue du Général Leclerc 35700 Rennes, France Tel 33 (0)2 23 23 80 83 Fax 33 (0)2 23 23 81 20 http://www.ensc-rennes.fr/ http://www.ensc-rennes.fr/ [[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] Smoothing Spline Clustering
Hi, I need to use the Smoothing Spline Clustering (SSC): genemerge.bioteam.net/SSClust-Manual.pdf But it doesn't work! If someone can try it and help me! In the folder you will find a file named SSClust.R, but, I do not why, it doesn't work. Also the SSClust.test.R file doesn't work, but it produced a part of the total output (you can see in the Example folder the real predicted output). I guess that the error is at line 178 [temp.pred=predict(temp,data.frame(my.time=tt.grid),se.fit=T)] I'm writing my PhD thesis and I'm in hurry...please help me!! Marco ps: if instead of ssanova (at line 176), you use lm everything go well __ 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 load functions in R
We may just read them in the R console instead of an external editor, and fix() or edit() them when we need to make any modifications. A trivial advantage of saving them as an image file in Windows is that you can double-click the file and R will be started with these objects loaded automatically. Anyway, to save the functions as ASCII files or even write a package are also good solutions :-) Regards, Yihui On Thu, Sep 11, 2008 at 10:34 PM, Adaikalavan Ramasamy [EMAIL PROTECTED] wrote: I would recommend saving the functions into a separate file and then using source() as bartjoosen suggested. I do not recommend using save() here because the output is non-readable (even when using ascii=TRUE option). Which means that you have to load() it, then copy-and-paste into an editor before making changes and then running it again in R and then save() again. Another better option is to consider making your own package. It may sound complicated but once you mastered it, it makes your functions more portable and encourages you to document it. Further, the function package.skeleton() simplifies much of it. Regards, Adai Yihui Xie wrote: Hi, you may save your functions somewhere on your disk using save() and load them next time when you want to use them. See ?save and ?load Yihui On Thu, Sep 11, 2008 at 9:30 PM, [EMAIL PROTECTED] wrote: Hello, I am trying to use self created functions in other scripts than the one where they are stored. For the moment I am using the following structure of commands to do that: 1. Load the text file with the functions in the current script: x=parse(path) 2. transform the tex in a function: f1=eval(x[1]), f2=eval(x[2]) if more than one function is stored in the text file 3. use the functions as normal Is there another possibility to do the same? Thank you, Mihai Mirauta [[alternative HTML version deleted]] -- Yihui Xie [EMAIL PROTECTED] Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China __ 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 load functions in R
Hello, It seems that all methods work. Source() however loads only the last function. with save(a,b,file=path) i can save more than 1 function. Thanks a lot, Mihai -Ursprüngliche Nachricht- Von: Yihui Xie [mailto:[EMAIL PROTECTED] Gesendet: Donnerstag, 11. September 2008 16:48 An: [EMAIL PROTECTED] Cc: Mirauta, Mihai; r-help@r-project.org Betreff: Re: [R] How to load functions in R We may just read them in the R console instead of an external editor, and fix() or edit() them when we need to make any modifications. A trivial advantage of saving them as an image file in Windows is that you can double-click the file and R will be started with these objects loaded automatically. Anyway, to save the functions as ASCII files or even write a package are also good solutions :-) Regards, Yihui On Thu, Sep 11, 2008 at 10:34 PM, Adaikalavan Ramasamy [EMAIL PROTECTED] wrote: I would recommend saving the functions into a separate file and then using source() as bartjoosen suggested. I do not recommend using save() here because the output is non-readable (even when using ascii=TRUE option). Which means that you have to load() it, then copy-and-paste into an editor before making changes and then running it again in R and then save() again. Another better option is to consider making your own package. It may sound complicated but once you mastered it, it makes your functions more portable and encourages you to document it. Further, the function package.skeleton() simplifies much of it. Regards, Adai Yihui Xie wrote: Hi, you may save your functions somewhere on your disk using save() and load them next time when you want to use them. See ?save and ?load Yihui On Thu, Sep 11, 2008 at 9:30 PM, [EMAIL PROTECTED] wrote: Hello, I am trying to use self created functions in other scripts than the one where they are stored. For the moment I am using the following structure of commands to do that: 1. Load the text file with the functions in the current script: x=parse(path) 2. transform the tex in a function: f1=eval(x[1]), f2=eval(x[2]) if more than one function is stored in the text file 3. use the functions as normal Is there another possibility to do the same? Thank you, Mihai Mirauta [[alternative HTML version deleted]] -- Yihui Xie [EMAIL PROTECTED] Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China __ 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] Truncating dates (and other date-time manipulations)
Dear all, I've been struggling to perform common operations on dates that I need to be able to correct draw date-time scales - in particular I need to be able to round/truncate/ceiling dates to arbitrary precision - e.g. to weeks, months or years (or multiples thereof). I haven't been able to find anything to do this in base R (trunc.Date only truncates to sub-day units), or in the date related contributed packages I've looked in (e.g. chron). Have I missed something? Otherwise, I have been working on a bottom up set of functions to make date manipulation easier - http://gist.github.com/10238. These should work for all date-time types and I've tried to use a consistent naming scheme and consistent output conventions. This seems like a rather small bundle of functions to be worth turning into a package, so I was wondering if anyone would be interested in adopting them into an existing date-time related package. Regards, Hadley -- http://had.co.nz/ __ 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] plotCI -- multiple plots on same graph
1) Look into plotmeans(), a wrapper function for plotCIit may be more appropriate for what you're looking for and one of the default options is to connect the points with lines. Otherwise you'll have to do a separate call to lines() after each plotCI() call. 2) To put multiple data sets on the same axes, you'll have to do a plotmeans/plotCI call for each data set but before the second, third, etc plot you should call par(new=TRUE) cheers, brandon On Thu, 11 Sep 2008 06:48:25 -0700 (PDT), bioinformatics_guy [EMAIL PROTECTED] wrote: I have a bunch of lines I want to plot using plotCI() What Id like to know is, how can I connect the points with a line and how can I print multiple lines on the same graph? -- View this message in context: http://www.nabble.com/plotCImultiple-plots-on-same-graph-tp19435198p19435198.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 load functions in R
YX == Yihui Xie [EMAIL PROTECTED] on Thu, 11 Sep 2008 22:47:47 +0800 writes: YX We may just read them in the R console instead of an external editor, YX and fix() or edit() them when we need to make any modifications. A YX trivial advantage of saving them as an image file in Windows is that YX you can double-click the file and R will be started with these objects YX loaded automatically. Anyway, to save the functions as ASCII files or YX even write a package are also good solutions :-) ^ also good... baahh... *THE* good! I'd strongly second Adai's view here: *DO* use *.R source files --- together with an R-syntax aware editor, there are many nowadays and source() them, as a first step; put them in an own package as a 2nd step. Martin Maechler, ETH Zurich YX Regards, YX Yihui YX On Thu, Sep 11, 2008 at 10:34 PM, Adaikalavan Ramasamy YX [EMAIL PROTECTED] wrote: I would recommend saving the functions into a separate file and then using source() as bartjoosen suggested. I do not recommend using save() here because the output is non-readable (even when using ascii=TRUE option). Which means that you have to load() it, then copy-and-paste into an editor before making changes and then running it again in R and then save() again. Another better option is to consider making your own package. It may sound complicated but once you mastered it, it makes your functions more portable and encourages you to document it. Further, the function package.skeleton() simplifies much of it. Regards, Adai Yihui Xie wrote: Hi, you may save your functions somewhere on your disk using save() and load them next time when you want to use them. See ?save and ?load Yihui On Thu, Sep 11, 2008 at 9:30 PM, [EMAIL PROTECTED] wrote: Hello, I am trying to use self created functions in other scripts than the one where they are stored. For the moment I am using the following structure of commands to do that: 1. Load the text file with the functions in the current script: x=parse(path) 2. transform the tex in a function: f1=eval(x[1]), f2=eval(x[2]) if more than one function is stored in the text file 3. use the functions as normal Is there another possibility to do the same? Thank you, Mihai Mirauta [[alternative HTML version deleted]] YX -- YX Yihui Xie [EMAIL PROTECTED] YX Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 YX Mobile: +86-15810805877 YX Homepage: http://www.yihui.name YX School of Statistics, Room 1037, Mingde Main Building, YX Renmin University of China, Beijing, 100872, China YX __ YX R-help@r-project.org mailing list YX https://stat.ethz.ch/mailman/listinfo/r-help YX PLEASE do read the posting guide http://www.R-project.org/posting-guide.html YX 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] Truncating dates (and other date-time manipulations)
I'm wrapping boost date_time into an R package. I'll post it up to cran shortly. http://www.boost.org/doc/libs/1_36_0/doc/html/date_time.html I'm not sure if that is what you are looking for, but there are a lot of useful utilities in this library. -Whit On Thu, Sep 11, 2008 at 11:02 AM, hadley wickham [EMAIL PROTECTED] wrote: Dear all, I've been struggling to perform common operations on dates that I need to be able to correct draw date-time scales - in particular I need to be able to round/truncate/ceiling dates to arbitrary precision - e.g. to weeks, months or years (or multiples thereof). I haven't been able to find anything to do this in base R (trunc.Date only truncates to sub-day units), or in the date related contributed packages I've looked in (e.g. chron). Have I missed something? Otherwise, I have been working on a bottom up set of functions to make date manipulation easier - http://gist.github.com/10238. These should work for all date-time types and I've tried to use a consistent naming scheme and consistent output conventions. This seems like a rather small bundle of functions to be worth turning into a package, so I was wondering if anyone would be interested in adopting them into an existing date-time related package. Regards, Hadley -- http://had.co.nz/ __ 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] Truncating dates (and other date-time manipulations)
I'm wrapping boost date_time into an R package. I'll post it up to cran shortly. http://www.boost.org/doc/libs/1_36_0/doc/html/date_time.html I'm not sure if that is what you are looking for, but there are a lot of useful utilities in this library. Looks useful, but I didn't see any built in way to round a date to arbitrary precision. Hadley -- http://had.co.nz/ __ 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] Truncating dates (and other date-time manipulations)
See ?cut.Date In the zoo package see: ?as.yearmon ?as.yearqtr ?aggregate.zoo and the many examples in: ?plot.zoo ?xyplot.zoo as well as the three zoo vignettes. Also in the xts package look at ?to.period For regularly spaced series the tis package supports a wide variety of time bases and can convert among them. There are as.zoo.tis and as.tis.zoo routines in zoo and tis; also, xts is a subclass of zoo so all these packages can work together. On Thu, Sep 11, 2008 at 11:02 AM, hadley wickham [EMAIL PROTECTED] wrote: Dear all, I've been struggling to perform common operations on dates that I need to be able to correct draw date-time scales - in particular I need to be able to round/truncate/ceiling dates to arbitrary precision - e.g. to weeks, months or years (or multiples thereof). I haven't been able to find anything to do this in base R (trunc.Date only truncates to sub-day units), or in the date related contributed packages I've looked in (e.g. chron). Have I missed something? Otherwise, I have been working on a bottom up set of functions to make date manipulation easier - http://gist.github.com/10238. These should work for all date-time types and I've tried to use a consistent naming scheme and consistent output conventions. This seems like a rather small bundle of functions to be worth turning into a package, so I was wondering if anyone would be interested in adopting them into an existing date-time related package. Regards, Hadley -- http://had.co.nz/ __ 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] csaps in R port from Octave?
Since I'm getting no joy looking for an R implementation of the matlab function csaps, can anybody advise me on porting csaps from Octave? There is an octave implementation of csaps here: http://octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/nonfree/spline-gsvspl/inst/csaps.m This function calls external C function gcvspl located here: http://octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/nonfree/spline-gsvspl/src/gcvspl.cc Any C gurus out there care to opine on how hard this would be to port to an external C function that R could call. I need to be able to repeat results from csaps as part of a review and don't have access to Matlab (or inclination to install and learn Octave). Or, back to the original query, is there a way to mimic csaps in R? In particular I need to be able to repeat an analysis with the the same smoothing parameter (p) from csaps. Please help! ::DrC __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] new RMySQL and new maintainer
Hello, [This is a re-posting of a previous announcement; I believe the original posting of a couple of days ago didn't go through.] The latest version of RMySQL 0.6-1 is now in CRAN. Please see the NEWS file for more details. Also, I'm happy to announce that Jeff Horner [EMAIL PROTECTED] has kindly agreed to maintain RMySQL from now on. Please continue sending your comments, suggestions, bug reports , patches, etc., to the R-sig-DB mailing list. Regards, -- David ___ R-packages mailing list [EMAIL PROTECTED] https://stat.ethz.ch/mailman/listinfo/r-packages __ 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 calcaulate matrices for two subsets
I am an R beginner and trying to run a market model using event study in R framework. First, I run a market model, that is lm(stock security~SP500 index, subset=Obs[197, 396]) -result1 Then I get predict results for a new dataset using predict (result1, newdata=Obs[397,399]) -pred1 Pred1 should have three numbers. Now I need to calculate abnormal return by the formula stock security [397,399] -pred1 But it does not work after trying many times. So, how to write a R code to implement the formula and get right results. Thanks, Bill [[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] request: most repeated component of a list
Did you try my function? I don't see how it doesn't fit the need of this reexplanation. For this set, x would end up equal to c(2,2,1), indicating that array 1 appears twice in the set and array 2 appears twice in the set. So, array 1 and array 2 appear maximally in the set. So, look at a[[1]] or a[[2]] and that is your answer. --Adam On Thu, 11 Sep 2008, Muhammad Azam wrote: Thanks for the effort but still we are far from the desired result. May be this example will help you to understand the situation. Example a1=c(1:12); a1=array(a1,dim=c(3,4)); a2=c(1:12); a2=array(a2,dim=c(3,4)); a3=c(1:16) a3=array(a3,dim=c(4,4)); a=list(a1,a2,a3); a [[1]] [,1] [,2] [,3] [,4] [1,]147 10 [2,]258 11 [3,]369 12 [[2]] [,1] [,2] [,3] [,4] [1,]147 10 [2,]258 11 [3,]369 12 [[3]] [,1] [,2] [,3] [,4] [1,]159 13 [2,]26 10 14 [3,]37 11 15 [4,]48 12 16 Here [[1]] and [[2]] are same out of three (internal values wise). The whole array [[1]] or [[2]] is in majority. So i want to get the whole array or component of list which is in majority. The result should be like this [,1] [,2] [,3] [,4] [1,]147 10 [2,]258 11 [3,]369 12 Hope it is much more clear as before. best regards Muhammad Azam - Original Message From: Adam D. I. Kramer [EMAIL PROTECTED] To: Muhammad Azam [EMAIL PROTECTED] Cc: R Help r-help@r-project.org Sent: Thursday, September 11, 2008 9:53:40 AM Subject: Re: [R] request: most repeated component of a list That is indeed different from what I thought the first time. x - sapply(1:length(l), function(x) { sum(sapply(l, function(y) { if ( nrow(l[[x]]) != nrow(y) | ncol(l[[x]]) != ncol(y) ) FALSE else sum(y != l[[x]]) == 0 })) } ) names(x) - names(l) Then, x has the same names as l, and x[i] is the number of matches that l[[i]] has...so you want the index or indices of max(x). --Adam On Thu, 11 Sep 2008, Muhammad Azam wrote: May be i could not explain properly. Actually there are components of list i.e. [[1]] to [[500]]. Each component containing r-rows (may be different for each [[ k ]] and c-columns same for all). I have to compare all the [[ k ]] components of that list and found the one appearing maximum no of times. e.g. from three components [[1]] to [[3]] given below. The most repeated is [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]43400 [3,]43400 [4,]43000Please help to find it. Thanks and best regards Muhammad Azam - Original Message From: jim holtman [EMAIL PROTECTED] To: Muhammad Azam [EMAIL PROTECTED] Cc: R-help request [EMAIL PROTECTED]; R Help r-help@r-project.org Sent: Wednesday, September 10, 2008 5:59:28 PM Subject: Re: [R] request: most repeated component of a list If want you want is the summary from all of them, then 'rbind' the data together into one matrix and analyze it: totalMat - do.call(rbind, listOfMatrices) On Wed, Sep 10, 2008 at 11:49 AM, Muhammad Azam [EMAIL PROTECTED] wrote: Dear R community I have stored the results of arrays in a list consist of J-components (say 200 components). Each component containing same no of columns but may be different no of rows. e.g [[1]] [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]43400 [3,]43400 [4,]43000 [[2]] [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]43400 [3,]43400 [4,]43000 [[3]] [,1] [,2] [,3] [,4] [,5] [1,]40000 [2,]44100 [3,]44100 [4,]44000 [5,]44000 For 200 components i want to make a frequency table. How can i make a frequency table of these components or the most repeated component out of all? Any help in this regard will be appreciated. Muhammad Azam [[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 Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list
Re: [R] Truncating dates (and other date-time manipulations)
probably not pre-canned routines for that, but very easy to implement with the tools provided in the library. Looks like most of what you want to do is fairly simple and not worth the trouble of involving c++. but things like month_durations and year_durations make it clear that the authors have been really thorough in their design: http://www.boost.org/doc/libs/1_36_0/doc/html/date_time/gregorian.html#date_time.gregorian.date_duration Reversibility of Operations Pitfall A natural expectation when adding a number of months to a date, and then subtracting the same number of months, is to end up exactly where you started. This is most often the result the date_time library provides but there is one significant exception: The snap-to-end-of-month behavior implemented by the months duration type. The months duration type may provide unexpected results when the starting day is the 28th, 29th, or 30th in a 31 day month. The month_iterator is not effected by this issue and is therefore included in the examples to illustrate a possible alternative. When the starting date is in the middle of a month, adding or subtracting any number of months will result in a date that is the same day of month (e.g. if you start on the 15th, you will end on the 15th). When a date is the last day of the month, adding or subtracting any number of months will give a result that is also the last day of the month (e.g if you start on Jan 31st, you will land on: Feb 28th, Mar 31st, etc). // using months duration type date d(2005, Nov, 30); // last day of November d + months(1); // result is last day of December 2005-Dec-31 d - months(1); // result is last day of October 2005-Oct-31 // using month_iterator month_iterator itr(d); // last day of November ++itr; // result is last day of December 2005-Dec-31 --itr; // back to original starting point 2005-Nov-30 --itr; // last day of October 2005-Oct-31 If the start date is the 28th, 29th, or 30th in a 31 day month, the result of adding or subtracting a month may result in the snap-to-end-of-month behavior kicking in unexpectedly. This would cause the final result to be different that the starting date. // using months duration type date d(2005, Nov, 29); d += months(1); // 2005-Dec-29 d += months(1); // 2006-Jan-29 d += months(1); // 2006-Feb-28 -- snap-to-end-of-month behavior kicks in d += months(1); // 2006-Mar-31 -- unexpected result d -= months(4); // 2005-Nov-30 -- unexpected result, not where we started // using month_iterator month_iterator itr(date(2005, Dec, 30)); ++itr; // 2006-Jan-30 -- ok ++itr; // 2006-Feb-28 -- snap-to DOES NOT kick in ++itr; // 2006-Mar-30 -- ok --itr; // 2006-Feb-28 -- ok --itr; // 2006-Jan-30 -- ok --itr; // 2005-Dec-30 -- ok, back where we started Cheers, Whit On Thu, Sep 11, 2008 at 11:49 AM, hadley wickham [EMAIL PROTECTED] wrote: I'm wrapping boost date_time into an R package. I'll post it up to cran shortly. http://www.boost.org/doc/libs/1_36_0/doc/html/date_time.html I'm not sure if that is what you are looking for, but there are a lot of useful utilities in this library. Looks useful, but I didn't see any built in way to round a date to arbitrary precision. Hadley -- http://had.co.nz/ __ 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] subscript out of bounds
I'm working on Human Exon Array 1.0 ST. I'm getting normalized data fine but I'm running into problems with QC. QCReport gives me the following error: load(file= huex10stv2cdf.rda) [EMAIL PROTECTED] - huex10stv2cdf QCReport(exon.data, file = QCReport.pdf) Error in as.vector(ans[[i]][, i.probes]) : subscript out of bounds Your insight is very much appreciated!! Dorothy __ 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] RSiteSearch for words ``as one entity''.
On Wed, Sep 10, 2008 at 11:33 PM, Prof Brian Ripley [EMAIL PROTECTED] wrote: If firefox is involved on a Mac, that is one difference. My Mac is using 'open' (the default, I believe) and that is calling Safari (the default, I believe). Yes, it would be the job of browseURL to encode URLs where required. But at least on Windows and using the -remoteURL mechanism (as on Linux) it is not. R itself does have URLencode. Thanks for pointing out URLencode(); I'll update (my very old) R.utils::toUrl() to use that and eventually deprecate it. /Henrik On Thu, 11 Sep 2008, Rolf Turner wrote: On 11/09/2008, at 10:09 AM, Marc Schwartz wrote: snip As Prof. Ripley noted, try using debug(RSiteSearch) and then step through the code to see where $HOME is being added to the URL variable. That can help pin it down further. If the URL is not corrupted by the time browseURL() is called, then use debug(browseURL) to trace within that function to see if something is happening there. I have done some digging. When I do: RSiteSearch(logistic regression) the RSiteSearch() function calls browseURL(qstring) where qstring is qs1 equal to http://search.r-project.org/cgi-bin/namazu.cgi?query=logistic+regressionmax=20result=normalsort=scoreidxname=Rhelp02aidxname=functionsidxname=docs; Similarly when I do RSiteSearch({logistic regression}) qstring is qs2 equal to http://search.r-project.org/cgi-bin/namazu.cgi?query={logistic+regression}max=20result=normalsort=scoreidxname=Rhelp02aidxname=functionsidxname=docs; i.e. the same except for the braces. If I do browseURL(qs1) outside of RSiteSearch() it works as expected. If I do browseURL(qs2) I get the error. Inside browseURL I find that it calls system(paste(browser, remoteCmd, /dev/null 21 ||, browser, quotedUrl, )) and browser is /usr/bin/open, remoteCmd is the qstring with the opening and closing quote marks attached (escaped with a ``\'') amd quotedUrl is the same. This is true irrespective of which qstring (qs1 or qs2 is used). Note that the double backslash shows up in remoteCmd == quotedUrl at this stage. Finally I put the system command into a file ``junk'' and from the command window (outside R) executed ``sh junk''. With the braces around ``logistic regression'' I can the same error message that I got in R. When I simply edited out the braces, the Firefox window opened at the appropriate URL. So the problem is in those braces and the single/double backslash at the start was a red herring. Finally, while I was doing all this I got Henrik Bengtsson's message, and tried his suggestion: library(R.utils) browseURL(toUrl(qs2)) and BINGO!!! that worked. (Thanks very much, Henrik.) It's still mysterious why the braces have their deleterious impact on my Mac but do not have that impact on Professor Ripley's machine. (But that's the story of my life: THEY always pick on ***me***! :-) ) So my problem is solved --- via a workaround --- but there's still some vestigial strangeness. Thanks to all who helped me, especially (again) to Henrik Bengtsson cheers, Rolf ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ 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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ 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] creating a package with internal (hiden) S4 classes and methods
Dear R users, I am writing my first R package and it finally past the R CMD check. Before sending it to CRAN, I would like to check a few issues. 1. I created s4 classes and methods in the package but I want only 1 function (foo) to be available to users and documented in the manual that goes with the package. I put foo in 1 file and the rest (internal functions, classes and methods) in a file called mypackage-internal.R. For the .Rd file, I created one for each class, method and internal functions, and I wrote \keyword{internal} and the end. Finally, I have created a NAMESPACE that export my function f00. I thought it would work but it created a problem with the classes and methods not being declared so I added Classes(''myclass) and Methods(my method) to the NAMESPACE file. Does this make sense as to a way to hide classes and methods from users, and avoid describing them? 2. Everything goes smoothly when I R CMD build and R CMD check. However, when I look at the mypackage-manual.tex file that the R CMD check created, I see all my internal classes, methods and functions listed. This is not what I want, I only want foo. I know that I need to send the tar.gz file to CRAN but I am clueless as to how the package manual (pdf) will be created. Will it look like the mypackage-manual.tex? If so, how do I make sure that only the package DESCRIPTION and the foo function are listed? Please do not simply refer me to the manual 'Writing R extensions!'. I have read it carefully but I have to admit that some of the stuff explained there is beyond me. I am lost. many thanks in advance, MP __ 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] Calculate mean/var by ID
Hello, I have a data set that looks like this. IDvalue 111 5 111 6 111 2 178 7 178 3 138 3 138 8 138 7 138 6 . . . I'd like to calculate the mean and var for each object identified by the ID. I can in theory just loop through the whole thing..., but is there a easier way/command which let me calculate the mean/var by ID? Thanks, Julia -- View this message in context: http://www.nabble.com/Calculate-mean-var-by-ID-tp19440461p19440461.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] fft: from characteristic funtion to density function
take a look at http://finzi.psych.upenn.edu/R/Rhelp02a/archive/130153.html hth, Matthias Jindan Zhou wrote: Hello all! I've posted the question before but I am still struggling for an answer, please help if you can;-) Suppose a discrete series of data is generated by the following equation: CF=exp(-(t^2)/2) which is the characteristic function of a random variable X with standard normal distribution, how do I *numerically* solve for its probability density function? i.e., obtain a series of data that plots a well know bell-shape curve? Or, find x such that Pr(Xx)=0.05? I have no problem to derive the forward and inverse Fourier equation pair, but just no clue on numerical method. A working code on this simplest exercise would clear off many, many of my confusions I have generated CF with t of 256 points equally spaced between -4 to 4 in Excel, but don't know how to proceed. Thanks for your help! Jindan __ 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. -- Dr. Matthias Kohl www.stamats.de __ 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] arima and xreg
You can have lagged inputs in the xreg statement, you just have to construct the input matrix properly so the dimensions are the same, e.g., x = ts.intersect(mort, trend, part, lag(part,-4)) arima(x[,1],order=c(2,0,1), xreg=x[,2:4]) ... and yes you have to worry about singularities or even multicolinearity (near or computational singularity), e.g., this fails: x = ts.intersect(mort, trend, part, part) arima(x[,1],order=c(2,0,1), xreg=x[,2:4]) Jose Capco wrote: On Sep 11, 6:24 am, David Stoffer [EMAIL PROTECTED] wrote: Your model is close, but not correct... there are no t's on the parameters and the U's aren't lagged. You can find an ARMAX example on our quick fix page:http://www.stat.pitt.edu/stoffer/tsa2/R_time_series_quick_fix.htm. The example is near the bottom and just above the spectral analysis example, but you may want to read the regression with autocorrelated errors example first to get some background. Ok. so arima of R can only deal with unlagged inputs (thus xreg has the latest value in the equation). Your example was an ARX (no moving averages) here is the code of yoru example : armax.fit = arima(mort, order=c(2,0,0), xreg=cbind(trend, part)) I guess I can change it to ARMAX if I use order=c(p,0,q) =) Now theres one thing that might be worth mentioning here though. The above can only work (I am guessing) if the input values (the columns of xreg) are uncorrelated (or what word do use for that, sorry Im a pure mathematician, not a statistician :p ). What I mean is that the matrix in which optim of R must be singular (otherwise I think, from my last try when using two equal valued columns in xreg, arima will complain that optim returns an infinity value). Is there a way to check if the xreg matrix have uncorrelated inputs and then just discard the column until xreg becomes uncorrelated? I'll do a few more experiment with xreg and report here.. Im doing this because the documentation (as many of us already know.. ) do not really explain xreg very well. Sincerely, Jose Capco __ 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. - The power of accurate observation is commonly called cynicism by those who have not got it. George Bernard Shaw -- View this message in context: http://www.nabble.com/arima-and-xreg-tp19415386p19440600.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] Calculate mean/var by ID
Try: with(x, sapply(list(mean, var), function(x)tapply(value, ID, x))) On Thu, Sep 11, 2008 at 2:45 PM, liujb [EMAIL PROTECTED] wrote: Hello, I have a data set that looks like this. IDvalue 111 5 111 6 111 2 178 7 178 3 138 3 138 8 138 7 138 6 . . . I'd like to calculate the mean and var for each object identified by the ID. I can in theory just loop through the whole thing..., but is there a easier way/command which let me calculate the mean/var by ID? Thanks, Julia -- View this message in context: http://www.nabble.com/Calculate-mean-var-by-ID-tp19440461p19440461.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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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] Calculate mean/var by ID
aggregate(value,list(ID=ID),mean) aggregate(value,list(ID=ID),var) --Adam On Thu, 11 Sep 2008, liujb wrote: Hello, I have a data set that looks like this. IDvalue 111 5 111 6 111 2 178 7 178 3 138 3 138 8 138 7 138 6 . . . I'd like to calculate the mean and var for each object identified by the ID. I can in theory just loop through the whole thing..., but is there a easier way/command which let me calculate the mean/var by ID? Thanks, Julia -- View this message in context: http://www.nabble.com/Calculate-mean-var-by-ID-tp19440461p19440461.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 calcaulate matrices for two subsets
Hi Bill, Tell me more about the Obs object. The subset of an lm should be a vector telling the lm which observations to use...if Obs[197,396] is a single number, only one observation will be used, and chances are your model is not what you intended. Also, predict(result1,newdata=Obs[397,339]) needs that cell in Obs to have a column called SP500 index, and predict.lm (check the man page for it) will only return one number, the prediction for the given new data. If you want it to have 3 numbers, maybe Obs[397:399] is what you want? The colon means 397 through 399, inclusive while the comma means row 397, column 399. If this is your mistake, you actually want subset=197:396, data=Obs in your call to lm. Hope this helped. --Adam On Thu, 11 Sep 2008, Xianchun Liao wrote: I am an R beginner and trying to run a market model using event study in R framework. First, I run a market model, that is lm(stock security~SP500 index, subset=Obs[197, 396]) -result1 Then I get predict results for a new dataset using predict (result1, newdata=Obs[397,399]) -pred1 Pred1 should have three numbers. Now I need to calculate abnormal return by the formula stock security [397,399] -pred1 But it does not work after trying many times. So, how to write a R code to implement the formula and get right results. Thanks, Bill [[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] Calculate mean/var by ID
Dear Julia, Try also x=read.table(textConnection(IDvalue 111 5 111 6 111 2 178 7 178 3 138 3 138 8 138 7 138 6),header=TRUE) closeAllConnections() attach(x) do.call(rbind,tapply(value,ID, function(x){ res=c(mean(x,na.rm=TRUE),var(x,na.rm=TRUE)) names(res)=c('Mean','Variance') res } ) ) HTH, Jorge On Thu, Sep 11, 2008 at 1:45 PM, liujb [EMAIL PROTECTED] wrote: Hello, I have a data set that looks like this. IDvalue 111 5 111 6 111 2 178 7 178 3 138 3 138 8 138 7 138 6 . . . I'd like to calculate the mean and var for each object identified by the ID. I can in theory just loop through the whole thing..., but is there a easier way/command which let me calculate the mean/var by ID? Thanks, Julia -- View this message in context: http://www.nabble.com/Calculate-mean-var-by-ID-tp19440461p19440461.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] database table merging tips with R
Dear R list, What is the best way to efficiently marry an R dataset with a very large (Oracle) database table? The goal is to only return Oracle table rows that match IDs present in the R dataset. I have an R data frame with 2000 user IDs analogous to: r = data.frame(userid=round(runif(2000)*10,0)) ...and I need to pull data from an Oracle table only for these 2000 IDs. The Oracle table is quite large. Additionally, the sql query may need to join to other tables to bring in ancillary fields. I currently connect to Oracle via odbc: library(RODBC) connection - odbcConnect(, uid=, pwd=) d = sqlQuery(connection, select userid, x, y, z from largetable where timestamp sysdate -7) ...allowing me to pull data from the database table into the R object d and then use the R merge function. The problem however is that if d is too large it may fail due to memory limitations or be inefficient. I would like to push the merge portion to the database and it would be very convenient if it were possible to request that the query look to the R object for the ID's to which it should restrict the output. Is there a way to do this? Something like the following fictional code: d = sqlQuery(connection, select t.userid, x, y, z from largetable t where r$userid=t.userid) Would sqldf (http://code.google.com/p/sqldf/) help me out here? If so, how? This would be convenient and help me avoid needing to create a temporary table to store the R data, join via sql, then return the data back to R. I am using R version 2.7.2 (2008-08-25) / i386-pc-mingw32 . Thanks for your comments, ideas, recommendations. -Avram __ 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 load functions in R
Strange. source() should read all the function in that file unless there was a syntax error or something else preventing the other function from being parsed correctly. Could you send us a simplified example that reproduces this problem? Thanks. Regards, Adai [EMAIL PROTECTED] wrote: Hello, It seems that all methods work. Source() however loads only the last function. with save(a,b,file=path) i can save more than 1 function. Thanks a lot, Mihai -Ursprüngliche Nachricht- Von: Yihui Xie [mailto:[EMAIL PROTECTED] Gesendet: Donnerstag, 11. September 2008 16:48 An: [EMAIL PROTECTED] Cc: Mirauta, Mihai; r-help@r-project.org Betreff: Re: [R] How to load functions in R We may just read them in the R console instead of an external editor, and fix() or edit() them when we need to make any modifications. A trivial advantage of saving them as an image file in Windows is that you can double-click the file and R will be started with these objects loaded automatically. Anyway, to save the functions as ASCII files or even write a package are also good solutions :-) Regards, Yihui On Thu, Sep 11, 2008 at 10:34 PM, Adaikalavan Ramasamy [EMAIL PROTECTED] wrote: I would recommend saving the functions into a separate file and then using source() as bartjoosen suggested. I do not recommend using save() here because the output is non-readable (even when using ascii=TRUE option). Which means that you have to load() it, then copy-and-paste into an editor before making changes and then running it again in R and then save() again. Another better option is to consider making your own package. It may sound complicated but once you mastered it, it makes your functions more portable and encourages you to document it. Further, the function package.skeleton() simplifies much of it. Regards, Adai Yihui Xie wrote: Hi, you may save your functions somewhere on your disk using save() and load them next time when you want to use them. See ?save and ?load Yihui On Thu, Sep 11, 2008 at 9:30 PM, [EMAIL PROTECTED] wrote: Hello, I am trying to use self created functions in other scripts than the one where they are stored. For the moment I am using the following structure of commands to do that: 1. Load the text file with the functions in the current script: x=parse(path) 2. transform the tex in a function: f1=eval(x[1]), f2=eval(x[2]) if more than one function is stored in the text file 3. use the functions as normal Is there another possibility to do the same? Thank you, Mihai Mirauta [[alternative HTML version deleted]] -- Yihui Xie [EMAIL PROTECTED] Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China __ 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] database table merging tips with R
I would load your set of userid's into a temporary table in oracle, then join that table with the rest of your SQL query to get only the matching rows out. -Aaron On Thu, Sep 11, 2008 at 2:33 PM, Avram Aelony [EMAIL PROTECTED] wrote: Dear R list, What is the best way to efficiently marry an R dataset with a very large (Oracle) database table? The goal is to only return Oracle table rows that match IDs present in the R dataset. I have an R data frame with 2000 user IDs analogous to: r = data.frame(userid=round(runif(2000)*10,0)) ...and I need to pull data from an Oracle table only for these 2000 IDs. The Oracle table is quite large. Additionally, the sql query may need to join to other tables to bring in ancillary fields. I currently connect to Oracle via odbc: library(RODBC) connection - odbcConnect(, uid=, pwd=) d = sqlQuery(connection, select userid, x, y, z from largetable where timestamp sysdate -7) ...allowing me to pull data from the database table into the R object d and then use the R merge function. The problem however is that if d is too large it may fail due to memory limitations or be inefficient. I would like to push the merge portion to the database and it would be very convenient if it were possible to request that the query look to the R object for the ID's to which it should restrict the output. Is there a way to do this? Something like the following fictional code: d = sqlQuery(connection, select t.userid, x, y, z from largetable t where r$userid=t.userid) Would sqldf (http://code.google.com/p/sqldf/) help me out here? If so, how? This would be convenient and help me avoid needing to create a temporary table to store the R data, join via sql, then return the data back to R. I am using R version 2.7.2 (2008-08-25) / i386-pc-mingw32 . Thanks for your comments, ideas, recommendations. -Avram __ 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] database table merging tips with R
Sorry, I see now you want to avoid this, but you did ask what was the best way to efficiently ..., and the temp. table solution certainly matches your description. What's wrong with using a temporary table? -Aaron On Thu, Sep 11, 2008 at 3:05 PM, Aaron Mackey [EMAIL PROTECTED] wrote: I would load your set of userid's into a temporary table in oracle, then join that table with the rest of your SQL query to get only the matching rows out. -Aaron On Thu, Sep 11, 2008 at 2:33 PM, Avram Aelony [EMAIL PROTECTED] wrote: Dear R list, What is the best way to efficiently marry an R dataset with a very large (Oracle) database table? The goal is to only return Oracle table rows that match IDs present in the R dataset. I have an R data frame with 2000 user IDs analogous to: r = data.frame(userid=round(runif(2000)*10,0)) ...and I need to pull data from an Oracle table only for these 2000 IDs. The Oracle table is quite large. Additionally, the sql query may need to join to other tables to bring in ancillary fields. I currently connect to Oracle via odbc: library(RODBC) connection - odbcConnect(, uid=, pwd=) d = sqlQuery(connection, select userid, x, y, z from largetable where timestamp sysdate -7) ...allowing me to pull data from the database table into the R object d and then use the R merge function. The problem however is that if d is too large it may fail due to memory limitations or be inefficient. I would like to push the merge portion to the database and it would be very convenient if it were possible to request that the query look to the R object for the ID's to which it should restrict the output. Is there a way to do this? Something like the following fictional code: d = sqlQuery(connection, select t.userid, x, y, z from largetable t where r$userid=t.userid) Would sqldf (http://code.google.com/p/sqldf/) help me out here? If so, how? This would be convenient and help me avoid needing to create a temporary table to store the R data, join via sql, then return the data back to R. I am using R version 2.7.2 (2008-08-25) / i386-pc-mingw32 . Thanks for your comments, ideas, recommendations. -Avram __ 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 load functions in R
Source(file.path) executes the file at file.path in order, just as if you had typed it in. So, the source file should in fact name each function in turn: f1 - function(x) { ... } f2 - function(x) { ... } ...etc. So a good way to debug is to just copy and paste lines from your source file into the R command line, and see if they behave as expected. --Adam On Thu, 11 Sep 2008, Adaikalavan Ramasamy wrote: Strange. source() should read all the function in that file unless there was a syntax error or something else preventing the other function from being parsed correctly. Could you send us a simplified example that reproduces this problem? Thanks. Regards, Adai [EMAIL PROTECTED] wrote: Hello, It seems that all methods work. Source() however loads only the last function. with save(a,b,file=path) i can save more than 1 function. Thanks a lot, Mihai -Ursprüngliche Nachricht- Von: Yihui Xie [mailto:[EMAIL PROTECTED] Gesendet: Donnerstag, 11. September 2008 16:48 An: [EMAIL PROTECTED] Cc: Mirauta, Mihai; r-help@r-project.org Betreff: Re: [R] How to load functions in R We may just read them in the R console instead of an external editor, and fix() or edit() them when we need to make any modifications. A trivial advantage of saving them as an image file in Windows is that you can double-click the file and R will be started with these objects loaded automatically. Anyway, to save the functions as ASCII files or even write a package are also good solutions :-) Regards, Yihui On Thu, Sep 11, 2008 at 10:34 PM, Adaikalavan Ramasamy [EMAIL PROTECTED] wrote: I would recommend saving the functions into a separate file and then using source() as bartjoosen suggested. I do not recommend using save() here because the output is non-readable (even when using ascii=TRUE option). Which means that you have to load() it, then copy-and-paste into an editor before making changes and then running it again in R and then save() again. Another better option is to consider making your own package. It may sound complicated but once you mastered it, it makes your functions more portable and encourages you to document it. Further, the function package.skeleton() simplifies much of it. Regards, Adai Yihui Xie wrote: Hi, you may save your functions somewhere on your disk using save() and load them next time when you want to use them. See ?save and ?load Yihui On Thu, Sep 11, 2008 at 9:30 PM, [EMAIL PROTECTED] wrote: Hello, I am trying to use self created functions in other scripts than the one where they are stored. For the moment I am using the following structure of commands to do that: 1. Load the text file with the functions in the current script: x=parse(path) 2. transform the tex in a function: f1=eval(x[1]), f2=eval(x[2]) if more than one function is stored in the text file 3. use the functions as normal Is there another possibility to do the same? Thank you, Mihai Mirauta [[alternative HTML version deleted]] -- Yihui Xie [EMAIL PROTECTED] Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China __ 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] database table merging tips with R
Perhaps I will need to create a temp table, but I am asking if there is a way to avoid it. It would be great if there were a way to tie the R data frame temporarily to the query in a transparent fashion. If not, I will see if I can create/drop the temp table directly from sqlQuery. -Avram On Thursday, September 11, 2008, at 12:07PM, Aaron Mackey [EMAIL PROTECTED] wrote: Sorry, I see now you want to avoid this, but you did ask what was the best way to efficiently ..., and the temp. table solution certainly matches your description. What's wrong with using a temporary table? -Aaron On Thu, Sep 11, 2008 at 3:05 PM, Aaron Mackey [EMAIL PROTECTED] wrote: I would load your set of userid's into a temporary table in oracle, then join that table with the rest of your SQL query to get only the matching rows out. -Aaron On Thu, Sep 11, 2008 at 2:33 PM, Avram Aelony [EMAIL PROTECTED] wrote: Dear R list, What is the best way to efficiently marry an R dataset with a very large (Oracle) database table? The goal is to only return Oracle table rows that match IDs present in the R dataset. I have an R data frame with 2000 user IDs analogous to: r = data.frame(userid=round(runif(2000)*10,0)) ...and I need to pull data from an Oracle table only for these 2000 IDs. The Oracle table is quite large. Additionally, the sql query may need to join to other tables to bring in ancillary fields. I currently connect to Oracle via odbc: library(RODBC) connection - odbcConnect(, uid=, pwd=) d = sqlQuery(connection, select userid, x, y, z from largetable where timestamp sysdate -7) ...allowing me to pull data from the database table into the R object d and then use the R merge function. The problem however is that if d is too large it may fail due to memory limitations or be inefficient. I would like to push the merge portion to the database and it would be very convenient if it were possible to request that the query look to the R object for the ID's to which it should restrict the output. Is there a way to do this? Something like the following fictional code: d = sqlQuery(connection, select t.userid, x, y, z from largetable t where r$userid=t.userid) Would sqldf (http://code.google.com/p/sqldf/) help me out here? If so, how? This would be convenient and help me avoid needing to create a temporary table to store the R data, join via sql, then return the data back to R. I am using R version 2.7.2 (2008-08-25) / i386-pc-mingw32 . Thanks for your comments, ideas, recommendations. -Avram __ 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] Truncating dates (and other date-time manipulations)
Look at the ti (Time Index) class in package tis. Here's some examples I just did: x - Sys.Date() x [1] 2008-09-11 ti(x, wsaturday) ## a ti for the week that x falls into [1] 20080913 class: ti ti(x + 1, wsaturday) - 1 ## ti for the latest complete week [1] 20080906 class: ti as.Date(ti(x + 1, wsaturday) - 1) ## as a Date [1] 2008-09-06 ymd(ti(x + 1, wsaturday) - 1) ## or just the mmdd number [1] 20080906 You can do the same for wsunday, if you want weeks that end on Sunday. In all, ti supports 7 different weekly frequencies, for weeks ending on Monday, Tuesday, ..., Sunday. It also has daily and business day frequencies, 14 biweekly frequencies, semimonthly, monthly, bimonthly, and three quarterly frequencies (for quarters that end in October, November and December). Similarly, there are 12 annual frequencies and 6 semiannual ones, and a biannual frequency. Also supported are hourly, minutely and secondly frequencies. Gabor and I have done some work towards making zoo and ti objects compatible with each other. hadley wickham [EMAIL PROTECTED] writes: I've been struggling to perform common operations on dates that I need to be able to correct draw date-time scales - in particular I need to be able to round/truncate/ceiling dates to arbitrary precision - e.g. to weeks, months or years (or multiples thereof). I haven't been able to find anything to do this in base R (trunc.Date only truncates to sub-day units), or in the date related contributed packages I've looked in (e.g. chron). Have I missed something? -- Jeff __ 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] Calculate mean/var by ID
A slight variation of what Jorge has proposed is: f - function(x) c( mu=mean(x), var=var(x) ) do.call( rbind, tapply( df$value, df$ID, f ) ) mu var 111 4.33 4.33 138 6.00 4.67 178 5.00 8.00 Regards, Adai Jorge Ivan Velez wrote: Dear Julia, Try also x=read.table(textConnection(IDvalue 111 5 111 6 111 2 178 7 178 3 138 3 138 8 138 7 138 6),header=TRUE) closeAllConnections() attach(x) do.call(rbind,tapply(value,ID, function(x){ res=c(mean(x,na.rm=TRUE),var(x,na.rm=TRUE)) names(res)=c('Mean','Variance') res } ) ) HTH, Jorge On Thu, Sep 11, 2008 at 1:45 PM, liujb [EMAIL PROTECTED] wrote: Hello, I have a data set that looks like this. IDvalue 111 5 111 6 111 2 178 7 178 3 138 3 138 8 138 7 138 6 . . . I'd like to calculate the mean and var for each object identified by the ID. I can in theory just loop through the whole thing..., but is there a easier way/command which let me calculate the mean/var by ID? Thanks, Julia -- View this message in context: http://www.nabble.com/Calculate-mean-var-by-ID-tp19440461p19440461.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-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] database table merging tips with R
I guess I'd do it something like this: dbGetQuery(con, CREATE TEMPORARY TABLE foo ( etc etc)) sapply(@userids, function (x) { dbGetQuery(con, paste(INSERT INTO foo (userid) VALUES (, x, ))) }) then later: dbGetQuery(con, DROP TABLE foo); -Aaron On Thu, Sep 11, 2008 at 3:21 PM, Avram Aelony [EMAIL PROTECTED] wrote: Perhaps I will need to create a temp table, but I am asking if there is a way to avoid it. It would be great if there were a way to tie the R data frame temporarily to the query in a transparent fashion. If not, I will see if I can create/drop the temp table directly from sqlQuery. -Avram On Thursday, September 11, 2008, at 12:07PM, Aaron Mackey [EMAIL PROTECTED] wrote: Sorry, I see now you want to avoid this, but you did ask what was the best way to efficiently ..., and the temp. table solution certainly matches your description. What's wrong with using a temporary table? -Aaron On Thu, Sep 11, 2008 at 3:05 PM, Aaron Mackey [EMAIL PROTECTED] wrote: I would load your set of userid's into a temporary table in oracle, then join that table with the rest of your SQL query to get only the matching rows out. -Aaron On Thu, Sep 11, 2008 at 2:33 PM, Avram Aelony [EMAIL PROTECTED] wrote: Dear R list, What is the best way to efficiently marry an R dataset with a very large (Oracle) database table? The goal is to only return Oracle table rows that match IDs present in the R dataset. I have an R data frame with 2000 user IDs analogous to: r = data.frame(userid=round(runif(2000)*10,0)) ...and I need to pull data from an Oracle table only for these 2000 IDs. The Oracle table is quite large. Additionally, the sql query may need to join to other tables to bring in ancillary fields. I currently connect to Oracle via odbc: library(RODBC) connection - odbcConnect(, uid=, pwd=) d = sqlQuery(connection, select userid, x, y, z from largetable where timestamp sysdate -7) ...allowing me to pull data from the database table into the R object d and then use the R merge function. The problem however is that if d is too large it may fail due to memory limitations or be inefficient. I would like to push the merge portion to the database and it would be very convenient if it were possible to request that the query look to the R object for the ID's to which it should restrict the output. Is there a way to do this? Something like the following fictional code: d = sqlQuery(connection, select t.userid, x, y, z from largetable t where r$userid=t.userid) Would sqldf (http://code.google.com/p/sqldf/) help me out here? If so, how? This would be convenient and help me avoid needing to create a temporary table to store the R data, join via sql, then return the data back to R. I am using R version 2.7.2 (2008-08-25) / i386-pc-mingw32 . Thanks for your comments, ideas, recommendations. -Avram __ 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] boxplot
Perhaps your data does not have whiskers? x - c(4,5,6,4,5,6,4,5,6,4,5,6) boxplot(x) # No whiskers boxplot(1:10) # whiskers --- On Thu, 9/11/08, Daniela Garavaglia [EMAIL PROTECTED] wrote: From: Daniela Garavaglia [EMAIL PROTECTED] Subject: [R] boxplot To: r-help@r-project.org Received: Thursday, September 11, 2008, 5:00 AM Sorry, I have some troubles with the graph device. How can I draw the whiskers in a boxplot? Thank's so much. Daniela __ 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] database table merging tips with R
Aaron Mackey writes: I guess I'd do it something like this: dbGetQuery(con, CREATE TEMPORARY TABLE foo ( etc etc)) sapply(@userids, function (x) { dbGetQuery(con, paste(INSERT INTO foo (userid) VALUES (, x, ))) }) then later: dbGetQuery(con, DROP TABLE foo); Actually, based on my reading of the DBI reference, you should be able to do the following to create a table (although possibly not temporary): dbWriteTable(connection, r_user_ids, r) Then you can use the following to drop the table: dbRemoveTable(connection, r_user_ids) Of course, I don't know whether the ODBC driver implements these functions or not. (Is 'RODBC' built on DBI? Looks like Aaron and I have been assuming that.) Coey -Aaron On Thu, Sep 11, 2008 at 3:21 PM, Avram Aelony [EMAIL PROTECTED] wrote: Perhaps I will need to create a temp table, but I am asking if there is a way to avoid it. It would be great if there were a way to tie the R data frame temporarily to the query in a transparent fashion. If not, I will see if I can create/drop the temp table directly from sqlQuery. -Avram On Thursday, September 11, 2008, at 12:07PM, Aaron Mackey [EMAIL PROTECTED] wrote: Sorry, I see now you want to avoid this, but you did ask what was the best way to efficiently ..., and the temp. table solution certainly matches your description. What's wrong with using a temporary table? -Aaron On Thu, Sep 11, 2008 at 3:05 PM, Aaron Mackey [EMAIL PROTECTED] wrote: I would load your set of userid's into a temporary table in oracle, then join that table with the rest of your SQL query to get only the matching rows out. -Aaron On Thu, Sep 11, 2008 at 2:33 PM, Avram Aelony [EMAIL PROTECTED] wrote: Dear R list, What is the best way to efficiently marry an R dataset with a very large (Oracle) database table? The goal is to only return Oracle table rows that match IDs present in the R dataset. I have an R data frame with 2000 user IDs analogous to: r = data.frame(userid=round(runif(2000)*10,0)) ...and I need to pull data from an Oracle table only for these 2000 IDs. The Oracle table is quite large. Additionally, the sql query may need to join to other tables to bring in ancillary fields. I currently connect to Oracle via odbc: library(RODBC) connection - odbcConnect(, uid=, pwd=) d = sqlQuery(connection, select userid, x, y, z from largetable where timestamp sysdate -7) ...allowing me to pull data from the database table into the R object d and then use the R merge function. The problem however is that if d is too large it may fail due to memory limitations or be inefficient. I would like to push the merge portion to the database and it would be very convenient if it were possible to request that the query look to the R object for the ID's to which it should restrict the output. Is there a way to do this? Something like the following fictional code: d = sqlQuery(connection, select t.userid, x, y, z from largetable t where r$userid=t.userid) Would sqldf (http://code.google.com/p/sqldf/) help me out here? If so, how? This would be convenient and help me avoid needing to create a temporary table to store the R data, join via sql, then return the data back to R. I am using R version 2.7.2 (2008-08-25) / i386-pc-mingw32 . Thanks for your comments, ideas, recommendations. -Avram __ 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-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] Plot qnorm
Dear Talina, On Thu, Sep 11, 2008 at 2:28 PM, Talina Ruiz [EMAIL PROTECTED] wrote: Hi, I have this problem: X is hazardous variable N(mean 2, sd=3) question 1) Find the c value, so that P(Xc)=0.10. using R question 2) Graph the function N(2,3) and with this graph, explain what you do in question number 1. I just found question number one but not the second one. So, I'd like to make a plot form this distribution N (2,3) using the functions plot and qnorm. I couldn't find how make it in R. Thanks for any hint. The notation that you have used is somewhat ambiguous, in that N(2,3) typically denotes the normal CDF (or sometimes the PDF), neither of which being the quantile function qnorm(). But as to your specific question, the IPSUR plugin for the R Commander will plot quantile functions. After installing Rcdmr and RcmdrPlugin.IPSUR (version = 0.1-5), do library(RcmdrPlugin.IPSUR) and after the Commander restarts take a look at the Distributions menu. You can plot any of the above. In addition, you will have code echoed to you for the console that you can use for other problems. Best wishes, Jay *** G. Jay Kerns, Ph.D. Associate Professor Department of Mathematics Statistics Youngstown State University Youngstown, OH 44555-0002 USA Office: 1035 Cushwa Hall Phone: (330) 941-3310 Office (voice mail) -3302 Department -3170 FAX E-mail: [EMAIL PROTECTED] http://www.cc.ysu.edu/~gjkerns/ __ 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] database table merging tips with R
While the subquery with a temporary table is probably the better option, you could just manually generate the subquery and pass it in with the query. As an example, if you have user_ids 1000-1005, instead of having ... where user_id in (select user_id from r_user_id), you would have ... where user_id in (1000,1001,1002,1003,1004,1005). With 2000 user_ids, you'd just have R generate the string, the whole query for that matter, and pass it in. Sure, it's a few thousand characters going into the database as a query, but it sure beats pulling down a few million characters that you're going to just throw away. I have no idea how the performance of the above method would compare to using a temporary table (on the database side, of course), but I have a hard time believing that it wouldn't be within a factor of two. But I'm just making the suggestion. Coey Avram Aelony writes: Dear R list, What is the best way to efficiently marry an R dataset with a very large (Oracle) database table? The goal is to only return Oracle table rows that match IDs present in the R dataset. I have an R data frame with 2000 user IDs analogous to: r = data.frame(userid=round(runif(2000)*10,0)) ...and I need to pull data from an Oracle table only for these 2000 IDs. The Oracle table is quite large. Additionally, the sql query may need to join to other tables to bring in ancillary fields. I currently connect to Oracle via odbc: library(RODBC) connection - odbcConnect(, uid=, pwd=) d = sqlQuery(connection, select userid, x, y, z from largetable where timestamp sysdate -7) ...allowing me to pull data from the database table into the R object d and then use the R merge function. The problem however is that if d is too large it may fail due to memory limitations or be inefficient. I would like to push the merge portion to the database and it would be very convenient if it were possible to request that the query look to the R object for the ID's to which it should restrict the output. Is there a way to do this? Something like the following fictional code: d = sqlQuery(connection, select t.userid, x, y, z from largetable t where r$userid=t.userid) Would sqldf (http://code.google.com/p/sqldf/) help me out here? If so, how? This would be convenient and help me avoid needing to create a temporary table to store the R data, join via sql, then return the data back to R. I am using R version 2.7.2 (2008-08-25) / i386-pc-mingw32 . Thanks for your comments, ideas, recommendations. -Avram __ 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] plot of all.effects object
All, I'm trying to plot an all.effects() object, as shown in the help for all.effects and also Crawley's R book (p.178, 2007). The data has a repeated measures structure, but I'm using all.effects for the simple lm() fit here. Below is a reproducible example that yields the error message. fm.ex = lm(dv ~ time.num*drug*X, data = dat.new) fm.effects = all.effects(fm.ex, xlevels = list(time.num = 1:4)) plot(fm.effects, time.num:Drug:X) Error in plot.window(...) : need finite 'xlim' values In addition: Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf 3: In min(x) : no non-missing arguments to min; returning Inf 4: In max(x) : no non-missing arguments to max; returning -Inf Cheers, David sessionInfo() R version 2.7.1 (2008-06-23) i386-apple-darwin8.10.1 locale: en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] grid stats graphics grDevices utils datasets methods base other attached packages: [1] effects_1.0-12 lattice_0.17-8 loaded via a namespace (and not attached): [1] Matrix_0.999375-11 lme4_0.999375-24 nlme_3.1-89tools_2.7. set.seed(500) n.timepoints - 4 n.subj.per.tx - 20 sd.d - 5; sd.p - 2; sd.res - 1.3 drug - factor(rep(c(D, P), each = n.timepoints, times = n.subj.per.tx)) drug.baseline - rep( c(0,5), each=n.timepoints, times=n.subj.per.tx ) Patient - rep(1:(n.subj.per.tx*2), each = n.timepoints) Patient.baseline - rep( rnorm( n.subj.per.tx*2, sd=c(sd.d, sd.p) ), each=n.timepoints ) time - factor(paste(Time-, rep(1:n.timepoints, n.subj.per.tx*2), sep=)) time.baseline - rep(1:n.timepoints,n.subj.per.tx*2)*as.numeric(drug==D) dv - rnorm( n.subj.per.tx*n.timepoints*2, mean=time.baseline+Patient.baseline+drug.baseline, sd=sd.res ) dat.new - data.frame(time, drug, dv, Patient) dat.new$time.num = rep(1:n.timepoints, n.subj.per.tx*2) dat.new$X - rnorm(160) ### to check plot of all.effects info __ 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] database table merging tips with R
I have not devoted time to setting up ROracle since binaries are not available and it seems to require some effort to compile (see http://cran.r-project.org/web/packages/ROracle/index.html). On the other hand, RODBC worked more or less magically once I set up the data sources. What is your success using ROracle and why would it be preferable to RODBC ? -Avram On Thursday, September 11, 2008, at 12:47PM, Coey Minear [EMAIL PROTECTED] wrote: Aaron Mackey writes: I guess I'd do it something like this: dbGetQuery(con, CREATE TEMPORARY TABLE foo ( etc etc)) sapply(@userids, function (x) { dbGetQuery(con, paste(INSERT INTO foo (userid) VALUES (, x, ))) }) then later: dbGetQuery(con, DROP TABLE foo); Actually, based on my reading of the DBI reference, you should be able to do the following to create a table (although possibly not temporary): dbWriteTable(connection, r_user_ids, r) Then you can use the following to drop the table: dbRemoveTable(connection, r_user_ids) Of course, I don't know whether the ODBC driver implements these functions or not. (Is 'RODBC' built on DBI? Looks like Aaron and I have been assuming that.) Coey -Aaron On Thu, Sep 11, 2008 at 3:21 PM, Avram Aelony [EMAIL PROTECTED] wrote: Perhaps I will need to create a temp table, but I am asking if there is a way to avoid it. It would be great if there were a way to tie the R data frame temporarily to the query in a transparent fashion. If not, I will see if I can create/drop the temp table directly from sqlQuery. -Avram On Thursday, September 11, 2008, at 12:07PM, Aaron Mackey [EMAIL PROTECTED] wrote: Sorry, I see now you want to avoid this, but you did ask what was the best way to efficiently ..., and the temp. table solution certainly matches your description. What's wrong with using a temporary table? -Aaron On Thu, Sep 11, 2008 at 3:05 PM, Aaron Mackey [EMAIL PROTECTED] wrote: I would load your set of userid's into a temporary table in oracle, then join that table with the rest of your SQL query to get only the matching rows out. -Aaron On Thu, Sep 11, 2008 at 2:33 PM, Avram Aelony [EMAIL PROTECTED] wrote: Dear R list, What is the best way to efficiently marry an R dataset with a very large (Oracle) database table? The goal is to only return Oracle table rows that match IDs present in the R dataset. I have an R data frame with 2000 user IDs analogous to: r = data.frame(userid=round(runif(2000)*10,0)) ...and I need to pull data from an Oracle table only for these 2000 IDs. The Oracle table is quite large. Additionally, the sql query may need to join to other tables to bring in ancillary fields. I currently connect to Oracle via odbc: library(RODBC) connection - odbcConnect(, uid=, pwd=) d = sqlQuery(connection, select userid, x, y, z from largetable where timestamp sysdate -7) ...allowing me to pull data from the database table into the R object d and then use the R merge function. The problem however is that if d is too large it may fail due to memory limitations or be inefficient. I would like to push the merge portion to the database and it would be very convenient if it were possible to request that the query look to the R object for the ID's to which it should restrict the output. Is there a way to do this? Something like the following fictional code: d = sqlQuery(connection, select t.userid, x, y, z from largetable t where r$userid=t.userid) Would sqldf (http://code.google.com/p/sqldf/) help me out here? If so, how? This would be convenient and help me avoid needing to create a temporary table to store the R data, join via sql, then return the data back to R. I am using R version 2.7.2 (2008-08-25) / i386-pc-mingw32 . Thanks for your comments, ideas, recommendations. -Avram __ 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-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] Difference in p-values between R and SPSS
That is a larger difference in p-values than I would expect due to numerical differences and stopping criteria. My guess is that you are running across the different approximations for tied failure times. If so, you will get better agreement with SPSS by using method=breslow in coxph(). -thomas On Thu, 11 Sep 2008, K?re Edvardsen wrote: My apologies for asking slightly about SPSS in addition to R... Could not find an exact answer in the archives on whether R and SPSS may give different p-vals when output for coeffs and conf-intervals are the same. Amyway, a colleague and I are doing a very simple coxreg analyses and get the same results for the coefficient and confidence interval, exp(coef) exp(-coef) lower .95 upper .95 age_at_entry 1.02 0.98 1.01 1.03 but in R we get p = 0.00011, and SPSS gives p 0.0001 Should we worry about this difference in p-value or do R and SPSS sometime differ? All the best, Kare __ 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. Thomas Lumley Assoc. Professor, Biostatistics [EMAIL PROTECTED] University of Washington, Seattle__ 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 load functions in R
On 12/09/2008, at 2:53 AM, [EMAIL PROTECTED] wrote: Hello, It seems that all methods work. Source() however loads only the last function. This is absolute nonsense. You are doing something wrong and/or not understanding what you are doing. This is bad practice. with save(a,b,file=path) i can save more than 1 function. No kidding! cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ 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] plot of all.effects object
Dear David, You have to spell the name of term correctly: plot(fm.effects, time.num:drug:X) (Admittedly, the error message is cryptic: I'll look into that.) A couple of other comments: (1) There is only one high-order term in your model, so it's not necessary to use all.effects(); (2) if you plot(fm.effects) (i.e., without specifying the term to plot) you'll be presented with a menu, in this instance with only one choice. I hope this helps, John On Thu, 11 Sep 2008 15:54:25 -0400 David Afshartous [EMAIL PROTECTED] wrote: All, I'm trying to plot an all.effects() object, as shown in the help for all.effects and also Crawley's R book (p.178, 2007). The data has a repeated measures structure, but I'm using all.effects for the simple lm() fit here. Below is a reproducible example that yields the error message. fm.ex = lm(dv ~ time.num*drug*X, data = dat.new) fm.effects = all.effects(fm.ex, xlevels = list(time.num = 1:4)) plot(fm.effects, time.num:Drug:X) Error in plot.window(...) : need finite 'xlim' values In addition: Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf 3: In min(x) : no non-missing arguments to min; returning Inf 4: In max(x) : no non-missing arguments to max; returning -Inf Cheers, David sessionInfo() R version 2.7.1 (2008-06-23) i386-apple-darwin8.10.1 locale: en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] grid stats graphics grDevices utils datasets methods base other attached packages: [1] effects_1.0-12 lattice_0.17-8 loaded via a namespace (and not attached): [1] Matrix_0.999375-11 lme4_0.999375-24 nlme_3.1-89 tools_2.7. set.seed(500) n.timepoints - 4 n.subj.per.tx - 20 sd.d - 5; sd.p - 2; sd.res - 1.3 drug - factor(rep(c(D, P), each = n.timepoints, times = n.subj.per.tx)) drug.baseline - rep( c(0,5), each=n.timepoints, times=n.subj.per.tx ) Patient - rep(1:(n.subj.per.tx*2), each = n.timepoints) Patient.baseline - rep( rnorm( n.subj.per.tx*2, sd=c(sd.d, sd.p) ), each=n.timepoints ) time - factor(paste(Time-, rep(1:n.timepoints, n.subj.per.tx*2), sep=)) time.baseline - rep(1:n.timepoints,n.subj.per.tx*2)*as.numeric(drug==D) dv - rnorm( n.subj.per.tx*n.timepoints*2, mean=time.baseline+Patient.baseline+drug.baseline, sd=sd.res ) dat.new - data.frame(time, drug, dv, Patient) dat.new$time.num = rep(1:n.timepoints, n.subj.per.tx*2) dat.new$X - rnorm(160) ### to check plot of all.effects info __ 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. John Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ __ 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] plot of all.effects object
Dear John, Thanks and sorry for the typo. For the example below, how do I get the time.num variable to correspond to the x-axis? I tried refitting the model with a different order of supplied variables but this didn't do it. Cheers, David On 9/11/08 4:28 PM, John Fox [EMAIL PROTECTED] wrote: Dear David, You have to spell the name of term correctly: plot(fm.effects, time.num:drug:X) (Admittedly, the error message is cryptic: I'll look into that.) A couple of other comments: (1) There is only one high-order term in your model, so it's not necessary to use all.effects(); (2) if you plot(fm.effects) (i.e., without specifying the term to plot) you'll be presented with a menu, in this instance with only one choice. I hope this helps, John On Thu, 11 Sep 2008 15:54:25 -0400 David Afshartous [EMAIL PROTECTED] wrote: All, I'm trying to plot an all.effects() object, as shown in the help for all.effects and also Crawley's R book (p.178, 2007). The data has a repeated measures structure, but I'm using all.effects for the simple lm() fit here. Below is a reproducible example that yields the error message. fm.ex = lm(dv ~ time.num*drug*X, data = dat.new) fm.effects = all.effects(fm.ex, xlevels = list(time.num = 1:4)) plot(fm.effects, time.num:Drug:X) Error in plot.window(...) : need finite 'xlim' values In addition: Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf 3: In min(x) : no non-missing arguments to min; returning Inf 4: In max(x) : no non-missing arguments to max; returning -Inf Cheers, David sessionInfo() R version 2.7.1 (2008-06-23) i386-apple-darwin8.10.1 locale: en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] grid stats graphics grDevices utils datasets methods base other attached packages: [1] effects_1.0-12 lattice_0.17-8 loaded via a namespace (and not attached): [1] Matrix_0.999375-11 lme4_0.999375-24 nlme_3.1-89 tools_2.7. set.seed(500) n.timepoints - 4 n.subj.per.tx - 20 sd.d - 5; sd.p - 2; sd.res - 1.3 drug - factor(rep(c(D, P), each = n.timepoints, times = n.subj.per.tx)) drug.baseline - rep( c(0,5), each=n.timepoints, times=n.subj.per.tx ) Patient - rep(1:(n.subj.per.tx*2), each = n.timepoints) Patient.baseline - rep( rnorm( n.subj.per.tx*2, sd=c(sd.d, sd.p) ), each=n.timepoints ) time - factor(paste(Time-, rep(1:n.timepoints, n.subj.per.tx*2), sep=)) time.baseline - rep(1:n.timepoints,n.subj.per.tx*2)*as.numeric(drug==D) dv - rnorm( n.subj.per.tx*n.timepoints*2, mean=time.baseline+Patient.baseline+drug.baseline, sd=sd.res ) dat.new - data.frame(time, drug, dv, Patient) dat.new$time.num = rep(1:n.timepoints, n.subj.per.tx*2) dat.new$X - rnorm(160) ### to check plot of all.effects info __ 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. John Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ __ 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] database table merging tips with R
Avram Aelony writes: I have not devoted time to setting up ROracle since binaries are not available and it seems to require some effort to compile (see http://cran.r-project.org/web/packages/ROracle/index.html). On the other hand, RODBC worked more or less magically once I set up the data sources. What is your success using ROracle and why would it be preferable to RODBC ? -Avram Actually, I've only been using RSQLite, so that's where my (limited) knowledge is coming from (and only for less than a week). RSQLite based on DBI, and noticed that Aaron and I were answering with DBI functions. I then noticed that you kept referring to sqlQuery. That's why I raised the issue of whether RODBC is based on DBI or not. If RODBC is not based on DBI, then obviously you cannot leverage the use of dbWriteTable and dbRemoveTable, as they may not be present. If RODBC offers something similar, you'll have to find out, but that may have driven your initial desire to avoid the temporary table option. Regardless of that, I don't see why you could not consider the pre-built subquery option, unless you find that ODBC, or RODBC, has a limit on what can be sent to the database. Coey On Thursday, September 11, 2008, at 12:47PM, Coey Minear [EMAIL PROTECTED] wrote: Aaron Mackey writes: I guess I'd do it something like this: dbGetQuery(con, CREATE TEMPORARY TABLE foo ( etc etc)) sapply(@userids, function (x) { dbGetQuery(con, paste(INSERT INTO foo (userid) VALUES (, x, ))) }) then later: dbGetQuery(con, DROP TABLE foo); Actually, based on my reading of the DBI reference, you should be able to do the following to create a table (although possibly not temporary): dbWriteTable(connection, r_user_ids, r) Then you can use the following to drop the table: dbRemoveTable(connection, r_user_ids) Of course, I don't know whether the ODBC driver implements these functions or not. (Is 'RODBC' built on DBI? Looks like Aaron and I have been assuming that.) Coey -Aaron On Thu, Sep 11, 2008 at 3:21 PM, Avram Aelony [EMAIL PROTECTED] wrote: Perhaps I will need to create a temp table, but I am asking if there is a way to avoid it. It would be great if there were a way to tie the R data frame temporarily to the query in a transparent fashion. If not, I will see if I can create/drop the temp table directly from sqlQuery. -Avram On Thursday, September 11, 2008, at 12:07PM, Aaron Mackey [EMAIL PROTECTED] wrote: Sorry, I see now you want to avoid this, but you did ask what was the best way to efficiently ..., and the temp. table solution certainly matches your description. What's wrong with using a temporary table? -Aaron On Thu, Sep 11, 2008 at 3:05 PM, Aaron Mackey [EMAIL PROTECTED] wrote: I would load your set of userid's into a temporary table in oracle, then join that table with the rest of your SQL query to get only the matching rows out. -Aaron On Thu, Sep 11, 2008 at 2:33 PM, Avram Aelony [EMAIL PROTECTED] wrote: Dear R list, What is the best way to efficiently marry an R dataset with a very large (Oracle) database table? The goal is to only return Oracle table rows that match IDs present in the R dataset. I have an R data frame with 2000 user IDs analogous to: r = data.frame(userid=round(runif(2000)*10,0)) ...and I need to pull data from an Oracle table only for these 2000 IDs. The Oracle table is quite large. Additionally, the sql query may need to join to other tables to bring in ancillary fields. I currently connect to Oracle via odbc: library(RODBC) connection - odbcConnect(, uid=, pwd=) d = sqlQuery(connection, select userid, x, y, z from largetable where timestamp sysdate -7) ...allowing me to pull data from the database table into the R object d and then use the R merge function. The problem however is that if d is too large it may fail due to memory limitations or be inefficient. I would like to push the merge portion to the database and it would be very convenient if it were possible to request that the query look to the R object for the ID's to which it should restrict the output. Is there a way to do this? Something like the following fictional code: d = sqlQuery(connection, select t.userid, x, y, z from largetable t where r$userid=t.userid) Would sqldf (http://code.google.com/p/sqldf/) help me out here? If so, how? This would be convenient and help me avoid needing to create a temporary table to store the R data, join via sql, then return the data back to R. I am using R version 2.7.2 (2008-08-25) /