Re: [R] Help needed for Loading tm package
How do you account for the fact that the package passed its checks on the build machine, e.g. http://cran.r-project.org/bin/windows/contrib/2.8/check/RWeka-check.log and no one else is reporting this? (And it does work for me.) Blaming your tools is easy, but doing so on a public forum is disrespectful and against the rw-FAQ http://cran.r-project.org/bin/windows/base/rw-FAQ.html#Can-I-install-packages-into-libraries-in-this-version_003f (note the word 'unsupported'). Uwe Ligges does a great job helping Windows' users by building binary packages, and deserves your thanks, not vague and unsubstantiated blame. On Mon, 12 Jan 2009, Kum-Hoe Hwang wrote: Thank Prof. Brian Ripley for your comments. Based on Prof Brian Ripley's comments, I checked Java environments in my PC. But I have not solved a tm package problem in Win R software. I am not sure but my current conclusion is that the Win-based R binary software has definitely a problem with Rweka package or subpackage. Should I wait for another upgraded R binary version under the window XP, tm' package or Rweka ets? Or I'd better migrate to non-window OS such as Linux, etc? You definitely shou;d read and follow the FAQ, as this could well be a Java incompatibility with the binary package. Kum Hwang, Ph.D. On Sat, Jan 10, 2009 at 8:06 PM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: On Sat, 10 Jan 2009, Kum-Hoe Hwang wrote: Howdy Gurus again Thanks to Tony.Breyal, I was able to writing the following script for analyzing a text document. But I got an error with tm' package. I don't why I got the error from the R script below. I think I followed proccess of R tm manual. Please do read the messages you got. I see Error in .jinit(system.file(jar, c(weka.jar, RWeka.jar), package = pkgname, : Cannot create Java virtual machine (-1) so the problem is with your Java installation and RWeka, not 'tm'. First make sure you have a working installation of RWeka -- I suspect you do not even have Java installed, but it could be a version or path issue (but very unlikely to be an R issue). I use R v2.8.1. and tm_0.3-3.zip under Win XP. Thanks in advance, Kum Hwang # setting directory my.path -'C:\\_work\\Daddys\\myProjects\\2009 defaultProject\\R\\textfile\\' # text miner pakacge library(tm) Loading required package: Snowball Loading required package: RWeka - Error in .jinit(system.file(jar, c(weka.jar, RWeka.jar), package = pkgname, : Cannot create Java virtual machine (-1) Error : .onLoad failed in 'loadNamespace' for 'RWeka' Error: package 'RWeka' could not be loaded my.corpurs -Corpus(DirSource(my.path), readerControl = list(reader=readPlain)) Error: could not find function Corpus my.tdm - TermDocMatrix(my.corpus) Error: could not find function TermDocMatrix my.tdm[1,] Error: object my.tdm not found -- Kum-Hoe Hwang, Ph.D. Phone : 82-31-250-3516 Email : phdhw...@gmail.com [[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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 -- Kum-Hoe Hwang, Ph.D. Phone : 82-31-250-3516 Email : phdhw...@gmail.com -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] connecting boxplots
Thank you very much David... Can you also describe me how to describe the standard deviation of the boxplots/matrices ? David Winsemius wrote: You do not provide a workable example and it appears you may be conflating the German and English spellings of group, but perhaps this code fragment using the first example in boxplots help menu will move you along. It results in drawing the connecting lines to the minimum value in each group. boxplot(count ~ spray, data = InsectSprays, col = lightgray) #draws the plot str(boxplot(count ~ spray, data = InsectSprays, col = lightgray) ) List of 6 $ stats: num [1:5, 1:6] 7 11 14 18.5 23 7 12 16.5 18 21 ... # Notice that the stats element is a matrix that has the first row as the minimums, third as the medians, and maxs are fifth. $ n: num [1:6] 12 12 12 12 12 12 $ conf : num [1:2, 1:6] 10.579 17.421 13.763 19.237 0.588 ... $ out : num [1:2] 7 12 $ group: num [1:2] 3 4 $ names: chr [1:6] A B C D ... boxplot(count ~ spray, data = InsectSprays, col = lightgray) $stats[c(1,5),] [,1] [,2] [,3] [,4] [,5] [,6] [1,]770219 # minimums [2,] 23 21466 26 # maximumns lines(boxplot(count ~ spray, data = InsectSprays, col = lightgray) $stats[c(1),] ) #adds the lines through minimums -- David Winsemius On Jan 11, 2009, at 8:00 PM, johnhj wrote: In other words: I will connect the median, min and the max area of the boxplot with a line. The function lines() could help me, but I don't know which parameters the lines() function should have. johnhj wrote: Hii, I created some boxplots with this commands: x -read.table(file=test.txt) x$group - rep(1:8, each=5) boxplot(V3~gruppe, data=x) Now, I will connect the boxplots to each other to the min, max and median values. Can anybody help me how to do it ? greetings, J __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/connecting-boxplots-tp21405459p21409779.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to reference previous row?
Hello, The solution to problem will seem far easier if you think in a different way. For instance, you may want to consider the extra dummy column previous.first.value - c( NA, first[ - length(first) ] ) Then you can horizontally compare first with it's previous value. Best regards, Carlos J. Gil Bellosta http://www.datanalytics.com On Mon, 2009-01-12 at 18:57 +1100, Heston Capital wrote: I am trying to write some code where the factor references its previous value, but can't find a solution searching through the archive. X first second 1 A 1 2 A 2 3 B 3 4 B 4 5 B 5 6 C 6 7 C 7 I need a third column, in pseudo code- If value of first=previous value of first: third=previous value of third else third = second So the third column would look like: 0 0 3 3 3 6 6 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] merge table rows (\multirow)
Felipe Carrillo mazatlanmexico at yahoo.com writes: I need help merging rows. I am trying to merge the 'Month' column using \multirow. For example for the column 'Week' I want July to be merged into one row(weeks 27,28,29,30) and so on for the following weeks. Below, I am creating a PDF using Sweave, MikTex,R-2.8.1 and windows XP to show an example. Thanks for the goodexample (Note to the you did not quote completely complainants: please use a thread reader to see the OP. This list is clutter with too many ). I don't fully understand how the table should look like, mainly how the Week display should look like. I suggest that you try to not do the main formatting in latex/xtable, but rather use function reshape or package reshape (below). The following should give you a starter, I know it is not fully what you want. I had some problems with the commas in you data set, so I removed these. Dieter sampDat - Month Week Estpassage MedFL July 27665 34 July 28223235 July 29924135 July 3028464 35 Aug 3141049 35 Aug 32 82216 35 Aug 33 230411 35 Aug 34 358541 35 Sept 35747839 35 Sept 36459682 36 Sept 37609567 36 Sept 38979475 36 Sept 39837189 36 DF - read.table(textConnection(sampDat), header = TRUE) library(reshape) DFm = melt(DF,id=c(Month,Week)) cast(DFm,variable~Month+Week) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] connecting boxplots
Or with package ggplot2 : library(ggplot2) c - qplot(cyl, mpg, data=mtcars) c + geom_boxplot(aes(group = factor(cyl))) + stat_summary(fun = median, geom = line, colour = red) + stat_summary(fun = function(x) min(x), geom = line, colour = blue) + stat_summary(fun = function(x) max(x), geom = line, colour = green) 2009/1/11 johnhj jhar...@web.de Hii, I created some boxplots with this commands: x -read.table(file=test.txt) x$group - rep(1:8, each=5) boxplot(V3~gruppe, data=x) Now, I will connect the boxplots to each other to the min, max and median values. Can anybody help me how to do it ? greetings, J -- View this message in context: http://www.nabble.com/connecting-boxplots-tp21405459p21405459.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to get solution of following polynomial?
RON70 ron_michael70 at yahoo.com writes: Hi Ravi, Thanks for this reply. However I could not understand meaning of vectorizing the function. Can you please be little bit elaborate on that? Secondly the package polynomial is not available in CRAN it seems. What is the alternate package? Thanks, Ravi means 'PolynomF' which is an improved version of the old polynomial package. You do not need to recreate the polynomial from points. Instead, calculate the exact polynomial: library(PolynomF) z - polynom() p11 - 1 - A1[1,1]*z - A2[1,1]*z^2 - A3[1,1]*z^3 - A4[1,1]*z^4 # ... p - p11*p22 - p12*p21 There is probably a shorter way to generate these four polynoms p11, ..., p22. Anyway, the result is p # 1 - 1.18*x + 0.2777*x^2 - 0.2941*x^3 - 0.1004*x^4 + 0.3664*x^5 - # 0.0636*x^6 + 0.062*x^7 - 0.068*x^8 solve(p) # [1] -1.365976+0.00i -0.737852-1.639581i -0.737852+1.639581i # [4] -0.012071-1.287727i -0.012071+1.287727i 1.00+0.00i # [7] 1.388794-0.281841i 1.388794+0.281841i and the real solutions are 1.0 and -1.365976 ! Regards, Hans Werner Ravi Varadhan wrote: Hi, You can use the polynomial package to solve your problem. The key step is to find the exact polynomial representation of fn(). Noting that it is a 8-th degree polynomial, we can get its exact form using the poly.calc() function. Once we have that, it is a simple matter of finding the roots using the solve() function. require(polynomial) a - c(-0.07, 0.17) b - c(1, -4) cc - matrix(c(0.24, 0.00, -0.08, -0.31), 2) d - matrix(c(0, 0, -0.13, -0.37), 2) e - matrix(c(0.2, 0, -0.06, -0.34), 2) A1 - diag(2) + a %*% t(b) + cc A2 - -cc + d A3 - -d + e A4 - -e # I am vectorizing your function fn - function(z) { sapply(z, function(z) { y - diag(2) - A1*z - A2*z^2 - A3*z^3 - A4*z^4 det(y) }) } x - seq(-5, 5, length=9) # note we need 9 points to exactly determine a 8-th degree polynomial y - fn(x) p - poly.calc(x, y) # uses Lagrange interpolation to determine polynomial form p 1 - 1.18*x + 0.2777*x^2 - 0.2941*x^3 - 0.1004*x^4 + 0.3664*x^5 - 0.0636*x^6 + 0.062*x^7 - 0.068*x^8 # plot showing that p is the exact polynomial representation of fn(z) pfunc - as.function(p) x1 -seq(-5, 5, length=100) plot(x1, fn(x1),type=l) lines(x1, pfunc(x1), col=2, lty=2) solve(p) # gives you the roots (some are, of course, complex) Hope this helps, Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvaradhan at jhmi.edu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 between panel.abline and log scales (lattice)
Hello and Happy New Year to all R-Users !!! I would like to plot a lattice graph with a logarthmic y axis and add two reference lines that is : ref-c(0.0070, 0.0096) graph1-xyplot(data$y1 ~ as.numeric(strptime(data$x1, format=%Y-%m-%d %H:%M:%S)) | as.character(data$Code), list(y = list(log = T)), xlab=X', ylab=Y, panel = function(...) { panel.xyplot(..., type=p, pch=20) panel.abline(h=ref, col=red) } ) print(graph1) With this script, no reference lines are plotted. But if I use list(y = list(log = F)), that is a linear scale, it works. Could you please explain me the problem (and help me to solve it) ? Thanks in advance, Ptit Bleu. -- View this message in context: http://www.nabble.com/Problem-between-panel.abline-and-log-scales-%28lattice%29-tp21411642p21411642.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] calibrate function
On Sun, 11 Jan 2009, [iso-8859-1] Elsa et Stéphane BOUEE wrote: Hi all, I have a question on the package « survey Please don't send questions to the list and to me separately. Either one is ok, but not both. I have some difficulties to use the function calibrate. Although it works well with one single factor variable, I cannot use it for 2 and get the message Erreur dans regcalibrate.survey.design2(design, formula, population, aggregate.stage = aggregate.stage, : Population and sample totals are not the same length. Here is the format I use as a data.frame: snip My program is: grap-svydesign(id=~1, data=ecodiaMG) regMG -c(region1MG_NE =852, region1MG_NO=662, region1MG_P=636, region1MG_SE=961, region1MG_SO=545) sexMG -c(sexe1MG_F =976, sexe1MG_H=2680) ageMG -c(age_cl1MG_40 =380, age_cl1MG_4054=2099, age_cl1MG_54=1177) grap2- calibrate(grap, formula= ~ age_cl1-1, c(ageMG)) grap3- calibrate(grap2, formula= ~ sexe1-1, c(sexMG)) grap4- calibrate(grap3, formula= ~region1-1, c(regMG)) I can calibrate the variables one by one, which is wrong, so I would like to do it all in once: grap2- calibrate(grap, formula= ~ age_cl1+ sexe1+ regMG -1, c(ageMG, sexMG, regMG )) You need to drop the first level of sex1 and region1 (I assume you mean region1, not regMG in the formula argument). grap2- calibrate(grap, formula= ~ age_cl1+ sexe1+ region1 -1, c(ageMG, sexMG[-1], regMG[-1] )) The population totals for calibrate() are the column totals for the regression model matrix specified by the formula. With the default settings, when you have a single factor ~region1 the model matrix has a intercept column and then columns for each level of the factor except the first. Using the -1 notation ~region1 -1 removes the intercept and so requires a column for each level of the factor. When you have two or more factors and no intercept the first factor is coded with a column for each level of the factor. The sum of these columns is a constant column, so the model now effectively includes an intercept and all remaining factor variables are coded with a column for all levels except the first. One way to be sure about what model matrix corresponds to the formula is to use the formula in a regression model, eg with svyglm() and see what coefficients appear. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Extraction from an output
Hello, Would you tell my how to extract a result from a test - it's justified because I need to run this test many times. Here is an example from authors' test: library(coin) lungtumor - data.frame(dose = rep(c(0, 1, 2), c(40, 50, 48)), tumor = c(rep(c(0, 1), c(38, 2)), rep(c(0, 1), c(43, 7)), rep(c(0, 1), c(33, 15 ca.test-independence_test(tumor ~ dose, data = lungtumor, teststat = quad) ca.test Asymptotic General Independence Test data: tumor by dose chi-squared = 10.6381, df = 1, p-value = 0.001108 How to use ca.test and extract p-value and chi-squared. Robert __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Grayscale figures in odfWeave?
Dear list, I am sorry if this is a FAQ, but I have just started using odfWeave for report construction and it seems not to behave exactly like Sweave. I want to get my figures in grayscale, but the tip given in the FAQ of Sweave http://www.stat.uni-muenchen.de/~leisch/Sweave/FAQ.html#x1-1A.8 only produces gray scale images in the screen output, not in the odf document. This is my init code: Init,echo=false= library(lattice) ltheme - canonical.theme(color = FALSE) ## in-built BW theme ltheme$strip.background$col - transparent ## change strip bg lattice.options(default.theme = ltheme) ## set as default @ What am I doing wrong? /Fredrik -- Life is like a trumpet - if you don't put anything into it, you don't get anything out of it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] PRESS alternative
Dear all, Using lm models one can calculate predicted residual sum of squares (PRESS) statistic to select appropriate number of prediction variables in lm model. Is there any alternative to PRESS statistic for lda (linear discriminant analysis) model where predicted outcome variable is categorical? Thanks in advance for any suggestion. Best, Andrej __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to reference previous row?
Try this: X$third - rep(X$second[which(!duplicated(X$first))], table(X$first)) On Mon, Jan 12, 2009 at 5:57 AM, Heston Capital hestoncapi...@gmail.comwrote: I am trying to write some code where the factor references its previous value, but can't find a solution searching through the archive. X first second 1 A 1 2 A 2 3 B 3 4 B 4 5 B 5 6 C 6 7 C 7 I need a third column, in pseudo code- If value of first=previous value of first: third=previous value of third else third = second So the third column would look like: 0 0 3 3 3 6 6 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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Loading workspaces from the command line
Hi, Is there any way to load workspaces (e.g. stuff from save.image) from the command line? I'm on Linux, and would find this very helpful. I'm guessing this functionality can be duplicated with a skillful bash script to rename the particular file to .RData (and then back once R terminates), but I'm wondering if there's a better way. Zhou Fang __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 workspaces from the command line
See ?load On Mon, Jan 12, 2009 at 10:12 AM, Zhou Fang zhou.zf...@gmail.com wrote: Hi, Is there any way to load workspaces (e.g. stuff from save.image) from the command line? I'm on Linux, and would find this very helpful. I'm guessing this functionality can be duplicated with a skillful bash script to rename the particular file to .RData (and then back once R terminates), but I'm wondering if there's a better way. Zhou Fang __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loading workspaces from the command line
That's not really what I meant by 'command line'. I meant, well, loading from e.g. a bash shell, not from within an interactive R session itself. Thanks anyways, Zhou (Possibly this email was sent twice. Apologies) On Mon, Jan 12, 2009 at 12:15 PM, Henrique Dallazuanna www...@gmail.com wrote: See ?load On Mon, Jan 12, 2009 at 10:12 AM, Zhou Fang zhou.zf...@gmail.com wrote: Hi, Is there any way to load workspaces (e.g. stuff from save.image) from the command line? I'm on Linux, and would find this very helpful. I'm guessing this functionality can be duplicated with a skillful bash script to rename the particular file to .RData (and then back once R terminates), but I'm wondering if there's a better way. Zhou Fang __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Extraction from an output
On 1/12/2009 6:42 AM, robert-mcfad...@o2.pl wrote: Hello, Would you tell my how to extract a result from a test - it's justified because I need to run this test many times. Here is an example from authors' test: library(coin) lungtumor - data.frame(dose = rep(c(0, 1, 2), c(40, 50, 48)), tumor = c(rep(c(0, 1), c(38, 2)), rep(c(0, 1), c(43, 7)), rep(c(0, 1), c(33, 15 ca.test-independence_test(tumor ~ dose, data = lungtumor, teststat = quad) ca.test Asymptotic General Independence Test data: tumor by dose chi-squared = 10.6381, df = 1, p-value = 0.001108 How to use ca.test and extract p-value and chi-squared. pvalue(ca.test) [1] 0.001107836 statistic(ca.test) [1] 10.63806 See the Value subsection on the help page for independence_test(). Robert __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] anova() or aov()?
Dear all, I have a simple (I think) question that is troubling me lately: Is there any main difference between anova() command and aov() command when performing an ANOVA in Experimental design analyses? Thank you for your time, Ismini __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] anova() or aov()?
On 1/12/2009 8:57 AM, j...@in.gr wrote: Dear all, I have a simple (I think) question that is troubling me lately: Is there any main difference between anova() command and aov() command when performing an ANOVA in Experimental design analyses? The main difference is that aov() *fits* a single model and anova() *summarizes* a single model or compares two or more models. Thank you for your time, Ismini __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loading workspaces from the command line
See if this material is helpful: http://cran.r-project.org/doc/manuals/R-intro.html#Invoking-R-from-the-command-line -- David Winsemius On Jan 12, 2009, at 7:24 AM, Zhou Fang wrote: That's not really what I meant by 'command line'. I meant, well, loading from e.g. a bash shell, not from within an interactive R session itself. Thanks anyways, Zhou (Possibly this email was sent twice. Apologies) On Mon, Jan 12, 2009 at 12:15 PM, Henrique Dallazuanna www...@gmail.com wrote: See ?load On Mon, Jan 12, 2009 at 10:12 AM, Zhou Fang zhou.zf...@gmail.com wrote: Hi, Is there any way to load workspaces (e.g. stuff from save.image) from the command line? I'm on Linux, and would find this very helpful. I'm guessing this functionality can be duplicated with a skillful bash script to rename the particular file to .RData (and then back once R terminates), but I'm wondering if there's a better way. Zhou Fang __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to get solution of following polynomial?
Hi Hans, I actaually meant the polynom package (not polynomial, which was a typo). I am curious as to the main differences between polynom and PolynomF. Ron - by vectorizing, I mean that the function fn() can take a vector as an input and return the function values at all the points in the vector. sapply is an easy way to do this. Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvarad...@jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Hans W. Borchers Sent: Monday, January 12, 2009 4:30 AM To: r-h...@stat.math.ethz.ch Subject: Re: [R] How to get solution of following polynomial? RON70 ron_michael70 at yahoo.com writes: Hi Ravi, Thanks for this reply. However I could not understand meaning of vectorizing the function. Can you please be little bit elaborate on that? Secondly the package polynomial is not available in CRAN it seems. What is the alternate package? Thanks, Ravi means 'PolynomF' which is an improved version of the old polynomial package. You do not need to recreate the polynomial from points. Instead, calculate the exact polynomial: library(PolynomF) z - polynom() p11 - 1 - A1[1,1]*z - A2[1,1]*z^2 - A3[1,1]*z^3 - A4[1,1]*z^4 # ... p - p11*p22 - p12*p21 There is probably a shorter way to generate these four polynoms p11, ..., p22. Anyway, the result is p # 1 - 1.18*x + 0.2777*x^2 - 0.2941*x^3 - 0.1004*x^4 + 0.3664*x^5 - # 0.0636*x^6 + 0.062*x^7 - 0.068*x^8 solve(p) # [1] -1.365976+0.00i -0.737852-1.639581i -0.737852+1.639581i # [4] -0.012071-1.287727i -0.012071+1.287727i 1.00+0.00i # [7] 1.388794-0.281841i 1.388794+0.281841i and the real solutions are 1.0 and -1.365976 ! Regards, Hans Werner Ravi Varadhan wrote: Hi, You can use the polynomial package to solve your problem. The key step is to find the exact polynomial representation of fn(). Noting that it is a 8-th degree polynomial, we can get its exact form using the poly.calc() function. Once we have that, it is a simple matter of finding the roots using the solve() function. require(polynomial) a - c(-0.07, 0.17) b - c(1, -4) cc - matrix(c(0.24, 0.00, -0.08, -0.31), 2) d - matrix(c(0, 0, -0.13, -0.37), 2) e - matrix(c(0.2, 0, -0.06, -0.34), 2) A1 - diag(2) + a %*% t(b) + cc A2 - -cc + d A3 - -d + e A4 - -e # I am vectorizing your function fn - function(z) { sapply(z, function(z) { y - diag(2) - A1*z - A2*z^2 - A3*z^3 - A4*z^4 det(y) }) } x - seq(-5, 5, length=9) # note we need 9 points to exactly determine a 8-th degree polynomial y - fn(x) p - poly.calc(x, y) # uses Lagrange interpolation to determine polynomial form p 1 - 1.18*x + 0.2777*x^2 - 0.2941*x^3 - 0.1004*x^4 + 0.3664*x^5 - 0.0636*x^6 + 0.062*x^7 - 0.068*x^8 # plot showing that p is the exact polynomial representation of fn(z) pfunc - as.function(p) x1 -seq(-5, 5, length=100) plot(x1, fn(x1),type=l) lines(x1, pfunc(x1), col=2, lty=2) solve(p) # gives you the roots (some are, of course, complex) Hope this helps, Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvaradhan at jhmi.edu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] assign a list using expression?
Dear R-users, I would like to assign elements to a list in the following manner: mylist - list(a = a, b = b, c = c) To do this I tried myexpr - expression(a = a, b = b, c = c) mylist - list( eval(myexpr) ) It ends up by overwriting a when b is assigned and b when c is assigned. Additionally the element of the list does not have a name. Could you tell me why this is the case? Thank you very much in advance! Best regards, Nils __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 workspaces from the command line
Ok, looks like I can do what I want with --args, commandArgs() and an appropiate .First. Thanks, Zhou On Mon, Jan 12, 2009 at 2:27 PM, David Winsemius dwinsem...@comcast.net wrote: See if this material is helpful: http://cran.r-project.org/doc/manuals/R-intro.html#Invoking-R-from-the-command-line -- David Winsemius On Jan 12, 2009, at 7:24 AM, Zhou Fang wrote: That's not really what I meant by 'command line'. I meant, well, loading from e.g. a bash shell, not from within an interactive R session itself. Thanks anyways, Zhou (Possibly this email was sent twice. Apologies) On Mon, Jan 12, 2009 at 12:15 PM, Henrique Dallazuanna www...@gmail.com wrote: See ?load On Mon, Jan 12, 2009 at 10:12 AM, Zhou Fang zhou.zf...@gmail.com wrote: Hi, Is there any way to load workspaces (e.g. stuff from save.image) from the command line? I'm on Linux, and would find this very helpful. I'm guessing this functionality can be duplicated with a skillful bash script to rename the particular file to .RData (and then back once R terminates), but I'm wondering if there's a better way. Zhou Fang __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Problems with impute function from Hmisc library
Hello I would like to use the transcan and impute functions from Hmisc library for single impution. library(Hmisc) m1-data.frame(x1=rnorm(20),x2=rnorm(20),x3=rnorm(20)) m1[c(2,4),1]-NA t1-transcan(~x1+x2+x3,data=m1,imputed=T) impute(t1) Fehler in as.environment(pos) : kein Eintrag names NA im Suchpfad Which means: Error in as.environment(pos): no entry called 'NA' in search path. What am I doing wrong? Regards, Erich [[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] Loading workspaces from the command line
Another possibility is to have a separate directory for each project and place an .RData file in each. Now just cd to whatever directory corresponds to the project you wish to work on and start R normally. No code is needed. On Mon, Jan 12, 2009 at 10:04 AM, Zhou Fang zhou.zf...@gmail.com wrote: Ok, looks like I can do what I want with --args, commandArgs() and an appropiate .First. Thanks, Zhou On Mon, Jan 12, 2009 at 2:27 PM, David Winsemius dwinsem...@comcast.net wrote: See if this material is helpful: http://cran.r-project.org/doc/manuals/R-intro.html#Invoking-R-from-the-command-line -- David Winsemius On Jan 12, 2009, at 7:24 AM, Zhou Fang wrote: That's not really what I meant by 'command line'. I meant, well, loading from e.g. a bash shell, not from within an interactive R session itself. Thanks anyways, Zhou (Possibly this email was sent twice. Apologies) On Mon, Jan 12, 2009 at 12:15 PM, Henrique Dallazuanna www...@gmail.com wrote: See ?load On Mon, Jan 12, 2009 at 10:12 AM, Zhou Fang zhou.zf...@gmail.com wrote: Hi, Is there any way to load workspaces (e.g. stuff from save.image) from the command line? I'm on Linux, and would find this very helpful. I'm guessing this functionality can be duplicated with a skillful bash script to rename the particular file to .RData (and then back once R terminates), but I'm wondering if there's a better way. Zhou Fang __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] assign a list using expression?
I think this is glossing over 9.7 of 'The R Inferno'. You aren't telling us what you really want to achieve. It seems hard for me to believe that the approach you are taking is going to be the easiest route to whatever that is. Patrick Burns patr...@burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of The R Inferno and A Guide for the Unwilling S User) Skotara wrote: Dear R-users, I would like to assign elements to a list in the following manner: mylist - list(a = a, b = b, c = c) To do this I tried myexpr - expression(a = a, b = b, c = c) mylist - list( eval(myexpr) ) It ends up by overwriting a when b is assigned and b when c is assigned. Additionally the element of the list does not have a name. Could you tell me why this is the case? Thank you very much in advance! Best regards, Nils __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] assign a list using expression?
The purpose of this is not clear but depending on what a and b are you might be able to use a data frame (which is a list): a - 1:2; b - 3:4 data.frame(a, b) a b 1 1 3 2 2 4 On Mon, Jan 12, 2009 at 9:42 AM, Skotara nils.skot...@uni-hamburg.de wrote: Dear R-users, I would like to assign elements to a list in the following manner: mylist - list(a = a, b = b, c = c) To do this I tried myexpr - expression(a = a, b = b, c = c) mylist - list( eval(myexpr) ) It ends up by overwriting a when b is assigned and b when c is assigned. Additionally the element of the list does not have a name. Could you tell me why this is the case? Thank you very much in advance! Best regards, Nils __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Loading workspaces from the command line
Well, that isn't ideal for my purposes. (A little context - basically I have a script that I'm running for a lot of simulations, which is kinda buggy, and what I'm doing is I'm having the script periodically save whatever it has done so far to an automatically named file. Then if something odd happens in between two saves, I can run forward from a previously saved point to find the problem and figure out why it happened, and also I won't risk losing everything if something catastrophic happens.) Anyways, if anyone's interested, in .Rprofile .First - function(){ if (rev(commandArgs())[2] == ld){ load(rev(commandArgs())[1], .GlobalEnv) } } Then e.g. alias Rload='R --arg ld' or make a bash script with gnome-terminal --command R --args ld $1 and set some Open With options, and you'll be about to open R workspaces from Nautilus etc by point and click. Zhou On Mon, Jan 12, 2009 at 3:14 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: Another possibility is to have a separate directory for each project and place an .RData file in each. Now just cd to whatever directory corresponds to the project you wish to work on and start R normally. No code is needed. On Mon, Jan 12, 2009 at 10:04 AM, Zhou Fang zhou.zf...@gmail.com wrote: Ok, looks like I can do what I want with --args, commandArgs() and an appropiate .First. Thanks, Zhou On Mon, Jan 12, 2009 at 2:27 PM, David Winsemius dwinsem...@comcast.net wrote: See if this material is helpful: http://cran.r-project.org/doc/manuals/R-intro.html#Invoking-R-from-the-command-line -- David Winsemius On Jan 12, 2009, at 7:24 AM, Zhou Fang wrote: That's not really what I meant by 'command line'. I meant, well, loading from e.g. a bash shell, not from within an interactive R session itself. Thanks anyways, Zhou (Possibly this email was sent twice. Apologies) On Mon, Jan 12, 2009 at 12:15 PM, Henrique Dallazuanna www...@gmail.com wrote: See ?load On Mon, Jan 12, 2009 at 10:12 AM, Zhou Fang zhou.zf...@gmail.com wrote: Hi, Is there any way to load workspaces (e.g. stuff from save.image) from the command line? I'm on Linux, and would find this very helpful. I'm guessing this functionality can be duplicated with a skillful bash script to rename the particular file to .RData (and then back once R terminates), but I'm wondering if there's a better way. Zhou Fang __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] connecting boxplots
johnhj jhar...@web.de wrote: Can you also describe me how to describe the standard deviation of the boxplots/matrices ? Try tapply: x -read.table(file=test.txt) x$group - rep(1:8, each=5) boxplot(V3~gruppe, data=x) with(x, tapply(V3, gruppe, sd)) Mike __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 and if problem
I have one final question... How can I save a CSV ifile with ; separation in stead of , separation? I know the write.csv(file=filename.csv) an that you can use sep=; when you open a .csv file, but that doesn't work with the write.csv command. -- View this message in context: http://www.nabble.com/for-loop-and-if-problem-tp21312449p21412888.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 in svd(S) : infinite or missing values in 'x'
Hi everyone. I was running correspondence analysis in R with the package 'ca' and I got a error message that I could not solve. summary(ca(gui)) Error in svd(S) : infinite or missing values in 'x' #where gui is my dat table as follows: 0 90 1 1 0 90 0 0 0 90 5 1 0 95 1 0 0 0 0 0 85 0 0 0 50 0 0 0 90 0 0 0 75 0 0 0 75 0 0 0 0 0 10 25 0 0 5 5 0 0 50 10 0 0 10 20 0 0 1 10 0 0 50 1 0 0 10 5 0 0 20 0 0 0 10 50 0 0 5 5 As far I could undestand, this error should appear due to missing data, but this is not the case of my table. I will apreciate any help to undertand what I am doing wrong. Thanks! Andre __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] problems with download.file() from ftp?
Dear list, I am trying to download a text file from an ftp site using download.file(). I used the following code: url - ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho/13e19.txt; dest - c:/test/downloadtest.txt download.file(url, dest) I get this error message, indicating that R is unable to open the connection: trying URL 'ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho/13e19.txt' Error in download.file(url, dest) : cannot open URL 'ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho/13e19.txt' I'm sure there is a simple solution that allows R to open this connection, but after reading the url help file for an hour, I can't seem to find the solution. Is anyone willing to help me solve this problem? thanks in advance for any advice, Zack __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] (no subject)
hi, I'm looking for R codes that can do modified Pearson correlation that corrects for spatially correlated variables. thanks, Mélanie-L. Le Blanc __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Working with duplicated rows
Dear all, I have a dataframe of 3 columns, consisting of 'longitude', 'latitude' and a corresponding 'value'. Where identical 'longitude' and 'latitude' pairs occur more than once, I want their corresponding 'value' to be summed and the 'pair' to only appear once. For example: long lat value 10 20 5 6 2 3 27-3 9 10 20 10 4 -1 0 6 2 9 would be converted to something like: long lat value 10 20 15 6 2 12 27-3 9 4 -1 0 ...as rows 1 and 4, 2 and 6 respectively are matched with respect to the 'long' and 'lat' columns. Their values in column 3 are then summed and reported as one row in the new dataframe. How would I go about coding this in R? Many thanks, Steve _ Are you a PC? Upload your PC story and show the world __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] assign a list using expression?
Thank you Patrick and Gabor! Sorry, I think I have not explainend it well. The purpose is as follows: names - letters[1:3] values - data.frame(a = 1:3, b = 4:6, c = 7:9) With more complicated objects similar to 'names' and 'values' I wrote the following line to assign the elements of the list: mycommand - parse(text = paste(names, = values[\, names, \], sep=) ) However, list(eval(mycommand)) does not do what I want. whereas list(a = values[a], b = values[b], c = values[c]) does. I can not tell why... I try to understand, what expression and eval do. I know that many times there are other ways to achieve the same goal. So here, too. But I think there should be a reason why it does not work that way. Best regards! Nils __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 and if problem
Try using: write.table(..., sep=;) write.csv just calls write.table On Mon, Jan 12, 2009 at 6:38 AM, Sake tlep.nav.e...@hccnet.nl wrote: I have one final question... How can I save a CSV ifile with ; separation in stead of , separation? I know the write.csv(file=filename.csv) an that you can use sep=; when you open a .csv file, but that doesn't work with the write.csv command. -- View this message in context: http://www.nabble.com/for-loop-and-if-problem-tp21312449p21412888.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] assign a list using expression?
Try using do.call: do.call(list, as.list(mycommand)) On Mon, Jan 12, 2009 at 1:58 PM, Skotara nils.skot...@uni-hamburg.dewrote: Thank you Patrick and Gabor! Sorry, I think I have not explainend it well. The purpose is as follows: names - letters[1:3] values - data.frame(a = 1:3, b = 4:6, c = 7:9) With more complicated objects similar to 'names' and 'values' I wrote the following line to assign the elements of the list: mycommand - parse(text = paste(names, = values[\, names, \], sep=) ) However, list(eval(mycommand)) does not do what I want. whereas list(a = values[a], b = values[b], c = values[c]) does. I can not tell why... I try to understand, what expression and eval do. I know that many times there are other ways to achieve the same goal. So here, too. But I think there should be a reason why it does not work that way. Best regards! Nils __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Working with duplicated rows
Try this: aggregate(dt$value, list(long = dt$long, lat = dt$lat), FUN = sum) On Mon, Jan 12, 2009 at 1:52 PM, Steve Murray smurray...@hotmail.comwrote: Dear all, I have a dataframe of 3 columns, consisting of 'longitude', 'latitude' and a corresponding 'value'. Where identical 'longitude' and 'latitude' pairs occur more than once, I want their corresponding 'value' to be summed and the 'pair' to only appear once. For example: long lat value 10 20 5 6 2 3 27-3 9 10 20 10 4 -1 0 6 2 9 would be converted to something like: long lat value 10 20 15 6 2 12 27-3 9 4 -1 0 ...as rows 1 and 4, 2 and 6 respectively are matched with respect to the 'long' and 'lat' columns. Their values in column 3 are then summed and reported as one row in the new dataframe. How would I go about coding this in R? Many thanks, Steve _ Are you a PC? Upload your PC story and show the world __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] assign a list using expression?
This still isn't clear. In your post, values is already a list with the required names and values in it so the whole exercise is pointless -- you are starting out with the answer. Just guessing, but maybe your setup is a set of variables in your workspace and a vector of their names with the output being a named list of them: a - 1:2; b - 1:3 nms - c(a, b) sapply(nms, get, simplify = FALSE) On Mon, Jan 12, 2009 at 10:58 AM, Skotara nils.skot...@uni-hamburg.de wrote: Thank you Patrick and Gabor! Sorry, I think I have not explainend it well. The purpose is as follows: names - letters[1:3] values - data.frame(a = 1:3, b = 4:6, c = 7:9) With more complicated objects similar to 'names' and 'values' I wrote the following line to assign the elements of the list: mycommand - parse(text = paste(names, = values[\, names, \], sep=) ) However, list(eval(mycommand)) does not do what I want. whereas list(a = values[a], b = values[b], c = values[c]) does. I can not tell why... I try to understand, what expression and eval do. I know that many times there are other ways to achieve the same goal. So here, too. But I think there should be a reason why it does not work that way. Best regards! Nils __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 and if problem
write.csv does exactly what you would expect ... creates a *Comma* Separated Values file. If you don't want a comma separated value format then use write.table with sep=; You can still name it whatever.csv. Or you if you also intend commas for decimal points, use write.csv2 as described in the help page: write.csv2 uses a comma for the decimal point and a semicolon for the separator, the Excel convention for CSV files in some Western European locales. -- David Winsemius On Jan 12, 2009, at 6:38 AM, Sake wrote: I have one final question... How can I save a CSV ifile with ; separation in stead of , separation? I know the write.csv(file=filename.csv) an that you can use sep=; when you open a .csv file, but that doesn't work with the write.csv command. -- View this message in context: http://www.nabble.com/for-loop-and-if-problem-tp21312449p21412888.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] Working with duplicated rows
try aggregate(), e.g., dat - read.table(textConnection(long lat value 10 20 5 6 2 3 27-3 9 10 20 10 4 -1 0 6 2 9), header = TRUE) closeAllConnections() aggregate(dat[value], list(Long = dat$long, Lat = dat$lat), sum) I hope it helps. Best, Dimitris Steve Murray wrote: Dear all, I have a dataframe of 3 columns, consisting of 'longitude', 'latitude' and a corresponding 'value'. Where identical 'longitude' and 'latitude' pairs occur more than once, I want their corresponding 'value' to be summed and the 'pair' to only appear once. For example: long lat value 10 20 5 6 2 3 27-3 9 10 20 10 4 -1 0 6 2 9 would be converted to something like: long lat value 10 20 15 6 2 12 27-3 9 4 -1 0 ...as rows 1 and 4, 2 and 6 respectively are matched with respect to the 'long' and 'lat' columns. Their values in column 3 are then summed and reported as one row in the new dataframe. How would I go about coding this in R? Many thanks, Steve _ Are you a PC? Upload your PC story and show the world __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] (no subject)
Mélanie-Louise Leblanc melanie-louise.leblanc.1 at ulaval.ca writes: hi, I'm looking for R codes that can do modified Pearson correlation that corrects for spatially correlated variables. thanks, Mélanie-L. Le Blanc I think you may need to find the answer to the statistical/subject area question first (i.e., how can I calculate/make inferences on a measure of association among observations that may also be correlated due to spatial association?) and then search to see whether R implements such methods. The only two thoughts that spring to mind are (1) partial Mantel tests (RSiteSearch(partial mantel) and read up on the associated literature) and (2) trying this question out on the r-sig-geo mailing list. good luck Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Interval censored Data in survreg() with zero values!
Hello again, I studied your suggestion but still I disagree. You wrote: From the way you wrote the problem I assumed that there is some number of n looks at the subject and then you count them up. But this is not the case. My data is clearly continuous quantities and no discrete choices. I know nothing about the underlying choice process, the only thing I know is the final share of one of three regimes. So sorry for the bad description of the problem. So I stick with my censored data model. Still the hint about the p-values is very helpful because I actually ran into this problem. So thank you for the hint. Best, Geraldine Terry Therneau schrieb: Apologies -- you are being more subtle than I thought. Nevertheless, I think that the censoring language isn't quite right. You are thinking of a hierarchical model: z ~ N(Xb, sigma), where Xb is the linear predictor, whatever covariates you think belong in the model. Whether the distribution should be Gaussian or somthing else depends not on the overall distribution of z, but on distribution of (z | Xb). We could have a skewed predictor leading to skewed z, even if the distribution about any given expectation is symmetric. y = F(z) is what you observe. The classic tobin model is y= max(0,z), which does lead to censored data. In your case y_i = Binomial(n_i, p_i = H(z)). Note a binomial is k heads out of n tries with a coin of probability p, a Bernouli is a binomial restricted to a single coin flip. From the way you wrote the problem I assumed that there is some number of n looks at the subject and then you count them up. Note that var(y) = n p (1-p) H describes how the probability changes with z. In biology we very rarely use H(z)= max(min(z,1),0) because it gives a hard threshold, and the probability of nearly anything doesn't go all the way to zero or one. If H were as above and var(y) = constant and n is sufficiently large so that Binomial dist is approx Gaussian and var(y |p) var(z| Xb) then your y will fit a censored Gaussian. Since at least the second is false, it doesn't. A censored model may still be an ok first cut at fitting the data, but I would be suspicious of variance estimates and particularly of any p-values. The bootstrap could help that. Terry T. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] merge table rows (\multirow)
Felipe Carrillo wrote: I am trying to merge the 'Month' column using \multirow. For example for the column 'Week' I want July to be merged into one row(weeks 27,28,29,30) and so on for the following weeks. Below, I am creating a PDF using Sweave, MikTex,R-2.8.1 and windows XP to show an example. .. Example removed and partially regenerated below Another try; had a bad hour this morning, too many typos. This comes closer to what you want, but not exactly. You might try to manually call format.df which is implicitly called in latex, and massage that. Again, I do not know if this is easier with xtable. If you want to post latex samples, it is not really necessary to include it in Sweave. The example below works fine for testing. Dieter library(Hmisc) sampDat - Month Week Estpassage MedFL July 27665 34 July 28223235 July 29924135 July 3028464 35 Aug 3141049 35 Aug 32 82216 35 Aug 33 230411 35 Aug 34 358541 35 Sept 35747839 35 Sept 36459682 36 Sept 37609567 36 Sept 38979475 36 Sept 39837189 36 DF - read.table(textConnection(sampDat), header = TRUE) row.names(DF)=DF$Week latex(DF[,-2],label=tab:hola,longtable=FALSE,caption='Sample table.', rowname=, rgroup=unique(DF$Month),n.rgroup=table(DF$Month)) -- View this message in context: http://www.nabble.com/merge-table-rows-%28%5Cmultirow%29-tp21408818p21417983.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] R2WinBUGS stopping execution
Apologies if this isn't acceptable for the general help list. I'm running OpenBUGS model via the R2WinBUGS package interface, under Windows. Is it possible to terminate running models, short of using the Windows Task Manager to forcibly exit the program? Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Working with duplicated rows
Thanks - that's great! _ Choose the perfect PC or mobile phone for you __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Determining variance components of classed covariates
Hi - I am interested in solving variance components for the data below with respect to the response variable, Expression within R. However, the covariates aren't independent and they also have a class (of which the total variance explained by covariates in that class I am most interested in). Very naively, I have tried to look at each individual covariates variance like this lm-lmer(Expression ~ 1 + (1|rs11834524) + (1|rs7074431), data=input_new) lm Linear mixed-effects model fit by REML Formula: Expression ~ 1 + (1 | rs11834524) + (1 | rs7074431) Data: input AIC BIC logLik MLdeviance REMLdeviance 108.4 116.5 -51.22 102.5102.4 Random effects: Groups NameVariance Std.Dev. rs11834524 (Intercept) 0.485538 0.69681 rs7074431 (Intercept) 0.013720 0.11713 Residual 0.128853 0.35896 number of obs: 109, groups: rs11834524, 3; rs7074431, 3 Fixed effects: Estimate Std. Error t value (Intercept) 9.9524 0.4098 24.29 My assumption is that this is telling me that rs11834524 explains 0.485538 of the variance and rs7074431 explains 0.013720 of the variance in Expression when looked at independently. However, I would like to know how to write a model where I know how much of the total variance (in Expression) is described by covariates rs11834524, rs1682421, rs13383869 and rs9457141 (call it class A) and covariates rs9459617, rs7074431, rs12450785, rs592724 (call it class B). Assuming an additive model within the class. The caveats are that there is missing data and again that there may be correlation between all the covariates. Such that a theoretical result may be that Class A: Explains 60% of the total variance in expression (response) Class B: Explains 10% of the total variance in expression Thanks for the help! I am sorry I am R challenged here...I really appreciate the guidance! Stephen dump(input_new, file=stdout()) input_new - structure(list(Individual = structure(1:109, .Label = c(NA06984, NA06985, NA06986, NA06989, NA06993, NA06994, NA07000, NA07022, NA07037, NA07045, NA07051, NA07055, NA07056, NA07345, NA07346, NA07347, NA07357, NA07435, NA11829, NA11830, NA11831, NA11832, NA11839, NA11840, NA11843, NA11881, NA11882, NA11892, NA11893, NA11894, NA11917, NA11918, NA11919, NA11920, NA11930, NA11931, NA11992, NA11993, NA11994, NA11995, NA12003, NA12005, NA12006, NA12043, NA12044, NA12056, NA12057, NA12144, NA12145, NA12146, NA12154, NA12155, NA12156, NA12234, NA12239, NA12248, NA12249, NA12264, NA12272, NA12273, NA12274, NA12275, NA12282, NA12283, NA12286, NA12287, NA12340, NA12341, NA12342, NA12343, NA12347, NA12348, NA12383, NA12399, NA12400, NA12414, NA12489, NA12546, NA12716, NA12718, NA12748, NA12749, NA12750, NA12751, NA12760, NA12761, NA12762, NA12763, NA12775, NA12776, NA12777, NA12778, NA12812, NA12813, NA12814, NA12815, NA12827, NA12828, NA12829, NA12830, NA12842, NA12843, NA12872, NA12873, NA12874, NA12875, NA12889, NA12891, NA12892 ), class = factor), Expression = c(9.46026823453575, 10.0788903323991, 9.20330296497174, 10.038741467793, 9.33092349416463, 11.0273957217919, 10.5498875891745, 9.81137299592747, 11.2023261987976, 9.90559354069027, 10.1524696609679, 10.3171767665993, 9.02155519577685, 9.84917871051438, 10.658877473136, 9.88895551011107, 8.62335008726357, 9.21529114100886, 10.7896248923916, 10.1302992505869, 8.64584282787018, 9.56057795866654, 9.89810004078774, 10.2557482141576, 8.95588077688637, 9.56452454115857, 9.26525135092154, 10.5438780642797, 9.8468571349548, 10.7416169225352, 10.5623721612979, 10.6565276881443, 9.67758493445612, 9.75385553511462, 8.997797236767, 11.0106882086179, 10.362578597992, 9.2745507212906, 10.7453355016181, 9.75998268015348, 9.45003620116962, 10.055504292376, 10.7072220720564, 10.0934686444392, 10.0472832129727, 10.1185615033486, 10.3340911031131, 9.70618910683157, 10.5953304905529, 10.4246307909547, 9.91463202635336, 10.249081562168, 10.9252022586474, 10.295544143525, 11.4838109797985, 10.5286570234792, 9.78692800868132, 10.0397050809162, 9.27914623343747, 10.37600233389, 9.27341681588134, 9.40195375611303, 10.8979822929135, 9.0398977389, 10.3911745662505, 10.4345408213054, 9.8548491618724, 10.1897729275437, 10.288149609, 8.9656977165014, 9.81595398472166, 10.1856794532084, 9.3763789479684, 10.1712420020647, 10.2964594680427, 10.3515965292101, 8.94492585275159, 11.2529257614993, 9.25146912450726, 10.1904309237525, 10.7490591053023, 10.3883924463568, 10.097023765247, 10.0824730785217, 10.0828512817661, 10.6371064852226, 10.5831044752098, 10.4484786486601, 8.50264408341596, 10.3468670812262, 9.46061433005316, 8.90027436167269, 9.73630671555279, 9.4022408144, 10.3220768104446, 8.55132985773453, 10.1678182524815, 10.6145417864386, 10.4169948161073, 10.0253039670548, 10.2568017077865, 10.5045847076951, 9.75993936712448, 8.7092895909, 10.674414794, 10.8640943324257, 10.4295384371541, 10.1987862649656,
Re: [R] problems with download.file() from ftp?
First, try the example in the test file (tests/internet.R) read.table(ftp://ftp.stats.ox.ac.uk/pub/datasets/csb/ch11b.dat;) or download.file(ftp://ftp.stats.ox.ac.uk/pub/datasets/csb/ch11b.dat;, test That is known to work on many, many R systems. I get the same error as you on that URL, but it looks to me that the site required PASV ftp, something R's download.file does not support. From the detailed logs (options(internet.info=0) 230- 230-Welcome To The 230- Natural Resources Conservation Service - USDA 230- NATIONAL WATER and CLIMATE CENTER 230- 230- 230-The Local Date and Time is Mon Jan 12 08:30:25 2009 230-Current Directory is / 230-Information Contact is: i...@wcc.nrcs.usda.gov 230---- 230-Note that data files herein are at most updated once an hour. 230- 230 Guest login ok, access restrictions apply. -- 19: In download.file(url, dest) : --- -- 20: In download.file(url, dest) : Got 230 21: In download.file(url, dest) : Invalid answer to PASV Since you are on Windows, using --internet2 (see the rw-FAQ) might work. On Mon, 12 Jan 2009, zack holden wrote: Dear list, I am trying to download a text file from an ftp site using download.file(). I used the following code: url - ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho/13e19.txt; dest - c:/test/downloadtest.txt download.file(url, dest) I get this error message, indicating that R is unable to open the connection: trying URL 'ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho/13e19.txt' Error in download.file(url, dest) : cannot open URL 'ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho/13e19.txt' I'm sure there is a simple solution that allows R to open this connection, but after reading the url help file for an hour, I can't seem to find the solution. Is anyone willing to help me solve this problem? thanks in advance for any advice, Zack -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problems with download.file() from ftp?
I ran your script on Windows Vista Ultimate, SP1 and it worked fine: ## R start... url - 'ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho/13e19.txt' dest - //PFO-SBS001/Redirected/tonyb/Desktop/test/downloadtest.txt download.file(url, dest) trying URL 'ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/ history/idaho/13e19.txt' ftp data connection made, file length 5026 bytes opened URL downloaded 5026 bytes ## R end. sessionInfo() R version 2.8.1 (2008-12-22) i386-pc-mingw32 locale: LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United Kingdom. 1252;LC_MONETARY=English_United Kingdom. 1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base On 12 Jan, 14:51, zack holden zack_hol...@hotmail.com wrote: Dear list, I am trying to download a text file from an ftp site using download.file(). I used the following code: url - ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho...; dest - c:/test/downloadtest.txt download.file(url, dest) I get this error message, indicating that R is unable to open the connection: trying URL 'ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho... Error in download.file(url, dest) : cannot open URL 'ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho... I'm sure there is a simple solution that allows R to open this connection, but after reading the url help file for an hour, I can't seem to find the solution. Is anyone willing to help me solve this problem? thanks in advance for any advice, Zack __ r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Working with duplicated rows
One of undoubtedly many ways: # kind of a pain to delete the blank rows. Try to give us full example next time? txt- long lat value + 10 20 5 + 6 2 3 + 27-3 9 + 10 20 10 + 4 -1 0 + 6 2 9 + DF2 - read.table(textConnection(txt), header=TRUE) DF3 - data.frame(with(DF2,list(lon=long, lat=lat, value=ave(value,long, lat, FUN=sum DF3 lon lat value 1 10 2015 2 6 212 3 27 -3 9 4 10 2015 5 4 -1 0 6 6 212 If you want the column name to be long, the fix is obvious. -- David Winsemius On Jan 12, 2009, at 10:52 AM, Steve Murray wrote: Dear all, I have a dataframe of 3 columns, consisting of 'longitude', 'latitude' and a corresponding 'value'. Where identical 'longitude' and 'latitude' pairs occur more than once, I want their corresponding 'value' to be summed and the 'pair' to only appear once. For example: long lat value 10 20 5 6 2 3 27-3 9 10 20 10 4 -1 0 6 2 9 would be converted to something like: long lat value 10 20 15 6 2 12 27-3 9 4 -1 0 ...as rows 1 and 4, 2 and 6 respectively are matched with respect to the 'long' and 'lat' columns. Their values in column 3 are then summed and reported as one row in the new dataframe. How would I go about coding this in R? Many thanks, Steve _ Are you a PC? Upload your PC story and show the world __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] lm: how are polynomial functions interpreted?
__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 storage of each matrix generated in a loop
I need to store each matrix generated in a loop. I've been working with the CUSUM algorithm and I've been trying to implement it in R. What I need to do with my dataset is to create 1000 randomized datasets and cumulative sum them all and store all of those randomized CUSUMed datasets for further analysis and creation of the simulation envelope in the CUSUM chart. But I can't manage to store all of them, the script I've written only stores the last randomized matrix in the variable I called cusumA. Here's the script I've written: mat - matrix(data=rep(c(1,2,3,4,5), 16), nrow=16, ncol=5) # The matrix that will be sampled A - matrix(data=0, nrow=16, ncol=5) # The variable that will store the sampled matrix for(i in 1:1000) { # I want to do it 1000 times for(j in 1:nrow(mat)) { # The number of rows to be sampled) A[j,] - sample(mat[j,]) # The sample itself - I want to do it 1000 times and then... cusumA - cumsum(data.frame(A)) # cumulative sum it, and store the 1000 randomized matrices }} I've already tried to store it in a null matrix but it will only store the first column of each matrix, so all I got was 1000 first columns. The code I used to do it was mat - matrix(data=rep(c(1,2,3,4,5), 16), nrow=16, ncol=5) A - matrix(data=0, nrow=16, ncol=5) cusumA - matrix() for(i in 1:1000) { for(j in 1:nrow(mat)) { A[j,] - sample(mat[j,]) cusumA[i] - cumsum(data.frame(A)) }} and I even got 50+ warnings... Any help'd be really appreciated! -- View this message in context: http://www.nabble.com/Help-with-storage-of-each-matrix-generated-in-a-loop-tp21418758p21418758.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] Determining variance components of classed covariates
You might want to try the https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models list next time for mixed model questions. At any rate the Variance column figures are variances, not percentages. We can use anova with REML=FALSE to make comparisons among models. Below we find that removing the rs7074431 term makes very little difference so we can drop it but removing the rs11834524 term makes a big difference. Thus modx0 can be used. modxx - lmer(Expression ~ 1 + (1|rs11834524) + (1|rs7074431), input_new, REML = FALSE) modx0 - lmer(Expression ~ 1 + (1|rs11834524), input_new, REML = FALSE) mod0x - lmer(Expression ~ 1 + (1|rs7074431), input_new, REML = FALSE) anova(modxx, modx0) Data: input_new Models: modx0: Expression ~ 1 + (1 | rs11834524) modxx: Expression ~ 1 + (1 | rs11834524) + (1 | rs7074431) Df AIC BIC logLik Chisq Chi Df Pr(Chisq) modx0 3 111.386 119.460 -52.693 modxx 4 110.288 121.053 -51.144 3.0986 10.07836 . --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 anova(modxx, mod0x) Data: input_new Models: mod0x: Expression ~ 1 + (1 | rs7074431) modxx: Expression ~ 1 + (1 | rs11834524) + (1 | rs7074431) Df AIC BIC logLik Chisq Chi Df Pr(Chisq) mod0x 3 206.652 214.726 -100.326 modxx 4 110.288 121.053 -51.144 98.365 1 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 On Mon, Jan 12, 2009 at 11:36 AM, Stephen Montgomery s...@sanger.ac.uk wrote: Hi - I am interested in solving variance components for the data below with respect to the response variable, Expression within R. However, the covariates aren't independent and they also have a class (of which the total variance explained by covariates in that class I am most interested in). Very naively, I have tried to look at each individual covariates variance like this lm-lmer(Expression ~ 1 + (1|rs11834524) + (1|rs7074431), data=input_new) lm Linear mixed-effects model fit by REML Formula: Expression ~ 1 + (1 | rs11834524) + (1 | rs7074431) Data: input AIC BIC logLik MLdeviance REMLdeviance 108.4 116.5 -51.22 102.5102.4 Random effects: Groups NameVariance Std.Dev. rs11834524 (Intercept) 0.485538 0.69681 rs7074431 (Intercept) 0.013720 0.11713 Residual 0.128853 0.35896 number of obs: 109, groups: rs11834524, 3; rs7074431, 3 Fixed effects: Estimate Std. Error t value (Intercept) 9.9524 0.4098 24.29 My assumption is that this is telling me that rs11834524 explains 0.485538 of the variance and rs7074431 explains 0.013720 of the variance in Expression when looked at independently. However, I would like to know how to write a model where I know how much of the total variance (in Expression) is described by covariates rs11834524, rs1682421, rs13383869 and rs9457141 (call it class A) and covariates rs9459617, rs7074431, rs12450785, rs592724 (call it class B). Assuming an additive model within the class. The caveats are that there is missing data and again that there may be correlation between all the covariates. Such that a theoretical result may be that Class A: Explains 60% of the total variance in expression (response) Class B: Explains 10% of the total variance in expression Thanks for the help! I am sorry I am R challenged here...I really appreciate the guidance! Stephen dump(input_new, file=stdout()) input_new - structure(list(Individual = structure(1:109, .Label = c(NA06984, NA06985, NA06986, NA06989, NA06993, NA06994, NA07000, NA07022, NA07037, NA07045, NA07051, NA07055, NA07056, NA07345, NA07346, NA07347, NA07357, NA07435, NA11829, NA11830, NA11831, NA11832, NA11839, NA11840, NA11843, NA11881, NA11882, NA11892, NA11893, NA11894, NA11917, NA11918, NA11919, NA11920, NA11930, NA11931, NA11992, NA11993, NA11994, NA11995, NA12003, NA12005, NA12006, NA12043, NA12044, NA12056, NA12057, NA12144, NA12145, NA12146, NA12154, NA12155, NA12156, NA12234, NA12239, NA12248, NA12249, NA12264, NA12272, NA12273, NA12274, NA12275, NA12282, NA12283, NA12286, NA12287, NA12340, NA12341, NA12342, NA12343, NA12347, NA12348, NA12383, NA12399, NA12400, NA12414, NA12489, NA12546, NA12716, NA12718, NA12748, NA12749, NA12750, NA12751, NA12760, NA12761, NA12762, NA12763, NA12775, NA12776, NA12777, NA12778, NA12812, NA12813, NA12814, NA12815, NA12827, NA12828, NA12829, NA12830, NA12842, NA12843, NA12872, NA12873, NA12874, NA12875, NA12889, NA12891, NA12892 ), class = factor), Expression = c(9.46026823453575, 10.0788903323991, 9.20330296497174, 10.038741467793, 9.33092349416463, 11.0273957217919, 10.5498875891745, 9.81137299592747, 11.2023261987976, 9.90559354069027, 10.1524696609679, 10.3171767665993, 9.02155519577685, 9.84917871051438, 10.658877473136, 9.88895551011107, 8.62335008726357, 9.21529114100886, 10.7896248923916, 10.1302992505869, 8.64584282787018, 9.56057795866654, 9.89810004078774, 10.2557482141576,
Re: [R] Help with storage of each matrix generated in a loop
If you are satisfied with the structure of cusumA and just want 999 more randome realizations of the same, then try creating an empty list to hold the 1000 dataframes you are creating and then accumulate sequentially to the list. mat - matrix(data=rep(c(1,2,3,4,5), 16), nrow=16, ncol=5) # The matrix that will be sampled A - matrix(data=0, nrow=16, ncol=5); cusumA - list() ## ^new empty list^ # The variable that will store the sampled matrix for(i in 1:1000) { + # I want to do it 1000 times + for(j in 1:nrow(mat)) { + # The number of rows to be sampled) + A[j,] - sample(mat[j,]) + # The sample itself - I want to do it 1000 times and then... + cusumA[[i]] - cumsum(data.frame(A)) # index + # cumulative sum it, and store the 1000 randomized matrices + }} str(cusumA) List of 1000 $ :'data.frame': 16 obs. of 5 variables: ..$ X1: num [1:16] 5 9 10 14 16 21 22 25 26 30 ... ..$ X2: num [1:16] 3 4 6 7 10 11 15 17 20 22 ... ..$ X3: num [1:16] 2 4 7 12 17 20 25 30 35 40 ... ..$ X4: num [1:16] 4 7 12 15 16 20 23 24 28 31 ... ..$ X5: num [1:16] 1 6 10 12 16 18 20 24 26 27 ... $ :'data.frame': 16 obs. of 5 variables: ..$ X1: num [1:16] 4 5 7 9 14 16 17 22 27 28 ... ..$ X2: num [1:16] 3 6 10 11 13 17 20 21 23 28 ... ..$ X3: num [1:16] 5 7 10 13 14 19 23 26 27 29 ... ..$ X4: num [1:16] 2 7 8 12 15 18 20 24 28 31 ... ..$ X5: num [1:16] 1 5 10 15 19 20 25 27 30 34 ... snip long output (no warnings) -- David Winsemius On Jan 12, 2009, at 12:07 PM, rafamoral wrote: I need to store each matrix generated in a loop. I've been working with the CUSUM algorithm and I've been trying to implement it in R. What I need to do with my dataset is to create 1000 randomized datasets and cumulative sum them all and store all of those randomized CUSUMed datasets for further analysis and creation of the simulation envelope in the CUSUM chart. But I can't manage to store all of them, the script I've written only stores the last randomized matrix in the variable I called cusumA. Here's the script I've written: mat - matrix(data=rep(c(1,2,3,4,5), 16), nrow=16, ncol=5) # The matrix that will be sampled A - matrix(data=0, nrow=16, ncol=5) # The variable that will store the sampled matrix for(i in 1:1000) { # I want to do it 1000 times for(j in 1:nrow(mat)) { # The number of rows to be sampled) A[j,] - sample(mat[j,]) # The sample itself - I want to do it 1000 times and then... cusumA - cumsum(data.frame(A)) # cumulative sum it, and store the 1000 randomized matrices }} I've already tried to store it in a null matrix but it will only store the first column of each matrix, so all I got was 1000 first columns. The code I used to do it was mat - matrix(data=rep(c(1,2,3,4,5), 16), nrow=16, ncol=5) A - matrix(data=0, nrow=16, ncol=5) cusumA - matrix() for(i in 1:1000) { for(j in 1:nrow(mat)) { A[j,] - sample(mat[j,]) cusumA[i] - cumsum(data.frame(A)) }} and I even got 50+ warnings... Any help'd be really appreciated! -- View this message in context: http://www.nabble.com/Help-with-storage-of-each-matrix-generated-in-a-loop-tp21418758p21418758.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] lm: how are polynomial functions interpreted?
On Mon, 12 Jan 2009, c...@witthoft.com wrote: [nothing deleted] matplot(1:100, lm(rnorm(100)~poly(1:100,4),x=T)$x ) # for example __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html Ahem! and provide commented, minimal, self-contained, reproducible code. ..^ Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] R2WinBUGS stopping execution
Richard.Cotton at hsl.gov.uk writes: Apologies if this isn't acceptable for the general help list. I'm running OpenBUGS model via the R2WinBUGS package interface, under Windows. Is it possible to terminate running models, short of using the Windows Task Manager to forcibly exit the program? Not that I know of (i.e., probably not). Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Two-way repeated measures anova with lme
Dear R-Users, I'm trying to set up a repeated measures anova with two within subjects factors. I tried it by 3 different anova functions: aov, Anova (from car package) and lme (from nlme package). I managed to get the same results with aov and Anova, but the results that I get from lme are slightly different and I don't figure out why. I guess I did not set up the error structure correctly. Here's an example, that I analysed with the 3 different anova functions: set.seed(10) df-data.frame(Time=as.factor(rep(paste('t',1:3,sep=''),each=36)),Cond=as.fa ctor(paste('c',1:4,sep='')),Subj=as.factor(rep(paste('s',1:9,sep=''),each=4) ),y=rnorm(108)) summary(aov(y ~ (Time*Cond) + Error(Subj/(Time*Cond)), data = df)) library(nlme) anova(lme(y~Time*Cond,random=~1|Subj,data=df)) df2-cast(df,Subj~Time+Cond)[-1] mod-lm(cbind(t1_c1,t1_c2,t1_c3,t1_c4,t2_c1,t2_c2,t2_c3,t2_c4,t3_c1,t3_c2,t3 _c3,t3_c4)~1,df2) idata=data.frame(Time=gl(3,4),Cond=gl(4,1)) summary(Anova(mod,idata=idata,idesign=~Time*Cond),multivariate=F) I would highly appreciate if anyone could explain why the results are slightly different. I probably spent hours to find an answer on the internet. I would like to use the lme function, because I need to do multiple comparisons with ghlt function. Regards, Erich [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] help on nested mixed effects ANOVA
Hello, I am trying to run a mixed effects nested ANOVA but none of my codes are giving me any meaningful results and I am not sure what I am doing wrong. I am a new user on R and would appreciate some help. The experimental design is that I have some frogs that have been exposed to three acoustic Treatments and I am measuring neural activity (egr), in 12 brain regions. Some frogs also called different calls than others so I am testing for effect of Call as a fixed effect. I have Treatment (Trt), Brain Region (Region), and Call (Call) as fixed effects and I am modeling Subject (Subj) as a random effect with brain region nested within subject. I am using lme4 package and I am not sure if that is the correct one to use. I also have some missing values as NA as part of the dataset. I have also set Subj, Region, and Call as factors using as.factor. I have run the model which I am sure is wrong: model1-anova(lme(egr ~ Trt* Region, random=~1|Subj/Region,na.action=na.omit)) The output I am getting is: numDF denDFF-value p-value Min. : 1.00 Min. : 32 Min. : 2.891 Min. :0.000e+00 1st Qu.: 1.75 1st Qu.:197 1st Qu.: 12.120 1st Qu.:0.000e+00 Median : 6.50 Median :252 Median : 20.275 Median :1.146e-05 Mean : 9.00 Mean :197 Mean : 87.353 Mean :1.383e-05 3rd Qu.:13.75 3rd Qu.:252 3rd Qu.: 95.508 3rd Qu.:2.530e-05 Max. :22.00 Max. :252 Max. :305.972 Max. :3.240e-05 Any help on what I am doing wrong on the coding would be very helpful. Thanks a lot. Mukta -- Department of Biology Wilson Hall, Rm. 316 CB#3280, University of North Carolina at Chapel Hill Chapel Hill, NC 27599-3280. Ph: (919) 962 1445 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] RMySQL crashes R
This is similar to another current post about RMySQL crashing R, except on the other post it crashed on connection to the database. I can successfully connect, and even can do dbListTables(). But, if I send a query or anything to actually see the data, R crashes to desktop. I have tried this on two computers, one Vista, one XP. Both crashed. I am running 2.8.1, and am using the correct version of DBI and RMySQL. They are both loaded with the library() function beforehand. Versions of MySQL that it was tried are 5.1 and 6.0a. I have searched on the internet and haven't found any answers, and would be grateful for any help, Nathan Forczyk Auburn University -- View this message in context: http://www.nabble.com/RMySQL-crashes-R-tp21419908p21419908.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] merge table rows (\multirow)
Hi: This is what my table should look like: Month Week EstpassageMedFL July-27456634 -28256835 -29328736 -30462337 Aug--31863237 --32423638 --33763239 --34598440 Sept-35125840 -36423541 -37257342 -38423-43 I don't want to reshape my dataset, I basically want a latex table showing only one value on the first column instead of repeating the month over and over. I know this can be done with \multirow if the table is created manually. Since this table is created dynamically on the fly I don't know how to use \multirow like that. Hope is clear. Thanks --- On Mon, 1/12/09, Dieter Menne dieter.me...@menne-biomed.de wrote: From: Dieter Menne dieter.me...@menne-biomed.de Subject: Re: [R] merge table rows (\multirow) To: r-h...@stat.math.ethz.ch Date: Monday, January 12, 2009, 12:41 AM Felipe Carrillo mazatlanmexico at yahoo.com writes: I need help merging rows. I am trying to merge the 'Month' column using \multirow. For example for the column 'Week' I want July to be merged into one row(weeks 27,28,29,30) and so on for the following weeks. Below, I am creating a PDF using Sweave, MikTex,R-2.8.1 and windows XP to show an example. I don't fully understand how the table should look like, mainly how the Week display should look like. I suggest that you try to not do the main formatting in latex/xtable, but rather use function reshape or package reshape (below). The following should give you a starter, I know it is not fully what you want. Dieter sampDat - Month Week Estpassage MedFL July 27 665 34 July 28 2232 35 July 29 9241 35 July 30 28464 35 Aug 31 41049 35 Aug 32 82216 35 Aug 33 230411 35 Aug 34 358541 35 Sept 35 747839 35 Sept 36 459682 36 Sept 37 609567 36 Sept 38 979475 36 Sept 39 837189 36 DF - read.table(textConnection(sampDat), header = TRUE) library(reshape) DFm = melt(DF,id=c(Month,Week)) cast(DFm,variable~Month+Week) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] rpart with interval censored data crashes R
Thank you for the input on rpart -- I just saw the message today. 1. You are right, it should not crash. Why it crashes rpart is simply that I (the author) never ever tried using interval censored data in the call. Real users try the most amazing things I'll fix it in my local version, but putting in a no no no message. My local version and the R version, maintained by Brian, have drifted quite far apart however. 2. Rpart deals with right censored data using the same trick as Cox models, by thinking of it as observation of a Poisson process; number of events seen over a given time window. The fact that the number is always 0 or 1 doesn't hinder the mathematical trick, which is based in counting process theory. BUT - the trick only works for right censored data. Using the mid points of your intervals is the only approach that comes readily to mind. Terry Therneau __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] RMySQL crashes R
On 1/12/2009 1:02 PM, auburneconomics wrote: This is similar to another current post about RMySQL crashing R, except on the other post it crashed on connection to the database. I can successfully connect, and even can do dbListTables(). But, if I send a query or anything to actually see the data, R crashes to desktop. I have tried this on two computers, one Vista, one XP. Both crashed. I am running 2.8.1, and am using the correct version of DBI and RMySQL. They are both loaded with the library() function beforehand. Versions of MySQL that it was tried are 5.1 and 6.0a. I have searched on the internet and haven't found any answers, and would be grateful for any help, I'd recommend using RODBC instead. The disadvantage is that you'll be at the mercy of whoever wrote the ODBC driver, but I believe I've had good experience with the MySQL one. 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] merge table rows (\multirow)
Look at the rgroup and n.rgroup arguments of ?latex function in Hmisc package or ?print.xtable in xtable package. On Mon, Jan 12, 2009 at 1:48 PM, Felipe Carrillo mazatlanmex...@yahoo.com wrote: Hi: This is what my table should look like: Month Week EstpassageMedFL July-27456634 -28256835 -29328736 -30462337 Aug--31863237 --32423638 --33763239 --34598440 Sept-35125840 -36423541 -37257342 -38423-43 I don't want to reshape my dataset, I basically want a latex table showing only one value on the first column instead of repeating the month over and over. I know this can be done with \multirow if the table is created manually. Since this table is created dynamically on the fly I don't know how to use \multirow like that. Hope is clear. Thanks --- On Mon, 1/12/09, Dieter Menne dieter.me...@menne-biomed.de wrote: From: Dieter Menne dieter.me...@menne-biomed.de Subject: Re: [R] merge table rows (\multirow) To: r-h...@stat.math.ethz.ch Date: Monday, January 12, 2009, 12:41 AM Felipe Carrillo mazatlanmexico at yahoo.com writes: I need help merging rows. I am trying to merge the 'Month' column using \multirow. For example for the column 'Week' I want July to be merged into one row(weeks 27,28,29,30) and so on for the following weeks. Below, I am creating a PDF using Sweave, MikTex,R-2.8.1 and windows XP to show an example. I don't fully understand how the table should look like, mainly how the Week display should look like. I suggest that you try to not do the main formatting in latex/xtable, but rather use function reshape or package reshape (below). The following should give you a starter, I know it is not fully what you want. Dieter sampDat - Month Week Estpassage MedFL July 27 665 34 July 28 2232 35 July 29 9241 35 July 30 28464 35 Aug 31 41049 35 Aug 32 82216 35 Aug 33 230411 35 Aug 34 358541 35 Sept 35 747839 35 Sept 36 459682 36 Sept 37 609567 36 Sept 38 979475 36 Sept 39 837189 36 DF - read.table(textConnection(sampDat), header = TRUE) library(reshape) DFm = melt(DF,id=c(Month,Week)) cast(DFm,variable~Month+Week) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] merge table rows (\multirow)
Thanks a lot Dieter, I'll play a little bit with it. Also thanks for the hint on how to post a latex reproducible example. --- On Mon, 1/12/09, Dieter Menne dieter.me...@menne-biomed.de wrote: From: Dieter Menne dieter.me...@menne-biomed.de Subject: Re: [R] merge table rows (\multirow) To: r-help@r-project.org Date: Monday, January 12, 2009, 8:32 AM Felipe Carrillo wrote: I am trying to merge the 'Month' column using \multirow. For example for the column 'Week' I want July to be merged into one row(weeks 27,28,29,30) and so on for the following weeks. Below, I am creating a PDF using Sweave, MikTex,R-2.8.1 and windows XP to show an example. .. Example removed and partially regenerated below Another try; had a bad hour this morning, too many typos. This comes closer to what you want, but not exactly. You might try to manually call format.df which is implicitly called in latex, and massage that. Again, I do not know if this is easier with xtable. If you want to post latex samples, it is not really necessary to include it in Sweave. The example below works fine for testing. Dieter library(Hmisc) sampDat - Month Week Estpassage MedFL July 27 665 34 July 28 223235 July 29 924135 July 30 28464 35 Aug 31 41049 35 Aug 32 82216 35 Aug 33 230411 35 Aug 34 358541 35 Sept 35 747839 35 Sept 36 459682 36 Sept 37 609567 36 Sept 38 979475 36 Sept 39 837189 36 DF - read.table(textConnection(sampDat), header = TRUE) row.names(DF)=DF$Week latex(DF[,-2],label=tab:hola,longtable=FALSE,caption='Sample table.', rowname=,rgroup=unique(DF$Month),n.rgroup=table(DF$Month)) -- View this message in context: http://www.nabble.com/merge-table-rows-%28%5Cmultirow%29-tp21408818p21417983.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] Useful books for learning the R software and the S programming language
any useful books for learning the R statistical software? are they pricey? and if the books recommended focus on S, how compatible will they be for someone learning R? thank you in advance for your help. P.S. specialized survey statistical procedures? Is R good at that? [[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] GarchOxFit Interface
please send me the GarchOxFit Interface thanks _ [[elided Hotmail spam]] [[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] Problems with RMySQL and MySQL server version 5.1
For those R user's who don't subscribe to R-sig-db and are having troubles with the latest RMySQL binary on CRAN, please read the email thread at the end of this message. RMySQL 0.7-2 does work with MySQL 5.1, however the CRAN binary is linked against the 5.0 version. Best, Jeff Original Message Subject: Re: [R-sig-DB] Problems with RMySQL and MySQL server version 5.1 Date: Wed, 07 Jan 2009 16:36:48 + From: Prof Brian Ripley rip...@stats.ox.ac.uk To: Jeffrey Horner jeff.hor...@vanderbilt.edu CC: r-sig...@stat.math.ethz.ch References: 4964cd3d.9000...@vanderbilt.edu There is a long, long history of precisely this (version mismatches in MySQL binaries cause crashes). We had it at 4.x, so I am not surprised to see it at 5.x now 'x' is no longer unique. When I distributed binaries, the README on my site pointed this out: I suggest you ask Uwe to put it in his README, and if possible do a version check at run time. Jeffrey Horner wrote: An FYI to those users having problems with windows RMySQL CRAN binaries. Original Message Subject: Problems with RMySQL and MySQL server version 5.1 Date: Wed, 7 Jan 2009 09:12:56 +0100 From: Erik Jørgensen erik.jorgen...@agrsci.dk To: jeff.hor...@vanderbilt.edu Hi Jeffrey I have some problems with the use of RMySQL since upgrading to RMySQL version 0.7-2 and MySQL server version 5.1. The RGUI crashes, when I e.g. call the function dbGetQuery(conn, sqlstring) (but not e.g. dbListTables(conn)). It seems that it is due to incompatibility with MySQL version 5.1. When I replace the libMySQL.dll file from version 5.1 with the 5.0 version of the file, the problem disappears. Best regards Erik Jørgensen Faculty of Agricultural Sciences, Aarhus University, Denmark PS. R - version 2.8.1 - Windows XP Professional Service Pack3. I specify the path to the DLL-file manually via the environment variable MYSQL_HOME. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 -- http://biostat.mc.vanderbilt.edu/JeffreyHorner __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] RMySQL crashes R
Duncan Murdoch-2 wrote: On 1/12/2009 1:02 PM, auburneconomics wrote: This is similar to another current post about RMySQL crashing R, except on the other post it crashed on connection to the database. I can successfully connect, and even can do dbListTables(). But, if I send a query or anything to actually see the data, R crashes to desktop. I have tried this on two computers, one Vista, one XP. Both crashed. I am running 2.8.1, and am using the correct version of DBI and RMySQL. They are both loaded with the library() function beforehand. Versions of MySQL that it was tried are 5.1 and 6.0a. I have searched on the internet and haven't found any answers, and would be grateful for any help, I'd recommend using RODBC instead. The disadvantage is that you'll be at the mercy of whoever wrote the ODBC driver, but I believe I've had good experience with the MySQL one. 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. I was hoping to be able to alter a MySQL database within R, which would in turn immediately update a web page written in PHP. I am already well versed in the MySQL/PHP stuff so it would be really neat if I could get this to work... My hunch is that there is something in a setting somewhere that is causing this. I bet its something really stupid (as it always seems to be). -- View this message in context: http://www.nabble.com/RMySQL-crashes-R-tp21419908p21421521.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] re tail case-pack ordering problem - can R help?
I'm a programmer, not a mathmatician. I heard about R, and I'm wondering if anyone can tell me if there is an existing R function that can help with a problem we're currently trying to find an algorithm for. If R is not the answer, but you can recommend a known algorithm, that would help a lot! I'm on a project in a retail corporation, working on a program to assist retail buyers in creating their orders. The program will be used internally, and not sold to other companies. In retail terms, the problem is to determine the best assortment of case packs to order for a given store, and given a set of desired quantities for each size of a product. A case pack is a set of sizes that the supplier assembles. The retailer must order in whole case packs. For example, For a given shoe style, in the color brown, a supplier has the following case packs available. Sizes -XS S M L XL XXL XXXL CasePack profiles: cp1 1 3 5 4 2 1 0 cp2 0 2 2 2 0 0 0 cp3 0 2 3 3 1 0 0 cp4 2 4 5 5 4 1 0 And, for a given store, the retailer has determined the following set the desired quantites of sizes to purchase. (This determination is based on sales history, and is not at all based on what the case packs for this item look like.) Sizes -XS S M L XL XXL XXXL 4 10 14 12 7 30 The question to be answered is, What set of quantities of the above case packs will give me the closest distribution to the desired set of sizes? The output would be a single recommendation for case-pack order quantities, in a form like the following. Case packQuantity cp1 0 cp2 3 cp3 2 cp4 1 There will be some other factors that may operate outside of the above core problem: There may be limits on the quantity available on some of the case packs. For instance, the supplier only has ten available of cp2. It seems this factor will need to be considered in the core algorithm. We realize we'll need to apply tolerance levels to the calculation. For example, for this shoe style, we will accept the solution if it comes to within 10% (plus or minus) of our desired quantities on each size. We may also apply a minimum. For example, the solution must have at least 1 of each size having a nonzero quantity. Thanks for any help! -- View this message in context: http://www.nabble.com/retail-case-pack-ordering-problem---can-R-help--tp21422054p21422054.html Sent from the R help mailing list archive at Nabble.com. [[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] Useful books for learning the R software and the S programming language
Look here to start. http://www.r-project.org/doc/bib/R-books.html Steve Friedman Ph. D. Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 steve_fried...@nps.gov Office (305) 224 - 4282 Fax (305) 224 - 4147 Robert Wilk dphage...@gmail. com To Sent by: r-help@r-project.org r-help-boun...@r- cc project.org Subject [R] Useful books for learning the R 01/12/2009 03:36 software and the S programming PM ESTlanguage any useful books for learning the R statistical software? are they pricey? and if the books recommended focus on S, how compatible will they be for someone learning R? thank you in advance for your help. P.S. specialized survey statistical procedures? Is R good at that? [[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] re tail case-pack ordering problem - can R help?
Hi gbh22, your problem looks a lot like a Cutting Stock Problem, http://en.wikipedia.org/wiki/Cutting_stock_problem Here, a_ij is your case pack profiles (how many of size j are in case pack i), x_i counts how many units of case pack i you want, and q_j counts how many units of size j you want. The Cutting Stock Problem then minimizes \sum c_ix_i subject to \sum a_ijx_j=q_j for all j, where c_i is some penalty parameter for case pack i. Perhaps you could model c_i as the price of case pack i, then you would minimize the total cost (while disregarding any leftover shoes). I'm sure variations have been looked at in the literature. I'd suggest you look at the literature cited in the Wikipedia article. In fact, this problem has been on my radar for a while now, though not with high priority. I'm in software for retail, not in retail itself: http://www.saf-ag.com. I'd love to discuss any solution approaches with you, if you are interested. Good luck with your case packs! Stephan Kolassa gbh22 schrieb: I'm a programmer, not a mathmatician. I heard about R, and I'm wondering if anyone can tell me if there is an existing R function that can help with a problem we're currently trying to find an algorithm for. If R is not the answer, but you can recommend a known algorithm, that would help a lot! I'm on a project in a retail corporation, working on a program to assist retail buyers in creating their orders. The program will be used internally, and not sold to other companies. In retail terms, the problem is to determine the best assortment of case packs to order for a given store, and given a set of desired quantities for each size of a product. A case pack is a set of sizes that the supplier assembles. The retailer must order in whole case packs. For example, For a given shoe style, in the color brown, a supplier has the following case packs available. Sizes -XS S M L XL XXL XXXL CasePack profiles: cp1 1 3 5 4 2 1 0 cp2 0 2 2 2 0 0 0 cp3 0 2 3 3 1 0 0 cp4 2 4 5 5 4 1 0 And, for a given store, the retailer has determined the following set the desired quantites of sizes to purchase. (This determination is based on sales history, and is not at all based on what the case packs for this item look like.) Sizes -XS S M L XL XXL XXXL 4 10 14 12 7 30 The question to be answered is, What set of quantities of the above case packs will give me the closest distribution to the desired set of sizes? The output would be a single recommendation for case-pack order quantities, in a form like the following. Case packQuantity cp1 0 cp2 3 cp3 2 cp4 1 There will be some other factors that may operate outside of the above core problem: There may be limits on the quantity available on some of the case packs. For instance, the supplier only has ten available of cp2. It seems this factor will need to be considered in the core algorithm. We realize we'll need to apply tolerance levels to the calculation. For example, for this shoe style, we will accept the solution if it comes to within 10% (plus or minus) of our desired quantities on each size. We may also apply a minimum. For example, the solution must have at least 1 of each size having a nonzero quantity. Thanks for any help! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Useful books for learning the R software and the S programming language
Robert Wilk wrote: any useful books for learning the R statistical software? are they pricey? Many. Useful depends on the reader, though, so look around. Here's a starting point http://www.r-project.org/doc/bib/R-books.html (modesty should forbid me to point at item 18 on the list and the fact that Amazon US has it currently 19% discounted) In general R books are cheaper than statistical monographs, but more expensive than the large market computer science books. and if the books recommended focus on S, how compatible will they be for someone learning R? Such books are strongly outnumbered by now. One important book from that group is Venables+Ripley's Modern Applied Statistics with S explicitly addresses R issues. thank you in advance for your help. P.S. specialized survey statistical procedures? Is R good at that? Not R in itself, but the survey package for it is rumoured to be state of the art, and its author has a book on it in its final stages. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 on nested mixed effects ANOVA
Mukta Chakraborty chakraborty.mukta at gmail.com writes: Hello, I am trying to run a mixed effects nested ANOVA but none of my codes are giving me any meaningful results and I am not sure what I am doing wrong. I am a new user on R and would appreciate some help. The experimental design is that I have some frogs that have been exposed to three acoustic Treatments and I am measuring neural activity (egr), in 12 brain regions. Some frogs also called different calls than others so I am testing for effect of Call as a fixed effect. I have Treatment (Trt), Brain Region (Region), and Call (Call) as fixed effects and I am modeling Subject (Subj) as a random effect with brain region nested within subject. I am using lme4 package and I am not sure if that is the correct one to use. I also have some missing values as NA as part of the dataset. I have also set Subj, Region, and Call as factors using as.factor. I have run the model which I am sure is wrong: model1-anova(lme(egr ~ Trt* Region, random=~1|Subj/Region,na.action=na.omit)) The output I am getting is: numDF denDFF-value p-value Min. : 1.00 Min. : 32 Min. : 2.891 Min. :0.000e+00 1st Qu.: 1.75 1st Qu.:197 1st Qu.: 12.120 1st Qu.:0.000e+00 Median : 6.50 Median :252 Median : 20.275 Median :1.146e-05 Mean : 9.00 Mean :197 Mean : 87.353 Mean :1.383e-05 3rd Qu.:13.75 3rd Qu.:252 3rd Qu.: 95.508 3rd Qu.:2.530e-05 Max. :22.00 Max. :252 Max. :305.972 Max. :3.240e-05 Any help on what I am doing wrong on the coding would be very helpful. Thanks a lot. Mukta 1. it would probably be a good idea to ask further questions on this topic on r-sig-mixed-models instead. 2. you probably want to look just at the lme() result, and not immediately wrap it an anova() frame. I'm a little surprised by your results -- but since you haven't given a reproducible example I don't know exactly what's wrong. When I run the lme example in the nlme package and then do anova(fm1) I get numDF denDF F-value p-value (Intercept) 180 3096.4889 .0001 age 180 85.8464 .0001 which doesn't look like your answer. 3. I don't think you want to use Region as both a random factor and a fixed factor. I would have guessed either lme(egr ~ Trt*Call, random=~1|Subj/Region,na.action=na.omit)) OR lme(egr ~ Trt*Call*Region, random=~1|Subj,na.action=na.omit)) I can also imagine that you might be interested in a crossed design in this case, in which case you should probably use lme4: library(lme4) lmer(egr~Trt*Call+(1|Subj)+(1|Region) ...) [I'm not sure how na.action works for lmer] good luck Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] roll weekly data to monthly level
Dear R users: I have a data set that looks something like this: IDtime y 12/01/20084 12/09/200812 19/01/20088 21/06/20083 23/01/20084 23/09/20089 26/03/20084 31/02/20083 31/10/20088 32/02/20087 32/10/20083 I'd like to sum up the weekly data to the monthly level, so that it looks something like this: IDtime y 12/200816 19/20088 21/20083 23/200813 26/20084 31/200811 32/200810 What is the best way to do it? Time must be character. How do I truncate a character so that I can remove the date and only keep the month and year? Thank you very much in advance. Julia -- View this message in context: http://www.nabble.com/roll-weekly-data-to-monthly-level-tp21424700p21424700.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] Useful books for learning the R software and the S programming language
Robert, I have Peter's book and I think it can be a very good place to start from... dispite the discount... :) If you like spatial analysis you can try to look for Roger Bivand et al. Applied Spatial Data Analysis with R, If you are into something else try the Use R collection from Springer... you may find something not that pricey that you can use. Best regards Carlos Em 2009/01/12, às 22:07, Peter Dalgaard escreveu: Robert Wilk wrote: any useful books for learning the R statistical software? are they pricey? Many. Useful depends on the reader, though, so look around. Here's a starting point http://www.r-project.org/doc/bib/R-books.html (modesty should forbid me to point at item 18 on the list and the fact that Amazon US has it currently 19% discounted) In general R books are cheaper than statistical monographs, but more expensive than the large market computer science books. and if the books recommended focus on S, how compatible will they be for someone learning R? Such books are strongly outnumbered by now. One important book from that group is Venables+Ripley's Modern Applied Statistics with S explicitly addresses R issues. thank you in advance for your help. P.S. specialized survey statistical procedures? Is R good at that? Not R in itself, but the survey package for it is rumoured to be state of the art, and its author has a book on it in its final stages. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Useful books for learning the R software and the S programming language
On Jan 12, 2009, at 3:36 PM, Robert Wilk wrote: any useful books for learning the R statistical software? are they pricey? Compared to medical texts, they are dirt cheap. and if the books recommended focus on S, how compatible will they be for someone learning R? Many are available for R these days. It used to be that MASS editions 1 through 4 by Venables and Ripley were the canonical starting points, but in recent years Dalgaard and other have contributed efforts at intro and intermediate texts. Cutting and pasting from the R-books page: http://www.r-project.org/doc/bib/R-books.html [18]Peter Dalgaard. Introductory Statistics with R. [49]John Verzani. Using R for Introductory Statistics. [48]Michael J. Crawley. Statistics: An Introduction using R. [62] William N. Venables and Brian D. Ripley. Modern Applied Statistics with S. Fourth Edition. (mentions only S in the title but I believe that where differences exist, they are pointed out in this edition.) [63]John Fox. An R and S-Plus Companion to Applied Regression. [65] Frank E. Harrell. Regression Modeling Strategies, with Applications to Linear Models, Survival Analysis and Logistic Regression. (I don't think Harrell intended this as a tutorial but I can't resist a plug. Alzola and Harrell have published a useful book length guide: http://biostat.mc.vanderbilt.edu/twiki/pub/Main/RS/sintro.pdf And Kuhnert and Venables have also written a book length pdf: http://cran.r-project.org/doc/contrib/Kuhnert+Venables-R_Course_Notes.zip thank you in advance for your help. P.S. specialized survey statistical procedures? Is R good at that? See whether Lumley's survey package functions are sufficient. Knowledgeable people have opined that they are more complete than what is available in SAS. http://faculty.washington.edu/tlumley/survey/ -- David Winsemius, MD Heritage Labs [[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] lm: how are polynomial functions interpreted?
Well. *_* , I think it should have been clear that this was not a question for which any code exists. In fact, I gave two very specific examples of function calls. The entire point of my question was not what's up with my (putative) code and data but rather to try to understand the overarching philosophy of the way lm() treats the function it's given. I do understand the sneaky ways to make it do a linear fit with or without forcing the origin. And, sure, I could have run a data set thru a bunch of different quadratic-like functions to try to see what happens. Let me pick a more complicated example. The general case of a sin fit might be Y = a + b*sin(d*x+phi) .(where, to be pedantic, x is the only data input. All others are coefficients to be found) If I try y-lm(yin~I(sin(x))), what is the actual fit function? And so on. That's why I was hoping for a more general explanation of what lm() does. Charles C. Berry wrote: On Mon, 12 Jan 2009, c...@witthoft.com wrote: [nothing deleted] matplot(1:100, lm(rnorm(100)~poly(1:100,4),x=T)$x ) # for example __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html Ahem! and provide commented, minimal, self-contained, reproducible code. ..^ Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.eduUC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] crash on multiple queries to postgresql db
On Friday 09 January 2009, Joe Conway wrote: Dylan Beaudette wrote: Subsequent calls to: conn - dbConnect(PgSQL(), host=localhost, dbname=xxx, user=xxx) query - dbSendQuery(conn, query_text) res - dbGetResult(query) are resulting in this: *** glibc detected *** /usr/local/lib/R/bin/exec/R: realloc(): invalid other attached packages: [1] RdbiPgSQL_1.8.0 Rdbi_1.8.0 lattice_0.17-20 Any ideas? Well, first off, since you are apparently using RdbiPgSQL from bioconductor, you should probably try asking there. But in any case, you might try the latest release from bioconductor: http://www.bioconductor.org/packages/release/bioc/src/contrib/RdbiPgSQL_1.1 6.0.tar.gz or else try the recently released PostgreSQL DBI package on CRAN: http://cran.stat.ucla.edu/src/contrib/RPostgreSQL_0.1-3.tar.gz HTH, Joe Thanks Joe. I have updated all of my R packages, along with my Bioconductor packages... and I still get the odd behavior: *** glibc detected *** /usr/local/lib/R/bin/exec/R: realloc(): invalid old size: 0xb7dad1e0 *** === Backtrace: = /lib/i686/cmov/libc.so.6[0xb7cc3624] /lib/i686/cmov/libc.so.6[0xb7cc71a1] /lib/i686/cmov/libc.so.6(realloc+0x106)[0xb7cc7b46] /usr/local/pgsql/lib/libpq.so.5[0xb7802166] /usr/local/pgsql/lib/libpq.so.5[0xb780239c] /usr/local/pgsql/lib/libpq.so.5[0xb77fbd31] /usr/local/pgsql/lib/libpq.so.5(PQfinish+0x15)[0xb77fbe85] /usr/local/lib/R/site-library/RdbiPgSQL/libs/RdbiPgSQL.so(PgSQLcloseConnection+0x38) [0xb783bb98] Again, here is my session info: R version 2.8.0 (2008-10-20) i686-pc-linux-gnu locale: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] grid stats graphics grDevices utils datasets methods [8] base other attached packages: [1] RdbiPgSQL_1.16.0 Rdbi_1.16.0 lattice_0.17-20 Here is the code that appears to be causing the problems: # load data from a PostGreSQL database, and return a dataframe # this will get called whenever the parent function is called # crashes after 3-5 subsequent calls load_sensor_data - function(query_text) { # conn becomes an object which contains the DB connection: conn - dbConnect(PgSQL(), host=localhost, dbname=SJER, user=dylan) ## pre-filter out possible bad data: query - dbSendQuery(conn, query_text) # fetch data according to query: res - dbGetResult(query) # convert characters to factors res - transform(res, probe_id = factor(probe_id)) res - transform(res, pedon_id = factor(pedon_id)) # generate a new date-time object in the dataframe res$date - as.POSIXct(strptime(res$date_time, format=%a %b %e %H:%M:%S %Y)) # cleanup dbDisconnect(conn) # doesn't completely fix problem crashing gc() # return the resulting dataframe return(res) } Thanks in advance, Dylan -- Dylan Beaudette Soil Resource Laboratory http://casoilresource.lawr.ucdavis.edu/ University of California at Davis 530.754.7341 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] lm: how are polynomial functions interpreted?
[E] Y = a + b*sin(d*x+phi) isn't a linear model and therefore can't be estimated with lm() -- you will need some heavier artillery. Linear as in lm() means linear in parameters. (As it happens, I'm adapting Gordon Smyth's pronyfreq S code for the above problem this afternoon, and have been wondering why someone else hasn't already done this? Any clues? url:www.econ.uiuc.edu/~rogerRoger Koenker emailrkoen...@uiuc.eduDepartment of Economics vox: 217-333-4558University of Illinois fax: 217-244-6678Champaign, IL 61820 On Jan 12, 2009, at 4:57 PM, Carl Witthoft wrote: Well. *_* , I think it should have been clear that this was not a question for which any code exists. In fact, I gave two very specific examples of function calls. The entire point of my question was not what's up with my (putative) code and data but rather to try to understand the overarching philosophy of the way lm() treats the function it's given. I do understand the sneaky ways to make it do a linear fit with or without forcing the origin. And, sure, I could have run a data set thru a bunch of different quadratic-like functions to try to see what happens. Let me pick a more complicated example. The general case of a sin fit might be Y = a + b*sin(d*x+phi) .(where, to be pedantic, x is the only data input. All others are coefficients to be found) If I try y-lm(yin~I(sin(x))), what is the actual fit function? And so on. That's why I was hoping for a more general explanation of what lm() does. Charles C. Berry wrote: On Mon, 12 Jan 2009, c...@witthoft.com wrote: [nothing deleted] matplot(1:100, lm(rnorm(100)~poly(1:100,4),x=T)$x ) # for example __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html Ahem! and provide commented, minimal, self-contained, reproducible code. ..^ Charles C. Berry(858) 534-2098 Dept of Family/ Preventive Medicine E mailto:cbe...@tajo.ucsd.eduUC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] roll weekly data to monthly level [SEC=UNCLASSIFIED]
Julia, I had a similar query a while ago which I solved using a suggestion from Gabor, have a look at: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/69597.html Hope it helps, Augusto Augusto Sanabria. MSc, PhD. Mathematical Modeller Risk Impact Analysis Group Geospatial Earth Monitoring Division Geoscience Australia (www.ga.gov.au) Cnr. Jerrabomberra Av. Hindmarsh Dr. Symonston ACT 2601 Ph. (02) 6249-9155 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of liujb Sent: Tuesday, 13 January 2009 8:58 To: r-help@r-project.org Subject: [R] roll weekly data to monthly level Dear R users: I have a data set that looks something like this: IDtime y 12/01/20084 12/09/200812 19/01/20088 21/06/20083 23/01/20084 23/09/20089 26/03/20084 31/02/20083 31/10/20088 32/02/20087 32/10/20083 I'd like to sum up the weekly data to the monthly level, so that it looks something like this: IDtime y 12/200816 19/20088 21/20083 23/200813 26/20084 31/200811 32/200810 What is the best way to do it? Time must be character. How do I truncate a character so that I can remove the date and only keep the month and year? Thank you very much in advance. Julia -- View this message in context: http://www.nabble.com/roll-weekly-data-to-monthly-level-tp21424700p21424700.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] roll weekly data to monthly level
I had trouble getting my output to look like yours until I realized that you did not want to sum up the weekly data to the monthly level but rather to sum up to the monthly *and* ID level. dftag-aggregate(dft$y, list(ID=dft$ID, Month=as.yearmon(dft$time, %m/%d/%Y)), FUN=sum) # in Month order rather than ID, Month order dftag[order(dftag$ID, dftag$Month), ] IDMonth x 3 1 Feb 2008 16 7 1 Sep 2008 8 1 2 Jan 2008 3 5 2 Mar 2008 13 6 2 Jun 2008 4 2 3 Jan 2008 11 4 3 Feb 2008 10 -- David Winsemius On Jan 12, 2009, at 4:57 PM, liujb wrote: Dear R users: I have a data set that looks something like this: IDtime y 12/01/20084 12/09/200812 19/01/20088 21/06/20083 23/01/20084 23/09/20089 26/03/20084 31/02/20083 31/10/20088 32/02/20087 32/10/20083 I'd like to sum up the weekly data to the monthly level, so that it looks something like this: IDtime y 12/200816 19/20088 21/20083 23/200813 26/20084 31/200811 32/200810 What is the best way to do it? Time must be character. How do I truncate a character so that I can remove the date and only keep the month and year? Thank you very much in advance. Julia -- View this message in context: http://www.nabble.com/roll-weekly-data-to-monthly-level-tp21424700p21424700.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] lm: how are polynomial functions interpreted?
I find the simplest way to interpret a *linear* model formula, as used by lm() and aov() is to take the left hand side as specifying the response variable (or variables) and to take the right hand side as specifying the *columns of the model matrix* in a coded way. Notice that the parameters are implicit and do not occur anywhere in the formula. To take your example, yin ~ I(sin(x)), [which you could simply write as yin ~ sin(x)] would specify yin as the response and the model matrix had two columns namely 1 for the intercept term and sin(x) X = [1 sin(x)] So the model you would be fitting, in a more conventional notation, would be Y = a + b*sin(x) + error. lm() and aov() accommodate only *linear* parameters. You can recoginse a linear parameter by the fact that when you differentiate the right hand side of the model formula with respect to it, the result does not depend on that parameter. To take your other model Y = a + b*sin(d*x + phi) + error (you left out the error, BTW), clearly a and b are linear parameters but d and phi are not, so you cannot fit this model directly with lm() or aov(). If you knew d and phi, of course, you could fit it since the remaining parameters are all linear and you would specify it using y ~ sin(d*x+phi) where d and phi would need to have values at the time of fitting. The simplest way to fit this kind of model is to use nls(). You can even exploit the fact that a and b are linear parameters by using the plinear algorithm, but I'll leave you to sort that one out. You can also re-write the model so that you have just one non-linear parameter, but again, you can sort that out. ___ I think the reason why people were perhaps looking a little askance at your this kind of question on R help is that there are plenty of books around where this sort of issue is really done to death. The introduction to R from the help menu of R is one place where you might start, but there are better ones and now plenty of them. Bill Venables http://www.cmis.csiro.au/bill.venables/ -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Carl Witthoft Sent: Tuesday, 13 January 2009 8:58 AM To: r-help@r-project.org Subject: Re: [R] lm: how are polynomial functions interpreted? Well. *_* , I think it should have been clear that this was not a question for which any code exists. In fact, I gave two very specific examples of function calls. The entire point of my question was not what's up with my (putative) code and data but rather to try to understand the overarching philosophy of the way lm() treats the function it's given. I do understand the sneaky ways to make it do a linear fit with or without forcing the origin. And, sure, I could have run a data set thru a bunch of different quadratic-like functions to try to see what happens. Let me pick a more complicated example. The general case of a sin fit might be Y = a + b*sin(d*x+phi) .(where, to be pedantic, x is the only data input. All others are coefficients to be found) If I try y-lm(yin~I(sin(x))), what is the actual fit function? And so on. That's why I was hoping for a more general explanation of what lm() does. Charles C. Berry wrote: On Mon, 12 Jan 2009, c...@witthoft.com wrote: [nothing deleted] matplot(1:100, lm(rnorm(100)~poly(1:100,4),x=T)$x ) # for example __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html Ahem! and provide commented, minimal, self-contained, reproducible code. ..^ Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.eduUC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] roll weekly data to monthly level
Try this. First we read in the data. In reality you would use the commented out read line. Then use chron to convert the times to chron dates and as.yearmon from zoo to convert them to year/months. Finally aggregate and sort. Lines - IDtime y + 12/01/20084 + 12/09/200812 + 19/01/20088 + 21/06/20083 + 23/01/20084 + 23/09/20089 + 26/03/20084 + 31/02/20083 + 31/10/20088 + 32/02/20087 + 32/10/20083 library(zoo) # as.yearmon library(chron) # chron # DF - read.table(myfile.dat, header = TRUE, as.is = TRUE) DF - read.table(textConnection(Lines), header = TRUE, as.is = TRUE) DF$yearmon - as.yearmon(chron(DF$time)) res - aggregate(DF[y], DF[c(ID, yearmon)], sum) res[order(res[, 1], res[, 2]), ] ID yearmon y 3 1 Feb 2008 16 7 1 Sep 2008 8 1 2 Jan 2008 3 5 2 Mar 2008 13 6 2 Jun 2008 4 2 3 Jan 2008 11 4 3 Feb 2008 10 On Mon, Jan 12, 2009 at 4:57 PM, liujb liujul...@yahoo.com wrote: Dear R users: I have a data set that looks something like this: IDtime y 12/01/20084 12/09/200812 19/01/20088 21/06/20083 23/01/20084 23/09/20089 26/03/20084 31/02/20083 31/10/20088 32/02/20087 32/10/20083 I'd like to sum up the weekly data to the monthly level, so that it looks something like this: IDtime y 12/200816 19/20088 21/20083 23/200813 26/20084 31/200811 32/200810 What is the best way to do it? Time must be character. How do I truncate a character so that I can remove the date and only keep the month and year? Thank you very much in advance. Julia -- View this message in context: http://www.nabble.com/roll-weekly-data-to-monthly-level-tp21424700p21424700.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] pmax and sort?
I am having a hard time understanding the documentation and I was wondering if there would be someone to help clear the cobwebs. The documentation for pmax states: pmax and pmin take one or more vectors (or matrices) as arguments and return a single vector giving the ‘parallel’ maxima (or minima) of the vectors. The first element of the result is the maximum (minimum) of the first elements of all the arguments, the second element of the result is the maximum (minimum) of the second elements of all the arguments and so on. Shorter inputs are recycled if necessary. attributes (such as names or dim) are transferred from the first argument (if applicable). This descirption seems to me like what sort would return. Would someone please help me understand the differenece between pmax and sort? Thank you. Kevin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] pmax and sort?
I am having a hard time understanding the documentation and I was wondering if there would be someone to help clear the cobwebs. The documentation for pmax states: pmax and pmin take one or more vectors (or matrices) as arguments and return a single vector giving the ‘parallel’ maxima (or minima) of the vectors. The first element of the result is the maximum (minimum) of the first elements of all the arguments, the second element of the result is the maximum (minimum) of the second elements of all the arguments and so on. Shorter inputs are recycled if necessary. attributes (such as names or dim) are transferred from the first argument (if applicable). This descirption seems to me like what sort would return. Would someone please help me understand the differenece between pmax and sort? Thank you. Kevin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Drawing Polygons with xyplot in lattice
Hello: I've come to a dead-end in my search for a solution to a graphing problem that I am encountering. I have used xyplot (from the lattice package) successfully to plot 36 time-series plots (lines) of under-5 mortality for a set of countries in Sub-Sarahan Africa. What I would now like to do is to add vertical bands (rectangles) that correspond to time-periods during which each of the 36 countries was at war, which would be different for each of the 36 panels. The effect I'd like to produce is similar that found here: http://thinkorthwim.com/2007/09/12/recession/ (but with 36 panels, each of which has a different period(s) shaded). I've done this successfully one plot at a time with the simple plot commmand (using polygon after having first drawn the line plot), but am having difficulty replicating it with xyplot. Here is some sample code (with 4 countries and 10 years), which is as far as I've been able to get: library(lattice) df-data.frame(c(u5cmr=round(runif(40)*100)),country=c(rep(Angola,10), rep(Benin,10), rep(Botswana,10), rep(Burkina Faso,10)), year=rep(1991:2000,4)) names(df)-c(u5cmr, country, year) xyplot(u5cmr ~ year | country , ylab = U5 cmr (per thousand), data = df, type = l, lty = 1, col =red, xlab=Year, as.table=T, lwd=2) R version 2.7.2 Patched (2008-09-20 r47259) on Mac OS 10.5 Thanks, Josip __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Drawing Polygons with xyplot in lattice
There is an example in the example section of the ?xyplot.zoo help page in the zoo package. On Mon, Jan 12, 2009 at 8:16 PM, Josip Dasovic j...@sfu.ca wrote: Hello: I've come to a dead-end in my search for a solution to a graphing problem that I am encountering. I have used xyplot (from the lattice package) successfully to plot 36 time-series plots (lines) of under-5 mortality for a set of countries in Sub-Sarahan Africa. What I would now like to do is to add vertical bands (rectangles) that correspond to time-periods during which each of the 36 countries was at war, which would be different for each of the 36 panels. The effect I'd like to produce is similar that found here: http://thinkorthwim.com/2007/09/12/recession/ (but with 36 panels, each of which has a different period(s) shaded). I've done this successfully one plot at a time with the simple plot commmand (using polygon after having first drawn the line plot), but am having difficulty replicating it with xyplot. Here is some sample code (with 4 countries and 10 years), which is as far as I've been able to get: library(lattice) df-data.frame(c(u5cmr=round(runif(40)*100)),country=c(rep(Angola,10), rep(Benin,10), rep(Botswana,10), rep(Burkina Faso,10)), year=rep(1991:2000,4)) names(df)-c(u5cmr, country, year) xyplot(u5cmr ~ year | country , ylab = U5 cmr (per thousand), data = df, type = l, lty = 1, col =red, xlab=Year, as.table=T, lwd=2) R version 2.7.2 Patched (2008-09-20 r47259) on Mac OS 10.5 Thanks, Josip __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Can't Destroy Dim Names
Dear all, I have the following matrix: str(mat) Named chr [1:32268] yQAAA jQAAQ UQAAg FQAAw 1QABA ... - attr(*, names)= chr [1:32268] CA CC CG CT ... I want to destroy the attribute yielding only this: str(mat) Named chr [1:32268] yQAAA jQAAQ UQAAg FQAAw 1QABA ... But why this command fail to do it? dimnames(mat) - NULL Btw, the object size for keeping matrix with dim names is greater than without, right? - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] pmax and sort?
Here are a couple of quick examples that may help: 1:10 [1] 1 2 3 4 5 6 7 8 9 10 10:1 [1] 10 9 8 7 6 5 4 3 2 1 pmax( 10:1, 1:10 ) [1] 10 9 8 7 6 6 7 8 9 10 pmin( 1:10, 5 ) [1] 1 2 3 4 5 5 5 5 5 5 In the first example with pmax, there are 2 vectors being compared (10-1, 1-10), so first 10 is compared to 1 and since 10 is larger it is the first element of the returned vector, then 9 is compared to 2 and 9 becomes the second element, this continues till the 10th comparison is 1 vs. 10 and 10 is the final element. The second (pmin) example shows the recycling, each of the numbers 1-10 is compared to the number 5, in each case the smaller of the pair is returned (1-4 for the first 4 elements, then 5 for the rest). Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of rkevinbur...@charter.net Sent: Monday, January 12, 2009 5:55 PM To: r-help@r-project.org Subject: [R] pmax and sort? I am having a hard time understanding the documentation and I was wondering if there would be someone to help clear the cobwebs. The documentation for pmax states: pmax and pmin take one or more vectors (or matrices) as arguments and return a single vector giving the ‘parallel’ maxima (or minima) of the vectors. The first element of the result is the maximum (minimum) of the first elements of all the arguments, the second element of the result is the maximum (minimum) of the second elements of all the arguments and so on. Shorter inputs are recycled if necessary. attributes (such as names or dim) are transferred from the first argument (if applicable). This descirption seems to me like what sort would return. Would someone please help me understand the differenece between pmax and sort? Thank you. Kevin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Can't Destroy Dim Names
Is this what you want: x - c(a=1, b=2, c=3) str(x) Named num [1:3] 1 2 3 - attr(*, names)= chr [1:3] a b c names(x) - NULL x [1] 1 2 3 On Mon, Jan 12, 2009 at 8:32 PM, Gundala Viswanath gunda...@gmail.com wrote: Dear all, I have the following matrix: str(mat) Named chr [1:32268] yQAAA jQAAQ UQAAg FQAAw 1QABA ... - attr(*, names)= chr [1:32268] CA CC CG CT ... I want to destroy the attribute yielding only this: str(mat) Named chr [1:32268] yQAAA jQAAQ UQAAg FQAAw 1QABA ... But why this command fail to do it? dimnames(mat) - NULL Btw, the object size for keeping matrix with dim names is greater than without, right? - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Can't Destroy Dim Names
Your mat variable is not a matrix, but a vector (a named vector), therefore it does not have dimensions or dimnames. Try names(mat) - NULL Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Gundala Viswanath Sent: Monday, January 12, 2009 6:32 PM To: r-h...@stat.math.ethz.ch Subject: [R] Can't Destroy Dim Names Dear all, I have the following matrix: str(mat) Named chr [1:32268] yQAAA jQAAQ UQAAg FQAAw 1QABA ... - attr(*, names)= chr [1:32268] CA CC CG CT ... I want to destroy the attribute yielding only this: str(mat) Named chr [1:32268] yQAAA jQAAQ UQAAg FQAAw 1QABA ... But why this command fail to do it? dimnames(mat) - NULL Btw, the object size for keeping matrix with dim names is greater than without, right? - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] lm: how are polynomial functions interpreted?
damn. My apologies to everyone -- I sent one message and it got destroyed somehow. Here's the part that was missing, which led to rather a lot of confusion on all parts. The two recent responses to a question about lm suggested 1) lm(y~poly(x,2)) 2) lm(y~I(x^2)) So my question was *supposed* to be related to how lm operated differently (if at all) on these two different 'versions' of a quadratic fit. My gut reaction was that y~I(x^2) would not be the same as y~f(x) where f(x) is a+bx+cx^2 . So what I was trying to find out was just how lm() deals with various definitions of the orthogonal polynomials its presented with. Another way, maybe, to ask, is: how does one specify to fit exactly to a + bx +cx^2 vs bx + cx^2 vs cx^2 ? Thanks and apologies again to all the people who quite properly misunderstood what I was harping on due to the munging of my first post. Carl David Winsemius wrote: On Jan 12, 2009, at 5:57 PM, Carl Witthoft wrote: Well. *_* , I think it should have been clear that this was not a question for which any code exists. In fact, I gave two very specific examples of function calls. Huh? I think most of the readers of the list saw a basically empty message body. That was the point of Berry's [nothing deleted]. If you are under the belief that this is a continuation of an earlier question, then it may not be threading up in the manner you hoped for. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Fast way to finding index in Vector
Dear all, Suppose I have the following vector as repository: repo - c(AAA, AAT, AAC, AAG, ATA,ATT) Given another query vector qr - c(AAC, ATT) is there a way I can find the query index in repository in a fast way. Giving: [1] 3 6 Typically the size of repo is around ~12million element, and query around ~1 million element. - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 needed for Loading tm package
I appreciate alll helpers for R. I have struggled with Rweka problem related with tm text mining package in R. My problem was solved when I replaced RWeka_0.3-15.zip with RWeka_0.3-13.zip under the OS of Win XP. Now my tm package works fine in R. I don't know why it works. Thanks all who gave me good help Kum Hwang Ph.D. On Mon, Jan 12, 2009 at 5:19 PM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: How do you account for the fact that the package passed its checks on the build machine, e.g. http://cran.r-project.org/bin/windows/contrib/2.8/check/RWeka-check.log and no one else is reporting this? (And it does work for me.) Blaming your tools is easy, but doing so on a public forum is disrespectful and against the rw-FAQ http://cran.r-project.org/bin/windows/base/rw-FAQ.html#Can-I-install-packages-into-libraries-in-this-version_003f (note the word 'unsupported'). Uwe Ligges does a great job helping Windows' users by building binary packages, and deserves your thanks, not vague and unsubstantiated blame. On Mon, 12 Jan 2009, Kum-Hoe Hwang wrote: Thank Prof. Brian Ripley for your comments. Based on Prof Brian Ripley's comments, I checked Java environments in my PC. But I have not solved a tm package problem in Win R software. I am not sure but my current conclusion is that the Win-based R binary software has definitely a problem with Rweka package or subpackage. Should I wait for another upgraded R binary version under the window XP, tm' package or Rweka ets? Or I'd better migrate to non-window OS such as Linux, etc? You definitely shou;d read and follow the FAQ, as this could well be a Java incompatibility with the binary package. Kum Hwang, Ph.D. On Sat, Jan 10, 2009 at 8:06 PM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: On Sat, 10 Jan 2009, Kum-Hoe Hwang wrote: Howdy Gurus again Thanks to Tony.Breyal, I was able to writing the following script for analyzing a text document. But I got an error with tm' package. I don't why I got the error from the R script below. I think I followed proccess of R tm manual. Please do read the messages you got. I see Error in .jinit(system.file(jar, c(weka.jar, RWeka.jar), package = pkgname, : Cannot create Java virtual machine (-1) so the problem is with your Java installation and RWeka, not 'tm'. First make sure you have a working installation of RWeka -- I suspect you do not even have Java installed, but it could be a version or path issue (but very unlikely to be an R issue). I use R v2.8.1. and tm_0.3-3.zip under Win XP. Thanks in advance, Kum Hwang # setting directory my.path -'C:\\_work\\Daddys\\myProjects\\2009 defaultProject\\R\\textfile\\' # text miner pakacge library(tm) Loading required package: Snowball Loading required package: RWeka - Error in .jinit(system.file(jar, c(weka.jar, RWeka.jar), package = pkgname, : Cannot create Java virtual machine (-1) Error : .onLoad failed in 'loadNamespace' for 'RWeka' Error: package 'RWeka' could not be loaded my.corpurs -Corpus(DirSource(my.path), readerControl = list(reader=readPlain)) Error: could not find function Corpus my.tdm - TermDocMatrix(my.corpus) Error: could not find function TermDocMatrix my.tdm[1,] Error: object my.tdm not found -- Kum-Hoe Hwang, Ph.D. Phone : 82-31-250-3516 Email : phdhw...@gmail.com [[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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 -- Kum-Hoe Hwang, Ph.D. Phone : 82-31-250-3516 Email : phdhw...@gmail.com -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 -- Kum-Hoe Hwang, Ph.D. Phone : 82-31-250-3516 Email : phdhw...@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] Fast way to finding index in Vector
Hi Jorge and all, How can I modified your code when query size can be bigger than repository, meaning that it can contain repeats. e.g. qr - c(AAC, ATT, ATT,AAC, ATT, ATT, AAT, ATT, ATT, ) Sorry, I should have mentioned this earlier. - Gundala Viswanath Jakarta - Indonesia On Tue, Jan 13, 2009 at 11:11 AM, Jorge Ivan Velez jorgeivanve...@gmail.com wrote: Perhaps which(repo%in%qr) ? HTH, Jorge On Mon, Jan 12, 2009 at 9:07 PM, Gundala Viswanath gunda...@gmail.com wrote: Dear all, Suppose I have the following vector as repository: repo - c(AAA, AAT, AAC, AAG, ATA,ATT) Given another query vector qr - c(AAC, ATT) is there a way I can find the query index in repository in a fast way. Giving: [1] 3 6 Typically the size of repo is around ~12million element, and query around ~1 million element. - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] polychoric correlation: issue with coefficient sign
Hello, I am running polychoric correlations on a dataset composed of 12 ordinal and binary variables (N =384), using the polycor package. One of the association (between 2 dichotomous variables) is very high using the 2-step estimate (0.933 when polychoric run only between the two variables; but 0.801 when polychoric run on the 12 variables). The same correlation run with ML estimate returns a singularity message. First, I would like to know why the estimations between only the two dichotomous variables and with all the variables at once (with the 2-step estimate) returns slightly different results. Secondly, when i checked back the distribution of these two dichotomous variables they appear about symmetrically opposed. Therefore, one should indeed expect a strong association between them, but a negative one, isn't it? Why does the polychoric correlation returns a positive coefficient? What does it mean for the rest of the coefficients, should i trust them? I have to say I'm new to R and not very strong in statistics, I hope I haven't posted a stupid question... cheers, Dorothee -- View this message in context: http://www.nabble.com/polychoric-correlation%3A-issue-with-coefficient-sign-tp21425977p21425977.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] lm: how are polynomial functions interpreted?
Try this to see the X matrix that its fitting y to: x - 1:10 model.matrix(~ poly(x, 2)) model.matrix(~ I(x^2)) On Mon, Jan 12, 2009 at 9:01 PM, Carl Witthoft c...@witthoft.com wrote: damn. My apologies to everyone -- I sent one message and it got destroyed somehow. Here's the part that was missing, which led to rather a lot of confusion on all parts. The two recent responses to a question about lm suggested 1) lm(y~poly(x,2)) 2) lm(y~I(x^2)) So my question was *supposed* to be related to how lm operated differently (if at all) on these two different 'versions' of a quadratic fit. My gut reaction was that y~I(x^2) would not be the same as y~f(x) where f(x) is a+bx+cx^2 . So what I was trying to find out was just how lm() deals with various definitions of the orthogonal polynomials its presented with. Another way, maybe, to ask, is: how does one specify to fit exactly to a + bx +cx^2 vs bx + cx^2 vs cx^2 ? Thanks and apologies again to all the people who quite properly misunderstood what I was harping on due to the munging of my first post. Carl David Winsemius wrote: On Jan 12, 2009, at 5:57 PM, Carl Witthoft wrote: Well. *_* , I think it should have been clear that this was not a question for which any code exists. In fact, I gave two very specific examples of function calls. Huh? I think most of the readers of the list saw a basically empty message body. That was the point of Berry's [nothing deleted]. If you are under the belief that this is a continuation of an earlier question, then it may not be threading up in the manner you hoped for. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Returning Non-Unique Index with Which (alternatives?)
Dear all, I tried to find index in repo given a query with this: repo - c(AAA, AAT, AAC, AAG, ATA, ATT) qr - c(AAC, ATT, ATT) which(repo%in%qr) [1] 3 6 Note that the query contain repeating elements, yet the output of which only returns unique. How can I make it returning [1] 3 6 6 instead? - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Fast way to finding index in Vector
Is this what you want: repo - c(AAA, AAT, AAC, AAG, ATA,ATT) qr - c(AAC, ATT, ATT,AAC, ATT, ATT, AAT, ATT, ATT) match(qr, repo) [1] 3 6 6 3 6 6 2 6 6 On Mon, Jan 12, 2009 at 9:22 PM, Gundala Viswanath gunda...@gmail.com wrote: Hi Jorge and all, How can I modified your code when query size can be bigger than repository, meaning that it can contain repeats. e.g. qr - c(AAC, ATT, ATT,AAC, ATT, ATT, AAT, ATT, ATT, ) Sorry, I should have mentioned this earlier. - Gundala Viswanath Jakarta - Indonesia On Tue, Jan 13, 2009 at 11:11 AM, Jorge Ivan Velez jorgeivanve...@gmail.com wrote: Perhaps which(repo%in%qr) ? HTH, Jorge On Mon, Jan 12, 2009 at 9:07 PM, Gundala Viswanath gunda...@gmail.com wrote: Dear all, Suppose I have the following vector as repository: repo - c(AAA, AAT, AAC, AAG, ATA,ATT) Given another query vector qr - c(AAC, ATT) is there a way I can find the query index in repository in a fast way. Giving: [1] 3 6 Typically the size of repo is around ~12million element, and query around ~1 million element. - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fast way to finding index in Vector
Yes Jim, exactly. BTW, I found from ?match Matching for lists is potentially very slow and best avoided except in simple cases. Since I am doing this for million of tags. Is there a faster alternatives? - Gundala Viswanath Jakarta - Indonesia On Tue, Jan 13, 2009 at 12:14 PM, jim holtman jholt...@gmail.com wrote: Is this what you want: repo - c(AAA, AAT, AAC, AAG, ATA,ATT) qr - c(AAC, ATT, ATT,AAC, ATT, ATT, AAT, ATT, ATT) match(qr, repo) [1] 3 6 6 3 6 6 2 6 6 On Mon, Jan 12, 2009 at 9:22 PM, Gundala Viswanath gunda...@gmail.com wrote: Hi Jorge and all, How can I modified your code when query size can be bigger than repository, meaning that it can contain repeats. e.g. qr - c(AAC, ATT, ATT,AAC, ATT, ATT, AAT, ATT, ATT, ) Sorry, I should have mentioned this earlier. - Gundala Viswanath Jakarta - Indonesia On Tue, Jan 13, 2009 at 11:11 AM, Jorge Ivan Velez jorgeivanve...@gmail.com wrote: Perhaps which(repo%in%qr) ? HTH, Jorge On Mon, Jan 12, 2009 at 9:07 PM, Gundala Viswanath gunda...@gmail.com wrote: Dear all, Suppose I have the following vector as repository: repo - c(AAA, AAT, AAC, AAG, ATA,ATT) Given another query vector qr - c(AAC, ATT) is there a way I can find the query index in repository in a fast way. Giving: [1] 3 6 Typically the size of repo is around ~12million element, and query around ~1 million element. - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fast way to finding index in Vector
Is this fast enough for you; matches of 2000 against 2M tags takes 0.2 seconds: str(x) chr [1:2000] EAEDC DACCD BEAAD CDDDA ABDCA ACACC DADAA ABCAD ... str(z) chr [1:200] EAEDC DACCD BEAAD CDDDA ABDCA ACACC DADAA ABCAD ... system.time(y - match(x,z)) user system elapsed 0.2 0.0 0.2 str(y) int [1:2000] 1 2 3 4 5 6 7 8 9 10 ... On Mon, Jan 12, 2009 at 10:17 PM, Gundala Viswanath gunda...@gmail.com wrote: Yes Jim, exactly. BTW, I found from ?match Matching for lists is potentially very slow and best avoided except in simple cases. Since I am doing this for million of tags. Is there a faster alternatives? - Gundala Viswanath Jakarta - Indonesia On Tue, Jan 13, 2009 at 12:14 PM, jim holtman jholt...@gmail.com wrote: Is this what you want: repo - c(AAA, AAT, AAC, AAG, ATA,ATT) qr - c(AAC, ATT, ATT,AAC, ATT, ATT, AAT, ATT, ATT) match(qr, repo) [1] 3 6 6 3 6 6 2 6 6 On Mon, Jan 12, 2009 at 9:22 PM, Gundala Viswanath gunda...@gmail.com wrote: Hi Jorge and all, How can I modified your code when query size can be bigger than repository, meaning that it can contain repeats. e.g. qr - c(AAC, ATT, ATT,AAC, ATT, ATT, AAT, ATT, ATT, ) Sorry, I should have mentioned this earlier. - Gundala Viswanath Jakarta - Indonesia On Tue, Jan 13, 2009 at 11:11 AM, Jorge Ivan Velez jorgeivanve...@gmail.com wrote: Perhaps which(repo%in%qr) ? HTH, Jorge On Mon, Jan 12, 2009 at 9:07 PM, Gundala Viswanath gunda...@gmail.com wrote: Dear all, Suppose I have the following vector as repository: repo - c(AAA, AAT, AAC, AAG, ATA,ATT) Given another query vector qr - c(AAC, ATT) is there a way I can find the query index in repository in a fast way. Giving: [1] 3 6 Typically the size of repo is around ~12million element, and query around ~1 million element. - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.