RE: [R] Read.table problem
- Original Message - From: ptremb17 [EMAIL PROTECTED] length(varnames) = 9 length(c(F,T,F,F,F,F,F,F,F,F))) = 10 To: R-HELP [EMAIL PROTECTED] Sent: Saturday, February 01, 2003 3:24 AM Subject: [R] Read.table problem Hi ! I am new to R, and using the MAC version onto Mac OS 9.1. My question concerns the problem I encounter when I try to read some data I have using the read.table function. I always get an error of type : Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : line 1 did not have 9 elements Here is my code: varnames - c(names, symbol, price, displ, gas, weight, reliab, origin, type) cardat - read.table(PowerMac 7300:Logiciels de Statistiques:rm162:car02.txt, col.names=varnames, as.is=c(F,T,F,F,F,F,F,F,F,F)) Can you advice me ? Thanks in advance, Pascale Tremblay __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] correspondance analysis clustering
Hi 1) I am using the function ca() of the package multiv to make a correspondance analysis of a matrix of categorical datas which are numericaly coded. I would like to be sure that it is considered as a matrix of categorical datas and not numerical. I cannot find any explicit mention of that in the help file for this function 2) I would like to take the resulting matrix rproj to do a clustering. I use hierclust() and partition() of the package multiv regarding hierclust() when I use the method number 1 i get this error: Error in hclust(a, method) : invalid clustering method when I change the number of the method I get Error in pmatch(x, table, duplicates.ok) : argument is not of mode character As for the partition() function, I also have some troubles. It seems I should mention a vector of clustered centers for initiating the iterative optimization process. But I do not know where to enter it. I get the following message Error in matrix(0, ng, m) : non-numeric matrix extent Has anybody ever encountered those problems? Thanks a lot _ MSN Search, le moteur de recherche qui pense comme vous ! __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] interpolation and 3D plots
I've been told that you may be able to help. I have a complex linear model with multiple two-way interaction terms. Is there a way to view the interaction terms in a 3d plot equivalent to the S functions: plan-interp(x,y,z) image(plan) where x and y are my explanatory variables and z my response variable. Thanks, Jonatha Davies __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] Overlaying a moving average curve on top of a barplot
Jose Santos Alegria wrote: I'm using standard barplot (Windows version 1.6.2 of R) to represent a certain weekly metric v and I would like to properly overlay on top of it its moving average mean.8 (window of 8 weeks). I must be doing something wrong since the moving average (using lines) doesn't overlay properly, i.e., both x-scales do not match! Have you considered using filter? I made a somehov similiar plot this way: (prec being a data frame with 'columns' date with dates of measurements and prec, precipitation at the actual date) code plot(prec) lines(prec$date,filter(prec$value,c(0.25,0.25,0.25,0.25))) /code Points showing actual measurements and a four periods moving average as a line. Hope this helps. Morten -- Morten Sickel Norwegian Radiation Protection Authority http://www.nrpa.no __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] Re-assigning vector elements based on their initial values.
Hi On 1 Feb 2003 at 7:17, John Fox wrote: Dear Rex, You can use if.else, which is vectorized: v.new - ifelse(v 0, -v/2, v) v.new [1] 5.0 5.0 1.5 1.5 7.0 8.0 10.0 or simply abs(v/((v0)+1)) it should be a little bit quicker (By the way, the solution that you suggested using a loop works, but for some reason the sign is wrong in the result that you printed; notice that your else clause does nothing -- you probably meant to assign to v.new not v -- and is unnecessary in any event.) I hope that this helps, John At 07:38 PM 1/31/2003 -0700, [EMAIL PROTECTED] wrote: Is there an eloquent solution to re-assign vector element values? I have a vector which contains chemical data, some of them are flagged as non-detected values by their negative values. I can find the statistics on the positive values in vector v simply by typing: v- c(5,5,-3,-3,7,8,10) v[(v0)] [1] 5 5 7 8 10 I can also convert to positive values by asb(v) [1] 5 5 3 3 7 9 10 I then can do mean() and var() etc. But when I want to come up with a way to change a negative value to a postive 1/2 value I couldn't come up with a nice way using vectoral syntax to do it. In the method I came up with , I discovered that I have to pre-define a new vector v.new or I get an error. v.new -v then I have to loop through all of the elements! for(i in 1:length(v)){ if (v[i] 0) v.new[i] - -1*v[i]/2 else v[i] - v[i]} v.new [1] 5.0 5.0 -1.5 -1.5 7.0 9.0 10.0 This works but seems labored given the previous crisp vector operations. - John Fox Department of Sociology McMaster University Hamilton, Ontario, Canada L8S 4M4 email: [EMAIL PROTECTED] phone: 905-525-9140x23604 web: www.socsci.mcmaster.ca/jfox - __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help Cheers Petr [EMAIL PROTECTED] [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] Overlaying a moving average curve on top of a barplot
My problem is not with plot() but with barplot()! I guess it may have to do with the fact that the barplot's bars have a non-negligible width and the moving average line not! Is it? José A. S. Alegria -Original Message- From: Morten Sickel [mailto:[EMAIL PROTECTED]] Sent: segunda-feira, 3 de Fevereiro de 2003 11:43 AM To: José Santos Alegria; R help (E-post) Subject: RE: [R] Overlaying a moving average curve on top of a barplot Jose Santos Alegria wrote: I'm using standard barplot (Windows version 1.6.2 of R) to represent a certain weekly metric v and I would like to properly overlay on top of it its moving average mean.8 (window of 8 weeks). I must be doing something wrong since the moving average (using lines) doesn't overlay properly, i.e., both x-scales do not match! Have you considered using filter? I made a somehov similiar plot this way: (prec being a data frame with 'columns' date with dates of measurements and prec, precipitation at the actual date) code plot(prec) lines(prec$date,filter(prec$value,c(0.25,0.25,0.25,0.25))) /code Points showing actual measurements and a four periods moving average as a line. Hope this helps. Morten -- Morten Sickel Norwegian Radiation Protection Authority http://www.nrpa.no __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Lattice not plotting within loop
Something I don't understand ... (!) With the lattice library loaded, I have a loop for( Z in ... ) { ... xyplot(y~x | t, xlab=..., ylab=... ) } and no plot appears on the R graphics device. However, when I run the commands within {...} separately for each instance of Z, I get the plot displayed each time. So it looks as though xyplot is not outputting to the graphics display when invoked within a loop. What am I mising? With thanks, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 167 1972 Date: 03-Feb-03 Time: 12:35:02 -- XFMail -- __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] plot.gam for glm objects.
Dear Toby, I think that you mean partial-residual (i.e., component+residual) plots rather than partial-regression (i.e., added-variable) plots. In either event, see the cr.plots and av.plots functions in the car package; both have methods for GLMs. I hope that this does what you need, John At 05:11 PM 2/3/2003 +1100, [EMAIL PROTECTED] wrote: All, I was wondering if someone had come across the problem of producing partial regression plots for glm objects in R? When using Splus in the past I have passed glm objects to the plot.gam function. To my knowledge this functionality isn't included in R ( I would be happily corrected here) and if someone had some code floating around to do this it would save me re-inventing wheels etc. - John Fox Department of Sociology McMaster University Hamilton, Ontario, Canada L8S 4M4 email: [EMAIL PROTECTED] phone: 905-525-9140x23604 web: www.socsci.mcmaster.ca/jfox - __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] interpolation and 3D plots
Dear Jonathan, The all.effects function in the car package will identify the high-order terms in a linear or generalized-linear model and absorb terms marginal to them (e.g., for a two-way interaction, the main effects marginal to the interaction and the constant). The plot method for the object produced uses trellis graphics to plot terms, but for a two-way interaction, the information in the object could easily be plotted as an image (or other 3D) plot. I hope that this helps, John At 10:02 AM 2/3/2003 +, Davies, Jonathan wrote: I've been told that you may be able to help. I have a complex linear model with multiple two-way interaction terms. Is there a way to view the interaction terms in a 3d plot equivalent to the S functions: plan-interp(x,y,z) image(plan) where x and y are my explanatory variables and z my response variable. - John Fox Department of Sociology McMaster University Hamilton, Ontario, Canada L8S 4M4 email: [EMAIL PROTECTED] phone: 905-525-9140x23604 web: www.socsci.mcmaster.ca/jfox - __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Bus error with xyplot
Has anybody else experienced something like the example below? Any clues about where I could start looking? Thank you in advance, Giovanni version _ platform sparc-sun-solaris2.7 arch sparc os solaris2.7 system sparc, solaris2.7 status major1 minor6.2 year 2003 month01 day 10 language R library(lattice) example(xyplot) xyplot data(quakes) xyplot Depth - equal.count(quakes$depth, number = 8, overlap = 0.1) xyplot xyplot(lat ~ long | Depth, data = quakes) Bus error -- __ [ ] [ Giovanni Petris [EMAIL PROTECTED] ] [ Department of Mathematical Sciences ] [ University of Arkansas - Fayetteville, AR 72701 ] [ Ph: (479) 575-6324, 575-8630 (fax) ] [ http://definetti.uark.edu/~gpetris/ ] [__] __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] Bus error with xyplot
Giovanni == Giovanni Petris [EMAIL PROTECTED] on Mon, 3 Feb 2003 08:36:06 -0600 (CST) writes: Giovanni Has anybody else experienced something like the example below? not recently. Could it be that your version of the `grid' package (which is loaded by `lattice') or `lattice' are incompatible (i.e. older than) to your R version? After library(lattice), use .path.package() to see where it was loaded from. Giovanni Any clues about where I could start looking? If it's not the above, and since you are on a unix system, start R inside the debugger. You then will hopefully see in which call the problem occurs: R -d gdb run library(lattice) ## The Bus error should leave you inside gdb, where you can enter `bt' to get the [b]ack[t]race of function calls. More details on using the debugger are in the R-FAQ and Writing Extensions.. Martin Maechler [EMAIL PROTECTED]http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO C16Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] Bus error with xyplot
From: Martin Maechler [mailto:[EMAIL PROTECTED]] Giovanni == Giovanni Petris [EMAIL PROTECTED] on Mon, 3 Feb 2003 08:36:06 -0600 (CST) writes: Giovanni Has anybody else experienced something like the example below? not recently. Could it be that your version of the `grid' package (which is loaded by `lattice') or `lattice' are incompatible (i.e. older than) to your R version? After library(lattice), use .path.package() to see where it was loaded from. This brings up (IIRC) a topic that was discussed on R-devel a while ago: Version checks for required packages. Is this feasible? Seems quite worthwhile to me... [...] Cheers, Andy -- __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] [Out off-topic] SJava under Windows
Sorry for this off-topic subject. I am fighting for running SJava under Windows. SJava_0.64 (compiled by Simon Urbanek, thanks), R 1.6.2, Java JDK 1.4.0_02, Windows XP pro: library(SJava) .JavaInit() Error in .JavaInit() : Couldn't start Java Virtual Machine: Cannot find the Omegahat interface manager class. Check you classpath! # And the second time... .JavaInit() It gives the error: The instruction at 0x10bc9f0d referenced memory at 0x10d60008. The memory could not be read, and ejects me. I have: .javaConfig $classPath [1] C:/PROGRA~1/R/rw1062/library/SJava/org/omegahat/Jars/Environment.jar [2] C:/PROGRA~1/R/rw1062/library/SJava/org/.. [3] C:/PROGRA~1/R/rw1062/library/SJava/org/omegahat/Jars/antlr.jar [4] C:/PROGRA~1/R/rw1062/library/SJava/org/omegahat/Jars/jas.jar [5] C:/PROGRA~1/R/rw1062/library/SJava/org/omegahat/Jars/jhall.jar $properties EmbeddedInR true InterfaceManagerClass org/omegahat/Interfaces/NativeInterface/OmegaInterfaceManager ForeignReferenceBaseClass org/omegahat/R/Java/RForeignReference java.compiler NONE OMEGA_HOME C:/PROGRA~1/R/rw1062/library/SJava/org/omegahat OmegahatSearchPath .,${OMEGA_HOME}/Environment/Scripts/Run,${OMEGA_HOME}/Jars/Environment.jar java.library.path C:/PROGRA~1/R/rw1062/library/SJava/libs $libraryPath [1] C:/PROGRA~1/R/rw1062/library/SJava/libs Any idea? Best regards, Philippe Grosjean ...](({°...°}))... ) ) ) ) ) ( ( ( ( ( Dr. Philippe Grosjean ) ) ) ) ) ( ( ( ( ( LOV, UMR 7093 ) ) ) ) ) Station Zoologique ( ( ( ( ( Observatoire Océanologique ) ) ) ) ) BP 28 ( ( ( ( ( 06234 Villefranche sur mer cedex ) ) ) ) ) France ( ( ( ( ( ) ) ) ) ) tel: +33.4.93.76.38.16, fax: +33.4.93.76.38.34 ( ( ( ( ( ) ) ) ) ) e-mail: [EMAIL PROTECTED] ( ( ( ( ( SciViews project coordinator (http://www.sciviews.org) ) ) ) ) ) ... __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] convert from seconds to date-time objects
A colleague of mine would like to know how seconds since 1970 (represented as integers) can be converted to date-time objects? thanks -- John Bjornar Bremnes Norwegian Meteorological Institute (met.no) Research and Development Department P.O.Box 43 Blindern, N-0313 Oslo, Norway Phone: (+47) 2296 3326. Fax: (+47) 2269 6355 __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] Bus error with xyplot
On Mon, Feb 03, 2003 at 10:00:46AM -0500, Liaw, Andy wrote: From: Martin Maechler [mailto:[EMAIL PROTECTED]] Giovanni == Giovanni Petris [EMAIL PROTECTED] on Mon, 3 Feb 2003 08:36:06 -0600 (CST) writes: Giovanni Has anybody else experienced something like the example below? not recently. Could it be that your version of the `grid' package (which is loaded by `lattice') or `lattice' are incompatible (i.e. older than) to your R version? After library(lattice), use .path.package() to see where it was loaded from. This brings up (IIRC) a topic that was discussed on R-devel a while ago: Version checks for required packages. Is this feasible? Seems quite worthwhile to me... And there has been some work on it (reposTools, under www.bioconductor.org), however, getting this right is not a small thing and has some fairly large implications that we are looking at. We too would like to be able to do this reliably. Robert [...] Cheers, Andy -- __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help -- +---+ | Robert Gentleman phone : (617) 632-5250 | | Associate Professor fax: (617) 632-2444 | | Department of Biostatistics office: M1B20 | Harvard School of Public Health email: [EMAIL PROTECTED] | +---+ __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] Overlaying a moving average curve on top of a barplot
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of José Santos Alegria Sent: Monday, February 03, 2003 5:30 AM To: [EMAIL PROTECTED] Subject: [R] Overlaying a moving average curve on top of a barplot I'm using standard barplot (Windows version 1.6.2 of R) to represent a certain weekly metric v and I would like to properly overlay on top of it its moving average mean.8 (window of 8 weeks). I must be doing something wrong since the moving average (using lines) doesn't overlay properly, i.e., both x-scales do not match! ... barplot(v[8:length(v)], col=7) lines(mean.8[1:length(mean.8)], lty=1, lwd=2, col=2) ... How do I make sure that both graphics are in synch as far as the x-scale and y-scales are concerned? Thanks, José A. S. Alegria The problem that you are having is that you need to get the bar midpoints from barplot() in order to use those values as the x coordinate values for lines(). barplot() returns the bar midpoints as an invisible vector (or matrix where appropriate). Modify your code to: mp - barplot(v[8:length(v)], col=7) lines(mp, mean.8[1:length(mean.8)], lty=1, lwd=2, col=2) This puts the bar midpoints (x axis values) in mp, which you can then use for lines(). HTH, Marc __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Problems with table
Hi, I'm having difficulties in the manipulation of the function table. Necessary to have access its elements and I am not obtaining. For example, if I have a data.frame with name df and make: t - data.frame(table(df)) and later trying to make a comparison of the type t[1,1 ] 0.1, generates an error of the type: [1] NA Warning message: not meaningful for factors in: Ops.factor(t[1, 1], 0.1) How can I resolve this? Thanks, -- Patrícia Maforte dos Santos Centro de Informatica Universidade Federal de Pernambuco Recife/PE - Brasil -- __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Installation problem - No X interface
Hi I've installed the R system under Solaris 8 on a SunFire V880. I configured it using the --with-x option. Installation seemed to go fine, but when I start R with the X-Windows GUI option, R --gui=X11 I just get put into the command-line mode. Any ideas what I'm missing? Thanks Scotty __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] convert from seconds to date-time objects
The solution turned out to be simple: x - 0:100 class(x) - POSIXct x John Bjornar John Bjornar Bremnes wrote: A colleague of mine would like to know how seconds since 1970 (represented as integers) can be converted to date-time objects? thanks -- John Bjornar Bremnes Norwegian Meteorological Institute (met.no) Research and Development Department P.O.Box 43 Blindern, N-0313 Oslo, Norway Phone: (+47) 2296 3326. Fax: (+47) 2269 6355 __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] convert from seconds to date-time objects
On Mon, 3 Feb 2003, John Bjornar Bremnes wrote: A colleague of mine would like to know how seconds since 1970 (represented as integers) can be converted to date-time objects? ISOdate(1970,1,1)+seconds -thomas __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] convert from seconds to date-time objects
On Mon, 3 Feb 2003, John Bjornar Bremnes wrote: The solution turned out to be simple: x - 0:100 class(x) - POSIXct x Yes, but that relies on the internal representation of POSIXct objects, which is probably unwise. -thomas __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] Installation problem - No X interface
Steve Howie [EMAIL PROTECTED] writes: Hi I've installed the R system under Solaris 8 on a SunFire V880. I configured it using the --with-x option. Installation seemed to go fine, but when I start R with the X-Windows GUI option, R --gui=X11 I just get put into the command-line mode. Any ideas what I'm missing? Possibly nothing. X11 *is* a GUI, --gui=X11 just means that X11 windows are used for graphics and the data editor. If plot(1) pops up a window, things are as they should be. -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] r-bugs web site temporarily UP
Peter Dalgaard BSA [EMAIL PROTECTED] writes: The machine that serves r-bugs.biostat.ku.dk has been taken off the net. A new machine is planned to replace it, but we need to reconfigure the DNS, which is not going to happen until Monday. The mail interface should still work. We got swamped by ORDB pointing out that sendmail wasn't up to snuff (if you don't know what that means, just consider yourself lucky...). So we just put the old machine back up for now, but it will obviously have to be taken down eventually. -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] convert from seconds to date-time objects
Thomas Lumley [EMAIL PROTECTED] writes: On Mon, 3 Feb 2003, John Bjornar Bremnes wrote: A colleague of mine would like to know how seconds since 1970 (represented as integers) can be converted to date-time objects? ISOdate(1970,1,1)+seconds I think you might want ISOdate(1970,1,1,hour=0)+1:100 to get it to count from midnight, GMT. Notice that there are devils lurking in using class(x)- class(ISOdate(1970,1,1,hour=0)+1:100) [1] POSIXt POSIXct so that's what you need to set class(x) to. Without the POSIXt bit you may run into method dispatch problems later on. Currently, that is! Relying on the internal representation of a class is generally to be avoided. -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] convert from seconds to date-time objects
On Mon, 3 Feb 2003, John Bjornar Bremnes wrote: A colleague of mine would like to know how seconds since 1970 (represented as integers) can be converted to date-time objects? structure(as.double(x), class=c(POSIXt, POSIXlt)) will do it in the current version. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] convert from seconds to date-time objects
On Mon, 3 Feb 2003, John Bjornar Bremnes wrote: The solution turned out to be simple: But wrong. That's not the right class. Thomas Lumley's suggestion is better, and mine is correct but less elegant. x - 0:100 class(x) - POSIXct x -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] vectorized leave one out analyses
Hi all, I'm implementing a population genetic statistic that requires repeated re-estimation of population parameters after a single observation has been left out. It seems to me that one could: a) use looping in R, b) use a vectorized approach in R, c) loop in a dynamically loaded c-function, d) or use an existing jackknife routine. an untested skeleton of the code for 'a': foo - function(datfrm) { retvec - rep(0,nrow(datfrm)) selvec - rep(T,nrow(datfrm)) for (i in 1:nrow(datfrm)) { selvec[i] - F retvec[i] - popstat(datfrm[selvec]) selvec[i] - T } retvec } I suppose that 'd' is the easiest option if such a routine exists, but I have not come across one by means of an archive search. I'd like to avoid 'a' because of efficiency, and 'c' because of additional coding and linking steps. I like the idea of 'b' because it would be nifty and likely fast, though there may be memory issues. I'm sure that this is a general problem that somebody has solved in an elegant fashion. I'm just looking for the solution. -- Allan Strand, Biologyhttp://linum.cofc.edu College of Charleston Ph. (843) 953-9189 Charleston, SC 29424 Fax (843) 953-9199 __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] vectorized leave one out analyses
There are jackknife functions about, but this is not jackknifing. Unless popstat is itself vectorized (meaning I think that it can take list of datasets, or perhaps a matrix) I doubt if anything is better than (a). Remember Jackson's rules of programming (which are quoted in `S Programming'). Don't optimize until you need to. On 3 Feb 2003, Allan Strand wrote: Hi all, I'm implementing a population genetic statistic that requires repeated re-estimation of population parameters after a single observation has been left out. It seems to me that one could: a) use looping in R, b) use a vectorized approach in R, c) loop in a dynamically loaded c-function, d) or use an existing jackknife routine. an untested skeleton of the code for 'a': foo - function(datfrm) { retvec - rep(0,nrow(datfrm)) selvec - rep(T,nrow(datfrm)) for (i in 1:nrow(datfrm)) { selvec[i] - F retvec[i] - popstat(datfrm[selvec]) selvec[i] - T } retvec } I suppose that 'd' is the easiest option if such a routine exists, but I have not come across one by means of an archive search. I'd like to avoid 'a' because of efficiency, and 'c' because of additional coding and linking steps. I like the idea of 'b' because it would be nifty and likely fast, though there may be memory issues. I'm sure that this is a general problem that somebody has solved in an elegant fashion. I'm just looking for the solution. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] (Off topic.) Game theory.
This has nothing to do with R as such; I'm simply trying to exploit the vast resource of knowledge and expertise that resides in the R community. For my sins, I am teaching a course on Game Theory this term. Game Theory I know from ***nothing***. I am trying to learn the subject as I go along, staying perhaps half a step in front of the students. I am having considerable difficulty with several elementary points, (vis-a-vis two person non-zero-sum games) and have not yet succeeded in clarifying these points from any of the books that I have managed to get my hands on. Is there any kind soul out there (or do any of you have a kind-soul colleague) who might be willing to discuss some of my game theory difficulties with me by email? Such a person would earn my undying gratitude. (Sorry that I can't offer a more substantial reward. :-) ) Since this is off-topic, please reply to me (only) at [EMAIL PROTECTED] and not to the list. Thanks, and thanks to everyone for their patience with my usurption of bandwidth. cheers, Rolf Turner __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] extension of generic functions in methods package
How can I extend the signature of a generic function, because the following example is unclear for me. setClass(A,representation(data=numeric)); setGeneric(func,function(obj,...){ res - standardGeneric(func); res@cal - match.arg(); return(res); }); func1.A - function(obj){ print(A); return(); } setMethod(func,A,func1.A); showMethods(func) ##Function func: ##obj = A func2.A - function(obj,x){ print(A); return(); } ## gives error ## setMethod(func,c(A,numeric),func2.A); ##Error in matchSignature(signature, fdef) : ## Invalid names in signature: ## extending the signature setGeneric(func,function(obj,x,...){ res - standardGeneric(func); res@cal - match.arg(); return(res); }); setMethod(func,c(A,numeric),func2.A); ## but: showMethods(func) ##Function func: ##obj = A, x = numeric ## and a - new(A); func(A) ## gives ##Error in func(a) : No direct or inherited method for function func for ##this call ## but this works func(a,1) ##[1] A ##NULL My questions: 1) Is it correct, that func1.A disappears in the showMethods output? 2) How can I extend the signature of a generic function, without removing the other functions? Thanks Thomas __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
FW: [R] unable to open connection
Thanks to Brian D. Ripley and Uwe Ligges. It works now. Zhu Wang Statistical Science Department Southern Methodist University 3225 Daniel Avenue, Heroy 123 Dallas, TX 75275 Tel: (214)768-2453 Fax: (214)768-4035 -Original Message- From: Uwe Ligges [mailto:[EMAIL PROTECTED]] Sent: Sunday, February 02, 2003 5:22 AM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: [R] unable to open connection [EMAIL PROTECTED] wrote: It works here on Windows with R 1.6.2. I rebuilt the precompiled version, as that seems no longer to so so (although it did when it was built under I think 1.5.0). The original posting did not give an OS. If this is Windows, the comments in the ReadMe and rw-FAQ apply: compile it from source yourself, and don't report problems on R-help. The service provided does not extend to checking that packages keep working with each new R version. My recompiled version will get to CRAN tonight: right now see http://toucan.stats.ox.ac.uk/R/RWin/waveslim.zip Great, Brian, it works now. But where is the relevant difference? I haven't tried to recompile, because I thought it does not matter. Uwe __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] binary scatterplot
Hi, When I use the function plot() to plot a categorical variable with two levels versus a continuous variable, the two levels of the categorical variable are plotted at the values of 1.0 and 2.0. I would like them to be plotted at the values of 0.0 and 1.0. How can I do this? Example: x - 1:10 y - as.factor(rep(c(A,B),c(5,5))) plot(x,y) Thanks in advance. version: platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major1 minor6.1 year 2002 month11 day 01 language R -- ** | Michael Fugate Phone: (505) 667-0398 | | Los Alamos National Laboratory Fax:(505) 665-5220 | | Group: CCS-3, Mail Stop: B265 e-mail: [EMAIL PROTECTED] | | Los Alamos, NM 87545 | ** __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] binary scatterplot
Michael == Michael Lynn Fugate [EMAIL PROTECTED] writes: Hi, When I use the function plot() to plot a categorical variable with two levels versus a continuous variable, the two levels of the categorical variable are plotted at the values of 1.0 and 2.0. I would like them to be plotted at the values of 0.0 and 1.0. How can I do this? This is not quite what you are asking for, but it might serve just as well: x - 1:10 y - as.factor(rep(c(A,B),c(5,5))) dotchart(x,groups=y) or require(lattice) df-data.frame(x,y) stripplot(y~x, data=df) or require(lattice) df-data.frame(x,y) dotplot(y~x, data=df) Mike __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] binary scatterplot
Michael Lynn Fugate wrote: Hi, When I use the function plot() to plot a categorical variable with two levels versus a continuous variable, the two levels of the categorical variable are plotted at the values of 1.0 and 2.0. I would like them to be plotted at the values of 0.0 and 1.0. How can I do this? Example: x - 1:10 y - as.factor(rep(c(A,B),c(5,5))) plot(x,y) plot(x, as.integer(y) - 1) Uwe Ligges Thanks in advance. version: platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major1 minor6.1 year 2002 month11 day 01 language R -- ** | Michael Fugate Phone: (505) 667-0398 | | Los Alamos National Laboratory Fax:(505) 665-5220 | | Group: CCS-3, Mail Stop: B265 e-mail: [EMAIL PROTECTED] | | Los Alamos, NM 87545 | ** __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] binary scatterplot
Dear Michael, You could use plot(x, as.numeric(y) - 1). John At 01:10 PM 2/3/2003 -0700, Michael Lynn Fugate wrote: Hi, When I use the function plot() to plot a categorical variable with two levels versus a continuous variable, the two levels of the categorical variable are plotted at the values of 1.0 and 2.0. I would like them to be plotted at the values of 0.0 and 1.0. How can I do this? Example: x - 1:10 y - as.factor(rep(c(A,B),c(5,5))) plot(x,y) John Fox Department of Sociology McMaster University email: [EMAIL PROTECTED] web: http://www.socsci.mcmaster.ca/jfox __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] Problems with table
Patricia Maforte dos Santos wrote: Hi, I'm having difficulties in the manipulation of the function table. Necessary to have access its elements and I am not obtaining. For example, if I have a data.frame with name df and make: t - data.frame(table(df)) Dou you really want to generate a data.frame from that table? BTW: Assigning is done by -, not - ... and later trying to make a comparison of the type t[1,1 ] 0.1, generates an error of the type: [1] NA Warning message: not meaningful for factors in: Ops.factor(t[1, 1], 0.1) Because t[1,1] is an element of a vector of class factor (due to the use of data.frame()). BTW: t() is a very basic function in R. Thus it's generally a bad idea to call another object t, although it works at least in this case. How can I resolve this? I guess you want something like table(df)[1,1] 0.1 don't you? Uwe Ligges Thanks, -- Patrícia Maforte dos Santos Centro de Informatica Universidade Federal de Pernambuco Recife/PE - Brasil -- __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Mtext and xyplot
Dear all; I wish to create a graphic object combing an xyplot() and an mtext(). My code looks like following, gmv - { trellis.device(windows, bg=white, width = 7, height = 7) xyplot(Mvol ~ Age | Nl * Th , data = Hft1, prepanel = function(x, y) prepanel.loess(x, y, span = 1), xlab =list(label = Age (Years), font = 2), ylab = , #ylab = list(expression(paste(Volume ( , paste(m^3/ha, )), sep= )), font=2), main = list( Volume), par.strip.text = list(cex=1.0, font = 2), panel = function(x, y) { panel.grid () panel.xyplot(x,y, col= black) panel.lmline(x, y, lty = 2, lwd = 2) panel.loess(x, y, span = 1, degree = 1, lty=1, lwd=2) } ) mtext(expression(paste(Volume ( , paste(m^3/ha, )), sep = )), outer=T, font = 2, side = 2, line = -1 ) } The mtext() is to replace the ylab because the font = 2 in the above commented line does not result in a bold font as in the xlab. The code within the outmost { } works fine on a windows device but generates error when it runs as a function: Error in mtext(expression(paste(Volume ( , paste(m^3/ha, )), : plot.new has not been called yet Any suggestions to rectify the error? TIA, Richard __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] Mtext and xyplot
On Monday 03 February 2003 03:47 pm, Yang, Richard wrote: Dear all; I wish to create a graphic object combing an xyplot() and an mtext(). You cannot. xyplot() uses grid for all its graphics, and grid graphics cannot be used in conjunction with base R graphics functions. My code looks like following, gmv - { trellis.device(windows, bg=white, width = 7, height = 7) xyplot(Mvol ~ Age | Nl * Th , data = Hft1, prepanel = function(x, y) prepanel.loess(x, y, span = 1), xlab =list(label = Age (Years), font = 2), ylab = , #ylab = list(expression(paste(Volume ( , paste(m^3/ha, )), sep= )), font=2), main = list( Volume), par.strip.text = list(cex=1.0, font = 2), panel = function(x, y) { panel.grid () panel.xyplot(x,y, col= black) panel.lmline(x, y, lty = 2, lwd = 2) panel.loess(x, y, span = 1, degree = 1, lty=1, lwd=2) } ) mtext(expression(paste(Volume ( , paste(m^3/ha, )), sep = )), outer=T, font = 2, side = 2, line = -1 ) } The mtext() is to replace the ylab because the font = 2 in the above commented line does not result in a bold font as in the xlab. And it does inside mtext ? (I don't see that on Linux, maybe it does on Windows.) The code within the outmost { } works fine on a windows device but generates error when it runs as a function: Error in mtext(expression(paste(Volume ( , paste(m^3/ha, )), : plot.new has not been called yet Any suggestions to rectify the error? maybe something like ylab = list(expression(bold(Volume... (read ?plotmath) TIA, Richard __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Plotting Venn diagrams in R
Last year there was a request seeking functions to plot Venn diagrams in R. Seeing no reply and for other reasons needing this, I wrote a quick routine. The general problem of creating a Venn diagram with overlap areas proportional to the number of counts in each overlap is over determined. An approximate solution is to make the area of the circles and pair wise overlap areas proportional to the number of counts in each. Using just the pair wise overlaps ignores (or hopes for the best on :) ) the area of the three-way overlap. R code that implements this is shown below. Usage: A, B and C are Boolean vectors of equal length, e.g. A = runif(100) 0.5 B = runif(100) 0.4 C = runif(100) 0.6 d = list() d$table = table(A,B,C) d$labels = c(A,B,C) plot.venn.diagram(d) This is pre-alpha code, caveat emptor. In particular, the code to position the labels needs work. If someone wants to convert this to a package or add it to an existing package, feel free to do so. To optimize the solution over all of the overlaps or if you have more than three sets, you can use a random sampling approach, but implementing this in R is too slow to be useful. David David J. States, M.D., Ph.D. Professor of Human Genetics Director of Bioinformatics University of Michigan School of Medicine Medical Science Building I, Room 5443 Ann Arbor, MI 48109 USA venn.overlap - function(r, a, b, target = 0) { # # calculate the overlap area for circles of radius a and b # with centers separated by r # target is included for the root finding code # pi = acos(-1) if(r = a + b) { return( - target) } if(r a - b) { return(pi * b * b - target) } if(r b - a) { return(pi * a * a - target) } s = (a + b + r)/2 triangle.area = sqrt(s * (s - a) * (s - b) * (s - r)) h = (2 * triangle.area)/r aa = 2 * atan(sqrt(((s - r) * (s - a))/(s * (s - b ab = 2 * atan(sqrt(((s - r) * (s - b))/(s * (s - a sector.area = aa * (a * a) + ab * (b * b) overlap = sector.area - 2 * triangle.area return(overlap - target) } plot.venn.diagram - function(d) { # # Draw Venn diagrams with proportional overlaps # d$table = 3 way table of overlaps # d$labels = array of character string to use as labels # pi = acos(-1) csz = 0.1 # Normalize the data n = length(dim(d$table)) c1 = vector(length = n) c1[1] = sum(d$table[2, , ]) c1[2] = sum(d$table[, 2, ]) c1[3] = sum(d$table[, , 2]) n1 = c1 # c2 = matrix(nrow = n, ncol = n, 0) c2[1, 2] = sum(d$table[2, 2, ]) c2[2, 1] = c2[1, 2] c2[1, 3] = sum(d$table[2, , 2]) c2[3, 1] = c2[1, 3] c2[2, 3] = sum(d$table[, 2, 2]) c2[3, 2] = c2[2, 3] n2 = c2 # c3 = d$table[2, 2, 2] n3 = c3 c2 = c2/sum(c1) c3 = c3/sum(c1) c1 = c1/sum(c1) n = length(c1) # Radii are set so the area is proporitional to number of counts pi = acos(-1) r = sqrt(c1/pi) r12 = uniroot(venn.overlap, interval = c(max(r[1] - r[2], r[2] - r[1], 0) + 0.01, r[1] + r[2] - 0.01), a = r[1], b = r[ 2], target = c2[1, 2])$root r13 = uniroot(venn.overlap, interval = c(max(r[1] - r[3], r[3] - r[1], 0) + 0.01, r[1] + r[3] - 0.01), a = r[1], b = r[ 3], target = c2[1, 3])$root r23 = uniroot(venn.overlap, interval = c(max(r[2] - r[3], r[3] - r[2], 0) + 0.01, r[2] + r[3] - 0.01), a = r[2], b = r[ 3], target = c2[2, 3])$root s = (r12 + r13 + r23)/2 x = vector() y = vector() x[1] = 0 y[1] = 0 x[2] = r12 y[2] = 0 angle = 2 * atan(sqrt(((s - r12) * (s - r13))/(s * (s - r13 x[3] = r13 * cos(angle) y[3] = r13 * sin(angle) xc = cos(seq(from = 0, to = 2 * pi, by = 0.01)) yc = sin(seq(from = 0, to = 2 * pi, by = 0.01)) cmx = sum(x * c1) cmy = sum(y * c1) x = x - cmx y = y - cmy rp=sqrt(x*x + y*y) frame() par(usr = c(-1, 1, -1, 1), pty = s) box() for(i in 1:3) { lines(xc * r[i] + x[i], yc * r[i] + y[i]) } xl = (rp[1] + (0.7 * r[1])) * x[1]/rp[1] yl = (rp[1] + (0.7 * r[1])) * y[1]/rp[1] text(xl, yl, d$labels[1]) text(xl, yl - csz, d$table[2, 1, 1]) xl = (rp[2] + (0.7 * r[2])) * x[2]/rp[2] yl = (rp[2] + (0.7 * r[2])) * y[2]/rp[2] text(xl, yl, d$labels[2]) text(xl, yl - csz, d$table[1, 2, 1]) xl = (rp[3] + (0.7 * r[3])) * x[3]/rp[3] yl = (rp[3] + (0.7 * r[3])) * y[3]/rp[3] text(xl, yl, d$labels[3]) text(xl, yl - csz, d$table[1, 1, 2]) # text((x[1] + x[2])/2, (y[1] + y[2])/2, d$table[2, 2, 1]) text((x[1] + x[3])/2, (y[1] + y[3])/2, d$table[2, 1, 2]) text((x[2] + x[3])/2, (y[2] + y[3])/2, d$table[1, 2, 2]) # text(0, 0, n3) list(r = r, x = x, y = y, dist = c(r12, r13, r23), count1 = c1, count2 = c2, labels = d$labels) } __ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help