Re: [R] Sweave, TEXINPUTS problem
Yes! I found the solution. The problem was in my export line in .bash_profile. The correct line is here export TEXINPUTS=.:/Library/Frameworks/R.framework/Resources/share/texmf:$TEXINPUTS -Johannes 2009/9/28 Charles C. Berry cbe...@tajo.ucsd.edu: On Mon, 28 Sep 2009, johannes rara wrote: Hi, I'm trying to use Sweave in my .tex-documents using \usepackage{Sweave} notation. I have this line in my .bash_profile export TEXINPUT=.:/Users/jrara/Library/Frameworks/R.framework/Resources/share/texmf:$TEXINPUTS When trying to typeset this .tex document, I get an error message saying ERROR: LaTeX Error: File `Sweave.sty' not found. You did not save how you were trying to typeset the .tex doc. I'd let texi2dvi take care of TEXINPUTS. In R, see ?tools:::texi2dvi and at the bash prompt try R CMD texi2dvi --help for documentation. Maybe using R CMD texi2dvi -p mytex.tex will do it for you. HTH, Chuck I tried to google this problem but could not find a solution. -Johannes sessionInfo() R version 2.9.2 (2009-08-24) i386-apple-darwin8.11.1 locale: fi_FI.UTF-8/fi_FI.UTF-8/C/C/fi_FI.UTF-8/fi_FI.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] data frame's column names not the same as in CSV
Thank you all. I would like to say that it was my first time posting on the r-help mailing list. I am very impressed and grateful that I got the answer to my problem so quickly. Back to the issue, using read.csv (instead of read.csv) and turning off the check.names flag solved my problem. Derek On Sat, Sep 26, 2009 at 5:17 PM, Don MacQueen m...@llnl.gov wrote: At 1:58 AM -0400 9/26/09, Derek Foo wrote: Hello, I am trying to read in a csv file with column such as \\LS01\Processor(_Total)\% Processor Time with the command read.csv(file). However, the column name in the resulted data frame is changed to X..LS01.Processor._TotalProcessor.Time. Strangely, Not so strange. Data can be anything, but column names are names of variables. In R, as in most (all? many?) computer languages, variable names have rules they must follow. Yours don't follow R's rules. See Gabor's response to learn how to tell R to ignore the rules (in this particular instance). You will find, however, that later on, when you want to use those variables, it will be more difficult to use variables whose names do not follow the rules. when I experimented with just reading the csv with the head flag set to false, the text was read correctly as the same to the raw file. I am wondering if anyone has encountered a similar problem. If so, I would really appreciate if you can share your insight. Best Regards, Derek [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://*stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http:// *www.*R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- -- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062 -- [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R and REST API's
Hi Gary, Greg, et al. In addition to making some things slightly simpler, the RCurl package also provides some necessary lower-level control over the HTTP requests. Firstly, it can handle HTTPS. Secondly, numerous REST applications will require more information in the header of the HTTP request, e.g. some authentication information. url() and friends aren't designed to allow R programmers to specify this. Also, JSON has come up in this thread. In addition to the rjson, there is the RJSONIO package which should be a faster, drop-in substitute for rjson. As for REST winning over SOAP, etc. both are in play and some providers provide APIs for both (e.g. Amazon). If you had to implement a client from scratch for either, REST is definitely simpler. However, SOAP is much more structured and can be automated because of the availability of WSDL files that describe the interface. Until WADL becomes established, it is actually easier for a consumer to programmatically generate a SOAP interface than each REST interface separately. BTW, Deb Nolan and I are writing a book on XML and Web Technologies with R that we hope will appear early next year that will cover many aspects of scraping, XML and JSON in this flavor. There are lots of packages on the Omegahat repository that do this (e.g. Rflickr, RAmazonS3, RAmazonDBREST, Zillow D. Greg Hirson wrote: Gary, Echoing Barry's suggestion of Omegahat packages, take a look at RCurl - http://www.omegahat.org/RCurl/ It has a function, getForm, which passes GET form parameters as a list to curl. I used it and the XML package in writing RLastFM (http://cran.r-project.org/web/packages/RLastFM/index.html) which implements this for last.fm. With a few XPath queries (in the XML) package, you can format the data into a data frame. Greg Gary Lewis wrote: Hi - Many organizations now make their data available as XML via a REST web service architecture. Is there any R package or facility to access this type of data directly (eg, to make the HTTP GET request and have the downloaded data put into an R data frame)? I used several R search sites to look for an answer, but came up with very little. Any help would be appreciated. Thanks very much. Gary Lewis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 3D to 2D projection
Have you used persp or trans3d before? Here is a little piece of data that I am want to convert to 2d. I can plot (x,z) or (z,y). I know there is a better way to convert it to 2d. I did it long time back in my 3d geometry class. http://en.wikipedia.org/wiki/3D_projection ? Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] SAS user now converting to R - Help with Transpose
Hi, Also take a look at cast(), melt() and recast() from the reshape package. Great and very flexible functions. cheers, Paul Daniel Malter schreef: ?reshape hth, Daniel baxterj wrote: I am just starting to code in R and need some help as I am used to doing this in SAS. I have a dataset that looks like this: Chemical Well1 Well2 Well3 Well4 BOD 13.2 14.2 15.5 14.2 O2 7.8 2.6 3.5 2.4 TURB 10.2 14.6 18.5 17.3 and so on with more chemicals I would like to transpose my data so that it looks like this: Chemical WellID Value BOD Well1 13.2 BOD Well2 14.2 BOD Well3 15.5 BOD Well4 14.2 O2 Well1 7.8 O2 Well2 2.6 and so on In sas I would code it like this: proc sort data=ds1; by chemical; run; Proc Transpose data=ds1 out=ds2; by chemical; var Well1 Well2 Well3 Well4; run; data ds3; set ds2; rename _name_ = WellID; rename col1 = value; run; How can I do this in R?? Any help is much appreciated. Thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 3D to 2D projection
On Sep 28, 2009, at 1:41 PM, Nair, Murlidharan T wrote: David, Have you used persp or trans3d before? Yes, both. persp requires an x-y grid of a particular sort ... from the help page Arguments x, y locations of grid lines at which the values in z are measured. These must be in ascending order. By default, equally spaced values from 0 to 1 are used. If x is a list, its components x$x and x$y are used for x and y, respectively. Here is a little piece of data that I am want to convert to 2d. Perhaps you should define what you mean by convert to 2d in more expansive terms. I can plot (x,z) or (z,y). I know there is a better way to convert it what is it??? The use of indefinite pronouns is quite commonly a barrier to communication. ... to 2d. I did it long time back in my 3d geometry class. I am not precisely clear what you are having problems with. I executed your code without any error reported. The s3d object looked like the 2- d projection of a single spiraled DNA-like shape. Then I plotted the points you specified, again without error or modification of your code and now I see: a) a second intertwined spiral curve, b) circles at the endpoints of the pseudo-3D segments, and c) a line that goes through the apparent center of the now pseudo-double-helix. Very pretty. s3d is now as set of 4 functions that will project points or other objects into that virtual space: str(s3d) List of 4 $ xyz.convert:function (x, y = NULL, z = NULL) $ points3d :function (x, y = NULL, z = NULL, type = p, ...) $ plane3d:function (Intercept, x.coef = NULL, y.coef = NULL, lty = dashed, lty.box = NULL, ...) $ box3d :function (...) You may have problems if the abstract object (a spiral) does not conform to the requirements of the function you are considering (persp), since it may not have a single value at a particular combination of x and y. I suppose you could trick persp into plotting just the corners of a grid while assigning the output to a res object (as illustrated in the persp help page), and then using lines(trans3d(x,y,z,res ) ) and points(trans3d(x,y,z, res) ) on the x,y,z of your interest. As Jim Holtman's tagline says: What problem are you trying to solve.? -- David Thanks ../Murli library(scatterplot3d) dnaStr-structure(list(x = c(-0.975688, -6.23153132820699, -9.09624485603214, -8.63556544492323, -4.93169249022181, 0.543553938928959, 5.64174931291628, 8.34431911056127, 7.41509534849297, 3.25793817052871, -2.65307138974052, -8.1739402999332, -11.2739770817494, -11.0523961376876, -0.975688, 4.65283498179159, 8.34690510167613, 8.79226549387186, 5.76337877843935, 0.36011024214207, -5.41074167495601, -9.54555893851015, -10.4135928669112, -7.82046928259718, -2.87048496956275, 2.43182259657596, 5.78000473462146, 5.86423147485841, 0, 0, -0.0747010058197876, -0.224103017459363, -0.373505029098938, -0.522907040738513, -0.672309052378088, -0.895991523123606, -1.19395445297507, -1.49191738282653, -1.78988031267799, -2.08784324252945, -2.45924790562486, -2.90409430196421), y = c(9.258795, 6.91702748519505, 1.94818850352474, -3.96996047465861, -8.44783195266353, -9.85357650887797, -7.72879278806027, -2.98312550512766, 2.29012749945630, 6.14410676772742, 6.95007482866252, 4.24353089435013, -1.04920275957987, -7.29644254501929, -9.258795, -8.06401751967253, -4.00546526835325, 1.49980094252710, 6.27267077967238, 8.41152490344017, 7.02084844979693, 2.35565979843151, -3.73136662594352, -9.10401295836816, -11.8667592918697, -11.1209788118259, -7.53850052521814, -2.53029214376759, 0, 0, -0.102817113851368, -0.308451341554103, -0.514085569256838, -0.719719796959573, -0.925354024662308, -1.23322653332276, -1.64333732294093, -2.05344811255911, -2.46355890217728, -2.87366969179545, -3.38486435525866, -3.99714289256690), z = c(-1.8, 1.59, 4.69619670884637, 7.75612339689976, 11.0469981052342, 14.6030384546677, 18.357177803767, 22.4500668968389, 26.4412083543305, 29.9717539469394, 32.9734610690970, 35.5800854363887, 37.7984507886837, 40.1485063481344, 1.8, 5.19, 8.71511020948371, 12.4692495585831, 16.0252899080165, 19.3161646163510, 22.3760913044043, 25.1539112488595, 27.7605356161511, 30.7622427383088, 34.2927883309177, 38.2839297884093, 42.5850840652024, 47.0021666825248, 0, 3.39, 6.77522880132507, 10.1556864039752, 13.5361440066254, 16.9166016092755, 20.2970592119256, 23.6632300791254, 27.0151142108747, 30.3669983426241, 33.7188824743734, 37.0707666061228, 40.3989288961516, 43.7033693444598), v4 = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), .Names = c(x, y, z, v4), row.names = c(NA, -42L), class = data.frame) endPtlength-length(dnaStr$x) endPt1-endPtlength/3 maxX-max(dnaStr$x) minX-min(dnaStr$x) minY-min(dnaStr$y) maxY-max(dnaStr$y) minZ-min(dnaStr$z) maxZ-max(dnaStr$z)
Re: [R] Running an ANOVA with a BY
On Sep 28, 2009, at 11:39 AM, baxterj wrote: I have a simple 1 way anova coded like summary(ANOVA1way - aov(Value ~ WellID, data = welldata)) How can I use the BY function to do this ANOVA for each group using another variable in the dataset?? I tried coding it like this, but it doesn't seem to work. Since you have not offered a reproducible example, we are left to choose our own. Checking the help page for by we see that a problem extremely similar to yours is already solved. I choose not to attach() the data for well-understood reasons: anova.LMH - by(warpbreaks, warpbreaks$tension, function(x) aov(breaks ~ wool, data=x) ) summary(ANOVA1way - by(welldata, Analyte, function(x) aov(Value ~ WellID, data = welldata))) In SAS I would code it like this: Proc sort data=welldata; by analyte; run; Proc glm data=welldata; by analyte; class wellid; model value = wellid; run; David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] re trieve user input from an tcl/tk interface
Hello everyone, this is my first post here and I hope I signed up correctly and someone will take me by the hand and help me out. I am new to R and cannot figure out what to do here... ... I want to have an User Interface that requests input. I want to save this input to a variable to use it later on. I was able to do this with a modalDiaglog ( http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples/modalDialog.html like this ) but I cannot figure out how to do this with multiple values to be read. I want to run a rather simple simulation and the user has to be able to set multiple parameters (say, number of trials and stimuli). The onOK-function should then collect these parameters and save them to variables (I guess). Here is a snippet of my code. Could someone tell me what to do? Am I heading in the right direction or is my approach hopeless? :p - OnOK = function(){ # I reckon this is where the important stuff should happen... tkdestroy(tt) } require(tcltk) tclRequire(BWidget) tt = tktoplevel() trials = tclVar(100) # I want to suggest default values but they should be editable. entry.trials = tkentry(tt, width = 3, textvariable = trials) tkgrid(tklabel(tt,text=Number of trials:)) tkgrid(entry.trials) Stimuli = tclVar(10)# I want to suggest default values but they should be editable. entry.Stimuli = tkentry(tt, width = 3, textvariable = Stimuli) tkgrid(tklabel(tt, text = Number of stimuli:)) tkgrid(entry.Stimuli) OK.but = tkbutton(tt,text= Go! ,command=OnOK) tkgrid(OK.but) tkfocus(tt) - Of course, I also tried to find a solution via google but couldn't really find anything. http://tolstoy.newcastle.edu.au/R/e4/help/08/07/17422.html The only thing I found was this post which never got answered . I hope someone can help. Thank you very much for reading this and any help is greatly appreciated! Best regards, Florian -- View this message in context: http://www.nabble.com/retrieve-user-input-from-an-tcl-tk-interface-tp25651905p25651905.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] (no subject)
Hello, I am having a problem understanding the lda package. I have a dataset here: [,1] [,2] [,3] [1,] 2.95 6.630 [2,] 2.53 7.790 [3,] 3.57 5.650 [4,] 3.16 5.470 [5,] 2.58 4.461 [6,] 2.16 6.221 [7,] 3.27 3.521 If I do the following; names(d)-c(y,x1,x2) d$x1 = d$x1 * 100 d$x2 = d$x2 * 100 g-lda( y ~ x1 + x2, data=d) v2 - predict(g, d), I get; LD1 1 -2.3769280 2 -2.7049437 3 -3.4748309 4 -0.9599825 5 4.2293774 6 2.6052193 7 2.6820884 However, If I do it manually, rawdata-matrix(scan(tab1_1.dat),ncol=3,byrow=T) group - rawdata[,1] X - 100 * rawdata[,2:3] Apf - X[group==1,] Af - X[group==0,] xbar1 - apply(Af, 2, mean) S1 - var(Af) N1 - dim(Af)[1] xbar2 - apply(Apf, 2, mean) S2 - var(Apf) N2 - dim(Apf)[1] S-((N1-1)*S1+(N2-1)*S2)/(N1+N2-2) Sinv=solve(S) d-xbar1-xbar2 b - Sinv %*% d v - X %*% b, I get; [,1] [1,] 164.4283 [2,] 166.2492 [3,] 170.5232 [4,] 156.5622 [5,] 127.7540 [6,] 136.7704 [7,] 136.3436 It seems there is an extra step that I am missing? The predict step that adds a constant to the second set of values? Can anyone clear this up for me? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help with time series
Hello I'm working with a bunch of time series data. The data are downloaded from a server and stored as ascii files prior to reading them into R. After reading the data sets read into R with no problem and I can us the ts function to coerce them to time series, sometimes this works and sometimes it fails. For example. P38_SubB - read.table(A:\\Data\\Output\\Sparrow\\Hydro_Data\\P38_Annual.txt, header=TRUE, skip=1, sep=,, stringsAsFactors=FALSE) P38_SubB$GS - rep(0.85, dim(P38_SubB)[1]) # GS is the ground surface elevation, which is not included in the initial file. P38_SubB$Depth - as.numeric(P38_SubB$P38_stage) - as.numeric(P38_SubB$GS) # now I subtract the ground surface to calculate water depth P38_SubB.ts - ts(data=P38_SubB, frequency = (1), start=c(1981, 1), end=c(2009,1)) # Here I convert to a time series plot(P38_SubB.ts,ylab=Mean Annual Water Depth, xlab=Year, main=CSSP Subpopulation B \n Water Depth P38) These lines work. But these do not: R3110_SubC - read.table(A:\\Data\\Output\\Sparrow\\Hydro_Data\\R3110_Annual.txt, header=TRUE, skip=1, sep=,, stringsAsFactors=FALSE) R3110_SubC$GS - rep(5.10, dim(R3110_SubC)[1]) R3110_SubC$Depth - as.numeric(R3110_SubC$R3110_stage) - as.numeric(R3110_SubC$GS) R3110_SubC.ts - ts(data=R3110_SubC, frequency = (1), start=c(1984, 1), end=c(2009, 1)) Warning message: NAs introduced by coercion I am asured that the input data are the same in each input file, yet some coerce correctly while others result in the error which prevents plotting. Are there any known issues with ts, what are the suggested solutions? Thanks Steve Friedman Ph. D. Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 steve_fried...@nps.gov Office (305) 224 - 4282 Fax (305) 224 - 4147 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] SAS user now converting to R - Help with Transpose
library(reshape) melt(dataset) # assuming dataset is a data.frame. --- On Mon, 9/28/09, baxterj j...@vt.edu wrote: From: baxterj j...@vt.edu Subject: [R] SAS user now converting to R - Help with Transpose To: r-help@r-project.org Received: Monday, September 28, 2009, 10:24 AM I am just starting to code in R and need some help as I am used to doing this in SAS. I have a dataset that looks like this: Chemical Well1 Well2 Well3 Well4 BOD 13.2 14.2 15.5 14.2 O2 7.8 2.6 3.5 2.4 TURB 10.2 14.6 18.5 17.3 and so on with more chemicals I would like to transpose my data so that it looks like this: Chemical WellID Value BOD Well1 13.2 BOD Well2 14.2 BOD Well3 15.5 BOD Well4 14.2 O2 Well1 7.8 O2 Well2 2.6 and so on In sas I would code it like this: proc sort data=ds1; by chemical; run; Proc Transpose data=ds1 out=ds2; by chemical; var Well1 Well2 Well3 Well4; run; data ds3; set ds2; rename _name_ = WellID; rename col1 = value; run; How can I do this in R?? Any help is much appreciated. Thanks! -- View this message in context: http://www.nabble.com/SAS-user-now-converting-to-R---Help-with-Transpose-tp25645393p25645393.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ The new Internet Explorer® 8 - Faster, safer, easier. Optimized for Yaho __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Running an ANOVA with a BY
baxterj wrote: I have a simple 1 way anova coded like summary(ANOVA1way - aov(Value ~ WellID, data = welldata)) How can I use the BY function to do this ANOVA for each group using another variable in the dataset?? I tried coding it like this, but it doesn't seem to work. summary(ANOVA1way - by(welldata, Analyte, function(x) aov(Value ~ WellID, data = welldata))) In SAS I would code it like this: Proc sort data=welldata; by analyte; run; Proc glm data=welldata; by analyte; class wellid; model value = wellid; run; Any suggestions??? Given you have asked two questions on translating SAS idioms to R, you might be a candidate for Bob Muenchen's book which some people have previously recommended: [3] Robert A. Muenchen. R for SAS and SPSS Users. Springer Series in Statistics and Computing. Springer, 2009. ISBN: 978-0-387-09417-5. [ bib | Discount Info | Publisher Info ] This book demonstrates which of the add-on packages are most like SAS and SPSS and compares them to R's built-in functions. It steps through over 30 programs written in all three packages, comparing and contrasting the packages' differing approaches. The programs and practice datasets are available for download. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Running an ANOVA with a BY
I downloaded the package and got it to work with the coding: model - function(df) {aov(values ~ WellID, data = twelldata)} ANOVA1way - dlply(twelldata, .(Analyte), model) print(ANOVA1way) This gives me degrees of freedom and sum of squares for each anova per analyte. However, I cant get the summary(ANOVA1way) to work so that I can get p-values, etc... How can I do this? Jodi Tobias Verbeke-2 wrote: baxterj wrote: I have a simple 1 way anova coded like summary(ANOVA1way - aov(Value ~ WellID, data = welldata)) How can I use the BY function to do this ANOVA for each group using another variable in the dataset?? I tried coding it like this, but it doesn't seem to work. summary(ANOVA1way - by(welldata, Analyte, function(x) aov(Value ~ WellID, data = welldata))) In SAS I would code it like this: Proc sort data=welldata; by analyte; run; Proc glm data=welldata; by analyte; class wellid; model value = wellid; run; Look at the plyr package for a general solution to this type of problems: http://cran.r-project.org/web/packages/plyr/index.html and its introductory guide on the package home page: http://had.co.nz/plyr/ HTH, Tobias __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Running-an-ANOVA-with-a-BY-tp25645413p25650273.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] multiclass SVM (e1071 package): number of estimated models
Dear John, there *are* indeed 3 classifiers trained, as you can see from predict(model, iris, decision.values = TRUE) However, the coefficients are stored in a compressed format -- see svminternals.txt in the /doc subdirectory. Best David - I run multiclass SVM for iris data, which contains 3 classes (manual page 52). Based on manual, the implementation uses one-against-one approach: k*(k-1)/2 binary classifiers trained. However, I am getting only two models instead of three (only two columns of support vectors and coefficients). What do I miss? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Select.spatial on spplots
Charlie's reply is quite correct - without an example that others can reproduce, it is hard to offer help. Julius is also ignoring the fact that spplot() methods use lattice graphics, while select.spatial() uses base graphics. The spplot() method for SpatialPointsDataFrames objects does provide an identify= argument, but this is not the same as select.spatial(), which lets the user select points spatially by drawing a polygon around the ones to be selected. Roger Bivand cls59 wrote: Julius Tesoro wrote: Hi everyone. I posted this on R-sig-geo but got no response. Can select.spatial() be used in an existing spplot? I have tried selecting points (eq) from a plot generated from sp. However, when I invoke select.spatial(eq). It generates only the points without the background containing the faults. I need the background to select which earthquakes coalesce on which fault. Is there an alternative? eq.pts-list(sp.points,eq, col=blue, lwd=0.5, pch = 4) spplot(faults,Dip, xlim = c(11,12), ylim = c(376,389), sp.layout=list(eq.pts), col = heat.colors(3)) select.spatial(eq) Cheers, Julius Tesoro Unfortunately, it looks like select.spatial() wipes the plotting region by executing it's own call to plot(). However, the function it's self is very, very simple, just type: select.spatial To see what goes on inside. It looks like you could obtain point-wise selection by just calling identify(): identify( coordinates( eq )[,1], coordinates( eq )[,2] To use areas, call locator() and then process the results using point.in.polygon(). As for whether this will work using a spplot-- I really couldn't say. I was not able to reproduce a spplot using the information you provided-- lack of a working example may be a reason you got nothing but silence on R-sig-geo. Good luck! -Charlie -- View this message in context: http://www.nabble.com/Select.spatial-on-spplots-tp25632668p25652492.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 3D to 2D projection
Thank you for this info. I think this has what I need. Cheers../murli -Original Message- From: hadley wickham [mailto:h.wick...@gmail.com] Sent: Monday, September 28, 2009 2:27 PM To: Nair, Murlidharan T Cc: David Winsemius; r-h...@stat.math.ethz.ch Subject: Re: [R] 3D to 2D projection Have you used persp or trans3d before? Here is a little piece of data that I am want to convert to 2d. I can plot (x,z) or (z,y). I know there is a better way to convert it to 2d. I did it long time back in my 3d geometry class. http://en.wikipedia.org/wiki/3D_projection ? Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rsolnp- Error (Help!)
Thanks, Ravi. I have attached the code again. (Still the same error) http://www.nabble.com/file/p25652730/OptTS.txt OptTS.txt Ravi Varadhan wrote: I was trying to run your code, but it seems like you haven’t specified the parameter called `Strk', so I was unable to run it. Can you send a fully reproducible code? jholtman wrote: It means that your expression max(tt[2] - 10 * tol, nineq) is returning NA: Notice I get the same error: if (1==1)1 [1] 1 if (NA == 1) 1 Error in if (NA == 1) 1 : missing value where TRUE/FALSE needed Check your script and see why it is NA. you might need: max(tt[2] - 10 * tol, nineq, na.rm=TRUE) If your data has NAs. On Sun, Sep 27, 2009 at 5:29 PM, tushar_kul tus...@gmail.com wrote: Hi I am relatively new to R and was trying to run an optimization problem using rsolnp. I am getting an error which seems to be not related to my construct of the optimization equations. Error in if (max(tt[2] - 10 * tol, nineq) = 0) rho = 0 : missing value where TRUE/FALSE needed I have attached the file code. I would greatly appreciate any help. Many thanks http://www.nabble.com/file/p25637806/OptTS.txt OptTS.txt -- -- View this message in context: http://www.nabble.com/rsolnp--Error-%28Help%21%29-tp25637806p25652730.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 3D to 2D projection
The code works fine. Was interested in understanding how to project it on a particular plane so that it looks symmetrical. I think I can get that info here from what Hadley sent http://en.wikipedia.org/wiki/3D_projection Cheers../Murli -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Monday, September 28, 2009 2:57 PM To: Nair, Murlidharan T Cc: r-h...@stat.math.ethz.ch Subject: Re: [R] 3D to 2D projection On Sep 28, 2009, at 1:41 PM, Nair, Murlidharan T wrote: David, Have you used persp or trans3d before? Yes, both. persp requires an x-y grid of a particular sort ... from the help page Arguments x, y locations of grid lines at which the values in z are measured. These must be in ascending order. By default, equally spaced values from 0 to 1 are used. If x is a list, its components x$x and x$y are used for x and y, respectively. Here is a little piece of data that I am want to convert to 2d. Perhaps you should define what you mean by convert to 2d in more expansive terms. I can plot (x,z) or (z,y). I know there is a better way to convert it what is it??? The use of indefinite pronouns is quite commonly a barrier to communication. ... to 2d. I did it long time back in my 3d geometry class. I am not precisely clear what you are having problems with. I executed your code without any error reported. The s3d object looked like the 2- d projection of a single spiraled DNA-like shape. Then I plotted the points you specified, again without error or modification of your code and now I see: a) a second intertwined spiral curve, b) circles at the endpoints of the pseudo-3D segments, and c) a line that goes through the apparent center of the now pseudo-double-helix. Very pretty. s3d is now as set of 4 functions that will project points or other objects into that virtual space: str(s3d) List of 4 $ xyz.convert:function (x, y = NULL, z = NULL) $ points3d :function (x, y = NULL, z = NULL, type = p, ...) $ plane3d:function (Intercept, x.coef = NULL, y.coef = NULL, lty = dashed, lty.box = NULL, ...) $ box3d :function (...) You may have problems if the abstract object (a spiral) does not conform to the requirements of the function you are considering (persp), since it may not have a single value at a particular combination of x and y. I suppose you could trick persp into plotting just the corners of a grid while assigning the output to a res object (as illustrated in the persp help page), and then using lines(trans3d(x,y,z,res ) ) and points(trans3d(x,y,z, res) ) on the x,y,z of your interest. As Jim Holtman's tagline says: What problem are you trying to solve.? -- David Thanks ../Murli library(scatterplot3d) dnaStr-structure(list(x = c(-0.975688, -6.23153132820699, -9.09624485603214, -8.63556544492323, -4.93169249022181, 0.543553938928959, 5.64174931291628, 8.34431911056127, 7.41509534849297, 3.25793817052871, -2.65307138974052, -8.1739402999332, -11.2739770817494, -11.0523961376876, -0.975688, 4.65283498179159, 8.34690510167613, 8.79226549387186, 5.76337877843935, 0.36011024214207, -5.41074167495601, -9.54555893851015, -10.4135928669112, -7.82046928259718, -2.87048496956275, 2.43182259657596, 5.78000473462146, 5.86423147485841, 0, 0, -0.0747010058197876, -0.224103017459363, -0.373505029098938, -0.522907040738513, -0.672309052378088, -0.895991523123606, -1.19395445297507, -1.49191738282653, -1.78988031267799, -2.08784324252945, -2.45924790562486, -2.90409430196421), y = c(9.258795, 6.91702748519505, 1.94818850352474, -3.96996047465861, -8.44783195266353, -9.85357650887797, -7.72879278806027, -2.98312550512766, 2.29012749945630, 6.14410676772742, 6.95007482866252, 4.24353089435013, -1.04920275957987, -7.29644254501929, -9.258795, -8.06401751967253, -4.00546526835325, 1.49980094252710, 6.27267077967238, 8.41152490344017, 7.02084844979693, 2.35565979843151, -3.73136662594352, -9.10401295836816, -11.8667592918697, -11.1209788118259, -7.53850052521814, -2.53029214376759, 0, 0, -0.102817113851368, -0.308451341554103, -0.514085569256838, -0.719719796959573, -0.925354024662308, -1.23322653332276, -1.64333732294093, -2.05344811255911, -2.46355890217728, -2.87366969179545, -3.38486435525866, -3.99714289256690), z = c(-1.8, 1.59, 4.69619670884637, 7.75612339689976, 11.0469981052342, 14.6030384546677, 18.357177803767, 22.4500668968389, 26.4412083543305, 29.9717539469394, 32.9734610690970, 35.5800854363887, 37.7984507886837, 40.1485063481344, 1.8, 5.19, 8.71511020948371, 12.4692495585831, 16.0252899080165, 19.3161646163510, 22.3760913044043, 25.1539112488595, 27.7605356161511, 30.7622427383088, 34.2927883309177, 38.2839297884093, 42.5850840652024, 47.0021666825248, 0, 3.39, 6.77522880132507, 10.1556864039752, 13.5361440066254, 16.9166016092755, 20.2970592119256, 23.6632300791254,
Re: [R] Running an ANOVA with a BY
baxterj wrote: I downloaded the package and got it to work with the coding: model - function(df) {aov(values ~ WellID, data = twelldata)} Hmm.. I guess you mean to use 'data = df' instead of 'data = twelldata' ANOVA1way - dlply(twelldata, .(Analyte), model) print(ANOVA1way) This gives me degrees of freedom and sum of squares for each anova per analyte. However, I cant get the summary(ANOVA1way) to work so that I can get p-values, etc... How can I do this? You need to extend your model function: - extract the bits you want - construct a result data frame - return it and use a ddply For example (non-tested): model - function(df) { lmObj - lm(values ~ WellID, data = df) summaryLmObj - summary(lmObj) res - data.frame(intercept = coef(lmObj)[1], adjr2 = summaryLmObj$adj.r.squared) # extract and insert anything return(res) } (ANOVA1way - ddply(twelldata, .(Analyte), model)) HTH, Tobias Tobias Verbeke-2 wrote: baxterj wrote: I have a simple 1 way anova coded like summary(ANOVA1way - aov(Value ~ WellID, data = welldata)) How can I use the BY function to do this ANOVA for each group using another variable in the dataset?? I tried coding it like this, but it doesn't seem to work. summary(ANOVA1way - by(welldata, Analyte, function(x) aov(Value ~ WellID, data = welldata))) In SAS I would code it like this: Proc sort data=welldata; by analyte; run; Proc glm data=welldata; by analyte; class wellid; model value = wellid; run; Look at the plyr package for a general solution to this type of problems: http://cran.r-project.org/web/packages/plyr/index.html and its introductory guide on the package home page: http://had.co.nz/plyr/ HTH, Tobias __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] xyplot help - colors and break in plot
Dear List, I am new to lattice plots, and am having problems with getting my plot to do what I want. Specifically: 1. I would like the legend to have the same symbols as the plot. I tried simpleKey but can't seem to get it to work with autoKey. Right now my plot has dots (pch=19) and my legend shows circles. 2. I have nine groups but xyplot seems to only be using seven colors, so two groups have the same color. How do I get a range of nine colors? 3. I have one group who's y range is much greater than all the others. I would like to split the plot somehow so that the bottom part shows ylim=c(0,200) and the top shows ylim=c(450,550). Is this possible? What I have so far is: library(lattice) xyplot(m.dp.area$Area.km2 ~ m.dp.area$DataPoint, m.dp.area, groups = m.dp.area$Manta, main = Cummulative area of 100% MCP, xlab = Data Point, ylab = MCP Area, ylim = c(0,150), scales = list(tck = c(1, 0)), #Removes tics on top and r-axis pch=19,cex=.4, auto.key = list(title = Mantas, x = .05, y=.95, corner = c(0,1),border = TRUE)) #Legend Thanks, Tim Tim Clark Department of Zoology University of Hawaii __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] re trieve user input from an tcl/tk interface
Here is one approach: getInfo - function() { require(tcltk) tt - tktoplevel() trials - tclVar(100) Stimuli - tclVar(10) f1 - tkframe(tt) tkpack(f1, side='top') tkpack(tklabel(f1, text='trials: '), side='left') tkpack(tkentry(f1, textvariable=trials), side='left') f2 - tkframe(tt) tkpack(f2, side='top') tkpack(tklabel(f2, text='Stimuli: '), side='left') tkpack(tkentry(f2, textvariable=Stimuli), side='left') tkpack(tkbutton(tt, text='Exit', command=function() tkdestroy(tt)), side='right', anchor='s') tkwait.window(tt) return( c(trials=as.numeric(tclvalue(trials)), Stimuli=as.numeric(tclvalue(Stimuli))) ) } out - getInfo() out Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of einsundeins Sent: Monday, September 28, 2009 2:02 PM To: r-help@r-project.org Subject: [R] re trieve user input from an tcl/tk interface Hello everyone, this is my first post here and I hope I signed up correctly and someone will take me by the hand and help me out. I am new to R and cannot figure out what to do here... ... I want to have an User Interface that requests input. I want to save this input to a variable to use it later on. I was able to do this with a modalDiaglog ( http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples/modalDialog.html like this ) but I cannot figure out how to do this with multiple values to be read. I want to run a rather simple simulation and the user has to be able to set multiple parameters (say, number of trials and stimuli). The onOK- function should then collect these parameters and save them to variables (I guess). Here is a snippet of my code. Could someone tell me what to do? Am I heading in the right direction or is my approach hopeless? :p - OnOK = function(){ # I reckon this is where the important stuff should happen... tkdestroy(tt) } require(tcltk) tclRequire(BWidget) tt = tktoplevel() trials = tclVar(100) # I want to suggest default values but they should be editable. entry.trials = tkentry(tt, width = 3, textvariable = trials) tkgrid(tklabel(tt,text=Number of trials:)) tkgrid(entry.trials) Stimuli = tclVar(10)# I want to suggest default values but they should be editable. entry.Stimuli = tkentry(tt, width = 3, textvariable = Stimuli) tkgrid(tklabel(tt, text = Number of stimuli:)) tkgrid(entry.Stimuli) OK.but = tkbutton(tt,text= Go! ,command=OnOK) tkgrid(OK.but) tkfocus(tt) - Of course, I also tried to find a solution via google but couldn't really find anything. http://tolstoy.newcastle.edu.au/R/e4/help/08/07/17422.html The only thing I found was this post which never got answered . I hope someone can help. Thank you very much for reading this and any help is greatly appreciated! Best regards, Florian -- View this message in context: http://www.nabble.com/retrieve-user- input-from-an-tcl-tk-interface-tp25651905p25651905.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to visualize gini coefficient in each node in RF?
Dear all, I am working with randomForest package and I am interested in examining the Gini importance measures that are used as a general indicator of feature relevance. Is there a possibility of getting the Gini measure that is being estimated in each tree by the output of the getTree() function? Thanks a lot, Chrysanthi [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rsolnp- Error (Help!)
Since you only have box constraints, you do not need to use rsolnp. You can use `nlminb' or optim's L-BFGS-B or `spg' in BB. I ran your problem using these algorithms, and I was not sure that I was getting a local minimum. Check your functions carefully, it seems like you may have some mistakes. Y1 - optim(par=p0, fn=opti, method=L-BFGS-B, lower=lCons, upper=uCons) Y2 - nlminb(start=p0, obj=opti, lower=lCons, upper=uCons) Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvarad...@jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.html -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of tushar_kul Sent: Monday, September 28, 2009 4:52 PM To: r-help@r-project.org Subject: Re: [R] rsolnp- Error (Help!) Thanks, Ravi. I have attached the code again. (Still the same error) http://www.nabble.com/file/p25652730/OptTS.txt OptTS.txt Ravi Varadhan wrote: I was trying to run your code, but it seems like you haven’t specified the parameter called `Strk', so I was unable to run it. Can you send a fully reproducible code? jholtman wrote: It means that your expression max(tt[2] - 10 * tol, nineq) is returning NA: Notice I get the same error: if (1==1)1 [1] 1 if (NA == 1) 1 Error in if (NA == 1) 1 : missing value where TRUE/FALSE needed Check your script and see why it is NA. you might need: max(tt[2] - 10 * tol, nineq, na.rm=TRUE) If your data has NAs. On Sun, Sep 27, 2009 at 5:29 PM, tushar_kul tus...@gmail.com wrote: Hi I am relatively new to R and was trying to run an optimization problem using rsolnp. I am getting an error which seems to be not related to my construct of the optimization equations. Error in if (max(tt[2] - 10 * tol, nineq) = 0) rho = 0 : missing value where TRUE/FALSE needed I have attached the file code. I would greatly appreciate any help. Many thanks http://www.nabble.com/file/p25637806/OptTS.txt OptTS.txt -- -- View this message in context: http://www.nabble.com/rsolnp--Error-%28Help%21%29-tp25637806p25652730.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with time series
On Sep 28, 2009, at 4:07 PM, steve_fried...@nps.gov wrote: Hello I'm working with a bunch of time series data. The data are downloaded from a server and stored as ascii files prior to reading them into R. After reading the data sets read into R with no problem and I can us the ts function to coerce them to time series, sometimes this works and sometimes it fails. For example. P38_SubB - read.table(A:\\Data\\Output\\Sparrow\\Hydro_Data\\P38_Annual.txt, header=TRUE, skip=1, sep=,, stringsAsFactors=FALSE) P38_SubB$GS - rep(0.85, dim(P38_SubB)[1]) # GS is the ground surface elevation, which is not included in the initial file. P38_SubB$Depth - as.numeric(P38_SubB$P38_stage) - as.numeric(P38_SubB$GS) # now I subtract the ground surface to calculate water depth P38_SubB.ts - ts(data=P38_SubB, frequency = (1), start=c(1981, 1), end=c(2009,1)) # Here I convert to a time series plot(P38_SubB.ts,ylab=Mean Annual Water Depth, xlab=Year, main=CSSP Subpopulation B \n Water Depth P38) These lines work. But these do not: R3110_SubC - read.table(A:\\Data\\Output\\Sparrow\\Hydro_Data\\R3110_Annual.txt, header=TRUE, skip=1, sep=,, stringsAsFactors=FALSE) R3110_SubC$GS - rep(5.10, dim(R3110_SubC)[1]) R3110_SubC$Depth - as.numeric(R3110_SubC$R3110_stage) - as.numeric(R3110_SubC$GS) R3110_SubC.ts - ts(data=R3110_SubC, frequency = (1), start=c(1984, 1), end=c(2009, 1)) Warning message: NAs introduced by coercion I am asured that the input data are the same in each input file, yet some coerce correctly while others result in the error which prevents plotting. They probably look that same on someone's spreadsheet but could have some invisible character of smart-quotes or some other formatting anomaly. What does str show you about the types of your variables? How about summary or Design::describe? Do they say htat the data.frames have tha same structure and lack of string anomalies. Are there any known issues with ts, what are the suggested solutions? -- David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] for loop
On Tue, 29 Sep 2009, Antonio Paredes wrote: Can somebody give a hint on how to speed-up the following loop: for(j in 0:KM1) { k=j*60 for(i in 1:60) { dat$yvac[k+i]= rbinom(1,dat$nvac[k+i],dat$p.trt[j+i]) } } K1=999 How about: rbinom((KM1 + 1)*60, dat$nvac, dat$p.trt[rep(0:KM1, each=60) + 1:60]) HTH Ray Brownrigg __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] help with lda function
I am having a problem understanding the lda package. I have a dataset here: [,1] [,2] [,3] [1,] 2.95 6.630 [2,] 2.53 7.790 [3,] 3.57 5.650 [4,] 3.16 5.470 [5,] 2.58 4.461 [6,] 2.16 6.221 [7,] 3.27 3.521 If I do the following; names(d)-c(y,x1,x2) d$x1 = d$x1 * 100 d$x2 = d$x2 * 100 g-lda( y ~ x1 + x2, data=d) v2 - predict(g, d), I get; LD1 1 -2.3769280 2 -2.7049437 3 -3.4748309 4 -0.9599825 5 4.2293774 6 2.6052193 7 2.6820884 However, If I do it manually, rawdata-matrix(scan(tab1_1. dat),ncol=3,byrow=T) group - rawdata[,1] X - 100 * rawdata[,2:3] Apf - X[group==1,] Af - X[group==0,] xbar1 - apply(Af, 2, mean) S1 - var(Af) N1 - dim(Af)[1] xbar2 - apply(Apf, 2, mean) S2 - var(Apf) N2 - dim(Apf)[1] S-((N1-1)*S1+(N2-1)*S2)/(N1+N2-2) Sinv=solve(S) d-xbar1-xbar2 b - Sinv %*% d v - X %*% b, I get; [,1] [1,] 164.4283 [2,] 166.2492 [3,] 170.5232 [4,] 156.5622 [5,] 127.7540 [6,] 136.7704 [7,] 136.3436 I am having a problem understanding the lda package. I have a dataset here: [,1] [,2] [,3] [1,] 2.95 6.630 [2,] 2.53 7.790 [3,] 3.57 5.650 [4,] 3.16 5.470 [5,] 2.58 4.461 [6,] 2.16 6.221 [7,] 3.27 3.521 If I do the following; names(d)-c(y,x1,x2) d$x1 = d$x1 * 100 d$x2 = d$x2 * 100 g-lda( y ~ x1 + x2, data=d) v2 - predict(g, d), I get; LD1 1 -2.3769280 2 -2.7049437 3 -3.4748309 4 -0.9599825 5 4.2293774 6 2.6052193 7 2.6820884 However, If I do it manually, rawdata-matrix(scan(tab1_1.dat),ncol=3,byrow=T) group - rawdata[,1] X - 100 * rawdata[,2:3] Apf - X[group==1,] Af - X[group==0,] xbar1 - apply(Af, 2, mean) S1 - var(Af) N1 - dim(Af)[1] xbar2 - apply(Apf, 2, mean) S2 - var(Apf) N2 - dim(Apf)[1] S-((N1-1)*S1+(N2-1)*S2)/(N1+N2-2) Sinv=solve(S) d-xbar1-xbar2 b - Sinv %*% d v - X %*% b, I get; [,1] [1,] 164.4283 [2,] 166.2492 [3,] 170.5232 [4,] 156.5622 [5,] 127.7540 [6,] 136.7704 [7,] 136.3436 It seems there is an extra step that I am missing? The predict step that adds a constant to the second set of values? Can anyone clear this up for me? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with lda function
Your results are the same (after scaling and sign reversal) out to the 4th decimal place as those from lda (which by the way is almost certainly from the MASS package and not from an impossible to find lda package.) read.table(textConnection(txt)) V1 1 164.4283 2 166.2492 3 170.5232 4 156.5622 5 127.7540 6 136.7704 7 136.3436 est -read.table(textConnection(txt)) scale(est) V1 [1,] 0.7656185 [2,] 0.8712707 [3,] 1.1192567 [4,] 0.3092117 [5,] -1.3622976 [6,] -0.8391481 [7,] -0.8639119 attr(,scaled:center) V1 151.233 attr(,scaled:scale) V1 17.23484 LD1est - read.table(textConnection( LD1 + 1 -2.3769280 + 2 -2.7049437 + 3 -3.4748309 + 4 -0.9599825 + 5 4.2293774 + 6 2.6052193 + 7 2.6820884), header=T) scale(LD1est) LD1 1 -0.7656170 2 -0.8712721 3 -1.1192555 4 -0.3092138 5 1.3622976 6 0.8391505 7 0.8639103 attr(,scaled:center) LD1 -3.172066e-17 attr(,scaled:scale) LD1 3.104591 On Sep 28, 2009, at 5:54 PM, Pete Shepard wrote: I am having a problem understanding the lda package. I have a dataset here: [,1] [,2] [,3] [1,] 2.95 6.630 [2,] 2.53 7.790 [3,] 3.57 5.650 [4,] 3.16 5.470 [5,] 2.58 4.461 [6,] 2.16 6.221 [7,] 3.27 3.521 If I do the following; names(d)-c(y,x1,x2) d$x1 = d$x1 * 100 d$x2 = d$x2 * 100 g-lda( y ~ x1 + x2, data=d) v2 - predict(g, d), I get; LD1 1 -2.3769280 2 -2.7049437 3 -3.4748309 4 -0.9599825 5 4.2293774 6 2.6052193 7 2.6820884 However, If I do it manually, rawdata-matrix(scan(tab1_1. dat),ncol=3,byrow=T) group - rawdata[,1] X - 100 * rawdata[,2:3] Apf - X[group==1,] Af - X[group==0,] xbar1 - apply(Af, 2, mean) S1 - var(Af) N1 - dim(Af)[1] xbar2 - apply(Apf, 2, mean) S2 - var(Apf) N2 - dim(Apf)[1] S-((N1-1)*S1+(N2-1)*S2)/(N1+N2-2) Sinv=solve(S) d-xbar1-xbar2 b - Sinv %*% d v - X %*% b, I get; [,1] [1,] 164.4283 [2,] 166.2492 [3,] 170.5232 [4,] 156.5622 [5,] 127.7540 [6,] 136.7704 [7,] 136.3436 I am having a problem understanding the lda package. I have a dataset here: [,1] [,2] [,3] [1,] 2.95 6.630 [2,] 2.53 7.790 [3,] 3.57 5.650 [4,] 3.16 5.470 [5,] 2.58 4.461 [6,] 2.16 6.221 [7,] 3.27 3.521 If I do the following; names(d)-c(y,x1,x2) d$x1 = d$x1 * 100 d$x2 = d$x2 * 100 g-lda( y ~ x1 + x2, data=d) v2 - predict(g, d), I get; LD1 1 -2.3769280 2 -2.7049437 3 -3.4748309 4 -0.9599825 5 4.2293774 6 2.6052193 7 2.6820884 However, If I do it manually, rawdata-matrix(scan(tab1_1.dat),ncol=3,byrow=T) group - rawdata[,1] X - 100 * rawdata[,2:3] Apf - X[group==1,] Af - X[group==0,] xbar1 - apply(Af, 2, mean) S1 - var(Af) N1 - dim(Af)[1] xbar2 - apply(Apf, 2, mean) S2 - var(Apf) N2 - dim(Apf)[1] S-((N1-1)*S1+(N2-1)*S2)/(N1+N2-2) Sinv=solve(S) d-xbar1-xbar2 b - Sinv %*% d v - X %*% b, I get; [,1] [1,] 164.4283 [2,] 166.2492 [3,] 170.5232 [4,] 156.5622 [5,] 127.7540 [6,] 136.7704 [7,] 136.3436 It seems there is an extra step that I am missing? The predict step that adds a constant to the second set of values? Can anyone clear this up for me? David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Polynomial Fitting
Hello All, This might seem elementary to everyone, but please bear with me. I've just spent some time fitting poly functions to time series data in R using lm() and predict(). I want to analyze the functions once I've fit them to the various data I'm studying. However, after pulling the first function into Octave (just by plotting the polynomial function using fplot() over the same x interval as my original data) I was surprised to see that the scale and y values were vastly different than the ones I have in R. The basic shape of the polynomial over the same interval looks similar in both Octave and R, but the y values are all different. When I compute the y values using the polynomial function by hand, the y values from the Octave plot are returned and not the y values predicted by predict() in R. Can someone explain to me why the values for a function would be different in R? Thanks, Chris Carleton _ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Tool for solving equations
Does exist any tool in R to solve equations, especially complex exponential equations? For example: y = 100*exp(b*(1-exp(c*x))/c) If it is so, then what is the package i have to use and what is algorythm for this solving? Thank you for advance. With regard, Dmitry. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] plot error -- figure margins too large
Hi, I am trying to plot my dataset, consisting of one column with numeric values and one column with group IDs. The set is similar to the following df. df - NULL for ( i in 1:20) { tmp1 - runif(1000,0,5) tmp2 - cbind(tmp1,i) df - rbind(df,tmp2) } Now I would like to plot the numeric column, stratified by the group IDs, in a single figure. First, I partitioned the frame into a 1x20 array. Then I plot the numeric values of each group in a sub-plot. Note that only should the left most y-axis be shown, and the x-axis is only the group numbers. Also the margin between two sub-frame should be fairly small so it looks like only one figure, rather than 20 figures. The following codes were used to achieve my goal, but I got an error saying figure margins too large. cols - sample(rainbow(20)) par(mfrow=c(1,20)) for ( i in 1:20) { tmp - subset(df, df[,2]==i) if(i!=1) { plot(df[,1],axes=F,col=cols[i],frame.plot=F,xlab=NA,pch=19,ylim=c(0,5)) mtext(i, line=1,side=1) } else{ plot(df[,1],axes=F,col=cols[i],frame.plot=F,xlab=NA,pch=19,ylim=c(0,5)) axis(2,at=0:5) mtext(i, line=1,side=1) } } I also tried to set the margins by modifying the _par_ command: par(mfrow=c(1,20),mar=(4,2,4,0.05)) Still, received the same error. The other experiment: While I was using the following codes, it almost showed what I would like, but the figure ended with only the last sub-plot. The only difference between the two is I was attempting to add a main-label in the figure. cols - sample(rainbow(20)) par(mfrow=c(1,20),mar=c(4,0.05,3,0.05)) plot.new() mtext(Multiple figures in a plot,line=1,at=13) for ( i in 1:20) { tmp - subset(df, df[,2]==i) if(i!=1) { plot(df[,1],axes=F,col=cols[i],frame.plot=F,xlab=NA,pch=19,ylim=c(0,5)) mtext(i, line=1,side=1) } else{ plot(df[,1],axes=F,col=cols[i],frame.plot=F,xlab=NA,pch=19,mar=c(4,4,3,0.05),ylim=c(0,5)) axis(2,at=0:5) mtext(i, line=1,side=1) } } Any suggestions and advices are welcome. Thanks, Mike __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] xyplot help - colors and break in plot
2009/9/29 Tim Clark mudiver1...@yahoo.com: Dear List, I am new to lattice plots, and am having problems with getting my plot to do what I want. Specifically: 1. I would like the legend to have the same symbols as the plot. I tried simpleKey but can't seem to get it to work with autoKey. Right now my plot has dots (pch=19) and my legend shows circles. Rather than the pch = 19 argument, use par.settings = simpleTheme(pch = 19, cex = .4) 2. I have nine groups but xyplot seems to only be using seven colors, so two groups have the same color. How do I get a range of nine colors? Yes, in the default theme, there are seven colours: see trellis.par.get(superpose.symbol) You can change the set of colours yourself by modifying that list (via trellis.par.set). An easier option is to use one of the predefined ColorBrewer palettes, with custom.theme() from the latticeExtra package, or just simpleTheme(). See ?brewer.pal (RColorBrewer package) You will see there are a few qualitative color palettes with 9 or more colours: e.g. brewer.pal(9, Set1) brewer.pal(12, Set3) 3. I have one group who's y range is much greater than all the others. I would like to split the plot somehow so that the bottom part shows ylim=c(0,200) and the top shows ylim=c(450,550). Is this possible? Yes... in the absence of a reproducible example, maybe something like xyplot(Area.km2 ~ DataPoint | (Area.km2 200), m.dp.area, groups = Manta, scales = list(y = free)) or AreaRange - shingle(Area.km2, rbind(c(0,200),c(450,550))) xyplot(Area.km2 ~ DataPoint | AreaRange, m.dp.area, groups = Manta, scales = list(y = free)) What I have so far is: library(lattice) xyplot(m.dp.area$Area.km2 ~ m.dp.area$DataPoint, m.dp.area, groups = m.dp.area$Manta, main = Cummulative area of 100% MCP, xlab = Data Point, ylab = MCP Area, ylim = c(0,150), scales = list(tck = c(1, 0)), #Removes tics on top and r-axis pch=19,cex=.4, auto.key = list(title = Mantas, x = .05, y=.95, corner = c(0,1),border = TRUE)) #Legend Thanks, Tim Tim Clark Department of Zoology University of Hawaii __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Felix Andrews / 安福立 Postdoctoral Fellow Integrated Catchment Assessment and Management (iCAM) Centre Fenner School of Environment and Society [Bldg 48a] The Australian National University Canberra ACT 0200 Australia M: +61 410 400 963 T: + 61 2 6125 1670 E: felix.andr...@anu.edu.au CRICOS Provider No. 00120C -- http://www.neurofractal.org/felix/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Polynomial Fitting
On 29/09/2009, at 10:52 AM, chris carleton wrote: Hello All, This might seem elementary to everyone, but please bear with me. I've just spent some time fitting poly functions to time series data in R using lm() and predict(). I want to analyze the functions once I've fit them to the various data I'm studying. However, after pulling the first function into Octave (just by plotting the polynomial function using fplot() over the same x interval as my original data) I was surprised to see that the scale and y values were vastly different than the ones I have in R. The basic shape of the polynomial over the same interval looks similar in both Octave and R, but the y values are all different. When I compute the y values using the polynomial function by hand, the y values from the Octave plot are returned and not the y values predicted by predict() in R. Can someone explain to me why the values for a function would be different in R? Thanks, Chris Carleton Presumably because you were using poly() with the argument raw left equal to its default, i.e. FALSE. cheers, Rolf Turner P. S. The posting guide asks for reproducible examples . R. T. ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Tool for solving equations
On Sep 28, 2009, at 6:22 PM, Dmitry Gospodaryov wrote: Does exist any tool in R to solve equations, especially complex exponential equations? For example: y = 100*exp(b*(1-exp(c*x))/c) If it is so, then what is the package i have to use and what is algorythm for this solving? Thank you for advance. With regard, Dmitry. You want an analytical solution of 100*exp(b*(1-exp(c*x))/c) = 0 in terms of b and c? library(Ryacas) # perhaps Or do you want to specify b and c and get a numerical solution? ?uniroot ?polyroot Or find the minimum of y? ?nlm # and others mentioned on that page. -- David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] packGrob and dynamic resizing
Hi I could speculate, but what would be more useful would be some profiling results. If you could try Rprof() on your examples (and post me the results directly), that would provide some useful information to see if some speed-ups could be made. Paul baptiste auguie wrote: Hi, I just tried a fourth variant, closer to what ggplot2 uses (I think): to each grob is assigned a viewport with row and column positions (in my example during their construction, with ggplot2 upon editing), and they're all plotted in a given grid.layout. The timing is poor compared to pushing and upping viewports (twice as long). Why would that be? All the best, baptiste (the full, self-contained comparison file is attached, run as: R --vanilla -f comparison.r ) # below is version 4 only makeContentInVp - function(d){ content - as.character(unlist(c(d))) nc - ncol(d) nr - nrow(d) n2nm - function(nr, nc){ expand.grid(seq(1, nr), seq(1, nc)) } vp.ind - n2nm(nr, nc) textii - function(d, gp=gpar(), name=content-label-){ function(ii) textGrob(label=d[ii], gp=gp, name=paste(name, ii, sep=), vp=viewport(layout.pos.row=vp.ind[ii, 1], layout.pos.col=vp.ind[ii, 2])) } makeOneLabel - textii(d=content, gp=gpar(col=blue)) lg - lapply(seq_along(content), makeOneLabel) list(lg=lg, nrow=nrow(d), ncol=ncol(d)) } ## table4 uses grobs that already have a viewport assigned table4 - function(content){ padding - unit(4, mm) lg - content$lg ## retrieve the widths and heights of all textGrobs wg - lapply(lg, grobWidth) # list of grob widths hg - lapply(lg, grobHeight) # list of grob heights ## concatenate this units widths.all - do.call(unit.c, wg) # all grob widths heights.all - do.call(unit.c, hg)#all grob heights ## matrix-like operations on units to define the table layout widths - colMax.units(widths.all, content$ncol) # all column widths heights - rowMax.units(heights.all, content$nrow) # all row heights vp - viewport(layout=grid.layout(content$nrow,content$ncol, w=widths+padding, h=heights+padding)) grid.draw(gTree(children=do.call(gList, lg), vp=vp)) } # uncomment for timing d - head(iris) #d - iris content2 - makeContentInVp(d) # grid.newpage() # system.time(table3(content)) ##user system elapsed ## 4.422 0.091 4.787 grid.newpage() system.time(table4(content2)) ##user system elapsed ## 8.810 0.184 9.555 2009/9/25 hadley wickham h.wick...@gmail.com: This matches my experience with ggplot2 - I have been gradually moving away from frameGrob and packGrob because doing the placement myself is much faster (and for most of the cases I'm interested in, the full power of packGrob is not needed) Hadley -- http://had.co.nz/ -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 p...@stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Tool for solving equations
On Sep 28, 2009, at 8:49 PM, David Winsemius wrote: On Sep 28, 2009, at 6:22 PM, Dmitry Gospodaryov wrote: Does exist any tool in R to solve equations, especially complex exponential equations? For example: y = 100*exp(b*(1-exp(c*x))/c) If you plot that function, you see that it is asymptotically zero in its positive domain: b=10; c=1 plot(-10:10, 100*exp(b*(1-exp(c*(-10:10)))/c)) 100*exp(b*(1-exp(c*(-10:10)))/c) [1] 2.201647e+06 2.199930e+06 2.195270e+06 2.182652e+06 2.148720e+06 2.059123e+06 [7] 1.834007e+06 1.338820e+06 5.691034e+05 5.562432e+04 1.00e+02 3.448235e-06 [13] 1.789295e-26 1.295885e-81 1.683418e-231 0.00e+00 0.00e +00 0.00e+00 [19] 0.00e+00 0.00e+00 0.00e+00 ... So that raises the question of what you are really trying to accomplish. If it is so, then what is the package i have to use and what is algorythm for this solving? Thank you for advance. With regard, Dmitry. -- David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] colMeans()
On 09/28/2009 10:47 PM, Matteo Mattiuzzi wrote: Hello, I use the function rowMeans(x,na.rm=T). The result is the mean of valid values in each row, with NA removed. A for me very important information is, from how many valid n this mean has computed. The thing is, that I apply this function on many millions of rows, so the time it takes is multiplied by this factor! (so getting this with rowSums(is.na(x)) it takes much to long) I was trying to look inside the function maybe to get not only the means but the valid n too, but I wasn't able. Hi Matteo, The number of observations that are NOT NA can be calculated with: sum(!is.na(x)) and you can see this in action in the valid.n function in the prettyR package. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Data formatting for matplot
Henrique, Thanks for the suggestion. I think I may not understand matplot() because the graph did not come out like it should have. Gabor suggested: library(lattice) xyplot(y ~ x, mydat, groups = id) Which gave what I was looking for. Is there a way to get matplot() to give the same graph? I don't have to use matplot(), but would like to understand its use. Thanks, Tim Tim Clark Department of Zoology University of Hawaii --- On Sun, 9/27/09, Henrique Dallazuanna www...@gmail.com wrote: From: Henrique Dallazuanna www...@gmail.com Subject: Re: [R] Data formatting for matplot To: Tim Clark mudiver1...@yahoo.com Cc: r-help@r-project.org Date: Sunday, September 27, 2009, 4:47 PM You can try this: matplot(do.call(cbind, split.dat)) On Sun, Sep 27, 2009 at 11:42 PM, Tim Clark mudiver1...@yahoo.com wrote: Dear List, I am wanting to produce a multiple line plot, and know I can do it with matplot but can't get my data in the format I need. I have a dataframe with three columns; individuals ID, x, and y. I have tried split() but it gives me a list of matrices, which is closer but not quite what I need. For example: id-rep(seq(1,5,1),length.out=100) x-rnorm(100,5,1) y-rnorm(100,20,5) mydat-data.frame(id,x,y) split.dat-split(mydat[,2:3],mydat[,1]) I would appreciate your help in either how to get this into a format acceptable to matplot or other options for creating a multiple line plot. Thanks, Tim Tim Clark Department of Zoology University of Hawaii __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] A programming question - is what I want to do possible in R?
I have a large data frame, 77 rows, with 10 columns. Each row represents a unique individual with 10 characteristics, some of which are categorical factors and some continuous numeric variables. Each of the ten variables is important (the 10 columns obviously correspond to the individuals of interest). Importantly, this data set represents a population (not sample) of people with a certain medical condition. What I want to do is to select 2000 random samples of between 2 and 24 individuals, preserving all the information. I can easily write loops that will sample from 1:77 2 - 24 times, what I really want to know is there any way to easily link the output of loops like that to the data set so I don't have to trawl through and do it manually 2000 times? Any advice on whether I should even attempt that in R, or try some sort of hash table in C or somewhere, would be appreciated. -- View this message in context: http://www.nabble.com/A-programming-question---is-what-I-want-to-do-possible-in-R--tp25639955p25639955.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] xyplot lmline: error message.
Hi, I am trying to produce an xyplot with a regression line. The data should be represented as log/log but when I fit the lmline I receive an error message - the plot is fine without the log transformation, but the then the plot is meaningless. I know it must be something simple, but I just can't see it. Hope someone can help... Thanks. xyplot(log(Pk)~log(k),data=rwpk,cex=1, panel=function(x,y){ panel.grid(h=-1, v=-1) panel.xyplot(x,y,cex=1.0) panel.lmline(x,y) }) http://www.nabble.com/file/p25641684/rwpk.csv rwpk.csv -- View this message in context: http://www.nabble.com/xyplot---lmline%3A-error-message.-tp25641684p25641684.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] xyplot lmline: error message.
On 9/28/2009 4:07 AM, Andrewjohnclose wrote: Hi, I am trying to produce an xyplot with a regression line. The data should be represented as log/log but when I fit the lmline I receive an error message - the plot is fine without the log transformation, but the then the plot is meaningless. I know it must be something simple, but I just can't see it. Hope someone can help... Thanks. What do you expect to happen with the values of 0 in Pk? Have a look at this: log(rwpk$Pk) [1] -1.108663 -1.698269 -2.551046 -2.796881 [5] -2.733368 -2.796881 -3.352407 -3.352407 [9] -4.074542 -3.244194 -4.074542 -4.342806 [13] -3.506558 -5.521461 -4.342806 -4.074542 [17] -4.342806 -3.506558 -4.342806 -4.342806 [21] -Inf -3.816713 -4.342806 -4.710531 [25] -4.342806 -Inf -Inf -4.074542 [29] -5.521461 -4.342806 -4.710531 -5.521461 [33] -5.521461 -5.521461 -5.521461 -5.521461 [37] -Inf -Inf -Inf -5.521461 [41] -Inf -Inf -5.521461 -Inf [45] -Inf -Inf -5.521461 -Inf [49] -Inf -Inf -Inf -Inf [53] -Inf -5.521461 -Inf -Inf [57] -Inf -Inf -Inf -Inf [61] -Inf -Inf -Inf -5.521461 If you want to ignore the zeros, perhaps you could do this: library(lattice) rwpk - read.csv(file='http://www.nabble.com/file/p25641684/rwpk.csv') xyplot(log(Pk) ~ log(k), data=subset(rwpk, Pk !=0), type=c('p','r')) xyplot(log(Pk)~log(k),data=rwpk,cex=1, panel=function(x,y){ panel.grid(h=-1, v=-1) panel.xyplot(x,y,cex=1.0) panel.lmline(x,y) }) http://www.nabble.com/file/p25641684/rwpk.csv rwpk.csv -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Starting values in “arima.sim” fu nction
Hello,  Could someone tell me please how can I find out which starting values has R used for the simulation?  I have AR(1) model:  y(t)=0.2*y(t-1)+0.2*y(t-2) + e(t)   (e(t) is distributed according standard normal distribution)  I need y(0) (or y(t-1), then t=1) values for my following calculations (it is very important parameter). Should I assume that y(0)=mean(yt) or set y(0)=0?  How to find out, which values R uses for y(0), y(-1) and so on?  Thank you very much for the answer in advance!  Best regards, Lina [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Re ading Functions that are in a Vector
Hi, You said, sumstats - c(mean,sd) sumstats[1] #Gives this error but this is not an error! You created a list that contains two functions, and sumstats[1] simply prints the first one. HTH, baptiste __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rsolnp- Error (Help!)
Thanks, but I do not have max(tt[2] - 10 * tol, nineq) in my script. Therefore, could the error be getting generated by rsolnp itself ? jholtman wrote: It means that your expression max(tt[2] - 10 * tol, nineq) is returning NA: Notice I get the same error: if (1==1)1 [1] 1 if (NA == 1) 1 Error in if (NA == 1) 1 : missing value where TRUE/FALSE needed Check your script and see why it is NA. you might need: max(tt[2] - 10 * tol, nineq, na.rm=TRUE) If your data has NAs. On Sun, Sep 27, 2009 at 5:29 PM, tushar_kul tus...@gmail.com wrote: Hi I am relatively new to R and was trying to run an optimization problem using rsolnp. I am getting an error which seems to be not related to my construct of the optimization equations. Error in if (max(tt[2] - 10 * tol, nineq) = 0) rho = 0 : missing value where TRUE/FALSE needed I have attached the file code. I would greatly appreciate any help. Many thanks http://www.nabble.com/file/p25637806/OptTS.txt OptTS.txt -- View this message in context: http://www.nabble.com/rsolnp--Error-%28Help%21%29-tp25637806p25637806.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/rsolnp--Error-%28Help%21%29-tp25637806p25641703.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] dichromat, regexp, and grid objects
Dear list, The dichromat package defines a dichromat function which Collapses red-green color distinctions to approximate the effect of the two common forms of red-green colour blindness, protanopia and deuteranopia. library(dichromat) library(grid) colorStrip - function (colors = 1:3, draw = TRUE) { x - seq(0, 1 - 1/length(colors), length = length(colors)) y - rep(0.5, length(colors)) my.grob - grid.rect(x = unit(x, npc), y = unit(y, npc), width = unit(1/length(colors), npc), height = unit(1, npc), just = left, hjust = NULL, vjust = NULL, default.units = npc, name = NULL, gp = gpar(fill = colors, col = colors, draw = draw, vp = NULL)) my.grob } colorStrip(1:3) colorStrip(dichromat(1:3)) Now what would be nice is a function that can edit the colours (col and fill parameters) of an existing grob. dichromatit - function(x){ .NotYetImplemented() } dichromatit(colorStrip()) It could allow high-level testing for visual perception of lattice and ggplot2 plots, p1 = xyplot(1~1) p2 = qplot(1,1, colour= I(red)) dichromatit(p1) p2 + dichromatit() One approach could be to use only integer codes for colours, and modify the current palette() (works also for base graphics). But this is quite a stringent request for lattice and ggplot2 which define many named colours in their various themes and scales. Therefore I'd like to think of an approach based on a recursive modification of a grob's gpar components. Does this seem doable with some regular expression magic [*]? All the best, baptiste [*]: http://xkcd.com/208/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] GAM predict
Hi there, I am predicting animal presence in a grid using a binomial distribution and the package mgcv. My data has many many zeros, is there a way to consider this and counterbalance it in R. The results I get are probabilities of less than 0.5 and I believe the zero inflated dataset is affecting it. I am already using a weight in my model with the effort spent in each grid cell. Thanks for your feedback, with my best regards, Simone __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Scaling data
Hello all I have a data frame representing a matrix of data. For each of my variables (rows) I want to scale the data between 0 (representing the minimum value in that row) and 1 (representing the maximum value in that row). I was wondering if there is a simple function anywhere that does this? Jonathan -- AstraZeneca UK Limited is a company incorporated in Engl...{{dropped:21}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] xtable - how to add a sum of values in a row column?
I wonder if the right approach is to convert temp.ts into a matrix, add the column at the end, and then call xtable()... ...anyone have any suggestions? TIA. - Ken Ken-JP wrote: Hi, I saw this example for 2.10 Time series in the xtable gallery documentation. http://cran.r-project.org/web/packages/xtable/vignettes/xtableGallery.pdf How would I add a column at the end Total which sums the row, with minimal changes to the code below? Thanks in advance. - Ken 2.10 Time series temp.ts - ts(cumsum(1 + round(rnorm(100), 0)), start = c(1954, + 7), frequency = 12) temp.table - xtable(temp.ts, digits = 0) caption(temp.table) - Time series example print(temp.table, floating = FALSE) Time series example Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 1954 2 3 6 8 11 10 1955 11 13 15 16 16 18 20 22 21 22 24 24 1956 25 26 28 28 28 28 29 31 31 32 33 34 1957 35 36 38 39 39 41 42 42 41 42 43 45 1958 46 46 47 47 49 51 54 56 58 59 61 61 1959 62 61 62 62 62 63 62 64 64 66 67 68 1960 67 67 69 71 74 75 77 78 79 80 82 81 1961 84 86 87 88 89 91 94 94 94 94 96 97 1962 98 99 101 102 104 105 108 107 106 107 -- View this message in context: http://www.nabble.com/xtable---how-to-add-a-%22sum-of-values-in-a-row%22-column--tp25635552p25643331.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Scaling data
On 28-Sep-09 09:55:04, Dry, Jonathan R wrote: Hello all I have a data frame representing a matrix of data. For each of my variables (rows) I want to scale the data between 0 (representing the minimum value in that row) and 1 (representing the maximum value in that row). I was wondering if there is a simple function anywhere that does this? Jonathan Example: set.seed(12345) X - matrix(rnorm(50),ncol=5) X #[,1] [,2] [,3][,4] [,5] # [1,] 0.5855288 -0.1162478 0.7796219 0.81187318 1.1285108 # [2,] 0.7094660 1.8173120 1.4557851 2.19683355 -2.3803581 # [3,] -0.1093033 0.3706279 -0.6443284 2.04919034 -1.0602656 # [4,] -0.4534972 0.5202165 -1.5531374 1.63244564 0.9371405 # [5,] 0.6058875 -0.7505320 -1.5977095 0.25427119 0.8544517 # [6,] -1.8179560 0.8168998 1.8050975 0.49118828 1.4607294 # [7,] 0.6300986 -0.8863575 -0.4816474 -0.32408658 -1.4130988 # [8,] -0.2761841 -0.3315776 0.6203798 -1.66205024 0.5674033 # [9,] -0.2841597 1.1207127 0.6121235 1.76773385 0.5831877 #[10,] -0.9193220 0.2987237 -0.1623110 0.02580105 -1.3067988 t(apply(X,1,function(x){(x-min(x))/(max(x)-min(x))})) # [,1] [,2] [,3] [,4] [,5] # [1,] 0.5637853 0.000 0.7197136 0.7456233 1.000 # [2,] 0.6750480 0.9170842 0.8380998 1.000 0.000 # [3,] 0.3058291 0.4601749 0.1337652 1.000 0.000 # [4,] 0.3451928 0.6508554 0.000 1.000 0.7817338 # [5,] 0.8986346 0.3454820 0.000 0.7552443 1.000 # [6,] 0.000 0.7272473 1.000 0.6373475 0.9049509 # [7,] 1.000 0.2578024 0.4558793 0.5329941 0.000 # [8,] 0.6071889 0.5829194 1.000 0.000 0.9767894 # [9,] 0.000 0.6846712 0.4368079 1.000 0.4227058 #[10,] 0.2413400 1.000 0.7128445 0.8300101 0.000 with identical results if applied to Y - as.data.frame(X) Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 28-Sep-09 Time: 11:11:23 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Scaling data
Try this, library(ggplot2) apply(matrix(10*rnorm(10),2), 1, ggplot2::rescale) HTH, baptiste 2009/9/28 Dry, Jonathan R jonathan@astrazeneca.com: Hello all I have a data frame representing a matrix of data. For each of my variables (rows) I want to scale the data between 0 (representing the minimum value in that row) and 1 (representing the maximum value in that row). I was wondering if there is a simple function anywhere that does this? Jonathan -- AstraZeneca UK Limited is a company incorporated in Engl...{{dropped:21}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Scaling data
On 09/28/2009 07:55 PM, Dry, Jonathan R wrote: Hello all I have a data frame representing a matrix of data. For each of my variables (rows) I want to scale the data between 0 (representing the minimum value in that row) and 1 (representing the maximum value in that row). I was wondering if there is a simple function anywhere that does this? Hi Jonathan, There are a number of such functions, but a particularly easy one in your case is rescale. Baptiste has already mentioned the one in ggplot, so I'll plug mine in plotrix: mat1-matrix(sample(1:20,16),nrow=4) library(plotrix) t(apply(mat1,1,rescale,c(0,1))) Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Trendline and R square value
Hi I would like to display the trendline and the R-square value in a xy scatter in R. For example if I want to plot f vs g I add the trendline using the commands below library(quantreg) plot(f,g) abline(rq(g~f)) however I don't know how to display the R2 in the graph. Thank you in advance. Kind regards Maria [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Re ading Functions that are in a Vector
Also, have a look at each() in the plyr package, library(plyr) each(length, mean, var)(rnorm(100)) baptiste 2009/9/28 trumpetsaz stephaniezim...@gmail.com: I am trying to write a function that will have an input of a vector of functions. Here is a simplistic example. sumstats - c(mean,sd) sumstats[1] #Gives this error # sumstats[1] #[[1]] #function (x, ...) #UseMethod(mean) #environment: namespace:base I thought about restricting the input to character variables such as the following sumstats2 - c(mean,sd) Is there a way to change mean to the function mean? -- View this message in context: http://www.nabble.com/Reading-Functions-that-are-in-a-Vector-tp25639720p25639720.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] implementation of matrix logarithm (inverse of matrix exponential)
DB == Douglas Bates ba...@stat.wisc.edu on Sun, 27 Sep 2009 17:25:39 -0500 writes: DB There is a logm function in the expm package in the expm project on DB R-forge. See http://expm.R-forge.R-project.org/ DB Martin was the person who added that function so I will defer to his DB explanations of what it does. I know he has been traveling and it may DB be a day or two before he can get to this thread. Indeed, thank you, Doug. Yes, I'd strongly recommend using the expm package's logm(). Computing Matrix Exponentials and Logs (and more) reliably is actually a quite a science. The recent addition of expm::logm() actually happened based on a master thesis done here at ETH, and that itself was based on *THE* reference on these topics, Higham, N.~J. (2008). _Functions of Matrices: Theory and Computation_; Society for Industrial and Applied Mathematics, Philadelphia, PA, USA. and so is are part of latest methods for the matrix exponential, expm(). One reason that I haven't released 'expm' to CRAN yet, has been that it hasn't been entirely clear to me what the default 'method' should be. The (currently only one) method, uses in Matrix::expm() is no longer state of the art (and yes, I had plans to also update that). An interesting side-question is actually how to deal with such issues, of active research rendering the state of the art to a moving target. In Matlab, I see they just provide the current method, so are not bug-back-compatible with previous versions of itself. In R, I'd at least want to provide an optional 'method' argument and keep former methods available. The question still remain if it's okay to change the default method, as the state of the art advances. For the matrix functions expm(), logm(), etc., I'd say yes, the default should be allowed to change. Martin Maechler, ETH Zurich DB On Sun, Sep 27, 2009 at 11:44 AM, Charles C. Berry cbe...@tajo.ucsd.edu wrote: On Sat, 26 Sep 2009, spencerg wrote: Sylvester's formula (http://en.wikipedia.org/wiki/Sylvester%27s_formula) applies to a square matrix A = S L solve(S), where L = a diagonal matrix and S = matrix of eigenvectors. Let f be an analytic function [for which f(A) is well defined]. Then f(A) = S f(L) solve(S). We can code this as follows: sylvester - function(x, f){ n - nrow(x) eig - eigen(x) vi - solve(eig$vectors) with(eig, (vectors * rep(f(values), each=n)) %*% vi) } logm - function(x)sylvester(x, log) Example: A - matrix(1:4, 2) eA - expm(A) logm(eA) With Chuck Berry's example, we get the following: M - matrix( c(0,1,0,0), 2 ) sylvester(M, log) The case I gave would be sylvester( as.matrix( expm( M ) ), log ) for which the perfectly sensible answer is M, not what appears here: Error in solve.default(eig$vectors) : system is computationally singular: reciprocal condition number = 1.00208e-292 This is a perfectly sensible answer in this case. We get the same result from sylvester(M, exp), though expm(M) works fine. A better algorithm for this could be obtains by studying the code for expm in the Matrix package and the references in the associated help page. I doubt that code already in R will handle cases requiring Jordan blocks for evaluation of the matrix logarithm (which cases arise in the context of discrete state, continuous time Markov chains) without requiring one to built that code more or less from scratch. I'd be happy to hear that this is not so. HTH, Chuck Hope this helps. Spencer Gabor Grothendieck wrote: Often one uses matrix logarithms on symmetric positive definite matrices so the assumption of being symmetric is sufficient in many cases. On Sat, Sep 26, 2009 at 7:28 PM, Charles C. Berry cbe...@tajo.ucsd.edu wrote: On Sat, 26 Sep 2009, Gabor Grothendieck wrote: OK. Try this: library(Matrix) M - matrix(c(2, 1, 1, 2), 2); M [,1] [,2] [1,] 2 1 [2,] 1 2 Right. expm( M ) is diagonalizable. But for M - matrix( c(0,1,0,0), 2 ) you get the wrong result. Maybe I should have added that I do not see the machinery in R for dealing with Jordan blocks. HTH, Chuck # log of expm(M) is original matrix M with(eigen(expm(M)), vectors %*% diag(log(values)) %*% t(vectors)) [,1] [,2] [1,] 2 1 [2,] 1 2 On Sat, Sep 26, 2009 at 6:24 PM, Charles C. Berry cbe...@tajo.ucsd.edu wrote: On
[R] How to assess object names within a function in lapply or l_ply?
Dear All, to produce output of several columns of a data frame, I tried to use lapply and also l_ply. In both cases, I would like to print a header line containing also the name of the respective column in the data frame. For example, I would like the following lapply(data.frame(a=1:3, b=2:4), function(x) print(deparse(substitute(x to produce: [1] a [1] b and not, what it actually does: [1] X[[1L]] [1] X[[2L]] $a [1] X[[1L]] $b [1] X[[2L]] or with l_ply (plyr package) l_ply(data.frame(a=1:3, b=2:4), function(x) print(deparse(substitute(x to produce: [1] a [1] b and not, what it actually does: [1] .data[[i]] [1] .data[[i]] Is this possible? Thanks, Heinz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to assess object names within a function in lapply or l_ply?
You can use names insteed: DF - data.frame(a=1:3, b=2:4) lapply(names(DF), function(x){ print(x) DF[x] }) On Mon, Sep 28, 2009 at 8:22 AM, Heinz Tuechler tuech...@gmx.at wrote: Dear All, to produce output of several columns of a data frame, I tried to use lapply and also l_ply. In both cases, I would like to print a header line containing also the name of the respective column in the data frame. For example, I would like the following lapply(data.frame(a=1:3, b=2:4), function(x) print(deparse(substitute(x to produce: [1] a [1] b and not, what it actually does: [1] X[[1L]] [1] X[[2L]] $a [1] X[[1L]] $b [1] X[[2L]] or with l_ply (plyr package) l_ply(data.frame(a=1:3, b=2:4), function(x) print(deparse(substitute(x to produce: [1] a [1] b and not, what it actually does: [1] .data[[i]] [1] .data[[i]] Is this possible? Thanks, Heinz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to assess object names within a function in lapply or l_ply?
Thank you, Henrique, my example was simplified. In a more complexe function I want to use the objects, not just their names. In your solution, I have to adapt the function itself, depending on the name of the data.frame, which I would like to avoid. Thanks, Heinz At 13:36 28.09.2009, Henrique Dallazuanna wrote: You can use names insteed: DF - data.frame(a=1:3, b=2:4) lapply(names(DF), function(x){ print(x) DF[x] }) On Mon, Sep 28, 2009 at 8:22 AM, Heinz Tuechler tuech...@gmx.at wrote: Dear All, to produce output of several columns of a data frame, I tried to use lapply and also l_ply. In both cases, I would like to print a header line containing also the name of the respective column in the data frame. For example, I would like the following lapply(data.frame(a=1:3, b=2:4), function(x) print(deparse(substitute(x to produce: [1] a [1] b and not, what it actually does: [1] X[[1L]] [1] X[[2L]] $a [1] X[[1L]] $b [1] X[[2L]] or with l_ply (plyr package) l_ply(data.frame(a=1:3, b=2:4), function(x) print(deparse(substitute(x to produce: [1] a [1] b and not, what it actually does: [1] .data[[i]] [1] .data[[i]] Is this possible? Thanks, Heinz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Data formatting for matplot
Tim, With Gabor examples, I understand this, You can get a similar graph with plot: with(mydat, plot(x, y, col = id)) On Mon, Sep 28, 2009 at 3:01 AM, Tim Clark mudiver1...@yahoo.com wrote: Henrique, Thanks for the suggestion. I think I may not understand matplot() because the graph did not come out like it should have. Gabor suggested: library(lattice) xyplot(y ~ x, mydat, groups = id) Which gave what I was looking for. Is there a way to get matplot() to give the same graph? I don't have to use matplot(), but would like to understand its use. Thanks, Tim Tim Clark Department of Zoology University of Hawaii --- On Sun, 9/27/09, Henrique Dallazuanna www...@gmail.com wrote: From: Henrique Dallazuanna www...@gmail.com Subject: Re: [R] Data formatting for matplot To: Tim Clark mudiver1...@yahoo.com Cc: r-help@r-project.org Date: Sunday, September 27, 2009, 4:47 PM You can try this: matplot(do.call(cbind, split.dat)) On Sun, Sep 27, 2009 at 11:42 PM, Tim Clark mudiver1...@yahoo.com wrote: Dear List, I am wanting to produce a multiple line plot, and know I can do it with matplot but can't get my data in the format I need. I have a dataframe with three columns; individuals ID, x, and y. I have tried split() but it gives me a list of matrices, which is closer but not quite what I need. For example: id-rep(seq(1,5,1),length.out=100) x-rnorm(100,5,1) y-rnorm(100,20,5) mydat-data.frame(id,x,y) split.dat-split(mydat[,2:3],mydat[,1]) I would appreciate your help in either how to get this into a format acceptable to matplot or other options for creating a multiple line plot. Thanks, Tim Tim Clark Department of Zoology University of Hawaii __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Data formatting for matplot
Tim, If you really want to use matplot, it's not hard. You need to feed it a matrix of x-values and a corresponding matrix of y-values. id - rep(1:5, len=100) x - rnorm(100,5,1) y - rnorm(100,20,5) xm - matrix(x, ncol = 5, byrow = TRUE) ym - matrix(y, ncol = 5, byrow = TRUE) matplot(x, y, pch = 1) But surely you don't need matplot: plot(y ~ x, data = mydat, col = id) -Peter Ehlers Tim Clark wrote: Henrique, Thanks for the suggestion. I think I may not understand matplot() because the graph did not come out like it should have. Gabor suggested: library(lattice) xyplot(y ~ x, mydat, groups = id) Which gave what I was looking for. Is there a way to get matplot() to give the same graph? I don't have to use matplot(), but would like to understand its use. Thanks, Tim Tim Clark Department of Zoology University of Hawaii --- On Sun, 9/27/09, Henrique Dallazuanna www...@gmail.com wrote: From: Henrique Dallazuanna www...@gmail.com Subject: Re: [R] Data formatting for matplot To: Tim Clark mudiver1...@yahoo.com Cc: r-help@r-project.org Date: Sunday, September 27, 2009, 4:47 PM You can try this: matplot(do.call(cbind, split.dat)) On Sun, Sep 27, 2009 at 11:42 PM, Tim Clark mudiver1...@yahoo.com wrote: Dear List, I am wanting to produce a multiple line plot, and know I can do it with matplot but can't get my data in the format I need. I have a dataframe with three columns; individuals ID, x, and y. I have tried split() but it gives me a list of matrices, which is closer but not quite what I need. For example: id-rep(seq(1,5,1),length.out=100) x-rnorm(100,5,1) y-rnorm(100,20,5) mydat-data.frame(id,x,y) split.dat-split(mydat[,2:3],mydat[,1]) I would appreciate your help in either how to get this into a format acceptable to matplot or other options for creating a multiple line plot. Thanks, Tim Tim Clark Department of Zoology University of Hawaii __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to assess object names within a function in lapply or l_ply?
Heinz, Try this: lapply(DF, function(x)names(DF)[as.numeric(gsub([^0-9], , deparse(substitute(x]) On Mon, Sep 28, 2009 at 8:43 AM, Heinz Tuechler tuech...@gmx.at wrote: Thank you, Henrique, my example was simplified. In a more complexe function I want to use the objects, not just their names. In your solution, I have to adapt the function itself, depending on the name of the data.frame, which I would like to avoid. Thanks, Heinz At 13:36 28.09.2009, Henrique Dallazuanna wrote: You can use names insteed: DF - data.frame(a=1:3, b=2:4) lapply(names(DF), function(x){ print(x) DF[x] }) On Mon, Sep 28, 2009 at 8:22 AM, Heinz Tuechler tuech...@gmx.at wrote: Dear All, to produce output of several columns of a data frame, I tried to use lapply and also l_ply. In both cases, I would like to print a header line containing also the name of the respective column in the data frame. For example, I would like the following lapply(data.frame(a=1:3, b=2:4), function(x) print(deparse(substitute(x to produce: [1] a [1] b and not, what it actually does: [1] X[[1L]] [1] X[[2L]] $a [1] X[[1L]] $b [1] X[[2L]] or with l_ply (plyr package) l_ply(data.frame(a=1:3, b=2:4), function(x) print(deparse(substitute(x to produce: [1] a [1] b and not, what it actually does: [1] .data[[i]] [1] .data[[i]] Is this possible? Thanks, Heinz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rsolnp- Error (Help!)
I would guess so. It may have to do with the data that you are passing in. On Mon, Sep 28, 2009 at 5:23 AM, tushar_kul tus...@gmail.com wrote: Thanks, but I do not have max(tt[2] - 10 * tol, nineq) in my script. Therefore, could the error be getting generated by rsolnp itself ? jholtman wrote: It means that your expression max(tt[2] - 10 * tol, nineq) is returning NA: Notice I get the same error: if (1==1)1 [1] 1 if (NA == 1) 1 Error in if (NA == 1) 1 : missing value where TRUE/FALSE needed Check your script and see why it is NA. you might need: max(tt[2] - 10 * tol, nineq, na.rm=TRUE) If your data has NAs. On Sun, Sep 27, 2009 at 5:29 PM, tushar_kul tus...@gmail.com wrote: Hi I am relatively new to R and was trying to run an optimization problem using rsolnp. I am getting an error which seems to be not related to my construct of the optimization equations. Error in if (max(tt[2] - 10 * tol, nineq) = 0) rho = 0 : missing value where TRUE/FALSE needed I have attached the file code. I would greatly appreciate any help. Many thanks http://www.nabble.com/file/p25637806/OptTS.txt OptTS.txt -- View this message in context: http://www.nabble.com/rsolnp--Error-%28Help%21%29-tp25637806p25637806.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/rsolnp--Error-%28Help%21%29-tp25637806p25641703.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A programming question - is what I want to do possible in R?
nTime - 15 # how many samples to take randomSamples - lapply(1:2000, function(){ largeDF[sample(nrow(largeDF), nTimes),] }) This will create a list of 2000 dataframes with the samples On Sun, Sep 27, 2009 at 10:45 PM, ewaters ewat...@nchecr.unsw.edu.au wrote: I have a large data frame, 77 rows, with 10 columns. Each row represents a unique individual with 10 characteristics, some of which are categorical factors and some continuous numeric variables. Each of the ten variables is important (the 10 columns obviously correspond to the individuals of interest). Importantly, this data set represents a population (not sample) of people with a certain medical condition. What I want to do is to select 2000 random samples of between 2 and 24 individuals, preserving all the information. I can easily write loops that will sample from 1:77 2 - 24 times, what I really want to know is there any way to easily link the output of loops like that to the data set so I don't have to trawl through and do it manually 2000 times? Any advice on whether I should even attempt that in R, or try some sort of hash table in C or somewhere, would be appreciated. -- View this message in context: http://www.nabble.com/A-programming-question---is-what-I-want-to-do-possible-in-R--tp25639955p25639955.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] xtable - how to add a sum of values in a row column?
Try this: temp.table - xtable(temp.ts, digits = 0) temp.table - xtable(addmargins(as.matrix(as.data.frame(temp.table)), 2), digits = 0) On Sun, Sep 27, 2009 at 2:24 PM, Ken-JP kfmf...@gmail.com wrote: Hi, I saw this example for 2.10 Time series in the xtable gallery documentation. http://cran.r-project.org/web/packages/xtable/vignettes/xtableGallery.pdf How would I add a column at the end Total which sums the row, with minimal changes to the code below? Thanks in advance. - Ken 2.10 Time series temp.ts - ts(cumsum(1 + round(rnorm(100), 0)), start = c(1954, + 7), frequency = 12) temp.table - xtable(temp.ts, digits = 0) caption(temp.table) - Time series example print(temp.table, floating = FALSE) Time series example Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 1954 2 3 6 8 11 10 1955 11 13 15 16 16 18 20 22 21 22 24 24 1956 25 26 28 28 28 28 29 31 31 32 33 34 1957 35 36 38 39 39 41 42 42 41 42 43 45 1958 46 46 47 47 49 51 54 56 58 59 61 61 1959 62 61 62 62 62 63 62 64 64 66 67 68 1960 67 67 69 71 74 75 77 78 79 80 82 81 1961 84 86 87 88 89 91 94 94 94 94 96 97 1962 98 99 101 102 104 105 108 107 106 107 -- View this message in context: http://www.nabble.com/xtable---how-to-add-a-%22sum-of-values-in-a-row%22-column--tp25635552p25635552.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A programming question - is what I want to do possible in R?
On Sep 27, 2009, at 10:45 PM, ewaters wrote: I have a large data frame, 77 rows, with 10 columns. Each row represents a unique individual with 10 characteristics, some of which are categorical factors and some continuous numeric variables. Most of us would consider that a small dataframe, unless of course we entered the values by hand as you may have. Each of the ten variables is important (the 10 columns obviously correspond to the individuals of interest). Importantly, this data set represents a population (not sample) of people with a certain medical condition. You have the world's enumeration of persons with condition X? Besides that obvious objection, if you really thought you had an entire population, there would be little point in doing statistics through random sampling. What I want to do is to select 2000 random samples of between 2 and 24 individuals, preserving all the information. I can easily write loops that will sample from 1:77 2 - 24 times, what I really want to know is there any way to easily link the output of loops like that to the data set so I don't have to trawl through and do it manually 2000 times? If you have a vector, vec of any length that represents a sample from 1:77 and your dataframe is df1, then you can use that index vector to extract a group thusly: df1[vec, ] Example: set.seed(97) df1 - data.frame(casenum=1:77, ht=rnorm(77, 56, 7), wt=rnorm(77, 160, 30) ) df1[c(17, 29, 36, 55, 72), ] casenum ht wt 17 17 62.68708 110.0956 29 29 69.97378 124.9440 36 36 49.97847 101.8919 55 55 57.46707 169.7421 72 72 52.25796 118.2071 Any advice on whether I should even attempt that in R, or try some sort of hash table in C or somewhere, would be appreciated. -- David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Trendline and R square value
Maria, Does rq() provide an R2? Anyway, have a look at ?text. -Peter Ehlers Lathouri, Maria wrote: Hi I would like to display the trendline and the R-square value in a xy scatter in R. For example if I want to plot f vs g I add the trendline using the commands below library(quantreg) plot(f,g) abline(rq(g~f)) however I don't know how to display the R2 in the graph. Thank you in advance. Kind regards Maria [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] synchronisation of time series data using interpolation
I saved the data sets as files and then tried to refer to those files. Therefore the instruction: z1-read.zoo(textConnection(/path/to/test1.txt) means that I wanted to replace the manual data entry for Lines1 with a file containing the data. It seems that your instructions only work when data is typed from the command terminal. I cannot use data stored in separated files. Command terminal output below: lines1-read.table(/path/to/test1.txt) lines2-read.table(/path/to/test2.txt) Warning message: incomplete final line found by readTableHeader on '/path/to/test2.txt' in: read.table(/path/to/test2.txt) This is test1 file: 01:00:00,500 01:00:15,600 01:00:30,750 01:00:45,720 01:01:00,700 01:01:15,725 01:01:30,640 01:01:45,710 This is test2 file: 01:00:12,20 01:01:01,55 01:01:55,22 Then I added a carriage return in test2 file and saved it: 01:00:12,20 01:01:01,55 01:01:55,22 Then I repeated the command terminal entry for lines2: lines2-read.table(/path/to/test2.txt) library(zoo) library(chron) z1-read.zoo(textConnection(lines1),header=FALSE,sep=,,FUN=times) Error in textConnection(lines1) : invalid 'text' argument __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Trendline and R square value
On Sep 28, 2009, at 6:36 AM, Lathouri, Maria wrote: Hi I would like to display the trendline and the R-square value in a xy scatter in R. For example if I want to plot f vs g I add the trendline using the commands below library(quantreg) plot(f,g) abline(rq(g~f)) plot(f,g) Error in plot(f, g) : object 'f' not found abline(rq(g~f)) Error in eval(expr, envir, enclos) : object 'g' not found Anyway, there is a worked example in the help page for rq. however I don't know how to display the R2 in the graph. Thank you in advance. Kind regards Maria David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] probability density function for maximum values in repeated finite samples from a normal distribution??
this is probably not really a R specific question, if so apologies for off-topic posting: I'm interested in the probability density function of the maximum values from repeated samples of size N from a normal distribution: smp - rnorm(N, meanval, stdev) with some mean 'meanval' and standard deviation 'stdev'. I would like to know what is the frequency distribution of max(smp) if I draw many such samples? if I investigate this simply via a simulation, I get of course approximate results (and see that the resulting distribution is not quite normal anymore, that the mean increases with increasing N, etc.). my question: does somebody know whether there exists an analytical expression for the distribution of max(smp) (or where to look)? thanks, joerg __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] launching two RGUI computations from two different Excel workbooks
Hello, I have the following problem: I have excel workbooks connected with R through RExcel package. Data are being loaded from excel, then they are processed in R and then the results are being put in excel. Everything works fine, except the fact that I can't launch two or more excel workbooks (and two or more R servers in the background) at the same time. I have to wait until one computation is finished and then launch another one. It would be much easier and quicker for me to launch two or more computations at the same time. Is this possible to launch two different R servers from Excel? Regards, Wojciech Turski __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] zoo: merging aggregated zoo-objects fails
Hello Gabor, I just tried dput() and it seems that running aggregate deletes the following information from zoo objects: origin = structure(c(1, 1, 1970)) So before merging I added: chron(index(z),origin=c(1,1,1970))-index(z) which solves my problem. Is that behaviour of aggregate.zoo intended or a bug? Yours sincerely, gunnar -- View this message in context: http://www.nabble.com/zoo%3A-merging-aggregated-zoo-objects-fails-tp25633345p25643930.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] zoo: merging aggregated zoo-objects fails
Hello Gabor, thanks for your reply. Please excuse the insufficient description of my problem. I hope this one is better: #Importing my data works basically like this dts - dates(c(19700201,19700201,19700201,19700202,19700202),format=ymd) tms - times(paste(c(21:00, 22:00, 23:00,00:00, 01:00),0,sep=:),format=h:m:s) x - chron(dates=dts,times=tms) z - zoo(c(174.055,174.067,174.076,174.085,174.091),x) #Because I need daily values I run: z - aggregate(z,trunc,mean) #And because I deal with different data sets and need to sum them up I run: m - merge(z,z) When R executes merge() I get the following error message: Fehler in matrix(unlist(lapply(dots, origin)), nrow = 3) : Versuch ein Attribut von NULL zu setzen (Sorry that it's German. It says something like 'Error... Try to set attribute NULL') It's curious that there is no error when I first run merge() and than aggregate(), but this is not possible due to the rest of the programm. So why is merging not possible? Thanks in advance, gunnar R version 2.9.1 (Debian Lenny, XFCE 4.4, EMACS 22.2.1, ESS 5.3.8) -- View this message in context: http://www.nabble.com/zoo%3A-merging-aggregated-zoo-objects-fails-tp25633345p25643639.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] synchronisation of time series data using interpolation
You should be using read.zoo, not read.table. This read.zoo(textConnection(Lines1), ...) becomes read.zoo(test1.txt, ...) etc. See ?read.zoo and read the three vignettes in the zoo package. On Mon, Sep 28, 2009 at 8:13 AM, e-letter inp...@gmail.com wrote: I saved the data sets as files and then tried to refer to those files. Therefore the instruction: z1-read.zoo(textConnection(/path/to/test1.txt) means that I wanted to replace the manual data entry for Lines1 with a file containing the data. It seems that your instructions only work when data is typed from the command terminal. I cannot use data stored in separated files. Command terminal output below: lines1-read.table(/path/to/test1.txt) lines2-read.table(/path/to/test2.txt) Warning message: incomplete final line found by readTableHeader on '/path/to/test2.txt' in: read.table(/path/to/test2.txt) This is test1 file: 01:00:00,500 01:00:15,600 01:00:30,750 01:00:45,720 01:01:00,700 01:01:15,725 01:01:30,640 01:01:45,710 This is test2 file: 01:00:12,20 01:01:01,55 01:01:55,22 Then I added a carriage return in test2 file and saved it: 01:00:12,20 01:01:01,55 01:01:55,22 Then I repeated the command terminal entry for lines2: lines2-read.table(/path/to/test2.txt) library(zoo) library(chron) z1-read.zoo(textConnection(lines1),header=FALSE,sep=,,FUN=times) Error in textConnection(lines1) : invalid 'text' argument __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] probability density function for maximum values in repea
On 28-Sep-09 12:15:39, Joerg van den Hoff wrote: this is probably not really a R specific question, if so apologies for off-topic posting: I'm interested in the probability density function of the maximum values from repeated samples of size N from a normal distribution: smp - rnorm(N, meanval, stdev) with some mean 'meanval' and standard deviation 'stdev'. I would like to know what is the frequency distribution of max(smp) if I draw many such samples? if I investigate this simply via a simulation, I get of course approximate results (and see that the resulting distribution is not quite normal anymore, that the mean increases with increasing N, etc.). my question: does somebody know whether there exists an analytical expression for the distribution of max(smp) (or where to look)? thanks, joerg Let Pmax(x,N) be the probability that the maximum of N is = x. Pmax(x,N) = Prob(all N values = x) = (Prob(a single value = x))^N = (pnorm(x,meanval,stdev))^N Hence the frequency distribution is the derivative of this with respect to x, say pmax(x,N): pmax(x,N) = N*((pnorm(x,meanval,stdev))^(N-1))*dnorm(x,meanval,stdev) Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 28-Sep-09 Time: 13:45:49 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] probability density function for maximum values in repeated finite samples from a normal distribution??
On Sep 28, 2009, at 8:15 AM, Joerg van den Hoff wrote: this is probably not really a R specific question, if so apologies for off-topic posting: I'm interested in the probability density function of the maximum values from repeated samples of size N from a normal distribution: smp - rnorm(N, meanval, stdev) with some mean 'meanval' and standard deviation 'stdev'. I would like to know what is the frequency distribution of max(smp) if I draw many such samples? if I investigate this simply via a simulation, I get of course approximate results (and see that the resulting distribution is not quite normal anymore, that the mean increases with increasing N, etc.). my question: does somebody know whether there exists an analytical expression for the distribution of max(smp) (or where to look)? Yes, there is an analytical description of the highest order statistic for Normal data. The question has been studied extensibly. You should be searching on extreme value theory or extremal distributions. There is also an extRemes package for R, as well as an fExtremes package for financial applications and a SpatialExtremes package. -- David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] JRI - get S4 objects from R and assign them again
Hello, I am writing a Java frontend for a selfwritten R program using JRI. Because I am working with my own S4 classes almost all of my R functions return a S4 object. In the Java Program I now need to run a R function and its result should be assigned to a new R variable afterwards. I tried REngine.eval(), but the returned REXP was always null. I tried also the rni methods: long result = re.rniParse(readInDataAndPreprocess(removemarked,removeflagged,substract_background),1); System.out.println(Result: + result); long r=re.rniEval(result, 0); System.out.println(Result = +r+, building REXP); REXP x=new REXP(re, r); re.assign(resultReading, x); but the variable resultReading was not available in R afterwards. Has anyone of you an idea what I could do? Thanks in advance! Best, Anni -- Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 - sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] zoo: merging aggregated zoo-objects fails
This looks like a problem in the chron package. Define: c.chron - function(...) chron(do.call(c, lapply(list(...), unclass))) and then try it again. I will discuss it with the chron maintainer. On Mon, Sep 28, 2009 at 6:41 AM, gunnar.p pr...@uni-potsdam.de wrote: Hello Gabor, thanks for your reply. Please excuse the insufficient description of my problem. I hope this one is better: #Importing my data works basically like this dts - dates(c(19700201,19700201,19700201,19700202,19700202),format=ymd) tms - times(paste(c(21:00, 22:00, 23:00,00:00, 01:00),0,sep=:),format=h:m:s) x - chron(dates=dts,times=tms) z - zoo(c(174.055,174.067,174.076,174.085,174.091),x) #Because I need daily values I run: z - aggregate(z,trunc,mean) #And because I deal with different data sets and need to sum them up I run: m - merge(z,z) When R executes merge() I get the following error message: Fehler in matrix(unlist(lapply(dots, origin)), nrow = 3) : Versuch ein Attribut von NULL zu setzen (Sorry that it's German. It says something like 'Error... Try to set attribute NULL') It's curious that there is no error when I first run merge() and than aggregate(), but this is not possible due to the rest of the programm. So why is merging not possible? Thanks in advance, gunnar R version 2.9.1 (Debian Lenny, XFCE 4.4, EMACS 22.2.1, ESS 5.3.8) -- View this message in context: http://www.nabble.com/zoo%3A-merging-aggregated-zoo-objects-fails-tp25633345p25643639.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error while plotting
I am trying to plot the confidence limits form multiple comparison analysis. How do I need to construct the object to plot it now. Thanks ../Murli -Original Message- From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] Sent: Sunday, September 27, 2009 1:17 PM To: Nair, Murlidharan T Cc: r-help@r-project.org Subject: Re: [R] error while plotting Nair, Murlidharan T wrote: I am getting the following errors when I am trying to plot the data below. I cannot figure out the error. Error in plot.window(...) : need finite 'xlim' values In addition: Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf 3: In min(x) : no non-missing arguments to min; returning Inf 4: In max(x) : no non-missing arguments to max; returning -Inf #I am using the following code #== library(multcomp) sig.data-structure(list(X = 1:10, Cell.lines = structure(c(2L, 5L, 8L, 9L, 3L, 6L, 10L, 1L, 4L, 7L), .Label = c(T(70%)a-N(0%)c, T(70%)a-N(0%)f, T(70%)a-N(0%)i, T(70%)c-N(0%)c, T(70%)c-N(0%)f, T(70%)c-N(0%)i, T(80%)a-N(0%)c, T(80%)a-N(0%)f, T(90%)-N(0%)f, T(90%)-N(0%)i ), class = factor), estimate = c(9859.74333, -5553.64802, 6227.17947, 8063.6472, 6548.86032, -8864.53103, 4752.7642, 9057.72021, -6355.67115, 5425.15635), lower = c(5560.57875, -9852.8126, 1928.01489, 3764.48262, 2249.69575, -13163.69561, 453.59962, 4758.55563, -10654.83573, 1125.99177), upper = c(14158.90791, -1254.48344, 10526.34405, 12362.81178, 10848.0249, -4565.36645, 9051.92877, 13356.88479, -2056.50657, 9724.32092), p.val.raw = c(1.15e-08, 5.78e-05, 1.36e-05, 3.21e-07, 6.91e-06, 6.97e-08, 0.000331, 4.87e-08, 1.04e-05, 7.63e-05 ), p.val.bon = c(2.66e-06, 0.0133, 0.00315, 7.41e-05, 0.0016, 1.61e-05, 0.0764, 1.13e-05, 0.0024, 0.0176), p.val.adj = c(2.65e-13, 0.000592, 2.82e-05, 9.72e-08, 6.56e-05, 8.76e-09, 0.0117, 6.22e-09, 6.44e-06, 0.000334)), .Names = c(X, Cell.lines, estimate, lower, upper, p.val.raw, p.val.bon, p.val.adj), class = data.frame, row.names = c(T(70%)a-N(0%)f, T(70%)c-N(0%)f, T(80%)a-N(0%)f, T(90%)-N(0%)f, T(70%)a-N(0%)i, T(70%)c-N(0%)i, T(90%)-N(0%)i, T(70%)a-N(0%)c, T(70%)c-N(0%)c, T(80%)a-N(0%)c)) rownames(sig.data)-sig.data[,2] my.hmtest - structure(list( estimate = t(t(structure(sig.data[,estimate], .Names = rownames(sig.data, conf.int = sig.data[,4:5], ctype = ABCC4-2007), class = hmtest) par(mex=0.5) #This helps to accomodate the margins when text is getting cut off plot(my.hmtest, cex.axis=0.7) There is not method plot.hmtest defined anywhere. Hence plot.default is used and that one does not know hoe to handle an object like the one you just defined. Uwe Ligges __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] binary quantile regression with IV
Hello, I was wondering if anyonw knows any reference or package about binary quantile regression with IV. I know that Kordas post S-plus package in his website. But I don't have S-plus. Furthermore, my friends told mw that his package is not recognized by S-plus 8. Hence, I decide to use R. Any suggestions are welcomed. Thank you in advance. Sungil _ [[elided Hotmail spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to assess object names within a function in lapply or l_ply?
Henrique, based on your solution I found out, how to avoid to name explicitly the object. lapply(data.frame(a=1:3, b=2:4), function(x) names(eval(as.list(sys.call(-1))[[2]])) [as.numeric(gsub([^0-9], , deparse(substitute(x] ) Thanks, Heinz At 13:57 28.09.2009, Henrique Dallazuanna wrote: Heinz, Try this: lapply(DF, function(x)names(DF)[as.numeric(gsub([^0-9], , deparse(substitute(x]) On Mon, Sep 28, 2009 at 8:43 AM, Heinz Tuechler tuech...@gmx.at wrote: Thank you, Henrique, my example was simplified. In a more complexe function I want to use the objects, not just their names. In your solution, I have to adapt the function itself, depending on the name of the data.frame, which I would like to avoid. Thanks, Heinz At 13:36 28.09.2009, Henrique Dallazuanna wrote: You can use names insteed: DF - data.frame(a=1:3, b=2:4) lapply(names(DF), function(x){ print(x) DF[x] }) On Mon, Sep 28, 2009 at 8:22 AM, Heinz Tuechler tuech...@gmx.at wrote: Dear All, to produce output of several columns of a data frame, I tried to use lapply and also l_ply. In both cases, I would like to print a header line containing also the name of the respective column in the data frame. For example, I would like the following lapply(data.frame(a=1:3, b=2:4), function(x) print(deparse(substitute(x to produce: [1] a [1] b and not, what it actually does: [1] X[[1L]] [1] X[[2L]] $a [1] X[[1L]] $b [1] X[[2L]] or with l_ply (plyr package) l_ply(data.frame(a=1:3, b=2:4), function(x) print(deparse(substitute(x to produce: [1] a [1] b and not, what it actually does: [1] .data[[i]] [1] .data[[i]] Is this possible? Thanks, Heinz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R and REST API's
Hi - Many organizations now make their data available as XML via a REST web service architecture. Is there any R package or facility to access this type of data directly (eg, to make the HTTP GET request and have the downloaded data put into an R data frame)? I used several R search sites to look for an answer, but came up with very little. Any help would be appreciated. Thanks very much. Gary Lewis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Determining name of calling function.
Not answering your question, but just pointing out the example of base::.NotYetImplemented() essentially doing the same thing. Best, baptiste 2009/9/28 Rolf Turner r.tur...@auckland.ac.nz: I have vague recollections of seeing this question discussed on r-help previously, but I can't find the relevant postings. I want to determine (from within a given function) the name of the function calling that given function. E.g. if I have a function foo() which calls a function bar(), and also a function clyde() which calls bar(), I want to have, in the code of bar(), an instruction which will return the character string foo if bar() was called from foo() and the string clyde if bar() was called from clyde(). Without really understanding what I'm doing I cobbled together the following: fname - as.character(sys.call(-1))[1] This ***seems*** to work, at least in simple test cases. But is it reliably robust? Are there traps for young players that I am not seeing? My ``solution'' returns NA as the value of fname if bar() is called from the command line, rather than being called by foo() or clyde(). This is acceptable. I think Any avuncular advice from those younger and wiser than myself? :-) cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] predict missing values with svm
Dear R-Users, i want to use the function svm of the e1071 package to predict missing data data(iris) ## create missing completely at random data for (i in 1:5) { mcar - rbinom(dim(iris)[1], size=1, prob=0.1) iris[mcar == 1, i] - NA } ok - complete.cases(iris) model - svm(Species ~ ., data=iris[ok,]) ## try to predict the missing values for Species ## neither pred - predict(model, iris[5]) ## nor pred - predict(model, iris[!ok, -5]) ## seems to work Many thanks if anyone could tell me what i do wrong and what is the problem here. best regards Andreas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Scaling data
Jim Lemon wrote: On 09/28/2009 07:55 PM, Dry, Jonathan R wrote: Hello all I have a data frame representing a matrix of data. For each of my variables (rows) I want to scale the data between 0 (representing the minimum value in that row) and 1 (representing the maximum value in that row). I was wondering if there is a simple function anywhere that does this? Hi Jonathan, There are a number of such functions, but a particularly easy one in your case is rescale. Baptiste has already mentioned the one in ggplot, so I'll plug mine in plotrix: mat1-matrix(sample(1:20,16),nrow=4) library(plotrix) t(apply(mat1,1,rescale,c(0,1))) Notice also that scale() will do it if you tickle it in the right places: x - rnorm(500) range(scale(x, min(x), diff(range(x [1] 0 1 -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to assess object names within a function in lapply or l_ply?
or with l_ply (plyr package) l_ply(data.frame(a=1:3, b=2:4), function(x) print(deparse(substitute(x The best way to do this is to supply both the object you want to iterate over, and its names. Unfortunately it's slightly difficult to create a data structure of the correct form to do this with m_ply. df - data.frame(a=1:3, b=2:4) input - list(x = df, name = names(df)) inputdf - structure(input, class = data.frame, row.names = seq_along(input[[1]])) m_ply(inputdf, function(x, name) { cat(name, -\n) print(x) }) I'll think about how to improve this for a future version. Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] predict missing values with svm
On Mon, 28 Sep 2009 16:12:11 +0200, Andreas Wittmann (AW) wrote: That is a bug in predict.svm, I will inform David Meyer, the author of the function. Best, Fritz Dear R-Users, i want to use the function svm of the e1071 package to predict missing data data(iris) ## create missing completely at random data for (i in 1:5) { mcar - rbinom(dim(iris)[1], size=1, prob=0.1) iris[mcar == 1, i] - NA } ok - complete.cases(iris) model - svm(Species ~ ., data=iris[ok,]) ## try to predict the missing values for Species ## neither pred - predict(model, iris[5]) ## nor pred - predict(model, iris[!ok, -5]) ## seems to work Many thanks if anyone could tell me what i do wrong and what is the problem here. best regards Andreas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] predict missing values with svm
Hi Andreas, Andreas Wittmann wrote: Dear R-Users, i want to use the function svm of the e1071 package to predict missing data data(iris) ## create missing completely at random data for (i in 1:5) { mcar - rbinom(dim(iris)[1], size=1, prob=0.1) iris[mcar == 1, i] - NA } ok - complete.cases(iris) model - svm(Species ~ ., data=iris[ok,]) ## try to predict the missing values for Species ## neither pred - predict(model, iris[5]) ## nor pred - predict(model, iris[!ok, -5]) ## seems to work ind - is.na(iris[,5]) !apply(iris[,-5], 1, function(x) any(is.na(x)) predict(model, iris[ind,-5]) Best, Jim Many thanks if anyone could tell me what i do wrong and what is the problem here. best regards Andreas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- James W. MacDonald, M.S. Biostatistician Douglas Lab University of Michigan Department of Human Genetics 5912 Buhl 1241 E. Catherine St. Ann Arbor MI 48109-5618 734-615-7826 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error while plotting
Perhaps you explain us how you really generate the data that are results from the multcomp package. Then it would probbaly be clear how to proceed. Uwe Ligges Nair, Murlidharan T wrote: I am trying to plot the confidence limits form multiple comparison analysis. How do I need to construct the object to plot it now. Thanks ../Murli -Original Message- From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] Sent: Sunday, September 27, 2009 1:17 PM To: Nair, Murlidharan T Cc: r-help@r-project.org Subject: Re: [R] error while plotting Nair, Murlidharan T wrote: I am getting the following errors when I am trying to plot the data below. I cannot figure out the error. Error in plot.window(...) : need finite 'xlim' values In addition: Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf 3: In min(x) : no non-missing arguments to min; returning Inf 4: In max(x) : no non-missing arguments to max; returning -Inf #I am using the following code #== library(multcomp) sig.data-structure(list(X = 1:10, Cell.lines = structure(c(2L, 5L, 8L, 9L, 3L, 6L, 10L, 1L, 4L, 7L), .Label = c(T(70%)a-N(0%)c, T(70%)a-N(0%)f, T(70%)a-N(0%)i, T(70%)c-N(0%)c, T(70%)c-N(0%)f, T(70%)c-N(0%)i, T(80%)a-N(0%)c, T(80%)a-N(0%)f, T(90%)-N(0%)f, T(90%)-N(0%)i ), class = factor), estimate = c(9859.74333, -5553.64802, 6227.17947, 8063.6472, 6548.86032, -8864.53103, 4752.7642, 9057.72021, -6355.67115, 5425.15635), lower = c(5560.57875, -9852.8126, 1928.01489, 3764.48262, 2249.69575, -13163.69561, 453.59962, 4758.55563, -10654.83573, 1125.99177), upper = c(14158.90791, -1254.48344, 10526.34405, 12362.81178, 10848.0249, -4565.36645, 9051.92877, 13356.88479, -2056.50657, 9724.32092), p.val.raw = c(1.15e-08, 5.78e-05, 1.36e-05, 3.21e-07, 6.91e-06, 6.97e-08, 0.000331, 4.87e-08, 1.04e-05, 7.63e-05 ), p.val.bon = c(2.66e-06, 0.0133, 0.00315, 7.41e-05, 0.0016, 1.61e-05, 0.0764, 1.13e-05, 0.0024, 0.0176), p.val.adj = c(2.65e-13, 0.000592, 2.82e-05, 9.72e-08, 6.56e-05, 8.76e-09, 0.0117, 6.22e-09, 6.44e-06, 0.000334)), .Names = c(X, Cell.lines, estimate, lower, upper, p.val.raw, p.val.bon, p.val.adj), class = data.frame, row.names = c(T(70%)a-N(0%)f, T(70%)c-N(0%)f, T(80%)a-N(0%)f, T(90%)-N(0%)f, T(70%)a-N(0%)i, T(70%)c-N(0%)i, T(90%)-N(0%)i, T(70%)a-N(0%)c, T(70%)c-N(0%)c, T(80%)a-N(0%)c)) rownames(sig.data)-sig.data[,2] my.hmtest - structure(list( estimate = t(t(structure(sig.data[,estimate], .Names = rownames(sig.data, conf.int = sig.data[,4:5], ctype = ABCC4-2007), class = hmtest) par(mex=0.5) #This helps to accomodate the margins when text is getting cut off plot(my.hmtest, cex.axis=0.7) There is not method plot.hmtest defined anywhere. Hence plot.default is used and that one does not know hoe to handle an object like the one you just defined. Uwe Ligges __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Determining name of calling function.
baptiste auguie wrote: Not answering your question, but just pointing out the example of base::.NotYetImplemented() essentially doing the same thing. Best, baptiste 2009/9/28 Rolf Turner r.tur...@auckland.ac.nz: I have vague recollections of seeing this question discussed on r-help previously, but I can't find the relevant postings. I want to determine (from within a given function) the name of the function calling that given function. E.g. if I have a function foo() which calls a function bar(), and also a function clyde() which calls bar(), I want to have, in the code of bar(), an instruction which will return the character string foo if bar() was called from foo() and the string clyde if bar() was called from clyde(). Without really understanding what I'm doing I cobbled together the following: fname - as.character(sys.call(-1))[1] This ***seems*** to work, at least in simple test cases. But is it reliably robust? Are there traps for young players that I am not seeing? My ``solution'' returns NA as the value of fname if bar() is called from the command line, rather than being called by foo() or clyde(). This is acceptable. I think Any avuncular advice from those younger and wiser than myself? :-) cheers, Rolf Turner (How old are you? Surely you are aware that avuncular advice usually comes from your parents' siblings and their spouses.) I'd maybe be more inclined to use something like deparse(sys.call(-1)[[1]]) but there's no clear benefit. The main trap would be that the first element of the call is not necessarily a name. Consider (function(x)deparse(sys.call()[[1]]))(x=2) [1] (function(x) deparse(sys.call()[[1]])) (function(x)as.character(sys.call()[1]))(x=2) [1] (function(x) as.character(sys.call()[1])) and notice that in fact the function bing called may not even _have_ a name. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rsolnp- Error (Help!)
Tushar, I was trying to run your code, but it seems like you haven’t specified the parameter called `Strk', so I was unable to run it. Can you send a fully reproducible code? Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvarad...@jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.html -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of tushar_kul Sent: Monday, September 28, 2009 5:24 AM To: r-help@r-project.org Subject: Re: [R] rsolnp- Error (Help!) Thanks, but I do not have max(tt[2] - 10 * tol, nineq) in my script. Therefore, could the error be getting generated by rsolnp itself ? jholtman wrote: It means that your expression max(tt[2] - 10 * tol, nineq) is returning NA: Notice I get the same error: if (1==1)1 [1] 1 if (NA == 1) 1 Error in if (NA == 1) 1 : missing value where TRUE/FALSE needed Check your script and see why it is NA. you might need: max(tt[2] - 10 * tol, nineq, na.rm=TRUE) If your data has NAs. On Sun, Sep 27, 2009 at 5:29 PM, tushar_kul tus...@gmail.com wrote: Hi I am relatively new to R and was trying to run an optimization problem using rsolnp. I am getting an error which seems to be not related to my construct of the optimization equations. Error in if (max(tt[2] - 10 * tol, nineq) = 0) rho = 0 : missing value where TRUE/FALSE needed I have attached the file code. I would greatly appreciate any help. Many thanks http://www.nabble.com/file/p25637806/OptTS.txt OptTS.txt -- View this message in context: http://www.nabble.com/rsolnp--Error-%28Help%21%29-tp25637806p25637806.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/rsolnp--Error-%28Help%21%29-tp25637806p25641703.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Determining name of calling function.
(Oops, that was of course intended for Rolf, not Baptiste) Peter Dalgaard wrote: baptiste auguie wrote: Not answering your question, but just pointing out the example of base::.NotYetImplemented() essentially doing the same thing. Best, baptiste 2009/9/28 Rolf Turner r.tur...@auckland.ac.nz: I have vague recollections of seeing this question discussed on r-help previously, but I can't find the relevant postings. I want to determine (from within a given function) the name of the function calling that given function. E.g. if I have a function foo() which calls a function bar(), and also a function clyde() which calls bar(), I want to have, in the code of bar(), an instruction which will return the character string foo if bar() was called from foo() and the string clyde if bar() was called from clyde(). Without really understanding what I'm doing I cobbled together the following: fname - as.character(sys.call(-1))[1] This ***seems*** to work, at least in simple test cases. But is it reliably robust? Are there traps for young players that I am not seeing? My ``solution'' returns NA as the value of fname if bar() is called from the command line, rather than being called by foo() or clyde(). This is acceptable. I think Any avuncular advice from those younger and wiser than myself? :-) cheers, Rolf Turner (How old are you? Surely you are aware that avuncular advice usually comes from your parents' siblings and their spouses.) I'd maybe be more inclined to use something like deparse(sys.call(-1)[[1]]) but there's no clear benefit. The main trap would be that the first element of the call is not necessarily a name. Consider (function(x)deparse(sys.call()[[1]]))(x=2) [1] (function(x) deparse(sys.call()[[1]])) (function(x)as.character(sys.call()[1]))(x=2) [1] (function(x) as.character(sys.call()[1])) and notice that in fact the function bing called may not even _have_ a name. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] creating vectors from a list
Hi guys, I have a list of 250 numbers as a result of using the ?by function! List of 246 $ 0 : num [1:28] 22 11 31... $ 1 : num [1:15] 12 14 9 ... .. .. .. - attr(*, dim)= int 250 - attr(*, dimnames)=List of 1 The problem is that each list of 250 has different length! I would like to get the values of each list in a vector like vector_0 = (22,11,31,..), is this possible? Thank you in advance, Christina [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to assess object names within a function in lapply or l_ply?
Hadley, many thanks for your answer and for the enormous work you put into plyr, a really powerful package. For now, I will solve my problem with a variable label attribute, I usually attach to columns in data frames. I asked the list, because I thought, I am overlooking something trivial, since lapply itself apparently knows the object names, as it labels the output by them. It just does not supply them to the function it calls. Maybe deparse(substitute(x)) with the right environment would do it, but I did not find it. Thanks, Heinz At 16:27 28.09.2009, hadley wickham wrote: or with l_ply (plyr package) l_ply(data.frame(a=1:3, b=2:4), function(x) print(deparse(substitute(x The best way to do this is to supply both the object you want to iterate over, and its names. Unfortunately it's slightly difficult to create a data structure of the correct form to do this with m_ply. df - data.frame(a=1:3, b=2:4) input - list(x = df, name = names(df)) inputdf - structure(input, class = data.frame, row.names = seq_along(input[[1]])) m_ply(inputdf, function(x, name) { cat(name, -\n) print(x) }) I'll think about how to improve this for a future version. Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] axis label using expression()
Probably a very simple problem: I want to annotate a plot axis with a name of my data using expression(). The name for the data is $\hat P4_k$ written in LaTex style - hat symbol above P, followed by a 4 and a subscripted k index I tried to write this using x-c(1,2,3,4) y-c(3,5,7,9) plot(x,y,xlab=expression(hat(P4[k])) ) but cant find a way to force the hat symbol to be located only above the P symbol and not above the 4 symbol. I have spent some time looking up ?expression, ?plotmath as well as some other R docu but cannot find a way. Any help is greatly appreciated. Regards, toby [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Bubble Plot
From looking at the code for bubble(), it doesn't appear there's any way to force special treatment of selected values. However, a simple work around would be to simply exclude the zero values from the plot(s) by subsetting your data creating a1 and a2. If you really want *no* representation, you're done. If you want them represented with the smallest dot size, then add them in afterwards with plot(), xyplot(), or spplot(), depending. Or, you could make a personal copy of bubble() [renamed, of course], and modify it to handle zeros in a special manner. That doesn't look too hard to do. -Don At 6:27 PM -0700 9/27/09, Marion Wittmann wrote: Hello, I am using the bubble plot and have been able to overlay two different data sets on the same graphic successfully. I would like to do the following and cannot: 1) suppress the zero values such that there is no representation of them on my plot (i.e., the zeroes show up as the smallest dot size, and I can't change this) 2) Give values to y or x axes with values, and labels My script looks as such: coordinates(data) = ~y + x a1 = bubble(data, Alive, zero.print = .,maxsize = 5.0, key.entries = 4*(1:6),col=c(0,3)) a2 = bubble(handcore, Dead, maxsize = 5.0, main = , key.entries = 5*(0:10),col=c(0,4)) print(b1, more = TRUE) print(b2, more = FALSE) Thanks in advance for your help. mw Marion Wittmann, Ph.D. Tahoe Environmental Research Center University of California Davis __ R-help@r-project.org mailing list https://*stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://*www.*R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- -- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] creating vectors from a list
Try this: L - list(`0` = 1:4, `1` = 2:3) sum(L$`0`) [1] 10 with(L, sum(`0`)) [1] 10 # not recommended tho' this is closest to what you asked for attach(L) sum(`0`) [1] 10 On Mon, Sep 28, 2009 at 10:57 AM, Christina Rodemeyer christinarodeme...@yahoo.de wrote: Hi guys, I have a list of 250 numbers as a result of using the ?by function! List of 246 $ 0 : num [1:28] 22 11 31... $ 1 : num [1:15] 12 14 9 ... .. .. .. - attr(*, dim)= int 250 - attr(*, dimnames)=List of 1 The problem is that each list of 250 has different length! I would like to get the values of each list in a vector like vector_0 = (22,11,31,..), is this possible? Thank you in advance, Christina [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Levelplot without margins
Hello, I'm not very experienced with lattice and I was wondering whether I get get some hints from you how to create a pure heatmap (using levelplot), without any axis, title, legend, margin at all... I just want to see the coloured squares, nothing else. Any suggestions? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] creating vectors from a list
Try this: lapply(names(L), function(l)assign(sprintf('vector_%s', l), L[l], envir = globalenv())) ls() On Mon, Sep 28, 2009 at 11:57 AM, Christina Rodemeyer christinarodeme...@yahoo.de wrote: Hi guys, I have a list of 250 numbers as a result of using the ?by function! List of 246 $ 0 : num [1:28] 22 11 31... $ 1 : num [1:15] 12 14 9 ... .. .. .. - attr(*, dim)= int 250 - attr(*, dimnames)=List of 1 The problem is that each list of 250 has different length! I would like to get the values of each list in a vector like vector_0 = (22,11,31,..), is this possible? Thank you in advance, Christina [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] axis label using expression()
Try this: plot(x,y,xlab=expression(hat(P)*4[k])) On Mon, Sep 28, 2009 at 11:59 AM, tobias.mat...@forst.bwl.de wrote: Probably a very simple problem: I want to annotate a plot axis with a name of my data using expression(). The name for the data is $\hat P4_k$ written in LaTex style - hat symbol above P, followed by a 4 and a subscripted k index I tried to write this using x-c(1,2,3,4) y-c(3,5,7,9) plot(x,y,xlab=expression(hat(P4[k])) ) but cant find a way to force the hat symbol to be located only above the P symbol and not above the 4 symbol. I have spent some time looking up ?expression, ?plotmath as well as some other R docu but cannot find a way. Any help is greatly appreciated. Regards, toby [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Regression line w/ residuals - tuning the plot
Hello everybody, I am sure this is a beginners' problem which is being asked recurrently every few months, but nevertheless I wasn't able to find the answer searching through the r-help list. So here is my problem: I would like to plot a set of points (y vs. x), a (linear) regression line through them, and on the second graph underneath the first one I would want to plot residuals vs. x. I came up with two solutions, unfortunately neither of them is fully satisfactory. First I tried with what I later learned is called traditional graphics (file norris.R). Here, the white space margins around the plots are too wide, meaning that the data in the plot are crammed. Probably I would be quite happy if I could somehow define a rectangular plotting area with its height being ~150% of its width, but I cannot prevent R from offering me a square plotting area. Next I tried a lattice package (file norris.lattice.R). Here, the margins are smaller, but the lower plot does not fit exactly under the upper one (the x-axes should match). Most likely I am not using the correct terminology (if I would have known it, I could have looked in the help pages myself, thank you :), but I hope that the attached files make more sense of what I am trying to do. Thanks in advance. All the best, Primoz -- Primož Peterlin, Inštitut za biofiziko, Med. fakulteta, Univerza v Ljubljani Lipičeva 2, SI-1000 Ljubljana, Slovenija.primoz.peter...@mf.uni-lj.si Tel +386-1-5437612, fax +386-1-4315127, http://biofiz.mf.uni-lj.si/~peterlin/ F8021D69 OpenPGP fingerprint: CB 6F F1 EE D9 67 E0 2F 0B 59 AF 0D 79 56 19 0F __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R and REST API's
On Mon, Sep 28, 2009 at 10:01 AM, Gary Lewis gary.m.le...@gmail.com wrote: Hi - Many organizations now make their data available as XML via a REST web service architecture. Is there any R package or facility to access this type of data directly (eg, to make the HTTP GET request and have the downloaded data put into an R data frame)? The url() function together with the XML package should let you do this -- Rajarshi Guha NIH Chemical Genomics Center [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] for loop
Can somebody give a hint on how to speed-up the following loop: for(j in 0:KM1) { k=j*60 for(i in 1:60) { dat$yvac[k+i]= rbinom(1,dat$nvac[k+i],dat$p.trt[j+i]) } } K1=999 -- -Tony [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.