Re: [R] binary data
karuna m wrote: hi, I am trying to calculate distance matrices for binary data frame. I am using dist.binary in 'ade4' package. This is the code i run and get error message as 'missing value where True/False needed: clss - as.data.frame(cls) dist.binary(clss, method = 1, diag = FALSE, upper = FALSE) Also, if i convert the factors into numeric(i.e,12 in the place of 01 for present/absent data), i get the distance matrices with 0's as elements. This is the code i run and get the matrix with all the elements as zeros: d - as.data.frame(lapply(cls,as.numeric)); dist.binary(d, method = 1, diag = FALSE, upper = FALSE) Can anybody help me to rectify the error? Thanks in advance, Kind regards, Ms.Karunambigai M PhD Scholar Dept. of Biostatistics NIMHANS Bangalore India The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. [[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. -- View this message in context: http://old.nabble.com/binary-data-tp26332493p26508277.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] interior and exterior colors of a map
Hi useR's, I have an image plot I want to overlay a map of the United States on, via map('usa'). The image is basically a large rectangular of various colors. When I overlay the United States map, the full rectangle of the image plot is visible, but I only want to display the image WITHIN the United States boundary. Does anyone know a way to do this? Thanks in advance, dxc13 -- View this message in context: http://old.nabble.com/interior-and-exterior-colors-of-a-map-tp26507134p26507134.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] reshape question
Thanks for your help on this Hadley and David! Dennis Murphy also had a good solution (changing list(data.out2[-1])...etc to names(data.out2[-1]}...): data.out3 - reshape(data.out2, direction = 'long', varying = names(data.out2[-1]), + idvar = 'id') data.out4 - split(data.out3, data.out3$time) names(data.out4) - paste('time', 1:4, sep = '') data.out4 AC On Tue, Nov 24, 2009 at 9:05 PM, hadley wickham h.wick...@gmail.com wrote: I don't really understand what you want and the example solution throws away quite a lot of data, so consider this alternative: data.out2 - read.table(textConnection(id rater.1 n.1 rater.2 n.2 rater.3 n.3 rater.4 n.4 11 11 0.118 79NA NANA NANA NA 114 114 0.2478709 113NA NANA NANA NA 12 12 0.3130655 54 0.3668242 54NA NANA NA 121 121 0.240 331NA NANA NANA NA 122 122 0.3004164 25 0.1046278 25 0.2424871 25 0.2796937 25 125 125 0.1634865 190NA NANA NANA NA), header=T, stringsAsFactors=F) Or library(reshape) df - melt(data.out2, na.rm = T, id = id) df - cbind(df, colsplit(df$variable, \\., c(var, time))) cast(df, id + time ~ var) See http://had.co.nz/reshape for more details. Hadley -- http://had.co.nz/ [[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] Eliminating 'Unprintable ASCII' characters
I think you mean the control characters: there are other unprintable characters (del for example). They are the character range [\001-\037]. E.g. test - intToUtf8(1:40, multiple=TRUE) grepl([\001-\037], test) [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [13] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [25] TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE [37] FALSE FALSE FALSE FALSE If you want to include del, use [\001-\037\177]. I have omitted nul (\000) which cannot occur in R character strings. You didn't give us the sessionInfo() output the posting guide asked you for, so I am presuming you are not doing this in an unusual locale: I wouldn't trust the regexp code in one of the stateful locales used for Japanese. On Wed, 25 Nov 2009, Steven Kang wrote: Hi all, I have a csv file containing words with *UNPRINTABLE ASCII* characters (described in the following table). Are there any viable method in eliminating these characters? I realise that *EXTENDED ASCII* characters (i.e , ?, ?, ?, ? etc) can be removed or replaced via *gsub* or *gregexpr* functions. But am not certain with the *UNPRINTABLE ASCII* characters. Your help in resolving this problem would be highly appreciated. Thanks Steven ASCII control characters (character code 0-31)The first 32 characters in the ASCII-table are unprintable control codes and are used to control peripherals such as printers. *DEC* *OCT* *HEX* *BIN* *Symbol* *HTML Number* *HTML Name* *Description* 0 000 00 NUL #000; Null char 1 001 01 0001 SOH #001; Start of Heading 2 002 02 0010 STX #002; Start of Text 3 003 03 0011 ETX #003; End of Text 4 004 04 0100 EOT #004; End of Transmission 5 005 05 0101 ENQ #005; Enquiry 6 006 06 0110 ACK #006; Acknowledgment 7 007 07 0111 BEL #007; Bell 8 010 08 1000 BS #008; Back Space 9 011 09 1001 HT #009; Horizontal Tab 10 012 0A 1010 LF #010; Line Feed 11 013 0B 1011 VT #011; Vertical Tab 12 014 0C 1100 FF #012; Form Feed 13 015 0D 1101 CR #013; Carriage Return 14 016 0E 1110 SO #014; Shift Out / X-On 15 017 0F SI #015; Shift In / X-Off 16 020 10 0001 DLE #016; Data Line Escape 17 021 11 00010001 DC1 #017; Device Control 1 (oft. XON) 18 022 12 00010010 DC2 #018; Device Control 2 19 023 13 00010011 DC3 #019; Device Control 3 (oft. XOFF) 20 024 14 00010100 DC4 #020; Device Control 4 21 025 15 00010101 NAK #021; Negative Acknowledgement 22 026 16 00010110 SYN #022; Synchronous Idle 23 027 17 00010111 ETB #023; End of Transmit Block 24 030 18 00011000 CAN #024; Cancel 25 031 19 00011001 EM #025; End of Medium 26 032 1A 00011010 SUB #026; Substitute 27 033 1B 00011011 ESC #027; Escape 28 034 1C 00011100 FS #028; File Separator 29 035 1D 00011101 GS #029; Group Separator 30 036 1E 0000 RS #030; Record Separator 31 037 1F 0001 US #031; Unit Separator [[alternative HTML version deleted]] -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ 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] Kerning issues with CairoPDF
Dear list members I'm using CairoPDF to generate PDF (because of its font embedding and support for transparent colours). However, at least on my (Windows) system, the text it outputs seems to have completely wrong kerning. Here's an example: CairoPDF(test.pdf) plot(rnorm(100),xlab=Ovreset) dev.off() The v is (slightly) too far away from the O, it's much too close to the r, partially overlapping it, and the e is too far away from the s. Can anyone reproduce it? Any ideas what's causing it, if it's possible to fix it, or if just a bug in CairoPDF. I remember a kerning-related change in R 2.9.0. Could that be related? sessionInfo() R version 2.10.0 (2009-10-26) i386-pc-mingw32 locale: [1] LC_COLLATE=Norwegian-Nynorsk_Norway.1252 [2] LC_CTYPE=Norwegian-Nynorsk_Norway.1252 [3] LC_MONETARY=Norwegian-Nynorsk_Norway.1252 [4] LC_NUMERIC=C [5] LC_TIME=Norwegian-Nynorsk_Norway.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] Cairo_1.4-5 loaded via a namespace (and not attached): [1] tools_2.10.0 -- Karl Ove Hufthammer __ 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] multiple regression model representation
Dear all, I have a problem when trying to fit a model to a dataset. The model I am fitting is: y~var1*var2*var3*var4*var5, with var3 and var4 having many 0´s. When I construct the model and I simplify it, it remains a model with 8 explicative variables (or interaction of them) and the intercept, but when I try to plot the model, R gives me the following error: Error in plot.new() : trying to draw in a null device Furthermore: missing warning message Not plotting observations with leverage one: 62, 78 What I do is the following: model1=lm(Error ~ Ciottoli *Ghiaia *Limo *Massi *Sabbia, data=datos) summary(model1) model1=lm(y ~ var1 *var2 *var3 *var4 *var5, data=mydata) summary(model1) model.error=step(model1) summary(model.error) model2=update(model.error,~.-var2:var5) summary(model2) model3=update(model2,~.-var1:var5) summary(model3) model4=update(model3,~.-var1:var2) summary(model4) model5=update(model4,~.-var5) summary(model5) model6=update(model5,~.-var4) summary(model6) model7=update(model6,~.-var2) summary(model7) model8=update(model7,~.-var1) summary(model8) plot(model8) I would be very please if you could throw light on this. Thank you very much in advance! Best wishes! Manuel [[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] which to trust...princomp() or prcomp() or neither?
Blair Smith b.smith at irl.cri.nz writes: According to R help: princomp() uses eigenvalues of covariance data. prcomp() uses the SVD method. yet when I run the (eg., USArrests) data example and compare with my own hand-written versions of PCA I get what looks like the opposite. ...clip... You see the problem: my SVD method yields results numerically similar to the princomp() method which supposedly uses the eigenvector calculation. Whereas my eigenvector calculation method yields results numerically similar to the prcomp() method which supposedly is a SVD calculation! Also, it surprised me that the two methods would differ so markedly (only 2 significant figure agreement at best). Ultimately the question is which method to trust as most accurate? When I get time I'll just put in some data with KNOWN PC stdevs to see, but I'm still curious to see if any of you reading this help list could explain in advance? Blair, A behavioural test is not the best choice here: the source code is visible and you can look there and see that prcomp() indeed uses svd() and princomp() uses eigen(). The easiest way to dump the code is to write the name of the function without trailing parentheses. The differences in the numbers you cite has nothing to do with the underlying algorithm, but it is only due to the scaling of the results: Function princomp()uses divisor 'N' for the covariance matrix (this is explicitly documented in?princomp), whereas prcomp() uses divisor 'N-1' (which is implied in ?prcomp -- this really could be more explicit). So you see: you did not need a guru to answer you -- reading the code and docs was sufficient. Cheers, Jari Oksanen __ 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] center of cluster of points in PCA
phoebe kong sityeekong at gmail.com writes: Can someone tell me how to find the center of cluster points in PCA (PC1 vs PC2)? Can R find that out? If yes, how it's generated by R? Is the coordinate of center point equals (mean score of PC1, mean score of PC2)? Phoebe: Yes. Cheers, Jari __ 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] ROCR Issue: Averaging Across Multiple Classifier Runs in ROC Curve
Dear R-philes, I am having some trouble averaging across multiple runs of a classifier in an ROC Curve. I am using the ROCR package and the plot() method. First, I initialize a list with two elements where each element is a list of predictions and labels: vowel.ROC - list(predictions=list(), labels=list()) For every run of the classifier, I append the scores and labels to their corresponding list elements as follows: vowel.ROC$predictions - append(vowel.ROC$predictions, list(scores)) vowel.ROC$labels - append(vowel.ROC$labels, list(numGrps)) The R display of vowel.ROC looks like the following (not sure why NULL is there): List of 2 $ predictions:List of 4 ..$ : num [1:148] 0.234 0.293 0.275 0.391 0.191 ... ..$ : num [1:152] 0.99 0.974 0.934 0.767 0.934 ... ..$ : num [1:293] 0.05009 0.00739 0.03211 0.85894 0.18265 ... ..$ : num [1:247] 0.0184 0.0168 0.0942 0.0149 0.089 ... $ labels :List of 4 ..$ : num [1:148] 1 1 1 1 1 2 2 1 1 1 ... ..$ : num [1:152] 2 2 2 2 2 1 1 1 1 2 ... ..$ : num [1:293] 1 1 1 1 2 1 1 2 2 1 ... ..$ : num [1:247] 1 1 1 1 1 2 1 1 1 2 ... NULL I make prediction and performance objects and plot the resulting performance object as shown below. pred - prediction(vowel.ROC$predictions, vowel.ROC$labels) perf - performance(pred, tpr, fpr) plot(perf, avg=horizontal, spread.estimate=boxplot) Instead of getting an average ROC curve, I am getting four separate ones on the same plot. This is nice but I prefer the average curve. Any direction would be much appreciated. Regards, Na'im __ 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] Scatter plot with margin distributions
Finally I get a plot manual...so I got the solution Sorry about inconveniences 2009/11/24, Jose Narillos de Santos narillosdesan...@gmail.com: Hi All, My doub I think is very simple. I hope it is. So you can again help, guide me. I´m trying to make a graph (scatter graph) about two variables, imagine I have a watter.txt file with two variables watter and hardness: This code extracted from: http://cran.r-project.org/web/packages/HSAUR/vignettes/Ch_simple_inference.pdf would make a plot similar I want I mean to make an scatterplot with marginal ditribution up and left...(in this case a boxplot on the left and also I omitt the location). layout(matrix(c(2, 0, 1, 3), 2, 2, byrow = TRUE), 2 + c(2, 1), c(1, 2), TRUE) plot(mortality ~ hardness, data = water, pch = psymb) abline(lm(mortality ~ hardness, data = water)) legend(topright, legend = levels(water$location), 7 + pch = c(1,2), bty = n) hist(water$hardness) boxplot(water$mortality) Can anyone explain what is the values in layout the inputs I mean, I have read the help but because I´m a begginer I ´m not able to comprehed why they put matrix c(2,0,1,3) and the other inputs? I need if someone can help me an easy example Thanks a lot. [[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] extract area in netcdf file
Dear R users I am working with a netcf data. The data are from a big area and I would like to extract a small region to analyse. How can one extract a region? Any help is strongly appreciated, thank you in advance [[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] searching code for combination of vector
For a given numeric vector v of length n and sum s, is there a ready- to-run code that returns every combination of v in n summing up to s? Example for n=3 and s=2: v - c(2, 0, 0) # find some coding here that returns [1] 2 0 0 [2] 1 1 0 [3] 1 0 1 [4] 0 2 0 [5] 0 1 1 [6] 0 0 2 Thanks Sören -- Sören Vogel, Dipl.-Psych. (Univ.), PhD-Student, Eawag, Dept. SIAM http://www.eawag.ch, http://sozmod.eawag.ch __ 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: remove columns with new levels automatically
Andreas Wittmann wrote: Sorry for my bad description, i don't want get a constructed algorithm without own work. i only hoped to get some advice how to do this. i don't want to predict any sort of data, i reference only to newdata which variables are the same as in the model data. But if factors in the data than i can by possibly that the newdata has a level which doesn't exist in the original data. So i have to compare each factor in the data and in the newdata and if the newdata has a levels which is not in the original data and drop this variable and do compute the model and prediction again. I thought this problem is quite common and i can use an algorithm somebody has already implemented. best regards Andreas If I understand correctly, you want to build a model that includes at least one factor predictor (say xf with k levels). Then you want to use this model to predict a response value when xf takes a _new_ level about which the model knows nothing. That doesn't make sense to me, so I doubt that it's a common problem. Introducing a new level for a factor variable is just like introducing a new variable. -Peter Ehlers Original-Nachricht Datum: Wed, 25 Nov 2009 00:48:59 -0500 Von: David Winsemius dwinsem...@comcast.net An: Andreas Wittmann andreas_wittm...@gmx.de CC: r-help@r-project.org Betreff: Re: [R] predict: remove columns with new levels automatically On Nov 24, 2009, at 2:24 PM, Andreas Wittmann wrote: Dear R-users, in the follwing thread http://tolstoy.newcastle.edu.au/R/help/03b/3322.html the problem how to remove rows for predict that contain levels which are not in the model. now i try to do this the other way round and want to remove columns (variables) in the model which will be later problematic with new levels for prediction. ## example: set.seed(0) x - rnorm(9) y - x + rnorm(9) training - data.frame(x=x, y=y, z=c(rep(A, 3), rep(B, 3), rep(C, 3))) test - data.frame(x=t-rnorm(1), y=t+rnorm(1), z=D) lm1 - lm(x ~ ., data=training) ## prediction does not work because the variable z has the new level D predict(lm1, test) ## solution: the variable z is removed from the model ## the prediction happens without using the information of variable z lm2 - lm(x ~ y, data=training) predict(lm2, test) How can i autmatically recognice this and calculate according to this? Let me get this straight. You want us to predict in advance (or more accurately design an algorithm that can see into the future and work around) any sort of newdata you might later construct -- 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] Plotting Stacked Bar
Dear R helpers, I am trying to plot a stacked graph. I have following data Month Core(%) Non_core(%) 1 45 55 2 48 52 3 36 64 4 60 40 5 35 65 Then for each of the months on X-axis, how do I plot stacked graph for core and non_core portion? I have tried the code as given in Quick_R, but i think its not appropriate The code was as - counts - table(core, non_core) barplot(counts, main=Core and Non-core) Please guide. Thanks and regards Julia Only a man of Worth sees Worth in other men [[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] extract area in netcdf file
Dear R users I am working with a netcf data. The data are from a big area and I would like to extract a small region to analyse. How can one extract a region? Any help is strongly appreciated, thank you in advance [[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] 11 distinguishable colors
Hi, Also take a look at the RColorBrewer package. cheers, Paul milton ruser wrote: Hi there, I picked it up from r.colors' grass manual: http://colorbrewer2.org/ The code bellow cold be usefull for you explore simbols and colors. x11(900,500) par(mfrow=c(1,2)) x-runif(20) y-runif(20) plot(y~x, type=n) Number.of.symbols-20 for (i in 1:Number.of.symbols) { points(y[i]~x[i], pch=i, cex=1.5) text((x[i]+0.02),y[i], i) } colors.list-colors() Number.of.colors-100 colors.list-colors.list[1:Number.of.colors] plot(0:1,0:1, type=n) for (i in colors.list) { x-runif(1) y-runif(1) text(x,y, i, col=i) } cheers miltinho On Tue, Nov 24, 2009 at 6:01 PM, phoebe kong sityeek...@gmail.com wrote: It should be 11 different groups, not 8. On Tue, Nov 24, 2009 at 3:00 PM, phoebe kong sityeek...@gmail.com wrote: Hi, I want to draw a plot where the data set has 8 different groups. Could you suggest 8 combination of colors and symbols that are distinguishable? If the colors are too close, it would be hard to differentiate from the plot. Thanks, [[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.htmlhttp://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. -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~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] R Packages Crack the 3,000 Mark!
Hello On 11/24/09, Muenchen, Robert A (Bob) muenc...@utk.edu wrote: I don't know if this has been reported before, but according to Henrique Dallazuanna's program (below) the number of R packages has exceeded the 3,000 mark. The count today is 3,175. I ran this just a couple of months ago the number was still in the high 2,000s, so it must be fairly recent. I think this represents about 50% growth in the last year. Not bad! Performing the same here I get only 2000+ packages. myPackageNames - available.packages() --- Please select a CRAN mirror for use in this session --- Loading Tcl/Tk interface ... done length(unique( rownames(myPackageNames) )) [1] 2058 And CRAN [1] reports a similar number. Perhaps you have some non-standard repositories configured? Liviu [1] http://cran.r-project.org/web/packages/ __ 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] Tests in Anova
Sarah and Dennis, thank you for help and page reference. Thanks, -- Silvano Cesar da Costa Departamento de Estatística Universidade Estadual de Londrina Fone: 3371-4346 __ 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 adline()
I run your script from the windows console (evidently), and as said, I can't reproduce your error. Can you give me the exact command you use to run it from the windows console? Cheers Joris On Tue, Nov 24, 2009 at 7:33 PM, yonosoyelmejor yonosoyelme...@hotmail.com wrote: Sure,but my problem is that the script is run from the console windows,therefore I believe that the cat or readline doesn´t work... JorisMeys wrote: I can't reproduce the error you have. With me, it runs all fine. In fact, readline apparently flushes automatically, as I didn't have to use the flush.console() at all. test.r --- cat(1- 24horas\n) cat(2- 12horas\n) cat(3- 8horas\n) selection-readline(prompt=\nSelecciona numero de horas:) if(selection==1){ cat(Selection1\n) } if(selection==2){ cat(Selection2\n) } if(selection==3){ cat(Selection3\n) } source(G:/Temp/test.r) # load the saved script test.r You can try to look at ?announce (package odfWeave) instead of cat and flush.console, but I have the slight impression there is something else going wrong. Cheers Joris On Tue, Nov 24, 2009 at 11:10 AM, yonosoyelmejor yonosoyelme...@hotmail.com wrote: I put that before selection but Nothing happened...I don´t know because when I executed the code, in the console doesn´t show cat(1-24hours)...and neither asked me Select numers of hours from de line or readline... Peter Dalgaard wrote: yonosoyelmejor wrote: Hello, I would like to ask you a question.I have a program in R and I use the readline method to ask the user some things,but i don´t use the R console but I use Win console then not appear what I put.I put the code as you look for: cat(1- 24horas\n) cat(2- 12horas\n) cat(3- 8horas\n) selection-readline(prompt=\nSelecciona numero de horas:) if(selection==1){ prediccion=exp(x.reconstruida[1441:1450]) } if(selection==2){ prediccion=exp(x.reconstruida[720:729]) } if(selection==3){ prediccion=exp(x.reconstruida[481:491]) } write.table(prediccion,C:\\Temp\\prePrueba.txt,quote=F,row.names=F,append=T,col.names=F) //end of code. Excuse me but my English is bad, i hope explained me well, A greeting, Ignacio. I think this is a matter of flushing the console before the readline call. See ?flush.console -pd -- 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. -- View this message in context: http://old.nabble.com/Readline%28%29-tp26476979p26493350.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. -- View this message in context: http://old.nabble.com/Readline%28%29-tp26476979p26499915.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] questions on the ff package
Dear Jeff, This is not exactly what you are asking, but what I do is close the object, save it as RData, and then when I need to load the RData. The RData objects themselves are very small. Best, R. On Wed, Nov 25, 2009 at 2:28 AM, Hao Cen h...@andrew.cmu.edu wrote: Hi, I have two questions on using the ff package and wonder if anyone who used ff can share some thoughts. I need to save a matrix as a memory-mapped file and load it back later. To save the matrix, I use mat = matrix(1:20, 4, 5) matFF = ff(mat, dim=dim(mat), filename=~/a.mat, overwrite=TRUE, dimnames = dimnames(mat)) To load it back, I use matFF2 = ff(vmode = double, dim= ???, filename=~/a.mat, overwrite=F) However, I don't always know the dimension when loading the matrix back. If I miss the dim attributes, ff will return it as vector. Is there a way to load the matrix without specifying the dimension? The second question is that the matrix may grow in terms of the number of rows. I would like to synchronize the change to the memory-mapped file. Is there an efficient way to do this? Thanks Jeff __ 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. -- Ramon Diaz-Uriarte Structural Biology and Biocomputing Programme Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz Phone: +34-91-732-8000 ext. 3019 __ 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 and area below a line graph
Imagine I have a variable X I use plot (X, type=l). I want to show with colour the area between the line of X and the Zero Axis. So that if X have negative values the colored area will be below zero. I´m trying to make this with polygons() but I´m not able Can you guide me to do it? The other question is how can I show the zero axis in a plot? [[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] Plot and area below a line graph
On Wed, 25 Nov 2009, Jose Narillos de Santos wrote: Imagine I have a variable X I use plot (X, type=l). I want to show with colour the area between the line of X and the Zero Axis. So that if X have negative values the colored area will be below zero. I?m trying to make this with polygons() but I?m not able Can you guide me to do it? Maybe something like this? ## artificial random walk set.seed(123) x - cumsum(rnorm(100)) ## plot plot(x, type = l) ## add shaded polygon polygon(c(1, 1:100, 100), c(0, x, 0), col = lightgray) ## zero axis abline(h = 0, lwd = 2, col = blue) hth, Z The other question is how can I show the zero axis in a plot? [[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] Method
Your suspicions were correct, I just try and works perfectly. Thank you very much for your help, :- Greetings, Ignacio. William Dunlap wrote: Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of David Winsemius Sent: Tuesday, November 24, 2009 12:22 PM To: yonosoyelmejor Cc: r-help@r-project.org Subject: Re: [R] Method On Nov 24, 2009, at 1:44 PM, yonosoyelmejor wrote: I use length(myVector),but when i want to use for example exp(x.reconstruida[length(myVector)+1:length(myVector)+9]), I need This may have nothing to do with your original problem, but I suspect that expression should be exp(x.reconstruida[(length(myVector)+1):(length(myVector)+9)]) or, equivalently, exp(x.reconstruida[length(myVector)+(1:9)]) (where the parentheses around 1:9 are not required but often helpful for understanding). Compare 5+1:5+10 [1] 16 17 18 19 20 (5+1):(5+10) [1] 6 7 8 9 10 11 12 13 14 15 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com that function returns the number of last element,would then: if the last position of my vector is 1440 exp(x.reconstruida[1440+1:1440+9] Again, (1440+1):(1440+9) or 1440+(1:9). So that should give you (assuming that you close the expression) a vector of values, e raised to a vector from elements 1441 to 1449, if such elements have already been defined and are numeric. This is what I need, I hope having explained, I do not think you have explained well enough. What is x.reconstruida? Does it have a longer length than myVector? Things would be much clearer if you made a small example (not 1440 elements long, maybe 10?). -- David A gretting, Ignacio. Johannes Graumann-2 wrote: myVector - c(seq(10),23,35) length(myVector) myVector[length(myVector)] it's unclear to me which of the two you want ... HTH, Joh yonosoyelmejor wrote: Hello, i would like to ask you another question. Is exist anymethod to vectors that tells me the last element?That is to say,I have a vector, I want to return the position of last element. I hope having explained. A greeting, Ignacio. __ 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://old.nabble.com/Method-tp26493442p26499919.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. 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-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://old.nabble.com/Method-tp26493442p26510040.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] Method
You are right,but I´ll explain,my code creates a time series,after some transformations I need to make a prediction,which predicts 10values using the above,then written in a file,I put the code to see if it looks better: # TODO: Add comment # # Author: Ignacio2 ### library(TSA) library(tseries) Invernadero-read.table(file.choose(),header=T,sep=,) attach(Invernadero) names(Invernadero) Invernadero-ts(Invernadero-Temp..Ext) plot(Hora,Invernadero,main=Temperatura Ext. Invernadero,xlab=Tiempo,ylab=Temperatura Ext.) x = log(Invernadero) #Estabilizar la varianza varianza-function(x) { ((length(x)-1)/length(x))*var(x) }#para saber la varianza varianza(x) varianza(Invernadero) x1-diff(x,lag=60) adf.test(x1) x2-diff(x1,lag=1) adf.test(x2) mean(x2) # La función “ar” permite seleccionar automáticamente “el #mejor modelo #autorregresivo: ar(x2) orden - ar(x2)$order #con esto obtenemos el orden seleccionado no toda la informacion #AIC(arima(x2,order=c(8,0,0)),arima(x2,order=c(31,0,0))) # Predicción: x2.pred.ar31-predict(arima(x2,order=c(orden,0,0)),n.ahead=10)$pred # Errores de predicción: x2.err.ar31-predict(arima(x2,order=c(orden,0,0)),n.ahead=10)$se plot(x2.err.ar31) #deshacer cambios x.completada-c(x2,x2.pred.ar31) xinv1-diffinv(x.completada,lag=1,xi=x1[1]) xinv2-diffinv(xinv1,lag=60,xi=x[1:60]) x.reconstruida-ts(xinv2,frequency=60) # Comprobación de que la reconstrucción fue correcta: yy-x-x.reconstruida[1:length(x)] # esto para Hora8 ## yy debe ser una serie de 0’s plot(yy) # Las predicciones para los minutos siguientes de la serie #original son: #prediccion = exp(x.reconstruida[481:491]) #en nuestro caso pondriamos los minutos a saber. prediccion = exp(x.reconstruida[length(x)+1:length(x)+9]) ###This is what I do not work, we still need to be reusable by if I change the number of elements write.table(prediccion,C:\\Temp\\prePrueba.txt,quote=F,row.names=F,append=T,col.names=F) Sarah Goslee wrote: If the last position of your vector is 1440, what do you expect to get from 1440 + 1??? And you certainly need some parentheses in there if you expect to get a range of values from your vector. Perhaps you need some subtraction? And no, we still can't tell exactly what you want. If this doesn't answer your question, make a reproducible example with a short vector, your code that doesn't work, and the _result you expect to get_ so we can help you. Sarah On Tue, Nov 24, 2009 at 1:44 PM, yonosoyelmejor yonosoyelme...@hotmail.com wrote: I use length(myVector),but when i want to use for example exp(x.reconstruida[length(myVector)+1:length(myVector)+9]), I need that function returns the number of last element,would then: if the last position of my vector is 1440 exp(x.reconstruida[1440+1:1440+9] This is what I need, I hope having explained, A gretting, Ignacio. -- Sarah Goslee http://www.functionaldiversity.org __ 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://old.nabble.com/Method-tp26493442p26509891.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] Re adline()
Is that what I did is to link it directly, then I click on it and I was launching the console run,but try it another way, what I did was use vectors and so I saved it.So we can conclude the issue,thank you very much indeed for your help Cheers Ignacio. JorisMeys wrote: I run your script from the windows console (evidently), and as said, I can't reproduce your error. Can you give me the exact command you use to run it from the windows console? Cheers Joris On Tue, Nov 24, 2009 at 7:33 PM, yonosoyelmejor yonosoyelme...@hotmail.com wrote: Sure,but my problem is that the script is run from the console windows,therefore I believe that the cat or readline doesn´t work... JorisMeys wrote: I can't reproduce the error you have. With me, it runs all fine. In fact, readline apparently flushes automatically, as I didn't have to use the flush.console() at all. test.r --- cat(1- 24horas\n) cat(2- 12horas\n) cat(3- 8horas\n) selection-readline(prompt=\nSelecciona numero de horas:) if(selection==1){ cat(Selection1\n) } if(selection==2){ cat(Selection2\n) } if(selection==3){ cat(Selection3\n) } source(G:/Temp/test.r) # load the saved script test.r You can try to look at ?announce (package odfWeave) instead of cat and flush.console, but I have the slight impression there is something else going wrong. Cheers Joris On Tue, Nov 24, 2009 at 11:10 AM, yonosoyelmejor yonosoyelme...@hotmail.com wrote: I put that before selection but Nothing happened...I don´t know because when I executed the code, in the console doesn´t show cat(1-24hours)...and neither asked me Select numers of hours from de line or readline... Peter Dalgaard wrote: yonosoyelmejor wrote: Hello, I would like to ask you a question.I have a program in R and I use the readline method to ask the user some things,but i don´t use the R console but I use Win console then not appear what I put.I put the code as you look for: cat(1- 24horas\n) cat(2- 12horas\n) cat(3- 8horas\n) selection-readline(prompt=\nSelecciona numero de horas:) if(selection==1){ prediccion=exp(x.reconstruida[1441:1450]) } if(selection==2){ prediccion=exp(x.reconstruida[720:729]) } if(selection==3){ prediccion=exp(x.reconstruida[481:491]) } write.table(prediccion,C:\\Temp\\prePrueba.txt,quote=F,row.names=F,append=T,col.names=F) //end of code. Excuse me but my English is bad, i hope explained me well, A greeting, Ignacio. I think this is a matter of flushing the console before the readline call. See ?flush.console -pd -- 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. -- View this message in context: http://old.nabble.com/Readline%28%29-tp26476979p26493350.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. -- View this message in context: http://old.nabble.com/Readline%28%29-tp26476979p26499915.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. -- View this message in context: http://old.nabble.com/Readline%28%29-tp26476979p26510243.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,
[R] Test Binary File
I've got an error with the way I'm using readBin on a binary file of unknown internal structure. I know the structure consists of rows and columns, but I'm not sure how many of each. So, does anyone know of a valid test set of binary data that I could reference while trying to figure out the technique of using readBin? It would be really helpful to try out readBin on a readily available and understood binary file instead of starting with one of dubious internal structure. Thank you again for your help and feedback. __ 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 from glmer
sj ssj1364 at gmail.com writes: predPN - model.matrix(terms(mod.PN),newDat) %*% fixef(mod.PN) this seems to work fine and the I print the predictions print(PredPN) [1] [2] 2.358722 2.312340 However I am not certain what I am looking at here, my best guess is that each of these could the odds (p/1-p). But I am not at all sure in my guess, any insights would be appreciated These are most likely to be log-odds rather than odds. (gmane wants me to say more or quote less ... you can use plogis(PredPN) to get the probabilities.) __ 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] Test Binary File
Do you know how it is structured? Is it 64-bit floating point, 32-bit floating point, 64 bit integer, 32 bit integer, byte values, etc.? If we know the structure, then we can determine how to decode the information. On Wed, Nov 25, 2009 at 7:34 AM, Jason Rupert jasonkrup...@yahoo.com wrote: I've got an error with the way I'm using readBin on a binary file of unknown internal structure. I know the structure consists of rows and columns, but I'm not sure how many of each. So, does anyone know of a valid test set of binary data that I could reference while trying to figure out the technique of using readBin? It would be really helpful to try out readBin on a readily available and understood binary file instead of starting with one of dubious internal structure. Thank you again for your help and feedback. __ 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.
[R] questions on the ff package
Jeff, I need to save a matrix as a memory-mapped file and load it back later. To save the matrix, I use mat = matrix(1:20, 4, 5) matFF = ff(mat, dim=dim(mat), filename=~/a.mat , overwrite=TRUE, dimnames = dimnames(mat)) # This stores the data in an ff file, # but not the metadata in R's ff object. # To do the latter you need to do save(matFF, file=~/matFF.RData) # Assuming that your ff file remains in the same location, # in a new R session you simply load(file=~/matFF.RData) # and the ff file is available automagically However, I don't always know the dimension when loading the matrix back. If I miss the dim attributes, ff will return it as vector. Is there a way to load the matrix without specifying the dimension? # You can create an ff object using your existing ff file by matFF - ff(filename=~/a.mat, vmode=double, dim=c(4,5)) # You can do the same at unknown file size with matFF - ff(filename=~/a.mat, vmode=double) # which gives you the length of the ff object length(matFF) # if you know the number of columns you can calculate the number of rows and give your ff object the interpretation of a matrix dim(matFF) - c(length(matFF)/5, 5) the matrix may grow in terms of the number of rows. Is there an efficient way to do this? # there are two ways to grow a matrix by rows # 1) you create the matrix in major row order matFF - ff(1:20, dim=c(4,5), dimorder=c(2:1)) # then you require a higher number of rows nrow(matFF) - 6 # as you can see there are new empty rows in the file matFF # 2) Instead of a matrix you create a ffdf data.frame #which you can also give more rows using nrow- #An example of this is in read.table.ffdf #which reads a csv file in chunks and extends the #number of rows in the ffdf Jens Oehlschlägel -- Preisknaller: GMX DSL Flatrate für nur 16,99 Euro/mtl.! http://portal.gmx.net/de/go/dsl02 __ 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] overdispersion and quasibinomial model
djpren wrote: Thanks for the reply. Naturally I already searched the site and help for the answers to these questions. I think I've figured out how to run a quasi-binomial model, but I cannot figure out how to test for over-dispersion or how to apply a shapiro-wilk test. This is not homework, neither do I have an instructor who is proficient in using R. This program was suggested to me by another researcher after he witnessed my frustration with the inflexibility of SPSS and other such programs. I am on a very tight schedule and I don't have time to become a statistician and computer scientist, which is why I wrote 3 very quick questions asking for commands that i had already tried to find myself. Testing for over-dispersion is probably something I can eventually get to grips with, since I just have get variance for the real and modelled data. However, I cannot find a command to do shapiro-wilks on the site or on these forums. Also, why do you say that most people here wouldn't recommend this procedure? ??shapiro stats::shapiro.test Shapiro-Wilk Normality Test (maybe you were searching for shapiro-wilks (sic)?) People often disrecommend statistical tests of normality because they have low power for small data sets (hence you don't have power to detect non-normality when it is present) and high power for large data sets even when the degree of non-normality detected is not enough to invalidate the results of some statistical procedures. Under what circumstances are the residuals from a quasibinomial GLM expected to be normally distributed ... ? -- View this message in context: http://old.nabble.com/overdispersion-and-quasibinomial-model-tp26502728p26512593.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] Test Binary File
On 25/11/2009 7:34 AM, Jason Rupert wrote: I've got an error with the way I'm using readBin on a binary file of unknown internal structure. I know the structure consists of rows and columns, but I'm not sure how many of each. So, does anyone know of a valid test set of binary data that I could reference while trying to figure out the technique of using readBin? It would be really helpful to try out readBin on a readily available and understood binary file instead of starting with one of dubious internal structure. You can write your own. For example, f - tempfile() writeBin(as.numeric(1:100), f) The hexView package is very nice for seeing what you've got: library(hexView) viewRaw(f) which will show something like this: 0 : 00 00 00 00 00 00 f0 3f 00 00 00 00 00 00 00 40 | ...?...@ 16 : 00 00 00 00 00 00 08 40 00 00 00 00 00 00 10 40 | ...@...@ 32 : 00 00 00 00 00 00 14 40 00 00 00 00 00 00 18 40 | ...@...@ ... viewRaw(f, human=real) will show 0 : 00 00 00 00 00 00 f0 3f 00 00 00 00 00 00 00 40 |1 2 16 : 00 00 00 00 00 00 08 40 00 00 00 00 00 00 10 40 |3 4 32 : 00 00 00 00 00 00 14 40 00 00 00 00 00 00 18 40 |5 6 48 : 00 00 00 00 00 00 1c 40 00 00 00 00 00 00 20 40 |7 8 ... Duncan Murdoch __ 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] interior and exterior colors of a map
Paul Murrell offered some worked examples of using paths from vector graphics in the articles and talks he has given for the grImport package: http://www.stat.auckland.ac.nz/~paul/Talks/import.pdf http://www.jstatsoft.org/v30/i04 http://cran.r-project.org/web/packages/grImport/grImport.pdf -- David On Nov 24, 2009, at 10:45 PM, dxc13 wrote: Hi useR's, I have an image plot I want to overlay a map of the United States on, via map('usa'). The image is basically a large rectangular of various colors. When I overlay the United States map, the full rectangle of the image plot is visible, but I only want to display the image WITHIN the United States boundary. Does anyone know a way to do this? Thanks in advance, dxc13 -- View this message in context: http://old.nabble.com/interior-and-exterior-colors-of-a-map-tp26507134p26507134.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. 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] predict: remove columns with new levels automatically
On Nov 25, 2009, at 1:48 AM, Andreas Wittmann wrote: Sorry for my bad description, i don't want get a constructed algorithm without own work. i only hoped to get some advice how to do this. i don't want to predict any sort of data, i reference only to newdata which variables are the same as in the model data. But if factors in the data than i can by possibly that the newdata has a level which doesn't exist in the original data. So i have to compare each factor in the data and in the newdata and if the newdata has a levels which is not in the original data and drop this variable and do compute the model and prediction again. I thought this problem is quite common and i can use an algorithm somebody has already implemented. best regards Andreas If you use str to look at the lm1 object you will find at the bottom a list called x: lm1$x will show you the factors that were present in variables at the time of the model creation lm1$x $z [1] A B C New testing scenario good level and bad level: test - data.frame(x=t-rnorm(2), y=t+rnorm(2), z=c(B, D) ) lm1 - lm(x ~ ., data=training) predict(lm1, subset(test, z %in% lm1$x$z) ) # get prediction for good level only 1 0.4225204 Original-Nachricht Datum: Wed, 25 Nov 2009 00:48:59 -0500 Von: David Winsemius dwinsem...@comcast.net An: Andreas Wittmann andreas_wittm...@gmx.de CC: r-help@r-project.org Betreff: Re: [R] predict: remove columns with new levels automatically On Nov 24, 2009, at 2:24 PM, Andreas Wittmann wrote: Dear R-users, in the follwing thread http://tolstoy.newcastle.edu.au/R/help/03b/3322.html the problem how to remove rows for predict that contain levels which are not in the model. now i try to do this the other way round and want to remove columns (variables) in the model which will be later problematic with new levels for prediction. ## example: set.seed(0) x - rnorm(9) y - x + rnorm(9) training - data.frame(x=x, y=y, z=c(rep(A, 3), rep(B, 3), rep(C, 3))) test - data.frame(x=t-rnorm(1), y=t+rnorm(1), z=D) lm1 - lm(x ~ ., data=training) ## prediction does not work because the variable z has the new level D predict(lm1, test) ## solution: the variable z is removed from the model ## the prediction happens without using the information of variable z lm2 - lm(x ~ y, data=training) predict(lm2, test) How can i autmatically recognice this and calculate according to this? Let me get this straight. You want us to predict in advance (or more accurately design an algorithm that can see into the future and work around) any sort of newdata you might later construct -- David Winsemius, MD Heritage Laboratories West Hartford, CT -- Preisknaller: GMX DSL Flatrate für nur 16,99 Euro/mtl.! http://portal.gmx.net/de/go/dsl02 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] Reading from Google Docs
I recently installed R 2.10 Now I get library(RGoogleDocs) Loading required package: RCurl Loading required package: bitops Loading required package: XML Attaching package: 'RGoogleDocs' The following object(s) are masked from package:methods : getAccess Warning message: package 'RGoogleDocs' was built under R version 2.9.1 and help will not work correctly Please re-install it But alas reinstalling it does not take away the error message. Farrel Buchinsky Google Voice Tel: (412) 567-7870 Sent from Pittsburgh, Pennsylvania, United States On Thu, Jul 9, 2009 at 08:15, Duncan Temple Lang dun...@wald.ucdavis.eduwrote: Thanks for pointing that out. Yes, the link on the package web site was for 0.2-1 and that was the one used to build the binary for Windows. Now updated in both places and the binary repository will give 0.2-2. How to find the version of an installed package? packageDescription(RGoogleDocs) D. Farrel Buchinsky wrote: Dear Duncan On my home computer I was able to use install.packages(RGoogleDocs, repos = http://www.omegahat.org/R;) But, alas it would not read the data in the spreadsheet. It went back to its nasty ways Error in !includeEmpty : invalid argument type That is what I was getting with version 0.2-1.You then sent me link to 0.2-2 (in source code) which is what worked. Is it possible that that the windows binary version you put in omegahat was 0.2-1 and not 0.2-2? I did not know how to tell what version had been installed. Farrel Buchinsky Google Voice Tel: (412) 567-7870 On Wed, Jul 8, 2009 at 22:53, Duncan Temple Lang dun...@wald.ucdavis.edumailto: dun...@wald.ucdavis.edu wrote: Farrel Buchinsky wrote: Boy oh boy that process of getting source to binary was super painful. Now that I have the package as binary I can share the whole folder with my coworker and she is able to use RGoogleDocs. I intend to use the same process for the other two windows machines that I use. I really do not want to go through the same installation and path hassles all over again. Should I post my directory containing the binary files somewhere so that others do not have to experience pain. Does etiquette dictate that I should post the directory to help other or does etiquette dictate that it is Duncan Temple Lang's code and thus it his prerogative to distribute his work as he wishes? Etiquette is one thing and the license another. Both encourage you to help others and make the binary available to others. And indeed, I hope that Windows users do build binaries for others and remove the additional work from those who provide the software in the first place. Having seen this thread today, I did put a binary version of RGoogleDocs on the Omegahat repository so install.packages(RGoogleDocs, repos = http://www.omegahat.org/R;) should install it and, if I had had time earlier, saved you the hardship of building the binary. Sorry to do it so soon after. D. Farrel Buchinsky Google Voice Tel: (412) 567-7870 On Wed, Jul 8, 2009 at 12:59, Farrel Buchinsky fjb...@gmail.com mailto:fjb...@gmail.com wrote: Does changing the path in Windows work in real time or does one need to restart the computer for the changes to take effect. Farrel Buchinsky Google Voice Tel: (412) 567-7870 On Wed, Jul 8, 2009 at 12:04, Gabor Grothendieck ggrothendi...@gmail.com mailto:ggrothendi...@gmail.com wrote: Its safer just to temporarily add it to your path. Unfortunately Rtools has a find command that conflicts with the find command in Windows so if you add the Rtools bin directory to your path permanently then you could find other programs stop working. That actually happened to me once and it took the longest time until I discovered that Rtools was the culprit. If you follow the advice I gave you normally won't have that problem. On Wed, Jul 8, 2009 at 11:21 AM, Duncan Murdochmurd...@stats.uwo.ca mailto:murd...@stats.uwo.ca wrote: On 08/07/2009 10:13 AM, Farrel Buchinsky wrote: Forgive my naivte, but how do I make windows find tar. In other words from where do I issue the command and what is the command. You need to install the toolset, and let the installer set your path. Duncan Murdoch Farrel
Re: [R] R Packages Crack the 3,000 Mark!
Hi Liviu, Yes, I selected all the repositories on the list, including things like CRAN (extras), the four Bioconductor (BioC) sites, and R-Forge. Cheers, Bob -Original Message- From: Liviu Andronic [mailto:landronim...@gmail.com] Sent: Wednesday, November 25, 2009 4:47 AM To: Muenchen, Robert A (Bob) Cc: r-help@r-project.org Subject: Re: [R] R Packages Crack the 3,000 Mark! Hello On 11/24/09, Muenchen, Robert A (Bob) muenc...@utk.edu wrote: I don't know if this has been reported before, but according to Henrique Dallazuanna's program (below) the number of R packages has exceeded the 3,000 mark. The count today is 3,175. I ran this just a couple of months ago the number was still in the high 2,000s, so it must be fairly recent. I think this represents about 50% growth in the last year. Not bad! Performing the same here I get only 2000+ packages. myPackageNames - available.packages() --- Please select a CRAN mirror for use in this session --- Loading Tcl/Tk interface ... done length(unique( rownames(myPackageNames) )) [1] 2058 And CRAN [1] reports a similar number. Perhaps you have some non-standard repositories configured? Liviu [1] http://cran.r-project.org/web/packages/ __ 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] arg min ???
Is there function what aproximate vector of parameters some function to minimum ? tet={tet1,tet2} i have they starting value and i want to find the tet what minimalizing some function of tet ? thanks -- View this message in context: http://old.nabble.com/arg-min-tp26513358p26513358.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] overdispersion and quasibinomial model
Thanks for the reply. Naturally I already searched the site and help for the answers to these questions. I think I've figured out how to run a quasi-binomial model, but I cannot figure out how to test for over-dispersion or how to apply a shapiro-wilk test. This is not homework, neither do I have an instructor who is proficient in using R. This program was suggested to me by another researcher after he witnessed my frustration with the inflexibility of SPSS and other such programs. I am on a very tight schedule and I don't have time to become a statistician and computer scientist, which is why I wrote 3 very quick questions asking for commands that i had already tried to find myself. Testing for over-dispersion is probably something I can eventually get to grips with, since I just have get variance for the real and modelled data. However, I cannot find a command to do shapiro-wilks on the site or on these forums. Also, why do you say that most people here wouldn't recommend this procedure? David Winsemius wrote: On Nov 24, 2009, at 3:41 PM, djpren wrote: I am looking for the correct commands to do the following things: 1. I have a binomial logistic regression model and i want to test for overdispersion. Under the teach a man to fish precept, ... try: RSiteSearch(test over dispersion binomial models) 2. If I do indeed have overdispersion i need to then run a quasi- binomial model, but I'm not sure of the command. ?glm # and follow the appropriate links 3. I can get the residuals of the model, but i need to then apply a shapiro wilk test to test them. Does anyone know the command for this? RSiteSearch(shapiro-wilks) # not that people here recommend this procedure The overall flavor of these questions is homework, so I'm speculating that you may want to consult your instructors. -- 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. -- View this message in context: http://old.nabble.com/overdispersion-and-quasibinomial-model-tp26502728p26511410.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] XML package example code?
Cls59 is correct that there is a lot of example code, just look in ? htmlTreeParse and you'll get most of what you need i think. here's some simplified code I use a lot of (XPath expressions are used to parse the code): # libraries library(RCurl) library(XML) # google url my.url - http://www.google.co.uk/search?hl=enclient=firefox- arls=org.mozilla%3Aen-GB%3Aofficialhs=6Sdq=google +wavebtnG=Searchmeta=aq=foq= # download page html - getURL(my.url) html.tree - htmlTreeParse(html, useInternalNodes = TRUE, error = function(...){}) # the xpath expression is next nodes - getNodeSet(html.tree, //a...@href][@class='l']) links - sapply(nodes, function(x) x - xmlAttrs(x)[[1]]) HTH Tony On 25 Nov, 01:49, Peng Yu pengyu...@gmail.com wrote: I'm interested in parsing an html page. I should use XML, right? Could you somebody show me some example code? Is there a tutorial for this package? __ r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://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] Plotting Stacked Bar
## Your original data is already the result of table(). ## Here are two versions, one using barchart and one barplot. tmpc - textConnection( Month Core(%) Non_core(%) 1 4555 2 4852 3 3664 4 6040 5 3565 ) tmp - data.matrix(read.table(tmpc, header=TRUE, row.names=Month)) close(tmpc) barchart(tmp, horizontal=FALSE) barplot(t(tmp)) __ 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] arg min ???
On Nov 25, 2009, at 9:15 AM, Peterko wrote: Is there function what aproximate vector of parameters some function to minimum ? tet={tet1,tet2} i have they starting value and i want to find the tet what minimalizing some function of tet ? ?which.min Perhaps: which.min( fn(tet) ) thanks -- View this message in context: http://old.nabble.com/arg-min-tp26513358p26513358.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. 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] Error in text.rpart(fit) : fit is not a tree, just a root
I've tried to make a decision tree for the following data set: I don't get a tree... The rpart routine has decided that the best model it can find is the intercept only model, i.e., a tree with no branches at all. Stepwise regression can have the same outcome, by the way, if no variables pass the F-to-enter threshold. The plot and text routines won't plot anything for a null tree, because there is nothing interesting to plot. Terry Therneau __ 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] Random data
Hi, how can I produce random data which lies around a straight line with angle 45 degree. Similar to this image: http://zoonek2.free.fr/UNIX/48_R/g134.png Cheers -- View this message in context: http://old.nabble.com/Random-data-tp26513822p26513822.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] overdispersion and quasibinomial model
On Nov 25, 2009, at 7:04 AM, djpren wrote: Thanks for the reply. Naturally I already searched the site and help for the answers to these questions. I think I've figured out how to run a quasi-binomial model, but I cannot figure out how to test for over-dispersion or how to apply a shapiro-wilk test. This is not homework, neither do I have an instructor who is proficient in using R. This program was suggested to me by another researcher after he witnessed my frustration with the inflexibility of SPSS and other such programs. I am on a very tight schedule and I don't have time to become a statistician and computer scientist, which is why I wrote 3 very quick questions asking for commands that i had already tried to find myself. Quick questions are somewhat deprecated here. Have you read the Posting Guide? Its overall message is that the list readership expects more detail rather than less. Perhaps with a better search method and a pointer to the glm() function, which will do what was requested, you might compose a more complete description of the data and the problem, and offer code that shows what progress you are making. Testing for over-dispersion is probably something I can eventually get to grips with, since I just have get variance for the real and modelled data. However, I cannot find a command to do shapiro-wilks on the site or on these forums. I would have thought my original reply would have pointed the way to more effective searching. The obvious search strategy using the RSiteSearch function would seem to be: RSiteSearch(shapiro wilks) A search query has been submitted to http://search.r-project.org The results page should open in your browser shortly A Browser window did open up and there were 8 hits, at least two of which were to functions that would do what you appear to be determined to do on a rather dubious basis. Also, why do you say that most people here wouldn't recommend this procedure? Are you doing this because some reviewer asked you to do so or because you are copying a path that someone else laid out for you? Testing for normality in a binomial model seems rather puzzling on the face of it. -- David. David Winsemius wrote: On Nov 24, 2009, at 3:41 PM, djpren wrote: I am looking for the correct commands to do the following things: 1. I have a binomial logistic regression model and i want to test for overdispersion. Under the teach a man to fish precept, ... try: RSiteSearch(test over dispersion binomial models) 2. If I do indeed have overdispersion i need to then run a quasi- binomial model, but I'm not sure of the command. ?glm # and follow the appropriate links 3. I can get the residuals of the model, but i need to then apply a shapiro wilk test to test them. Does anyone know the command for this? RSiteSearch(shapiro-wilks) # not that people here recommend this procedure The overall flavor of these questions is homework, so I'm speculating that you may want to consult your instructors. -- 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. -- View this message in context: http://old.nabble.com/overdispersion-and-quasibinomial-model-tp26502728p26511410.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. 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] Random data
one way is: x - sort(rnorm(100)) y - rnorm(100, mean = x, sd = 0.3) plot(x, y) abline(a = 0, b = 1) I hope it helps. Best, Dimitris mentor_ wrote: Hi, how can I produce random data which lies around a straight line with angle 45 degree. Similar to this image: http://zoonek2.free.fr/UNIX/48_R/g134.png Cheers -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 __ 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] Random data
One option, first, generate the range of x data that you want, then add normally distributed noise to each x, these will be your y data. n - 20 x - sample(20:50, n) y - rnorm(n, mean = x, sd = 3) plot(y ~ x) Erik -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of mentor_ Sent: Wednesday, November 25, 2009 8:43 AM To: r-help@r-project.org Subject: [R] Random data Hi, how can I produce random data which lies around a straight line with angle 45 degree. Similar to this image: http://zoonek2.free.fr/UNIX/48_R/g134.png Cheers -- View this message in context: http://old.nabble.com/Random-data- tp26513822p26513822.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] Random data
That's not a 45-degree angle: the x and y scales are quite different. But you can use corgen from the ecodist package to create correlated x and y variables, and then adjust the scale as needed. Sarah On Wed, Nov 25, 2009 at 9:42 AM, mentor_ ment...@gmx.net wrote: Hi, how can I produce random data which lies around a straight line with angle 45 degree. Similar to this image: http://zoonek2.free.fr/UNIX/48_R/g134.png Cheers -- Sarah Goslee http://www.functionaldiversity.org __ 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] problem in building an R package
clue_less wrote: i am trying to build an R package and submit to CRAN. i am using - package.skeleton(name=xxzz, code_files = H:\xxzz.R) to build package xxzz. --- The code above generates 'xxzz' folder. It seems that I have to manually edit the files generated in xxzz folder (to add titles, authors, etc) -- But when I re-run - package.skeleton(name=xxzz, code_files = H:\xxzz.R) Why do you rerun it once you have the structure of your package? You can add separate files now and add documentation via prompt(). Uwe Ligges All the edited information will be lost since the default files are regenerated such as DESCRIPTION file. --- I have found the process of building package is extremely troublesome. Have anybody had a better approach? 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] searching code for combination of vector
soeren.vo...@eawag.ch wrote: For a given numeric vector v of length n and sum s, is there a ready-to-run code that returns every combination of v in n summing up to s? Example for n=3 and s=2: v - c(2, 0, 0) # find some coding here that returns [1] 2 0 0 [2] 1 1 0 [3] 1 0 1 [4] 0 2 0 [5] 0 1 1 [6] 0 0 2 Function comb() in pkg:forensim does just that. -Peter Ehlers Thanks Sören __ 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 Packages Crack the 3,000 Mark!
Note that: - there are also 199 R packages on google code: http://code.google.com/hosting/search?q=label:R - some (many?) of the packages on R-Forge and on google code are also on CRAN On Wed, Nov 25, 2009 at 9:11 AM, Muenchen, Robert A (Bob) muenc...@utk.edu wrote: Hi Liviu, Yes, I selected all the repositories on the list, including things like CRAN (extras), the four Bioconductor (BioC) sites, and R-Forge. Cheers, Bob -Original Message- From: Liviu Andronic [mailto:landronim...@gmail.com] Sent: Wednesday, November 25, 2009 4:47 AM To: Muenchen, Robert A (Bob) Cc: r-help@r-project.org Subject: Re: [R] R Packages Crack the 3,000 Mark! Hello On 11/24/09, Muenchen, Robert A (Bob) muenc...@utk.edu wrote: I don't know if this has been reported before, but according to Henrique Dallazuanna's program (below) the number of R packages has exceeded the 3,000 mark. The count today is 3,175. I ran this just a couple of months ago the number was still in the high 2,000s, so it must be fairly recent. I think this represents about 50% growth in the last year. Not bad! Performing the same here I get only 2000+ packages. myPackageNames - available.packages() --- Please select a CRAN mirror for use in this session --- Loading Tcl/Tk interface ... done length(unique( rownames(myPackageNames) )) [1] 2058 And CRAN [1] reports a similar number. Perhaps you have some non-standard repositories configured? Liviu [1] http://cran.r-project.org/web/packages/ __ 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] Re-arrange Columns in data frame
Hi, I have a data frame which is 24 columns by 10 rows. This is essentially 6 groups of 4 columns. I want to re-arrange the columns into the following order 1,7,13,19,2,8,14,20,3,9,15,21,4,10,16,22,5,11,17,23,6,12,18,24 i.e. first of each group of 6 grouped together, then 2nd of each group of six etc. I know that I can do df[,c(1,7,13,19,2,8,14,20,3,9,15,21,4,10,16,22,5,11,17,23,6,12,18,24)], but what if I now have 4 groups of 4 columns, I would want the order to be c(1,5,9,13,2,6,10,14,3,7,11,15,4,8,12,16). I know that seq() comes into it somewhere, and I've got as far as seq(1,ncol(df),number_of_groups), but that gives me only one sequence. Is there a way of combining with rep() that can do this? Jabez [[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] XML package example code?
On Wed, Nov 25, 2009 at 12:19 AM, cls59 ch...@sharpsteen.net wrote: Peng Yu wrote: I'm interested in parsing an html page. I should use XML, right? Could you somebody show me some example code? Is there a tutorial for this package? Did you try looking through the help pages for the XML package or browsing the Omegahat website? Look at: library(XML) ?htmlTreeParse And the relevant web page for documentation and examples is: http://www.omegahat.org/RSXML/ http://www.omegahat.org/RSXML/shortIntro.html I'm trying the example on the above webpage. But I'm not sure why I got the following error. Would you help to take a look? $ Rscript main.R library(XML) download.file('http://www.omegahat.org/RSXML/index.html','index.html') trying URL 'http://www.omegahat.org/RSXML/index.html' Content type 'text/html; charset=ISO-8859-1' length 3021 bytes opened URL == downloaded 3021 bytes doc = xmlInternalTreeParse(index.html) Opening and ending tag mismatch: dd line 68 and dl Opening and ending tag mismatch: li line 67 and body Opening and ending tag mismatch: dt line 66 and html Premature end of data in tag dd line 64 Premature end of data in tag li line 63 Premature end of data in tag dt line 62 Premature end of data in tag dl line 61 Premature end of data in tag body line 5 Premature end of data in tag html line 1 Error: 1: Opening and ending tag mismatch: dd line 68 and dl 2: Opening and ending tag mismatch: li line 67 and body 3: Opening and ending tag mismatch: dt line 66 and html 4: Premature end of data in tag dd line 64 5: Premature end of data in tag li line 63 6: Premature end of data in tag dt line 62 7: Premature end of data in tag dl line 61 8: Premature end of data in tag body line 5 9: Premature end of data in tag html line 1 Execution halted __ 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] Structural Equation Models(SEM)
Hi R-colleagues. In the sem-package i have a problem to introduce hidden variables. As a simple example I take an ordinary factor analysis. The program: cmat=c(0.14855886, 0.05774635, 0.08003300, 0.04900990, 0.05774635, 0.18042029, 0.11213013, 0.03752475, 0.08003300, 0.11213013, 0.24646337, 0.03609901, 0.04900990, 0.03752475, 0.03609901, 0.31702970) rn=c(R,L,I,M) cn=c(R,L,I,M) tcv=matrix(cmat,nrow=4,ncol=4,dimnames=list(rn,cn)) model.RLIM - specify.model() R - f1, laddR, NA L - f1, laddL, NA I - f1, laddI, NA M - f1, laddM, NA R - R, dR,NA L - L, dL,NA I - I, dI,NA M - M, dM,NA f1 - f1, df1,NA sem.RLIM=sem(model.RLIM,tcv,101) The output: Error in dimnames(x) - dn : length of 'dimnames' [2] not equal to array extent In addition: Warning messages: 1: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : singular Hessian: model is probably underidentified. 2: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : refitting without aliased parameters. I use R version 2.10.0 (2009-10-26) under Windows XP sem_0.9-19 version. Where did I make a mistake? Have anyone of you knowledge of any other package doing similar things like Confirmative Factor Analysis Ralf Finne Novia University of Applied Science Vasa Finland __ 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-arrange Columns in data frame
Try this: # first case ix - c(matrix(1:24, 4, byrow = TRUE)) DF[ix] # second case ix - c(matrix(1:16, 4, byrow = TRUE)) DF[ix] On Wed, Nov 25, 2009 at 11:16 AM, Jabez Wilson jabez...@yahoo.co.uk wrote: Hi, I have a data frame which is 24 columns by 10 rows. This is essentially 6 groups of 4 columns. I want to re-arrange the columns into the following order 1,7,13,19,2,8,14,20,3,9,15,21,4,10,16,22,5,11,17,23,6,12,18,24 i.e. first of each group of 6 grouped together, then 2nd of each group of six etc. I know that I can do df[,c(1,7,13,19,2,8,14,20,3,9,15,21,4,10,16,22,5,11,17,23,6,12,18,24)], but what if I now have 4 groups of 4 columns, I would want the order to be c(1,5,9,13,2,6,10,14,3,7,11,15,4,8,12,16). I know that seq() comes into it somewhere, and I've got as far as seq(1,ncol(df),number_of_groups), but that gives me only one sequence. Is there a way of combining with rep() that can do this? Jabez [[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] arg min ???
This is nice, but i have to define vector of possible theta, this is not what i want to do. I have vector of unknow parameters theta. I have som estimate of theta, but i want to do better estimate of them, using some criterion function. I mean it is clasical argmin f(x_1,x_2,...x_n) to fit vector (x_1,x_2...,x_n)` David Winsemius wrote: On Nov 25, 2009, at 9:15 AM, Peterko wrote: Is there function what aproximate vector of parameters some function to minimum ? tet={tet1,tet2} i have they starting value and i want to find the tet what minimalizing some function of tet ? ?which.min Perhaps: which.min( fn(tet) ) thanks -- View this message in context: http://old.nabble.com/arg-min-tp26513358p26513358.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. 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. -- View this message in context: http://old.nabble.com/arg-min-tp26513358p26515110.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] difference of two rows
Dear R user, I'd like to calculate the difference of two rows, where ID is the same. eg.: I've got the following dataframe: ID YEAR 13 2007 15 2003 15 2006 15 2008 21 2006 21 2007 and I'd like to get the difference, like this: ID YEAR diff 13 2007 NA 15 2003 3 15 2006 2 15 2008 NA 21 2006 1 21 2007 NA that should be fairly easy...I hope Thanks for any helpful comments B. -- View this message in context: http://old.nabble.com/difference-of-two-rows-tp26515212p26515212.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] Reading from Google Docs
If your goal is solely to download data from a Google Spreadsheet into R, it is possible to configure the Google Docs access so that only read.csv is needed. The details are here: http://blog.revolution-computing.com/2009/09/how-to-use-a-google-spreadsheet-as-data-in-r.html But if you need any of the other functionality of RGoogleDocs, this isn't going to help I'm afraid. # David -- David M Smith da...@revolution-computing.com VP of Community, REvolution Computing http://blog.revolution-computing.com Tel: +1 (206) 577-4778 x3203 (Palo Alto, CA, USA) Download REvolution R free: www.revolution-computing.com/downloads/revolution-r.php On Wed, Nov 25, 2009 at 5:39 AM, Farrel Buchinsky fjb...@gmail.com wrote: I recently installed R 2.10 Now I get library(RGoogleDocs) Loading required package: RCurl Loading required package: bitops Loading required package: XML Attaching package: 'RGoogleDocs' The following object(s) are masked from package:methods : getAccess Warning message: package 'RGoogleDocs' was built under R version 2.9.1 and help will not work correctly Please re-install it But alas reinstalling it does not take away the error message. Farrel Buchinsky Google Voice Tel: (412) 567-7870 [[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] Concave hull
Dear friends, Do you know how to calculate the CONCAVE hull of a set of points (2- dimensional or n-dimensional)? is that possible in R? (With a smoothing parameter of course). Best, -- Corrado Topi Global Climate Change Biodiversity Indicators Area 18,Department of Biology University of York, York, YO10 5YW, UK Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk __ 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-arrange Columns in data frame
Thanks very much. Using the matrix function and then DF[,ix] gives me exactly what I wanted. Jabez --- On Wed, 25/11/09, Gabor Grothendieck ggrothendi...@gmail.com wrote: From: Gabor Grothendieck ggrothendi...@gmail.com Subject: Re: [R] Re-arrange Columns in data frame To: Jabez Wilson jabez...@yahoo.co.uk Cc: R Mailing List r-help@r-project.org Date: Wednesday, 25 November, 2009, 16:27 Try this: # first case ix - c(matrix(1:24, 4, byrow = TRUE)) DF[ix] # second case ix - c(matrix(1:16, 4, byrow = TRUE)) DF[ix] On Wed, Nov 25, 2009 at 11:16 AM, Jabez Wilson jabez...@yahoo.co.uk wrote: Hi, I have a data frame which is 24 columns by 10 rows. This is essentially 6 groups of 4 columns. I want to re-arrange the columns into the following order 1,7,13,19,2,8,14,20,3,9,15,21,4,10,16,22,5,11,17,23,6,12,18,24 i.e. first of each group of 6 grouped together, then 2nd of each group of six etc. I know that I can do df[,c(1,7,13,19,2,8,14,20,3,9,15,21,4,10,16,22,5,11,17,23,6,12,18,24)], but what if I now have 4 groups of 4 columns, I would want the order to be c(1,5,9,13,2,6,10,14,3,7,11,15,4,8,12,16). I know that seq() comes into it somewhere, and I've got as far as seq(1,ncol(df),number_of_groups), but that gives me only one sequence. Is there a way of combining with rep() that can do this? Jabez [[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.
[R] fitting mixture of normals distribution to asset return data
Hi, I have a 15 years of monthly return data (180 observations) from instruments that have non-normal return distributions. Thus, I would like to fit a mixture of normal distribution to each of the series. So, that I would be able to simulate from the marginal distributions like this: asset.1-exp(c(rnorm(500,-0.07,0.02),rnorm(9500,0.05,0.05)))-1 My problem is that I have tried to use Google and go through some packages (eg mixtools mclust) but haven't been able to find a function to fit the mixture of normals. I would like to have two different states of world and then get the probabilities and the mean and sigma in those states (as in the example above). I am newbie in this subject so if someone could point me a R function for this, I'd really appreciate it... br, John [[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] rattle(): unable to load shared library
Hi I'm trying to install the rattle GUI on winwos 2000, with last version R 2.10. I had a first problem using the rattle package, as it was asking pkg XMl, which is no more in the CRAN repo. I instead simply install in R/libraries the XML pkg from: http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.10/ Maybe I mised something here... So now I was able to run the library(rattle) then, using: rattle() I have following error message, it wants to install GTK+, what I do, restart R but then it does not work and I have following error message: Error in inDL(x, as.logical(local), as.logical(now), ...) : unable to load shared library 'C:/Programme/R/R-2.10.0/library/RGtk2/libs/RGtk2.dll': LoadLibrary failure: Die angegebene Prozedur wurde nicht gefunden. Failed to load RGtk2 dynamic library, attempting to install it. Learn more about GTK+ at http://www.gtk.org If the package still does not load, please ensure that GTK+ is installed and that it is on your PATH environment variable IN ANY CASE, RESTART R BEFORE TRYING TO LOAD THE PACKAGE AGAIN Error in .Call(name, ..., PACKAGE = PACKAGE) : C symbol name S_glade_xml_new not in DLL for package RGtk2 Rattle timestamp (for the error above): 2009-11-25 17:47:50 Checked for the install of GTK+, it's on the disk, and even on the PATH... don't know what I should do... any idea? Thanks!! Matthieu Stigler __ 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] Importing many files from a single code
Dear R users, Does somebody know the way to import many files by a single command in R ? I have 50 files in a directory and now, i am importing the files repeatedly (one by one). If there is a way to import all files at a time, it makes much more easy and save times too. Thanks in advance. Sincerely, Ram Kumar Basent Wageningen University, the Netherlands [[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] difference of two rows
You want to use tapply ?tapply This is a simple example dat = data.frame(a=sample(1:10,100,T),b=rnorm(100,0,1)) tapply(dat$b,dat$a,mean) Hope that helps, Sam On Wed, Nov 25, 2009 at 11:55 AM, clion birt...@hotmail.com wrote: Dear R user, I'd like to calculate the difference of two rows, where ID is the same. eg.: I've got the following dataframe: ID YEAR 13 2007 15 2003 15 2006 15 2008 21 2006 21 2007 and I'd like to get the difference, like this: ID YEAR diff 13 2007 NA 15 2003 3 15 2006 2 15 2008 NA 21 2006 1 21 2007 NA that should be fairly easy...I hope Thanks for any helpful comments B. -- View this message in context: http://old.nabble.com/difference-of-two-rows-tp26515212p26515212.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] XML package example code?
Peng Yu wrote: On Wed, Nov 25, 2009 at 12:19 AM, cls59 ch...@sharpsteen.net wrote: Peng Yu wrote: I'm interested in parsing an html page. I should use XML, right? Could you somebody show me some example code? Is there a tutorial for this package? Did you try looking through the help pages for the XML package or browsing the Omegahat website? Look at: library(XML) ?htmlTreeParse And the relevant web page for documentation and examples is: http://www.omegahat.org/RSXML/ http://www.omegahat.org/RSXML/shortIntro.html I'm trying the example on the above webpage. But I'm not sure why I got the following error. Would you help to take a look? $ Rscript main.R library(XML) download.file('http://www.omegahat.org/RSXML/index.html','index.html') trying URL 'http://www.omegahat.org/RSXML/index.html' Content type 'text/html; charset=ISO-8859-1' length 3021 bytes opened URL == downloaded 3021 bytes doc = xmlInternalTreeParse(index.html) You are trying to parse an HTML document as if it were XML. But HTML is often not well-formed. So use htmlParse() for a more forgiving parser. Or use the RTidyHTML package (www.omegahat.org/RTidyHTML) to make the HTML well-formed before passing it to xmlTreeParse() (aka xmlInternalTreeParse()). That package is an interface to libtidy. D. Opening and ending tag mismatch: dd line 68 and dl Opening and ending tag mismatch: li line 67 and body Opening and ending tag mismatch: dt line 66 and html Premature end of data in tag dd line 64 Premature end of data in tag li line 63 Premature end of data in tag dt line 62 Premature end of data in tag dl line 61 Premature end of data in tag body line 5 Premature end of data in tag html line 1 Error: 1: Opening and ending tag mismatch: dd line 68 and dl 2: Opening and ending tag mismatch: li line 67 and body 3: Opening and ending tag mismatch: dt line 66 and html 4: Premature end of data in tag dd line 64 5: Premature end of data in tag li line 63 6: Premature end of data in tag dt line 62 7: Premature end of data in tag dl line 61 8: Premature end of data in tag body line 5 9: Premature end of data in tag html line 1 Execution halted __ 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] tick marks on fold change versus fold change plot
Dear R users, i try to produce the fold change versus fold change plot where i have the values for x and y ranging from 0.01 to 100. So i start with plot(x,y,xlim=c(0.01,100),ylim=c(0.01,100), axes=F). Then i would like both axes to have tick marks as c(0.01,0.1,1,10,100) but they should appear equidistant. How should i manage this? Thank you for your help, Alla. __ 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 2.9.1: Error building target 'front'
Loris Bennett loris.benn...@fu-berlin.de writes: Bad news: I found no solution to this problem. Good news: The problem does not occur with version 2.10.0. Loris Loris Bennett loris.benn...@fu-berlin.de writes: I get the same problem using R version 2.9.2. I would be very grateful if anyone could shed some light on this issue. Regards Loris loris.benn...@fu-berlin.de (Loris Bennett) writes: Hi, I am getting the following error # (R-2.9.1/src/library/methods): gmake front /bin/sh: 0403-057 Syntax error at line 1 : `;' is not expected. gmake: *** [front] Error 2 However, I am not sure what script sh is trying to execute at this point. I am building on AIX 5.3. Here is some more information on this problem. Running gmake -n front produces for f in ; do \ if test -f ./${f}; then \ /usr/local/bin/install -c -m 644 ./${f} \ ../../../library/methods; \ fi; \ done This seems to come from the following line in share/make/basepkg.mk @for f in $(FRONTFILES); do \ Grepping for FRONTFILES yields library/stats/Makefile.in:FRONTFILES = COPYRIGHTS.modreg SOURCES.ts library/stats/Makefile.win:FRONTFILES = COPYRIGHTS.modreg SOURCES.ts library/stats/Makefile:FRONTFILES = COPYRIGHTS.modreg SOURCES.ts Is something similar missing from the makefiles in src/library/methods? Loris -- Dr. Loris Bennett Computer Centre Freie Universität Berlin Berlin, Germany __ 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. -- Dr. Loris Bennett Computer Centre Freie Universität Berlin Berlin, Germany __ 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] Unique observations
Hey R list, A beginners question. How can I do the following: In my research population it is possible that several items can appear several times, measured on different moments in time. This is being supplied in a total list with all observations identified by a number (per item) and a moment of observation (date). Now I want to make a unique list of this observation preserving the characteristics of the first observation. As example: Tree disease date Tree1 leaves 01-01-2009 Tree2 roots 13-09-2009 Tree1 roots 24-10-2009 Now I want to create a list of unique elements (in the example only once Tree1 and Tree2) with the first observed disease and date. For the example the result would look like: Tree disease date Tree1 roots 24-10-2008 Tree2 roots 13-09-2009 Can someone help me with this question? Thanks in advance. Kind regards, John [[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] XML package example code?
Not sure if my code was attached in that last post: library(RCurl) library(XML) html - getURL(http://www.omegahat.org/RSXML/index.html;) html.tree - htmlTreeParse(html, useInternalNodes = TRUE, error = function(...){}) On 25 Nov, 16:21, Peng Yu pengyu...@gmail.com wrote: On Wed, Nov 25, 2009 at 12:19 AM, cls59 ch...@sharpsteen.net wrote: Peng Yu wrote: I'm interested in parsing an html page. I should use XML, right? Could you somebody show me some example code? Is there a tutorial for this package? Did you try looking through the help pages for the XML package or browsing the Omegahat website? Look at: library(XML) ?htmlTreeParse And the relevant web page for documentation and examples is: http://www.omegahat.org/RSXML/ http://www.omegahat.org/RSXML/shortIntro.html I'm trying the example on the above webpage. But I'm not sure why I got the following error. Would you help to take a look? $ Rscript main.R library(XML) download.file('http://www.omegahat.org/RSXML/index.html','index.html') trying URL 'http://www.omegahat.org/RSXML/index.html' Content type 'text/html; charset=ISO-8859-1' length 3021 bytes opened URL == downloaded 3021 bytes doc = xmlInternalTreeParse(index.html) Opening and ending tag mismatch: dd line 68 and dl Opening and ending tag mismatch: li line 67 and body Opening and ending tag mismatch: dt line 66 and html Premature end of data in tag dd line 64 Premature end of data in tag li line 63 Premature end of data in tag dt line 62 Premature end of data in tag dl line 61 Premature end of data in tag body line 5 Premature end of data in tag html line 1 Error: 1: Opening and ending tag mismatch: dd line 68 and dl 2: Opening and ending tag mismatch: li line 67 and body 3: Opening and ending tag mismatch: dt line 66 and html 4: Premature end of data in tag dd line 64 5: Premature end of data in tag li line 63 6: Premature end of data in tag dt line 62 7: Premature end of data in tag dl line 61 8: Premature end of data in tag body line 5 9: Premature end of data in tag html line 1 Execution halted __ r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://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] R: Re: R: Re: chol( neg.def.matrix ) WAS: Re: Choleski and Choleski with pivoting of matrix fails
Dear Peter, thank you very much for your answer. My problem is that I need to calculate the following quantity: solve(chol(A)%*%Y) Y is a 3*3 diagonal matrix and A is a 3*3 matrix. Unfortunately one eigenvalue of A is negative. I can anyway take the square root of A but when I multiply it by Y, the imaginary part of the square root of A is dropped, and I do not get the right answer. I tried to exploit the diagonal structure of Y by using 2*2 matrices for A and Y. In this way the problem mentioned above disappears (since all eigenvalues of A are positive) and when I perform the calculation above I get approximately the right answer. The approximation is quite good. However it is an approximation. Any suggestion? Thank you very much! Simon Messaggio originale Da: p.dalga...@biostat.ku.dk Data: 23-nov-2009 14.09 A: simona.racio...@libero.itsimona.racio...@libero.it Cc: Charles C. Berrycbe...@tajo.ucsd.edu, r-help@r-project.org Ogg: Re: R: Re: [R] chol( neg.def.matrix ) WAS: Re: Choleski and Choleski with pivoting of matrix fails simona.racio...@libero.it wrote: It works! But Once I have the square root of this matrix, how do I convert it to a real (not imaginary) matrix which has the same property? Is that possible? No. That is theoretically impossible. If A = B'B, then x'Ax = ||Bx||^2 = 0 for any x, which implies in particular that all eigenvalues of A should be nonnegative. Best, Simon Messaggio originale Da: p.dalga...@biostat.ku.dk Data: 21-nov-2009 18.56 A: Charles C. Berrycbe...@tajo.ucsd.edu Cc: simona.racio...@libero.itsimona.racio...@libero.it, r-h...@r- project.org Ogg: Re: [R] chol( neg.def.matrix ) WAS: Re: Choleski and Choleski with pivoting of matrix fails Charles C. Berry wrote: On Sat, 21 Nov 2009, simona.racio...@libero.it wrote: Hi Everyone, I need to take the square root of the following matrix: [,1] [,2][,3] [1,] 0.5401984 -0.3998675 -1.3785897 [2,] -0.3998675 1.0561872 0.8158639 [3,] -1.3785897 0.8158639 1.6073119 I tried Choleski which fails. I then tried Choleski with pivoting, but unfortunately the square root I get is not valid. I also tried eigen decomposition but i did no get far. Any clue on how to do it?! If you want to take the square root of a negative definite matrix, you could use sqrtm( neg.def.mat ) from the expm package on rforge: http://r-forge.r-project.org/projects/expm/ But that matrix is not negative definite! It has 2 positive and one negative eigenvalue. It is non-positive definite. It is fairly easy in any case to get a matrix square root from the eigen decomposition: v%*%diag(sqrt(d+0i))%*%t(v) [,1] [,2] [,3] [1,] 0.5164499+0.4152591i -0.1247682-0.0562317i -0.7257079+0.3051868i [2,] -0.1247682-0.0562317i 0.9618445+0.0076145i 0.3469916-0.0413264i [3,] -0.7257079+0.3051868i 0.3469916-0.0413264i 1.0513849+0.2242912i ch - v%*%diag(sqrt(d+0i))%*%t(v) t(ch)%*% ch [,1] [,2] [,3] [1,] 0.5401984+0i -0.3998675-0i -1.3785897-0i [2,] -0.3998675-0i 1.0561872+0i 0.8158639-0i [3,] -1.3785897-0i 0.8158639-0i 1.6073119-0i A triangular square root is, er, more difficult, but hardly impossible. -- 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 -- 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] XML package example code?
It's been a long time since i read the tutorials, but 'I think', the reason you get those notifications is because the html code is malformed, meaning that some of the opening tags 'dd' don't have corresponding end tags /dd etc. The XML package seems rather good at working with malformed code, and therefore I usually just force those notifications into an empty function. library(RCurl) library(XML) html - getURL(http://www.omegahat.org/RSXML/index.html;) html.tree - htmlTreeParse(html, useInternalNodes = TRUE, error = function(...){}) HTH, Tony Breyal On 25 Nov, 16:21, Peng Yu pengyu...@gmail.com wrote: On Wed, Nov 25, 2009 at 12:19 AM, cls59 ch...@sharpsteen.net wrote: Peng Yu wrote: I'm interested in parsing an html page. I should use XML, right? Could you somebody show me some example code? Is there a tutorial for this package? Did you try looking through the help pages for the XML package or browsing the Omegahat website? Look at: library(XML) ?htmlTreeParse And the relevant web page for documentation and examples is: http://www.omegahat.org/RSXML/ http://www.omegahat.org/RSXML/shortIntro.html I'm trying the example on the above webpage. But I'm not sure why I got the following error. Would you help to take a look? $ Rscript main.R library(XML) download.file('http://www.omegahat.org/RSXML/index.html','index.html') trying URL 'http://www.omegahat.org/RSXML/index.html' Content type 'text/html; charset=ISO-8859-1' length 3021 bytes opened URL == downloaded 3021 bytes doc = xmlInternalTreeParse(index.html) Opening and ending tag mismatch: dd line 68 and dl Opening and ending tag mismatch: li line 67 and body Opening and ending tag mismatch: dt line 66 and html Premature end of data in tag dd line 64 Premature end of data in tag li line 63 Premature end of data in tag dt line 62 Premature end of data in tag dl line 61 Premature end of data in tag body line 5 Premature end of data in tag html line 1 Error: 1: Opening and ending tag mismatch: dd line 68 and dl 2: Opening and ending tag mismatch: li line 67 and body 3: Opening and ending tag mismatch: dt line 66 and html 4: Premature end of data in tag dd line 64 5: Premature end of data in tag li line 63 6: Premature end of data in tag dt line 62 7: Premature end of data in tag dl line 61 8: Premature end of data in tag body line 5 9: Premature end of data in tag html line 1 Execution halted __ r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://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] tick marks on fold change versus fold change plot
It sounds like you want to plot 'log' on both axis: plot(..., log='xy') On Wed, Nov 25, 2009 at 12:24 PM, Alla Bulashevska alla.bullashev...@fdm.uni-freiburg.de wrote: Dear R users, i try to produce the fold change versus fold change plot where i have the values for x and y ranging from 0.01 to 100. So i start with plot(x,y,xlim=c(0.01,100),ylim=c(0.01,100), axes=F). Then i would like both axes to have tick marks as c(0.01,0.1,1,10,100) but they should appear equidistant. How should i manage this? Thank you for your help, Alla. __ 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] Natural colours for topographic data
Tysdag 24. november 2009 11.08.08 skreiv du: I would be happy with a simple one, that just mapped negative values to water colours and positive values to land colours. Have you tried my colourscheme package? Its not on CRAN but you can get it from here: Thanks for the suggestion. It looks very nice. Perhaps I’ll even write a general function for generating topographic colour scales, based on this. (It might be a while before it’s ready, though.) -- Karl Ove Hufthammer http://huftis.org/ Jabber: k...@huftis.org __ 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] Importing many files from a single code
Exactly what do you mean by import? What commands are you using? You can get a list of the files in a directory and then iterate through reading each one in. If you use 'lapply', you can 'read.table' in some data frames and then 'rbind' them into a single data frame. You need to be more specific on the problem you are trying to solve. On Wed, Nov 25, 2009 at 9:35 AM, ram basnet basnet...@yahoo.com wrote: Dear R users, Does somebody know the way to import many files by a single command in R ? I have 50 files in a directory and now, i am importing the files repeatedly (one by one). If there is a way to import all files at a time, it makes much more easy and save times too. Thanks in advance. Sincerely, Ram Kumar Basent Wageningen University, the Netherlands [[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. -- 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] Unique observations
shouldn't the first observation for Tree1 be Tree1 leaves 01-01-2009? x - read.table(textConnection(Tree disease date + Tree1 leaves 01-01-2009 + Tree2 roots 13-09-2009 + Tree1 roots 24-10-2009), header=TRUE) closeAllConnections() # split by Tree and take first observation do.call('rbind', lapply(split(x, x$Tree), function(.tr) .tr[1,])) Tree disease date Tree1 Tree1 leaves 01-01-2009 Tree2 Tree2 roots 13-09-2009 On Wed, Nov 25, 2009 at 9:44 AM, John Lipkins john.lipk...@googlemail.com wrote: Hey R list, A beginners question. How can I do the following: In my research population it is possible that several items can appear several times, measured on different moments in time. This is being supplied in a total list with all observations identified by a number (per item) and a moment of observation (date). Now I want to make a unique list of this observation preserving the characteristics of the first observation. As example: Tree disease date Tree1 leaves 01-01-2009 Tree2 roots 13-09-2009 Tree1 roots 24-10-2009 Now I want to create a list of unique elements (in the example only once Tree1 and Tree2) with the first observed disease and date. For the example the result would look like: Tree disease date Tree1 roots 24-10-2008 Tree2 roots 13-09-2009 Can someone help me with this question? Thanks in advance. Kind regards, John [[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. -- 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] Unique observations
On Nov 25, 2009, at 9:44 AM, John Lipkins wrote: Hey R list, A beginners question. How can I do the following: In my research population it is possible that several items can appear several times, measured on different moments in time. This is being supplied in a total list with all observations identified by a number (per item) and a moment of observation (date). Now I want to make a unique list of this observation preserving the characteristics of the first observation. As example: Tree disease date Tree1 leaves 01-01-2009 Tree2 roots 13-09-2009 Tree1 roots 24-10-2009 Now I want to create a list of unique elements (in the example only once Tree1 and Tree2) with the first observed disease and date. For the example the result would look like: Tree disease date Tree1 roots 24-10-2008 Tree2 roots 13-09-2009 Can someone help me with this question? I think the function you will need include: ?as.Date #to get the date field into sortable form ?order#as in treedat2 - treedat[ order(treedat$dt, treedat$Tree), ] ?duplicated # as in treedat2[ !duplicated(treedat2(Tree), ] -- 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] difference of two rows
Try this: x - read.table(textConnection(ID YEAR + 13 2007 + 15 2003 + 15 2006 + 15 2008 + 21 2006 + 21 2007), header=TRUE) x$diff - ave(x$YEAR, x$ID, FUN=function(a) c(diff(a), NA)) x ID YEAR diff 1 13 2007 NA 2 15 20033 3 15 20062 4 15 2008 NA 5 21 20061 6 21 2007 NA On Wed, Nov 25, 2009 at 10:55 AM, clion birt...@hotmail.com wrote: Dear R user, I'd like to calculate the difference of two rows, where ID is the same. eg.: I've got the following dataframe: ID YEAR 13 2007 15 2003 15 2006 15 2008 21 2006 21 2007 and I'd like to get the difference, like this: ID YEAR diff 13 2007 NA 15 2003 3 15 2006 2 15 2008 NA 21 2006 1 21 2007 NA that should be fairly easy...I hope Thanks for any helpful comments B. -- View this message in context: http://old.nabble.com/difference-of-two-rows-tp26515212p26515212.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] R Packages Crack the 3,000 Mark!
I thought that the unique function would eliminate duplicate package names. Is there a better way to count the number of packages? Thanks, Bob -Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: Wednesday, November 25, 2009 10:40 AM To: Muenchen, Robert A (Bob) Cc: r-help@r-project.org Subject: Re: [R] R Packages Crack the 3,000 Mark! Note that: - there are also 199 R packages on google code: http://code.google.com/hosting/search?q=label:R - some (many?) of the packages on R-Forge and on google code are also on CRAN On Wed, Nov 25, 2009 at 9:11 AM, Muenchen, Robert A (Bob) muenc...@utk.edu wrote: Hi Liviu, Yes, I selected all the repositories on the list, including things like CRAN (extras), the four Bioconductor (BioC) sites, and R-Forge. Cheers, Bob -Original Message- From: Liviu Andronic [mailto:landronim...@gmail.com] Sent: Wednesday, November 25, 2009 4:47 AM To: Muenchen, Robert A (Bob) Cc: r-help@r-project.org Subject: Re: [R] R Packages Crack the 3,000 Mark! Hello On 11/24/09, Muenchen, Robert A (Bob) muenc...@utk.edu wrote: I don't know if this has been reported before, but according to Henrique Dallazuanna's program (below) the number of R packages has exceeded the 3,000 mark. The count today is 3,175. I ran this just a couple of months ago the number was still in the high 2,000s, so it must be fairly recent. I think this represents about 50% growth in the last year. Not bad! Performing the same here I get only 2000+ packages. myPackageNames - available.packages() --- Please select a CRAN mirror for use in this session --- Loading Tcl/Tk interface ... done length(unique( rownames(myPackageNames) )) [1] 2058 And CRAN [1] reports a similar number. Perhaps you have some non-standard repositories configured? Liviu [1] http://cran.r-project.org/web/packages/ __ 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] Importing many files from a single code
See the example in ?source, which does exactly this... or make a package depending on your needs. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of ram basnet Sent: Wednesday, November 25, 2009 8:35 AM To: R help Subject: [R] Importing many files from a single code Dear R users, Does somebody know the way to import many files by a single command in R ? I have 50 files in a directory and now, i am importing the files repeatedly (one by one). If there is a way to import all files at a time, it makes much more easy and save times too. Thanks in advance. Sincerely, Ram Kumar Basent Wageningen University, the Netherlands [[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] fitting mixture of normals distribution to asset return data
Dear John, I don't know what the exp stuff in your line below is about, but mclustBIC in package mclust does fit normal mixtures. Try for a start library(mclust) mmm - mclustBIC(data,G=2) mmms - summary(mmm) mmms If you want to learn more, read the documentation. Christian On Wed, 25 Nov 2009, John Seppänen wrote: Hi, I have a 15 years of monthly return data (180 observations) from instruments that have non-normal return distributions. Thus, I would like to fit a mixture of normal distribution to each of the series. So, that I would be able to simulate from the marginal distributions like this: asset.1-exp(c(rnorm(500,-0.07,0.02),rnorm(9500,0.05,0.05)))-1 My problem is that I have tried to use Google and go through some packages (eg mixtools mclust) but haven't been able to find a function to fit the mixture of normals. I would like to have two different states of world and then get the probabilities and the mean and sigma in those states (as in the example above). I am newbie in this subject so if someone could point me a R function for this, I'd really appreciate it... br, John [[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. *** --- *** Christian Hennig University College London, Department of Statistical Science Gower St., London WC1E 6BT, phone +44 207 679 1698 chr...@stats.ucl.ac.uk, www.homepages.ucl.ac.uk/~ucakche__ 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] Structural Equation Models(SEM)
The model you have specified there is not an ordinary factor analysis model. This may be closer to what you are thinking of: model.RLIM - specify.model() f1 - R, laddR, NA f1 - L, laddL, NA f1 - I, laddI, NA f1 - M, laddM, NA R - R, dR, NA L - L, dL, NA I - I, dI, NA M - M, dM, NA f1 - f1, NA, 1 sem.RLIM=sem(model.RLIM,tcv,101) summary(sem.RLIM) Note that the paths go from the latent factor to the manifest variables, not vice-versa. Best, -- Wolfgang Viechtbauerhttp://www.wvbauer.com/ Department of Methodology and StatisticsTel: +31 (0)43 388-2277 School for Public Health and Primary Care Office Location: Maastricht University, P.O. Box 616 Room B2.01 (second floor) 6200 MD Maastricht, The Netherlands Debyeplein 1 (Randwyck) From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of Ralf Finne [ralf.fi...@novia.fi] Sent: Wednesday, November 25, 2009 5:23 PM To: r-help@r-project.org Subject: [R] Structural Equation Models(SEM) Hi R-colleagues. In the sem-package i have a problem to introduce hidden variables. As a simple example I take an ordinary factor analysis. The program: cmat=c(0.14855886, 0.05774635, 0.08003300, 0.04900990, 0.05774635, 0.18042029, 0.11213013, 0.03752475, 0.08003300, 0.11213013, 0.24646337, 0.03609901, 0.04900990, 0.03752475, 0.03609901, 0.31702970) rn=c(R,L,I,M) cn=c(R,L,I,M) tcv=matrix(cmat,nrow=4,ncol=4,dimnames=list(rn,cn)) model.RLIM - specify.model() R - f1, laddR, NA L - f1, laddL, NA I - f1, laddI, NA M - f1, laddM, NA R - R, dR,NA L - L, dL,NA I - I, dI,NA M - M, dM,NA f1 - f1, df1,NA sem.RLIM=sem(model.RLIM,tcv,101) The output: Error in dimnames(x) - dn : length of 'dimnames' [2] not equal to array extent In addition: Warning messages: 1: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : singular Hessian: model is probably underidentified. 2: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : refitting without aliased parameters. I use R version 2.10.0 (2009-10-26) under Windows XP sem_0.9-19 version. Where did I make a mistake? Have anyone of you knowledge of any other package doing similar things like Confirmative Factor Analysis Ralf Finne Novia University of Applied Science Vasa Finland __ 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] Importing many files from a single code
On Nov 25, 2009, at 9:35 AM, ram basnet wrote: Dear R users, Does somebody know the way to import many files by a single command in R ? I have 50 files in a directory and now, i am importing the files repeatedly (one by one). If there is a way to import all files at a time, it makes much more easy and save times too. Thanks in advance. Learn to search: RSiteSearch(import many files) A search query has been submitted to http://search.r-project.org The results page should open in your browser shortly One link away you find: https://stat.ethz.ch/pipermail/r-help/attachments/20080903/4172cd28/attachment.pl -- 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] Structural Equation Models(SEM)
Ralf, If you are representing this as a factor model, you need to have the factors lead to the variables: model.RLIM - specify.model() f1 - R , laddR, NA f1 - L, laddL, NA f1 - I, laddI, NA f1 - M, laddM, NA R - R, dR,NA L - L, dL,NA I - I, dI,NA M - M, dM,NA f1 - f1, df1,NA sem(mod1,tcv,101) Model Chisquare = 5.955411 Df = 3 F1RF1LF1Ix1ex2ex3ex4e 0.20301850 0.28443881 0.39421470 0.10734247 0.09951485 0.09105800 0.31702970 Iterations = 24 For a simple way to create the sem commands from an exploratory factor analysis, you might want to look at the psych package and the vignette: psych_for_sem. e.g., library(psych) f1 - fa(tcv) #do the exploratory factor analysis mod1 - structure.diagram(f1,errors=TRUE) #draw the path diagram from the model and create the sem commands mod1 Path Parameter StartValue 1 MR1-RF1R 2 MR1-LF1L 3 MR1-IF1I 4 R-R x1e 5 L-L x2e 6 I-I x3e 7 M-M x4e 8 MR1-MR1 fixed 1 sem(mod1,tcv,101) #do the sem Model Chisquare = 5.955411 Df = 3 F1RF1LF1Ix1ex2ex3ex4e 0.20301850 0.28443881 0.39421470 0.10734247 0.09951485 0.09105800 0.31702970 Iterations = 24 Best wishes, Bill At 6:23 PM +0200 11/25/09, Ralf Finne wrote: Hi R-colleagues. In the sem-package i have a problem to introduce hidden variables. As a simple example I take an ordinary factor analysis. The program: cmat=c(0.14855886, 0.05774635, 0.08003300, 0.04900990, 0.05774635, 0.18042029, 0.11213013, 0.03752475, 0.08003300, 0.11213013, 0.24646337, 0.03609901, 0.04900990, 0.03752475, 0.03609901, 0.31702970) rn=c(R,L,I,M) cn=c(R,L,I,M) tcv=matrix(cmat,nrow=4,ncol=4,dimnames=list(rn,cn)) model.RLIM - specify.model() R - f1, laddR, NA L - f1, laddL, NA I - f1, laddI, NA M - f1, laddM, NA R - R, dR,NA L - L, dL,NA I - I, dI,NA M - M, dM,NA f1 - f1, df1,NA sem.RLIM=sem(model.RLIM,tcv,101) The output: Error in dimnames(x) - dn : length of 'dimnames' [2] not equal to array extent In addition: Warning messages: 1: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : singular Hessian: model is probably underidentified. 2: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : refitting without aliased parameters. I use R version 2.10.0 (2009-10-26) under Windows XP sem_0.9-19 version. Where did I make a mistake? Have anyone of you knowledge of any other package doing similar things like Confirmative Factor Analysis Ralf Finne Novia University of Applied Science Vasa Finland __ 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. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnight http://www.thebulletin.org __ 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] order of panels in xyplots
I'd like do a simple xyplot with customized order of panels and try to understand how to use index.cond for that. Several attempts didn't deliver the correct results. Now, I noticed the following: p - xyplot(dur~roi|trial, data) p$index.cond [[1]] [1] 1 2 3 4 5 6 7 8 9 10 These numbers are valid indexing vector for the integer vector '1:nlevels(g_i)' but levels(data$trial)[p$index.cond[[1]]] does not yield the correct level names of the data points in data. (Actually the first ten levels are not used in data.) I was expecting that this should plot the panels in the order in which the levels occur in the data frame: xyplot(dur~roi|trial, data, index.cond=unique(as.integer(data$trial))) But this leaves the panels empty. Could anybody please help me to understand this? Thanks! Titus __ 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] draw circle on PCA plot
Hi, I have a hard time in drawing circle on PCA. I have 60 samples. The corresponding PC1 scores and PC2 scores were stored as mergedata. Here are the summary of PCs scores. range(mergedata[,PC1]) [1] 0.0085 0.0100 range(mergedata[,PC2]) [1] 0.0032 0.0075 mean(mergedata[,PC1]) [1] 0.009241667 mean(mergedata[,PC2]) [1] 0.005541667 dim(mergedata) [1] 60 102 First of all, I need to find the center of the cluster points in PC plot. Then, I would lilke to draw out from that center concentric circles with radius 1 SD, 1.5 SD, 2 SD, 2.5 SD and 3 SD. plot(mergedata[,PC1],mergedata[,PC2],xlab=PC1,ylab=PC2,xlim=range(mergedata[,PC1]),ylim=range(mergedata[,PC2]),pch=20,col=blue) circle with radius 1SD symbols(mean(mergedata[,PC1]),mean(mergedata[,PC2]),circle=sd(c(mergedata[,PC2],mergedata[,PC1])),inches=FALSE,add=TRUE) However, only points were plotted, but the cicle doesn't appear. Could anyone tell me what's wrong with my code? Thanks, Phoebe [[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] augPred and nlme
Hello there, Using 'The R Book' (p675-677) I am following instructions on performing a series of nonlinear regressions fitting the same model to a set of groups. I have been to able to fit the model to my data using the following call to nlme: library(nlme) inorg.model-nlme(inorg.grv ~ a*exp( - ((numDate-b)^2 / 2*c^2)), fixed=a+b+c~1, random=a~1|Sectionf, start=c(a=adi,b=bdi,c=cdi), verbose = TRUE) Now, again following the R book, I would like to plot these models using augPred. However I receive the following error: plot(augPred(inorg.model)) Error in augPred.lme(inorg.model) : Data in inorg.model call must evaluate to a data frame I am not sure even how to diagnose this problem. I basically followed to R book directions to the letter. I could plot each of these curves from each out individually but the prospect of R doing it all for me is too tempting. I am using R 2.8.1-1 and Ubuntu 9.04. Thanks in advance! Sam -- * Sam Albers Geography Program University of Northern British Columbia University Way Prince George, British Columbia Canada, V2N 4Z9 phone: 250 960-6777 * [[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] order of panels in xyplots
On Wed, Nov 25, 2009 at 7:03 PM, Titus Malsburg malsb...@gmail.com wrote: I was expecting that this should plot the panels in the order in which the levels occur in the data frame: xyplot(dur~roi|trial, data, index.cond=unique(as.integer(data$trial))) The answer is apparently: xyplot(dur~roi|trial, data, index.cond=rank(unique(data$trial))) (Strange phenomenon, that I very often find the solution myself minutes after posting to the mailing list.) Best, Titus __ 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 writing for loop
Hi, I’d like to ask for some help in writing a loop. My situation is the following: I have a matrix (matrix.A) containing 3 columns and 100 rows. The columns represent parameter estimates a, b, and c. The rows contain different values for these parameter estimates. Each row is unique. I want to insert these parameter estimates into a model (say, y = a + bx + cx^2) and solve for y given a separate matrix (matrix.B) of x values (where x has a length of 1500). I want to solve for y 100 times using each set of the parameter estimates in matrix.A once. At present my code looks like this and it only performs the first iteration. For (i in 1:length(matrix.A)) { y - matrix.A$a[[i]] + matrixA$b[[i]] * matrix.B$x + matrixA$c[[i]] * matrix.B$x^2) I have not been able to figure out how to loop through the rows of parameter estimates in matrix.A. I am new to writing loops, so any assistance would be much appreciated. Regards, Jessica Schedlbauer __ 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] order of panels in xyplots
On 11/25/2009 07:33 PM, Titus Malsburg wrote: On Wed, Nov 25, 2009 at 7:03 PM, Titus Malsburg malsb...@gmail.com wrote: I was expecting that this should plot the panels in the order in which the levels occur in the data frame: xyplot(dur~roi|trial, data, index.cond=unique(as.integer(data$trial))) The answer is apparently: xyplot(dur~roi|trial, data, index.cond=rank(unique(data$trial))) (Strange phenomenon, that I very often find the solution myself minutes after posting to the mailing list.) Best, Titus __ 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. An alternative could be to reorder the levels of trial prior to calling xyplot or in the xyplot call itself (useful if you want to order the levels on some other criterion like the mean or median of another variable). See ?reorder Just a thought S __ 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] Grouped Barplot
Hi R Users, I tried plotting a similar boxplot as it is on the FOLLOWING LINK: http://www.imachordata.com/wp-content/uploads/2009/09/boxplot.png Sample data is attached -- there are 9 years and 5 cities. In my case I'm looking to plot Year on x-axis and grouping boxplots by City. I tried the following code. foo-read.table(SampleData.csv, sep=,, header=TRUE) attach(foo) boxplot(Admit ~ City + Year, range=0.5, col=2:6) # its not solving the purpose I need some help with: 1) Plotting only 9 labels on x-axis (1996-2004). 2) For each Year, I need to plot FIVE boxplots -- one for each City. [so it will look like nine clusters with five boxplots each (with no gap between them, but with gaps between year labels]. 3) Adding MEAN to the boxplots. 4) And, legend including color + city name. Any help would be greatly appreciated! ~Gary __ 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: Re: R: Re: chol( neg.def.matrix ) WAS: Re: Choleski and Choleski with pivoting of matrix fails
I do not understand what the problem is, as it works just fine for me: A - matrix(c(0.5401984,-0.3998675,-1.3785897,-0.3998675,1.0561872, 0.8158639,-1.3785897, 0.8158639, 1.6073119), 3, 3, byrow=TRUE) eA - eigen(A) chA - eA$vec %*% diag(sqrt(eA$val+0i)) %*% t(eA$vec) all.equal(A, Re(chA %*% t(chA))) Y - diag(c(1,2,3)) solve(chA %*% Y) 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 simona.racio...@libero.it Sent: Wednesday, November 25, 2009 9:59 AM To: p.dalga...@biostat.ku.dk Cc: r-help@r-project.org Subject: [R] R: Re: R: Re: chol( neg.def.matrix ) WAS: Re: Choleski and Choleski with pivoting of matrix fails Dear Peter, thank you very much for your answer. My problem is that I need to calculate the following quantity: solve(chol(A)%*%Y) Y is a 3*3 diagonal matrix and A is a 3*3 matrix. Unfortunately one eigenvalue of A is negative. I can anyway take the square root of A but when I multiply it by Y, the imaginary part of the square root of A is dropped, and I do not get the right answer. I tried to exploit the diagonal structure of Y by using 2*2 matrices for A and Y. In this way the problem mentioned above disappears (since all eigenvalues of A are positive) and when I perform the calculation above I get approximately the right answer. The approximation is quite good. However it is an approximation. Any suggestion? Thank you very much! Simon Messaggio originale Da: p.dalga...@biostat.ku.dk Data: 23-nov-2009 14.09 A: simona.racio...@libero.itsimona.racio...@libero.it Cc: Charles C. Berrycbe...@tajo.ucsd.edu, r-help@r-project.org Ogg: Re: R: Re: [R] chol( neg.def.matrix ) WAS: Re: Choleski and Choleski with pivoting of matrix fails simona.racio...@libero.it wrote: It works! But Once I have the square root of this matrix, how do I convert it to a real (not imaginary) matrix which has the same property? Is that possible? No. That is theoretically impossible. If A = B'B, then x'Ax = ||Bx||^2 = 0 for any x, which implies in particular that all eigenvalues of A should be nonnegative. Best, Simon Messaggio originale Da: p.dalga...@biostat.ku.dk Data: 21-nov-2009 18.56 A: Charles C. Berrycbe...@tajo.ucsd.edu Cc: simona.racio...@libero.itsimona.racio...@libero.it, r-h...@r- project.org Ogg: Re: [R] chol( neg.def.matrix ) WAS: Re: Choleski and Choleski with pivoting of matrix fails Charles C. Berry wrote: On Sat, 21 Nov 2009, simona.racio...@libero.it wrote: Hi Everyone, I need to take the square root of the following matrix: [,1] [,2][,3] [1,] 0.5401984 -0.3998675 -1.3785897 [2,] -0.3998675 1.0561872 0.8158639 [3,] -1.3785897 0.8158639 1.6073119 I tried Choleski which fails. I then tried Choleski with pivoting, but unfortunately the square root I get is not valid. I also tried eigen decomposition but i did no get far. Any clue on how to do it?! If you want to take the square root of a negative definite matrix, you could use sqrtm( neg.def.mat ) from the expm package on rforge: http://r-forge.r-project.org/projects/expm/ But that matrix is not negative definite! It has 2 positive and one negative eigenvalue. It is non-positive definite. It is fairly easy in any case to get a matrix square root from the eigen decomposition: v%*%diag(sqrt(d+0i))%*%t(v) [,1] [,2] [,3] [1,] 0.5164499+0.4152591i -0.1247682-0.0562317i -0.7257079+0.3051868i [2,] -0.1247682-0.0562317i 0.9618445+0.0076145i 0.3469916-0.0413264i [3,] -0.7257079+0.3051868i 0.3469916-0.0413264i 1.0513849+0.2242912i ch - v%*%diag(sqrt(d+0i))%*%t(v) t(ch)%*% ch [,1] [,2] [,3] [1,] 0.5401984+0i -0.3998675-0i -1.3785897-0i [2,] -0.3998675-0i 1.0561872+0i 0.8158639-0i [3,] -1.3785897-0i 0.8158639-0i 1.6073119-0i A triangular square root is, er, more difficult, but hardly impossible. -- 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 -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen
[R] Sampling dataframe
Hi, I have a table like that: datatest var1 var2 var3 1 111 2 312 3 813 4 614 51015 6 221 7 422 8 623 9 824 10 1025 I need to create another table based on that with the rules: take a random sample by var2==1 (2 sample rows for example): var1 var2 var3 1 111 4 614 in this random sample a get the 1 and 4 value on the var3, now I need to complete the table with var1==2 with the lines that var3 are not select on var2==1 The resulting table is: var1 var2 var3 1 111 4 614 7 422 8 623 10 1025 the value 1 and 4 on var3 is not present in the var2==2. I try several options but without success. take a random value is easy, but I cant select the others value excluding the random selected values. Any help? Thanks Ronaldo -- 17ª lei - Seu orientador quer que você se torne famoso, de modo que ele possa, finalmente, se tornar famoso. --Herman, I. P. 2007. Following the law. NATURE, Vol 445, p. 228. -- Prof. Ronaldo Reis Júnior | .''`. UNIMONTES/DBG/Lab. Ecologia Comportamental e Computacional | : :' : Campus Universitário Prof. Darcy Ribeiro, Vila Mauricéia | `. `'` CP: 126, CEP: 39401-089, Montes Claros - MG - Brasil | `- Fone: (38) 3229-8192 | ronaldo.r...@unimontes.br | chrys...@gmail.com | http://www.ppgcb.unimontes.br/lecc | ICQ#: 5692561 | LinuxUser#: 205366 -- Favor NÃO ENVIAR arquivos do Word ou Powerpoint Prefira enviar em PDF, Texto, OpenOffice (ODF), HTML, or RTF. __ 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] overdispersion and quasibinomial model
djpren wrote: Thanks for the reply. Naturally I already searched the site and help for the answers to these questions. I think I've figured out how to run a quasi-binomial model, but I cannot figure out how to test for over-dispersion or how to apply a shapiro-wilk test. This is not homework, neither do I have an instructor who is proficient in using R. This program was suggested to me by another researcher after he witnessed my frustration with the inflexibility of SPSS and other such programs. I am on a very tight schedule and I don't have time to become a statistician and computer scientist, which is why I wrote 3 very quick questions asking for commands that i had already tried to find myself. Testing for over-dispersion is probably something I can eventually get to grips with, since I just have get variance for the real and modelled data. However, I cannot find a command to do shapiro-wilks on the site or on these forums. Also, why do you say that most people here wouldn't recommend this procedure? The customary (well, at least to me) to check for overdispersion is to look at the ratio of the sum of squared Pearson residuals over residual degrees of freedom. This is well discussed in MASS (the book). Example: library(MASS) fm1 - glm(low ~ age + race, family = binomial, data = birthwt) phi - sum(resid(fm, type = pearson)^2) / df.residual(fm) phi #[1] 1.011612 For a binomial glm, this value is expected to be near 1.0 as it is here. So there is no indication of overdispersion in this example. I don't know of a specific test for overdispersion. Personally, I start to worry about the adequacy of the model if the data set is large and phi is greater than about 1.2. For small data sets I wouldn't be too concerned if phi is less than 1.5. But this all depends crucially on what you want to do with your model results. Adjusting phi to be greater than 1.0 will provide more conservative estimates of the parameters. Note that using family=quasibinomial won't change the parameter estimates, just their SEs. fm2 - glm(low ~ age + race, family = quasibinomial, data = birthwt) Now you can compare summary(fm1) with summary(fm2). What Shapiro-Wilk has to do with this is: Nothing! -Peter Ehlers David Winsemius wrote: On Nov 24, 2009, at 3:41 PM, djpren wrote: I am looking for the correct commands to do the following things: 1. I have a binomial logistic regression model and i want to test for overdispersion. Under the teach a man to fish precept, ... try: RSiteSearch(test over dispersion binomial models) 2. If I do indeed have overdispersion i need to then run a quasi- binomial model, but I'm not sure of the command. ?glm # and follow the appropriate links 3. I can get the residuals of the model, but i need to then apply a shapiro wilk test to test them. Does anyone know the command for this? RSiteSearch(shapiro-wilks) # not that people here recommend this procedure The overall flavor of these questions is homework, so I'm speculating that you may want to consult your instructors. -- 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-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] Is there a package for generating standardized R script command line options?
Hi, In python, there is a package that helps generating command line options. I am wondering if there is such a package in R that helps generating the command options for a R script? http://docs.python.org/library/optparse.html Regards, Peng I recently put a package on CRAN that tries to implement much of the functionality and approach of python's optparse library: http://cran.r-project.org/web/packages/optparse/ It contains a package vignette (use vignette(optparse) after installing the package) that illustrates an example program using optparse and trying it with various options on the command line. The getopt package or manually parsing the command line remain good approaches too. Trevor Davis Research Assistant Division of Research Statistics Federal Reserve Board of Governors __ 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] multi variate plot with string data
Ive got two columns in data_set that are strings the first column is called character and has levels: good, bad, ugly the second column is called abusive and has levels: aggressive, moderately aggressive, mildly aggressive I want to do a stacked boxplot that has this sort of structure: %aggressive %aggressive %aggressive %moderately aggressive %moderately aggressive %moderately aggressive %mildly aggressive %mildly aggressive %mildly aggressive %not agressive %not agressive %not agressive bad good ugly ...with legend at the size showing which colour each of the abusive levels takes. How is it done? -- View this message in context: http://old.nabble.com/multi-variate-plot-with-string-data-tp26517211p26517211.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] Feature request for as.Date() function
Hello - I have a csv file with a few date columns. Some of the records have an NA character string instead of the date. When I attempt to use read.csv() and typecast the columns using colClasses, I receive the following error: Error in charToDate(x) : character string is not in a standard unambiguous format Similarly, the following command produces the same error: as.Date(NA) However, as.Date(NA) performs as documented. Can we enhance the as.Date() function to convert NA strings into NA value prior to type conversion? 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] Grouped Barplot
On 11/25/2009 07:48 PM, Gary wrote: Hi R Users, I tried plotting a similar boxplot as it is on the FOLLOWING LINK: http://www.imachordata.com/wp-content/uploads/2009/09/boxplot.png Sample data is attached -- there are 9 years and 5 cities. In my case I'm looking to plot Year on x-axis and grouping boxplots by City. I tried the following code. foo-read.table(SampleData.csv, sep=,, header=TRUE) attach(foo) boxplot(Admit ~ City + Year, range=0.5, col=2:6) # its not solving the purpose I need some help with: 1) Plotting only 9 labels on x-axis (1996-2004). 2) For each Year, I need to plot FIVE boxplots -- one for each City. [so it will look like nine clusters with five boxplots each (with no gap between them, but with gaps between year labels]. 3) Adding MEAN to the boxplots. 4) And, legend including color + city name. Any help would be greatly appreciated! ~Gary __ 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. Have a look at https://stat.ethz.ch/pipermail/r-help/2000-November/009191.html. Might be what you're looking for. [[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 writing for loop
Hi, The great thing about the S language is that it is 'vectorized', so you can do a lot of matrix manipulations without loops. Here's a smaller example of what you describe. matrix A with 3 columns and 10 rows (instead of 100) matrix B with 3 columns and 15 rows (instead of 1500) set.seed(123) mA - matrix(runif(30), ncol = 3) mA [,1] [,2] [,3] [1,] 0.2875775 0.95683335 0.8895393 [2,] 0.7883051 0.45333416 0.6928034 [3,] 0.4089769 0.67757064 0.6405068 [4,] 0.8830174 0.57263340 0.9942698 [5,] 0.9404673 0.10292468 0.6557058 [6,] 0.0455565 0.89982497 0.7085305 [7,] 0.5281055 0.24608773 0.5440660 [8,] 0.8924190 0.04205953 0.5941420 [9,] 0.5514350 0.32792072 0.2891597 [10,] 0.4566147 0.95450365 0.1471136 x - seq(15) mB - cbind(1, x, x^2) mB x [1,] 1 1 1 [2,] 1 2 4 [3,] 1 3 9 [4,] 1 4 16 [5,] 1 5 25 [6,] 1 6 36 [7,] 1 7 49 [8,] 1 8 64 [9,] 1 9 81 [10,] 1 10 100 [11,] 1 11 121 [12,] 1 12 144 [13,] 1 13 169 [14,] 1 14 196 [15,] 1 15 225 mR - apply(mB, 1, function(x){mA %*% x}) mR [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 2.133950 5.759401 11.163931 18.347540 27.310227 38.05199 50.57284 [2,] 1.934443 4.466187 8.383538 13.686496 20.375061 28.44923 37.90901 [3,] 1.727054 4.326145 8.206250 13.367368 19.809500 27.53265 36.53681 [4,] 2.449921 6.005363 11.549346 19.081867 28.602929 40.11253 53.61067 [5,] 1.699098 3.769140 7.150594 11.843459 17.847736 25.16342 33.79052 [6,] 1.653912 4.679328 9.121806 14.981344 22.257943 30.95160 41.06232 [7,] 1.318259 3.196545 6.162963 10.217513 15.360195 21.59101 28.90995 [8,] 1.528621 3.353106 6.365876 10.566930 15.956267 22.53389 30.29979 [9,] 1.168515 2.363915 4.137635 6.489674 9.420032 12.92871 17.01571 [10,] 1.558232 2.954077 4.644149 6.628448 8.906974 11.47973 14.34671 [,8] [,9] [,10] [,11] [,12] [,13] [,14] [1,] 64.87276 80.95176 98.80984 118.44700 139.86324 163.05856 188.03295 [2,] 48.75440 60.98539 74.60199 89.60419 105.99201 123.76542 142.92445 [3,] 46.82198 58.38816 71.23536 85.36358 100.77281 117.46305 135.43430 [4,] 69.09735 86.57257 106.03633 127.48863 150.92947 176.35884 203.77676 [5,] 43.72904 54.97896 67.54029 81.41304 96.59720 113.09277 130.89975 [6,] 52.59011 65.53495 79.89685 95.67582 112.87184 131.48493 151.51508 [7,] 37.31703 46.81224 57.39559 69.06706 81.82667 95.67440 110.61027 [8,] 39.25398 49.39646 60.72722 73.24626 86.95358 101.84919 117.93309 [9,] 21.68102 26.92466 32.74662 39.14689 46.12549 53.68240 61.81763 [10,] 17.50792 20.96335 24.71302 28.75691 33.09502 37.72737 42.65394 [,15] [1,] 214.78642 [2,] 163.46908 [3,] 154.68657 [4,] 233.18322 [5,] 150.01814 [6,] 172.96229 [7,] 126.63428 [8,] 135.20527 [9,] 70.53119 [10,] 47.87474 so the results matrix mR has one column for each element of x, and the i-th row element is the solution for y = a + bx + cx^2 for the i-th row of coefficients in the parameter estimates matrix mA You can spot check with e.g. mA[1,] %*% mB[15,] [,1] [1,] 214.7864 mA[1,] %*% mB[5,] [,1] [1,] 27.31023 mA[1,] [1] 0.2875775 0.9568333 0.8895393 mB[5,] x 1 5 25 HTH Steven McKinney, Ph.D. Statistician Molecular Oncology and Breast Cancer Program British Columbia Cancer Research Centre email: smckinney +at+ bccrc +dot+ ca tel: 604-675-8000 x7561 BCCRC Molecular Oncology 675 West 10th Ave, Floor 4 Vancouver B.C. V5Z 1L3 Canada From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of Jessica Schedlbauer [jsche...@fiu.edu] Sent: November 25, 2009 10:43 AM To: r-help@r-project.org Subject: [R] help writing for loop Hi, I’d like to ask for some help in writing a loop. My situation is the following: I have a matrix (matrix.A) containing 3 columns and 100 rows. The columns represent parameter estimates a, b, and c. The rows contain different values for these parameter estimates. Each row is unique. I want to insert these parameter estimates into a model (say, y = a + bx + cx^2) and solve for y given a separate matrix (matrix.B) of x values (where x has a length of 1500). I want to solve for y 100 times using each set of the parameter estimates in matrix.A once. At present my code looks like this and it only performs the first iteration. For (i in 1:length(matrix.A)) { y - matrix.A$a[[i]] + matrixA$b[[i]] * matrix.B$x + matrixA$c[[i]] * matrix.B$x^2) I have not been able to figure out how to loop through the rows of parameter estimates in matrix.A. I am new to writing loops, so any assistance would be much appreciated. Regards, Jessica Schedlbauer __ 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,
Re: [R] Reading from Google Docs
On Wed, Nov 25, 2009 at 5:39 AM, Farrel Buchinsky fjb...@gmail.com wrote: I recently installed R 2.10 Now I get library(RGoogleDocs) Loading required package: RCurl Loading required package: bitops Loading required package: XML Attaching package: 'RGoogleDocs' The following object(s) are masked from package:methods : getAccess Warning message: package 'RGoogleDocs' was built under R version 2.9.1 and help will not work correctly Please re-install it But alas reinstalling it does not take away the error message. Farrel Buchinsky How did you try reinstalling it? It sounds like you are using a binary distribution that was built under 2.9.1-- you probably have to build and install from a source distribution of the package. -Charlie __ 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] Grouped Barplot
On Nov 25, 2009, at 1:48 PM, Gary wrote: Hi R Users, I tried plotting a similar boxplot as it is on the FOLLOWING LINK: http://www.imachordata.com/wp-content/uploads/2009/09/boxplot.png Looks like a product of a function from ggplot2. In fact trimming that URL brings you to a page with the code that created it! Sample data is attached -- No, it's not. Read the Posting Guide for what file types are acceptable to the server. I suspect you will get better success if the extension is .txt, even if it is comma separated. Or better yet follow the directions there for posting data in a form that can be enclosed in your posting and copy-pasted into the console session. there are 9 years and 5 cities. In my case I'm looking to plot Year on x-axis and grouping boxplots by City. I tried the following code. foo-read.table(SampleData.csv, sep=,, header=TRUE) attach(foo) boxplot(Admit ~ City + Year, range=0.5, col=2:6) # its not solving the purpose I need some help with: 1) Plotting only 9 labels on x-axis (1996-2004). 2) For each Year, I need to plot FIVE boxplots -- one for each City. [so it will look like nine clusters with five boxplots each (with no gap between them, but with gaps between year labels]. 3) Adding MEAN to the boxplots. 4) And, legend including color + city name. Any help would be greatly 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] predict: remove columns with new levels automatically
Thank you all for the good advice. Now i did a fast hack, which does want i was looking for, maybe anyone else finds this usefull set.seed(0) x - rnorm(9) y - x + rnorm(9) training - data.frame(x=x, y=y, z1=c(rep(A, 3), rep(B, 3), rep(C, 3)), z2=c(rep(F, 4), rep(G, 5))) test - data.frame(x=t-rnorm(1), y=t+rnorm(1), z1=D, z2=F) `predict.drop` - function(f, dat, newdat) { datlev - vector(list, ncol(dat)) newdatlev - vector(list, ncol(newdat)) `filllevs` - function(dat, veclev) { for (j in 1:ncol(dat)) { if (is.factor(dat[,j])) veclev[[j]] - levels(dat[,j]) else veclev[[j]] - NULL } return(veclev) } datlev - filllevs(dat, datlev) newdatlev - filllevs(newdat, newdatlev) if (ncol(dat) == ncol(newdat)) { drop - logical(ncol(dat)) names(drop) - colnames(dat) for (j in 1:ncol(dat)) { if (!is.null(datlev[[j]])) { if (!(newdatlev[[j]] %in% datlev[[j]])) drop[j] - TRUE } } } else stop(dat and newdat must have the same column length!) m - lm(formula(f), data=dat[,(1:ncol(dat))[!drop]]) p - predict(m, newdat) return(list(drop=drop, p=p)) } predict.drop(x ~ ., training, test) best regards Andreas David Winsemius wrote: On Nov 25, 2009, at 1:48 AM, Andreas Wittmann wrote: Sorry for my bad description, i don't want get a constructed algorithm without own work. i only hoped to get some advice how to do this. i don't want to predict any sort of data, i reference only to newdata which variables are the same as in the model data. But if factors in the data than i can by possibly that the newdata has a level which doesn't exist in the original data. So i have to compare each factor in the data and in the newdata and if the newdata has a levels which is not in the original data and drop this variable and do compute the model and prediction again. I thought this problem is quite common and i can use an algorithm somebody has already implemented. best regards Andreas If you use str to look at the lm1 object you will find at the bottom a list called x: lm1$x will show you the factors that were present in variables at the time of the model creation lm1$x $z [1] A B C New testing scenario good level and bad level: test - data.frame(x=t-rnorm(2), y=t+rnorm(2), z=c(B, D) ) lm1 - lm(x ~ ., data=training) predict(lm1, subset(test, z %in% lm1$x$z) ) # get prediction for good level only 1 0.4225204 Original-Nachricht Datum: Wed, 25 Nov 2009 00:48:59 -0500 Von: David Winsemius dwinsem...@comcast.net An: Andreas Wittmann andreas_wittm...@gmx.de CC: r-help@r-project.org Betreff: Re: [R] predict: remove columns with new levels automatically On Nov 24, 2009, at 2:24 PM, Andreas Wittmann wrote: Dear R-users, in the follwing thread http://tolstoy.newcastle.edu.au/R/help/03b/3322.html the problem how to remove rows for predict that contain levels which are not in the model. now i try to do this the other way round and want to remove columns (variables) in the model which will be later problematic with new levels for prediction. ## example: set.seed(0) x - rnorm(9) y - x + rnorm(9) training - data.frame(x=x, y=y, z=c(rep(A, 3), rep(B, 3), rep(C, 3))) test - data.frame(x=t-rnorm(1), y=t+rnorm(1), z=D) lm1 - lm(x ~ ., data=training) ## prediction does not work because the variable z has the new level D predict(lm1, test) ## solution: the variable z is removed from the model ## the prediction happens without using the information of variable z lm2 - lm(x ~ y, data=training) predict(lm2, test) How can i autmatically recognice this and calculate according to this? Let me get this straight. You want us to predict in advance (or more accurately design an algorithm that can see into the future and work around) any sort of newdata you might later construct -- David Winsemius, MD Heritage Laboratories West Hartford, CT -- Preisknaller: GMX DSL Flatrate für nur 16,99 Euro/mtl.! http://portal.gmx.net/de/go/dsl02 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] Feature request for as.Date() function
Seems to work fine in my testing: x - read.csv(textConnection(date,value + 2009-01-01,10 + 2009-02-01,1 + 'NA', 3), colClasses=c(Date, 'integer')) str(x) 'data.frame': 3 obs. of 2 variables: $ date :Class 'Date' num [1:3] 14245 14276 NA $ value: int 10 1 3 x - read.csv(textConnection(date,value + 2009-01-01,10 + 2009-02-01,1 + NA, 3), colClasses=c(Date, 'integer')) str(x) 'data.frame': 3 obs. of 2 variables: $ date :Class 'Date' num [1:3] 14245 14276 NA $ value: int 10 1 3 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. On Wed, Nov 25, 2009 at 12:38 PM, nabble.30.miller_2...@spamgourmet.com wrote: Hello - I have a csv file with a few date columns. Some of the records have an NA character string instead of the date. When I attempt to use read.csv() and typecast the columns using colClasses, I receive the following error: Error in charToDate(x) : character string is not in a standard unambiguous format Similarly, the following command produces the same error: as.Date(NA) However, as.Date(NA) performs as documented. Can we enhance the as.Date() function to convert NA strings into NA value prior to type conversion? 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. -- 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.