[R] questions about axis
Dear helper. I am a beginer. I have difficulties to handle axis. I want to draw axis label such that axis has range of [-0.4,0.4] with intervel 0.2 for x and y axis. Some part of range do not have data points. Thus, plot does not show whole range. How can I enforce plot to depict the whole range regardless of existence of data points ? Another problem is that when I depict axis labels, some labels are overlapped because interval is very small. In this case, I'd like to put one of label into insde the box which is drawn by plot. How can I do this ? If I can see related source code, it will be very helpful. Thanks a lot, Yunho Hong [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] questions about axis
Hi, On Wed, 22 Oct 2003, yyh wrote: I have difficulties to handle axis. I want to draw axis label such that axis has range of [-0.4,0.4] with intervel 0.2 for x and y axis. Some part of range do not have data points. Thus, plot does not show whole range. How can I enforce plot to depict the whole range regardless of existence of data points ? You can draw the plot from first principle. For example: x = seq(-0.4, 0.4, length = 50) y = runif(50, -0.2, 0.2) plot.new() plot.window(xlim = c(-0.4, 0.4), ylim = c(-0.4, 0.4)) axis(1, at = seq(-0.4, 0.4, by = 0.2)) axis(2, at = seq(-0.4, 0.4, by = 0.2)) points(x, y) box() Another problem is that when I depict axis labels, some labels are overlapped because interval is very small. In this case, I'd like to put one of label into insde the box which is drawn by plot. How can I do this ? Try: title(xlab = This is my x-label, line = -2) Of course, this is just a silly example, with 50 uniform random numbers between -0.2 and 0.2. But you get the idea... -- Cheers, Kevin --- Ko-Kang Kevin Wang Master of Science (MSc) Student SLC Tutor and Lab Demonstrator Department of Statistics University of Auckland New Zealand Homepage: http://www.stat.auckland.ac.nz/~kwan022 Ph: 373-7599 x88475 (City) x88480 (Tamaki) __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] run R under linux
Thank you for your help. But try() seems to only allow for an expression. My simulation have serveral expressions which possibly have problem. Is there any possibility to include them all in the try()? If not, I seem to use several try(). From: Jason Turner [EMAIL PROTECTED] To: Zhen Pang [EMAIL PROTECTED] CC: [EMAIL PROTECTED] Subject: Re: [R] run R under linux Date: Wed, 22 Oct 2003 10:15:54 +1300 Zhen Pang wrote: We are not allowed to submit job directly, so I never type R to use R, just make a batch. How can I use try() to correct my codes? In the interactive mode, I know how to continue, but now I never enter the R window, where to find my results and save seed to continue? Like you'd program any exception handling. A toy example to get you started might look like this: (somewhere inside your script file) ... results - vector(length=200,mode=numeric) #or whatever you use set.seed(123) ... errors - list() for(ii in 1:200) { foo - try(some.simulation.thingy(your.params)) if(inherits(foo,try-error)) { #something bombed results[ii] - NA errors[[as.character(ii)]] - foo } else { #it worked results[ii] - foo } } ... save(results,errors,file=results+errors.RData) ... The end. Play with that, and see if you get some useful ideas. Cheers Jason -- Indigo Industrial Controls Ltd. http://www.indigoindustrial.co.nz 64-21-343-545 [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Automatically updating GLM object
Dear all, i generated several GLM objects, named myobject1 to myobject25. Now i'd like to update both of them. So i tried: for(ii in 1:25) { assign(paste(myobject.updated, ii, sep=), update( myobject[ii] ,.~ + VAR2)) } Doesn't work I also tried to get all the names in a vector and update(names.myobject[ii],.~ + VAR2) Stiil doesn't work Any ideas thanks O__ Alain Le Tertre c/ /'_ --- Institut de Veille Sanitaire (InVS) (*) \(*) -- 12 rue du val d'Osne ~~ - 94415 Saint Maurice cedex FRANCE Voice: 33 1 41 79 67 50 Fax: 33 1 41 79 67 68 email: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] run R under linux
On Wed, 22 Oct 2003, Zhen Pang wrote: Thank you for your help. But try() seems to only allow for an expression. My simulation have serveral expressions which possibly have problem. Is there any possibility to include them all in the try()? If not, I seem to use several try(). {line1 line2 line3} *is* a single expression. As in the example on the help page for try, you can also wrap the computation in a function call, and that is usually a good idea. -- 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 272860 (secr) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] Graphics overview
Christoph Bier schrieb: [...] Yes, it is, thanks! But it seems only to work with arrays as No, it also works with data.frames as help(colSums) told me. -- Christoph Bier, Dipl.Oecotroph., Email: [EMAIL PROTECTED] Universitaet Kassel, FG Oekologische Lebensmittelqualitaet und Ernaehrungskultur \\ Postfach 12 52 \\ 37202 Witzenhausen Tel.: +49 (0) 55 42 / 98 -17 21, Fax: -17 13 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] Automatically updating GLM object
What does Doesn't work mean here? Note that myobject[ii] is unlikely to be what you want, and perhaps it should be get(paste(myobject, ii, sep=)) but the error messages you surely got should have been informative. On Wed, 22 Oct 2003, LE TERTRE Alain wrote: Dear all, i generated several GLM objects, named myobject1 to myobject25. Now i'd like to update both of them. So i tried: for(ii in 1:25) { assign(paste(myobject.updated, ii, sep=), update( myobject[ii] ,.~ + VAR2)) } Doesn't work I also tried to get all the names in a vector and update(names.myobject[ii],.~ + VAR2) Stiil doesn't work -- 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 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE : [R] Automatically updating GLM object
Sure that doesn't work is not very informative. The error message is Error in update.default(mod.init, new.form, data = mydata, na.action = na.omit) : need an object with call component That's because he's looking at a character object (the name) and not at the object itself. But your solution is what i wanted. Thanks both for the solution and your ability to read further an obscure doesn't work O__ Alain Le Tertre c/ /'_ --- Institut de Veille Sanitaire (InVS) (*) \(*) -- 12 rue du val d'Osne ~~ - 94415 Saint Maurice cedex FRANCE Voice: 33 1 41 79 67 50 Fax: 33 1 41 79 67 68 email: [EMAIL PROTECTED] -Message d'origine- De : Prof Brian Ripley [mailto:[EMAIL PROTECTED] Envoyé : mercredi 22 octobre 2003 09:56 À : LE TERTRE Alain Cc : [EMAIL PROTECTED] Objet : Re: [R] Automatically updating GLM object What does Doesn't work mean here? Note that myobject[ii] is unlikely to be what you want, and perhaps it should be get(paste(myobject, ii, sep=)) but the error messages you surely got should have been informative. On Wed, 22 Oct 2003, LE TERTRE Alain wrote: Dear all, i generated several GLM objects, named myobject1 to myobject25. Now i'd like to update both of them. So i tried: for(ii in 1:25) { assign(paste(myobject.updated, ii, sep=), update( myobject[ii] ,.~ + VAR2)) } Doesn't work I also tried to get all the names in a vector and update(names.myobject[ii],.~ + VAR2) Stiil doesn't work -- 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 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R]: Prediction interval for a Gaussian family log-link model
Hi there fellow R-users, Can anyone tell me how to build a prediction interval for a gaussian log-link model for the reponse variable?? I can find the standard error of the predictions but I cant seem to find the prediction interval. Is there a way I can calculate the prediction interval from the standard errors?? Here's the example: logX-rnorm(100) logY--2-0.5*logX+rnorm(100,0,0.4) Y-exp(logY) my.glm.mod-glm(Y~logX,family=gaussian(link=log)) predict(my.glm.mod,type=response,se.fit=TRUE) Thanks, Wayne Dr Wayne R. Jones Senior Statistician / Research Analyst KSS Group plc St James's Buildings 79 Oxford Street Manchester M1 6SS Tel: +44(0)161 609 4084 Mob: +44(0)7810 523 713 KSS Ltd Seventh Floor St James's Buildings 79 Oxford Street Manchester M1 6SS England Company Registration Number 2800886 Tel: +44 (0) 161 228 0040 Fax: +44 (0) 161 236 6305 mailto:[EMAIL PROTECTED]http://www.kssg.com The information in this Internet email is confidential and m...{{dropped}} __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Indicator Kriging
Indicator kriging is nothing but ordinary or simple kriging on binary (0/1) data; there's quite a list of packages that can do kriging: gstat, geoR, sgeostat, fields, spatial, ... Be aware that indicator kriging outcomes only estimate probabilities and may lie outside [0,1] To my knowledge there's no package that ports GSLIB to R. -- Edzer __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] RSPerl on Windows
Dear All, RSPerl looks like a great package. Does anyone have it working on Windows? I have seen references to problems building it on Windows, and suggestions to use R(D)COM instead, therefore I was wondering what the current state of play is. Many thanks, Matthew __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] plotmath question: y'
Hi all, I wonder how to correctly write the following expression (it's the axis label in a plot command): ylab=expression(y' == y - bar(y) ) Somehow the single quote in y' is causing the problems, I guess because it is interpreted as a quote... Does it have to be escaped? But how? Thanks for your help Pascal __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] non linear regression with R
Dear Colleagues, I have x, y data (pollen and seed dispersal from oaks !) that I would like to fit with a function which look like this: p(a,b,x,y)=b/(2*pi*a²gamma(2/b))*exp(-(square_root(x²+y²)/a)power(b)) I am looking for a and b values that fit my data at best. Can someone give me hints to perform such an analysis with R ? Thanks a lot Sophie Sophie Gerber [EMAIL PROTECTED] INRA - UMR BIOGECO 69 route d'Arcachon tel (33) (0)5 57 12 28 30 33612 Cestas cedexfax (33) (0)5 57 12 28 81 http://www.pierroton.inra.fr/genetics/Perso/Sophie/ page_sophie_english.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R]: Prediction interval for a Gaussian family log-link model
Wayne Jones [EMAIL PROTECTED] writes: Hi there fellow R-users, Can anyone tell me how to build a prediction interval for a gaussian log-link model for the reponse variable?? I can find the standard error of the predictions but I cant seem to find the prediction interval. Is there a way I can calculate the prediction interval from the standard errors?? Here's the example: logX-rnorm(100) logY--2-0.5*logX+rnorm(100,0,0.4) Y-exp(logY) my.glm.mod-glm(Y~logX,family=gaussian(link=log)) predict(my.glm.mod,type=response,se.fit=TRUE) Er, that's not the right model for those data! Y - exp(-2-0.5*logX)+rnorm(100,0,0.4) would be a log-link gaussian model (but a smaller SD would be more interesting). Assuming that this is what you intended, logX-sort(rnorm(100)) Y - exp(-2-0.5*logX)+rnorm(100,0,0.04) my.glm.mod-glm(Y~logX,family=gaussian(link=log), etastart=pmax(Y,0)) pp - predict(my.glm.mod,type=response,se.fit=TRUE) bounds - pp$fit + outer(sqrt(pp$residual.scale^2+pp$se.fit^2), qt(c(.05,.95),100-2)) plot(logX,Y) matlines(logX,bounds) BTW, we seem to have a problem with the gaussian(log) starting values if the observations are negative... Notice that this *only* works for gaussian responses and relies on the approximate normality of the predicted values. In general you have to compute the convolution of the error distribution with the distribution of the fitted value (possibly approximate). With discrete response variables, all bets are off: It is not at all clear what a prediction interval for binary response means. If you really intended a lognormal distribution for Y, and a loglinear relation with logX, just fit a linear model for log(Y) and transform everything back. -- 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 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] plotmath question: y'
Pascal A. Niklaus wrote: Hi all, I wonder how to correctly write the following expression (it's the axis label in a plot command): ylab=expression(y' == y - bar(y) ) expression(y * ' == y - bar(y)) Uwe Ligges Somehow the single quote in y' is causing the problems, I guess because it is interpreted as a quote... Does it have to be escaped? But how? Thanks for your help Pascal __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] plotmath question: y'
Pascal A. Niklaus [EMAIL PROTECTED] writes: Hi all, I wonder how to correctly write the following expression (it's the axis label in a plot command): ylab=expression(y' == y - bar(y) ) Somehow the single quote in y' is causing the problems, I guess because it is interpreted as a quote... Does it have to be escaped? But how? y*minute or y*' should do it. -- 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 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] select text using only the keyboard
I have a different wish: I want to be able to mouseclick in the middle of a line to get the cursor there (as in SPlus). While I appreciate that to get my wish I should just write a little patch, I estimate it would take me about 2 years to reach the point where I was capable of it, assuming I did nothing else, and I would certainly have to understand Windows, which in previous brushes I have found to be very bad for the brain. I can live without it. Paul - in the meantime you might type savehistory() and then edit .Rhistory in your favourite keyboard-friendly editor. -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: 21 October 2003 07:51 To: Paul Livingstone Cc: R-Help Subject: Re: [R] select text using only the keyboard Security Warning: If you are not sure an attachment is safe to open please contact Andy on x234. There are 0 attachments with this message. On Tue, 21 Oct 2003, Paul Livingstone wrote: I am using R 1.6.1 on Windows. I usually write/edit code in the R console, and when I get it working right, copy and paste it to a text file for later use. In Splus for Windows, this could be done easily using just the keyboard, with up-arrow, shift-end or shift-home, ctrl-c, etc. But in R, the shift key doesn't select text. The only way I can select text in R is with the mouse. Does anyone know how to select text in R using only the keyboard? No. If you think this would be a useful contribution, please send a patch against the current R sources (1.9.0-to-be, not 1.6.1). -- 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 https://www.stat.math.ethz.ch/mailman/listinfo/r-help Simon Fear Senior Statistician Syne qua non Ltd Tel: +44 (0) 1379 69 Fax: +44 (0) 1379 65 email: [EMAIL PROTECTED] web: http://www.synequanon.com Number of attachments included with this message: 0 This message (and any associated files) is confidential and\...{{dropped}} __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] adjacency matrix
Dear R experts, I am new to the list and R software. I need to convert arcview file to Winbugs having R has middle package. Got from friends that it is possible following the steps: 1. Converting arcview shapefile to cgm clear text file 2. Downloading convert.r to into R 2.1 use source(convert.r) 2.2 convert(filename_cgm) without the extension. But that doesn't work, given the following errors: R : Copyright 2003, The R Development Core Team Version 1.8.0 (2003-10-08) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. [Previously saved workspace restored] source(convert.r) convert(transf) Error in file(file, r) : unable to open connection In addition: Warning message: cannot open file `transf.cgm' --- Have i done some mistakes?Or i am missing some files? Please assist. Rgs, Orlando. [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] aliases for R constructs?
Some related suggestions: 1. instead of dataFrame[condition, ], use subset() which has an inbuilt test for !is.na(condition). This function is not documented in the Introduction or cross-referenced by ?[, so should be posted to this list at least once a week until everybody knows about it. (Sorry Martin M. that I still have not done what I promised re documentation. The ink has faded so much on the sticky reminder that I can't read it any more.) 2. consider using an editor with definable keyboard macros. There's nothing quicker, or easier to debug, than plain old, bottom level !is.na, but you can get there by typing F1 if you set it up that way. 3. I have a very old brown-covered book describing macros in the S language (version 1? I don't have it to hand to check). When and why did they disappear? (Hoping John Chambers is reading this.) -Original Message- From: Thomas Lumley [mailto:[EMAIL PROTECTED] Sent: 20 October 2003 23:03 To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: [R] aliases for R constructs? Security Warning: If you are not sure an attachment is safe to open please contact Andy on x234. There are 0 attachments with this message. On Mon, 20 Oct 2003 [EMAIL PROTECTED] wrote: Hi Folks, My recent response to Laura Quinn's query about matrix subsetting reminded of a question. I wrote: iDir - ((Winds[,20]45)|(Winds[,20]315))(!is.na(Winds[,20])) Now, I find !is.na a bit awkward to type, so I might prefer to type it as nis.na. While it is possible to define nis.na - function(x){ !is.na(x) } this involves a slight bloat of overhead in execution since achieving !is.na involves an extra layer of function call. So is it possible to define an alias so that nis.na(x) is _exactly_ equivalent to !is.na(x) No, R doesn't have macros. As R is interpreted, a macro wouldn't necessarily save you any execution time -- Lisp macros, IIRC, are only expanded at compile-time. You can get most of the programming advantages of macros with substitute and eval, but this is presumably slower rather than faster. -thomas __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help Simon Fear Senior Statistician Syne qua non Ltd Tel: +44 (0) 1379 69 Fax: +44 (0) 1379 65 email: [EMAIL PROTECTED] web: http://www.synequanon.com Number of attachments included with this message: 0 This message (and any associated files) is confidential and\...{{dropped}} __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Help with STL function in R compared to S-Plus
I am trying to understand the nuances of STL (seasonal trend decomposition with loess) based on William Cleveland's (and others?) original development. I do not understand the specification or use of frequency components or equivalent low-pass filter components in the stl() function. I have run the stl() function on a standard example data (co2) in both S-Plus and in R version 1.8 and the stacked-panel plots are different. The R version shows only rawdata, seasonal, (long-term) trend and then remainder (residual). The S-Plus version of the plot shows in addition plots for the specified frequency components. Why ? In both versions of stl() the user specifies a univariate time series, and the length of window for a seasonal component, a trend component and one or more frequency (or low-pass filter) component(s). Using the data co2 as example, the S-Plus specification is something like: stl(co2, ss.window=17, fc.window=c(101,25), fc.degree=c(1,2))) The near-equivalent specification of stl in R is something like: stl(co2, s.window=17, l.window=c(101,25), l.degree=c(1,2)) The user has the option of selecting multiple frequency components in S-Plus asa concatenation of values, as: fc.window =c(101,25) as the S-Plus stl help page example shows. It is NOT clear if such a specification actually works in the R implementation of stl(), although summary() of the stl output object shows that the values are entered and stored in the routine. Can anyone help explain the use and tuning of frequency components in S-Plus version of STL and the parallel low-pass filter components in R ? the RESULTS of specified frequency components show up in the stl.plot in S-Plus as additional plot panels, whereas the low-pass filter results do not! Only the raw-data, then seasonal, then trend, and finally residuals plots are stacked up. This is what confuses me the most: why the same routine from Wm. Cleveland and same named function would show 2 different results and plot formats in S-Plus vs R. Thanks very much for any help with this matter. Aloha from Hawaii, Andy White email: [EMAIL PROTECTED]; [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] non linear regression with R
Have you considered nls or optim? My way of handling this kind of problem is to assume that x and / or y follow some probability distribution with parameters a and b. Then I write a function to compute deviance = (-2*log(likelihood)) = (-2*log(probability density for x and / or y given a and b)) and feed it to optim to minimize this deviance. Or if the response variable is a nonlinear model plus independent normal errors with constant variance, I may use nls. hope this helps. spencer graves Sophie Gerber wrote: Dear Colleagues, I have x, y data (pollen and seed dispersal from oaks !) that I would like to fit with a function which look like this: p(a,b,x,y)=b/(2*pi*a²gamma(2/b))*exp(-(square_root(x²+y²)/a)power(b)) I am looking for a and b values that fit my data at best. Can someone give me hints to perform such an analysis with R ? Thanks a lot Sophie Sophie Gerber [EMAIL PROTECTED] INRA - UMR BIOGECO 69 route d'Arcachon tel (33) (0)5 57 12 28 30 33612 Cestas cedexfax (33) (0)5 57 12 28 81 http://www.pierroton.inra.fr/genetics/Perso/Sophie/ page_sophie_english.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] non linear regression with R
Your function is not quite complete -- you need to specify an error distribution such as Poisson or negative binomial (see literature from the past decade by J. Clark, Muller-Landau, Ribbens and others) Assuming Poisson errors, if x and y are locations and d is observed density: f - function(p) { a - p[1] b - p[2] r - sqrt(x^2+y^2) exp.dens = b/(2*pi*a^2*gamma(2/b))*exp(-(r/a)^b) lik = -sum(dpois(d,exp.dens,log=TRUE)) } optim(fn=f,par=(a vector of reasonable starting values)) I see from my e-mail that Spencer Graves has just replied to this message too so I'll go see what he wrote ... On Wed, 22 Oct 2003, Sophie Gerber wrote: Dear Colleagues, I have x, y data (pollen and seed dispersal from oaks !) that I would like to fit with a function which look like this: p(a,b,x,y)=b/(2*pi*a²gamma(2/b))*exp(-(square_root(x²+y²)/a)power(b)) I am looking for a and b values that fit my data at best. Can someone give me hints to perform such an analysis with R ? Thanks a lot Sophie Sophie Gerber [EMAIL PROTECTED] INRA - UMR BIOGECO 69 route d'Arcachon tel (33) (0)5 57 12 28 30 33612 Cestas cedexfax (33) (0)5 57 12 28 81 http://www.pierroton.inra.fr/genetics/Perso/Sophie/ page_sophie_english.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help -- 620B Bartram Hall[EMAIL PROTECTED] Zoology Department, University of Floridahttp://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Latex and R
Hi all! Is there a possibility to read Latex-formulas directly into R, e.g. to read c=\frac{a}{b} such that R knows that c- a/b is meant? I wish to generate some numerical examples of a theoretical model with R (and also to generate some plots) and I find it exhausting to translate my model into a R-code. Thanks in advance Salva Thanks in advancesalvatore barbaro department of public economics platz der göttinger sieben 3 37073 göttingen tel.: +49 551 3919704 fax: +49 551 39 7353 http://www.gwdg.de/~sbarbar __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] aliases for R constructs?
Simon Fear wrote: 3. I have a very old brown-covered book describing macros in the S language (version 1? I don't have it to hand to check). When and why did they disappear? (Hoping John Chambers is reading this.) Pretty much the same reason that you don't grind your flour by hand with a stone. Patrick Burns Burns Statistics [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and A Guide for the Unwilling S User) __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] Help with STL function in R compared to S-Plus
On Wed, 22 Oct 2003, Andrew White wrote: I am trying to understand the nuances of STL (seasonal trend decomposition with loess) based on William Cleveland's (and others?) original development. I do not understand the specification or use of frequency components or equivalent low-pass filter components in the stl() function. Have you read the original paper? -- I found it helped. I have run the stl() function on a standard example data (co2) in both S-Plus and in R version 1.8 and the stacked-panel plots are different. The R version shows only rawdata, seasonal, (long-term) trend and then remainder (residual). The S-Plus version of the plot shows in addition plots for the specified frequency components. Why ? Not the same function! In both versions of stl() the user specifies a univariate time series, and the length of window for a seasonal component, a trend component and one or more frequency (or low-pass filter) component(s). Using the data co2 as example, the S-Plus specification is something like: stl(co2, ss.window=17, fc.window=c(101,25), fc.degree=c(1,2))) The near-equivalent specification of stl in R is something like: stl(co2, s.window=17, l.window=c(101,25), l.degree=c(1,2)) The user has the option of selecting multiple frequency components in S-Plus asa concatenation of values, as: fc.window =c(101,25) as the S-Plus stl help page example shows. It is NOT clear if such a specification actually works in the R implementation of stl(), although summary() of the stl output object shows that the values are entered and stored in the routine. Can anyone help explain the use and tuning of frequency components in S-Plus version of STL and the parallel low-pass filter components in R ? the RESULTS of specified frequency components show up in the stl.plot in S-Plus as additional plot panels, whereas the low-pass filter results do not! Only the raw-data, then seasonal, then trend, and finally residuals plots are stacked up. This is what confuses me the most: why the same routine from Wm. Cleveland and same named function would show 2 different results and plot formats in S-Plus vs R. It's not the same routine. The R one is the one taken from the R reference, and I don't know what exactly is in S-PLUS but it is not the same code. Thanks very much for any help with this matter. Aloha from Hawaii, Andy White -- 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 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] High frequency time-series
Having to collect hourly electricity loads and quarter-of-an-hour electricity production data for some years I think that the tidiest way of doing it is to resort to ts but I don't know how to define such a frequency starting from a set date. Leafing through r-help mail archives I've found this *ALMOST* satisfactory message: == . I have a series of hourly rainfall and quarterly flow measurements (i.e. 4 times an hour) of a catchment Maybe time series are easier, but in ts(data = NA, start = X,... X should be a number or a vector. how does this coresponds to a data and hour (e.g. april 26,2002, 15:00:00)? If your observations are equidistant, e.g. you've got 24 hourly measurements per day, you could do something like this for the above example: R rain - ts(rain, start = c(26, 15), freq = 24) R flow - ts(flow, start = c(26, 15), freq = 96) ... But how does R know that we are speaking of a timeseries starting from April 26, 2002 and not, say, Feb 26, 2000? There's some piece of info missing in the answer. Am I correct? Please help. Ciao from Rome Vittorio __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] adjacency matrix
On Wed, 22 Oct 2003, Orlando Zacarias wrote: Dear R experts, I am new to the list and R software. I need to convert arcview file to Winbugs having R has middle package. Got from friends that it is possible following the steps: 1. Converting arcview shapefile to cgm clear text file 2. Downloading convert.r to into R 2.1 use source(convert.r) 2.2 convert(filename_cgm) without the extension. But that doesn't work, given the following errors: R : Copyright 2003, The R Development Core Team Version 1.8.0 (2003-10-08) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. [Previously saved workspace restored] source(convert.r) convert(transf) Error in file(file, r) : unable to open connection In addition: Warning message: cannot open file `transf.cgm' --- This is quite a narrow question based on other people knowing that you are refering to: http://www.biostat.umn.edu/~yuecui/ and the file you have downloaded from there. The most typical cause of files not being found is when you are not in the correct working directory. Use: getwd() to access the directory name, and list.files() to see if the name of your *.cgm file is returned. The key comment in the web page you must have used is: Open Splus or R under the folder in which convert.s is saved but even if you start in another folder, you can change the R working directory using setwd(where_I_want_to_be) or from the File menu. Have i done some mistakes?Or i am missing some files? Please assist. Rgs, Orlando. [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Breiviksveien 40, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93 e-mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] Patches for DBI/RMySQL valueClass problem?
Hi, I think yesterday's email from M.Kondrin's [EMAIL PROTECTED] summarizes two alternatives (1 and 2 below); of course you can also use R-1.7.1. To recap, I think you have 3 easy choices (at least): (1) install R-patched from ftp://ftp.stat.math.ethz.ch/Software/R/R-patched.tar.gz (2) Or add the line export(.valueClassTest) to the file $R_HOME/src/library/methods/NAMESPACE (where $R_HOME is the directory where you installed R-1.8.0) (3) Or revert back to R 1.7.1 Hope this helps, -- David Barnet Wagman wrote: According David Jame's response to my earlier question, there is a problem with setGeneric.setMethod in R 1.8.0 that affects DBI and RMySQL. Is there a fix for this? David Jame's refers to an 'R-patched version' but I haven't seen anything like this on CRAN. Would going back to an older version of R solve the problem? Thanks, Barnet Wagman David James wrote: However, there is a problem in the released version of R 1.8.0 that affects the DBI and other packages (has something to do with methods that use the valueClass argument in the setGeneric/setMethod functions). In this case one needs to use the R-patched version. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] adjacency matrix
Your question is not really clear because: - I don't know what 'convert.r' do - I don't know where 'transf.cgm' is (BTW, 'cgm' is not the usual extension for shapefiles which is 'shp'). Check if it is really in your current directory. but, yes, if what you want is to import shapefiles in R, it's easy. Look at the 'maptools' package on CRAN (there is also a 'shapefiles' package). And if you want to build an adjacency matrix for a map of polygons (as I guess from the header of you mail), look at the 'spdep' package, too. It is then possible to write a text file with your data as a list readable by WinBUGS. (I send a copy of my answer to the the R-SIG-GEO mailing list which can be of interest to you). Hope it helps. Christophe -- Christophe DECLERCQ, MD Observatoire Régional de la Santé Nord-Pas-de-Calais 13, rue Faidherbe 59046 LILLE Cedex FRANCE Phone +33 3 20 15 49 24 Fax +33 3 20 55 92 30 E-mail [EMAIL PROTECTED] -Message d'origine- De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] la part de Orlando Zacarias Envoyé : mercredi 22 octobre 2003 11:58 À : [EMAIL PROTECTED] Objet : [R] adjacency matrix Dear R experts, I am new to the list and R software. I need to convert arcview file to Winbugs having R has middle package. Got from friends that it is possible following the steps: 1. Converting arcview shapefile to cgm clear text file 2. Downloading convert.r to into R 2.1 use source(convert.r) 2.2 convert(filename_cgm) without the extension. But that doesn't work, given the following errors: R : Copyright 2003, The R Development Core Team Version 1.8.0 (2003-10-08) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. [Previously saved workspace restored] source(convert.r) convert(transf) Error in file(file, r) : unable to open connection In addition: Warning message: cannot open file `transf.cgm' --- Have i done some mistakes?Or i am missing some files? Please assist. Rgs, Orlando. [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] Excel to R
Indeed, keeping the computations in R and working directly with the Excel view of the cells is desirable for generality. It minimizes the loss in information from translating to simpler forms such as CSV, strings, etc. From within R on Windows, one can use DCOM to create an Excel application, load the file and then read each of the worksheets in the workbook cell by cell and obtain all sorts of information about each cell. The RDCOMClient package on the Omegahat Web site (http://www.omegahat.org/RDCOMClient) and Thomas Baier's rcom package provide the DCOM facilities from R. David James has already done some work to process Excel Worksheet and Range objects using the RDCOMClient and create R data frames. And there is C code in the GGobi distribution which does something very similar. D. Gabor Grothendieck wrote: I have Excel files containing data that I would like to move to R. They are in the standard form of a one row header followed by rows of data, one record per row EXCEPT that there are a few rows of comments before the header. The number of rows of comments varies. For Excel files of this form without comments I have had success with: require(RODBC) z - odbcConnectExcel(C:/myspread.xls) z.df - sqlFetch(z,Sheet1) close(z) but the comments interfere with this. I don't want to manually delete the rows but want the entire process from Excel file to R to be automatic. I can accomplish this with a free utility, Baird's dataload that I found on the net. This will convert the Excel files to text and then the text can be processed using R to locate the start of the header and only process the remainder of the file. (There is also another free utility called xlhtml that I don't use, but could have, that does this too.) Thus at this point I have an adequate automated solution. Nevertheless, I was wondering, for sake of interest, if there is some solution in R that does not involve such an external program such as dataload or xlhtml. Thanks. (I am using Windows 2000.) ___ No banners. No pop-ups. No kidding. Introducing My Way - http://www.myway.com __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help -- ___ Duncan Temple Lang[EMAIL PROTECTED] Bell Labs, Lucent Technologiesoffice: (908)582-3217 700 Mountain Avenue, Room 2C-259 fax:(908)582-3340 Murray Hill, NJ 07974-2070 http://cm.bell-labs.com/stat/duncan __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] 0-only-rows in correspondence analysis
Hello, I am looking for a workaround of species empty plots in a correspondence analysis. I tried to do a community structure analysis with a ca via decorana(), ca() and CAIV(), but none of them allow 0 only-rows. I have species (abs./pres) in columns and sites in rows sp1 sp1 sp3 ... plot1 01 1 plot2 000 plot3 10 1 . but on some plots no species could be found, therefore only 0 appear. I know that this isn't interesting for a community analysis but I am interested in the contributions of variables to the factors for a further analysis with env. variables where it is interesting that there are no species found. i thought about adding a dummy species with only presence on all sites, that would solve the 0-only-row problem but I am not sure if that would bias the outcome of a ca seriously. Or is there a subcommand to allow 0 rows in a ca which I haven't seen? thnaks Martin __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] aliases for R constructs?
On Wed, 22 Oct 2003, Patrick Burns wrote: Simon Fear wrote: 3. I have a very old brown-covered book describing macros in the S language (version 1? I don't have it to hand to check). When and why did they disappear? (Hoping John Chambers is reading this.) Pretty much the same reason that you don't grind your flour by hand with a stone. Well, many very civilised languages have macros (not the #define things, but ones that work on parsed expressions). Lazy evaluation lets us do most of the same things, but not all. If we had a compiler there would probably be more interest in macros, as then there would be a distinction between compile-time and run-time evaluation. -thomas __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] Patches for DBI/RMySQL valueClass problem?
Thank you. The copy of M.Kondrin's email that I received was truncated, so I don't know what he suggested. This should get me going. Regards, Barnet Wagman David James wrote: Hi, I think yesterday's email from M.Kondrin's [EMAIL PROTECTED] summarizes two alternatives (1 and 2 below); of course you can also use R-1.7.1. To recap, I think you have 3 easy choices (at least): (1) install R-patched from ftp://ftp.stat.math.ethz.ch/Software/R/R-patched.tar.gz (2) Or add the line export(.valueClassTest) to the file $R_HOME/src/library/methods/NAMESPACE (where $R_HOME is the directory where you installed R-1.8.0) (3) Or revert back to R 1.7.1 Hope this helps, -- David Barnet Wagman wrote: According David Jame's response to my earlier question, there is a problem with setGeneric.setMethod in R 1.8.0 that affects DBI and RMySQL. Is there a fix for this? David Jame's refers to an 'R-patched version' but I haven't seen anything like this on CRAN. Would going back to an older version of R solve the problem? Thanks, Barnet Wagman David James wrote: However, there is a problem in the released version of R 1.8.0 that affects the DBI and other packages (has something to do with methods that use the valueClass argument in the setGeneric/setMethod functions). In this case one needs to use the R-patched version. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] High frequency time-series
You may find the irregular time-series (its) package on CRAN helpful. If your raw data were in a csv file thus: x april 26 2002 15:00:00 1.1 april 26 2002 15:15:00 1.2 april 26 2002 15:30:00 1.3 april 26 2002 15:45:00 1.4 Then you could read it in thus: require(its) its.format(%B %d %Y %H:%M:%S) x - its(readcsvIts(c:/temp/mydata.csv)) If on the other hand you already have the times in POSIX form, it is slightly simpler e.g. x - its(xmat,POSIXdate) Giles -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: 22 October 2003 14:10 To: r-help r-help Subject: [R] High frequency time-series Having to collect hourly electricity loads and quarter-of-an-hour electricity production data for some years I think that the tidiest way of doing it is to resort to ts but I don't know how to define such a frequency starting from a set date. Leafing through r-help mail archives I've found this *ALMOST* satisfactory message: == . I have a series of hourly rainfall and quarterly flow measurements (i.e. 4 times an hour) of a catchment Maybe time series are easier, but in ts(data = NA, start = X,... X should be a number or a vector. how does this coresponds to a data and hour (e.g. april 26,2002, 15:00:00)? If your observations are equidistant, e.g. you've got 24 hourly measurements per day, you could do something like this for the above example: R rain - ts(rain, start = c(26, 15), freq = 24) R flow - ts(flow, start = c(26, 15), freq = 96) ... But how does R know that we are speaking of a timeseries starting from April 26, 2002 and not, say, Feb 26, 2000? There's some piece of info missing in the answer. Am I correct? Please help. Ciao from Rome Vittorio __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help ** This is a commercial communication from Commerzbank AG.\ \ T...{{dropped}} __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] High frequency time-series
On Wednesday 22 October 2003 15:09, [EMAIL PROTECTED] wrote: Having to collect hourly electricity loads and quarter-of-an-hour electricity production data for some years I think that the tidiest way of doing it is to resort to ts but I don't know how to define such a frequency starting from a set date. Leafing through r-help mail archives I've found this *ALMOST* satisfactory message: == . I have a series of hourly rainfall and quarterly flow measurements (i.e. 4 times an hour) of a catchment Maybe time series are easier, but in ts(data = NA, start = X,... X should be a number or a vector. how does this coresponds to a data and hour (e.g. april 26,2002, 15:00:00)? If your observations are equidistant, e.g. you've got 24 hourly measurements per day, you could do something like this for the above example: R rain - ts(rain, start = c(26, 15), freq = 24) R flow - ts(flow, start = c(26, 15), freq = 96) ... But how does R know that we are speaking of a timeseries starting from April 26, 2002 and not, say, Feb 26, 2000? There's some piece of info missing in the answer. Two possibilities: - ts(): you can just have a single number which counts the time unit. So you have to do that in a unique way. Either by convention or e.g. by augmenting the ts object by an additional attribute which gives the start date or something in that direction. - irts(): this is a function for definin irregularly spaced time series and it's available in the package tseries. The time attribute is a vector of POSIXct times. This is more flexible in some sense, but requires the storage of more information. Furthermore, you have more functions around which can compute objects of interest based on ts object than on irts objects. hth, Z Am I correct? Please help. Ciao from Rome Vittorio __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] 0-only-rows in correspondence analysis
CA is based on relative composition and not on absolute value. So, empty site do not give any information. In a computational point of view, empty row or column do not allow to compute row / col weights. that is why most function do not work with empty row or column. dudi.coa (ade4 package) allows empty rows or columns. They are simply put at the centroid (and so have no weight in the analysis). CA do not take into acccount the information given by empty site !!! If you want that the information given by empty site are taken into account, you should prefer an other analysis (e.g. pca). Sincerely, At 10:09 22/10/2003, you wrote: Hello, I am looking for a workaround of species empty plots in a correspondence analysis. I tried to do a community structure analysis with a ca via decorana(), ca() and CAIV(), but none of them allow 0 only-rows. I have species (abs./pres) in columns and sites in rows sp1 sp1 sp3 ... plot1 01 1 plot2 000 plot3 10 1 . but on some plots no species could be found, therefore only 0 appear. I know that this isn't interesting for a community analysis but I am interested in the contributions of variables to the factors for a further analysis with env. variables where it is interesting that there are no species found. i thought about adding a dummy species with only presence on all sites, that would solve the 0-only-row problem but I am not sure if that would bias the outcome of a ca seriously. Or is there a subcommand to allow 0 rows in a ca which I haven't seen? thnaks Martin __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] comments and Sweave
I am using Sweave to produce handouts for teaching. Is there a way of making Sweave keep the comments following the `#' in the code chuncks? Thanks, Giovanni -- __ [ ] [ 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 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Weighted Clustering
Hi, I have a data set(say 2-d demands of a product (say flow-rate vs concentration)) and with each demand is the weightage (like a probability) of that demand occuring. Is there a way to cluster this demand-data (deterministic or probabilistic(if possible)) which also incorporates the weights (just multiplying distances with weights gives poor and mixed clusters) while clustering (Something like a Facility Location problem). I would appreciate any advice. Regards Vishal Goyal -- Simplicity is the ultimate sophistication --- Vishal Goyal, Graduate Student Department of Chemical and Biochemical Engineering Rutgers - The State University of New Jersey 98 Brett Road, Piscataway, NJ 08854 tel: 732-445-7061 (O) email: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Scheme and R
I have been using a product called rpy to allow me to access R from Python. I was wondering if anybody know if a similar product for Scheme. Thanks, Arend __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] output in a list
Hello. I've got a very short question. I've got a vector with about 800 numbers; and I would like to put them in a file, but I need them to be written just one value in each row. Is this possible? Best regards Javier __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] output in a list
javier garcia - CEBAS [EMAIL PROTECTED] writes: I've got a very short question. I've got a vector with about 800 numbers; and I would like to put them in a file, but I need them to be written just one value in each row. Is this possible? write(myvec, file = 'myfile.txt', ncol = 1) __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] INDEX file building packages?
Hi! Have build a package. I do not create by myself an INDEX file. If I got it right it is optional. If no INDEX are there it is created during the installation process.(So I understand the manual.) I call R CMD INSTALL mytest .. But no INDEX file are generated. Hence no function list are displayed when calling help(package=mytest). There are some warnings during the compilation of the Rd files but no errors. The html documentation and platform specific documentation stuff are generated from Rd files. Eryk. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] output in a list
On Wed, 22 Oct 2003, javier garcia - CEBAS wrote: Hello. I've got a very short question. I've got a vector with about 800 numbers; and I would like to put them in a file, but I need them to be written just one value in each row. Is this possible? Yes. ?write tells you one way. -- 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 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] providing a variable as a parameter in a function
From a data frame, how do we extract a specific column name, and plug that into a command (eg. for Anova as shown below) df = read.delim(mydata.txt) y = colnames(df) r = ncol(x) Lets say that in the data frame column 1 contains treatments, column 2 contains doses, and columns 3, 4, 5 etc. are different responses, and I want to run separate 2-way anovas for each response, i.e. my first anova will be done using col 1: Treatment, col 2: Dose and Col 3: a response, second anova will be done using treatment (col1), dose (col2) and another response (col 4) and so on. I could use a loop to automate the task. for (i in 3:r) { + mod = lm(y[i]~Trt*Dose, data = x, contrasts = list(Trt = contr.sum, Dose = contr.sum)) + Anova(mod, type = III) + } The problem is when I directly plug in y[3] for my response variables name, it gives me an error Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : invalid variable type This is likely because the lm() function wants the actual column name, rather than a variable containing the column name. Can someone advice? Thanks, Karth. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] passing a variable (containing the value of the argument) to a function
My previous question put in a simpler way: How would I pass a value of a variable to a function such as lm(Effect1~Trt*Dose, data = x, contrasts = list(Trt = contr.sum, Dose = contr.sum))? Here, 'Effect' is a column name in my data matrix, and I want Effect1 to be replaced by Effect2 and so on (my other column names in the data frame) for successive anova calculations. So I am storing the column names as an array, and passing the array as a parameter to the lm() function. Thanks, - Forwarded by Subramanian Karthikeyan/HC-SC/GC/CA on 2003-10-22 01:47 PM - Subramanian Karthikeyan To: [EMAIL PROTECTED] cc: 2003-10-22 01:31 Subject: providing a variable as a parameter in a function PM From a data frame, how do we extract a specific column name, and plug that into a command (eg. for Anova as shown below) df = read.delim(mydata.txt) y = colnames(df) r = ncol(x) Lets say that in the data frame column 1 contains treatments, column 2 contains doses, and columns 3, 4, 5 etc. are different responses, and I want to run separate 2-way anovas for each response, i.e. my first anova will be done using col 1: Treatment, col 2: Dose and Col 3: a response, second anova will be done using treatment (col1), dose (col2) and another response (col 4) and so on. I could use a loop to automate the task. for (i in 3:r) { + mod = lm(y[i]~Trt*Dose, data = x, contrasts = list(Trt = contr.sum, Dose = contr.sum)) + Anova(mod, type = III) + } The problem is when I directly plug in y[3] for my response variables name, it gives me an error Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : invalid variable type This is likely because the lm() function wants the actual column name, rather than a variable containing the column name. Can someone advice? Thanks, Karth. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] comments and Sweave
Hi, I asked exactly the same question to the author of Sweave privately last week. Friedrich's reply was that it is not possible at the moment, as R parser discard the comments. But he's working on it ;-D On Wed, 22 Oct 2003, Giovanni Petris wrote: Date: Wed, 22 Oct 2003 10:59:38 -0500 (CDT) From: Giovanni Petris [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: [R] comments and Sweave I am using Sweave to produce handouts for teaching. Is there a way of making Sweave keep the comments following the `#' in the code chuncks? Thanks, Giovanni -- Cheers, Kevin --- Ko-Kang Kevin Wang Master of Science (MSc) Student SLC Tutor and Lab Demonstrator Department of Statistics University of Auckland New Zealand Homepage: http://www.stat.auckland.ac.nz/~kwan022 Ph: 373-7599 x88475 (City) x88480 (Tamaki) __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] INDEX file building packages?
On Wed, 22 Oct 2003, Eryk Wolski wrote: Hi! Have build a package. I do not create by myself an INDEX file. If I got it right it is optional. If no INDEX are there it is created during the installation process.(So I understand the manual.) I call R CMD INSTALL mytest .. But no INDEX file are generated. Hence no function list are displayed when calling help(package=mytest). There are some warnings during the compilation of the Rd files but no errors. The html documentation and platform specific documentation stuff are generated from Rd files. R CMD build --force should do it. Eryk. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Breiviksveien 40, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93 e-mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] providing a variable as a parameter in a function
Dear Subramanian, How about this: for (y in df[, 3:5]) { mod = lm(y ~ Trt*Dose, data = x, contrasts = list(Trt = contr.sum, Dose = contr.sum)) Anova(mod, type = III) } Does that give you what you want? John At 01:31 PM 10/22/2003 -0400, Subramanian Karthikeyan wrote: From a data frame, how do we extract a specific column name, and plug that into a command (eg. for Anova as shown below) df = read.delim(mydata.txt) y = colnames(df) r = ncol(x) Lets say that in the data frame column 1 contains treatments, column 2 contains doses, and columns 3, 4, 5 etc. are different responses, and I want to run separate 2-way anovas for each response, i.e. my first anova will be done using col 1: Treatment, col 2: Dose and Col 3: a response, second anova will be done using treatment (col1), dose (col2) and another response (col 4) and so on. I could use a loop to automate the task. for (i in 3:r) { + mod = lm(y[i]~Trt*Dose, data = x, contrasts = list(Trt = contr.sum, Dose = contr.sum)) + Anova(mod, type = III) + } The problem is when I directly plug in y[3] for my response variables name, it gives me an error Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : invalid variable type This is likely because the lm() function wants the actual column name, rather than a variable containing the column name. Can someone advice? Thanks, Karth. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help John Fox Department of Sociology McMaster University email: [EMAIL PROTECTED] web: http://www.socsci.mcmaster.ca/jfox __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] select text using only the keyboard
Simon Fear wrote: I have a different wish: I want to be able to mouseclick in the middle of a line to get the cursor there (as in SPlus). While I appreciate that to get my wish I should just write a little patch, I estimate it would take me about 2 years to reach the point where I was capable of it, assuming I did nothing else, and I would certainly have to understand Windows, which in previous brushes I have found to be very bad for the brain. Or you could get a copy of (X)Emacs, and use ESS. Total install and learning warm-up time should be in the order of a week at most. It does all these nice things, and much more. In my short experience with it, XEmacs plays nicer with ESS under Windows than GNU Emacs - YMMV. Cheers Jason -- Indigo Industrial Controls Ltd. http://www.indigoindustrial.co.nz 64-21-343-545 [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] How to reformat data from database into data.frame?
I'm trying to find a clever way to re-map data from a database query into a data.frame. Querying a database often returns a table (data.frame) like this: GeneID MethodID Value 61 123 62 456 63 987 71 234 73 432 82 190 83 34 81 864 Note that GeneID=7 doesn't have a value for MethodID=2. Note that GeneID=8 doesn't have the MethodID in any particular order and, in fact, there doesn't need to be an order to the GeneID, although I can force ordering as part of my SQL query. I want to reformat this into a data.frame with multiple columns: Value Value Value GeneID Method1 Method2 Method3 6 123 456 987 7 234 NA432 8 864 190 34 Is there an elegant way to do this type of reformating in R? Thanks. Mark -- Mark Dalphin email: [EMAIL PROTECTED] Mail Stop: 29-2-A phone: +1-805-447-4951 (work) One Amgen Center Drive +1-805-375-0680 (home) Thousand Oaks, CA 91320 fax: +1-805-499-9955 (work) __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] providing a variable as a parameter in a function
Thanks John, Your solution worked.. After i posted my message I tried sth else which also worked... I tried this: for (i in 3:cnum) { fla = as.formula(paste((cnom[i],~,Trt*Dose)) mod = lm(fla, data = x, contrasts = list(Trt = contr.sum, Dose = contr.sum)) an = Anova(mod,type = III) print(an) } but yours is a succint and nice solution. Thanks again, Karth. John Fox [EMAIL PROTECTED]To: Subramanian Karthikeyan [EMAIL PROTECTED] cc: [EMAIL PROTECTED] Subject: Re: [R] providing a variable as a parameter in a function 2003-10-22 02:24 PM Dear Subramanian, How about this: for (y in df[, 3:5]) { mod = lm(y ~ Trt*Dose, data = x, contrasts = list(Trt = contr.sum, Dose = contr.sum)) Anova(mod, type = III) } Does that give you what you want? John At 01:31 PM 10/22/2003 -0400, Subramanian Karthikeyan wrote: From a data frame, how do we extract a specific column name, and plug that into a command (eg. for Anova as shown below) df = read.delim(mydata.txt) y = colnames(df) r = ncol(x) Lets say that in the data frame column 1 contains treatments, column 2 contains doses, and columns 3, 4, 5 etc. are different responses, and I want to run separate 2-way anovas for each response, i.e. my first anova will be done using col 1: Treatment, col 2: Dose and Col 3: a response, second anova will be done using treatment (col1), dose (col2) and another response (col 4) and so on. I could use a loop to automate the task. for (i in 3:r) { + mod = lm(y[i]~Trt*Dose, data = x, contrasts = list(Trt = contr.sum, Dose = contr.sum)) + Anova(mod, type = III) + } The problem is when I directly plug in y[3] for my response variables name, it gives me an error Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : invalid variable type This is likely because the lm() function wants the actual column name, rather than a variable containing the column name. Can someone advice? Thanks, Karth. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help John Fox Department of Sociology McMaster University email: [EMAIL PROTECTED] web: http://www.socsci.mcmaster.ca/jfox __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] passing a variable (containing the value of the argument) to a function
Subramanian Karthikeyan [EMAIL PROTECTED] writes: My previous question put in a simpler way: How would I pass a value of a variable to a function such as lm(Effect1~Trt*Dose, data = x, contrasts = list(Trt = contr.sum, Dose = contr.sum))? Here, 'Effect' is a column name in my data matrix, and I want Effect1 to be replaced by Effect2 and so on (my other column names in the data frame) for successive anova calculations. So I am storing the column names as an array, and passing the array as a parameter to the lm() function. A canonical trick is for (myname in names(myframe)){ mycall - substitute(lm(myvar~etc.etc.),list(myvar=as.name(myname))) myfit - eval(mycall) print(summary(myfit)) } -- 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 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] select text using only the keyboard
Simon Fear [EMAIL PROTECTED] writes: While I appreciate that to get my wish I should just write a little patch, I estimate it would take me about 2 years to reach the point where I was capable of it, assuming I did nothing else, and I would certainly have to understand Windows, which in previous brushes I have found to be very bad for the brain. Now that actually goes for most members of R core as well, so the question is really whose brain you'd want to preserve. I can live without it. Well *you* said it! ;-) -- 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 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] How to reformat data from database into data.frame?
Assuming your input data frame is genes: reshape(genes,idvar=GeneID,timevar=MethodID,direction=wide) --- On Wed 10/22, Mark Dalphin [EMAIL PROTECTED] wrote: From: Mark Dalphin [mailto: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Date: Wed, 22 Oct 2003 12:05:44 -0700 Subject: [R] How to reformat data from database into data.frame? I'm trying to find a clever way to re-map data from a databasebrquery into a data.frame.brbrQuerying a database often returns a table (data.frame) like this:brbrGeneIDMethodID Valuebr6 1 123br6 2 456br6 3 987br7 1 234br7 3 432br8 2 190br8 3 34br8 1 864 brbrNote that GeneID=7 doesn't have a value for MethodID=2.brbrNote that GeneID=8 doesn't have the MethodID in any particular orderbrand, in fact, there doesn't need to be an order to the GeneID, althoughbrI can force ordering as part of my SQL query.brbrI want to reformat this into a data.frame with multiple columns:brbr ValueValue ValuebrGeneID Method1 Method2 Method3br6 123 456 987br7 234 NA432br8 864 190 34brbrIs there an elegant way to do this type of reformating in R?brbrThanks.brMarkbrbr-- brMark Dalphin email: [EMAIL PROTECTED] mgen.combrMail Stop: 29-2-A phone: +1-805-447-4951 (work)brOne Amgen Center Drive +1-805-375-0680 (home)brThousand Oaks, CA 91320 fax: +1-805-499-9955 (work)brbr__br[EMAIL PROTECTED] mailing listbrhttps://www.stat.math.ethz.ch/mailman/listinfo/r-helpbr ___ No banners. No pop-ups. No kidding. Introducing My Way - http://www.myway.com __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] passing a variable (containing the value of the argument) to a function
Hi, Peter: How does that compare with the following: for (myname in names(myframe)[1:4]){ mdl - formula(paste(myname, ~ etc.etc)) myfit - lm(mdl, data=myframe) print(summary(myfit)) } Or: for (myname in names(myframe)[1:4]){ lm.txt - paste(lm(, myname, ~ etc.etc, data=myframe)) myfit - eval(parse(text=lm.txt)) print(summary(myfit)) } You are teaching me new uses of substitute, and I just wonder about the relative advantages and disadvantages of the different approaches. Thanks, spencer graves Peter Dalgaard wrote: Subramanian Karthikeyan [EMAIL PROTECTED] writes: My previous question put in a simpler way: How would I pass a value of a variable to a function such as lm(Effect1~Trt*Dose, data = x, contrasts = list(Trt = contr.sum, Dose = contr.sum))? Here, 'Effect' is a column name in my data matrix, and I want Effect1 to be replaced by Effect2 and so on (my other column names in the data frame) for successive anova calculations. So I am storing the column names as an array, and passing the array as a parameter to the lm() function. A canonical trick is for (myname in names(myframe)){ mycall - substitute(lm(myvar~etc.etc.),list(myvar=as.name(myname))) myfit - eval(mycall) print(summary(myfit)) } __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] passing a variable (containing the value of the argument) to a function
Spencer Graves [EMAIL PROTECTED] writes: Hi, Peter: How does that compare with the following: for (myname in names(myframe)[1:4]){ mdl - formula(paste(myname, ~ etc.etc)) myfit - lm(mdl, data=myframe) print(summary(myfit)) } Or: for (myname in names(myframe)[1:4]){ lm.txt - paste(lm(, myname, ~ etc.etc, data=myframe)) myfit - eval(parse(text=lm.txt)) print(summary(myfit)) } You are teaching me new uses of substitute, and I just wonder about the relative advantages and disadvantages of the different approaches. Thanks, spencer graves Those variants should work (and similar code is all over the place in the modelling functions). I just tend to prefer to avoid going via the textual representation. There are a couple of devils lurking in there, in particular if a data frame has variables with funny names - spaces or special characters inside, for example. To wit: myname - foo bar lm.txt - paste(lm(, myname, ~ etc.etc, data=myframe)) lm.txt [1] lm( foo bar ~ etc.etc, data=myframe) parse(text=lm.txt) Error in parse(file, n, text, prompt) : parse error -- 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 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] passing a variable (containing the value of the argument) to a function
Hi, Peter: I'll have to study your example and alternatives. spencer graves Peter Dalgaard wrote: Spencer Graves [EMAIL PROTECTED] writes: Hi, Peter: How does that compare with the following: for (myname in names(myframe)[1:4]){ mdl - formula(paste(myname, ~ etc.etc)) myfit - lm(mdl, data=myframe) print(summary(myfit)) } Or: for (myname in names(myframe)[1:4]){ lm.txt - paste(lm(, myname, ~ etc.etc, data=myframe)) myfit - eval(parse(text=lm.txt)) print(summary(myfit)) } You are teaching me new uses of substitute, and I just wonder about the relative advantages and disadvantages of the different approaches. Thanks, spencer graves Those variants should work (and similar code is all over the place in the modelling functions). I just tend to prefer to avoid going via the textual representation. There are a couple of devils lurking in there, in particular if a data frame has variables with funny names - spaces or special characters inside, for example. To wit: myname - foo bar lm.txt - paste(lm(, myname, ~ etc.etc, data=myframe)) lm.txt [1] lm( foo bar ~ etc.etc, data=myframe) parse(text=lm.txt) Error in parse(file, n, text, prompt) : parse error __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] 2 D non-parametric density estimation
I have spatial data in 2 dimensions - say (x,y). The correlation between x and y is fairly substantial. My goal is to use a non-parametric approach to estimate the multivariate density describing the spatial locations. Ultimately, I would like to use this estimated density to determine the area associated with a 95% probability contour for the data. Given the strong correlation between x and y, I have not been real happy w/ the results obtained using kernel density estimators with separate smoothing parameters for the x and y directions - e.g., bkde2D (KernSmooth library), sm (sm library), kde2d (MASS library). It seems to me that a better alternative would be to transform the data to have ~0 correlation, estimate the density, then transform back to the original scale. Does this seem reasonable for this sort of problem? Has anyone written code in R to do this sort of thing? I also attempted to explore local likelihood fitting (using locfit library). I liked the look of the estimated densities, but found it difficult to obtain predictions at an arbitrary set of grid points (as needed to determine a 95% probability contour). Does anyone have examples using locfit w/ the ev option or predict.locfit in order to obtain local likelihood density estimates at an arbitrary set of grid points? Any suggestions would be greatly appreciated! John John Fieberg, Ph.D. Wildlife Biometrician, MN DNR 5463-C W. Broadway Forest Lake, MN 55434 Phone: (651) 296-2704 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] 2 D non-parametric density estimation
John - My recollection is that Adrian Raftery's contributed package 'mclust' does kernel density estimation as well. Not sure whether it does what you need. Take a look at it on CRAN. Ah..I see that the description which shows up on Jon Baron's search page is not encouraging. Give it a try, anyway. That description does not do it justice. - tom blackwell - u michigan medical school - ann arbor - On Wed, 22 Oct 2003, John Fieberg wrote: I have spatial data in 2 dimensions - say (x,y). The correlation between x and y is fairly substantial. My goal is to use a non-parametric approach to estimate the multivariate density describing the spatial locations. Ultimately, I would like to use this estimated density to determine the area associated with a 95% probability contour for the data. Given the strong correlation between x and y, I have not been real happy w/ the results obtained using kernel density estimators with separate smoothing parameters for the x and y directions - e.g., bkde2D (KernSmooth library), sm (sm library), kde2d (MASS library). It seems to me that a better alternative would be to transform the data to have ~0 correlation, estimate the density, then transform back to the original scale. Does this seem reasonable for this sort of problem? Has anyone written code in R to do this sort of thing? I also attempted to explore local likelihood fitting (using locfit library). I liked the look of the estimated densities, but found it difficult to obtain predictions at an arbitrary set of grid points (as needed to determine a 95% probability contour). Does anyone have examples using locfit w/ the ev option or predict.locfit in order to obtain local likelihood density estimates at an arbitrary set of grid points? Any suggestions would be greatly appreciated! John John Fieberg, Ph.D. Wildlife Biometrician, MN DNR 5463-C W. Broadway Forest Lake, MN 55434 Phone: (651) 296-2704 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help