Re: [R] 2 x 3 Probability under the null
On 27-Oct-11 04:09:46, Jim Silverton wrote: I have a 2 x 3 matrix called snp and I want to compute the following probability: choose(sum(snp[,1]), snp[1,1]) * choose(sum(snp[,2]), snp[1,2]) * choose(sum(snp[,3]), snp[1,3])/choose(sum(snp), sum(snp[1,])) but I keep getting Infs and NaNs. Is there a function that can do this in R? -- Thanks, Jim. Since 1/0 -- Inf, and 0/0 -- NaN, it seems likely that your data lead to zero denominators. However, true diagnosis needs to see what your data really are. What is a typical 2x3 matrix that gives such results? If this guess is correct, then no possible function in R can resolve the problem! For data where the problem does not arise, then you can of course write your own function to implement your code above for an arbitrary 2x3 matrix. Hoping this helps, Ted. E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 27-Oct-11 Time: 07:32:30 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] AlgDesign how to find back the 2^(7-4) plan
Dear all, i try to anderstand the AlgDesign package, so i make some tests to find with optFederoy some plan I know. I would like to find back a simple optimal design : 7 factors with 2 attributes each ( the beter plan is 2^(7-4) and needs 8 rows) library(AlgDesign) levels.design = c(2,2,2,2,2,2,2) f.design - gen.factorial(levels.design) # i know that optFederov(data=f.design,nTrials=8) # is the better # but optFederov(data=f.design) # 13 rows! optFederov(data=f.design,maxIteration=1000,nRepeats=500) # 13 rows! optFederov(data=f.design,maxIteration=1000,nRepeats=500,criterion=D) optFederov(data=f.design,maxIteration=1000,nRepeats=500,criterion=A) optFederov(data=f.design,maxIteration=1000,nRepeats=500,criterion=I) optFederov always find a 13 rows results.. how can i obtain the 8 row design ( if i dont know that the better is 8) ? 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.
[R] Fitting Maximums of data series with cubic spline
Hi Users, I want to fit the maximums of a data series with a cubic spline. How do I go about this in R. I failed to figure out how I can use the mgcv library to do this. Thanks ZABLONE __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] 2 x 3 Probability under the null
On 11-10-27 12:09 AM, Jim Silverton wrote: I have a 2 x 3 matrix called snp and I want to compute the following probability: choose(sum(snp[,1]), snp[1,1]) * choose(sum(snp[,2]), snp[1,2]) * choose(sum(snp[,3]), snp[1,3])/choose(sum(snp), sum(snp[1,])) but I keep getting Infs and NaNs. Is there a function that can do this in R? Work in the log scale. You're probably getting overflows. lchoose() calculates the log of choose(). Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] FOR loop with statistical analysis for microarray data
y1,y2 were designed as follow,from the original data file : y1=data[,1:2] y2=data[,3:4] ...I am a bit confused with what redesign the whole vector again and specify indices twice actually mean?...could u point it out in the script? Thanks so much I really appreciate it!! Sent from my -DROID- On Oct 26, 2011 6:56 PM, Weidong Gu wrote: If you provide an example data (y1 and y2 in the loop), you might have got specific helps already. A few things in your loop seem suspicious. fc and pv are vectors, and in each loop you redesigned the whole vectors and specific indices twice. That may cause your problems. Weidong Gu On Wed, Oct 26, 2011 at 4:56 PM, Seb seba@gmail.com wrote: hi all i started recently using R and i found myself stuck when i try to analyze microarray data. i use the affy package to obtain the intensities of the probes, i have two CTRs and two treated. HG.U133A.Experiment1.CEL HG.U133A.Experiment2.CEL HG.U133A_Control1.CEL HG.U133A_Control2.CEL 1007_s_at 2156.23115467.75615 364.60615 362.11865 1053_at 88.76368 93.58436 438.49365 357.75615 117_at 144.00743101.26120 95.7 107.01623 121_at 551.36865639.45615 456.66865 435.95615 1255_g_at 65.33164 18.39570 14.22565 20.74632 1294_at 106.19083169.69369 78.15722 81.14689 i divided the first two columns in two data.frames to divide Experim and CTRs then, i created a FOR loop to create a vector per each row containing a vector with two values per each gene and i wanted to do a Wilcox.test to obtain the significant genes..BUT i get a list of NULL like you can see here ..the first row works but then i get NULL down till the end of the array... fcpv [1,] 1007_s_at -20.248 0.4664612 [2,] 1053_at -344.7132 NULL [3,] 117_atNULL NULL [4,] 121_atNULL NULL [5,] 1255_g_at NULL NULL [6,] 1294_at NULL NULL the script i used is: === fc=0 pv=0 for (i in 1:nrow(data)) { v1= c(y1[i,1], y1[i,2]) v2= c(y2[i,1], y2[1,2]) fc=v1-v2 w=t.test(v1,v2) pv=w$p.value fc[i]= w[1] pv[i]= w[2] } results = cbind(row.names(y1), fc, pv) head(results) what did i do wrong? i can't find a way around this!!! thanks so much!!! Seb __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] SpatialLines
Mark Newcomb newc1.mac at me.com writes: I'm hoping to use R for spatial analysis. In working through examples in Chapt. 4 of Applied Spatial Data Analysis with R I've come across the following error in trying to plot lines with the meuse data set. The text is verbatim from the book. This is in Chapter 3, and is mentioned in the errata on the book website, http://www.asdar-book.org. The code download is also updated on the website. The erratum is: Chapter 3 Page 59: Top of page - from sp version 0.9-66, Lines objects must be give a valid ID; changed to m.sl - SpatialLines(list(Lines(list(Line(cc)), 1))). Lines and Polygons objects must have valid IDs. As mentioned in another reply, the R-sig-geo list may be more relevant for a question of this kind. Hope this clarifies, Roger m.sl - SpatialLines(list(Lines(list(Line(cc) Error in Lines(list(Line(cc))) : Single ID required What does Single ID required mean? Thanks. Mark __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using functions written in Fortran in R
On 10/27/2011 04:24 AM, John Sorkin wrote: Windows XP R 2.12 I am trying to understand how I can take a subroutine (i.e. function) I have written in Fortran, and call the function in R. I need to know (1) where I should store the Fortran subroutine (2) how to prepare the function for use in R, and (3) how to load and call the function. There's a large literature that describes how to construct packages (including S Programming by Venables and Ripley, which I have referenced), but everything I have seen appears overly complex and generally geared to R running under Linux where as I run R under Windows XP. Hi, I'm afraid that to some degree running Fortran code from R is complex. Take a look at the .Fortran functions. Another good tip is to take a look at an R package which includes a lot of Fortran and see how they organise their code. Linux is much more ready for these kinds of solutions, but probably you could get it to work under Windows. You need a compiler, set all kinds of enviroment variables etc. Running R under cygwin should make it possible to use the tutorials/books that are geared towards Linux, for Windows. good luck, Paul I want to put R functions and Fortran routines in a library so they can be easily accessed. If, for example, I write a subroutine in Fortran called sqrtvector (n, vector), I want to compile it (to a .dll ?) and then put it in a library so subsequently I can code y = sqrtvector(nn, x) in my R programs. Thanks! John John David Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) Confidentiality Statement: This email message, including any attachments, is for ...{{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] Using functions written in Fortran in R
On 11-10-27 8:02 AM, Paul Hiemstra wrote: On 10/27/2011 04:24 AM, John Sorkin wrote: Windows XP R 2.12 I am trying to understand how I can take a subroutine (i.e. function) I have written in Fortran, and call the function in R. I need to know (1) where I should store the Fortran subroutine (2) how to prepare the function for use in R, and (3) how to load and call the function. There's a large literature that describes how to construct packages (including S Programming by Venables and Ripley, which I have referenced), but everything I have seen appears overly complex and generally geared to R running under Linux where as I run R under Windows XP. Hi, I'm afraid that to some degree running Fortran code from R is complex. Take a look at the .Fortran functions. Another good tip is to take a look at an R package which includes a lot of Fortran and see how they organise their code. Linux is much more ready for these kinds of solutions, but probably you could get it to work under Windows. You need a compiler, set all kinds of enviroment variables etc. Running R under cygwin should make it possible to use the tutorials/books that are geared towards Linux, for Windows. I think nowadays many Linux distros are no more ready than Windows for this. On Linux, you'll likely need to install development libraries and tools; on Windows, the same. The advantage of Windows is that the tools have all been collected in one place (www.murdoch-sutherland.com/Rtools), so it's pretty easy to get everything going. Duncan Murdoch good luck, Paul I want to put R functions and Fortran routines in a library so they can be easily accessed. If, for example, I write a subroutine in Fortran called sqrtvector (n, vector), I want to compile it (to a .dll ?) and then put it in a library so subsequently I can code y= sqrtvector(nn, x) in my R programs. Thanks! John John David Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) Confidentiality Statement: This email message, including any attachments, is for ...{{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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Using functions written in Fortran in R
On 10/27/2011 12:13 PM, Duncan Murdoch wrote: On 11-10-27 8:02 AM, Paul Hiemstra wrote: On 10/27/2011 04:24 AM, John Sorkin wrote: Windows XP R 2.12 I am trying to understand how I can take a subroutine (i.e. function) I have written in Fortran, and call the function in R. I need to know (1) where I should store the Fortran subroutine (2) how to prepare the function for use in R, and (3) how to load and call the function. There's a large literature that describes how to construct packages (including S Programming by Venables and Ripley, which I have referenced), but everything I have seen appears overly complex and generally geared to R running under Linux where as I run R under Windows XP. Hi, I'm afraid that to some degree running Fortran code from R is complex. Take a look at the .Fortran functions. Another good tip is to take a look at an R package which includes a lot of Fortran and see how they organise their code. Linux is much more ready for these kinds of solutions, but probably you could get it to work under Windows. You need a compiler, set all kinds of enviroment variables etc. Running R under cygwin should make it possible to use the tutorials/books that are geared towards Linux, for Windows. I think nowadays many Linux distros are no more ready than Windows for this. On Linux, you'll likely need to install development libraries and tools; on Windows, the same. The advantage of Windows is that the tools have all been collected in one place (www.murdoch-sutherland.com/Rtools), so it's pretty easy to get everything going. You are right. This might be my Linux heart and predjudice towards Windows speaking too loudly :)...altough I was really happy switching from Windows XP to Debian Linux during my PhD (couldn't resist promoting linux ;)). Paul Duncan Murdoch good luck, Paul I want to put R functions and Fortran routines in a library so they can be easily accessed. If, for example, I write a subroutine in Fortran called sqrtvector (n, vector), I want to compile it (to a .dll ?) and then put it in a library so subsequently I can code y= sqrtvector(nn, x) in my R programs. Thanks! John John David Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) Confidentiality Statement: This email message, including any attachments, is for ...{{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. -- Paul Hiemstra, Ph.D. Global Climate Division Royal Netherlands Meteorological Institute (KNMI) Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39 P.O. Box 201 | 3730 AE | De Bilt tel: +31 30 2206 494 http://intamap.geo.uu.nl/~paul http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Fitting Maximums of data series with cubic spline
On 10/27/2011 10:46 AM, Zablone Owiti wrote: Hi Users, I want to fit the maximums of a data series with a cubic spline. How do I go about this in R. I failed to figure out how I can use the mgcv library to do this. Thanks ZABLONE __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Hi Zablone, As a first remark, to get meaningful responses: PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. For calculating the maximum, use the max() function. For fitting splines take a look at the splines package. good luck, Paul -- Paul Hiemstra, Ph.D. Global Climate Division Royal Netherlands Meteorological Institute (KNMI) Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39 P.O. Box 201 | 3730 AE | De Bilt tel: +31 30 2206 494 http://intamap.geo.uu.nl/~paul http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Consistant test for NAs in a factor when exclude = NULL?
On Oct 27, 2011, at 12:21 AM, andrewH wrote: Thanks Jeff! I appreciate you sharing your experience. My data set is survey data, 13,209 records over nine years, collected by someone else, converted from SPSS format. It includes missing values, identified however SPSS does so, and translated to NAs by the import process. It also includes values along the lines of none of your business or beats me that are missing so far as I am concerned. I have assigned NAs to these values. Now I am trying to figure out some things about where these missing values are -- whether they are disproportionately located in any period or group. I have been trying to get counts for subsets, but I have not been able to make the subset counts add up to the total counts that I get from, e.g. summary. So I wrote these simplified versions, and even for the simplest examples, I could not find a function that correctly identified the NAs that I knew were there because I put them there myself. That is why I am looking for help. Does this make sense? You might consider looking at the Hmisc package. I think it provides facilities for multiple missing attributes imported from SAS datasets. The help page to consult is sas.get {Hmisc}, I see no indication that a direct spss read facility was contmeplated, so it may take some extra work to get use out of this application of R attributes to store type-of-missingness-information in sequence with R NA's. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Problem Installing a local package in linux
Dear all, I am still fairly new to R and newer still to linux (opensuse). I want to install a package called FEAR from http://www.clemson.edu/economics/faculty/wilson/Software/FEAR/fear-download.html;. So, I downloaded the tar.gz file called FEAR-linux-64bit-2.6.16.60-0.21-smp.tar.gz and it is in the directory /home/sambit/Downloads right now. Then I invoked R from terminal and keyed in install.packages(/home/sambit/Downloads/FEAR-linux-64bit-2.6.16.60-0.21-smp.tar.gz, repos=NULL) Installing package(s) into ‘/home/sambit/R/x86_64-unknown-linux-gnu-library/2.13’ (as ‘lib’ is unspecified) * installing *binary* package ‘FEAR’ ... * DONE (FEAR) So, I think that the installation was successful. But when I load the package, library(FEAR) Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared object '/home/sambit/R/x86_64-unknown-linux-gnu-library/2.13/FEAR/libs/FEAR.so': libgfortran.so.1: cannot open shared object file: No such file or directory Error: package/namespace load failed for 'FEAR' I do not know what to do right now. I would really appreciate it someone could point out the next step. Thanks in advance. Sambit __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] FOR loop with statistical analysis for microarray data
In your loop, you assign, for example, pv twice pv=w$p.value # pv is scalar pv[i]= w[2] # pv is a vector give an example for the point pv=1 pv[5]=2 pv [1] 1 NA NA NA 2 This may not be what you want. Weidong On Thu, Oct 27, 2011 at 7:40 AM, Seb seba@gmail.com wrote: y1,y2 were designed as follow,from the original data file : y1=data[,1:2] y2=data[,3:4] ...I am a bit confused with what redesign the whole vector again and specify indices twice actually mean?...could u point it out in the script? Thanks so much I really appreciate it!! Sent from my -DROID- On Oct 26, 2011 6:56 PM, Weidong Gu wrote: If you provide an example data (y1 and y2 in the loop), you might have got specific helps already. A few things in your loop seem suspicious. fc and pv are vectors, and in each loop you redesigned the whole vectors and specific indices twice. That may cause your problems. Weidong Gu On Wed, Oct 26, 2011 at 4:56 PM, Seb seba@gmail.com wrote: hi all i started recently using R and i found myself stuck when i try to analyze microarray data. i use the affy package to obtain the intensities of the probes, i have two CTRs and two treated. HG.U133A.Experiment1.CEL HG.U133A.Experiment2.CEL HG.U133A_Control1.CEL HG.U133A_Control2.CEL 1007_s_at 2156.23115 467.75615 364.60615 362.11865 1053_at 88.76368 93.58436 438.49365 357.75615 117_at 144.00743 101.26120 95.7 107.01623 121_at 551.36865 639.45615 456.66865 435.95615 1255_g_at 65.33164 18.39570 14.22565 20.74632 1294_at 106.19083 169.69369 78.15722 81.14689 i divided the first two columns in two data.frames to divide Experim and CTRs then, i created a FOR loop to create a vector per each row containing a vector with two values per each gene and i wanted to do a Wilcox.test to obtain the significant genes..BUT i get a list of NULL like you can see here ..the first row works but then i get NULL down till the end of the array... fc pv [1,] 1007_s_at -20.248 0.4664612 [2,] 1053_at -344.7132 NULL [3,] 117_at NULL NULL [4,] 121_at NULL NULL [5,] 1255_g_at NULL NULL [6,] 1294_at NULL NULL the script i used is: === fc=0 pv=0 for (i in 1:nrow(data)) { v1= c(y1[i,1], y1[i,2]) v2= c(y2[i,1], y2[1,2]) fc=v1-v2 w=t.test(v1,v2) pv=w$p.value fc[i]= w[1] pv[i]= w[2] } results = cbind(row.names(y1), fc, pv) head(results) what did i do wrong? i can't find a way around this!!! thanks so much!!! Seb __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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.
[R] question R regarding consecutive numbers
Hi everyone Do you know about any possibility in R to check for consecutive numbers in vectors? That is, I do not only want to count the number of observations in total (which can be done table(x)), but I also want to count for instance how many times that vector contains a certain number consecutively. For example in the following vector x the number 1 appears 7 times. However, I want to check for instance how many times two consecutive 1's appear in the vector, which would actually be two times the case in the below vector. x=c(1,1,3,4,9,1,9,1,5,4,5,2,1,1,1,6) Any ideas for this issue? Thanks, S.B. [[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] Interesting Memory Management Problem (Windows)
Hi, I am try to fit an eGARCH model on an expanding basis using the rugarch package. I have 6 columns of data, and I am trying refit parameters ~6000 for each column. If I run the following code, I get an error in windows on the 2nd column (this means I am getting all the way through the first inner loop succesfully). By using gc() within the loop and removing the fitted object I have extended the length of time it takes to hit the memory error. Also, this process takes a very long time in general and I am wondering if there is anyway to improve it on my end. The package itself seems to be written very efficiently with most of the filtering being done in low level C. I could probably refit the model every 30-60 days, but I would really prefer to do it this way. I am running R 2.13.2 on 32-Bit windows. Thanks in advance. Edit: The error is: The instruction at 0x6c732a07 referenced memory at 0x0008. The memory could not be read. After searching through the forums (and also posting on Stack Overflow, so sorry if you are reading this twice) I also tried using memory.limit(size = 3092), which did not solve the problem. The surprising thing about this is that my objects are not very big, I never would have expected to have so many memory errors. library(rugarch) library(xts) e.spec - ugarchspec(variance.model = list(model = eGARCH, garchOrder = c(1,1)), mean.model = list(armaOrder = c(1,0), include.mean = TRUE)) dly.xts - xts(matrix(rnorm(8000*6), nrow = 8000, ncol = 6), as.Date(1:8000)) tst.xts - tail(dly.xts, 6000) names(tst.xts) - 1:6 tst.idx - index(tst.xts) dly.idx - index(dly.xts) for(j in 1:ncol(tst.xts)){ sig.est - rep(NA, nrow(tst.xts)) for(i in 1:nrow(tst.xts)){ print(i) dat - dly.xts[dly.idx = tst.idx[i], j] fit - try(ugarchfit(e.spec, data = dat[-nrow(dat), ], solver = solnp, solver.control = list(trace = FALSE))) if(class(fit) != try-error){ spec.new - ugarchspec(variance.model = list(model = eGARCH, garchOrder = c(1,1)), mean.model = list(armaOrder = c(1,0), include.mean = TRUE), fixed.pars = coef(fit)) sig.est[i] - as.numeric(tail(sigma(ugarchfilter(spec = spec.new, data = dat)),1)) rm(spec.new) rm(fit) gc() }else{ sig.est[i] - NA } } save(sig.est, file = paste(egarch, names(tst.xts)[j], .RData, sep = )) } -- View this message in context: http://r.789695.n4.nabble.com/Interesting-Memory-Management-Problem-Windows-tp3944243p3944243.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] help with paste
Hi Joshua, Thanks for the suggestion. Sharad -- View this message in context: http://r.789695.n4.nabble.com/help-with-paste-tp3942818p3943753.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] Error installing packages
Hello, I got an error if I try to install a package. For example package emg: R CMD check emg Everything is fine. R CMD INSTALL emg I got the following errors: * installing to library 'c:/R_2_13_1/library' * installing *source* package 'emg' ... Error in file_path_as_absolute(dfile) : Datei './DESCRIPTION' existiert nicht ERROR: installing package DESCRIPTION failed fo * removing 'c:/R_2_13_1/library/emg' * restoring previous 'c:/R_2_13_1/library/emg' It says, file DESCRIPTION is missing, despite it exists. The same behavoir with other packages. I would be very pleased if someone can help me with that problem. cheers, Joerg -- View this message in context: http://r.789695.n4.nabble.com/Error-installing-packages-tp3943807p3943807.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] help with parallel processing code
Hello R gurus, I have the code below for which i need help and pointers to make it run in parallel on a dual core win7 computer with R 2.13.x, using foreach, iterators,doMC. library(scatterplot3d) # Loads 3D library. library(fields) library(MASS) library(ROCR) library(verification) library(caret) library(gregmisc) ##simulated data d=replicate(9, rnorm(40)+10) colnames(d)-c(LEPTIN,SAA,PTH,sEGFR,IGFBP6,MMP2,OPG,IGFBP3,PDGFAABB) mols=c(LEPTIN,SAA,PTH,sEGFR,IGFBP6,MMP2,OPG,IGFBP3,PDGFAABB) Name of the results output file1=AUCvalues_3plex.csv temp1=c('protein comb', 'AUC') pdf('ROC Charts-3plex.pdf') #generate combinations pc3 = combinations(n=length(mols),r=3) #runing the combinations for (len in 1:dim(pc3)[1]) { prs = pc3[len,] ## new data mat samples - mols[prs] mat -data [,c(samples,'Self_T1D')] mat-mat[complete.cases(mat),] # LDA # rows- c(1:nrow(mat)) scores - c() labels -c() for (itr in 1:1000) { train - sample(rows, length(rows)-1) label =0 ; if (mat$Self_T1D[-train] == N) label = 1 #need the value for this line, should it be 'N' or 'Y' z - lda(Self_T1D ~ ., mat, subset = train) score = predict(z, mat[-train, ])$pos[1] scores - c(scores, score) labels- c(labels, label) } ## ROC # pred - prediction(scores, labels) perf - performance(pred,tpr, fpr) plot(perf,colorize = F) # plot a ROC curve for a single prediction run # with CI by bootstrapping and fitted curve #roc.plot(labels,scores, xlab = False positive rate, #ylab = True positive rate, main = NULL, CI = T, n.boot = 100, plot = both, binormal = TRUE) auc - as.numeric(performance(pred, measure = auc, x.measure = cutoff)@y.values) auc = round(auc,3) text(.9,0,paste( AUC=, auc, sep= ), cex=1) names1 = paste (samples, collapse=+) text(.8,.05,names1, cex=0.75) temp = c(names1, auc) temp1 = rbind(temp1 , temp) print(paste(3,' ','done len=',len, ,names1,' ',date(),sep='')) } dev.off() write.csv(temp1 , file=file1) Thanks sharad -- View this message in context: http://r.789695.n4.nabble.com/help-with-parallel-processing-code-tp3944303p3944303.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] show.ci='FALSE' ignored in simple.lm
Hi, I am using PostgreSQL 9.1 and want to run loglinear_simple-simple.lm(x$p_overPnot,x$logQuantity,show.ci =FALSE,conf.level=confidenceLevel) without showing the graph, however the show.ci=FALSE is ignored. Thank you [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Correllogram of Daily Time Series
Hi there, What is the best way to get a time series of daily stock price observations into R (from excel). The time series are daily but there are spaces for w/e's and holidays etc. So I am not sure a ts object will be suitable but I am not sure what I should use? What ever package you recemmned i need to be able to run a corrolelagram. Thanks Hugh -- View this message in context: http://r.789695.n4.nabble.com/Correllogram-of-Daily-Time-Series-tp3944094p3944094.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] question R regarding consecutive numbers
On 27/10/2011 8:43 AM, Samir Benzerfa wrote: Hi everyone Do you know about any possibility in R to check for consecutive numbers in vectors? That is, I do not only want to count the number of observations in total (which can be done table(x)), but I also want to count for instance how many times that vector contains a certain number consecutively. For example in the following vector x the number 1 appears 7 times. However, I want to check for instance how many times two consecutive 1's appear in the vector, which would actually be two times the case in the below vector. x=c(1,1,3,4,9,1,9,1,5,4,5,2,1,1,1,6) Any ideas for this issue? How about this? runs - rle(x) with(runs, table(values, lengths)) lengths values 1 2 3 1 2 1 1 2 1 0 0 3 1 0 0 4 2 0 0 5 2 0 0 6 1 0 0 9 2 0 0 Duncan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem Installing a local package in linux
Hi, Yea Linux! I think you are missing a library file (libgfortran.so.1), you can use locate to try and find the so file, in bash type: locate libgfortran Now three things can happen: - It doesn't find anything, than you need to install an additional gfortran package. This is often called libgfortran-dev or something (at least it is called this way in debian and ubuntu). This installs development files, including libgfortran.so - It finds a file called libgfotran.so.something but not .so.1. So you have the file, but it is not named correctly. Easiest solution is to create a symbolic link called libgfortran.so.1 to libgfortran.so.something and loading the library in R - It finds the correct file. Could be that the file is not in your PATH. Add the location of the file (the directy that is) to your path. cheers, Paul On 10/27/2011 12:56 PM, sambit rath wrote: Dear all, I am still fairly new to R and newer still to linux (opensuse). I want to install a package called FEAR from http://www.clemson.edu/economics/faculty/wilson/Software/FEAR/fear-download.html;. So, I downloaded the tar.gz file called FEAR-linux-64bit-2.6.16.60-0.21-smp.tar.gz and it is in the directory /home/sambit/Downloads right now. Then I invoked R from terminal and keyed in install.packages(/home/sambit/Downloads/FEAR-linux-64bit-2.6.16.60-0.21-smp.tar.gz, repos=NULL) Installing package(s) into ‘/home/sambit/R/x86_64-unknown-linux-gnu-library/2.13’ (as ‘lib’ is unspecified) * installing *binary* package ‘FEAR’ ... * DONE (FEAR) So, I think that the installation was successful. But when I load the package, library(FEAR) Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared object '/home/sambit/R/x86_64-unknown-linux-gnu-library/2.13/FEAR/libs/FEAR.so': libgfortran.so.1: cannot open shared object file: No such file or directory Error: package/namespace load failed for 'FEAR' I do not know what to do right now. I would really appreciate it someone could point out the next step. Thanks in advance. Sambit __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Paul Hiemstra, Ph.D. Global Climate Division Royal Netherlands Meteorological Institute (KNMI) Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39 P.O. Box 201 | 3730 AE | De Bilt tel: +31 30 2206 494 http://intamap.geo.uu.nl/~paul http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] minimizing device-dependent code in graphics scripts
Here is a common scenario that I and probably others often face: - I write a script, test.R, to produce some graphs, viewing them on-screen and tinkering until they look right - I want to save image files (e.g., .png), so I wrap each plot in device driver calls, e.g., png(file='test01.png', width=600, height=600); plot(1:10) dev.off() png(file='test02.png', width=600, height=600); plot(10:1) dev.off() ... - Then I want to include those graphs in a document, so maybe I want them in .pdf or .eps format. So I have to modify all the device calls to pdf() or postscript(), changing the filenames and perhaps other options. If I want those graphs to be squentially numbered with filenames like 'test%02d' and insert a new graph in the sequence, I have to edit all the filenames after the insertion. There has to be an easier way. (I know I could use Sweave, but that introduces another layer that I want to avoid while I'm developing plots.) This contrasts strongly with what I've done for many years with SAS: I use *no* device-dependent code in .sas files, but instead use a collection of device-independent macros that respond to a global macro variable, DEVTYP. On linux, a custom (perl) script sets this as an environment variable used by these macros, so I can run test.sas at the command line via % alias s=mysas % s -b -d eps test % s -d pdf test % s -v -d png test and get test1.eps, test2.eps, ... etc. where the basename of the image files is automatically set to something like 'test%01d'. The -v option opens each of the generated graphics files in an appropriate viewer (gs, display, xpdf, etc.) The -b option for .eps files runs a bbfix script to adjust bounding boxes on .eps files. I don't need anything this elaborate for R, but it's a long way from what I do with SAS vs what I do currently with R. Perhaps other have some partial solutions for this general problem they'd be willing to share. For what it's worth, here is an initial sketch of one approach, using two general functions, img() and img.off(). Perhaps others could help improve it. img.R ### # shorthand for eps() eps - function(file=Rplot.eps, horizontal=FALSE, paper=special, height=6, width=6, ...) { postscript(file=file, onefile=FALSE, horizontal=horizontal, paper=paper, height=height, width=width,...) } img - function(file, type, height=6, width=6, res=100, units=in, ...) { # handle image types types - c(bmp, eps, jpg, pdf, png) if (missing(type)) { if (exists(imgtype)) { if (is.null(imgtype)) return() else type - imgtype } } else { t - match(type, types, nomatch=0) if(t 0) type - types[t] else stop(unknown file type) } if (exists(imgnum) imgnum - imgnum+1 else imgnum - 1 # TODO: Handle global imgnum in filename if (missing(file)) { file - if(exists(imgname)) paste(imgname, '%03d', sep='') else Rplot%03d } filename - paste(file, '.', type, sep='') switch(type, bmp = bmp(filename, height=height, width=width, res=res, units=units, ...), eps = eps(filename, height=height, width=width, ...), jpg = jpeg(filename, height=height, width=width, res=res, units=units, ...), pdf = pdf(filename, height=height, width=width, ...), png = png(filename, height=height, width=width, res=res, units=units, ...) ) } img.off - function() { if (exists(imgtype) !is.null(imgtype)) dev.off() } TESTME - FALSE if(TESTME) { # set global image name and starting number imgname - 'test' imgnum - 1 imgtype - NULL # screen output img() plot(1:10, main=paste(imgtype:, imgtype)) img.off() imgtype - pdf img() plot(10:1, main=paste(imgtype:, imgtype)) img.off() } -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele StreetWeb: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] minimizing device-dependent code in graphics scripts
On 27/10/2011 10:13 AM, Michael Friendly wrote: Here is a common scenario that I and probably others often face: - I write a script, test.R, to produce some graphs, viewing them on-screen and tinkering until they look right - I want to save image files (e.g., .png), so I wrap each plot in device driver calls, e.g., png(file='test01.png', width=600, height=600); plot(1:10) dev.off() png(file='test02.png', width=600, height=600); plot(10:1) dev.off() ... - Then I want to include those graphs in a document, so maybe I want them in .pdf or .eps format. So I have to modify all the device calls to pdf() or postscript(), changing the filenames and perhaps other options. If I want those graphs to be squentially numbered with filenames like 'test%02d' and insert a new graph in the sequence, I have to edit all the filenames after the insertion. There has to be an easier way. (I know I could use Sweave, but that introduces another layer that I want to avoid while I'm developing plots.) I use Sweave, more or less as you describe at the top: I fiddle with the graphs on screen first, then when they're fine, I put the code into the document. Mostly the documents use PDF figures, but it's a global change at the top if I want something else. Since all the fiddling is done on screen, I don't have the issue of Sweave overhead being a problem during development (and it's generally pretty low overhead, as long as I don't put long computations into the documents). But if I wanted to avoid device calls in scripts, I'd probably do what you did below. Duncan Murdoch This contrasts strongly with what I've done for many years with SAS: I use *no* device-dependent code in .sas files, but instead use a collection of device-independent macros that respond to a global macro variable, DEVTYP. On linux, a custom (perl) script sets this as an environment variable used by these macros, so I can run test.sas at the command line via % alias s=mysas % s -b -d eps test % s -d pdf test % s -v -d png test and get test1.eps, test2.eps, ... etc. where the basename of the image files is automatically set to something like 'test%01d'. The -v option opens each of the generated graphics files in an appropriate viewer (gs, display, xpdf, etc.) The -b option for .eps files runs a bbfix script to adjust bounding boxes on .eps files. I don't need anything this elaborate for R, but it's a long way from what I do with SAS vs what I do currently with R. Perhaps other have some partial solutions for this general problem they'd be willing to share. For what it's worth, here is an initial sketch of one approach, using two general functions, img() and img.off(). Perhaps others could help improve it. img.R ### # shorthand for eps() eps- function(file=Rplot.eps, horizontal=FALSE, paper=special, height=6, width=6, ...) { postscript(file=file, onefile=FALSE, horizontal=horizontal, paper=paper, height=height, width=width,...) } img- function(file, type, height=6, width=6, res=100, units=in, ...) { # handle image types types- c(bmp, eps, jpg, pdf, png) if (missing(type)) { if (exists(imgtype)) { if (is.null(imgtype)) return() else type- imgtype } } else { t- match(type, types, nomatch=0) if(t 0) type- types[t] else stop(unknown file type) } if (exists(imgnum) imgnum- imgnum+1 else imgnum- 1 # TODO: Handle global imgnum in filename if (missing(file)) { file- if(exists(imgname)) paste(imgname, '%03d', sep='') else Rplot%03d } filename- paste(file, '.', type, sep='') switch(type, bmp = bmp(filename, height=height, width=width, res=res, units=units, ...), eps = eps(filename, height=height, width=width, ...), jpg = jpeg(filename, height=height, width=width, res=res, units=units, ...), pdf = pdf(filename, height=height, width=width, ...), png = png(filename, height=height, width=width, res=res, units=units, ...) ) } img.off- function() { if (exists(imgtype) !is.null(imgtype)) dev.off() } TESTME- FALSE if(TESTME) { # set global image name and starting number imgname- 'test' imgnum- 1 imgtype- NULL # screen output img() plot(1:10, main=paste(imgtype:, imgtype)) img.off() imgtype- pdf img() plot(10:1, main=paste(imgtype:, imgtype)) img.off() } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] show.ci='FALSE' ignored in simple.lm
On Oct 27, 2011, at 6:58 AM, Elinor Zeev wrote: Hi, I am using PostgreSQL 9.1 and want to run loglinear_simple-simple.lm(x$p_overPnot,x$logQuantity,show.ci =FALSE,conf.level=confidenceLevel) without showing the graph, however the show.ci=FALSE is ignored. My guess (and it is a guess since you did not specify a package for simple.lm) is that specifying a conf.level is over-riding the show.ci parameter. Why would one specify a value for conf.level if one did not want a confidence level? I have quite few packages loaded and I still get: ?simple.lm No documentation for 'simple.lm' in specified packages and libraries: you could try '??simple.lm' -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] FOR loop with statistical analysis for microarray data
thanks for the replies so, i remove the indices pv[i] and fc[i]..but when i run it like this: === fc=0 pv=0 for (i in 1:nrow(data)) { v1= c(y1[i,1], y1[i,2]) v2= c(y2[i,1], y2[1,2]) fc=v1-v2 w=t.test(v1,v2) pv=w$p.value } results = cbind(row.names(y1), fc, pv) head(results) = i get === Warning message: In cbind(row.names(y1), fc, pv) : number of rows of result is not a multiple of vector length (arg 2) = and the fc values are repeated over until the end of the rows and the pv is the same all across the samples...how can i fix it?! ...i apologize if it's a silly situation but i'm new to this and can't get my head around it! thanks so much!! On Thu, Oct 27, 2011 at 9:02 AM, Weidong Gu anopheles...@gmail.com wrote: In your loop, you assign, for example, pv twice pv=w$p.value # pv is scalar pv[i]= w[2] # pv is a vector give an example for the point pv=1 pv[5]=2 pv [1] 1 NA NA NA 2 This may not be what you want. Weidong On Thu, Oct 27, 2011 at 7:40 AM, Seb seba@gmail.com wrote: y1,y2 were designed as follow,from the original data file : y1=data[,1:2] y2=data[,3:4] ...I am a bit confused with what redesign the whole vector again and specify indices twice actually mean?...could u point it out in the script? Thanks so much I really appreciate it!! Sent from my -DROID- On Oct 26, 2011 6:56 PM, Weidong Gu wrote: If you provide an example data (y1 and y2 in the loop), you might have got specific helps already. A few things in your loop seem suspicious. fc and pv are vectors, and in each loop you redesigned the whole vectors and specific indices twice. That may cause your problems. Weidong Gu On Wed, Oct 26, 2011 at 4:56 PM, Seb seba@gmail.com wrote: hi all i started recently using R and i found myself stuck when i try to analyze microarray data. i use the affy package to obtain the intensities of the probes, i have two CTRs and two treated. HG.U133A.Experiment1.CEL HG.U133A.Experiment2.CEL HG.U133A_Control1.CEL HG.U133A_Control2.CEL 1007_s_at 2156.23115 467.75615 364.60615 362.11865 1053_at 88.76368 93.58436 438.49365 357.75615 117_at 144.00743 101.26120 95.7 107.01623 121_at 551.36865 639.45615 456.66865 435.95615 1255_g_at 65.33164 18.39570 14.22565 20.74632 1294_at 106.19083 169.69369 78.15722 81.14689 i divided the first two columns in two data.frames to divide Experim and CTRs then, i created a FOR loop to create a vector per each row containing a vector with two values per each gene and i wanted to do a Wilcox.test to obtain the significant genes..BUT i get a list of NULL like you can see here ..the first row works but then i get NULL down till the end of the array... fc pv [1,] 1007_s_at -20.248 0.4664612 [2,] 1053_at -344.7132 NULL [3,] 117_at NULL NULL [4,] 121_at NULL NULL [5,] 1255_g_at NULL NULL [6,] 1294_at NULL NULL the script i used is: === fc=0 pv=0 for (i in 1:nrow(data)) { v1= c(y1[i,1], y1[i,2]) v2= c(y2[i,1], y2[1,2]) fc=v1-v2 w=t.test(v1,v2) pv=w$p.value fc[i]= w[1] pv[i]= w[2] } results = cbind(row.names(y1), fc, pv) head(results) what did i do wrong? i can't find a way around this!!! thanks so much!!! Seb __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] question R regarding consecutive numbers
On Oct 27, 2011, at 9:21 AM, Duncan Murdoch wrote: On 27/10/2011 8:43 AM, Samir Benzerfa wrote: Hi everyone Do you know about any possibility in R to check for consecutive numbers in vectors? That is, I do not only want to count the number of observations in total (which can be done table(x)), but I also want to count for instance how many times that vector contains a certain number consecutively. For example in the following vector x the number 1 appears 7 times. However, I want to check for instance how many times two consecutive 1's appear in the vector, which would actually be two times the case in the below vector. x=c(1,1,3,4,9,1,9,1,5,4,5,2,1,1,1,6) Any ideas for this issue? How about this? runs - rle(x) with(runs, table(values, lengths)) And to go even a bit further, the table function returns a matrix which can be addressed to yield the specific answer requested: with(runs, table(values, lengths))[1,2] [1] 1 # m=number of exactly runs if length 2 sum( tbl[1, 2:ncol(tbl)] ) [1] 2 # number of runs of length two or more. -- David lengths values 1 2 3 1 2 1 1 2 1 0 0 3 1 0 0 4 2 0 0 5 2 0 0 6 1 0 0 9 2 0 0 Duncan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Calculate the difference using ave
Thanks Dimitris, but I would like to bind the result on the dataframe, so the length should be equal to nrow(df1). BTW, sorry for the example, it wasn't very clear, next try: # options(stringsAsFactors = FALSE) set.seed(123) df1 - data.frame(id = rep(LETTERS[1:6], 3), yr = rep(c(2009:2011), each=6), water = sample(c(100:500), 18), salt = sample(c(10:40), 18)) CalcDiffPct - function(xdf) { n - length(unique(xdf[[id]])) n.NA - rep(NA, n) w - seq_len(nrow(xdf) - n) diff_pct - xdf$salt / c(n.NA, xdf$water[w]) * 100 diff_pct } # The order is important df1 - df1[order(df1$yr, df1$id), ] # This works, as long as each # combination of yr / id exist with(df1, table(id, yr)) df1$salt_pct - CalcDiffPct(df1) df1 # But if the I drop any row the result will be wrong # (or 'correct' as the function doesn't handle this case) df2 - df1 df2 - df2[-15, ] with(df2, table(id, yr)) df2$salt_pct2 - CalcDiffPct(df2) df2 ## Thanks for any help! Patrick Am 26.10.2011 14:00, schrieb Dimitris Rizopoulos: Maybe one approach could be: set.seed(123) df1 - data.frame(measure = rep(c(A1, A2, A3), each=3), water = sample(c(100:200), 9), tide = sample(c(-10:+10), 9)) 100 * tail(df1$tide, -3) / head(df1$water, -3) I hope it helps. Best, Dimitris On 10/26/2011 12:02 PM, Patrick Hausmann wrote: Dear R users, It may be very simple but it is being difficult for me. I'd like to calculate the difference in percent between to measures. My data looks like this: set.seed(123) df1 - data.frame(measure = rep(c(A1, A2, A3), each=3), water = sample(c(100:200), 9), tide = sample(c(-10:+10), 9)) df1 # What I want to calculate is: # tide_[A2] / water_[A1], # tide_[A3] / water_[A2] # This 'works' for the example, but I am # looking for a more general solution. df1$tide_diff - ave(df1$tide, FUN=function(L) L / c(NA, NA, NA, df1$water)) * 100 df1 Thanks for any help! Patrick __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 time series
hi, I want any suggestion for a differents packages to manipulate a time series. thanks for help. -- View this message in context: http://r.789695.n4.nabble.com/package-for-time-series-tp3944825p3944825.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] Trying to create a function to extract values from a matrix
My issue seems simple but I can't find any method to work... I've got a matrix with 4 columns and I want to extract the values from each row to make a new 2x2 matrix for each row. From these resultant matrices, I want to get the Eigen Values and output them from the function as usable numbers (not a text string). Here's the function... ### Ef = function(MAT) {for(i in c(1:(length(MAT)/4))) return(matrix(c (eigen(matrix(c(MAT[i,]),ncol=2))$values),ncol=2))} ### This function will return only the Eigen Values of the first row (MAT[1,]) of the matrix. However, if I replace return in the function with cat, the function will output all the desired values, but they will be as a text string, which I can't use. Furthermore, if I set a variable in the function, and then return the variable at the end of the function, it yields the Eigen Values for the last row of my matrix. That function looks like... ### Ef= function(MAT) {for(i in c(1:(length(MAT)/4))) EV=(matrix(c (eigen(matrix(c(MAT[i,]),ncol=2))$values),ncol=2)); return(EV)} ### From what I can tell, it seems that the function is working, however, I don't know how to get it to spit out all the information in a usable manner. Thanks for any suggestions. Stephen -- View this message in context: http://r.789695.n4.nabble.com/Trying-to-create-a-function-to-extract-values-from-a-matrix-tp3944737p3944737.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] Correllogram of Daily Time Series
Usually it's encouraged to use a csv or txt intermediary between Excel and R: depending on what you want to do, you can either convert it once it's in R or maybe use read.zoo() to simplify a few things. Most people find the raw ts class hard to use and prefer a contributed class instead: my usual favorite is xts. Info on correlograms can be found here: http://www.statmethods.net/advgraphs/correlograms.html Michael On Thu, Oct 27, 2011 at 7:55 AM, Bazman76 h_a_patie...@hotmail.com wrote: Hi there, What is the best way to get a time series of daily stock price observations into R (from excel). The time series are daily but there are spaces for w/e's and holidays etc. So I am not sure a ts object will be suitable but I am not sure what I should use? What ever package you recemmned i need to be able to run a corrolelagram. Thanks Hugh -- View this message in context: http://r.789695.n4.nabble.com/Correllogram-of-Daily-Time-Series-tp3944094p3944094.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] Trying to create a function to extract values from a matrix
This might be an easier method: suppose your data is in MAT t(apply(MAT, 1, function(v) eigen(matrix(v, 2))$values)) Your problem is that return() automatically returns the output and ceases function execution as soon as its hit. Michael On Thu, Oct 27, 2011 at 10:44 AM, StephenHughes kshug...@ncsu.edu wrote: My issue seems simple but I can't find any method to work... I've got a matrix with 4 columns and I want to extract the values from each row to make a new 2x2 matrix for each row. From these resultant matrices, I want to get the Eigen Values and output them from the function as usable numbers (not a text string). Here's the function... ### Ef = function(MAT) {for(i in c(1:(length(MAT)/4))) return(matrix(c (eigen(matrix(c(MAT[i,]),ncol=2))$values),ncol=2))} ### This function will return only the Eigen Values of the first row (MAT[1,]) of the matrix. However, if I replace return in the function with cat, the function will output all the desired values, but they will be as a text string, which I can't use. Furthermore, if I set a variable in the function, and then return the variable at the end of the function, it yields the Eigen Values for the last row of my matrix. That function looks like... ### Ef= function(MAT) {for(i in c(1:(length(MAT)/4))) EV=(matrix(c (eigen(matrix(c(MAT[i,]),ncol=2))$values),ncol=2)); return(EV)} ### From what I can tell, it seems that the function is working, however, I don't know how to get it to spit out all the information in a usable manner. Thanks for any suggestions. Stephen -- View this message in context: http://r.789695.n4.nabble.com/Trying-to-create-a-function-to-extract-values-from-a-matrix-tp3944737p3944737.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.
[R] Syntax Check: rshape2 melt()
This is my first excursion into using reshape2 and I want to ensure that the melt() function call is syntactically correct. The unmodifed data frame is organized this way: head(tds.anal) site sampdate param quant 1UDS-O 2006-12-06 TDS 10800 4 STC-FS 1996-06-14 Cond 280 7UDS-O 2007-10-04Mg 1620 9UDS-O 2007-10-04 SO4 7580 19 JCM-10B 2007-06-21Ca79 20 JCM-10B 2007-06-21Cl 114 What I want looks like this: sitesampdate TDS Cond Mg Ca Cl Na SO4 UDS-O 2006-12-06 10800 NA 1620 NA NA NA 7580 with the actual data for each param, of course. I've read the reshape.pdf, reshape2.pdf, the ?melt help page, and the ?melt.data.frame help page. I'm still unclear on the differences among measure.vars, variable.name, and value.name. After several attempts I have what may be what the melted tds.anal should look like: m.tds.anal - melt(tds.anal, id.vars = c('site', 'sampdate', 'param'), \ measure.vars = 'quant', value.name = 'quant', na.rm = F) head(m.tds.anal) site sampdate param variable quant 1 UDS-O 2006-12-06 TDSquant 10800 2 STC-FS 1996-06-14 Condquant 280 3 UDS-O 2007-10-04Mgquant 1620 4 UDS-O 2007-10-04 SO4quant 7580 5 JCM-10B 2007-06-21Caquant79 6 JCM-10B 2007-06-21Clquant 114 Is the melt() function call correct? Should the melted result look like the unmelted (long form in Paul Dalgaard's book) data with the additional 'variable' column containing 'quant' for each row? Rich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 time series
http://lmgtfy.com/?q=CRAN+time+series+analysis Michael On Thu, Oct 27, 2011 at 11:08 AM, rgui wa7@gmail.com wrote: hi, I want any suggestion for a differents packages to manipulate a time series. thanks for help. -- View this message in context: http://r.789695.n4.nabble.com/package-for-time-series-tp3944825p3944825.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] FOR loop with statistical analysis for microarray data
Looks like you have problems with indexing. In your code, fc is a vector of length 2, pv is a scalar(it only keeps the last value of the loop), then you try to cbind different lengths of vectors (row.names(y1), fc and pv). cbind only works for vectors with the same length. I don't know what you want to achieve, but you can keep p.value using pv[i]. In the previous code, you reassiged pv before pv[i]. So your 1st assignment of pv wiped out pv vector. You need to read helps about indexing, vectors. Weidong On Thu, Oct 27, 2011 at 10:41 AM, Seb seba@gmail.com wrote: thanks for the replies so, i remove the indices pv[i] and fc[i]..but when i run it like this: === fc=0 pv=0 for (i in 1:nrow(data)) { v1= c(y1[i,1], y1[i,2]) v2= c(y2[i,1], y2[1,2]) fc=v1-v2 w=t.test(v1,v2) pv=w$p.value } results = cbind(row.names(y1), fc, pv) head(results) = i get === Warning message: In cbind(row.names(y1), fc, pv) : number of rows of result is not a multiple of vector length (arg 2) = and the fc values are repeated over until the end of the rows and the pv is the same all across the samples...how can i fix it?! ...i apologize if it's a silly situation but i'm new to this and can't get my head around it! thanks so much!! On Thu, Oct 27, 2011 at 9:02 AM, Weidong Gu anopheles...@gmail.com wrote: In your loop, you assign, for example, pv twice pv=w$p.value # pv is scalar pv[i]= w[2] # pv is a vector give an example for the point pv=1 pv[5]=2 pv [1] 1 NA NA NA 2 This may not be what you want. Weidong On Thu, Oct 27, 2011 at 7:40 AM, Seb seba@gmail.com wrote: y1,y2 were designed as follow,from the original data file : y1=data[,1:2] y2=data[,3:4] ...I am a bit confused with what redesign the whole vector again and specify indices twice actually mean?...could u point it out in the script? Thanks so much I really appreciate it!! Sent from my -DROID- On Oct 26, 2011 6:56 PM, Weidong Gu wrote: If you provide an example data (y1 and y2 in the loop), you might have got specific helps already. A few things in your loop seem suspicious. fc and pv are vectors, and in each loop you redesigned the whole vectors and specific indices twice. That may cause your problems. Weidong Gu On Wed, Oct 26, 2011 at 4:56 PM, Seb seba@gmail.com wrote: hi all i started recently using R and i found myself stuck when i try to analyze microarray data. i use the affy package to obtain the intensities of the probes, i have two CTRs and two treated. HG.U133A.Experiment1.CEL HG.U133A.Experiment2.CEL HG.U133A_Control1.CEL HG.U133A_Control2.CEL 1007_s_at 2156.23115 467.75615 364.60615 362.11865 1053_at 88.76368 93.58436 438.49365 357.75615 117_at 144.00743 101.26120 95.7 107.01623 121_at 551.36865 639.45615 456.66865 435.95615 1255_g_at 65.33164 18.39570 14.22565 20.74632 1294_at 106.19083 169.69369 78.15722 81.14689 i divided the first two columns in two data.frames to divide Experim and CTRs then, i created a FOR loop to create a vector per each row containing a vector with two values per each gene and i wanted to do a Wilcox.test to obtain the significant genes..BUT i get a list of NULL like you can see here ..the first row works but then i get NULL down till the end of the array... fc pv [1,] 1007_s_at -20.248 0.4664612 [2,] 1053_at -344.7132 NULL [3,] 117_at NULL NULL [4,] 121_at NULL NULL [5,] 1255_g_at NULL NULL [6,] 1294_at NULL NULL the script i used is: === fc=0 pv=0 for (i in 1:nrow(data)) { v1= c(y1[i,1], y1[i,2]) v2= c(y2[i,1], y2[1,2]) fc=v1-v2 w=t.test(v1,v2) pv=w$p.value fc[i]= w[1] pv[i]= w[2] } results = cbind(row.names(y1), fc, pv) head(results) what did i do wrong? i can't find a way around this!!! thanks so much!!! Seb __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Power mixed model ordinal logistic regression
Is there a package that will perform power calculations for mixed model ordinal logistic regression? I searched and came up with nothing. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 time series
On 27/10/2011 11:08 AM, rgui wrote: hi, I want any suggestion for a differents packages to manipulate a time series. thanks for help. See the Time Series task view on http://cran.r-project.org/web/views/. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Consistant test for NAs in a factor when exclude = NULL?
Note that for factors with NA in the levels, is.na(f)[2] - TRUE and is.na(f[2])-TRUE give different results: f - factor(c(A,A,NA), levels=c(NA, A), exclude=NULL) str(f) Factor w/ 2 levels NA,A: 2 2 1 is.na(f) [1] FALSE FALSE FALSE is.na(f[2]) - TRUE str(f) Factor w/ 2 levels NA,A: 2 1 1 is.na(f) [1] FALSE FALSE FALSE is.na(f)[2] - TRUE str(f) Factor w/ 2 levels NA,A: 2 NA 1 is.na(f) [1] FALSE TRUE FALSE f[2] - NA str(f) Factor w/ 2 levels NA,A: 2 1 1 is.na(f) [1] FALSE FALSE FALSE You may find it easiest to change the NA's to strings with a different name. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of andrewH Sent: Wednesday, October 26, 2011 9:22 PM To: r-help@r-project.org Subject: Re: [R] Consistant test for NAs in a factor when exclude = NULL? Thanks Jeff! I appreciate you sharing your experience. My data set is survey data, 13,209 records over nine years, collected by someone else, converted from SPSS format. It includes missing values, identified however SPSS does so, and translated to NAs by the import process. It also includes values along the lines of none of your business or beats me that are missing so far as I am concerned. I have assigned NAs to these values. Now I am trying to figure out some things about where these missing values are -- whether they are disproportionately located in any period or group. I have been trying to get counts for subsets, but I have not been able to make the subset counts add up to the total counts that I get from, e.g. summary. So I wrote these simplified versions, and even for the simplest examples, I could not find a function that correctly identified the NAs that I knew were there because I put them there myself. That is why I am looking for help. Does this make sense? Warmest regards, andrewH -- View this message in context: http://r.789695.n4.nabble.com/Consistant-test-for-NAs-in-a-factor-when- exclude-NULL-tp3942755p3943157.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.
[R] R.oo package, inherit two classes
Hello, How do I inherit two classes using the R.oo package. Below is kind of a silly example, but I am trying to create class PerDog from classes Dog and Person. Error at bottom. I've tried a few other ways of using extend(), but nothing seems to get me what I want. Example: setConstructorS3(Person, function(age=NA) { this = extend(Object(), Person, .age=age ) this }) setMethodS3(getAge, Person, function(this, ...) { this$.age; }) setMethodS3(setAge, Person, function(this,num, ...) { this$.age = num; }) # .. setConstructorS3(Dog, function(dog_age=NA) { this = extend(Object(), Dog, .dog_age=dog_age ) this }) setMethodS3(getDogAge, Dog, function(this, ...) { this$.dog_age; }) setMethodS3(setDogAge, Dog, function(this,num, ...) { this$.dog_age = num; }) #.. setConstructorS3(PerDog, function(age=NA,wt=NA,dog_age=NULL) { extend(Person(age=age),Dog(dog_age=dog_age), PerDog, .wt=wt ) }) setMethodS3(getWeight, PerDog, function(this, ...) { this$.wt; }) setMethodS3(setWeight, PerDog, function(this,w, ...) { this$.wt = w; }) pd = PerDog(67,150,1) Error in list(`PerDog(67, 150, 1)` = environment, `extend(Person(age = age), Dog(dog_age = dog_age), PerDog, .wt = wt)` = environment, : [2011-10-27 09:34:06] Exception: Missing name of field #1 in class definition: Dog: 0x73880408 at throw(Exception(...)) at throw.default(Missing name of field #, k, in class definition: , ...className) at throw(Missing name of field #, k, in class definition: , ...className) at extend.Object(Person(age = age), Dog(dog_age = dog_age), PerDog, .wt = wt) at extend(Person(age = age), Dog(dog_age = dog_age), PerDog, .wt = wt) at PerDog(67, 150, 1) Three (of many) other things I have tried: 1) setConstructorS3(PerDog, function(age=NA,wt=NA,dog_age=NULL) { this = extend(extend(Person(age=age), PerDog),Dog(dog_age=dog_age), PerDog, .wt=wt ) this }) 2) setConstructorS3(PerDog, function(age=NA,wt=NA,dog_age=NULL) { this = extend(Dog(dog_age=dog_age), PerDog, .wt=wt ) this }) setConstructorS3(PerDog, function(age=NA,wt=NA,dog_age=NULL) { this = extend(Person(age=age), PerDog, .wt=wt ) this }) 3) setConstructorS3(PerDog, function(age=NA,wt=NA,dog_age=NULL) { this = extend(Dog(dog_age=dog_age), PerDog, setConstructorS3(PerDog, function(age=NA,wt=NA,dog_age=NULL) { extend(Person(age=age), PerDog, .wt=wt ) }) ) this }) Thanks, ben [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] LATEX Command in R in Windows 7
Hi guys, I have 64-bit Windows 7 machine. I need to execute the latex and pdflatex commands from R to print out tables in pdf. I use R 2.13 64-bit, and I have GSView, GSScript and TexWorks installed. I remember i did this once but I forgot the next step. What shall I do? Thanks, -- Ş. Barış Demiral, PhD. Department of Psychiatry Washington University School of Medicine 660 S. Euclid Avenue Box 8134 Saint Louis, MO 63110 Phone: +1 (314) 7477 1603 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Power mixed model ordinal logistic regression
Scott Raynaud scott.raynaud at yahoo.com writes: Is there a package that will perform power calculations for mixed model ordinal logistic regression? I searched and came up with nothing. Didn't you ask this question, and get an answer, on this list yesterday ... ?? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Syntax Check: rshape2 melt()
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Rich Shepard Sent: Thursday, October 27, 2011 8:26 AM To: r-help@r-project.org Subject: [R] Syntax Check: rshape2 melt() This is my first excursion into using reshape2 and I want to ensure that the melt() function call is syntactically correct. The unmodifed data frame is organized this way: head(tds.anal) site sampdate param quant 1UDS-O 2006-12-06 TDS 10800 4 STC-FS 1996-06-14 Cond 280 7UDS-O 2007-10-04Mg 1620 9UDS-O 2007-10-04 SO4 7580 19 JCM-10B 2007-06-21Ca79 20 JCM-10B 2007-06-21Cl 114 What I want looks like this: sitesampdate TDS Cond Mg Ca Cl Na SO4 UDS-O 2006-12-06 10800 NA 1620 NA NA NA 7580 with the actual data for each param, of course. I've read the reshape.pdf, reshape2.pdf, the ?melt help page, and the ?melt.data.frame help page. I'm still unclear on the differences among measure.vars, variable.name, and value.name. After several attempts I have what may be what the melted tds.anal should look like: m.tds.anal - melt(tds.anal, id.vars = c('site', 'sampdate', 'param'), \ measure.vars = 'quant', value.name = 'quant', na.rm = F) head(m.tds.anal) site sampdate param variable quant 1 UDS-O 2006-12-06 TDSquant 10800 2 STC-FS 1996-06-14 Condquant 280 3 UDS-O 2007-10-04Mgquant 1620 4 UDS-O 2007-10-04 SO4quant 7580 5 JCM-10B 2007-06-21Caquant79 6 JCM-10B 2007-06-21Clquant 114 Is the melt() function call correct? Should the melted result look like the unmelted (long form in Paul Dalgaard's book) data with the additional 'variable' column containing 'quant' for each row? Rich Rich, What I think you want is as simple as test.melted - melt(test) wanted - cast(test.melted, site + sampdate ~ param) Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] glmmBUGS fails to accept higher level covariates
Hello I am using glmmBUGS to fit a multilevel model. Treatments are nested in Course are nested in Patients. The predicted variable in total EEG duration. The predictors are: at the observation level : Medication dose at the Course level: Weight in KG and Age at the Patient level: Weight in KG and Age I am trying to fit a multilevel model as in lmer, but in BUGS. Here is an example of the model I want to run: Linear mixed model fit by REML Formula: totalEEG ~ workDose + (1 + WEIGHTKG + AgeYrs | MRN/COURSE) Data: book AIC BIC logLik deviance REMLdev 7041 7112 -3506 70047011 Random effects: Groups NameVariance Std.Dev. Corr COURSE:MRN (Intercept) 6.5755e-06 2.5643e-03 WEIGHTKG1.9015e-11 4.3606e-06 -1.000 AgeYrs 1.1138e-09 3.3373e-05 -1.000 1.000 MRN(Intercept) 5.0897e+02 2.2560e+01 WEIGHTKG2.8231e-02 1.6802e-01 -1.000 AgeYrs 8.1881e-04 2.8615e-02 1.000 -1.000 Residual 2.4965e+02 1.5800e+01 Number of obs: 818, groups: COURSE:MRN, 114; MRN, 103 Fixed effects: Estimate Std. Error t value (Intercept) 51.721608 1.669860 30.974 workDose-0.010632 0.003246 -3.275 Correlation of Fixed Effects: (Intr) workDose -0.663 bgs.toteeg-glmmBUGS(data=book, observations=totalEEG, covariates=list(MRN=AgeYrs, COURSE=WEIGHTKG, observations=workDose), effects=c(MRN, COURSE), family=gaussian, modelFile=model.bug) however, this is failing with: Error in glmmBUGS(data = book, observations = totalEEG, covariates = list(MRN = AgeYrs, : unused argument(s) (observations = totalEEG, covariates = list(MRN = AgeYrs, COURSE = WEIGHTKG)) I have already run models with multiple predictors at the lowest level. glmmBUGS parameterises and runs a WINBUGS model fine. however, this full mixed model seems not to work. When I tried: bgs.toteeg-glmmBUGS(data=book, totalEEG~workDose, reparam=c(MRN=AgeYrs, COURSE=WEIGHTKG), effects=c(MRN, COURSE), family=poisson, modelFile=model.bug) IT compiled the WinBUGS model fine, but winBUGS stalled on an error, not recognising a node xobservations. I'm learning, so it's not just a case where I can step-up and model it directly in Winbugs. R 2.13.2 on Win 7 i3Intel with lmer, nlme, R2WinBUGS, BRugs, lattice, attached. Winbugs version 14.3. (Which I know is working fine - Brainware problem most likely) Thank you Ross ross.du...@tcd.ie -- View this message in context: http://r.789695.n4.nabble.com/glmmBUGS-fails-to-accept-higher-level-covariates-tp3945251p3945251.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] Syntax Check: rshape2 melt()
On Thu, 27 Oct 2011, Nordlund, Dan (DSHS/RDA) wrote: What I think you want is as simple as test.melted - melt(test) Dan, I see the difference this syntax makes; sampdate is the variable associated with the value (quant) for a specific ID pair of site and param. wanted - cast(test.melted, site + sampdate ~ param) This, unfortunately, doesn't work: c.tds.anal - cast(m.tds.anal, site + sampdate ~ param) Error: could not find function cast ?cast has an example using acast() so I tried that: c.tds.anal - acast(m.tds.anal, site + sampdate ~ param) Error in eval(expr, envir, enclos) : object 'sampdate' not found Changing 'sampdate' to 'variable' produces results, but not what's needed: c.tds.anal - acast(m.tds.anal, site + variable ~ param) Aggregation function missing: defaulting to length head(c.tds.anal) Ca Cl Cond Mg Na SO4 TDS BC-0.5_sampdate 1 13 1 0 3 3 BC-0.5_quant 1 13 1 0 3 3 BC-1_sampdate8 8 11 8 7 10 10 BC-1_quant 8 8 11 8 7 10 10 BC-1.5_sampdate 3 46 3 0 6 6 BC-1.5_quant 3 46 3 0 6 6 Now that I better understand melt(), I'll read ?cast. Thanks very much, Rich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] show.ci='FALSE' ignored in simple.lm
Hi: A trip to package sos reveals that simple.lm() is in the UsingR package. Looking at the code of this function, it plots the (x, y) pairs and the fitted least squares line without an option to suppress the plot. Here's a slight hack of the function; it adds a new argument plot with default action TRUE; after the linear model is fit, an if statement tests to see if the plot is desired; if FALSE, it simply returns the (print method of the) fitted object. simple.lm2 - function (x, y, plot = TRUE, show.residuals = FALSE, show.ci = FALSE, conf.level = 0.95, pred = FALSE) { op - par() ord - order(x) x - x[ord] y - y[ord] tmp.lm - lm(y ~ x) if(!plot) return(tmp.lm) else { if (show.residuals) { par(mfrow = c(2, 2)) } plot(x, y) abline(tmp.lm) if (show.ci) { xvals - seq(min(x), max(y), length = 15) curve(predict(tmp.lm, data.frame(x = x), level = conf.level, interval = confidence)[, 3], add = TRUE) curve(predict(tmp.lm, data.frame(x = x), level = conf.level, interval = confidence)[, 2], add = TRUE) curve(predict(tmp.lm, data.frame(x = x), level = conf.level, interval = prediction)[, 3], lty = 3, add = TRUE) curve(predict(tmp.lm, data.frame(x = x), level = conf.level, interval = prediction)[, 2], lty = 3, add = TRUE) } coeffs - floor(tmp.lm$coeff * 100 + 0.5)/100 plusorminus - c(+) if (coeffs[1] 0) plusorminus - c() title(paste(y = , coeffs[2], x , plusorminus, coeffs[1])) if (show.residuals) { Fitted - fitted.values(tmp.lm) Residuals - residuals(tmp.lm) plot(Fitted, Residuals) abline(h = 0) title(Residuals vs. fitted) hist(Residuals, main = hist of residuals) qqnorm(Residuals, main = normal plot of residuals) qqline(Residuals) } if (pred) { print(predict(tmp.lm, data.frame(x = pred))) } } tmp.lm } # # Simple test: plot(x - 1:10) y - 5*x + rnorm(10,0,1) tmp1 - simple.lm2(x, y, plot = FALSE) summary(tmp1) # Produces the plot simple.lm2(x, y) HTH, Dennis On Thu, Oct 27, 2011 at 7:35 AM, David Winsemius dwinsem...@comcast.net wrote: On Oct 27, 2011, at 6:58 AM, Elinor Zeev wrote: Hi, I am using PostgreSQL 9.1 and want to run loglinear_simple-simple.lm(x$p_overPnot,x$logQuantity,show.ci =FALSE,conf.level=confidenceLevel) without showing the graph, however the show.ci=FALSE is ignored. My guess (and it is a guess since you did not specify a package for simple.lm) is that specifying a conf.level is over-riding the show.ci parameter. Why would one specify a value for conf.level if one did not want a confidence level? I have quite few packages loaded and I still get: ?simple.lm No documentation for 'simple.lm' in specified packages and libraries: you could try '??simple.lm' -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Correllogram of Daily Time Series
You also might be satisfied with the output of acf() or pacf() if you are just looking at the auto-correlation of one series. Michael On Thu, Oct 27, 2011 at 11:18 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: Usually it's encouraged to use a csv or txt intermediary between Excel and R: depending on what you want to do, you can either convert it once it's in R or maybe use read.zoo() to simplify a few things. Most people find the raw ts class hard to use and prefer a contributed class instead: my usual favorite is xts. Info on correlograms can be found here: http://www.statmethods.net/advgraphs/correlograms.html Michael On Thu, Oct 27, 2011 at 7:55 AM, Bazman76 h_a_patie...@hotmail.com wrote: Hi there, What is the best way to get a time series of daily stock price observations into R (from excel). The time series are daily but there are spaces for w/e's and holidays etc. So I am not sure a ts object will be suitable but I am not sure what I should use? What ever package you recemmned i need to be able to run a corrolelagram. Thanks Hugh -- View this message in context: http://r.789695.n4.nabble.com/Correllogram-of-Daily-Time-Series-tp3944094p3944094.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] Problem Installing a local package in linux
Dear Paul, Thanks for the response. I could resolve the problem. The problem, as you had rightly pointed out, was the absence of the gfortran package called libgfortran41. I located the rpm and installed it. This contains libgfortran.so.1. That does it. Thanks again. sambit On 27 October 2011 19:04, Paul Hiemstra paul.hiems...@knmi.nl wrote: Hi, Yea Linux! I think you are missing a library file (libgfortran.so.1), you can use locate to try and find the so file, in bash type: locate libgfortran Now three things can happen: - It doesn't find anything, than you need to install an additional gfortran package. This is often called libgfortran-dev or something (at least it is called this way in debian and ubuntu). This installs development files, including libgfortran.so - It finds a file called libgfotran.so.something but not .so.1. So you have the file, but it is not named correctly. Easiest solution is to create a symbolic link called libgfortran.so.1 to libgfortran.so.something and loading the library in R - It finds the correct file. Could be that the file is not in your PATH. Add the location of the file (the directy that is) to your path. cheers, Paul On 10/27/2011 12:56 PM, sambit rath wrote: Dear all, I am still fairly new to R and newer still to linux (opensuse). I want to install a package called FEAR from http://www.clemson.edu/economics/faculty/wilson/Software/FEAR/fear-download.html;. So, I downloaded the tar.gz file called FEAR-linux-64bit-2.6.16.60-0.21-smp.tar.gz and it is in the directory /home/sambit/Downloads right now. Then I invoked R from terminal and keyed in install.packages(/home/sambit/Downloads/FEAR-linux-64bit-2.6.16.60-0.21-smp.tar.gz, repos=NULL) Installing package(s) into ‘/home/sambit/R/x86_64-unknown-linux-gnu-library/2.13’ (as ‘lib’ is unspecified) * installing *binary* package ‘FEAR’ ... * DONE (FEAR) So, I think that the installation was successful. But when I load the package, library(FEAR) Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared object '/home/sambit/R/x86_64-unknown-linux-gnu-library/2.13/FEAR/libs/FEAR.so': libgfortran.so.1: cannot open shared object file: No such file or directory Error: package/namespace load failed for 'FEAR' I do not know what to do right now. I would really appreciate it someone could point out the next step. Thanks in advance. Sambit __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Paul Hiemstra, Ph.D. Global Climate Division Royal Netherlands Meteorological Institute (KNMI) Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39 P.O. Box 201 | 3730 AE | De Bilt tel: +31 30 2206 494 http://intamap.geo.uu.nl/~paul http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 vector os zeros for simulations (beginner's question)
Dear R helpers, I know this is a simple task, but I'm new to R and I'm still havind difficulties with the language. I want to create 30 vectors to be used in a simulation, each with 1 columm and 5 lines, of random numbers N(0,1). What I tried was this: N=150 u2-rep(1:150,0) u2-list(matrix(0,5)) u2 for(i in 1:N) { u2[i]-rnorm(5) } u2 ### also tried this: N=150 u2-rep((matrix(0,5)),30) u2 for(i in 1:N) { u2[i]-rnorm(5) } u2 The problem is none of this gives me the random numbers arranged in vectors. I've tried other variations too, but haven't managed to get it through. Any help is very welcome. Kind regards, Iara [[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] Syntax Check: rshape2 melt()
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Rich Shepard Sent: Thursday, October 27, 2011 10:22 AM To: r-help@r-project.org Subject: Re: [R] Syntax Check: rshape2 melt() On Thu, 27 Oct 2011, Nordlund, Dan (DSHS/RDA) wrote: What I think you want is as simple as test.melted - melt(test) Dan, I see the difference this syntax makes; sampdate is the variable associated with the value (quant) for a specific ID pair of site and param. wanted - cast(test.melted, site + sampdate ~ param) This, unfortunately, doesn't work: c.tds.anal - cast(m.tds.anal, site + sampdate ~ param) Error: could not find function cast ?cast has an example using acast() so I tried that: c.tds.anal - acast(m.tds.anal, site + sampdate ~ param) Error in eval(expr, envir, enclos) : object 'sampdate' not found Changing 'sampdate' to 'variable' produces results, but not what's needed: c.tds.anal - acast(m.tds.anal, site + variable ~ param) Aggregation function missing: defaulting to length head(c.tds.anal) Ca Cl Cond Mg Na SO4 TDS BC-0.5_sampdate 1 13 1 0 3 3 BC-0.5_quant 1 13 1 0 3 3 BC-1_sampdate8 8 11 8 7 10 10 BC-1_quant 8 8 11 8 7 10 10 BC-1.5_sampdate 3 46 3 0 6 6 BC-1.5_quant 3 46 3 0 6 6 Now that I better understand melt(), I'll read ?cast. Thanks very much, Rich Rich, I should apologize. I saw rshape2 and just glossed over that and read rshape. So I was using the rshape package rather than rshape2. I don't know the relationship between those two packages and/or how they differ. I am sure that there are others that can help you out here. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] regression in R
1) Packages to be used- For smaller datasets use these 1. CAR Package http://cran.r-project.org/web/packages/car/index.html 2. GVLMA Package http://cran.r-project.org/web/packages/gvlma/index.html 3. ROCR Package http://rocr.bioinf.mpi-sb.mpg.de/ 4. Relaimpo Package 5. DAAG package 6. MASS package 7. Bootstrap package 8. Leaps package Also see http://cran.r-project.org/web/packages/rms/index.html or RMS package rms works with almost any regression model, but it was especially written to work with binary or ordinal logistic regression, Cox regression, accelerated failure time models, ordinary linear models, the Buckley-James model, generalized least squares for serially or spatially correlated observations, generalized linear models, and quantile regression. For bigger datasets also see Biglm http://cran.r-project.org/web/packages/biglm/index.html and RevoScaleR packages. http://www.revolutionanalytics.com/products/enterprise-big-data.php 2) Syntax 1. outp=lm(y~x1+x2+xn,data=dataset) Model Eq 2. summary(outp) Model Summary 3. par(mfrow=c(2,2)) + plot(outp) Model Graphs 4. vif(outp) MultiCollinearity 5. gvlma(outp) Heteroscedasticity using GVLMA package 6. outlierTest (outp) for Outliers 7. predicted(outp) Scoring dataset with scores 8. anova(outp) 9. predict(lm.result,data.frame(conc = newconc), level = 0.9, interval = âconfidenceâ) For a Reference Card -Cheat Sheet see http://cran.r-project.org/doc/contrib/Ricci-refcard-regression.pdf 3) Also read- http://cran.r-project.org/web/views/Econometrics.html from the blog post at- http://www.decisionstats.com/building-a-regression-model-in-r-use-rstats/ additional hint- please use google to search (packages for regression in R) before sending multiple emails on the r help list best regards ajay [[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] Syntax Check: rshape2 melt()
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Nordlund, Dan (DSHS/RDA) Sent: Thursday, October 27, 2011 10:47 AM To: r-help@r-project.org Subject: Re: [R] Syntax Check: rshape2 melt() -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Rich Shepard Sent: Thursday, October 27, 2011 10:22 AM To: r-help@r-project.org Subject: Re: [R] Syntax Check: rshape2 melt() On Thu, 27 Oct 2011, Nordlund, Dan (DSHS/RDA) wrote: What I think you want is as simple as test.melted - melt(test) Dan, I see the difference this syntax makes; sampdate is the variable associated with the value (quant) for a specific ID pair of site and param. wanted - cast(test.melted, site + sampdate ~ param) This, unfortunately, doesn't work: c.tds.anal - cast(m.tds.anal, site + sampdate ~ param) Error: could not find function cast ?cast has an example using acast() so I tried that: c.tds.anal - acast(m.tds.anal, site + sampdate ~ param) Error in eval(expr, envir, enclos) : object 'sampdate' not found Changing 'sampdate' to 'variable' produces results, but not what's needed: c.tds.anal - acast(m.tds.anal, site + variable ~ param) Aggregation function missing: defaulting to length head(c.tds.anal) Ca Cl Cond Mg Na SO4 TDS BC-0.5_sampdate 1 13 1 0 3 3 BC-0.5_quant 1 13 1 0 3 3 BC-1_sampdate8 8 11 8 7 10 10 BC-1_quant 8 8 11 8 7 10 10 BC-1.5_sampdate 3 46 3 0 6 6 BC-1.5_quant 3 46 3 0 6 6 Now that I better understand melt(), I'll read ?cast. Thanks very much, Rich Rich, I should apologize. I saw rshape2 and just glossed over that and read rshape. So I was using the rshape package rather than rshape2. I don't know the relationship between those two packages and/or how they differ. I am sure that there are others that can help you out here. Dan I need more coffee. That should have been reshape and reshape2, not rshape and rshape2. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Syntax Check: rshape2 melt()
On Thu, 27 Oct 2011, Nordlund, Dan (DSHS/RDA) wrote: I should apologize. I saw rshape2 and just glossed over that and read rshape. Dan, Apparently the 'e' in the subject line fell off. It's 'reshape2'. So I was using the rshape package rather than rshape2. I don't know the relationship between those two packages and/or how they differ. I am sure that there are others that can help you out here. I, too, don't know how the two packages 'reshape, The Orignal' and 'reshape2, Rebooted' differ. The two articles by Hadley that I read (Statistical Computing and Graphics, 2005, and Journal of Statistical Software, 2007) do not explicitly specify which version of reshape is addressed. Rich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Syntax Check: rshape2 melt()
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Rich Shepard Sent: Thursday, October 27, 2011 10:56 AM To: r-help@r-project.org Subject: Re: [R] Syntax Check: rshape2 melt() On Thu, 27 Oct 2011, Nordlund, Dan (DSHS/RDA) wrote: I should apologize. I saw rshape2 and just glossed over that and read rshape. Dan, Apparently the 'e' in the subject line fell off. It's 'reshape2'. So I was using the rshape package rather than rshape2. I don't know the relationship between those two packages and/or how they differ. I am sure that there are others that can help you out here. I, too, don't know how the two packages 'reshape, The Orignal' and 'reshape2, Rebooted' differ. The two articles by Hadley that I read (Statistical Computing and Graphics, 2005, and Journal of Statistical Software, 2007) do not explicitly specify which version of reshape is addressed. Rich Rich, You should be able to get what you want using the dcast function (I think). test.melted - melt(tds.anal) dcast(test.melted, site + sampdate ~ param) Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] package for time series
This book is also pretty good: Introductory Time Series with R Paul S.P. Cowpertwait and Andrew V. Metcalfe http://www.springer.com/statistics/statistical+theory+and+methods/book/9 78-0-387-88697-8 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Duncan Murdoch Sent: 27 October 2011 16:29 To: rgui Cc: r-help@r-project.org Subject: Re: [R] package for time series On 27/10/2011 11:08 AM, rgui wrote: hi, I want any suggestion for a differents packages to manipulate a time series. thanks for help. See the Time Series task view on http://cran.r-project.org/web/views/. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. LEGAL NOTICE This message is intended for the use o...{{dropped:10}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Syntax Check: rshape2 melt()
On Thu, 27 Oct 2011, Nordlund, Dan (DSHS/RDA) wrote: You should be able to get what you want using the dcast function (I think). test.melted - melt(tds.anal) dcast(test.melted, site + sampdate ~ param) Dan, I don't think the data frame melted properly. I tried the dcast() but sampdate is not found: c.tds.anal - dcast(m.tds.anal, site + sampdate ~ param) Error in eval(expr, envir, enclos) : object 'sampdate' not found Perhaps I still need to better understand the parameters in the melt() function. Rich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] creating vector os zeros for simulations (beginner's question)
you could try this: u2=matrix(rnorm(150), nrow=5, ncol=30); u2 Seb On Thu, Oct 27, 2011 at 1:44 PM, Iara Faria iarag...@yahoo.com.br wrote: Dear R helpers, I know this is a simple task, but I'm new to R and I'm still havind difficulties with the language. I want to create 30 vectors to be used in a simulation, each with 1 columm and 5 lines, of random numbers N(0,1). What I tried was this: N=150 u2-rep(1:150,0) u2-list(matrix(0,5)) u2 for(i in 1:N) { u2[i]-rnorm(5) } u2 ### also tried this: N=150 u2-rep((matrix(0,5)),30) u2 for(i in 1:N) { u2[i]-rnorm(5) } u2 The problem is none of this gives me the random numbers arranged in vectors. I've tried other variations too, but haven't managed to get it through. Any help is very welcome. Kind regards, Iara [[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] help with parallel processing code
sorry for noise the simulated data should be like this d=data.frame(replicate(9, rnorm(40)+10),rep(c('y','n'),20)) colnames(d)-c(LEPTIN,SAA,PTH,sEGFR,IGFBP6,MMP2,OPG,IGFBP3,PDGFAABB,group) -- View this message in context: http://r.789695.n4.nabble.com/help-with-parallel-processing-code-tp3944303p3944922.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 time series
if you are a beginer then try this http://www.stat.pitt.edu/stoffer/tsa2/R_time_series_quick_fix.htm there are lots of books and their exercises available on the authors website. also search in google books http://books.google.com/books?id=0fRcUmyhUIQCprintsec=frontcoversource=gbs_ge_summary_rcad=0#v=onepageqf=false. regards sharad -- View this message in context: http://r.789695.n4.nabble.com/package-for-time-series-tp3944825p3944878.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] plotting large time series
hello, I got a problem with plotting large time series, since I want to store the results in a .PDF file (I want to store several pages of plots). The PDF files get too large to be handled ( 10MB, one was even 200MB big). So I wonder, if there would be a possibilty to either - reduce the file size of the PDF - change the way the plot is generated to reduce the plot size? I use: plot(myDate,myFile[,1],type=l,xlab=Date) using myts = as.ts(start=myDate[1],end=myDate[length(myDate)],x=myFile[,1]) plot.ts(myts,xlab=Date) produces the same file size. for storing the PDF I use: pdf(file=paste(outpath,myPDF.pdf,sep=''),paper=a4r). I would be very grateful for an answer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with parallel processing code
my modification gives me error rows- c(1:nrow(mat)) scores - c() labels -c() itr-1000 chnksz-ceiling(itr/getDoParWorkers()) smpopt=list(chunkSize=chnksz) foreach(icount(itr),.combine=cbind,.options.smp=smpopts)%dopar% + { + train - sample(rows, length(rows)-1) + label =0 ; if (mat$Self_T1D[-train] == N) label = 1 #need the value for this line, should it be 'N' or 'Y' + z - lda(mat[train,4] ~ mat[train,1:3]) + score = predict(z, mat[-train, ])$pos[1] + scores - c(scores, score) + labels- c(labels, label) + } Error in { : task 1 failed - could not find function lda -- View this message in context: http://r.789695.n4.nabble.com/help-with-parallel-processing-code-tp3944303p3945243.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] Using optim with parameters that are factors (instead of continuous parameters)
Ben, Thank you for the incredibly helpful suggestions and links. I've been exploring each over the past few days, and for anyone else's future reference, here's what I've found. (1) I was able to use SANN to specify how to choose new candidate solutions, but I wasn't able to easily use SANN for a model that includes both discrete and continuous parameters. That would require designating two separate rules for choosing new candidate solutions -- one rule for the continuous parameters and one rule for the discrete parameters. (2) Your second suggestion ended up solving the problem best for the needs of this data. I wrote a continuous function that looks a lot like a discrete pulse, and optim was able to find its way towards the specification with the maximum likelihood. A function of the general form f(x) = 1/(k + (c - x)^n) does the trick, where c represents the location of the discrete jump. I then optimized over potential values of c. (3) Generating log-likelihoods for each separate value of the parameter works well, especially for a parameter with few potential values. Since I'm also running a specification with individual-specific thresholds, however, re-running the regression five times for each individual is a little unwieldy. So it made the most sense to use solution #2. Thanks again for your prompt and productive response! Lucas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Redundancy canonical analysis plot problem in 3D using VEGAN, RGL, SCATTERPLOT3D and SFSMISC
Hi Guys, First, English is not my native language so sorry if the question is too difficult to understand. I can rephrase it if necessary. I have 32-bit Windows Xp SP3, i use R version 2.12.0 (2010-10-15), and the question is about Redundancy canonical analysis plot problem in 3D using VEGAN, RGL, SCATTERPLOT3D and SFSMISC. I noticed the following code to explain as clearly as possible the problems encountered. I am not able to add species scores from RDA results in 3D plot like i can in 2D plot. With the code i used , i get errors like ; ERROR dans t$sites : $ operator is invalid for atomic vectors, Erreur dans match.arg (display, items) : 'arg' should be one of xyz.convert, points3d, plane3d, box3d, points, arrows I saw that I can use other functions, but it is impossible to extract the 3D scores ( and add species to 3d plot ), Other fonctions works but, add elements in a 2D space. How can I add the species scores (sites and arrows are added correctly) to the 3D plot as with the 2D plot. Thank you for your help, Sincerely, Thomas University of Quebec at Trois-Rivieres , Canada Environmental science MSC student. rouss...@uqtr.ca, thomasbeaum...@hotmail.com Here is the noticed code I used; - CODE # Load library library(vegan) library(rgl) library(scatterplot3d) library(sfsmisc) # Import data ALLMAS - read.table(C:/data.txt, header=TRUE, sep=, na.strings=NA, dec=., strip.white=TRUE # Define var. X -ALLMAS[,c(10,14,15,16,18,19,22)] # env. (7) var. Y -ALLMAS[,c(9,3:6)] # y. (4) var Z -ALLMAS[,c(25)] # Z. (1) var covariate ENVIESRDA -rda(Y,X,Z) # Redundancy canonical analysis pl - ordiplot3d(ENVIESRDA, angle=15, type=n) # Get $Points (1:2) , get $arrows (1:2) text(pl, arrows, col=blue, pos=3, cex = 1) # Text env. var in plot text(pl, points, col=red, pos=1, cex = 0.5) # Point sites (y.var) in plot text(pl, species, col=blue, cex=0.8) # Text species in plot , # I get the following error message: # Erreur dans match.arg(display, items) : # 'arg' should be one of xyz.convert, points3d, plane3d, box3d, points, arrows # I saw that I can use other functions, but it is impossible to extract the 3D scores. Other features add elements in a 2D space. # Then I try the following code, which works well in 2D when I extract the summary of the results of the RDA. t -summary(ENVIESRDA,scal=2) # t -summary(pl,scal=2) # I get ; # Length Class Mode # xyz.convert 1 -none- function # points3d 1 -none- function # plane3d 1 -none- function # box3d 1 -none- function # points 48 -none- numeric # arrows 14 -none- numeric # Points = sites but where is species scores ? X =t$sites[,1] # ERROR dans t$sites : $ operator is invalid for atomic vectors Y =t$sites[,2] t$sites summary(ENVIESRDA, step=1000, perm.max=1000) # Summary anova(ENVIESRDA, step=1000, perm.max=1000) # Anova # Draw arrows to connect the sites with each other before / after study. # But I can't get the new coordinates of 3D graphics using the function summary. stn2= p.arrows(X[1],Y[1], X[13],Y[13],fill=red,width=1) stn3= p.arrows(X[2],Y[2], X[14],Y[14],fill=yellow,width=1) stn4= p.arrows(X[3],Y[3], X[15],Y[15],fill=yellow,width=1) stn5= p.arrows(X[4],Y[4], X[16],Y[16],fill=red,width=1) stn6= p.arrows(X[5],Y[5], X[17],Y[17],fill=yellow,width=1) stn7= p.arrows(X[6],Y[6], X[18],Y[18],fill=red,width=1) stn9= p.arrows(X[7],Y[7], X[19],Y[19],fill=yellow,width=1) stn10= p.arrows(X[8],Y[8], X[20],Y[20],fill=yellow,width=1) stn11= p.arrows(X[9],Y[9], X[21],Y[21],fill=red,width=1) stn12= p.arrows(X[10],Y[10], X[22],Y[22],fill=yellow,width=1) stn13= p.arrows(X[11],Y[11], X[23],Y[23],fill=red,width=1) stn18= p.arrows(X[12],Y[12], X[24],Y[24],fill=red,width=1) stn19= p.arrows(X[13],Y[13], X[25],Y[25],fill=red,width=1) # END - Courriel expédié via https://courriel.uqtr.ca [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Trying to create a function to extract values from a matrix
Thanks Michael, this worked great. Stephen -- View this message in context: http://r.789695.n4.nabble.com/Trying-to-create-a-function-to-extract-values-from-a-matrix-tp3944737p3945236.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] Syntax Check: rshape2 melt()
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Rich Shepard Sent: Thursday, October 27, 2011 11:17 AM To: r-help@r-project.org Subject: Re: [R] Syntax Check: rshape2 melt() On Thu, 27 Oct 2011, Nordlund, Dan (DSHS/RDA) wrote: You should be able to get what you want using the dcast function (I think). test.melted - melt(tds.anal) dcast(test.melted, site + sampdate ~ param) Dan, I don't think the data frame melted properly. I tried the dcast() but sampdate is not found: c.tds.anal - dcast(m.tds.anal, site + sampdate ~ param) Error in eval(expr, envir, enclos) : object 'sampdate' not found Perhaps I still need to better understand the parameters in the melt() function. Rich Rich, I read in the sample data that you put in an earlier post. tds.anal - read.table('clipboard',header=TRUE) tds.anal site sampdate param quant 1UDS-O 2006-12-06 TDS 10800 4 STC-FS 1996-06-14 Cond 280 7UDS-O 2007-10-04Mg 1620 9UDS-O 2007-10-04 SO4 7580 19 JCM-10B 2007-06-21Ca79 20 JCM-10B 2007-06-21Cl 114 Then ran the following code library(reshape2) melt(tds.anal) Using site, sampdate, param as id variables site sampdate param variable value 1 UDS-O 2006-12-06 TDSquant 10800 2 STC-FS 1996-06-14 Condquant 280 3 UDS-O 2007-10-04Mgquant 1620 4 UDS-O 2007-10-04 SO4quant 7580 5 JCM-10B 2007-06-21Caquant79 6 JCM-10B 2007-06-21Clquant 114 dcast(melt(tds.anal), site + sampdate ~ param) Using site, sampdate, param as id variables site sampdate Ca Cl Cond Mg SO4 TDS 1 JCM-10B 2007-06-21 79 114 NA NA NANA 2 STC-FS 1996-06-14 NA NA 280 NA NANA 3 UDS-O 2006-12-06 NA NA NA NA NA 10800 4 UDS-O 2007-10-04 NA NA NA 1620 7580NA So you can see that at least it worked for me. Can you show us the actual output you get when running the melt and dcast functions on a sample of your data? I am not sure why sampdate is not found since it appears to be in your original sample data. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] loading RMySQL - location of MySQL install
I am having trouble loading RMySQL after installing it. I have looked at archived r-help files and it seems many people have had issues, but I didn't find my specific issue. I also went to the webpage at Vanderbilt (http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL) and followed the instructions as best I understood them: - I created a file called Renviron.site under etc in the R folder. In it, I tried to put a pointer to where MySQL is. I tried: - MYSQL_HOME=C:/PROGRA~1/MySQL/MYSQL~Server~5.5/ - MYSQL_HOME=C:/PROGRA~1/MySQL/MYSQLS~5.5/bin (which are guesses at how this should be written from the example on the webpage.) - MYSQL_HOME=C:/Program Files/MySQL/MySQL Server 5.5 (the actual location; n.b. adding \bin yields the location of the mysql.exe file) - I then re-start R and attempt to load the package. - I get the following error messages: Loading required package: DBI Error : MYSQL_HOME was set but does not point to a directory Error : .onLoad failed in 'loadNamespace' for 'RMySQL' Error: package/namespace load failed for 'RMySQL' Does anyone know how to write this so that it does point to the directory properly?Or, what else might be the problem? Thanks, Jeff PS, I am running windows XP media edition and R 2.10.1, if that matters. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Syntax Check: rshape2 melt()
On Thu, 27 Oct 2011, Nordlund, Dan (DSHS/RDA) wrote: What I think you want is as simple as test.melted - melt(test) Dan, et al.: No, it's not that simple. Unfortunately. I've tried various combinations of id.vars, measure.vars, and variable, but just cannot get the dates to display in the melted data frame. For example, m.tds.anal - melt(tds.anal, id.vars = c('site', 'param'), measure.vars = 'sampdate', variable.name = 'variable', na.rm = T, value.name = 'quant') head(m.tds.anal) site param variable quant 1 UDS-O TDS sampdate 13488 2 STC-FS Cond sampdate 9661 3 UDS-OMg sampdate 13790 4 UDS-O SO4 sampdate 13790 5 JCM-10BCa sampdate 13685 6 JCM-10BCl sampdate 13685 No matter where I put 'sampdate' it displays as that string rather than as the date itself. Rich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 time series
On Thu, 27 Oct 2011, Mehmet Suzen wrote: This book is also pretty good: Introductory Time Series with R Paul S.P. Cowpertwait and Andrew V. Metcalfe http://www.springer.com/statistics/statistical+theory+and+methods/book/9 78-0-387-88697-8 There's also: Time Series Analysis and its Applications, 3rd Ed., With R Examples by Robert H. Shumway and David S. Stoffer. Also published by Springer in their 'Springer Texts in Statistics' series. Rich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] preceding X. and X
Hello, Why do I get preceding X. (that is a and X followed by a period) for negative numbers and an X for positive numbers when I read a csv file? Am I stuck with this? If so, how do I convert it to normal numbers? dat=read.csv(file_path) dat [1] X0.0 X.0.240432350374 X0.355468069625 X.0.211469972378 X1.1812797415 X.0.227975150826 X0.74834842067 X.1.04923922494X0.566058942902X.0.184077147931 [11] X.0.693389240029 X.0.474961946724 X.0.557555716654 X0.374198813899X0.560620781209X.0.0609127295732 X0.645337364133 X0.353711785227X.0.0999146114953 X.0.320711825714 [21] X0.332194935294X0.513794862516X0.228124868198 X0.141250108666X0.879359879038X0.721652892103X.1.14723732497 X.0.0871541975062 X0.302181204959X0.0594492294833 [31] X.0.240723094394 X0.358971714966X.0.42954330242 X.0.0739978455876 X.0.108806367787 X0.616107131373X.0.202669947993 X.0.200450609711 X0.15421692014 X.0.0629346641528 [41] X1.16077454571 X.0.100980386545 X.0.457429357325 X0.128929934631X.0.143442822494 X.1.09050490567X.0.270230489547 X.0.438100470791 X.0.069111547 X0.18367056566 [51] X0.728842996177X0.221986311856X.0.793971624503 X.0.258083713185 X0.460468157809X.0.608552686527 X.0.11024558138 X.0.247014689522 X.0.137467423146 X0.0577133684917 [61] X0.615590960098X.0.210395786553 X0.372979876654 X.0.763661795812 X1.22248872639 X1.17541364078 X1.34965201031 X.0.0653956005331 X0.446173249776X0.738548926264 [71] X0.426787360705X.0.409994430265 X.0.445643675958 etc... Thanks ben [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Syntax Check: rshape2 melt()
On Thu, 27 Oct 2011, Nordlund, Dan (DSHS/RDA) wrote: I read in the sample data that you put in an earlier post. tds.anal - read.table('clipboard',header=TRUE) tds.anal site sampdate param quant 1UDS-O 2006-12-06 TDS 10800 4 STC-FS 1996-06-14 Cond 280 7UDS-O 2007-10-04Mg 1620 9UDS-O 2007-10-04 SO4 7580 19 JCM-10B 2007-06-21Ca79 20 JCM-10B 2007-06-21Cl 114 Dan, In your 'tds.anal' is sampdate a factor or a date? Here it's a date: str(tds.anal) 'data.frame': 11434 obs. of 4 variables: $ site: Factor w/ 143 levels BC-0.5,BC-1,..: 134 127 134 134 73 73 91 91 91 91 ... $ sampdate: Date, format: 2006-12-06 1996-06-14 ... $ param : Factor w/ 7 levels Ca,Cl,Cond,..: 7 3 4 6 1 2 4 5 1 4 ... $ quant : num 10800 280 1620 7580 79 114 301 27.5 381 274 ... I wonder if that's what's not working here. Then ran the following code melt(tds.anal) Using site, sampdate, param as id variables site sampdate param variable value 1 UDS-O 2006-12-06 TDSquant 10800 2 STC-FS 1996-06-14 Condquant 280 3 UDS-O 2007-10-04Mgquant 1620 4 UDS-O 2007-10-04 SO4quant 7580 5 JCM-10B 2007-06-21Caquant79 6 JCM-10B 2007-06-21Clquant 114 When I do this I see: melt(tds.anal) Using site, param as id variables site param variable value 1 UDS-O TDS sampdate 13488.000 2 STC-FS Cond sampdate 9661.000 3 UDS-OMg sampdate 13790.000 4 UDS-O SO4 sampdate 13790.000 5JCM-10BCa sampdate 13685.000 6JCM-10BCl sampdate 13685.000 Notice there's no sampdate here. Rich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] NROW doesn't equal length(x)
Hi, I am converting a data.frame to xts. the data.frame is 4 columns and 1000 rows. I get a message that NROW (x) must match length(order.by) class is data.frame, mode is list when I run dim(x) # I get 1000 4 #which is consistent with 1000 rows and 4 columns NROW (x) # I get 1000 # which is the right answer When I run length on each of columns in x separately using the $ I get 1000, which is the right number too. So length on each of the columns individually gives me the right answer, but length on the data.frame gives me the number of columns instead of the number of rows, is there an explanation thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Syntax Check: rshape2 melt()
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Rich Shepard Sent: Thursday, October 27, 2011 12:00 PM To: r-help@r-project.org Subject: Re: [R] Syntax Check: rshape2 melt() On Thu, 27 Oct 2011, Nordlund, Dan (DSHS/RDA) wrote: I read in the sample data that you put in an earlier post. tds.anal - read.table('clipboard',header=TRUE) tds.anal site sampdate param quant 1UDS-O 2006-12-06 TDS 10800 4 STC-FS 1996-06-14 Cond 280 7UDS-O 2007-10-04Mg 1620 9UDS-O 2007-10-04 SO4 7580 19 JCM-10B 2007-06-21Ca79 20 JCM-10B 2007-06-21Cl 114 Dan, In your 'tds.anal' is sampdate a factor or a date? Here it's a date: str(tds.anal) 'data.frame': 11434 obs. of 4 variables: $ site: Factor w/ 143 levels BC-0.5,BC-1,..: 134 127 134 134 73 73 91 91 91 91 ... $ sampdate: Date, format: 2006-12-06 1996-06-14 ... $ param : Factor w/ 7 levels Ca,Cl,Cond,..: 7 3 4 6 1 2 4 5 1 4 ... $ quant : num 10800 280 1620 7580 79 114 301 27.5 381 274 ... I wonder if that's what's not working here. Then ran the following code melt(tds.anal) Using site, sampdate, param as id variables site sampdate param variable value 1 UDS-O 2006-12-06 TDSquant 10800 2 STC-FS 1996-06-14 Condquant 280 3 UDS-O 2007-10-04Mgquant 1620 4 UDS-O 2007-10-04 SO4quant 7580 5 JCM-10B 2007-06-21Caquant79 6 JCM-10B 2007-06-21Clquant 114 When I do this I see: melt(tds.anal) Using site, param as id variables site param variable value 1 UDS-O TDS sampdate 13488.000 2 STC-FS Cond sampdate 9661.000 3 UDS-OMg sampdate 13790.000 4 UDS-O SO4 sampdate 13790.000 5JCM-10BCa sampdate 13685.000 6JCM-10BCl sampdate 13685.000 Notice there's no sampdate here. Rich Rich, You were right about sampdate as I read it in. How about trying this on your data m.tds.anal - melt(tds.anal, id.vars = c('site', 'sampdate', 'param'), variable.name = 'variable', na.rm = T, value.name = 'quant') wanted - dcast(m.tds.anal, site + sampdate ~ param) Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] NROW doesn't equal length(x)
Data frame is list internally so length(df) = ncol(df) M On Oct 27, 2011, at 2:44 PM, Muhammad Abuizzah izzah...@yahoo.com wrote: Hi, I am converting a data.frame to xts. the data.frame is 4 columns and 1000 rows. I get a message that NROW (x) must match length(order.by) class is data.frame, mode is list when I run dim(x) # I get 1000 4 #which is consistent with 1000 rows and 4 columns NROW (x) # I get 1000 # which is the right answer When I run length on each of columns in x separately using the $ I get 1000, which is the right number too. So length on each of the columns individually gives me the right answer, but length on the data.frame gives me the number of columns instead of the number of rows, is there an explanation thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] preceding X. and X
Figured it out. Solution: dat=read.csv(file_path, header=F) dat V1 V2V3 V4 V5 V6V7 V8V9V10V11V12V13 V14 V15 V16 V17 V18 V19V20 1 0 -0.2404324 0.3554681 -0.21147 1.18128 -0.2279752 0.7483484 -1.049239 0.5660589 -0.1840771 -0.6933892 -0.4749619 -0.5575557 0.3741988 0.5606208 -0.06091273 0.6453374 0.3537118 -0.09991461 -0.3207118 V21 V22 V23 V24 V25 V26 V27V28 V29V30V31 V32V33 V34V35 V36V37V38 V39 1 0.3321949 0.5137949 0.2281249 0.1412501 0.8793599 0.7216529 -1.147237 -0.0871542 0.3021812 0.05944923 -0.2407231 0.3589717 -0.4295433 -0.07399785 -0.1088064 0.6161071 -0.2026699 -0.2004506 0.1542169 V40 V41V42V43 V44V45 V46V47V48 V49 V50 V51 V52 V53V54 V55V56V57V58 1 -0.06293466 1.160775 -0.1009804 -0.4574294 0.1289299 -0.1434428 -1.090505 -0.2702305 -0.4381005 -0.0691 0.1836706 0.728843 0.2219863 -0.7939716 -0.2580837 0.4604682 -0.6085527 -0.1102456 -0.2470147 V59V60 V61V62 V63V64 V65 V66 V67V68 V69 V70 V71 V72V73 V74 V75V76V77 1 -0.1374674 0.05771337 0.615591 -0.2103958 0.3729799 -0.7636618 1.222489 1.175414 1.349652 -0.0653956 0.4461732 0.7385489 0.4267874 -0.4099944 -0.4456437 0.1310654 0.5912901 0.03645256 -0.1760742 V78 V79 V80 Thanks, Ben On Thu, Oct 27, 2011 at 1:12 PM, Justin Haynes jto...@gmail.com wrote: Id look at the actual csv file. I assume it has the X there also. sounds like a good candidate for some data munging tools first before you bring it into R. also ?str of the data would be helpful. My first guess is those are all being read as column names. Were they data in the data.frame dat the should be quoted: dat-c('X0.0','X.0.24','X0.35','X.0.211') dat [1] X0.0X.0.24 X0.35 X.0.211 versus: names(dat)-c('col_one','X.0.44',0.65,'last_col') dat col_oneX.0.44 0.65 last_col X0.0 X.0.24 X0.35 X.0.211 However, if you want to use R to clean it up, I'd use the stringr package. library(stringr) dat-str_replace(dat,'X.0.','-0.') dat [1] X0.0 -0.24 X0.35 -0.211 dat-str_replace(dat,'X','') dat [1] 0.0-0.24 0.35 -0.211 dat-as.numeric(dat) dat [1] 0.000 -0.240 0.350 -0.211 hope that helps, Justin On Thu, Oct 27, 2011 at 11:47 AM, Ben quant ccqu...@gmail.com wrote: Hello, Why do I get preceding X. (that is a and X followed by a period) for negative numbers and an X for positive numbers when I read a csv file? Am I stuck with this? If so, how do I convert it to normal numbers? dat=read.csv(file_path) dat [1] X0.0 X.0.240432350374 X0.355468069625 X.0.211469972378 X1.1812797415 X.0.227975150826 X0.74834842067 X.1.04923922494X0.566058942902X.0.184077147931 [11] X.0.693389240029 X.0.474961946724 X.0.557555716654 X0.374198813899X0.560620781209X.0.0609127295732 X0.645337364133 X0.353711785227X.0.0999146114953 X.0.320711825714 [21] X0.332194935294X0.513794862516X0.228124868198 X0.141250108666X0.879359879038X0.721652892103X.1.14723732497 X.0.0871541975062 X0.302181204959X0.0594492294833 [31] X.0.240723094394 X0.358971714966X.0.42954330242 X.0.0739978455876 X.0.108806367787 X0.616107131373X.0.202669947993 X.0.200450609711 X0.15421692014 X.0.0629346641528 [41] X1.16077454571 X.0.100980386545 X.0.457429357325 X0.128929934631X.0.143442822494 X.1.09050490567X.0.270230489547 X.0.438100470791 X.0.069111547 X0.18367056566 [51] X0.728842996177X0.221986311856X.0.793971624503 X.0.258083713185 X0.460468157809X.0.608552686527 X.0.11024558138 X.0.247014689522 X.0.137467423146 X0.0577133684917 [61] X0.615590960098X.0.210395786553 X0.372979876654 X.0.763661795812 X1.22248872639 X1.17541364078 X1.34965201031 X.0.0653956005331 X0.446173249776X0.738548926264 [71] X0.426787360705X.0.409994430265 X.0.445643675958 etc... Thanks ben [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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
Re: [R] help with parallel processing code
Did you load the class package before calling lda()? Dennis On Thu, Oct 27, 2011 at 10:14 AM, 1Rnwb sbpuro...@gmail.com wrote: my modification gives me error rows- c(1:nrow(mat)) scores - c() labels -c() itr-1000 chnksz-ceiling(itr/getDoParWorkers()) smpopt=list(chunkSize=chnksz) foreach(icount(itr),.combine=cbind,.options.smp=smpopts)%dopar% + { + train - sample(rows, length(rows)-1) + label =0 ; if (mat$Self_T1D[-train] == N) label = 1 #need the value for this line, should it be 'N' or 'Y' + z - lda(mat[train,4] ~ mat[train,1:3]) + score = predict(z, mat[-train, ])$pos[1] + scores - c(scores, score) + labels- c(labels, label) + } Error in { : task 1 failed - could not find function lda -- View this message in context: http://r.789695.n4.nabble.com/help-with-parallel-processing-code-tp3944303p3945243.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] preceding X. and X
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Ben quant Sent: Thursday, October 27, 2011 12:26 PM To: r-help@r-project.org Subject: Re: [R] preceding X. and X Figured it out. Solution: dat=read.csv(file_path, header=F) dat V1 V2V3 V4 V5 V6V7 V8V9V10V11V12V13 V14 V15 V16 V17 V18 V19V20 1 0 -0.2404324 0.3554681 -0.21147 1.18128 -0.2279752 0.7483484 - 1.049239 0.5660589 -0.1840771 -0.6933892 -0.4749619 -0.5575557 0.3741988 0.5606208 -0.06091273 0.6453374 0.3537118 -0.09991461 -0.3207118 V21 V22 V23 V24 V25 V26 V27V28 V29V30V31 V32V33 V34V35 V36V37V38 V39 1 0.3321949 0.5137949 0.2281249 0.1412501 0.8793599 0.7216529 -1.147237 -0.0871542 0.3021812 0.05944923 -0.2407231 0.3589717 -0.4295433 - 0.07399785 -0.1088064 0.6161071 -0.2026699 -0.2004506 0.1542169 V40 V41V42V43 V44V45 V46V47V48 V49 V50 V51 V52 V53V54 V55V56V57V58 1 -0.06293466 1.160775 -0.1009804 -0.4574294 0.1289299 -0.1434428 - 1.090505 -0.2702305 -0.4381005 -0.0691 0.1836706 0.728843 0.2219863 - 0.7939716 -0.2580837 0.4604682 -0.6085527 -0.1102456 -0.2470147 V59V60 V61V62 V63V64 V65 V66 V67V68 V69 V70 V71 V72V73 V74 V75V76V77 1 -0.1374674 0.05771337 0.615591 -0.2103958 0.3729799 -0.7636618 1.222489 1.175414 1.349652 -0.0653956 0.4461732 0.7385489 0.4267874 -0.4099944 -0.4456437 0.1310654 0.5912901 0.03645256 -0.1760742 V78 V79 V80 Thanks, Ben On Thu, Oct 27, 2011 at 1:12 PM, Justin Haynes jto...@gmail.com wrote: Id look at the actual csv file. I assume it has the X there also. sounds like a good candidate for some data munging tools first before you bring it into R. also ?str of the data would be helpful. My first guess is those are all being read as column names. Were they data in the data.frame dat the should be quoted: dat-c('X0.0','X.0.24','X0.35','X.0.211') dat [1] X0.0X.0.24 X0.35 X.0.211 versus: names(dat)-c('col_one','X.0.44',0.65,'last_col') dat col_oneX.0.44 0.65 last_col X0.0 X.0.24 X0.35 X.0.211 However, if you want to use R to clean it up, I'd use the stringr package. library(stringr) dat-str_replace(dat,'X.0.','-0.') dat [1] X0.0 -0.24 X0.35 -0.211 dat-str_replace(dat,'X','') dat [1] 0.0-0.24 0.35 -0.211 dat-as.numeric(dat) dat [1] 0.000 -0.240 0.350 -0.211 hope that helps, Justin On Thu, Oct 27, 2011 at 11:47 AM, Ben quant ccqu...@gmail.com wrote: Hello, Why do I get preceding X. (that is a and X followed by a period) for negative numbers and an X for positive numbers when I read a csv file? Am I stuck with this? If so, how do I convert it to normal numbers? dat=read.csv(file_path) dat [1] X0.0 X.0.240432350374 X0.355468069625 X.0.211469972378 X1.1812797415 X.0.227975150826 X0.74834842067 Ben, Are you sure that is what you want? What is the result of running str(dat) Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Syntax Check: rshape2 melt()
Try this, based on your small example: tds.a - read.table(textConnection( + site sampdate param quant + 1UDS-O 2006-12-06 TDS 10800 + 4 STC-FS 1996-06-14 Cond 280 + 7UDS-O 2007-10-04Mg 1620 + 9UDS-O 2007-10-04 SO4 7580 + 19 JCM-10B 2007-06-21Ca79 + 20 JCM-10B 2007-06-21Cl 114), header = TRUE, stringsAsFactors = FALSE) closeAllConnections() # Define param so that all of its levels are represented: tds.a - within(tds.a, { param = factor(param, levels = c('TDS', 'Cond', 'Mg', 'Ca', 'Cl', 'Na', 'SO4')) sampdate = as.Date(sampdate) } ) library('reshape2') dcast(tds.a, site + sampdate ~ param, value_var = 'quant') # Result: site sampdate TDS Cond Mg Ca Cl SO4 1 JCM-10B 2007-06-21NA NA NA 79 114 NA 2 STC-FS 1996-06-14NA 280 NA NA NA NA 3 UDS-O 2006-12-06 10800 NA NA NA NA NA 4 UDS-O 2007-10-04NA NA 1620 NA NA 7580 HTH, Dennis On Thu, Oct 27, 2011 at 8:26 AM, Rich Shepard rshep...@appl-ecosys.com wrote: This is my first excursion into using reshape2 and I want to ensure that the melt() function call is syntactically correct. The unmodifed data frame is organized this way: head(tds.anal) site sampdate param quant 1 UDS-O 2006-12-06 TDS 10800 4 STC-FS 1996-06-14 Cond 280 7 UDS-O 2007-10-04 Mg 1620 9 UDS-O 2007-10-04 SO4 7580 19 JCM-10B 2007-06-21 Ca 79 20 JCM-10B 2007-06-21 Cl 114 What I want looks like this: site sampdate TDS Cond Mg Ca Cl Na SO4 UDS-O 2006-12-06 10800 NA 1620 NA NA NA 7580 with the actual data for each param, of course. I've read the reshape.pdf, reshape2.pdf, the ?melt help page, and the ?melt.data.frame help page. I'm still unclear on the differences among measure.vars, variable.name, and value.name. After several attempts I have what may be what the melted tds.anal should look like: m.tds.anal - melt(tds.anal, id.vars = c('site', 'sampdate', 'param'), \ measure.vars = 'quant', value.name = 'quant', na.rm = F) head(m.tds.anal) site sampdate param variable quant 1 UDS-O 2006-12-06 TDS quant 10800 2 STC-FS 1996-06-14 Cond quant 280 3 UDS-O 2007-10-04 Mg quant 1620 4 UDS-O 2007-10-04 SO4 quant 7580 5 JCM-10B 2007-06-21 Ca quant 79 6 JCM-10B 2007-06-21 Cl quant 114 Is the melt() function call correct? Should the melted result look like the unmelted (long form in Paul Dalgaard's book) data with the additional 'variable' column containing 'quant' for each row? Rich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] loading RMySQL - location of MySQL install
(I apologize if this ends up being posted twice, I tried to post it earlier, and it didn't seem to 'take'.) I am having trouble loading RMySQL after installing it. I have looked at archived r-help files and it seems many people have had issues, but I didn't find my specific issue. I also went to the webpage at Vanderbilt (http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL) and followed the instructions as best I understood them: - I created a file called Renviron.site under etc in the R folder. In it, I tried to put a pointer to where MySQL is. I tried: - MYSQL_HOME=C:/PROGRA~1/MySQL/MYSQL~Server~5.5/ - MYSQL_HOME=C:/PROGRA~1/MySQL/MYSQLS~5.5/bin (which are guesses at how this should be written from the example on the webpage.) - MYSQL_HOME=C:/Program Files/MySQL/MySQL Server 5.5 (the actual location; n.b. adding \bin yields the location of the mysql.exe file) - I then re-start R and attempt to load the package. - I get the following error messages: Loading required package: DBI Error : MYSQL_HOME was set but does not point to a directory Error : .onLoad failed in 'loadNamespace' for 'RMySQL' Error: package/namespace load failed for 'RMySQL' Does anyone know how to write this so that it does point to the directory properly?Or, what else might be the problem? Thanks, Jeff PS, I am running windows XP media edition and R 2.10.1, if that matters. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] loading RMySQL - location of MySQL install
On Thu, Oct 27, 2011 at 1:46 PM, Jeff Laux jeffl...@gmail.com wrote: I am having trouble loading RMySQL after installing it. I have looked at archived r-help files and it seems many people have had issues, but I didn't find my specific issue. I also went to the webpage at Vanderbilt (http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL) and followed the instructions as best I understood them: - I created a file called Renviron.site under etc in the R folder. In it, I tried to put a pointer to where MySQL is. I tried: - MYSQL_HOME=C:/PROGRA~1/MySQL/MYSQL~Server~5.5/ - MYSQL_HOME=C:/PROGRA~1/MySQL/MYSQLS~5.5/bin (which are guesses at how this should be written from the example on the webpage.) - MYSQL_HOME=C:/Program Files/MySQL/MySQL Server 5.5 (the actual location; n.b. adding \bin yields the location of the mysql.exe file) - I then re-start R and attempt to load the package. - I get the following error messages: Loading required package: DBI Error : MYSQL_HOME was set but does not point to a directory Error : .onLoad failed in 'loadNamespace' for 'RMySQL' Error: package/namespace load failed for 'RMySQL' Does anyone know how to write this so that it does point to the directory properly?Or, what else might be the problem? Thanks, Jeff PS, I am running windows XP media edition and R 2.10.1, if that matters. Check out: http://r.789695.n4.nabble.com/RMySQL-problem-on-Windows-7-32-bit-tt3520472.html#a3522409 -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Syntax Check: rshape2 melt()
So I was using the rshape package rather than rshape2. I don't know the relationship between those two packages and/or how they differ. I am sure that there are others that can help you out here. I, too, don't know how the two packages 'reshape, The Orignal' and 'reshape2, Rebooted' differ. The two articles by Hadley that I read (Statistical Computing and Graphics, 2005, and Journal of Statistical Software, 2007) do not explicitly specify which version of reshape is addressed. See here: https://github.com/hadley/reshape -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University 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] preceding X. and X
I think it is what I want. The values look OK. I do get a warning. Here is what you asked for: dat=read.csv(file_path, header=F) Warning message: In read.table(file = file, header = header, sep = sep, quote = quote, : incomplete final line found by readTableHeader on 'y:\ALL STRATEGIES\INVEST-TRADING\Zacks\RCsvData\VarPortRtns.csv' str(dat) 'data.frame': 1 obs. of 251 variables: $ V1 : num 0 $ V2 : num -0.24 $ V3 : num 0.355 $ V4 : num -0.211 $ V5 : num 1.18 $ V6 : num -0.228 $ V7 : num 0.748 $ V8 : num -1.05 $ V9 : num 0.566 $ V10 : num -0.184 $ V11 : num -0.693 ...etc dat V1 V2V3 V4 V5 V6V7 V8V9V10V11V12V13 V14 V15 V16 V17 V18 V19V20 1 0 -0.2404324 0.3554681 -0.21147 1.18128 -0.2279752 0.7483484 -1.049239 0.5660589 -0.1840771 -0.6933892 -0.4749619 -0.5575557 0.3741988 0.5606208 -0.06091273 0.6453374 0.3537118 -0.09991461 -0.3207118 V21 V22 V23 V24 V25 V26 V27V28 V29V30V31 V32V33 V34V35 V36V37V38 V39 1 0.3321949 0.5137949 0.2281249 0.1412501 0.8793599 0.7216529 -1.147237 -0.0871542 0.3021812 0.05944923 -0.2407231 0.3589717 -0.4295433 -0.07399785 -0.1088064 0.6161071 -0.2026699 -0.2004506 0.1542169 V40 V41V42V43 V44V45 V46V47V48 V49 V50 V51 V52 V53V54 V55V56V57V58 1 -0.06293466 1.160775 -0.1009804 -0.4574294 0.1289299 -0.1434428 -1.090505 -0.2702305 -0.4381005 -0.0691 0.1836706 0.728843 0.2219863 -0.7939716 -0.2580837 0.4604682 -0.6085527 -0.1102456 -0.2470147 V5 ...etc... Ben On Thu, Oct 27, 2011 at 1:37 PM, Nordlund, Dan (DSHS/RDA) nord...@dshs.wa.gov wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Ben quant Sent: Thursday, October 27, 2011 12:26 PM To: r-help@r-project.org Subject: Re: [R] preceding X. and X Figured it out. Solution: dat=read.csv(file_path, header=F) dat V1 V2V3 V4 V5 V6V7 V8V9V10V11V12V13 V14 V15 V16 V17 V18 V19V20 1 0 -0.2404324 0.3554681 -0.21147 1.18128 -0.2279752 0.7483484 - 1.049239 0.5660589 -0.1840771 -0.6933892 -0.4749619 -0.5575557 0.3741988 0.5606208 -0.06091273 0.6453374 0.3537118 -0.09991461 -0.3207118 V21 V22 V23 V24 V25 V26 V27V28 V29V30V31 V32V33 V34V35 V36V37V38 V39 1 0.3321949 0.5137949 0.2281249 0.1412501 0.8793599 0.7216529 -1.147237 -0.0871542 0.3021812 0.05944923 -0.2407231 0.3589717 -0.4295433 - 0.07399785 -0.1088064 0.6161071 -0.2026699 -0.2004506 0.1542169 V40 V41V42V43 V44V45 V46V47V48 V49 V50 V51 V52 V53V54 V55V56V57V58 1 -0.06293466 1.160775 -0.1009804 -0.4574294 0.1289299 -0.1434428 - 1.090505 -0.2702305 -0.4381005 -0.0691 0.1836706 0.728843 0.2219863 - 0.7939716 -0.2580837 0.4604682 -0.6085527 -0.1102456 -0.2470147 V59V60 V61V62 V63V64 V65 V66 V67V68 V69 V70 V71 V72V73 V74 V75V76V77 1 -0.1374674 0.05771337 0.615591 -0.2103958 0.3729799 -0.7636618 1.222489 1.175414 1.349652 -0.0653956 0.4461732 0.7385489 0.4267874 -0.4099944 -0.4456437 0.1310654 0.5912901 0.03645256 -0.1760742 V78 V79 V80 Thanks, Ben On Thu, Oct 27, 2011 at 1:12 PM, Justin Haynes jto...@gmail.com wrote: Id look at the actual csv file. I assume it has the X there also. sounds like a good candidate for some data munging tools first before you bring it into R. also ?str of the data would be helpful. My first guess is those are all being read as column names. Were they data in the data.frame dat the should be quoted: dat-c('X0.0','X.0.24','X0.35','X.0.211') dat [1] X0.0X.0.24 X0.35 X.0.211 versus: names(dat)-c('col_one','X.0.44',0.65,'last_col') dat col_oneX.0.44 0.65 last_col X0.0 X.0.24 X0.35 X.0.211 However, if you want to use R to clean it up, I'd use the stringr package. library(stringr) dat-str_replace(dat,'X.0.','-0.') dat [1] X0.0 -0.24 X0.35 -0.211 dat-str_replace(dat,'X','') dat [1] 0.0-0.24 0.35 -0.211 dat-as.numeric(dat) dat [1] 0.000 -0.240 0.350 -0.211 hope that helps, Justin On Thu, Oct 27, 2011 at 11:47 AM, Ben quant
Re: [R] Using functions written in Fortran in R
On 28/10/11 01:13, Duncan Murdoch wrote: SNIP I think nowadays many Linux distros are no more ready than Windows for this. On Linux, you'll likely need to install development libraries and tools; on Windows, the same. The advantage of Windows is that the tools have all been collected in one place (www.murdoch-sutherland.com/Rtools), so it's pretty easy to get everything going. SNIP Then how come Uwe Ligges provides a win.builder facility for Linux users to build packages for Windoze, but there is no corresponding linux.builder facility for Windoze users to build packages for Linux? :-) [Answer: There is no need, because package building is a breeze on Linux. Even I can do it.] cheers, Rolf P. S. And if Duncan hadn't gone to all the trouble and effort of collecting the tools in one place, building packages on Windoze would be impossible for ordinary mortals. R. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Simple time series question with zoo
New user here. My goal is pull daily averages from a long dataset. I've been working with some code I got from this list from https://stat.ethz.ch/pipermail/r-help/2009-March/191302.html The code how I have been using it is as follows: library(zoo) library(chron) DB-read.table(/Users/me/Desktop/R/data.csv, sep=,, header=TRUE, as.is =TRUE) z-zoo(LTER6$temp, chron(LTER6$Date, LTER6$Time)) z.day=aggregate(z, trunc, mean) #This last line gives me daily averages for my data Simple and elegant- and it works. Thanks to the author the hard part is over. But I plan to tweak it so I have some questions about why this works 1- The data I have has the date and time format as a single string like this 2006-04-09 10:20:00. But the code was set up to read the data in two columns ie- 2006-04-09 10:20:00. Is this how the chrom package expects to have the data, or is there a way I can change the code to read the data as a single column. For now I am chopping up my date and time data manually before I run R. 2- I've read the help on as.is, and I'm not sure why I need that function in the first line of code. This is what my original data looks like (with header) if this helps answer this this question line.site,time_local,time_utc,reef_type_code,sensor_type,sensor_depth_m,temp 06,2006-04-09 10:20:00,2006-04-09 20:20:00,BAK,sb39, 2, 29.63 06,2006-04-09 10:40:00,2006-04-09 20:40:00,BAK,sb39, 2, 29.56 3. Finally- how does the function trunc know to aggregate the data by day? If I wanted to do monthly averages I would need to specify with as.yearmon, but I don't seem to need to specify day anywhere in the code. Thanks in advance. Your help has saved me multiple hours of spreadsheet time. [[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] help with parallel processing code
yes the library(MASS) was loaded. -- View this message in context: http://r.789695.n4.nabble.com/help-with-parallel-processing-code-tp3944303p3945972.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] Correllogram of Daily Time Series
I did it using the code below thank you. Will the fact I have used a ts object but the observations are not really equally spaced invalidate the results? vols=read.csv(file=C:/Documents and Settings/Hugh/My Documents/PhD/Swaption vols.csv + , header=TRUE, sep=,) x-ts(vols[,2]) x acf(x) -- View this message in context: http://r.789695.n4.nabble.com/Correllogram-of-Daily-Time-Series-tp3944094p3945927.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] help with parallel processing code
If i understand correctly you mean to write the line as below: foreach(icount(itr),.combine=combine,.options.smp=smpopts,.packages='MASS')%dopar% -- View this message in context: http://r.789695.n4.nabble.com/help-with-parallel-processing-code-tp3944303p3945954.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] Syntax Check: rshape2 melt()
On Fri, 28 Oct 2011, Hadley Wickham wrote: See here: https://github.com/hadley/reshape Thanks, Hadley. Rich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Syntax Check: rshape2 melt()
On Thu, 27 Oct 2011, Dennis Murphy wrote: # Define param so that all of its levels are represented: tds.a - within(tds.a, { param = factor(param, levels = c('TDS', 'Cond', 'Mg', 'Ca', 'Cl', 'Na', 'SO4')) sampdate = as.Date(sampdate) } ) Dennis, This produces an error: tds.a - within(tds.anal, {param = factor(param, levels = c('TDS', 'Cond', 'Mg', 'Ca', 'Cl', 'Na', 'SO4')) sampdate = as.Date(sampdate)}) Error: unexpected symbol in tds.a - within(tds.anal, {param = factor(param, levels = c('TDS', 'Cond', 'Mg', 'Ca', 'Cl', 'Na', 'SO4')) sampdate So I did the conversion and melting the long way: tds.a - tds.anal tds.a$sampdate - factor(tds.a$sampdate) Now sampdate is a factor, and quant has the proper values: str(tds.a) 'data.frame': 11434 obs. of 4 variables: $ site: Factor w/ 143 levels BC-0.5,BC-1,..: 134 127 134 134 73 73 $ sampdate: Factor w/ 890 levels 1981-11-30,1982-04-28,..: 686 268 727 $ param : Factor w/ 7 levels Ca,Cl,Cond,..: 7 3 4 6 1 2 4 5 1 4 ... $ quant : num 10800 280 1620 7580 79 114 301 27.5 381 274 ... However, ... dcast(tds.a, site + sampdate ~ param, value_var = 'quant') c.tds.anal - dcast(tds.a, site + sampdate ~ param, value_var = 'quant') Aggregation function missing: defaulting to length. That's because c.tds.anal has lost the quant values: str(c.tds.anal) 'data.frame': 2309 obs. of 9 variables: $ site: Factor w/ 143 levels BC-0.5,BC-1,..: 1 1 1 2 2 2 2 2 2 2 ... $ sampdate: Factor w/ 890 levels 1981-11-30,1982-04-28,..: 239 252 260 99 101 102 155 163 170 179 ... $ Ca : int 1 0 0 1 1 1 1 1 0 1 ... $ Cl : int 1 0 0 1 1 1 1 1 0 1 ... $ Cond: int 1 1 1 1 1 1 1 1 1 1 ... $ Mg : int 1 0 0 1 1 1 1 1 0 1 ... $ Na : int 0 0 0 1 1 1 1 1 0 1 ... $ SO4 : int 1 1 1 1 1 1 1 1 0 1 ... $ TDS : int 1 1 1 1 1 1 1 1 0 1 ... I don't see what I did differently from your sample code. Rich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Syntax Check: rshape2 melt()
On Thu, 27 Oct 2011, Rich Shepard wrote: So I did the conversion and melting the long way: tds.a - tds.anal tds.a$sampdate - factor(tds.a$sampdate) I didn't copy the melt command: tds.anal.m - melt(tds.a) However, ... c.tds.anal - dcast(tds.a, site + sampdate ~ param, value_var = 'quant') And the above was actually c.tds.anal - dcast(m.tds.anal ...) but produces the same error. Rich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] combining pairs plot with other plots in one output
I would like to combine multiple plots (one of which is a pairs plot) in one output display: While this works well: layout(matrix(c(1,2,3,3,3,3), ncol=2, byrow=T)) data - matrix(rnorm(1000), ncol=10) boxplot(data) hist(data) plot(data) This doesn't: (because the pairs function seems to override the layout parameters?) layout(matrix(c(1,2,3,3,3,3), ncol=2, byrow=T)) data - matrix(rnorm(1000), ncol=10) boxplot(data) hist(data) pairs(data) Thanks for your help, Uli --- Ulrich Schlecht, PhD 855 South California Avenue Palo Alto, CA-94304, USA [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Syntax Check: rshape2 melt()
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Rich Shepard Sent: Thursday, October 27, 2011 2:41 PM To: r-help@r-project.org Subject: Re: [R] Syntax Check: rshape2 melt() On Thu, 27 Oct 2011, Dennis Murphy wrote: # Define param so that all of its levels are represented: tds.a - within(tds.a, { param = factor(param, levels = c('TDS', 'Cond', 'Mg', 'Ca', 'Cl', 'Na', 'SO4')) sampdate = as.Date(sampdate) } ) Dennis, This produces an error: tds.a - within(tds.anal, {param = factor(param, levels = c('TDS', 'Cond', 'Mg', 'Ca', 'Cl', 'Na', 'SO4')) sampdate = as.Date(sampdate)}) Error: unexpected symbol in tds.a - within(tds.anal, {param = factor(param, levels = c('TDS', 'Cond', 'Mg', 'Ca', 'Cl', 'Na', 'SO4')) sampdate So I did the conversion and melting the long way: tds.a - tds.anal tds.a$sampdate - factor(tds.a$sampdate) Now sampdate is a factor, and quant has the proper values: str(tds.a) 'data.frame': 11434 obs. of 4 variables: $ site: Factor w/ 143 levels BC-0.5,BC-1,..: 134 127 134 134 73 73 $ sampdate: Factor w/ 890 levels 1981-11-30,1982-04-28,..: 686 268 727 $ param : Factor w/ 7 levels Ca,Cl,Cond,..: 7 3 4 6 1 2 4 5 1 4 ... $ quant : num 10800 280 1620 7580 79 114 301 27.5 381 274 ... However, ... dcast(tds.a, site + sampdate ~ param, value_var = 'quant') c.tds.anal - dcast(tds.a, site + sampdate ~ param, value_var = 'quant') Aggregation function missing: defaulting to length. That's because c.tds.anal has lost the quant values: str(c.tds.anal) 'data.frame': 2309 obs. of 9 variables: $ site: Factor w/ 143 levels BC-0.5,BC-1,..: 1 1 1 2 2 2 2 2 2 2 ... $ sampdate: Factor w/ 890 levels 1981-11-30,1982-04-28,..: 239 252 260 99 101 102 155 163 170 179 ... $ Ca : int 1 0 0 1 1 1 1 1 0 1 ... $ Cl : int 1 0 0 1 1 1 1 1 0 1 ... $ Cond: int 1 1 1 1 1 1 1 1 1 1 ... $ Mg : int 1 0 0 1 1 1 1 1 0 1 ... $ Na : int 0 0 0 1 1 1 1 1 0 1 ... $ SO4 : int 1 1 1 1 1 1 1 1 0 1 ... $ TDS : int 1 1 1 1 1 1 1 1 0 1 ... I don't see what I did differently from your sample code. Rich Rich, It appears that what you did differently was to dcast the un-melted data. In addition, you shouldn't need to turn your dates into factors. I assume that your unaltered data is in tds.anal. Melt the data this way: m.tds.anal - melt(tds.anal, id.vars = c('site', 'sampdate', 'param')) Then, cast the data this way: wanted - dcast(m.tds.anal, site + sampdate ~ param) Does this do what you wanted? Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Syntax Check: rshape2 melt()
On Thu, 27 Oct 2011, Nordlund, Dan (DSHS/RDA) wrote: It appears that what you did differently was to dcast the un-melted data. In addition, you shouldn't need to turn your dates into factors. I assume that your unaltered data is in tds.anal. Dan, It's been that sort of a day when that might well have been what I did. So I checked and re-melted the data with similar lack of results. Melt the data this way: m.tds.anal - melt(tds.anal, id.vars = c('site', 'sampdate', 'param')) OK. This yields: head(m.tds.anal) site sampdate param variable value 1 UDS-O 2006-12-06 TDSquant 10800 2 STC-FS 1996-06-14 Condquant 280 3 UDS-O 2007-10-04Mgquant 1620 4 UDS-O 2007-10-04 SO4quant 7580 5 JCM-10B 2007-06-21Caquant79 6 JCM-10B 2007-06-21Clquant 114 Then, cast the data this way: wanted - dcast(m.tds.anal, site + sampdate ~ param) Does this do what you wanted? I still get this error: wanted - dcast(m.tds.anal, site + sampdate ~ param) Aggregation function missing: defaulting to length and the values are replaced by lengths in the output: head(wanted) site sampdate Ca Cl Cond Mg Na SO4 TDS 1 BC-0.5 1996-04-19 1 11 1 0 1 1 2 BC-0.5 1996-05-21 0 01 0 0 1 1 3 BC-0.5 1996-06-02 0 01 0 0 1 1 4 BC-1 1994-05-24 1 11 1 1 1 1 5 BC-1 1994-06-02 1 11 1 1 1 1 6 BC-1 1994-06-10 1 11 1 1 1 1 This is what happens each time I try. That's why I thought that sampdate needed to be a factor rather than a date. I certainly have no idea why I'm not getting valid results, but appreciate the help that you and others provide so I can learn to do this correctly. Thanks again, Rich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Simple time series question with zoo
On Thu, Oct 27, 2011 at 4:18 PM, Vinny Moriarty vwmoria...@gmail.com wrote: New user here. My goal is pull daily averages from a long dataset. I've been working with some code I got from this list from https://stat.ethz.ch/pipermail/r-help/2009-March/191302.html The code how I have been using it is as follows: library(zoo) library(chron) DB-read.table(/Users/me/Desktop/R/data.csv, sep=,, header=TRUE, as.is =TRUE) z-zoo(LTER6$temp, chron(LTER6$Date, LTER6$Time)) z.day=aggregate(z, trunc, mean) #This last line gives me daily averages for my data Simple and elegant- and it works. Thanks to the author the hard part is over. But I plan to tweak it so I have some questions about why this works 1- The data I have has the date and time format as a single string like this 2006-04-09 10:20:00. But the code was set up to read the data in two columns ie- 2006-04-09 10:20:00. Is this how the chrom package expects to have the data, or is there a way I can change the code to read the data as a single column. For now I am chopping up my date and time data manually before I run R. 2- I've read the help on as.is, and I'm not sure why I need that function in the first line of code. This is what my original data looks like (with header) if this helps answer this this question line.site,time_local,time_utc,reef_type_code,sensor_type,sensor_depth_m,temp 06,2006-04-09 10:20:00,2006-04-09 20:20:00,BAK,sb39, 2, 29.63 06,2006-04-09 10:40:00,2006-04-09 20:40:00,BAK,sb39, 2, 29.56 3. Finally- how does the function trunc know to aggregate the data by day? If I wanted to do monthly averages I would need to specify with as.yearmon, but I don't seem to need to specify day anywhere in the code. That link is several years old. Since then the zoo package has gained additional capabilities. Assuming the 2nd field is the desired date/time and the last field on each line is the one you want try this read.zoo statement. See ?read.zoo and also try: vignette(zoo-read) library(zoo) library(chron) # create test file Lines - line.site,time_local,time_utc,reef_type_code,sensor_type,sensor_depth_m,temp 06,2006-04-09 10:20:00,2006-04-09 20:20:00,BAK,sb39, 2, 29.63 06,2006-04-09 10:40:00,2006-04-09 20:40:00,BAK,sb39, 2, 29.56 cat(Lines, \n, file = data.txt) # NULL fields are removed temp - read.zoo(data.txt, FUN = as.chron, header = TRUE, sep = ,, colClasses = c(NULL, NA, NULL, NULL, NULL, NULL, NA)) # daily temp.day - read.zoo(data.txt, FUN = as.Date, header = TRUE, sep = ,, aggregate = mean, colClasses = c(NULL, NA, NULL, NULL, NULL, NULL, NA)) # monthly temp.ym - read.zoo(data.txt, FUN = as.yearmon, header = TRUE, sep = ,, aggregate = mean, colClasses = c(NULL, NA, NULL, NULL, NULL, NULL, NA)) chron represents date/time internally as days since the Epoch + fraction of day for the time. Thus truncating to an integer removes the fractional part (i.e. the time) leaving the day. See R News 4/1. We could alternately just use the Date class in the base of R as shown above. If we had read in temp and wanted to aggregate it rather than read it straight into an aggregated form then here are some possibilities: aggregate(temp, trunc, mean) # daily aggregate(temp, as.Date, mean) # daily with Date class aggregate(temp, as.yearmon, mean) # monthly -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Syntax Check: rshape2 melt()
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Rich Shepard Sent: Thursday, October 27, 2011 4:29 PM To: r-help@r-project.org Subject: Re: [R] Syntax Check: rshape2 melt() On Thu, 27 Oct 2011, Nordlund, Dan (DSHS/RDA) wrote: It appears that what you did differently was to dcast the un-melted data. In addition, you shouldn't need to turn your dates into factors. I assume that your unaltered data is in tds.anal. Dan, It's been that sort of a day when that might well have been what I did. So I checked and re-melted the data with similar lack of results. Melt the data this way: m.tds.anal - melt(tds.anal, id.vars = c('site', 'sampdate', 'param')) OK. This yields: head(m.tds.anal) site sampdate param variable value 1 UDS-O 2006-12-06 TDSquant 10800 2 STC-FS 1996-06-14 Condquant 280 3 UDS-O 2007-10-04Mgquant 1620 4 UDS-O 2007-10-04 SO4quant 7580 5 JCM-10B 2007-06-21Caquant79 6 JCM-10B 2007-06-21Clquant 114 Then, cast the data this way: wanted - dcast(m.tds.anal, site + sampdate ~ param) Does this do what you wanted? I still get this error: wanted - dcast(m.tds.anal, site + sampdate ~ param) Aggregation function missing: defaulting to length and the values are replaced by lengths in the output: head(wanted) site sampdate Ca Cl Cond Mg Na SO4 TDS 1 BC-0.5 1996-04-19 1 11 1 0 1 1 2 BC-0.5 1996-05-21 0 01 0 0 1 1 3 BC-0.5 1996-06-02 0 01 0 0 1 1 4 BC-1 1994-05-24 1 11 1 1 1 1 5 BC-1 1994-06-02 1 11 1 1 1 1 6 BC-1 1994-06-10 1 11 1 1 1 1 This is what happens each time I try. That's why I thought that sampdate needed to be a factor rather than a date. I certainly have no idea why I'm not getting valid results, but appreciate the help that you and others provide so I can learn to do this correctly. Thanks again, Rich Rich, I will be leaving work shortly, and won't be able to look at this again until tomorrow some time. However, I went back and reread the help page on dcast. Here is part of that page. fun.aggregate aggregation function needed if variables do not identify a single observation for each output cell. Defaults to length (with a message) if needed but not specified. It looks like your data may be slightly different than I expected. The fact that dcast is looking for an aggregation function suggests that you have more than one record for some combination of site|sampdate|param. No param value ('TDS', 'SO4', ...) should occur more than once for any combination of site and sampdate (i.e. no multiple measures of the same parameter on the same day in the same site). So, you might want to check your data to make sure you have no more than 1 measurement per param per sampdate per site. If that isn't the problem, then I would start thinking about restarting R and then re-installing reshape2. Good luck. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Syntax Check: rshape2 melt()
On Thu, 27 Oct 2011, Nordlund, Dan (DSHS/RDA) wrote: I will be leaving work shortly, and won't be able to look at this again until tomorrow some time. However, I went back and reread the help page on dcast. Here is part of that page. fun.aggregate aggregation function needed if variables do not identify a single observation for each output cell. Defaults to length (with a message) if needed but not specified. I read that, too, Dan. But did not see how that applies to these data. It looks like your data may be slightly different than I expected. The fact that dcast is looking for an aggregation function suggests that you have more than one record for some combination of site|sampdate|param. No param value ('TDS', 'SO4', ...) should occur more than once for any combination of site and sampdate (i.e. no multiple measures of the same parameter on the same day in the same site). So, you might want to check your data to make sure you have no more than 1 measurement per param per sampdate per site. Nope. Can't. In the database table site, date, param are the compound primary key. Besides, it makes no sense to have two concentration measurements of the same chemical on the same day from the same location. I spent a lot of time getting rid of duplicate records because the same site was listed with two spellings (one with a hyphen, one without) or some records were listed as TDS while others from the same day and location were entered in their spreadsheet as Total Dissolved Solids. That table is clean, and the .csv copy didn't change any values on its way into R. If that isn't the problem, then I would start thinking about restarting R and then re-installing reshape2. Good luck. I'll do that tomorrow. It's sorta' a Microsoft solution: shut down computer, spin around it your chair three times, restart computer. Too bad there is not more detailed diagnostic information about the source of the error, or a way to stick a stub of code in the function call to illucidate just what dcast() thinks it sees. Thanks, Rich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plotting large time series
Try another format (tiff, jpg, etc) to see how they look, what the sizes are for different resolutions. If you have a lot of single points, PDF files get very large because of the commands used to print each point. If you want to keep PDF, then find some way of aggregating the data points so that you plot an average of several of them. Depending on what you are trying to show, I have used the hexbin package to plot large numbers of points. Why do you need PDFs? Will something else do? On Thu, Oct 27, 2011 at 11:39 AM, Agnes Richard agnes.rich...@fhnw.ch wrote: hello, I got a problem with plotting large time series, since I want to store the results in a .PDF file (I want to store several pages of plots). The PDF files get too large to be handled ( 10MB, one was even 200MB big). So I wonder, if there would be a possibilty to either - reduce the file size of the PDF - change the way the plot is generated to reduce the plot size? I use: plot(myDate,myFile[,1],type=l,xlab=Date) using myts = as.ts(start=myDate[1],end=myDate[length(myDate)],x=myFile[,1]) plot.ts(myts,xlab=Date) produces the same file size. for storing the PDF I use: pdf(file=paste(outpath,myPDF.pdf,sep=''),paper=a4r). I would be very grateful for an answer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] combining pairs plot with other plots in one output
On Oct 27, 2011, at 6:27 PM, Ulrich wrote: I would like to combine multiple plots (one of which is a pairs plot) in one output display: While this works well: layout(matrix(c(1,2,3,3,3,3), ncol=2, byrow=T)) data - matrix(rnorm(1000), ncol=10) boxplot(data) hist(data) plot(data) This doesn't: (because the pairs function seems to override the layout parameters?) Right. But you have not specified what should go in what location. layout(matrix(c(1,2,3,3,3,3), ncol=2, byrow=T)) data - matrix(rnorm(1000), ncol=10) boxplot(data) hist(data) pairs(data) You should look at the ?pairs page. It implements a panel.hist function that can be offered to diag.panel: panel.hist - function(x, ...) { usr - par(usr); on.exit(par(usr)) par(usr = c(usr[1:2], 0, 1.5) ) h - hist(x, plot = FALSE) breaks - h$breaks; nB - length(breaks) y - h$counts; y - y/max(y) rect(breaks[-nB], 0, breaks[-1], y, col=cyan, ...) } pairs(data, diag.panel=panel.hist, upper.panel=panel.smooth) There is also a panel.pairs function in package lattice, but you would need to create your page layout with grid calls rather than base graphics. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with parallel processing code
I have had issues with some parallel backends not finding functions within a namespace for packages listed in the .packages argument or explicitly loaded in the body of the foreach loop. This has occurred with MPI but not with multicore. I can get around this to some extent by calling the functions using the namespace (eg foo:::bar) but this is pretty kludgy. sessionInfo() R version 2.13.2 (2011-09-30) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] doMPI_0.1-5 Rmpi_0.5-9 doMC_1.2.3 multicore_0.1-7 foreach_1.3.2 codetools_0.2-8 iterators_1.0.5 Max On Thu, Oct 27, 2011 at 4:30 PM, 1Rnwb sbpuro...@gmail.com wrote: If i understand correctly you mean to write the line as below: foreach(icount(itr),.combine=combine,.options.smp=smpopts,.packages='MASS')%dopar% -- View this message in context: http://r.789695.n4.nabble.com/help-with-parallel-processing-code-tp3944303p3945954.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. -- Max __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] vis.gam zlab problem
I am using the mgcv package to develop vis.gam plots and having trouble figuring out how to relabel the z-axis (image attached). It is currently labeled as linear predictor, but I would like to change it to a different name. Currently I am using this code: vis.gam(model1,theta=320,ticktype=detailed,color=gray,nCol=12, zlab=BCS) However, when run R states: Error in persp.default(m1, m2, z, col = col, zlim = c(min.z, max.z), xlab = view[1], : formal argument zlab matched by multiple actual arguments Any assistance would be greatly appreciated!! -Jared http://r.789695.n4.nabble.com/file/n3946213/BCS_Plot.jpeg -- View this message in context: http://r.789695.n4.nabble.com/vis-gam-zlab-problem-tp3946213p3946213.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] Proc Mixed to R
Hi All, I'm working with some SAS code to analyze an experiment set up as follows: 66 subjects (colonies) treated with a random treatment (1-8) and measured at three time points. The data structure looks like: input colony tmt y1 y2 y3; y=y1; date=*1*; output; y=y2; date=*2*; output; y=y3; date=*3*; output; datalines; 1 3 6725 6750 925 2 8 6950 5800 11275 3 4 4200 6100 6475 Procedure: *proc* *mixed* data=Nosema method=ml covtest; class colony tmt; model y=tmt date tmt*date / s; repeated / type=un subject=colony; random colony; lsmeans tmt/cl adjust=tukey; I am able to get something close by running aov on it, even closer by using Anova{car} and calling type=3. The problem I'm having is running the tukey and/or getting something similar to SAS's Solution for Fixed Effects table. Any idea what to do? Thanks, Molly [[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] 'for' in steps
I want to use for (i in 1:time) but I want the increments to be monthly. For example, if I'm adding interest to a virtual bank account monthly, for a total of 'time' in years which the user has entered. Is there a simple way of doing this please? I'm not familiar with many R functions yet. -- View this message in context: http://r.789695.n4.nabble.com/for-in-steps-tp3946248p3946248.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.