[R] A complicated 'aggregate'
Hi, I have a financial (zoo) time series with prices and volumes (although I can get the coredata as a matrix). Due to the data-source some indices have multiple observations. I want to aggregate these according to a weighted average. 11:00:0134 1000 11:00:0135 500 11:00:0135 1000 11:00:0234 500 11:00:0235 500 should become 11:00:0134.62500 11:00:0234.51000 I currently do this using a loop, and the result is abysmally slow: f - function(x) { retval - c(0, 0); x - coredata(x); retval[2] - sum(x[,2]); retval[1] - sum(x[,1] * x[,2]) / retval[2]; retval; } #ts is a zoo timeseries uniqueTimes - unique(index(ts)) tmpMat - NULL for(i in 1:length(uniqueTimes)) { tmpMat - rbind(tmpMat, f(ts[uniqueTimes[i]])); } ts.agg - zooreg(tmpMat, order.by=uniqueTimes); I'm sure the above can be done with aggregate or tapply or by or something, but I haven't managed to get those to work. Any suggestions greatly appreciated! Cheers, Josh Quigley. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A simple question about summary.glm
Thanks Uwe for your question, Yesterday I found out what I wanted to know: In the summary table the values refer to the different of each treatment to the first treatment alphabetical (in my case it was the control group and therefore served as Tukey test, which is what I wanted in the first place). Uwe Ligges wrote: michal33 wrote: Hello, I am new to R and have tried to search similar questions but could not find exactly what I am looking for, but I apologize if the question was already asked. I have 10 different treatments and want to know whether they affect the sex ratios of insect emergence. After running the glms I got this table: Df Deviance Resid. Df Resid. Dev F Pr(F) NULL133 9250.3 sex1481.5 132 8768.9 7.7212 0.006314 ** trt9 1099.1 123 7669.7 1.9585 0.049780 * But now I would like to know WHICH of the treatments was significant. I tried to use Tukey test but for some reason it does not work. My question is: I used the following function: summary(file.name, corr=F) and got the following table: Deviance Residuals: Min 1Q Median 3Q Max -14.118 -4.808 -1.4662.033 33.882 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 8.696e+00 1.893e+00 4.594 1.06e-05 *** sexm-3.791e+00 1.364e+00-2.779 0.00631 ** trtccc -1.050e+00 4.325e+00-0.243 0.80859 trtcga3 2.450e+00 4.325e+00 0.566 0.57211 trtcga4 -2.300e+00 4.325e+00-0.532 0.59584 trtg 1.550e+00 2.497e+00 0.621 0.53593 trtga4 -5.550e+00 4.325e+00-1.283 0.20183 trtp 5.422e+00 2.566e+00 2.113 0.03658 * trtpg -1.850e+00 2.497e+00-0.741 0.46019 trtw-3.634e-17 2.497e+00 -1.46e-17 1.0 trtwg -3.750e+00 2.497e+00-1.502 0.13573 What do the stars mean? Well, you omitted the last lines from the output which include: Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 i.e. *** for values 0.001; * for values in [0.01, 0.05) etc. Uwe Ligges Is it the same as Tukey test that tells me which treatment is different from which? i.e. is trtp (with *) significantly different to the control (which, by the way do not appear in this list and I do not know why)? Thanks Michal __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/A-simple-question-about-summary.glm-tf4167757.html#a11935815 Sent from the R help mailing list archive at Nabble.com. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Goodman Kruskal's tau
Hi I need to know which package in R calculates the Goodman Kruskal's tau statistic for nominal data. Also is there any implementation for multiple classification analysis (Andrews at al 1973) in R? Any information on this would be greatly appreciated. Thank you Upasna -- - Upasna Sharma Research Scholar Shailesh J. Mehta School of Management, Indian Institute of Technology, Bombay Powai, Mumbai - 400076, India - Homepage: http://www.som.iitb.ac.in/people/upasna/ - The past is a history, the future is a mystery, and this moment is a gift. That is why this moment is called 'the present'. Anonymous __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] MTBF Reliability calculations
On Tue, 2007-07-31 at 15:10 -0700, Jennings, Eric wrote: I'm working on a project involving reliability values (known failure rates) for a system with approximately 700 components with a set cconfiguration. I'm looking to compute a parts-count MTBF (mean time between failures) for the system. (See also MIL-HDBK-217) Is there anything in R that can help me with this? You could enter all the data (component types and counts) into a file and then use R to multiply and add. R is a little more than you need to perform a parts count 217 analysis or a part stress analysis for that matter. A spreadsheet would suffice for something as small as 700 components if you don't want to or can't use something like Relex, Reliasoft, Item, etc. -- Andrew Weibullguy Rowland Reliability Safety Engineer [EMAIL PROTECTED] http://webpages.charter.net/weibullguy http://reliafree.sourceforge.net signature.asc Description: This is a digitally signed message part __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] array loop
Hi Dong GUO 郭东 [EMAIL PROTECTED] napsal dne 31.07.2007 15:27:35: Thanks, Petr. I changed the equation mark from = to -, then, it works fine. Dont know what difference it has made between the = and -.. from help page The operators - and = assign into the environment in which they are evaluated. The operator- can be used anywhere, whereas the operator = is only allowed at the top level (e.g., in the complete expression typed at the command prompt) or as one of the subexpressions in a braced list of expressions. Although I do not fully understand where I can use - and where =, to be on safe side I use - everywhere when I want to do assignment of some value(s). Regards Petr Regards, Dong On 7/31/07, Petr PIKAL [EMAIL PROTECTED] wrote: Hi as you say that the computing is part of a function than the best way to see what is hapenning is to use debug(your.function) see ?debug for options. Regards Petr [EMAIL PROTECTED] [EMAIL PROTECTED] napsal dne 31.07.2007 00:11:00: Dear all, here are two arrays: region(26,31,8), nation(8) I tried to get a new array, say, giGi(26,31,8) giGi - array(0,dim = c(region_dim)) for (i in (1:region_dim[3])) { giGi[,,i] = region[,,i]-nation[,i] } As the above is part of function, but results shows only giGi[,,1] has the right answers, all the others (giGi[,,2],..giGi[..8]) are zeros. I have checked array of region and nation, they are not zeros at all when I do manually, it is not the case, giGi has meanful numbers. can some one tell me the trick in this process?? Many thanks in advance. Dong [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Nonlinear optimization with constraints
Make a function and add the constraints to the function eg. if (Ai1 x ) Inf. By making the result Infinite, you have added the constraints manually. Vu Nguyen-4 wrote: Hello R community, I am sorry for the previous accidental posting as I pressed a wrong key. I am using R for creating a model using optimization. I would like to ask if there is R-function/package for solving the problem below: Minimize sum(abs(exp^(Ai1 x1 + Ai2 x2 + ... + Aim xm - bi) - 1)), for each i = 1, ..., n. subject to Ai1 x1 + Ai2 x2 + ... + Ajm xm - bi = c, where c is a scalar. (x is a vector of variables, A is nxm matrix, b is a vector) I tried to use optim(), nlm(), and constrOptim, but they do not allow a kind of the constraint in the problem above. Thanks for your help. Regards, Vu - Original Message From: Vu Nguyen [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Tuesday, July 31, 2007 3:50:52 PM Subject: Nonlinear optimization with constraints Hello R community, I am using R for creating a model using optimization. I would like to ask if there is R-function/package for solving the problem below: Minimize sum(abs(exp^(Ai1 x1 + Ai2 x2 + ... + Aim xm - bi) - 1)), for each i = 1, ..., n. subject to Ai1 x1 + Ai2 x2 + ... + Ajm xm - bi = c, where c is a scalar. (x is a vector of variables, A is nxm matrix, b is a vector) [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Re%3A-Nonlinear-optimization-with-constraints-tf4197046.html#a11941309 Sent from the R help mailing list archive at Nabble.com. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] deriv for psigamma
UweL == Uwe Ligges [EMAIL PROTECTED] on Tue, 31 Jul 2007 12:13:45 +0200 writes: UweL francogrex wrote: Hi, 2 questions: [] Question 2: deriv(~gamma(x),x) expression({ .expr1 - gamma(x) .value - .expr1 .grad - array(0, c(length(.value), 1), list(NULL, c(x))) .grad[, x] - .expr1 * psigamma(x) attr(.value, gradient) - .grad .value }) BUT deriv3(~gamma(x),x) Error in deriv3.formula(~gamma(x), x) : Function 'psigamma' is not in the derivatives table What I want is the expression for the second derivative (which I believe is trigamma(x), or psigamma(x,1)), how can I obtain that? UweL By using some algebraic software (rather than a numeric one) or UweL contributing complete derivatives tables for the next R release. Yes, but for the present case, one could argue that the R internal code which knows d/dx lgamma(x) = psi(x) = digamma(x) = psigamma(x,0) should easily be enhanced to also know d/dx psigamma(x, n) = psigamma(x, n+1) and consequently (but maybe with an extra clause) d/dx psigamma(x) = psigamma(x, 1) The code is in R*/src/main/deriv.c and patches which implement the above and (there are few more 'FIXME's there ... ;-) against https://svn.r-project.org/R/trunk/src/main/deriv.c are welcome - after useR!2007 Martin Maechler, ETH Zurich __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] RWeka cross-validation and Weka_control Parametrization
Hello, I have two questions concerning the RWeka package: 1.) First question: How can one perform a cross validation, -say 10fold- for a given data set and given model ? 2.) Second question What is the correct syntax for the parametrization of e.g. Kernel classifiers interface m1 - SMO(Species ~ ., data = iris, control = Weka_control(K=weka.classifiers.functions.supportVector.RBFKernel,G=0.1)) m2 - SMO(Species ~ ., data = iris, control = Weka_control(K=weka.classifiers.functions.supportVector.RBFKernel,G=1.0)) m1 SMO Kernel used: RBF kernel: K(x,y) = e^-(0.01* x-y,x-y^2) ## should be: RBF kernel: K(x,y) = e^-(0.1* x-y,x-y^2) m2 SMO Kernel used: RBF kernel: K(x,y) = e^-(0.01* x-y,x-y^2) ## should be: RBF kernel: K(x,y) = e^-(1.0* x-y,x-y^2) That is, the control arguments ignores the parameter 'G' (Gamma) for the above syntax. What's wrong with this syntax ? many thanks Bjoern __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Custom axis
Dear R users, I would like to draw a plot with a custom scale for the axis. More precisely, instead of plotting y on x, I want to plot y on a monotone function of x (for instance a*x+b). Which command and/or package should I use in order to get this result? Thanks Florent Bresson _ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] need help with pdf-plot
Hello, I'm trying to plot a set of barplots like a matrix (2 rows, 10 columns fromreduced_mat) to a pdf. It works with the following parameters: pdf(test.pdf,width=ncol(reduced_mat)*2, height=nrow(reduced_mat)*2, pointsize = 12) par(mfcol = c(nrow(reduced_mat),ncol(reduced_mat)), oma = c(0,0,0,0), lwd=48/96, cex.axis = 0.5, las = 2, cex.main = 1.0) The I get a long narrow page format with the quadratic barplots. But I would like to have a A4 format in the end and the plots not filling the whole page (they should stay somehow quadratic and not be stretched...). What shall I look for to achieve this? Antje __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Nonlinear optimization with constraints
If you put in penalties for breaking constraints, it is generally better to make the penalty depend on the size of the violation. This keeps the function continuous (though usually not differentiable at the boundary), and gives the optimizer a hint about which way to go. Patrick Burns [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and A Guide for the Unwilling S User) Bartjoosen wrote: Make a function and add the constraints to the function eg. if (Ai1 x ) Inf. By making the result Infinite, you have added the constraints manually. Vu Nguyen-4 wrote: Hello R community, I am sorry for the previous accidental posting as I pressed a wrong key. I am using R for creating a model using optimization. I would like to ask if there is R-function/package for solving the problem below: Minimize sum(abs(exp^(Ai1 x1 + Ai2 x2 + ... + Aim xm - bi) - 1)), for each i = 1, ..., n. subject to Ai1 x1 + Ai2 x2 + ... + Ajm xm - bi = c, where c is a scalar. (x is a vector of variables, A is nxm matrix, b is a vector) I tried to use optim(), nlm(), and constrOptim, but they do not allow a kind of the constraint in the problem above. Thanks for your help. Regards, Vu - Original Message From: Vu Nguyen [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Tuesday, July 31, 2007 3:50:52 PM Subject: Nonlinear optimization with constraints Hello R community, I am using R for creating a model using optimization. I would like to ask if there is R-function/package for solving the problem below: Minimize sum(abs(exp^(Ai1 x1 + Ai2 x2 + ... + Aim xm - bi) - 1)), for each i = 1, ..., n. subject to Ai1 x1 + Ai2 x2 + ... + Ajm xm - bi = c, where c is a scalar. (x is a vector of variables, A is nxm matrix, b is a vector) [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Custom axis
x - 1:10 y - rnorm(10,10,1) x2 - 3*x + 2 plot(y ~ x, xaxt = n) axis(side=1,at = x, labels = x2) Joris Florent Bresson [EMAIL PROTECTED] frTo Sent by: r-help@stat.math.ethz.ch [EMAIL PROTECTED] cc at.math.ethz.ch Subject [R] Custom axis 01/08/2007 11:49 Dear R users, I would like to draw a plot with a custom scale for the axis. More precisely, instead of plotting y on x, I want to plot y on a monotone function of x (for instance a*x+b). Which command and/or package should I use in order to get this result? Thanks Florent Bresson _ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Re : Custom axis
Maybe I do not explain well what I would like to do. I do not want to change the labels of the axis, but the scale. What I want is a general procedure for changing the scale. Its like using a logarithmic scale on a plot. Labels are the same, but the increases of x along the x-axis are defined by a known monotone and continuous function. Florent Bresson - Message d'origine De : [EMAIL PROTECTED] [EMAIL PROTECTED] À : Florent Bresson [EMAIL PROTECTED] Cc : r-help@stat.math.ethz.ch; [EMAIL PROTECTED] Envoyé le : Mercredi, 1 Août 2007, 12h01mn 58s Objet : Re: [R] Custom axis x - 1:10 y - rnorm(10,10,1) x2 - 3*x + 2 plot(y ~ x, xaxt = n) axis(side=1,at = x, labels = x2) Joris Florent Bresson [EMAIL PROTECTED] frTo Sent by: r-help@stat.math.ethz.ch [EMAIL PROTECTED] cc at.math.ethz.ch Subject [R] Custom axis 01/08/2007 11:49 Dear R users, I would like to draw a plot with a custom scale for the axis. More precisely, instead of plotting y on x, I want to plot y on a monotone function of x (for instance a*x+b). Which command and/or package should I use in order to get this result? Thanks Florent Bresson _ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Re : Custom axis
What about the other way round? x - 1:10 y - rnorm(10,10,1) x2 - 3*x + 2 plot(y ~ x2, xaxt = n) axis(side=1,at = x2, labels = x) Florent Bresson [EMAIL PROTECTED] frTo [EMAIL PROTECTED] 01/08/2007 12:14 cc r-help@stat.math.ethz.ch, [EMAIL PROTECTED] Subject Re : [R] Custom axis Maybe I do not explain well what I would like to do. I do not want to change the labels of the axis, but the scale. What I want is a general procedure for changing the scale. Its like using a logarithmic scale on a plot. Labels are the same, but the increases of x along the x-axis are defined by a known monotone and continuous function. Florent Bresson - Message d'origine De : [EMAIL PROTECTED] [EMAIL PROTECTED] À : Florent Bresson [EMAIL PROTECTED] Cc : r-help@stat.math.ethz.ch; [EMAIL PROTECTED] Envoyé le : Mercredi, 1 Août 2007, 12h01mn 58s Objet : Re: [R] Custom axis x - 1:10 y - rnorm(10,10,1) x2 - 3*x + 2 plot(y ~ x, xaxt = n) axis(side=1,at = x, labels = x2) Joris Florent Bresson [EMAIL PROTECTED] frTo Sent by: r-help@stat.math.ethz.ch [EMAIL PROTECTED] cc at.math.ethz.ch Subject [R] Custom axis 01/08/2007 11:49 Dear R users, I would like to draw a plot with a custom scale for the axis. More precisely, instead of plotting y on x, I want to plot y on a monotone function of x (for instance a*x+b). Which command and/or package should I use in order to get this result? Thanks Florent Bresson _ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Cut marks on a plot's y-axis to indica te it is a truncated axis
Hi, I've plotted a Kaplan-Meier curve but the curves only range from 0.7 to 1 on the y-axis. Therefore I have used: - ylim=c(0.7,1) [although I think convention dictates that you plot 0.5 to 1 to show the median? A few papers I've read have done this]?? BUT, I would like a symbol like // (but rotated 90 degrees) to indicate that the y-axis has been truncated. I'd need to be able to specify exactly where on the axis to put the symbol as well. I couldn't find anything under par or plot for doing this Thanks for any help, DaveL Study to be a Paralegal at a school near you. Click here to get free info now. http://tagline.bidsystem.com/fc/Ioyw36XJIG4kS9LX6hifX0P6pUB4A2ryL6hnXlr q7nFKzLeaHmCnIS/ span id=m2wTlpfont face=Arial, Helvetica, sans-serif size=2 style=font-size:13.5px___BRGet the Free email that has everyone talking at a href=http://www.mail2world.com target=newhttp://www.mail2world.com/abr font color=#99Unlimited Email Storage #150; POP3 #150; Calendar #150; SMS #150; Translator #150; Much More!/font/font/span [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Cut marks on a plot's y-axis to indica te it is a truncated axis
Hi, I've plotted a Kaplan-Meier curve but the curves only range from 0.7 to 1 on the y-axis. Therefore I have used: - ylim=c(0.7,1) [although I think convention dictates that you plot 0.5 to 1 to show the median? A few papers I've read have done this]?? BUT, I would like a symbol like // (but rotated 90 degrees) to indicate that the y-axis has been truncated. I'd need to be able to specify exactly where on the axis to put the symbol as well. I couldn't find anything under par or plot for doing this Thanks for any help, DaveL Free information on becoming a Legal Assistant. Click Now! http://tagline.bidsystem.com/fc/Ioyw36XKKhNb648GlNi10yhQt8Hj9egcisvXgKE K8RmtgEBA8RI05g/ span id=m2wTlpfont face=Arial, Helvetica, sans-serif size=2 style=font-size:13.5px___BRGet the Free email that has everyone talking at a href=http://www.mail2world.com target=newhttp://www.mail2world.com/abr font color=#99Unlimited Email Storage #150; POP3 #150; Calendar #150; SMS #150; Translator #150; Much More!/font/font/span [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] array loop
Thanks again, Petr. Following the reference, that would be true that = only assign values to the top level...So apparently using '-' is the safe all the time to assign values. Dong On 8/1/07, Petr PIKAL [EMAIL PROTECTED] wrote: Hi Dong GUO ¹ù¶« [EMAIL PROTECTED] napsal dne 31.07.2007 15:27:35: Thanks, Petr. I changed the equation mark from = to -, then, it works fine. Dont know what difference it has made between the = and -.. from help page The operators - and = assign into the environment in which they are evaluated. The operator- can be used anywhere, whereas the operator = is only allowed at the top level (e.g., in the complete expression typed at the command prompt) or as one of the subexpressions in a braced list of expressions. Although I do not fully understand where I can use - and where =, to be on safe side I use - everywhere when I want to do assignment of some value(s). Regards Petr Regards, Dong On 7/31/07, Petr PIKAL [EMAIL PROTECTED] wrote: Hi as you say that the computing is part of a function than the best way to see what is hapenning is to use debug(your.function) see ?debug for options. Regards Petr [EMAIL PROTECTED] [EMAIL PROTECTED] napsal dne 31.07.2007 00:11:00: Dear all, here are two arrays: region(26,31,8), nation(8) I tried to get a new array, say, giGi(26,31,8) giGi - array(0,dim = c(region_dim)) for (i in (1:region_dim[3])) { giGi[,,i] = region[,,i]-nation[,i] } As the above is part of function, but results shows only giGi[,,1] has the right answers, all the others (giGi[,,2],..giGi[..8]) are zeros. I have checked array of region and nation, they are not zeros at all when I do manually, it is not the case, giGi has meanful numbers. can some one tell me the trick in this process?? Many thanks in advance. Dong [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] clear workspace
Dear all, How can I clear the workspace, as we do in Matlab clear all?? Many thanks in advance. Dong [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Simple table with frequency variable
Hallo, Im trying to find out how to tabulate frequencies of factors when the data have a frequency variable. e,g: i-rep(1:5,2) j-rep(1:2,5) N-10*i+j table(i,j) gives a table of ones as each combination occurs only once. How does one get a table with the corresponding N's? Thanks! Gerrit. -- Gerrit Draisma Department of Public Health Erasmus MC, University Medical Center Rotterdam Room AE-103 P.O. Box 2040 3000 CA Rotterdam The Netherlands Phone: +31 10 4087124 Fax: +31 10 4638474 http://mgzlx4.erasmusmc.nl/pwp/?gdraisma __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Cut marks on a plot's y-axis to indicate it is a truncated axis
David Lloyd wrote: Hi, I've plotted a Kaplan-Meier curve but the curves only range from 0.7 to 1 on the y-axis. Therefore I have used: - ylim=c(0.7,1) [although I think convention dictates that you plot 0.5 to 1 to show the median? A few papers I've read have done this]?? BUT, I would like a symbol like // (but rotated 90 degrees) to indicate that the y-axis has been truncated. I'd need to be able to specify exactly where on the axis to put the symbol as well. I couldn't find anything under par or plot for doing this Hi David, Try looking for axis.break in the plotrix package. Jim __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A complicated 'aggregate'
Use wtd.mean from Hmisc and by: Lines - 11:00:0134 1000 11:00:0135 500 11:00:0135 1000 11:00:0234 500 11:00:0235 500 library(Hmisc) # for wtd.mean library(zoo) library(chron) # replace with DF - read.table(mytable.dat) DF - read.table(textConnection(Lines)) f - function(x) { data.frame(time = x[1,1], price = wtd.mean(x[,2], x[,3]), vol = sum(x[,3])) } DFby - do.call(rbind, by(DF, DF[1], f)) z - zoo(cbind(price = DFby[,2], vol = DFby[,3]), times(DFby[,1])) zr - as.zooreg(z) On 7/31/07, Josh Quigley [EMAIL PROTECTED] wrote: Hi, I have a financial (zoo) time series with prices and volumes (although I can get the coredata as a matrix). Due to the data-source some indices have multiple observations. I want to aggregate these according to a weighted average. 11:00:0134 1000 11:00:0135 500 11:00:0135 1000 11:00:0234 500 11:00:0235 500 should become 11:00:0134.62500 11:00:0234.51000 I currently do this using a loop, and the result is abysmally slow: f - function(x) { retval - c(0, 0); x - coredata(x); retval[2] - sum(x[,2]); retval[1] - sum(x[,1] * x[,2]) / retval[2]; retval; } #ts is a zoo timeseries uniqueTimes - unique(index(ts)) tmpMat - NULL for(i in 1:length(uniqueTimes)) { tmpMat - rbind(tmpMat, f(ts[uniqueTimes[i]])); } ts.agg - zooreg(tmpMat, order.by=uniqueTimes); I'm sure the above can be done with aggregate or tapply or by or something, but I haven't managed to get those to work. Any suggestions greatly appreciated! Cheers, Josh Quigley. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] clear workspace
On Wed, 2007-08-01 at 14:06 +0200, Dong GUO 郭东 wrote: Dear all, How can I clear the workspace, as we do in Matlab clear all?? Many thanks in advance. Dong ?rm E.g.: rm(list = ls()) will remove everything shown by ls(). Look at ?ls to see possible arguments to that function to fine tune this, for example, by default objects that start with a . are omitted from the results of ls(). G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Cut marks on a plot's y-axis to indicate it is a truncated axis
--- David Lloyd [EMAIL PROTECTED] wrote: Hi, I've plotted a Kaplan-Meier curve but the curves only range from 0.7 to 1 on the y-axis. Therefore I have used: - ylim=c(0.7,1) [although I think convention dictates that you plot 0.5 to 1 to show the median? A few papers I've read have done this]?? BUT, I would like a symbol like // (but rotated 90 degrees) to indicate that the y-axis has been truncated. I'd need to be able to specify exactly where on the axis to put the symbol as well. I couldn't find anything under par or plot for doing this Thanks for any help, DaveL I think Jim Lemon's anwsered the question but why do you need a cut? There is no need to have a zero on the plot unless it is some quirky style matter for the journal. Any literate scientific reader should be able to understand that the y-axis runs from .5 to 1 or whatever. Adding a zero point and the || simply is what Tufte would call chart junk. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plot matrix data- lattice?
Try this: mat - matrix(1:24, 6, dimnames = list(year = 2001:2006, region = letters[1:4])) library(lattice) xyplot(Freq ~ year | region, as.data.frame.table(mat)) On 8/1/07, Dong Guo [EMAIL PROTECTED] wrote: Dear all, I have a matrix, dim = (years, regions) I would like to plot the data in a lattice so that each panel is region's plot with y-axis based on values, x-axis based on year. how can I do that? Many thanks in advance. Dong [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] plot matrix data- lattice?
Dear all, I have a matrix, dim = (years, regions) I would like to plot the data in a lattice so that each panel is region's plot with y-axis based on values, x-axis based on year. how can I do that? Many thanks in advance. Dong [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plot matrix data- lattice?
?matrix On 8/1/07, Dong Guo [EMAIL PROTECTED] wrote: Thanks, Gabor. My matrix is from a big array(year, regions,variables). so, matrix does not have row names or col names, how could i add the col names or row names?? Thanks again. Dong On 8/1/07, Gabor Grothendieck [EMAIL PROTECTED] wrote: Try this: mat - matrix(1:24, 6, dimnames = list(year = 2001:2006, region = letters[1:4])) library(lattice) xyplot(Freq ~ year | region, as.data.frame.table(mat)) On 8/1/07, Dong Guo [EMAIL PROTECTED] wrote: Dear all, I have a matrix, dim = (years, regions) I would like to plot the data in a lattice so that each panel is region's plot with y-axis based on values, x-axis based on year. how can I do that? Many thanks in advance. Dong [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plot matrix data- lattice?
Thanks, Gabor. My matrix is from a big array(year, regions,variables). so, matrix does not have row names or col names, how could i add the col names or row names?? Thanks again. Dong On 8/1/07, Gabor Grothendieck [EMAIL PROTECTED] wrote: Try this: mat - matrix(1:24, 6, dimnames = list(year = 2001:2006, region = letters[1:4])) library(lattice) xyplot(Freq ~ year | region, as.data.frame.table(mat)) On 8/1/07, Dong Guo [EMAIL PROTECTED] wrote: Dear all, I have a matrix, dim = (years, regions) I would like to plot the data in a lattice so that each panel is region's plot with y-axis based on values, x-axis based on year. how can I do that? Many thanks in advance. Dong [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Reading Matrices
Dear all, I have been successful so far in plotting matrices and getting the regression line. But, as the matrices contains values like 1 and 0 (diagonal line) which is actually not needed as they are for the same gene, is creating bias in my regression line. I wish to neglect that part of the matrix and read the rest and plot the matrices again. I am attaching two matrices here for your reference. Can anyone please help me regarding that. Thanks very much. Urmi - Get the freedom to save as many mails as you wish. Click here to know how.1 -0.012096 -0.100857 -0.069916 -0.097162 0.0073820.49239 -0.083894 0.3832290.122648 -0.133041 0.378121-0.064975 0.475417-0.156476 -0.080742 -0.012096 1 -0.105556 0.113937-0.092952 0.1747180.08174 0.064185-0.004801 0.118615 0.0733620.025144-0.051149 0.0055490.144066 -0.045014 -0.100857 -0.105556 1 0.048302-0.065759 -0.021766 -0.089656 -0.026402 -0.187463 0.115297 -0.094202 -0.179138 -0.036165 -0.106557 -0.087692 0.675215 -0.069916 0.1139370.0483021 0.025407 0.0166620.0097610.302218-0.157830.004884 -0.0539 0.06716 0.078652-0.047702 -0.000423 -0.037833 -0.097162 -0.092952 -0.065759 0.0254071 -0.018238 -0.087263 0.021593-0.078723 -0.110616 0.127107-0.02927-0.094423 -0.048349 0.019307 -0.05013 0.0073820.174718-0.021766 0.016662-0.018238 1 -0.01282-0.015617 0.084991-0.061002 -0.017901 -0.02836-0.023457 0.0027270.675366 -0.016839 0.49239 0.08174 -0.089656 0.009761-0.087263 -0.01282 1 0.1033510.5451160.137995-0.120075 0.335196-0.036118 0.454495-0.186613 -0.069724 -0.083894 0.064185-0.026402 0.3022180.021593 -0.015617 0.1033511 -0.082256 0.022675 0.0294520.010494-0.039677 -0.04907-0.019435 -0.035206 0.383229-0.004801 -0.187463 -0.15783-0.078723 0.0849910.545116-0.082256 1 0.087963 0.2123690.413117-0.030350.5761470.169672 -0.140684 0.1226480.1186150.1152970.004884-0.110616 -0.061002 0.1379950.0226750.0879631 0.0667210.100693-0.105733 0.054071-0.080891 -0.123128 -0.133041 0.073362-0.094202 -0.0539 0.127107 -0.017901 -0.120075 0.0294520.2123690.066721 1 0.19798 -0.097407 -0.115526 0.167922-0.058937 0.3781210.025144-0.179138 0.06716 -0.02927 -0.028360.3351960.0104940.4131170.100693 0.19798 1 -0.105542 0.2247350.079891-0.165202 -0.064975 -0.051149 -0.036165 0.078652-0.094423 -0.023457 -0.036118 -0.039677 -0.03035-0.105733 -0.097407 -0.105542 1 -0.062121 -0.062172 -0.023992 0.4754170.005549-0.106557 -0.047702 -0.048349 0.0027270.454495-0.049070.5761470.054071 -0.115526 0.224735-0.062121 1 -0.025131 -0.086425 -0.156476 0.144066-0.087692 -0.000423 0.019307 0.675366-0.186613 -0.019435 0.169672-0.080891 0.1679220.079891-0.062172 -0.025131 1 -0.075676 -0.080742 -0.045014 0.675215-0.037833 -0.05013 -0.016839 -0.069724 -0.035206 -0.140684 -0.123128 -0.058937 -0.165202 -0.023992 -0.086425 -0.075676 1 0 1.7016341.7329661.6384781.804548 1.6799821.8086821.9079091.7820821.820282 1.3932571.5688962.0142731.40849 1.7308051.645146 1.7016340 1.121.0721741.238244 1.1136781.58344 1.6826671.55684 1.59504 1.423253 1.9618982.4072751.8014922.1238072.038148 1.7329661.120 0.5481740.977588 0.8530221.614772
[R] Two-way ANOVA
I've got this dataframe X12 X14 X17 X19 vitigni years 11 4 78 54 rie 2005 21 4 7 4 rie 2005 31 4 75 5 rie 2005 42 5 66 5croa 2005 51 4 4 46croa 2005 62 5 7 6croa 2005 73 2 56 5 rie 2006 83 6 4 7 rie 2006 93 2 36 7 rie 2006 10 1 5 3 7croa 2006 11 1 342 65 7croa 2006 12 1 4 56 6croa 2006 vitigni and years are the two factors. how can I run a two way ANOVA on each column? -- Scegli infostrada: ADSL gratis per tutta lestate e telefoni senza canone Telecom __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] passing args to R CMD BATCH in win 2000
Hello and sorry to bother. Please help. I searched the archives but could not find out why --args is being ignored on Windows 2000. I try R CMD BATCH --slave 11.R 11.Rout --args 12 and 11.R has x=commandArgs(trail=T) print(x) a=x[length(x)] write.csv(a,file=13.out) q(no) the argument is not passed to the R process. 11.Rout only shows processing time and 13.out does not have the value. Thank you all. stephen [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] lattice: densityplot: improper length of lim when more than one conditioning variable, scales free, and empty panels
I am using R 2.5.0 and lattice 0.15-5. plot1, plot2, and plot3 all work fine. plot4 gives the error. x-1:12 f-gl(3,4) g-gl(4,3) plot1-xyplot(y~x|f*g) plot2-xyplot(y~x|f*g,scales=list(relation=free)) plot3-densityplot(~x|f*g) plot4-densityplot(~x|f*g,scales=list(relation=free)) Thanks Ben __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [R-pkgs] New R package sqldf
On 8/1/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Extremely cool and useful I immediately saw uses for it in some of the work I do. So went to look at it. I especially liked the examples with joins! I observed a few small bugs in the documentation: - The help references The sqldf home page URL: http://code.google.com/p/batchfiles/ but it should be of course .../p/sqldf Thanks. Its fixed in the svn repository now. Will be part of next release. - Example 5 there didn't work for me. Maybe I don't have something loaded? minSL - 7 limit - 3 fn$sqldf(select * from iris where Sepal_Length $minSL limit $limit) Error: attempt to apply non-function Works for me. What versions are you using? library(sqldf) minSL - 7 limit - 3 fn$sqldf(select * from iris where Sepal_Length $minSL limit $limit) Sepal_Length Sepal_Width Petal_Length Petal_Width Species 1 7.1 3.0 5.9 2.1 virginica 2 7.6 3.0 6.6 2.1 virginica 3 7.3 2.9 6.3 1.8 virginica packageDescription(gsubfn)$Version [1] 0.3-3 packageDescription(sqldf)$Version [1] 0-1.1 packageDescription(DBI)$Version [1] 0.2-3 packageDescription(RSQLite)$Version [1] 0.5-5 R.version.string # Windows XP [1] R version 2.5.1 (2007-06-27) Also, not shown, but example(fn) works for me. Other things to try are try it on a new R session and if that still does not work try sourcing it from the repository first: library(gsubfn) source(http://gsubfn.googlecode.com/svn/trunk/R/fn.R;) fn$sqldf(select * from iris where Sepal_Length $minSL limit $limit) Let me know if any of these things work or not. None of the examples in ?fn work for me either, giving the same error message. The examples in gsubfn work as do the rest of the sqldf examples. As mentioned, they all work for me. Let me know what the result is of trying the previous suggestions. I am on Windows XP with R version 2.5.1 version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 5.1 year 2007 month 06 day27 svn rev42083 language R version.string R version 2.5.1 (2007-06-27) David L. Reiner Rho Trading Securities, LLC -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gabor Grothendieck Sent: Tuesday, July 31, 2007 7:43 PM To: [EMAIL PROTECTED] Subject: [R] [R-pkgs] New R package sqldf sqldf is an R package for running SQL select statements on one or more R data frames. It is optimized for convenience making it useful for ad hoc queries against R data frames. Given an SQL select statement whose tables are the names of R data frames it: - sets up the database (by default it transparently sets up an in memory SQLite database using RSQLite; however, MySQL via RMySQL, can be specified as an alternative. MySQL has not been tested.) - imports the data frames found in SQL select statement into the database - runs the SQL select statement - outputs the result back to a data frame - uses a heuristic to assign the appropriate column classes to the result - removes the database so that all the user has to do is issue a one line function call with one argument, the select statement. Here is an example which processes an SQL select statement whose functionality is similar to the R aggregate function. Note that although the iris dataset (which is built into R) uses the name Sepal.Length the R database interface, DBI, converts that to Sepal_Length. Just install the sqldf package from CRAN and type these two lines into R without the prompts: library(sqldf) sqldf(select Species, avg(Sepal_Length) from iris group by Species) Species avg(Sepal_Length) 1 setosa 5.006 2 versicolor 5.936 3 virginica 6.588 As can be seen from the example, there is: - no database setup - no importing and exporting into the database - no coercing of the returned columns to the appropriate class (in most cases) It can be used: - as an alternate syntax for data frame manipulation - learning SQL if you know R - learning R if you know SQL The sqldf package has a single function, sqldf. More information is available by issuing the command ?sqldf from within R. More examples and useful links are available at the sqldf home page: http://code.google.com/p/sqldf/ ___ R-packages mailing list [EMAIL PROTECTED] https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Two-way ANOVA
I forget to specify that the data in the table are random. and I want to know how it is possible to carry out all the two way ANOVA test in a single run for all the columns. thank you -- Initial Header --- From : [EMAIL PROTECTED] To : Cc : r-help r-help@stat.math.ethz.ch Date : Wed, 1 Aug 2007 16:57:39 +0200 Subject : [R] Two-way ANOVA I've got this dataframe X12 X14 X17 X19 vitigni years 11 4 78 54 rie 2005 21 4 7 4 rie 2005 31 4 75 5 rie 2005 42 5 66 5croa 2005 51 4 4 46croa 2005 62 5 7 6croa 2005 73 2 56 5 rie 2006 83 6 4 7 rie 2006 93 2 36 7 rie 2006 10 1 5 3 7croa 2006 11 1 342 65 7croa 2006 12 1 4 56 6croa 2006 vitigni and years are the two factors. how can I run a two way ANOVA on each column? -- Scegli infostrada: ADSL gratis per tutta lestate e telefoni senza canone Telecom __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Scegli infostrada: ADSL gratis per tutta lestate e telefoni senza canone Telecom __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] cross-correlations
Dear R-users, I would like a suggestion. I have two time series covering the period 1000-2000 a.D. and I would like to understand if there are some time significant correlations between them. Samples in the first time series are quite compact because about a sample per year is available. The second one is a time serie where values are quite sporadic, i.e. there is a value every 20-50 years. Which is the best way to procede? How to compare them? I tried to consider average values over the same time interval (e.g. 100 years) and running averages (es. time intervals of 100 years shifted by 20 y). I think that running average over overlapping intervals can influence correlation. How to consider the significativity of my test? Thank You very Much Michela Rosso - - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] shadow between two lines in plot()
Dear R users, I used the following code to draw a scatter plot. plot(x,y,type=n) points(x,y,pch=1) And then I used the abline functions to draw two lines. I want to add the shadow between those two lines. abline(h=200) abline(h=300) Any suggestions? Thanks Rebecca -- This e-mail and any files transmitted with it may contain pr...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to sort dataframe levels
Emilio- One possible way to do this is to create a new factor and put the levels in the order you want them in. For example: related.differences$header2 - factor(related.differences$header, levels=c(spontaneous recovery, negative reinforcer, ... etc. ) where you want spontaneous recovery to be the first level, negative is the second, and so forth. Cheers, Andrea Johnson [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [R-pkgs] New R package sqldf
It works after rm(list=ls()) I had a function called 'fn'; if I had paid close attention when I loaded gsubfn, I would have seen the warning. My fault. Thanks again for a most useful package! David L. Reiner Rho Trading Securities, LLC -Original Message- From: Gabor Grothendieck [mailto:[EMAIL PROTECTED] Sent: Wednesday, August 01, 2007 10:27 AM To: David Reiner [EMAIL PROTECTED] Cc: r-help@stat.math.ethz.ch Subject: Re: [R] [R-pkgs] New R package sqldf On 8/1/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Extremely cool and useful I immediately saw uses for it in some of the work I do. So went to look at it. I especially liked the examples with joins! I observed a few small bugs in the documentation: - The help references The sqldf home page URL: http://code.google.com/p/batchfiles/ but it should be of course .../p/sqldf Thanks. Its fixed in the svn repository now. Will be part of next release. - Example 5 there didn't work for me. Maybe I don't have something loaded? minSL - 7 limit - 3 fn$sqldf(select * from iris where Sepal_Length $minSL limit $limit) Error: attempt to apply non-function Works for me. What versions are you using? library(sqldf) minSL - 7 limit - 3 fn$sqldf(select * from iris where Sepal_Length $minSL limit $limit) Sepal_Length Sepal_Width Petal_Length Petal_Width Species 1 7.1 3.0 5.9 2.1 virginica 2 7.6 3.0 6.6 2.1 virginica 3 7.3 2.9 6.3 1.8 virginica packageDescription(gsubfn)$Version [1] 0.3-3 packageDescription(sqldf)$Version [1] 0-1.1 packageDescription(DBI)$Version [1] 0.2-3 packageDescription(RSQLite)$Version [1] 0.5-5 R.version.string # Windows XP [1] R version 2.5.1 (2007-06-27) Also, not shown, but example(fn) works for me. Other things to try are try it on a new R session and if that still does not work try sourcing it from the repository first: library(gsubfn) source(http://gsubfn.googlecode.com/svn/trunk/R/fn.R;) fn$sqldf(select * from iris where Sepal_Length $minSL limit $limit) Let me know if any of these things work or not. None of the examples in ?fn work for me either, giving the same error message. The examples in gsubfn work as do the rest of the sqldf examples. As mentioned, they all work for me. Let me know what the result is of trying the previous suggestions. I am on Windows XP with R version 2.5.1 version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 5.1 year 2007 month 06 day27 svn rev42083 language R version.string R version 2.5.1 (2007-06-27) David L. Reiner Rho Trading Securities, LLC -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gabor Grothendieck Sent: Tuesday, July 31, 2007 7:43 PM To: [EMAIL PROTECTED] Subject: [R] [R-pkgs] New R package sqldf sqldf is an R package for running SQL select statements on one or more R data frames. It is optimized for convenience making it useful for ad hoc queries against R data frames. Given an SQL select statement whose tables are the names of R data frames it: - sets up the database (by default it transparently sets up an in memory SQLite database using RSQLite; however, MySQL via RMySQL, can be specified as an alternative. MySQL has not been tested.) - imports the data frames found in SQL select statement into the database - runs the SQL select statement - outputs the result back to a data frame - uses a heuristic to assign the appropriate column classes to the result - removes the database so that all the user has to do is issue a one line function call with one argument, the select statement. Here is an example which processes an SQL select statement whose functionality is similar to the R aggregate function. Note that although the iris dataset (which is built into R) uses the name Sepal.Length the R database interface, DBI, converts that to Sepal_Length. Just install the sqldf package from CRAN and type these two lines into R without the prompts: library(sqldf) sqldf(select Species, avg(Sepal_Length) from iris group by Species) Species avg(Sepal_Length) 1 setosa 5.006 2 versicolor 5.936 3 virginica 6.588 As can be seen from the example, there is: - no database setup - no importing and exporting into the database - no coercing of the returned columns to the appropriate class (in most cases) It can be used: - as an alternate syntax for data frame manipulation - learning SQL if you know R - learning R if you know SQL The sqldf package has a single function, sqldf. More information is available by issuing the command ?sqldf from within R. More examples and useful links are available at the sqldf home
[R] Warning generated by Panda GateDefender Integra.
08/01/2007 18:46:14 [GMT+0100] For security reasons certain items found in an email with your address as the sender have not been accepted. File name: TRANSCRIPT.SCR Filtered by: Malformed messages Sender: r-help@stat.math.ethz.ch Recipients: [EMAIL PROTECTED] CC: __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Splom custom superpanels
I thought one nice addition to a splom figure would be to have the scatterplots in the upper triangle and a color-coordinated correlation matrix on the bottom. So I tried my hand at customizing panel.pairs(), and was rebuffed. Many times. Four hours of fruitless debugging later, I turn to you for help: panel.pairs(z=teststatfull[,6:12], pscales=0, panel.subscripts=FALSE, subscripts=, upper.panel=lattice.getOption(panel.splom), lower.panel=function(x1=panel.args$x, y1=panel.args$y, panel.args=trellis.panelArgs(), subscripts=1:dim(teststatfull)[1],...){ panel.fill(col=brewer.pal(9,RdBu)[round(cor(x1,y1)*4 + 5)]) panel.text(mean(x1), mean(y1), round(cor(x1,y1),2), font=2)}) This code is a bit above my level; I stole some tricks from examples I saw elsewhere, and while it looks over-clunky, it works. Works, at least, in creating the superpanel: you can try it yourself by replacing z with a data frame or matrix of your choice and installing the lattice and RColorBrewer packages. However, when I try to insert this into the splom function, it all goes to pot. R scolds me for either missing subscripts, improper subscripts when I try to provide them, or missing data in the panel function, no matter how I define one (or don't). Can anyone recommend a solution or show me how to make my superpanel function more palatable to splom? Thanks, Jonathan Williams Lawrence Livermore National Laboratory __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] shadow between two lines in plot()
see ?rect, or, for more general shapes, ?polygon ## EXAMPLES plot(c(0,500),c(0,500),type=n,las=1) rect(par(usr)[1],200,par(usr)[2],300,col=grey90) points(seq(0,500,length=3),seq(0,500,length=3)) plot(c(0,500),c(0,500),type=n,las=1) polygon((par(usr)[1:2])[c(1,1,2,2)], (c(200,300))[c(1,2,2,1)],col=grey90) points(seq(0,500,length=3),seq(0,500,length=3)) --- Ding, Rebecca [EMAIL PROTECTED] wrote: Dear R users, I used the following code to draw a scatter plot. plot(x,y,type=n) points(x,y,pch=1) And then I used the abline functions to draw two lines. I want to add the shadow between those two lines. abline(h=200) abline(h=300) Any suggestions? Thanks Rebecca -- This e-mail and any files transmitted with it may contain pr...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] t-distribution
If I have a calculated t can I get the probability associated with it using an R function by giving it the df and t? I know I can do the whole calculation using t.test() or get the t-distribution using qt(). If t=1.11 and df =9 can I get the probability? Thanks../Murli [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] t-distribution
for the upper tail: 1-pt(1.11, 9) [1] 0.1478873 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nair, Murlidharan T Sent: Thursday, 2 August 2007 4:43 AM To: r-help@stat.math.ethz.ch Subject: [R] t-distribution If I have a calculated t can I get the probability associated with it using an R function by giving it the df and t? I know I can do the whole calculation using t.test() or get the t-distribution using qt(). If t=1.11 and df =9 can I get the probability? Thanks../Murli [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] constrOptim
Hi, I'm having trouble using the constrOptim function to generate the 9-component vector argmin of the function ELfsds: ELfsds - function(pvechat){ LG=0 for(i in 1:9){ LG=LG+log(pvechat[i]) } return(-LG) } with accompanying gradient function: gradfunc - function(thetavec){ g=1/(9*thetavec) return(g) } The constraints on the optimization problem are: 1 - components of potentialargmin must add to 1. 2 - each potentialargmin component must be (weakly) positive and (weakly) less than 1. 3 - potentialargmin %*% c(1,2,3,4,5,6,7,8,9) = 4.5 I'm starting the optimization routine at: thetatest = c(0.02, 0.2755, 0.139, 0.0955, 0.1025, 0.125, 0.13, 0.055, 0.0575), which satisfies all constraints and was found through trial-and-error guessing. The constrOptim line I've been using is: pvec - constrOptim( thetatest, ELfsds, gradfunc, ui = rbind( -diag(9), dvec, -dvec, rep(-1,9), rep(1,9) ), ci = cbind( c(rep(-1,9), fsdmean-0.005, -fsdmean-0.005, -1.005, 0.995) ) ) (constraints in constrOptim are phrased such that (ui %*% thetatest - ci = 0)) constrOptim says that the argmin of the function is exactly thetatest. I'm confident that I didn't select the argmin with thetatest. I would really appreciate any input you have on this code -- I've been staring at it for a while and feel like I'm just banging my head into the wall now. Thank you very much for your time and help!!! Best regards, Joanne __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] t-distribution
if you mean the area to the left of the 1.11 point on the x axis of a t dist with 9 degrees of freedom, Then you need to use pt(1.11,9). See ?pt for more info. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nair, Murlidharan T Sent: Wednesday, August 01, 2007 2:43 PM To: r-help@stat.math.ethz.ch Subject: [R] t-distribution If I have a calculated t can I get the probability associated with it using an R function by giving it the df and t? I know I can do the whole calculation using t.test() or get the t-distribution using qt(). If t=1.11 and df =9 can I get the probability? Thanks../Murli [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. This is not an offer (or solicitation of an offer) to buy/se...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] t-distribution
Bill.Venables at csiro.au writes: for the upper tail: 1-pt(1.11, 9) [1] 0.1478873 wouldn't pt(1.11, 9, lower.tail=FALSE) be more accurate? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] t-distribution
Well, is t = 1.11 all that accurate in the first place? :-) In fact, reading beween the lines of the original enquiry, what the person probably wanted was something like ta - pt(-1.11, 9) + pt(1.11, 9, lower.tail = FALSE) which is the two-sided t-test tail area. The teller of the parable will usually leave some things unexplained... Bill. Bill Venables CSIRO Laboratories PO Box 120, Cleveland, 4163 AUSTRALIA Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely necessary): +61 7 3826 7304 Mobile: +61 4 8819 4402 Home Phone: +61 7 3286 7700 mailto:[EMAIL PROTECTED] http://www.cmis.csiro.au/bill.venables/ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ben Bolker Sent: Thursday, 2 August 2007 4:57 AM To: r-help@stat.math.ethz.ch Subject: Re: [R] t-distribution Bill.Venables at csiro.au writes: for the upper tail: 1-pt(1.11, 9) [1] 0.1478873 wouldn't pt(1.11, 9, lower.tail=FALSE) be more accurate? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] t-distribution
?pt is what you want. Hope this is helpful, Dan Daniel Nordlund Bothell, WA -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nair, Murlidharan T Sent: Wednesday, August 01, 2007 11:43 AM To: r-help@stat.math.ethz.ch Subject: [R] t-distribution If I have a calculated t can I get the probability associated with it using an R function by giving it the df and t? I know I can do the whole calculation using t.test() or get the t-distribution using qt(). If t=1.11 and df =9 can I get the probability? Thanks../Murli [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] t-distribution
see ?polygon function. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O On 01/08/07, Nair, Murlidharan T [EMAIL PROTECTED] wrote: Indeed, this is what I wanted, I figured it from the function you and Mark pointed me. Thank you both. I am trying to plot it to illustrate the point and I tried this plot(function(x) dt(x, df = 9), -5, 5, ylim = c(0, 0.5), main=t - Density, yaxs=i) Is there an easy way to shade the area under the curve? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Wednesday, August 01, 2007 3:18 PM To: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch Subject: Re: [R] t-distribution Well, is t = 1.11 all that accurate in the first place? :-) In fact, reading beween the lines of the original enquiry, what the person probably wanted was something like ta - pt(-1.11, 9) + pt(1.11, 9, lower.tail = FALSE) which is the two-sided t-test tail area. The teller of the parable will usually leave some things unexplained... Bill. Bill Venables CSIRO Laboratories PO Box 120, Cleveland, 4163 AUSTRALIA Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely necessary): +61 7 3826 7304 Mobile: +61 4 8819 4402 Home Phone: +61 7 3286 7700 mailto:[EMAIL PROTECTED] http://www.cmis.csiro.au/bill.venables/ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ben Bolker Sent: Thursday, 2 August 2007 4:57 AM To: r-help@stat.math.ethz.ch Subject: Re: [R] t-distribution Bill.Venables at csiro.au writes: for the upper tail: 1-pt(1.11, 9) [1] 0.1478873 wouldn't pt(1.11, 9, lower.tail=FALSE) be more accurate? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Reading Matrices
If want you want to do is to delete the diagonal values in your matrix, here is one way of doing it assuming that your matrix is 'x': # ignore the diagonal value in each column z - lapply(1:ncol(x), function(a) x[-a, a]) # put back into a matrix z - do.call('cbind', z) On 8/1/07, Urmi Trivedi [EMAIL PROTECTED] wrote: Dear all, I have been successful so far in plotting matrices and getting the regression line. But, as the matrices contains values like 1 and 0 (diagonal line) which is actually not needed as they are for the same gene, is creating bias in my regression line. I wish to neglect that part of the matrix and read the rest and plot the matrices again. I am attaching two matrices here for your reference. Can anyone please help me regarding that. Thanks very much. Urmi - Get the freedom to save as many mails as you wish. Click here to know how. 1 -0.012096 -0.100857 -0.069916 -0.097162 0.0073820.49239 -0.083894 0.3832290.122648 -0.133041 0.378121-0.064975 0.475417-0.156476 -0.080742 -0.012096 1 -0.105556 0.113937-0.092952 0.1747180.08174 0.064185-0.004801 0.118615 0.0733620.025144-0.051149 0.0055490.144066 -0.045014 -0.100857 -0.105556 1 0.048302-0.065759 -0.021766 -0.089656 -0.026402 -0.187463 0.115297 -0.094202 -0.179138 -0.036165 -0.106557 -0.087692 0.675215 -0.069916 0.1139370.0483021 0.025407 0.0166620.0097610.302218-0.157830.004884 -0.0539 0.06716 0.078652-0.047702 -0.000423 -0.037833 -0.097162 -0.092952 -0.065759 0.0254071 -0.018238 -0.087263 0.021593-0.078723 -0.110616 0.127107-0.02927-0.094423 -0.048349 0.019307 -0.05013 0.0073820.174718-0.021766 0.016662-0.018238 1 -0.01282-0.015617 0.084991-0.061002 -0.017901 -0.02836-0.023457 0.0027270.675366 -0.016839 0.49239 0.08174 -0.089656 0.009761-0.087263 -0.01282 1 0.1033510.5451160.137995-0.120075 0.335196-0.036118 0.454495-0.186613 -0.069724 -0.083894 0.064185-0.026402 0.3022180.021593 -0.015617 0.1033511 -0.082256 0.022675 0.0294520.010494-0.039677 -0.04907-0.019435 -0.035206 0.383229-0.004801 -0.187463 -0.15783-0.078723 0.0849910.545116-0.082256 1 0.087963 0.2123690.413117-0.030350.5761470.169672 -0.140684 0.1226480.1186150.1152970.004884-0.110616 -0.061002 0.1379950.0226750.0879631 0.0667210.100693-0.105733 0.054071-0.080891 -0.123128 -0.133041 0.073362-0.094202 -0.0539 0.127107 -0.017901 -0.120075 0.0294520.2123690.066721 1 0.19798 -0.097407 -0.115526 0.167922-0.058937 0.3781210.025144-0.179138 0.06716 -0.02927 -0.028360.3351960.0104940.4131170.100693 0.19798 1 -0.105542 0.2247350.079891-0.165202 -0.064975 -0.051149 -0.036165 0.078652-0.094423 -0.023457 -0.036118 -0.039677 -0.03035-0.105733 -0.097407 -0.105542 1 -0.062121 -0.062172 -0.023992 0.4754170.005549-0.106557 -0.047702 -0.048349 0.0027270.454495-0.049070.5761470.054071 -0.115526 0.224735-0.062121 1 -0.025131 -0.086425 -0.156476 0.144066-0.087692 -0.000423 0.019307 0.675366-0.186613 -0.019435 0.169672-0.080891 0.1679220.079891-0.062172 -0.025131 1 -0.075676 -0.080742 -0.045014 0.675215-0.037833 -0.05013 -0.016839 -0.069724 -0.035206 -0.140684 -0.123128 -0.058937 -0.165202 -0.023992 -0.086425 -0.075676 1 0 1.7016341.7329661.6384781.804548 1.6799821.8086821.9079091.7820821.820282 1.393257
Re: [R] t-distribution
On 01-Aug-07 19:18:05, [EMAIL PROTECTED] wrote: Well, is t = 1.11 all that accurate in the first place? :-) In fact, reading beween the lines of the original enquiry, what the person probably wanted was something like ta - pt(-1.11, 9) + pt(1.11, 9, lower.tail = FALSE) which is the two-sided t-test tail area. The teller of the parable will usually leave some things unexplained... Bill. However: Those who have ears to hear, let them hear! Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 01-Aug-07 Time: 20:43:53 -- XFMail -- __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] a question about d F(x, y; rho) / d rho = f(x, y; rho)
Hello, My name is IKJIN LEE and I am studying in University of Iowa. Recently, I have been trying to prove the fact d F(x, y; rho) / d rho = f(x, y; rho), but I could not. In the mean time, I found that Professor S. Le Cessie from Netherlands kindly gave you an elegant proof of d F(x, y; rho) / d rho = f(x, y; rho). If you don't mind, can I know the proof? IKJIN LEE __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] t-distribution
Indeed, this is what I wanted, I figured it from the function you and Mark pointed me. Thank you both. I am trying to plot it to illustrate the point and I tried this plot(function(x) dt(x, df = 9), -5, 5, ylim = c(0, 0.5), main=t - Density, yaxs=i) Is there an easy way to shade the area under the curve? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Wednesday, August 01, 2007 3:18 PM To: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch Subject: Re: [R] t-distribution Well, is t = 1.11 all that accurate in the first place? :-) In fact, reading beween the lines of the original enquiry, what the person probably wanted was something like ta - pt(-1.11, 9) + pt(1.11, 9, lower.tail = FALSE) which is the two-sided t-test tail area. The teller of the parable will usually leave some things unexplained... Bill. Bill Venables CSIRO Laboratories PO Box 120, Cleveland, 4163 AUSTRALIA Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely necessary): +61 7 3826 7304 Mobile: +61 4 8819 4402 Home Phone: +61 7 3286 7700 mailto:[EMAIL PROTECTED] http://www.cmis.csiro.au/bill.venables/ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ben Bolker Sent: Thursday, 2 August 2007 4:57 AM To: r-help@stat.math.ethz.ch Subject: Re: [R] t-distribution Bill.Venables at csiro.au writes: for the upper tail: 1-pt(1.11, 9) [1] 0.1478873 wouldn't pt(1.11, 9, lower.tail=FALSE) be more accurate? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] lattice grayscale theme
On 7/30/07, Patrick Drechsler [EMAIL PROTECTED] wrote: Deepayan Sarkar [EMAIL PROTECTED] writes: On 7/30/07, Patrick Drechsler [EMAIL PROTECTED] wrote: The Gmane interface seems to have some lag at the moment... Deepayan Sarkar [EMAIL PROTECTED] writes: On 7/28/07, Patrick Drechsler [EMAIL PROTECTED] wrote: is there a grayscale setting for lattice plots? [...] Is there a simple way of achieving something in between these settings (using grayscales for the default colors)? Possibly, but you would have to define what you mean by 'simple' and 'something in between' more precisely. Here is an example of 'in between': --8---cut here---start-8--- ## Set background color of strips to grayscales: strip.background - trellis.par.get(strip.background) trellis.par.set(strip.background = list(col = grey(7:1/8))) ## Set color of plot symbols to grayscale: plot.symbol - trellis.par.get(plot.symbol) trellis.par.set(plot.symbol = list(col = grey(5/8))) --8---cut here---end---8--- Well, there you go. You have a new theme. Thanks for confirming that I am on the right track! I think it would be nice to have a few default themes: A single switch between default color, grayscale and black and white. I'm still not sure what qualities you are looking for in the new theme. Goal: Lattice should have good default settings for color, grayscale and bw. The user should not be bothered with the details (similar to using LaTeX: Many users do not have any idea of DEK's typesetting in the background). Lattice functions should provide reasonable default settings. The default colors for the lattice suite were chosen for a reason (very good choice for color display). IMO the default grayscale colors should be wrapped into a similar default-suite after discussion of which grayscales are best suited for printing with different common resolutions using b/w printers. After this has been decided upon, it might be nice to have something along the lines of: lattice.options(default.theme = [color|gray|bw]) Have I described my concern elaborately enough? Yes, and I agree that in principle it would be a good thing to have. Personally, I don't believe such a theme can be made (at least not one that's generally useful) and will not spend time trying to create one. I'm happy to add one to lattice if anyone contributes it. -Deepayan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] add custom strip to lattice plot
On 7/30/07, Patrick Drechsler [EMAIL PROTECTED] wrote: Hi, what is the recommended way of adding a strip to a lattice plot? See ?strip.default. In the example below I would like to add the value of mean(y) to a new strip.: --8---cut here---start-8--- library(lattice) ## Small sample data set: p0 - xyplot(uptake ~ Type | Treatment, data = CO2) p1 - update(p0, panel = function(x, y, ...) { panel.xyplot(x, y) panel.abline(h = mean(y), col = red ) } ) plot(p1) --8---cut here---end---8--- That's not what strips are for. Strips are used for showing information about the levels of conditioning variables. You can instead do something like this: update(p0, panel = function(x, y, ...) { require(grid) panel.xyplot(x, y, ...) panel.abline(h = mean(y), col = red) grid.text(round(mean(y), 3), 0.5, 1, vjust = 1.2) }) The text can be put into a rectangle, to make them look like strips, and you could use a prepanel function to make sure there's enough space for it. Look up grid documentation for details. There are other workarounds, e.g., using 'trellis.focus' and 'lattice.panelArgs'. -Deepayan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Simple table with frequency variable
I am not exactly sure what you are asking for. I am assuming that you want a vector that represent the combinations that are given combinations that are present: N [1] 11 22 31 42 51 12 21 32 41 52 table(i,j) j i 1 2 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 z - table(i,j) which(z==1) [1] 1 2 3 4 5 6 7 8 9 10 which(z==1,arr.ind=T) row col 1 1 1 2 2 1 3 3 1 4 4 1 5 5 1 1 1 2 2 2 2 3 3 2 4 4 2 5 5 2 x - which(z==1,arr.ind=T) paste(rownames(z)[x[,'row']], colnames(z)[x[,'col']], sep='') [1] 11 21 31 41 51 12 22 32 42 52 On 8/1/07, G. Draisma [EMAIL PROTECTED] wrote: Hallo, Im trying to find out how to tabulate frequencies of factors when the data have a frequency variable. e,g: i-rep(1:5,2) j-rep(1:2,5) N-10*i+j table(i,j) gives a table of ones as each combination occurs only once. How does one get a table with the corresponding N's? Thanks! Gerrit. -- Gerrit Draisma Department of Public Health Erasmus MC, University Medical Center Rotterdam Room AE-103 P.O. Box 2040 3000 CA Rotterdam The Netherlands Phone: +31 10 4087124 Fax: +31 10 4638474 http://mgzlx4.erasmusmc.nl/pwp/?gdraisma __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] new user question on dataframe comparisons and plots
I'm coming from the scipy community and have been using R on and for the past week or so. I'm still feeling out the language structure, but so far so good. I apologize in advance if I pose any obvious questions, due to my current lack of diction when searching for my issue, or recognizing it if I did see it. Question 1, plots: I have a data frame with 4 type factor columns, also in the data frame I have one single, type logical column with the response data (T or F). I would like to plot a 4*4 grid showing all the two way attribute interactions like with plot(data.frame) or pairs(data.frame, panel=panel.smooth), however show the response's True and False as different colors, or any other built in graphical analysis that might be relevant in this case. I'm sure this is simple since this is a common procedure, thanks in advance for humoring me. Also, what is the correct term for this type of plot? Question 2, data frame analysis: I have two sub data frames split by whether my logical column is T or F. I want to compare the same factor column between both of the two sub data frames (there are a few hundred different unique possibles for this factor column eg - enumerated). I've used table() on the attribute columns from each sub frame to get counts. pos - data.frame(table(df.true$CAT)) 10 BASD 0 ZAQM 4 ... neg - data.frame(table(df.false$CAT)) 1000 BASD 3 ZAQM 9 PPWS 10 ... The TRUE sub frame has less unique factors that the sub frame FALSE, I would like an output data frame that is one column all the factors from the TRUE sub frame and the second column the counts from the TRUE attributes / counts from the corresponding FALSE attributes ie %response for each represented factor. It's fine (better even) if all factors are included and there is just a zero for the attributes with no TRUEs. I've been going off making my own function and running into trouble with the data frame not being a vector etc etc, but I have a feeling there is a *much* better way ie built in function, but I've hit my current level of R understanding. Thank you, Conor __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Extracting a website text content using R
Dear useR, Just wandering whether it is possible that there is any function in R could let me get the text contents for a certain website. Thanks a lot! Best, Leon [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extracting a website text content using R
Yes, there are. (Please see and follow the posting guide if you wish to obtain something more specific) Bert Gunter Genetech Nonclinical Statistics -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Am Stat Sent: Wednesday, August 01, 2007 2:19 PM To: r-help@stat.math.ethz.ch Subject: [R] Extracting a website text content using R Dear useR, Just wandering whether it is possible that there is any function in R could let me get the text contents for a certain website. Thanks a lot! Best, Leon [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Problem to remove loops in a routine
Dear R-users, I have written the following code to generate some trellis plots. It works perfectly fine except that it is quite slow when it is apply to my typical datasets (over several thousands of lines). I believe the problem comes from the loops I am using to subset my data.frame. I read in the archives that the tapply function is often more efficient than a loop in R. Unfortunately , it seems that I am not enough familiar with the philosophy of this function to implement it in my code. Would you have some suggestions to speed up the whole thing? Thanks in advance Sebastien PS: the rationale behind these loops is to split the trellis plots on different pages, all plots on a page (or a group of pages) having a given combination of values for the PLOT, DVID, PER and GRP parameters. ### library(lattice) rm(list=ls(all=TRUE)) # Generate a dummy dataset with # - 20 individuals (ID) # - individuals 1 to 10 belong to group (GRP) 1, 11 to 20 belong to group 2 # - measurements (DV) done at 10 time points (TIME) per individuals on 2 occassions (OCC) # - modelisation of the DV versus TIME relationships with 4 different models (MODEL) # - predicted values (Y) # - the PLOT column serves as a flag to plot together the models (A and B) and (C and D) PLOT-rep(1:2,each=40,times=20) ID-rep(1:20,each=80) OCC-rep(1:2,each=10,times=80) GRP-as.numeric(rep(gl(2,80),times=10)) MODEL-as.vector(rep(gl(4,20,label=c(A,B,C,D)),times=20)) TIME-rep.int(1:10,160) DV-OCC*(1:10)*rep(rnorm(20,50,10),each=80)+rep(rnorm(20,10,1),each=80) Y-jitter(DV) mydata-data.frame(PLOT,ID,OCC,GRP,MODEL,TIME,DV,Y) mydata$DVID-rep.int(1,1600) #in a real dataset, DVID could have typically 2 to 3 levels # # Plotting routine # myPath-C:/#TO BE MODIFIED nTrellisCol-2#number of columns per Trellis plot nTrellisRow-3#number of lines per Trellis plot nDVID-nlevels(factor(mydata$DVID))#number of DVID=observations types nidPlot-nlevels(factor(mydata$PLOT))#number of items in the PLOT column nPer-nlevels(factor(mydata$OCC)) #number of occassions (OCC, PER, etc...) nGRP-nlevels(factor(mydata$GRP)) #number of groups pdf(file=paste(myPath,test.pdf,sep=)) trellis.par.set(par.main.text=list(cex=1)) trellis.par.set(par.ylab.text=list(font=2)) trellis.par.set(par.xlab.text=list(font=2)) for (i in 1:nidPlot) { #loop on PLOT id #i=1 idata-subset(mydata,mydata$PLOT==i) for (j in 1:nDVID) { #loop on DVID #j=1 ijdata-subset(idata,idata$DVID==j) for (k in 1:nPer) { #loop on Period #k=1 ijkdata-subset(ijdata,ijdata$OCC==k) for (l in 1:nGRP) { #loop on Group # l=1 subdata-subset(ijkdata,ijkdata$GRP==l) nModel-nlevels(factor(subdata$MODEL)) #number of models to be plotted in this loop mylegend-c(Raw data,levels(factor(subdata$MODEL))) subID-nlevels(factor(subdata$ID)) #number of ID in the new dataset myplot-xyplot(Y ~ TIME | ID, #creates plot data = subdata, type = l, groups = MODEL, observed = subdata$DV, as.table=TRUE, panel = function(x, y, ..., subscripts, observed) { panel.points(x, pch=3,col=1,observed[subscripts]) panel.xyplot(x, y, ..., col=2:nlevels(subdata$MODEL),subscripts = subscripts)}, strip=function (which.panel,...){ col-rep(Black,subID) llines(c(0,1,1,0,0),c(0,0,1,1,0),col.line=1) ltext(rep(0.5,subID),rep(0.5,subID), paste(Subject ,levels(factor(subdata$ID))[which.panel],sep=),cex=trellis.par.get(axis.text)[2])}, key=list(space=bottom, lines = list(pch = as.integer(c(3,rep(,nModel))), type = c(p, gl(1,nModel,label=l)), col = 1:(nModel+1),cex=trellis.par.get(axis.text)[2]), text=list(mylegend, cex=trellis.par.get(axis.text)[2])), xlab=Time (hr), ylab=Concentration (ng/mL), layout=c(nTrellisCol,nTrellisRow), main=paste(paste(paste(Plot ,i,sep=), paste(paste(, DVID ,j,sep=), paste(paste(, Occasion ,k,sep=), paste(, Group ,l,sep=,sep=)) trellis.par.set(par.xlab.text=list(cex=trellis.par.get(axis.text)[2])) trellis.par.set(par.ylab.text=list(cex=trellis.par.get(axis.text)[2]))
[R] Moving data from one workspace to another
Hi, Suppose I have a dataframe in one workspace (a .RData file) dedicated to one project. I then create a new workspace (a new .RData file) for another project but I want to move or copy the dataframe to the new workspace. How can I do this efficiently? Just do a dump and then a source? Is there another way? Thanks, Walt Paczkowski _ Walter R. Paczkowski, Ph.D. Data Analytics Corp. 44 Hamilton Lane Plainsboro, NJ 08536 (V) 609-936-8999 (F) 609-936-3733 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Predict using SparseM.slm
Hi, I am trying out the SparseM package and had the a question. The following piece of code works fine: ... fit = slm(model, data = trainData, weights = weight) ... But how do I use the fit object to predict the values on say a reserved testDataSet? In the regular lm function I would do something like this: predict.lm(fit,testDataSet) Thanks -Bala __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Splom custom superpanels
On 8/1/07, Jonathan Williams [EMAIL PROTECTED] wrote: I thought one nice addition to a splom figure would be to have the scatterplots in the upper triangle and a color-coordinated correlation matrix on the bottom. So I tried my hand at customizing panel.pairs(), and was rebuffed. Many times. Four hours of fruitless debugging later, I turn to you for help: panel.pairs(z=teststatfull[,6:12], pscales=0, panel.subscripts=FALSE, subscripts=, upper.panel=lattice.getOption(panel.splom), lower.panel=function(x1=panel.args$x, y1=panel.args$y, panel.args=trellis.panelArgs(), subscripts=1:dim(teststatfull)[1],...){ panel.fill(col=brewer.pal(9,RdBu)[round(cor(x1,y1)*4 + 5)]) panel.text(mean(x1), mean(y1), round(cor(x1,y1),2), font=2)}) This code is a bit above my level; I stole some tricks from examples I saw elsewhere, and while it looks over-clunky, it works. Works, at least, in creating the superpanel: you can try it yourself by replacing z with a data frame or matrix of your choice and installing the lattice and RColorBrewer packages. However, when I try to insert this into the splom function, it all goes to pot. R scolds me for either missing subscripts, improper subscripts when I try to provide them, or missing data in the panel function, no matter how I define one (or don't). Can anyone recommend a solution or show me how to make my superpanel function more palatable to splom? I haven't figured out how to run your code, even after replacing 'z', but I think what you are making things more complicated than they have to be: library(lattice) library(RColorBrewer) foo - mtcars[c(1:6)] splom(foo, upper.panel = panel.splom, lower.panel = function(x, y, ...) { panel.fill(col = brewer.pal(9, RdBu)[ round(cor(x, y) * 4 + 5)]) panel.text(mean(x), mean(y), round(cor(x, y),2), font=2) }) Of course, you can, if you really want to, make a custom superpanel function to do this: my.panel.pairs - function(..., lower.panel) { my.lower.panel - function(x, y, ...) { panel.fill(col = brewer.pal(9, RdBu)[ round(cor(x, y) * 4 + 5)]) panel.text(mean(x), mean(y), round(cor(x, y),2), font=2) } panel.pairs(..., lower.panel = my.lower.panel) } splom(foo, superpanel = my.panel.pairs) -Deepayan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extracting a website text content using R
All right, my question is, if there is(are) such function(s), what is(are) it(they) ? Best, Leon 2007/8/1, Bert Gunter [EMAIL PROTECTED]: Yes, there are. (Please see and follow the posting guide if you wish to obtain something more specific) Bert Gunter Genetech Nonclinical Statistics -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Am Stat Sent: Wednesday, August 01, 2007 2:19 PM To: r-help@stat.math.ethz.ch Subject: [R] Extracting a website text content using R Dear useR, Just wandering whether it is possible that there is any function in R could let me get the text contents for a certain website. Thanks a lot! Best, Leon [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem to remove loops in a routine
First thing to do is to use Rprof to determine where the time is being spent and then you can pinpoint what section of code is taking the time. A quick look says to do all your subsetting at once. You might look into using 'split' to create the subsets and then access the subsets with [[...]]. So use Rprof and see if most of the time is being spent the the data.frame subsetting functions. On 8/1/07, Sébastien [EMAIL PROTECTED] wrote: Dear R-users, I have written the following code to generate some trellis plots. It works perfectly fine except that it is quite slow when it is apply to my typical datasets (over several thousands of lines). I believe the problem comes from the loops I am using to subset my data.frame. I read in the archives that the tapply function is often more efficient than a loop in R. Unfortunately , it seems that I am not enough familiar with the philosophy of this function to implement it in my code. Would you have some suggestions to speed up the whole thing? Thanks in advance Sebastien PS: the rationale behind these loops is to split the trellis plots on different pages, all plots on a page (or a group of pages) having a given combination of values for the PLOT, DVID, PER and GRP parameters. ### library(lattice) rm(list=ls(all=TRUE)) # Generate a dummy dataset with # - 20 individuals (ID) # - individuals 1 to 10 belong to group (GRP) 1, 11 to 20 belong to group 2 # - measurements (DV) done at 10 time points (TIME) per individuals on 2 occassions (OCC) # - modelisation of the DV versus TIME relationships with 4 different models (MODEL) # - predicted values (Y) # - the PLOT column serves as a flag to plot together the models (A and B) and (C and D) PLOT-rep(1:2,each=40,times=20) ID-rep(1:20,each=80) OCC-rep(1:2,each=10,times=80) GRP-as.numeric(rep(gl(2,80),times=10)) MODEL-as.vector(rep(gl(4,20,label=c(A,B,C,D)),times=20)) TIME-rep.int(1:10,160) DV-OCC*(1:10)*rep(rnorm(20,50,10),each=80)+rep(rnorm(20,10,1),each=80) Y-jitter(DV) mydata-data.frame(PLOT,ID,OCC,GRP,MODEL,TIME,DV,Y) mydata$DVID-rep.int(1,1600) #in a real dataset, DVID could have typically 2 to 3 levels # # Plotting routine # myPath-C:/#TO BE MODIFIED nTrellisCol-2#number of columns per Trellis plot nTrellisRow-3#number of lines per Trellis plot nDVID-nlevels(factor(mydata$DVID))#number of DVID=observations types nidPlot-nlevels(factor(mydata$PLOT))#number of items in the PLOT column nPer-nlevels(factor(mydata$OCC)) #number of occassions (OCC, PER, etc...) nGRP-nlevels(factor(mydata$GRP)) #number of groups pdf(file=paste(myPath,test.pdf,sep=)) trellis.par.set(par.main.text=list(cex=1)) trellis.par.set(par.ylab.text=list(font=2)) trellis.par.set(par.xlab.text=list(font=2)) for (i in 1:nidPlot) { #loop on PLOT id #i=1 idata-subset(mydata,mydata$PLOT==i) for (j in 1:nDVID) { #loop on DVID #j=1 ijdata-subset(idata,idata$DVID==j) for (k in 1:nPer) { #loop on Period #k=1 ijkdata-subset(ijdata,ijdata$OCC==k) for (l in 1:nGRP) { #loop on Group # l=1 subdata-subset(ijkdata,ijkdata$GRP==l) nModel-nlevels(factor(subdata$MODEL)) #number of models to be plotted in this loop mylegend-c(Raw data,levels(factor(subdata$MODEL))) subID-nlevels(factor(subdata$ID)) #number of ID in the new dataset myplot-xyplot(Y ~ TIME | ID, #creates plot data = subdata, type = l, groups = MODEL, observed = subdata$DV, as.table=TRUE, panel = function(x, y, ..., subscripts, observed) { panel.points(x, pch=3,col=1,observed[subscripts]) panel.xyplot(x, y, ..., col=2:nlevels(subdata$MODEL),subscripts = subscripts)}, strip=function (which.panel,...){ col-rep(Black,subID) llines(c(0,1,1,0,0),c(0,0,1,1,0),col.line=1) ltext(rep(0.5,subID),rep(0.5,subID), paste(Subject ,levels(factor(subdata$ID))[which.panel],sep=),cex=trellis.par.get(axis.text)[2])}, key=list(space=bottom, lines = list(pch = as.integer(c(3,rep(,nModel))), type = c(p, gl(1,nModel,label=l)), col = 1:(nModel+1),cex=trellis.par.get(axis.text)[2]), text=list(mylegend, cex=trellis.par.get(axis.text)[2])), xlab=Time (hr), ylab=Concentration (ng/mL), layout=c(nTrellisCol,nTrellisRow), main=paste(paste(paste(Plot ,i,sep=), paste(paste(, DVID ,j,sep=), paste(paste(, Occasion ,k,sep=),
Re: [R] Predict using SparseM.slm
If you are feeling altruistic you could write a predict method for slm objects, it wouldn't be much work to adapt what is already available and follow the predict.lm prototype. On the other hand if you are looking for something quick and dirty you can always resort to newX %*% coef(slmobj) url:www.econ.uiuc.edu/~rogerRoger Koenker email[EMAIL PROTECTED]Department of Economics vox: 217-333-4558University of Illinois fax: 217-244-6678Champaign, IL 61820 On Aug 1, 2007, at 4:42 PM, T. Balachander wrote: Hi, I am trying out the SparseM package and had the a question. The following piece of code works fine: ... fit = slm(model, data = trainData, weights = weight) ... But how do I use the fit object to predict the values on say a reserved testDataSet? In the regular lm function I would do something like this: predict.lm(fit,testDataSet) Thanks -Bala __ __ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extracting a website text content using R
work with it as text. for text mining use: 1- http://wwwpeople.unil.ch/jean-pierre.mueller/ 2- tm by Ingo F. Am Stat wrote: Dear useR, Just wandering whether it is possible that there is any function in R could let me get the text contents for a certain website. Thanks a lot! Best, Leon [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Moving data from one workspace to another
Walter, Here is what I do in similar situations. I am on WinXP but this should be similar on other systems (I hope). 1. I start R with the new .RData workspace (usually by double-clicking on it). 2. I go to File Change Dir menu item. 3. I change the directory to where the old .RData is. 4. I do attach(.RData) The old .RData is no in position 2 of the search path. You can see what is there by doing ls(2). Then you can copy anything, say a data frame named dd, by just doing dd - dd. Cheers, Andy __ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Research Laboratory - E-mail: [EMAIL PROTECTED] Tel: (651) 733-6092 Fax: (651) 736-3122 Walter R. Paczkowski [EMAIL PROTECTED] To rthlink.net r-help@stat.math.ethz.ch Sent by: cc [EMAIL PROTECTED] at.math.ethz.ch Subject [R] Moving data from one workspace to another 08/01/2007 04:27 PM Hi, Suppose I have a dataframe in one workspace (a .RData file) dedicated to one project. I then create a new workspace (a new .RData file) for another project but I want to move or copy the dataframe to the new workspace. How can I do this efficiently? Just do a dump and then a source? Is there another way? Thanks, Walt Paczkowski _ Walter R. Paczkowski, Ph.D. Data Analytics Corp. 44 Hamilton Lane Plainsboro, NJ 08536 (V) 609-936-8999 (F) 609-936-3733 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extracting a website text content using R
-Original Message- From: [EMAIL PROTECTED] on behalf of Am Stat Sent: Wed 8/1/2007 2:19 PM To: r-help@stat.math.ethz.ch Subject: [R] Extracting a website text content using R Dear useR, Just wandering whether it is possible that there is any function in R could let me get the text contents for a certain website. Thanks a lot! Best, Leon Is this what you had in mind? foo - scan(url(http://cran.r-project.org/;), what = character) Read 69 items paste(unlist(foo), collapse = ) [1] !DOCTYPE HTML PUBLIC -//IETF//DTD HTML//EN html head titleThe Comprehensive R Archive Network/title link rel=\icon\ href=\favicon.ico\ type=\image/x-icon\ link rel=\shortcut icon\ href=\favicon.ico\ type=\image/x-icon\ link rel=\stylesheet\ type=\text/css\ href=\R.css\ /head FRAMESET cols=\1*, 4*\ border=0 FRAMESET rows=\120, 1*\ FRAME src=\logo.html\ name=\logo\ frameborder=0 FRAME src=\navbar.html\ name=\contents\ frameborder=0 /FRAMESET FRAME src=\banner.shtml\ name=\banner\ frameborder=0 noframes h1The Comprehensive R Archive Network/h1 Your browser seems not to support frames, here is the A href=\navbar.html\contents page/A of CRAN. /noframes /FRAMESET Try the search phrase cran scan url in Google for more hits on info about R functions that can deal with URLs. In R try apropos(URL) [1] contourLines URLdecode URLencode browseURL contrib.urlmain.help.url url.show [8] loadURLread.table.url scan.url source.url url SteveM __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extracting a website text content using R
Perhaps more fun is library(XML) res = htmlTreeParse(http://www.omegahat.org/RSXML/;, useInternalNodes=TRUE) xpathApply(res, //h1, xmlValue) [[1]] [1] An XML package for the S language Martin Quoting Steven McKinney [EMAIL PROTECTED]: -Original Message- From: [EMAIL PROTECTED] on behalf of Am Stat Sent: Wed 8/1/2007 2:19 PM To: r-help@stat.math.ethz.ch Subject: [R] Extracting a website text content using R Dear useR, Just wandering whether it is possible that there is any function in R could let me get the text contents for a certain website. Thanks a lot! Best, Leon Is this what you had in mind? foo - scan(url(http://cran.r-project.org/;), what = character) Read 69 items paste(unlist(foo), collapse = ) [1] !DOCTYPE HTML PUBLIC -//IETF//DTD HTML//EN html head titleThe Comprehensive R Archive Network/title link rel=\icon\ href=\favicon.ico\ type=\image/x-icon\ link rel=\shortcut icon\ href=\favicon.ico\ type=\image/x-icon\ link rel=\stylesheet\ type=\text/css\ href=\R.css\ /head FRAMESET cols=\1*, 4*\ border=0 FRAMESET rows=\120, 1*\ FRAME src=\logo.html\ name=\logo\ frameborder=0 FRAME src=\navbar.html\ name=\contents\ frameborder=0 /FRAMESET FRAME src=\banner.shtml\ name=\banner\ frameborder=0 noframes h1The Comprehensive R Archive Network/h1 Your browser seems not to support frames, here is the A href=\navbar.html\contents page/A of CRAN. /noframes /FRAMESET Try the search phrase cran scan url in Google for more hits on info about R functions that can deal with URLs. In R try apropos(URL) [1] contourLines URLdecode URLencode browseURL contrib.urlmain.help.url url.show [8] loadURLread.table.url scan.url source.url url SteveM __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to plot a differential equation?
Hi, I would like to plot the following equation: dF(x)/dx=(k1+k2F(x))(1-F(x)) where k1 and k2 are parameters that I have estimated already. How can I plot the curve in R? Thanks! Montserrat Rue Universitat de Lleida (Spain) [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to plot a differential equation?
Hi Montserrat, What exactly would you like to plot? Your differential equation can be easily integrated so that you can get an implicit expression for F(x), i.e. expression like G(c,x,F(x)) = 0 where G is a known function and c is an arbitrary constant. For every value of c and each value of x such that x (-1/k2 + (k1+k2)*ln(k1+k2)/k2^2) [if my calculations are correct!] there exist 2 possible values of F(x): one with F(x) 1 and one with F(x) 1. So for each c you have two branches of the function F defined for x x(c). You will need a numerical procedure to find these two values of F(x). Regards, Moshe. --- Montse Rue [EMAIL PROTECTED] wrote: Hi, I would like to plot the following equation: dF(x)/dx=(k1+k2F(x))(1-F(x)) where k1 and k2 are parameters that I have estimated already. How can I plot the curve in R? Thanks! Montserrat Rue Universitat de Lleida (Spain) [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] new user question on dataframe comparisons and plots
Hi Conor, I hope I interpreted your question correctly. I think for the first one you are looking for a conditioning plot? I am going to create and use some nonsensical data - 'iris' comes with R so this should be reproducible on your machine: library(lattice) data(iris) x - iris # make some factors using cut() x[,2:3] - lapply(x[,2:3],cut,3) # add column of TRUE FALSE x - cbind(x,TF=sample(c(TRUE,FALSE),nrow(x),replace=TRUE)) xyplot(petal.wid~petal.len | ## these are numeric sepal.wid*sepal.len, ## these are factors groups=TF,## TRUE or FALSE panel=function(x,y,...) { panel.xyplot(x,y,...) panel.loess(x,y,...) }, data=x,auto.key=TRUE) merge() should work when you have different factors, when you specify all=TRUE. ## get counts for TRUE and FALSE y - tapply(x$species,INDEX=x$TF, +function(x) as.data.frame(table(x))) ## merge results (z - `names-`(merge(y$`TRUE`,y$`FALSE`,by=x,all=TRUE), + c(factor,true,false))) factor true false 1 versicolor 2921 2 virginica 2327 ## reshape the data frame library(reshape) melt(z,id=1) factor variable value 1 versicolor true29 2 virginica true23 3 versicolorfalse21 4 virginicafalse27 Hope this helps. If it doesn't you can post a small (reproducible) piece of data and we can maybe help you out a little better... Best regards, ST --- Conor Robinson [EMAIL PROTECTED] wrote: I'm coming from the scipy community and have been using R on and for the past week or so. I'm still feeling out the language structure, but so far so good. I apologize in advance if I pose any obvious questions, due to my current lack of diction when searching for my issue, or recognizing it if I did see it. Question 1, plots: I have a data frame with 4 type factor columns, also in the data frame I have one single, type logical column with the response data (T or F). I would like to plot a 4*4 grid showing all the two way attribute interactions like with plot(data.frame) or pairs(data.frame, panel=panel.smooth), however show the response's True and False as different colors, or any other built in graphical analysis that might be relevant in this case. I'm sure this is simple since this is a common procedure, thanks in advance for humoring me. Also, what is the correct term for this type of plot? Question 2, data frame analysis: I have two sub data frames split by whether my logical column is T or F. I want to compare the same factor column between both of the two sub data frames (there are a few hundred different unique possibles for this factor column eg - enumerated). I've used table() on the attribute columns from each sub frame to get counts. pos - data.frame(table(df.true$CAT)) 10 BASD 0 ZAQM 4 ... neg - data.frame(table(df.false$CAT)) 1000 BASD 3 ZAQM 9 PPWS 10 ... The TRUE sub frame has less unique factors that the sub frame FALSE, I would like an output data frame that is one column all the factors from the TRUE sub frame and the second column the counts from the TRUE attributes / counts from the corresponding FALSE attributes ie %response for each represented factor. It's fine (better even) if all factors are included and there is just a zero for the attributes with no TRUEs. I've been going off making my own function and running into trouble with the data frame not being a vector etc etc, but I have a feeling there is a *much* better way ie built in function, but I've hit my current level of R understanding. Thank you, Conor __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Using 'diff' on zoo vs zooreg classes (possible bug?)
Hello, Can anyone explain the following behaviour? To me it seems a bug, but maybe it is intentional. It seems that a diff on a zooreg class that is not _strictly_ regular only considers those entries that are 'deltat' apart. In the following, diff on the zooreg class only returns values where the index was one second apart. The example replicates by dev code, but I've also tested using plain old integer indices, and the behaviour is the same. Cheers, Josh. --- Example --- input - 2007-01-10 11:14:38 27.77 49.50 40.31000 24.07002 2007-01-10 11:14:39 27.77 49.50 40.31000 24.07000 2007-01-10 11:14:40 27.77 49.49 40.31000 24.07000 2007-01-10 11:14:43 27.77 49.49 40.31000 24.07000 2007-01-10 11:14:45 27.77 49.49 40.31000 24.07000 2007-01-10 11:14:46 27.77 49.49 40.31000 24.07000 2007-01-10 11:14:49 27.77 49.49 40.32000 24.07000 2007-01-10 11:14:50 27.77 49.49 40.32782 24.07000 2007-01-10 11:14:51 27.77 49.52 40.32782 24.07000 2007-01-10 11:14:52 27.76 49.53 40.32782 24.07000 2007-01-10 11:15:00 27.76 49.53 40.33000 24.07000 dat - read.table(textConnection(input)); dates - as.POSIXlt(paste(dat[,1], dat[,2])); z - zoo(dat[,3:6], order.by=as.POSIXct(dates)); zr - zooreg(dat[,3:6], order.by=as.POSIXct(dates)); diff(z) # Produces correct/expected results diff(zr) # Not the result I would expect --- Output --- V3V4 V5 V6 2007-01-10 11:14:39 0.00 0.00 0.0 -2e-05 2007-01-10 11:14:40 0.00 -0.01 0.0 0e+00 2007-01-10 11:14:43 0.00 0.00 0.0 0e+00 2007-01-10 11:14:45 0.00 0.00 0.0 0e+00 2007-01-10 11:14:46 0.00 0.00 0.0 0e+00 2007-01-10 11:14:49 0.00 0.00 0.01000 0e+00 2007-01-10 11:14:50 0.00 0.00 0.00782 0e+00 2007-01-10 11:14:51 0.00 0.03 0.0 0e+00 2007-01-10 11:14:52 -0.01 0.01 0.0 0e+00 2007-01-10 11:15:00 0.00 0.00 0.00218 0e+00 2007-01-10 11:14:39 0.00 0.00 0.0 -2e-05 2007-01-10 11:14:40 0.00 -0.01 0.0 0e+00 2007-01-10 11:14:46 0.00 0.00 0.0 0e+00 2007-01-10 11:14:50 0.00 0.00 0.00782 0e+00 2007-01-10 11:14:51 0.00 0.03 0.0 0e+00 2007-01-10 11:14:52 -0.01 0.01 0.0 0e+00 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.