Re: [R] Reading data from a serial port
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Wednesday, 14 September 2005 8:13 AM To: vittorio Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Reading data from a serial port snip Now all this of course is written in terms of a Linux system, and we don't know yet what sort of system you are using. On Windows, I find one can navigate by hand through My Computer - Control Panel - System - Device Manager - Ports - Communications Port (COM1) - Port settings where again one can manually set Bits per second, Data bits, Stop bits and Flow control but, again, I don't know of a program which can be used to set these non-manually. I think that windows would use com1 for /dev/ttyS0 so one could use a batch file in windows with something like mode com1:4800,0,7,1 I recall somewhere about setting parity to 0 for space parity, but I don't have a DOS manual here at work. snip Tom __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Anyone have any code for importing data from NAMCS?
David L. Van Brunt, Ph.D. dlvanbrunt at gmail.com writes: The National Ambulatory and Medical Care Survey is a free data set from the CDC that I'd like to analyze using the Survey package in R. Before I dive in, though, it occurred to me that someone may already have gone to the trouble of writing code that will bring in the data and assign the variable names and value labels. At least the 2002 and 2003 files are available as SPSS macros (not as SPSS file, as far I know). So if you know someone with SPSS, ask her to run the macros, and read in the data with R and package foreign. Dieter Menne __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Long lines with Sweave
I have used Sweave a lot the latest year, but never really used any long function calls. If I have code which look like this - gof - benthic.flux(ID=Gulf of Finland, meas.conc=conc, bw.conc=bw.conc, time=times, substance=expression(DIC~(mmol~m^{-3})) ) - I get the output by Sweave in my pdf file, like this: --- gof - benthic.flux(ID = Gulf of Finland, meas.conc = conc, + bw.conc = bw.conc, time = times, substance = expression(DIC ~ + (mmol ~ m^{ + -3 + }))) I can understand that it will not look exactly as entered but why is the '-3' on a line of it's own? Can anyone suggest a idea to how I can make this more readable. - Henrik Andersson Netherlands Institute of Ecology - Centre for Estuarine and Marine Ecology P.O. Box 140 4400 AC Yerseke Phone: +31 113 577473 [EMAIL PROTECTED] http://www.nioo.knaw.nl/ppages/handersson __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] is *package* loaded
Seth == Seth Falcon [EMAIL PROTECTED] on Tue, 13 Sep 2005 21:28:48 -0700 writes: Seth On 13 Sep 2005, [EMAIL PROTECTED] wrote: packageLoaded() may well be a bad name but loadedNamespaces() won't detect a package without a namespace. Seth Right, that's a problem. It therefore seemed safe to me to check the path, which would include both packages with and without namespaces. With respect to loading and attaching, I thought that library() both loaded a package (with or without a namespace) and attached it to the search path, that's correct. But still your proposed function isn't doing what its name suggests; so its name is really very misleading or bad as Robert said. OTOH, the name could be quite good if it's implementation changed: packageLoaded - function(name) { ## Purpose: is package 'name' loaded? ## -- (paste(package:, name, sep=) %in% search()) || (name %in% loadedNamespaces()) } but I must admit that I'm easily confused about these distinctions. Seth As I understand it, library(foo) will load and attach package foo. correct Seth If foo has a namespace, some of foo's dependencies may get loaded but Seth not attached. This is only possible if said dependencies also use Seth namespaces. Seth So it is possible for a package to be loaded and not attached. Yes. There's another maybe even more common case of package loading without attaching: e.g. using MASS::rlm(...) anywhere in your code silently loads the MASS package but doesn't attach it. Seth In this case, the loaded package is not visible via search(), but is Seth visible via loadedNamespaces() since only packages with namespaces can Seth be loaded and not attached. Indeed. Further note that package loading is more than just loading the exported R symbols from the namespace. E.g., it also dyn.load()s the ./src/ stuff [ such that in the example, MASS::rlm() can work at all ]. Seth Clear as mud? Seth HTH, Seth + seth Martin __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] adf test and cross-correlation with missing values
Dear List, I have multiple time series, all of which (excepting 1) have missing values. These run for ~30 years, with monthly sampling. I need to determine stationarity, and have tried to use the Augmented Dickey-Fuller test (adf.test), but this cannot handle missing values. The same problem occurs when attempting cross-correlation (ccf). Could someone please suggest any suitable functions in R to check for stationarity and to look at cross-correlation when NAs are present in a time series (and also, which packages these would be in) - or, do I have to interpolate the missing values first in order to perform these tests on my time series? Thankyou, Lillian. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Long lines with Sweave
On Wed, Sep 14, 2005 at 10:14:59AM +0200, Henrik Andersson wrote: I have used Sweave a lot the latest year, but never really used any long function calls. If I have code which look like this - gof - benthic.flux(ID=Gulf of Finland, meas.conc=conc, bw.conc=bw.conc, time=times, substance=expression(DIC~(mmol~m^{-3})) ) - I get the output by Sweave in my pdf file, like this: --- gof - benthic.flux(ID = Gulf of Finland, meas.conc = conc, + bw.conc = bw.conc, time = times, substance = expression(DIC ~ + (mmol ~ m^{ + -3 + }))) I can understand that it will not look exactly as entered but why is the '-3' on a line of it's own? Can anyone suggest a idea to how I can make this more readable. It seems you've been thinking LaTeX rather than R ;-) : The exponent -3 in the expression should be enclosed by parentheses rather than by curly braces. The code formatting done by the print method inserts the newline after { and before }. Best regards, Jan -- +- Jan T. Kim ---+ |*NEW*email: [EMAIL PROTECTED] | |*NEW*WWW: http://www.cmp.uea.ac.uk/people/jtk | *-= hierarchical systems are for files, not for humans =-* __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Graphical presentation of logistic regression
Hi, I wonder if anyone has written any code to implement the suggestions of Smart et al (2004) in the Bulletin of the Ecological Society of America for a new way of graphically presenting the results of logistic regression (see www.esapubs.org/bulletin/backissues/085-3/bulletinjuly2004_2column.htm#t ools1 for the full text)? I couldn't find anything relating to this sort of graphical representation of logistic models in the archives, but maybe someone has solved it already? In short, Smart et al suggest that a logistic regression be presented as a combination of the two histograms for successes and failures (with one presented upside down at the top of the figure, the other the right way up at the bottom) overlaid by the probability function (ie logistic curve). It's somewhat hard to describe, but is nicely illustrated in the full text version above. I think it is a sensible way of presenting these results and am keen to do so - at the moment I can only do this by generating the two histograms and the logistic curve separately (using hist() and lines()), then copying and pasting the graphs out of R and inverting one in a graphics package, before overlying the others. I'm sure this could be done within R and would be a handy plotting function to develop. Has anyone done so, or can anyone give me any pointers to doing this? I really nead to know how to invert a histogram and how to overlay this with another histogram the right way up. Any thoughts would be welcome. Thanks in advance, Colin ... __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Graphical presentation of logistic regression
Beale, Colin wrote: Hi, I wonder if anyone has written any code to implement the suggestions of Smart et al (2004) in the Bulletin of the Ecological Society of America for a new way of graphically presenting the results of logistic regression (see www.esapubs.org/bulletin/backissues/085-3/bulletinjuly2004_2column.htm#t ools1 for the full text)? I couldn't find anything relating to this sort of graphical representation of logistic models in the archives, but maybe someone has solved it already? In short, Smart et al suggest that a logistic regression be presented as a combination of the two histograms for successes and failures (with one presented upside down at the top of the figure, the other the right way up at the bottom) overlaid by the probability function (ie logistic curve). It's somewhat hard to describe, but is nicely illustrated in the full text version above. I think it is a sensible way of presenting these results and am keen to do so - at the moment I can only do this by generating the two histograms and the logistic curve separately (using hist() and lines()), then copying and pasting the graphs out of R and inverting one in a graphics package, before overlying the others. I'm sure this could be done within R and would be a handy plotting function to develop. Has anyone done so, or can anyone give me any pointers to doing this? I really nead to know how to invert a histogram and how to overlay this with another histogram the right way up. Any thoughts would be welcome. My reaction was that I had seen some R code in a Bulletin of the ESA that someone sent me. A quick search revealed this: http://www.esapubs.org/bulletin/backissues/086-1/bulletinjan2005.htm#et which has the code. Bob -- Bob O'Hara Dept. of Mathematics and Statistics P.O. Box 68 (Gustaf Hällströmin katu 2b) FIN-00014 University of Helsinki Finland Telephone: +358-9-191 51479 Mobile: +358 50 599 0540 Fax: +358-9-191 51400 WWW: http://www.RNI.Helsinki.FI/~boh/ Journal of Negative Results - EEB: http://www.jnr-eeb.org __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Graphical presentation of logistic regression
Beale, Colin wrote: Hi, I wonder if anyone has written any code to implement the suggestions of Smart et al (2004) in the Bulletin of the Ecological Society of America for a new way of graphically presenting the results of logistic regression (see www.esapubs.org/bulletin/backissues/085-3/bulletinjuly2004_2column.htm#t ools1 for the full text)? I couldn't find anything relating to this sort of graphical representation of logistic models in the archives, but maybe someone has solved it already? In short, Smart et al suggest that a logistic regression be presented as a combination of the two histograms for successes and failures (with one presented upside down at the top of the figure, the other the right way up at the bottom) overlaid by the probability function (ie logistic curve). It's somewhat hard to describe, but is nicely illustrated in the full text version above. I think it is a sensible way of presenting these results and am keen to do so - at the moment I can only do this by generating the two histograms and the logistic curve separately (using hist() and lines()), then copying and pasting the graphs out of R and inverting one in a graphics package, before overlying the others. I'm sure this could be done within R and would be a handy plotting function to develop. Has anyone done so, or can anyone give me any pointers to doing this? I really nead to know how to invert a histogram and how to overlay this with another histogram the right way up. Any thoughts would be welcome. Thanks in advance, Colin From what you describe, that is a poor way to represent the model except for judging discrimination ability (if the model is calibrated well). Effect plots, odds ratio charts, and nomograms are better. See the Design package for details. -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Graphical presentation of logistic regression
Frank E Harrell Jr wrote: I really nead to know how to invert a histogram and how to overlay this with another histogram the right way up. Flipping the last two numbers in par()$usr has this effect... From what you describe, that is a poor way to represent the model except for judging discrimination ability (if the model is calibrated well). Effect plots, odds ratio charts, and nomograms are better. See the Design package for details. From the poor-diagnostics-R-us dept, here's something to work from: logDiag - function(x,y){ d0=x[y==0] d1=x[y==1] h0=hist(d0,plot=FALSE) h1=hist(d1,plot=FALSE, breaks=h0$breaks) # set the xlim so the stalactites dont hit the stalagmites: plot(h0, ylim=c(0,max(c(h0$counts,h1$counts))*2)) pu=par()$usr # flip the Y-axis limits par(usr=pu[c(1,2,4,3)]) # draw the stalactites lines(h1) # reset axis par(usr=pu) } sample: xyd=data.frame(x=runif(1000),y=as.numeric(runif(1000).2)) logDiag(xyd$x,xyd$y) lets just hope this plot isn't patented like that baseball diamond plot a few years ago. My lawyer is ready... Baz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Reading data from a serial port
On 13-Sep-05 vittorio wrote: Hoping this helps, Thanks, it helps! But Ted, how do you let R know the parameters of the serial connection (e.g. 4800 7S1) ? Ciao Vittorio Following up, I've now had info from people pointing out the following. For Windows, there's a simple DOS utility which, for a serial port, is one the lines of MODE COM1:speed,parity,databits,stopbuts[,P] where the optional P is to allow infinite retries to send data to a non-responding device. This shouldn't be necessary when passively reading data being output from external equipment. Any of the above can be omitted (in which case the corresponding setting is not changed) provided the requisite commas are present. Example: MODE COM1:4800,E,7,1 will set 4800 baud, Even parity, 7 databits and 1 stop bit. Thanks to Tom Mulholland for reminding me of this! For Linux, there is the 'stty' command (which can set far more things as well, since it is designed for terminal consoles connected via serial lines). Something like stty -F /dev/ttyS0 4800 parenb -parodd cs7 -cstopb would have the same effect as the above. See man stty for more details. So, since there is a simple command foreither Windows or Linux, this can be sent from within an R session using the 'system' command, which will set up the serial port. After this, 'scan' should simply read the incoming data (as discussed earlier). Best wishes to all, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 14-Sep-05 Time: 13:09:55 -- XFMail -- __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Long lines with Sweave
Jan T. Kim wrote: On Wed, Sep 14, 2005 at 10:14:59AM +0200, Henrik Andersson wrote: I have used Sweave a lot the latest year, but never really used any long function calls. If I have code which look like this - gof - benthic.flux(ID=Gulf of Finland, meas.conc=conc, bw.conc=bw.conc, time=times, substance=expression(DIC~(mmol~m^{-3})) ) - I get the output by Sweave in my pdf file, like this: --- gof - benthic.flux(ID = Gulf of Finland, meas.conc = conc, + bw.conc = bw.conc, time = times, substance = expression(DIC ~ + (mmol ~ m^{ + -3 + }))) I can understand that it will not look exactly as entered but why is the '-3' on a line of it's own? Can anyone suggest a idea to how I can make this more readable. It seems you've been thinking LaTeX rather than R ;-) : The exponent -3 in the expression should be enclosed by parentheses rather than by curly braces. The code formatting done by the print method inserts the newline after { and before }. Best regards, Jan If you look at demo(plotmath), I get the impression that m^(-3) does not give me the desired behavior. I want to have -3 in superscript without visible parentheses. Tricky! - Henrik Andersson Netherlands Institute of Ecology - Centre for Estuarine and Marine Ecology P.O. Box 140 4400 AC Yerseke Phone: +31 113 577473 [EMAIL PROTECTED] http://www.nioo.knaw.nl/ppages/handersson __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] non-central t : R v.Splus
Hi For bureaucratic reasons beyond my control I need to rewrite an R function (for producing operating characteristic curves) as an Splus function ( version 6 , windows XP ). The R function makes extensive use of the fact that the student's t distribution function pt() has a non-centrality parameter built in ... sadly that parameter is not present in the Splus pt() function . However, the Splus f distribution function pf() does have such a parameter , so I have tried to write my own non-central version of pt() based around pf() , using the relationship between the t and F distributions. Unfortunately my success has been limited ... I can only get correct probabilities for part of the range of the quantile space , failing when the quantile becomes small ... and I'm beginning to wonder whether it's actually possible to do what I want at all , given that the range of x in F(x) is [ 0:Inf ] while that in t(x) is [-Inf , Inf ] , and the non-central t distribution is not symmetric ... Do any wiser heads than mine have any experience or advice to offer ... ? thanks Bob Kinley [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] [S] non-central t : R v.Splus
I think that you might find the following usefull: http://www.biostat.wustl.edu/archives/html/s-news/2002-11/msg00079.html I hope this helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Robert Kinley [EMAIL PROTECTED] To: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch Sent: Wednesday, September 14, 2005 3:24 PM Subject: [S] non-central t : R v.Splus Hi For bureaucratic reasons beyond my control I need to rewrite an R function (for producing operating characteristic curves) as an Splus function ( version 6 , windows XP ). The R function makes extensive use of the fact that the student's t distribution function pt() has a non-centrality parameter built in ... sadly that parameter is not present in the Splus pt() function . However, the Splus f distribution function pf() does have such a parameter , so I have tried to write my own non-central version of pt() based around pf() , using the relationship between the t and F distributions. Unfortunately my success has been limited ... I can only get correct probabilities for part of the range of the quantile space , failing when the quantile becomes small ... and I'm beginning to wonder whether it's actually possible to do what I want at all , given that the range of x in F(x) is [ 0:Inf ] while that in t(x) is [-Inf , Inf ] , and the non-central t distribution is not symmetric ... Do any wiser heads than mine have any experience or advice to offer ... ? thanks Bob Kinley Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] *** saving files ***
Hi, I need help :o( I want that my function saves result files in a for()-loop while it runs automatically. the filenames must be saved like: file_1 - for 1. result file_2 - for 2. result file_3 - for 3. result and . . . file_n - for n. result the file names are the same identified by _1, _2 , _3, ... , _n these files will loaded by a second function later in the same sequence (_1 to _n). how can I do that ... [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Long lines with Sweave
On Wed, Sep 14, 2005 at 02:49:56PM +0200, Henrik Andersson wrote: Jan T. Kim wrote: On Wed, Sep 14, 2005 at 10:14:59AM +0200, Henrik Andersson wrote: I have used Sweave a lot the latest year, but never really used any long function calls. If I have code which look like this - gof - benthic.flux(ID=Gulf of Finland, meas.conc=conc, bw.conc=bw.conc, time=times, substance=expression(DIC~(mmol~m^{-3})) ) - I get the output by Sweave in my pdf file, like this: --- gof - benthic.flux(ID = Gulf of Finland, meas.conc = conc, + bw.conc = bw.conc, time = times, substance = expression(DIC ~ + (mmol ~ m^{ + -3 + }))) I can understand that it will not look exactly as entered but why is the '-3' on a line of it's own? Can anyone suggest a idea to how I can make this more readable. It seems you've been thinking LaTeX rather than R ;-) : The exponent -3 in the expression should be enclosed by parentheses rather than by curly braces. The code formatting done by the print method inserts the newline after { and before }. Best regards, Jan If you look at demo(plotmath), I get the impression that m^(-3) does not give me the desired behavior. I want to have -3 in superscript without visible parentheses. Tricky! Ok, I see. It seems to me that you could omit the curly braces in the example, I don't see any differences between the title in the plots produced by plot(1:10, main = expression(DIC~(mmol~m^-3))) and plot(1:10, main = expression(DIC~(mmol~m^{-3}))) For more complex exponents, you could try plain() to prevent them from being wrongly grouped by operator precedence, as in plot(1:10, main = expression(DIC~(mmol~m^plain(-3 + t Not exactly ideal for readability, however... Best regards, Jan -- +- Jan T. Kim ---+ |*NEW*email: [EMAIL PROTECTED] | |*NEW*WWW: http://www.cmp.uea.ac.uk/people/jtk | *-= hierarchical systems are for files, not for humans =-* __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] *** saving files ***
Hi, write.table(result, paste(path/file_,i,sep=)) inside the for-loop should done this in a for( i in ... ) loop. Or: save(result, file=paste(path/file_,i,sep=) See ?read.table and ?load for loading the files. Best, Matthias Hi, I need help :o( I want that my function saves result files in a for()-loop while it runs automatically. the filenames must be saved like: file_1 - for 1. result file_2 - for 2. result file_3 - for 3. result and . . . file_n - for n. result the file names are the same identified by _1, _2 , _3, ... , _n these files will loaded by a second function later in the same sequence (_1 to _n). how can I do that ... [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] *** saving files ***
Shahrokh Keiwani a écrit : the filenames must be saved like: file_1 - for 1. result file_2 - for 2. result file_n - for n. result for (i in 1:n) { myfilename = paste(file_ , i , sep=); ... } hih __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] *** saving files ***
Depending on the size of your objects, you may be able to just keep them in a list, especially as you say you will need them in the same order later. If because of memory constraints or for some other reason you really need to have a separate file for each round, you can generate object and file names using paste, assign the object to the name with assign, and save the file: (warning: untested code) for(i in 1:n){ obj.name - paste(base.obj.name, i, sep = .) file.name - paste(obj.name, rda, sep = .) # or whatever other file name you want this.obj - my.fn.that.creates.object(my.arguments) assign(obj.name, this.obj) save(list = obj.name, file = file.name) } When retrieving the files, you can use a similar loop, but instead of using assign, you can use get to retrieve the value and assign it to another variable. Or, in interactive use, you know the name so you can refer to the variable. Hope this helps, Matt -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shahrokh Keiwani Sent: Wednesday, September 14, 2005 9:43 AM To: r-help@stat.math.ethz.ch Subject: [R] *** saving files *** Hi, I need help :o( I want that my function saves result files in a for()-loop while it runs automatically. the filenames must be saved like: file_1 - for 1. result file_2 - for 2. result file_3 - for 3. result and . . . file_n - for n. result the file names are the same identified by _1, _2 , _3, ... , _n these files will loaded by a second function later in the same sequence (_1 to _n). how can I do that ... [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] *** saving files ***
If your loop is from 1:n then you can do the following. suppose you call the resulslts results 1:n using assign or something. so like this for(i in 1:n){ assign(results_, i, sep=), lm(bla bla)) save(get( for(i in 1:10){ + temp - paste(results_, i, sep=) + assign(temp, rnorm(i)) + save(list=temp, file=temp) + } dir() [1] results_1 results_10 results_2 results_3 results_4 [6] results_5 results_6 results_7 results_8 results_9 P.S. If you need to call your results within the loop do something like temp2-get(temp) and you can use temp2 as any regular object HTH On Wed, 14 Sep 2005, Shahrokh Keiwani wrote: Hi, I need help :o( I want that my function saves result files in a for()-loop while it runs automatically. the filenames must be saved like: file_1 - for 1. result file_2 - for 2. result file_3 - for 3. result and . . . file_n - for n. result the file names are the same identified by _1, _2 , _3, ... , _n these files will loaded by a second function later in the same sequence (_1 to _n). how can I do that ... [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] specification for glmmPQL
Dear Prof. Bates and Group: I hope it is not to late to revisit this thread. My concern is with the difference in standard errors estimated from data that is arranged as grouped (data.1) and ungrouped (data.2). With the grouped data set, the effect of treatment is highly significant; with the data ungrouped, is is only marginally significant. My empirical findings depend on the choice of how to construct the data frame. Which is correct? Best wishes, Andrew summary(fm.5 - lmer(cbind(response, 100 - response) ~ expt + + (1 | subject), data = data.1, family = binomial, + method = AGQ)) Generalized linear mixed model fit using AGQ Formula: cbind(response, 100 - response) ~ expt + (1 | subject) Data: data.1 Family: binomial(logit link) AIC BIClogLik deviance 2437.298 2443.161 -1214.649 2429.298 Random effects: GroupsNameVarianceStd.Dev. subject (Intercept)0.026600 0.16309 # of obs: 32, groups: subject, 8 Estimated scale (compare to 1) 8.669802 Fixed effects: Estimate Std. Error z value Pr(|z|) (Intercept) 0.3082489 0.0081604 37.774 2.2e-16 *** expttreatment 0.2160440 0.0115933 18.635 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Correlation of Fixed Effects: (Intr) expttretmnt -0.704 summary(fm.6 - lmer(response ~ expt + (1 | subject), data = data.2, + family = binomial, method = AGQ)) Generalized linear mixed model fit using AGQ Formula: response ~ expt + (1 | subject) Data: data.2 Family: binomial(logit link) AIC BIClogLik deviance 4298.023 4322.306 -2145.011 4290.023 Random effects: GroupsNameVarianceStd.Dev. subject (Intercept)0.015878 0.12601 # of obs: 3200, groups: subject, 8 Estimated scale (compare to 1) 1.007666 Fixed effects: Estimate Std. Error z value Pr(|z|) (Intercept)0.308130.08075 3.8159 0.0001357 *** expttreatment 0.213500.11473 1.8609 0.0627583 . --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Correlation of Fixed Effects: (Intr) expttretmnt -0.704 Douglas Bates wrote: On 9/4/05, Andrew R. Criswell [EMAIL PROTECTED] wrote: Hello Dr. Bates and group, I understand, the attached data file did not accompany my original message. I have listed below the code used to create that file. data.1 - data.frame(subject = factor(rep(c(one, two, three, four, five, six, seven, eight), each = 4), levels = c(one, two, three, four, five, six, seven, eight)), day = factor(rep(c(one, two, three, four), times = 8), levels = c(one, two, three, four)), expt = rep(c(control, treatment), each = 16), response = c(58, 63, 57, 54, 63, 59, 61, 53, 52, 62, 46, 55, 59, 63, 58, 59, 62, 59, 64, 53, 63, 75, 62, 64, 53, 58, 62, 53, 64, 72, 65, 74)) mtrx.1 - matrix(apply(data.1[, -4], 2, function(x) rep(x, 100 - data.1$response)), ncol = 3, byrow = F) mtrx.2 - matrix(apply(data.1[, -4], 2, function(x) rep(x, data.1$response)), ncol = 3, byrow = F) data.2 - data.frame(subject = factor(c(mtrx.1[,1], mtrx.2[,1]), levels = c(one, two, three, four, five, six, seven, eight)), day = factor(c(mtrx.1[,2], mtrx.2[,2]), levels = c(one, two, three, four)), expt = factor(c(mtrx.1[,3], mtrx.2[,3]), levels = c(control, treatment)), response = factor(c(rep(yes, nrow(mtrx.1)), rep(no, nrow(mtrx.2))), levels = c(yes, no))) #---# Thanks for sending the data. In your first message you said that you got completely different results from glmmPQL when fitting the two models. When I fit these models with glmmPQL I got quite similar parameter estimates. The reported log-likelihood or AIC or BIC values are quite different but these values apply to a different model (the list weighted linear mixed model used in the PQL algorithm) and should not be used for a glmm
[R] correlation as distance/dissimilarity
I've been asked (privately) CarlosJ == jaramilloc [EMAIL PROTECTED] on Wed, 14 Sep 2005 09:40:22 -0400 writes: .. CarlosJ In Kaufman Rousseeuw 2000 book on Cluster Analysis, it says that CarlosJ Daisy can compute Pearson correlation between variables and then CarlosJ transform these to dissimilarities. I don't think it does say this. But it does talk about doing it your self, e.g., on pages 17--19. CarlosJ Has this capability being CarlosJ implemented in the Cluster package for R? It seems that is not CarlosJ there. How could I do that using R? CarlosJ I would appreciate your help. It has never been explicitly in R, because in the past 'everyone' has thought this was obvious and trivial. The past here was when S was used by statisticians, mathematicians or engineers... Anyway, here is an example on how to do this. dd - as.dist((1 - cor(USJudgeRatings))/2) plot(hclust(dd)) round(1000 * dd) CONT INTG DMNR DILG CFMG DECI PREP FAMI ORAL WRIT PHYS INTG 567 DMNR 577 18 DILG 494 64 82 CFMG 432 93 93 21 DECI 457 99 98 229 PREP 494 61 72 11 21 21 FAMI 513 66 79 21 32 295 ORAL 506 44 47 23 25 2689 WRIT 522 46 53 20 29 27753 PHYS 473 129 106 94 60 64 76 78 54 72 RTEN 517 31 28 35 36 38 25 299 16 47 I'm going to add the example to the help page for 'dist' in R-2.2.0 Martin Maechler __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Random effect model
Dear R-help group, I would like to model directly following random effect model: Y_ik = M_ik + E_ik where M_ik ~ N(Mew_k,tau_k^2) E_ik ~ N(0,s_ik^2) i = number of study k = number of treatment --- I have practiced using the command from 'Mixed -Effects models in S and S-plus' as follow fm1logit.lme - lme(logitp~1, data=logit, random = ~1|factor(Tr)) It can be written in this model Y_ik = Mew + B_i + E_ik where M_i ~ N(0,sigma_b^2) E_ik ~ N(0,sigma^2) but it is not the same what my model is. Could somebody please point me in the right direction ? Sorry if this turns out to be an extreamly simple question, I'm a new user to R. Thank you very much, Ae __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Apply a function for each Row
Dear All, I wonder how to apply a given function to each row of a data frame. I've seen this function before but don't remember its name Thank you, Bernard - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Apply a function for each Row
Marc Bernard wrote: Dear All, I wonder how to apply a given function to each row of a data frame. I've seen this function before but don't remember its name You've just said it twice! 'apply'! Baz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] if() command
Ok Petr, I run your suggestion and I got this message: age-sample(seq(10,50,10), 20, replace=T) if (age =10) {group - 1} else if (age 10 age = 20) {group - 2} else {group - 3} Warning message: the condition has length 1 and only the first element will be used in: if (age = 10) { What does it means ? And when I look to the database I have no new classification ! Could you help please ? Mauricio Petr Pikal escreveu: Hallo On 13 Sep 2005 at 10:29, Carlos Maurício Cardeal Mende wrote: Hi everyone ! Could you please help me with this problem ? I´ve trying to write a code that assign to a variable the content from another, but all I´ve got is a message error. For example: if (age =10) {group == 1} else if (age 10 age = 20) {group == 2} else {group == 3} if you put your statement on one line it works (at least it does not give you syntax error) but the result is hardly what you really expect age-sample(seq(10,50,10), 20, replace=T) if (age =10) {group - 1} else if (age 10 age = 20) {group - 2} else {group - 3} if (age =10) {group == 1} else if (age 10 age = 20) {group == 2} else {group == 3} Maybe you want something like group-as.numeric(cut(age,c(0,10,20,100))) but it is only guess HTH Petr Syntax error Or if (age =10) {group == 1} else (age 10 age = 20) {group == 2} else {group == 3} Syntax error I know that is possible to find the solution by ifelse command or even recode command, but I´d like to use this way, because I can add another variable as a new condition and I believe to expand the possibilites. Thanks, Mauricio __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Petr Pikal [EMAIL PROTECTED] No virus found in this incoming message. Checked by AVG Anti-Virus. Version: 7.0.344 / Virus Database: 267.10.21/96 - Release Date: 10/9/2005 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] if() command
Hello reid ! About your third explanation, could you please write the complete code including that option: a loop ? Forgiveme, I'm trying to learn R and my mind is full of other statistical program syntax. And I'd like very very much to improve my knowledge using R and maybe contribute to someone, someday, somehow. Thanks, again Mauricio Huntsinger, Reid escreveu: First, == is logical comparison, so if you want to create a variable based on both age and group you can do that. However, it looks like you want to define the variable group, so you want to use - or = for that. Second, if you're typing this at a command prompt, you need to make sure you tell R you're not finished when it looks like you could be. There are several ways to do this. One is to put everything inside braces; another is to deliberately leave lines incomplete, like if (age = 10) { group - 1 } else { if (age = 20) { group - 2 } else group - 3 } Third, this will work for a vector of length 1. If you want to take a vector age and produce a corresponding vector group, you'll need to put this in a loop, or use lapply, or some iteration. Fourth, you can also write the above as group - if (age = 10) 1 else if (age = 20) 2 else 3 that is, if() returns a value you can assign. Finally, besides ifelse you can use cut for this particular task. Reid Huntsinger -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Carlos Maurício Cardeal Mendes Sent: Tuesday, September 13, 2005 9:29 AM To: r-help@stat.math.ethz.ch Subject: [R] if() command Hi everyone ! Could you please help me with this problem ? I´ve trying to write a code that assign to a variable the content from another, but all I´ve got is a message error. For example: if (age =10) {group == 1} else if (age 10 age = 20) {group == 2} else {group == 3} Syntax error Or if (age =10) {group == 1} else (age 10 age = 20) {group == 2} else {group == 3} Syntax error I know that is possible to find the solution by ifelse command or even recode command, but I´d like to use this way, because I can add another variable as a new condition and I believe to expand the possibilites. Thanks, Mauricio __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Notice: This e-mail message, together with any attachments...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] if() command
if is not vectorised and age is a vector. Try the following test: if(c(TRUE, FALSE)) TRUE else FALSE You really need to use ifelse. ifelse(c(TRUE, FALSE), TRUE, FALSE) As others have suggested, you might want to look at ?cut. --sundar Carlos Mauricio Cardeal Mendes wrote: Ok Petr, I run your suggestion and I got this message: age-sample(seq(10,50,10), 20, replace=T) if (age =10) {group - 1} else if (age 10 age = 20) {group - 2} else {group - 3} Warning message: the condition has length 1 and only the first element will be used in: if (age = 10) { What does it means ? And when I look to the database I have no new classification ! Could you help please ? Mauricio Petr Pikal escreveu: Hallo On 13 Sep 2005 at 10:29, Carlos Maurício Cardeal Mende wrote: Hi everyone ! Could you please help me with this problem ? I´ve trying to write a code that assign to a variable the content from another, but all I´ve got is a message error. For example: if (age =10) {group == 1} else if (age 10 age = 20) {group == 2} else {group == 3} if you put your statement on one line it works (at least it does not give you syntax error) but the result is hardly what you really expect age-sample(seq(10,50,10), 20, replace=T) if (age =10) {group - 1} else if (age 10 age = 20) {group - 2} else {group - 3} if (age =10) {group == 1} else if (age 10 age = 20) {group == 2} else {group == 3} Maybe you want something like group-as.numeric(cut(age,c(0,10,20,100))) but it is only guess HTH Petr Syntax error Or if (age =10) {group == 1} else (age 10 age = 20) {group == 2} else {group == 3} Syntax error I know that is possible to find the solution by ifelse command or even recode command, but I´d like to use this way, because I can add another variable as a new condition and I believe to expand the possibilites. Thanks, Mauricio __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Petr Pikal [EMAIL PROTECTED] No virus found in this incoming message. Checked by AVG Anti-Virus. Version: 7.0.344 / Virus Database: 267.10.21/96 - Release Date: 10/9/2005 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] nls()
Hi, I am using nls() with the form: nls(~my.fcn(...)) because I have to iteratively compute the expected y values. The function my.fcn() returns y.obs-y.pred However, I want to fix some of the parameters in my.fcn at various values and compute the parameter estimates. In Splus there is such a thing as a parameterized dataframe. I don't think this exists in R so does anyone know how to set one or more of the parameters as constants in the model? Thank you. Jeff Breiwick __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] if() command
On Wed, 14 Sep 2005, Carlos Mauricio Cardeal Mendes wrote: Ok Petr, I run your suggestion and I got this message: age-sample(seq(10,50,10), 20, replace=T) if (age =10) {group - 1} else if (age 10 age = 20) {group - 2} else {group - 3} Warning message: the condition has length 1 and only the first element will be used in: if (age = 10) { What does it means ? And when I look to the database I have no new classification ! Although the syntax issue is real, if() is not the way to go if you are comparing a vector with a scalar; if() will only compare the first element of the vector with the scalar. The ifelse() function is vectorised: age-sample(seq(10,50,10), 20, replace=T) group_ifelse - ifelse(age 10, ifelse(age 20, 3, 2), 1) group_ifelse [1] 3 2 3 3 3 2 3 3 1 2 3 1 1 1 3 2 3 2 3 3 or maybe even better, use the cut function to create a grouping factor: group_cut - cut(age, breaks=c(0,10,20,100), include.lowest=TRUE) group_cut [1] (20,100] (10,20] (20,100] (20,100] (20,100] (10,20] (20,100] (20,100] [9] [0,10] (10,20] (20,100] [0,10] [0,10] [0,10] (20,100] (10,20] [17] (20,100] (10,20] (20,100] (20,100] Levels: [0,10] (10,20] (20,100] age [1] 30 20 30 40 30 20 50 50 10 20 30 10 10 10 30 20 40 20 50 40 as.integer(group_cut) [1] 3 2 3 3 3 2 3 3 1 2 3 1 1 1 3 2 3 2 3 3 Sometimes you need to enclose cut() within ordered(), and if there are empty intervals, you may not get what you expect from the integer representation of the result. Yet another elegant function is findInterval(): group_findInterval - findInterval(age, c(0,10.001,20.001,100)) group_findInterval [1] 3 2 3 3 3 2 3 3 1 2 3 1 1 1 3 2 3 2 3 3 Hope this helps Could you help please ? Mauricio Petr Pikal escreveu: Hallo On 13 Sep 2005 at 10:29, Carlos Maurício Cardeal Mende wrote: Hi everyone ! Could you please help me with this problem ? I´ve trying to write a code that assign to a variable the content from another, but all I´ve got is a message error. For example: if (age =10) {group == 1} else if (age 10 age = 20) {group == 2} else {group == 3} if you put your statement on one line it works (at least it does not give you syntax error) but the result is hardly what you really expect age-sample(seq(10,50,10), 20, replace=T) if (age =10) {group - 1} else if (age 10 age = 20) {group - 2} else {group - 3} if (age =10) {group == 1} else if (age 10 age = 20) {group == 2} else {group == 3} Maybe you want something like group-as.numeric(cut(age,c(0,10,20,100))) but it is only guess HTH Petr Syntax error Or if (age =10) {group == 1} else (age 10 age = 20) {group == 2} else {group == 3} Syntax error I know that is possible to find the solution by ifelse command or even recode command, but I´d like to use this way, because I can add another variable as a new condition and I believe to expand the possibilites. Thanks, Mauricio __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Petr Pikal [EMAIL PROTECTED] No virus found in this incoming message. Checked by AVG Anti-Virus. Version: 7.0.344 / Virus Database: 267.10.21/96 - Release Date: 10/9/2005 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] if() command
Looping would look like: group - vector(length=length(age)) for (i in 1:length(age)) { group[i] - if (age[i] = 10) 1 else if (age[i] = 20) 2 else 3 } Another way to do this is to write a function, say category, like category - function(x) if(x = 10) 1 else if (x = 20) 2 else 3 and then apply the function to all elements of age like group - sapply(age,category) (This is a common way to vectorize a function.) Reid Huntsinger -Original Message- From: Carlos Mauricio Cardeal Mendes [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 14, 2005 1:21 PM To: Huntsinger, Reid Cc: r-help@stat.math.ethz.ch Subject: Re: [R] if() command Hello reid ! About your third explanation, could you please write the complete code including that option: a loop ? Forgiveme, I'm trying to learn R and my mind is full of other statistical program syntax. And I'd like very very much to improve my knowledge using R and maybe contribute to someone, someday, somehow. Thanks, again Mauricio Huntsinger, Reid escreveu: First, == is logical comparison, so if you want to create a variable based on both age and group you can do that. However, it looks like you want to define the variable group, so you want to use - or = for that. Second, if you're typing this at a command prompt, you need to make sure you tell R you're not finished when it looks like you could be. There are several ways to do this. One is to put everything inside braces; another is to deliberately leave lines incomplete, like if (age = 10) { group - 1 } else { if (age = 20) { group - 2 } else group - 3 } Third, this will work for a vector of length 1. If you want to take a vector age and produce a corresponding vector group, you'll need to put this in a loop, or use lapply, or some iteration. Fourth, you can also write the above as group - if (age = 10) 1 else if (age = 20) 2 else 3 that is, if() returns a value you can assign. Finally, besides ifelse you can use cut for this particular task. Reid Huntsinger -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Carlos Maurício Cardeal Mendes Sent: Tuesday, September 13, 2005 9:29 AM To: r-help@stat.math.ethz.ch Subject: [R] if() command Hi everyone ! Could you please help me with this problem ? I´ve trying to write a code that assign to a variable the content from another, but all I´ve got is a message error. For example: if (age =10) {group == 1} else if (age 10 age = 20) {group == 2} else {group == 3} Syntax error Or if (age =10) {group == 1} else (age 10 age = 20) {group == 2} else {group == 3} Syntax error I know that is possible to find the solution by ifelse command or even recode command, but I´d like to use this way, because I can add another variable as a new condition and I believe to expand the possibilites. Thanks, Mauricio __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html --- --- Notice: This e-mail message, together with any attachments...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Forcing hist()
I'm trying to create histogram (using hist()) that fullfill the following criteria: * data is on a ordinal scale (1, 2, 3, 4, 5) * I want bars centered over the number on the x-axis * I want 5 bars of equal width I have tried various versions of the hist() command, with no luck. what am I missing? /Par -- Par Leijonhufvud [EMAIL PROTECTED] If you're not part of the solution, be part of the problem! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Apply a function for each Row
From: Barry Rowlingson Marc Bernard wrote: Dear All, I wonder how to apply a given function to each row of a data frame. I've seen this function before but don't remember its name You've just said it twice! 'apply'! A small catch: Marc wants to apply the function to rows of a data frame, but apply() expects a matrix or array, and will coerce to such if given a data frame, which may (or may not) be problematic... Andy Baz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Forcing hist()
On Wed, 2005-09-14 at 20:17 +0200, Par Leijonhufvud wrote: I'm trying to create histogram (using hist()) that fullfill the following criteria: * data is on a ordinal scale (1, 2, 3, 4, 5) * I want bars centered over the number on the x-axis * I want 5 bars of equal width I have tried various versions of the hist() command, with no luck. what am I missing? /Par More than likely, you want to use barplot() and not hist(): Try: barplot(1:5, names.arg = 1:5) See ?barplot for more information. HTH, Marc Schwartz P.S. To R Core: It probably makes sense to add barplot to the See Also section of ?hist, since hist is listed in the See Also for ?barplot. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Can I use lme to deal with grouping data when I only get one data point per group?
Hi there, I have a question for using lme. Say, I have 6 data points and they belong to six groups (one group factor). So there is no replicates for each group and I cannot separate the with-in group variation from the between group variation. But when I try to use lme to deal with it, it gave the answers for both with-in group variation and the between group variation! The statement is as below: === fac=as.factor(c(1:6)) y=data data.y=data.frame(y,fac) y.g=groupedData(y~1|fac) fit.y=lme(y~1,random=~1|fac) = An example is: y=c(-0.3465181, -0.2019839, -0.7610653, -0.1992943, -0.1663348, 0.2811794) then the lme gave me the variance components: 0.09865809 (intercept , between-group variance) 0.01387379 (residual, with-in group variance) So, my question is, from theory we cannot get separate estimates of with-in group variation and the between group variation, then what dose the output of the lme mean? Thanks! Ruixiao [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Converting coordinates to actual distances
Hello, I've been searching for a method of converting Lat/Lon decimal coordinates into actual distances between points, and taking into account the curvature of the earth. Is there such a package in R? I've looked at the GeoR package, but this does not seem to contain what I am looking for. Ideally the output would be a triangular matrix of distances. Thanks in advance, Paul Brewin Paul E Brewin (PhD) Center for Research in Biological Systems University of California San Diego 9500 Gilman Drive MC 0505 La Jolla CA, 92093-0505 USA Ph: 858-822-0871 Fax: 858-822-3631 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] maximum string length in RdbiPgSQL and in R
Because my problem involves the RdbiPgSQL package, I sent a message similar to this one to the Bioconductor list. But while awaiting moderator approval of my message (because I am not a member of that list), it occurred to me to send it to R-help as the problem may be more general than just RdbiPgSQL. Here's my situation: I have been using RdbiPgSQL successfully for a year or two. I commonly save my queries in text files that I can use either in PostgreSQL's psql (useful for testing and editing) or in R using readLines(). For example (in R): library(RdbiPgSQL) conn - dbConnect(PgSQL(), host = localhost, dbname = agdb) test.sql readLines(queryfile) test.df - dbGetQuery(conn, paste(test.sql, collapse = )) This works fine for all the multiline files I have tried -- except one. I have recently encountered a problem with a moderately complex, moderately long query (12 lines, 459 characters). I can execute the query with no problem in psql and it returns the 14 rows that I expect. When I execute the query in R as above, I get a dataframe with the expected column names, but no rows. I get no error message. I am wondering if the query string is too long. Is there a maximum length for queries in RdbiPgSQL or for strings in R? By the way, I can use collapse = \n in paste() and get the same result, so I don't think line length is the problem. Or maybe someone has a better idea of how to read (in R) the file containing the query and sending it to my database. Of course, I know I can execute the query outside of R and use read.table to make my dataframe, but I want to do this inside R. Thanks for any ideas. -- William D. McCoy Geosciences University of Massachusetts, Amherst [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Can I use lme to deal with grouping data when I only get one data point per group?
Ruixiao Lu tinypenguin at gmail.com writes: I have a question for using lme. Say, I have 6 data points and they belong to six groups (one group factor). So there is no replicates for each group and I cannot separate the with-in group variation from the between group variation. But when I try to use lme to deal with it, it gave the answers for both with-in group variation and the between group variation! The statement is as below: ((Slightly modified by DM)) fac=as.factor(c(1:6)) y=c(-0.3465181, -0.2019839, -0.7610653, -0.1992943, -0.1663348, 0.2811794) data.y=data.frame(y,fac) y.g=groupedData(y~1|fac) intervals(y.g) ## and you will see Similar example on page 27 of Pinheiro/Bates Dieter Menne __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Converting coordinates to actual distances
Paul Brewin wrote: Hello, I've been searching for a method of converting Lat/Lon decimal coordinates into actual distances between points, and taking into account the curvature of the earth. Is there such a package in R? I've looked at the GeoR package, but this does not seem to contain what I am looking for. Ideally the output would be a triangular matrix of distances. Thanks in advance, Paul Brewin Paul E Brewin (PhD) Center for Research in Biological Systems University of California San Diego 9500 Gilman Drive MC 0505 La Jolla CA, 92093-0505 USA Ph: 858-822-0871 Fax: 858-822-3631 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html See http://www.meridianworlddata.com/Distance-Calculation.asp. The calculations are trivial. -- Bob Wheeler --- http://www.bobwheeler.com/ ECHIP, Inc. --- Randomness comes in bunches. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Converting coordinates to actual distances
See http://finzi.psych.upenn.edu/R/Rhelp02a/archive/29117.html On 9/14/05, Paul Brewin [EMAIL PROTECTED] wrote: Hello, I've been searching for a method of converting Lat/Lon decimal coordinates into actual distances between points, and taking into account the curvature of the earth. Is there such a package in R? I've looked at the GeoR package, but this does not seem to contain what I am looking for. Ideally the output would be a triangular matrix of distances. Thanks in advance, Paul Brewin Paul E Brewin (PhD) Center for Research in Biological Systems University of California San Diego 9500 Gilman Drive MC 0505 La Jolla CA, 92093-0505 USA Ph: 858-822-0871 Fax: 858-822-3631 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Converting coordinates to actual distances
On Wed, 14 Sep 2005, Paul Brewin wrote: Hello, I've been searching for a method of converting Lat/Lon decimal coordinates into actual distances between points, and taking into account the curvature of the earth. Is there such a package in R? I've looked at the GeoR package, but this does not seem to contain what I am looking for. Ideally the output would be a triangular matrix of distances. Using C code in the sp package (which will be exposed at the R level shortly) and sp 0.8 and maptools 0.5: library(maptools) Loading required package: foreign Loading required package: sp xx - readShapePoly(system.file(shapes/sids.shp, package=maptools)[1]) ll - getSpPPolygonsLabptSlots(xx) # ll is a matrix of long-lat centroids of North Carolina county polygons str(ll) num [1:100, 1:2] -81.5 -81.1 -79.3 -79.8 -78.7 ... plot(ll) x - as.double(ll[,1]) y - as.double(ll[,2]) n - as.integer(length(x)) dists - vector(mode=double, length=n) lonlat - as.integer(1) res - matrix(as.double(NA), 100, 100) for (i in 1:100) res[i,] - .C(sp_dists, x, y, x[i], y[i], n, dists, + lonlat)[[6]] gives a full matrix measured in kilometers for the WGS-84 ellipsoid. Accessing the C function like this puts the responsibility for checking the argument modes on the user. If this seems scary, rdist.earth() in the fields package has an R version of this. But maybe you need the actual functions to use great circle distance instead of Euclidean, rather than just to generate a distance matrix? Hope this helps, Roger Bivand Thanks in advance, Paul Brewin Paul E Brewin (PhD) Center for Research in Biological Systems University of California San Diego 9500 Gilman Drive MC 0505 La Jolla CA, 92093-0505 USA Ph: 858-822-0871 Fax: 858-822-3631 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Graphical presentation of logistic regression
On Wed, 14 Sep 2005, Beale, Colin wrote: Hi, I wonder if anyone has written any code to implement the suggestions of Smart et al (2004) in the Bulletin of the Ecological Society of America for a new way of graphically presenting the results of logistic regression (see www.esapubs.org/bulletin/backissues/085-3/bulletinjuly2004_2column.htm#t ools1 for the full text)? I couldn't find anything relating to this sort of graphical representation of logistic models in the archives, but maybe someone has solved it already? In short, Smart et al suggest that a logistic regression be presented as a combination of the two histograms for successes and failures (with one presented upside down at the top of the figure, the other the right way up at the bottom) overlaid by the probability function (ie logistic curve). It's somewhat hard to describe, but is nicely illustrated in the full text version above. I think it is a sensible way of presenting these results and am keen to do so - at the moment I can only do this by generating the two histograms and the logistic curve separately (using hist() and lines()), then copying and pasting the graphs out of R and inverting one in a graphics package, before overlying the others. I'm sure this could be done within R and would be a handy plotting function to develop. Has anyone done so, or can anyone give me any pointers to doing this? I really nead to know how to invert a histogram and how to overlay this with another histogram the right way up. I think if you take a peek at hist.default you will find it is pretty straightforward. All that happens in hist.default is there is a lot of stuff about choosing the breaks for the bins, then some C code is called to get the counts, then the information is assembled and plot is called where the object plotted is of class histogram. If you then look at plot.histogram (getAnywhere(plot.histogram)) you find all it really does is plot some rectangles. Just change the plotting bit. If you want an example of how it might be done, you can look at log.hist in my package HyperbDist (or a more recent version logHist.R on my homepage at http://www.stat.auckland.ac.nz/~dscott/) David Scott _ David Scott Department of Statistics, Tamaki Campus The University of Auckland, PB 92019 AucklandNEW ZEALAND Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000 Email: [EMAIL PROTECTED] Graduate Officer, Department of Statistics __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] bootstrapping for clustering
Dear R-listers, Is anyone familiar with a package that would perform bootstrapping on species/site matrices for clustering ? So far I have been using the vegan package to generate trees (Bray-Curtis index), but I would like to associate a certainty to each node (similarly to a phylogenetic tree). If no package exist, I would know how to generate bootstrapped matrices of distance, but how could I plot the results ? Graphically, I am looking for something similar to what is available from the pvclust package (my understanding is that pvclust makes covariance clustering from dataframes, and it cannot be used with matrices to generate Bray-Curtis similarity dendrograms?) Please forgive my ignorance! Thank you in advance, eric pante __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Scan and Lists
This may be a newbie question - although I did search for this error message in the archives and via google and didn't see this error: The help page for scan indicates that among the types of data capable of being read are: The supported types are 'logical', 'integer', 'numeric', 'complex', 'character', 'raw' and 'list': 'list' values should have elements which are one of the first six types listed or 'NULL'. I have tried to use a list within a what list : f - scan(file=c:/test/testout.csv,what=list(hi=0.0,bye=,wave=list(1:1000)),sep=,,skip=1) and the following error is returned: c:/test/testout.csv, what = list(hi = 0, bye = , : unimplemented type 'list' in 'extractItem' So, is my syntax confusing R, or is the documentation wrong, or is it some other, third, option? Thanks M -- Michael Lefsky College of Natural Resources Colorado State University - Out of the crooked timber of humanity, no straight thing was ever made- Immanuel Kant __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Importing IDL Structures
I am trying to get started with R, but before I do, I need to find a way to import my existing datasets, which are currently stored as arrays of IDL structures (RSI's IDL, not the other one). The problem I has is this: the IDL structures contain scalar items, as well as n-dimensional arrays. I can export the data in a number of ways, including as separate files for scalars and for each of the arrays. Has anyone tackled this problem? If not, can you advise me on the best data structure(s) to hold such data in R? Data frames seemed to be the most obvious choice, but I prefer the syntax used for lists (it is more similar to IDL), if that is possible. And of course (as I said in a previous message) there is the question of how to import the data into the structure (it looks like I will need to export each array separately , import them into R and then assemble the final structure). Any assistance will be appreciated. M -- Michael Lefsky College of Natural Resources Colorado State University - Out of the crooked timber of humanity, no straight thing was ever made- Immanuel Kant __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Scan and Lists
Hi Michael An example of your list would have helped. Anyhow, why do you want to read a list? If you created a list object in R and want to save it and then read it back in other session or in some other time a good option is to write an ASCII representation of the object using dput and then recreate it using dget i.e. mylist= list(x=cars[,1], y=cars[,2]) dput(mylist,mylist) mylistback=dget(mylist) $x [1] 4 4 7 7 8 9 10 10 10 11 11 12 12 12 12 13 13 13 13 14 14 14 14 15 15 [26] 15 16 16 17 17 17 18 18 18 18 19 19 19 20 20 20 20 20 22 23 24 24 24 24 25 $y [1] 2 10 4 22 16 10 18 26 34 17 28 14 20 24 28 26 34 34 46 [20] 26 36 60 80 20 26 54 32 40 32 40 50 42 56 76 84 36 46 68 [39] 32 48 52 56 64 66 54 70 92 93 120 85 If you want to read some other type of data take a look at the higher lever functions listed under ?read.table and the functions at library(help=foreign) I hope this helps Francisco PS: Nasty weather in Fort Collins today! From: Michael Lefsky [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Subject: [R] Scan and Lists Date: Wed, 14 Sep 2005 15:06:17 -0600 This may be a newbie question - although I did search for this error message in the archives and via google and didn't see this error: The help page for scan indicates that among the types of data capable of being read are: The supported types are 'logical', 'integer', 'numeric', 'complex', 'character', 'raw' and 'list': 'list' values should have elements which are one of the first six types listed or 'NULL'. I have tried to use a list within a what list : f - scan(file=c:/test/testout.csv,what=list(hi=0.0,bye=,wave=list(1:1000)),sep=,,skip=1) and the following error is returned: c:/test/testout.csv, what = list(hi = 0, bye = , : unimplemented type 'list' in 'extractItem' So, is my syntax confusing R, or is the documentation wrong, or is it some other, third, option? Thanks M -- Michael Lefsky College of Natural Resources Colorado State University - Out of the crooked timber of humanity, no straight thing was ever made- Immanuel Kant __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Log scale in histograms
Can't find any information about this, but others must want to do it. In the example below, the second plot has the desired log scale, but the first does not. Any help appreciated. JD -- data(state) area_Mh = 259*state.area/100 histlogarea = hist(log(area_Mh), 13, xlab=Area (Mh), main=) histlogarea$mids = exp(histlogarea$mids) histlogarea$breaks = exp(histlogarea$breaks) plot(histlogarea, log=x) plot(histlogarea$mids, histlogarea$density, log=x) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html