[R] scale change
Hi all, I am sure this is simple, but being a beginner in R,I am finding it difficult to manage myself. I am running the following code to get a multiple line plot for two time series variables, x and y: plot(as.ts(cbind(x,y)), plot.type = single, col = 1:2) I want to change the scales of both axes: I need to 'stretch' the x-axis and 'shrink' the y-axis (1/2cm on the previous x-axis would now need to be stretched to 1 cm on the new one and exactly the opposite for the y-axis). I am not being able to do this. Any help is welcome. -- Preetam Pal (+91)-9432212774 M-Stat 2nd Year, Room No. N-114 Statistics Division, C.V.Raman Hall Indian Statistical Institute, B.H.O.S. Kolkata. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to create surface3d plot with surface data
WIth x, y are vectors, the grid is plotted by surface3d. Thanks for your answer. My code is here; #SurfacePlot is plotted by above surface data Surface - read.csv(D:/R/Surface.csv, header=F) Surface - as.matrix(Surface) x - Surface[2:17,1] x - as.numeric(x) # x is vector 1x16 y - Surface[1,2:11] y - t(y) y - as.numeric(y) #y is vector 1x10 z - Surface[2:17,2:11] # z is matrix 16x10 plot3d(ScatterPlot$x1, ScatterPlot$y1, ScatterPlot$z1, xlab=x,ylab=y,zlab=z, type=s, col = blue, size=0.25, lit=FALSE) # ScatterPlot is showed as below data. surface3d(x,y,z,alpha=0.4,front=lines,back=lines) I combined surface3d and plot3d() in graph. And now, I want to add line segments showing the error between points of scatter plot and grid of surface3d. ScatterPlot Data: X1 Y1 Z1 1 25000.030 0.001218202 0.1915856 2 5118.15450 0.061169029 0.4711610 3 17005.82875 0.007177435 0.3222662 4 5300.22698 0.029688212 0.2770485 ... (3000 points) I think I should build linear model to predict z1_new values from x1 y1 based on Surface data, And use spheres3d() to plot points of Scatterplot on surface grid, and then use segment3d() to add line segments between points of scatter plot and grid of surface3d coordinate. But. i don't know to do that. What should I do? my method is true ? Nguyen.Hoang -- View this message in context: http://r.789695.n4.nabble.com/How-to-create-surface3d-plot-with-surface-data-tp4667483p4667555.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] choosing the correct number of clusters using NbClust
I have the same problem you mention here. As there is no answer, did you find the way to obtain the optimal number of groups? Thank you! [[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] Using loop for applying function on matrix
Hello R Experts, I need a bit of help in using loop. I have a matrix onto which I need to use several functions. In a simplified form suppose my matrix is mdat [,1] [,2] [,3] [,4] [,5] [1,]12345 [2,] 11 12 13 10 10 [3,]23456 [4,] 10989 10 [5,]56784 And I have one vector x [1] 14 15 10 11 18 Now suppose in simple form I want to create a matrix in which each col value will be divided with consecutive no from vector x. For example column 1 of new vector will be C1=mdat[,1]*100/x[1] C1 [1] 7.142857 78.571429 14.285714 71.428571 35.714286 Now how can I use the loop to have the complete vector at a time? I tried something like this, but in vain. for(i in 1:5) { Data=(mdat[,i]*100/x[i], add=T) } Any help will be really great. Thanks, Mitra [[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] Using loop for applying function on matrix
Hi, ?sweep mdat - matrix(c(1,11,2,10,5,2,12,3,9,6,3,13,4,8,7,4,10,5,9,8,5,10,6,10,4),5,5) x - c(14,15,10,11,18) sweep(mdat*100, 2, x, FUN='/') [,1] [,2] [,3] [,4] [,5] [1,] 7.142857 13.3 30 36.36364 27.8 [2,] 78.571429 80.0 130 90.90909 55.6 [3,] 14.285714 20.0 40 45.45455 33.3 [4,] 71.428571 60.0 80 81.81818 55.6 [5,] 35.714286 40.0 70 72.72727 22.2 Hope this helps, Pascal On 05/21/2013 04:16 PM, Suparna Mitra wrote: Hello R Experts, I need a bit of help in using loop. I have a matrix onto which I need to use several functions. In a simplified form suppose my matrix is mdat [,1] [,2] [,3] [,4] [,5] [1,]12345 [2,] 11 12 13 10 10 [3,]23456 [4,] 10989 10 [5,]56784 And I have one vector x [1] 14 15 10 11 18 Now suppose in simple form I want to create a matrix in which each col value will be divided with consecutive no from vector x. For example column 1 of new vector will be C1=mdat[,1]*100/x[1] C1 [1] 7.142857 78.571429 14.285714 71.428571 35.714286 Now how can I use the loop to have the complete vector at a time? I tried something like this, but in vain. for(i in 1:5) { Data=(mdat[,i]*100/x[i], add=T) } Any help will be really great. Thanks, Mitra [[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] Using loop for applying function on matrix
On 21-05-2013, at 09:16, Suparna Mitra suparna.mitra...@gmail.com wrote: Hello R Experts, I need a bit of help in using loop. I have a matrix onto which I need to use several functions. In a simplified form suppose my matrix is mdat [,1] [,2] [,3] [,4] [,5] [1,]12345 [2,] 11 12 13 10 10 [3,]23456 [4,] 10989 10 [5,]56784 And I have one vector x [1] 14 15 10 11 18 Now suppose in simple form I want to create a matrix in which each col value will be divided with consecutive no from vector x. For example column 1 of new vector will be C1=mdat[,1]*100/x[1] C1 [1] 7.142857 78.571429 14.285714 71.428571 35.714286 Now how can I use the loop to have the complete vector at a time? I tried something like this, but in vain. for(i in 1:5) { Data=(mdat[,i]*100/x[i], add=T) } See this discussion: http://r.789695.n4.nabble.com/Divide-matrix-columns-by-different-numbers-td4666013.html Other possibilities taken from that thread mdat*100/rep(x,each=nrow(mdat)) 100*t(t(mdat)/x) Berend __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Repeated k-fold Cross-Validation with Stepwise Regression
Hi All, I am looking for a package that performs Repeated k-fold cross-validation with Stepwise Regression. I would greatly appreciate if someone could share with us a package(s) that include this type of analysis. Thank you very much in advance. Chris [[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] Using loop for applying function on matrix
Hello, If you *really* need a loop: Data - array(NA, dim(mdat)) for(i in 1:ncol(mdat)){ Data[,i] - mdat[,i]*100/x[i] } But I would consider first the thread cited by Berend. Regards, Pascal On 05/21/2013 06:19 PM, Suparna Mitra wrote: Thanks for your reply Pascal. I am presently using it with sweep. But here in the question I just gave one simple example. In reality I need several functions to run. Thus I was wondering, if without sweep, I can use loop. Also want to learn how to do this using loop. Any help will be really great, Thanks, Mitra Dr. Suparna Mitra Department of Molecular and Clinical Pharmacology Institute of Translational Medicine University of Liverpool Block A: Waterhouse Buildings 1-5 Brownlow Street Liverpool L69 3GL Tel. +44 (0)151 795 5414 M: +44 (0) 7523228621 Internal ext: 55401 On 21 May 2013 16:29, Pascal Oettli kri...@ymail.com mailto:kri...@ymail.com wrote: Hi, ?sweep mdat - matrix(c(1,11,2,10,5,2,12,3,9,__6,3,13,4,8,7,4,10,5,9,8,5,10,__6,10,4),5,5) x - c(14,15,10,11,18) sweep(mdat*100, 2, x, FUN='/') [,1] [,2] [,3] [,4] [,5] [1,] 7.142857 13.3 30 36.36364 27.8 [2,] 78.571429 80.0 130 90.90909 55.6 [3,] 14.285714 20.0 40 45.45455 33.3 [4,] 71.428571 60.0 80 81.81818 55.6 [5,] 35.714286 40.0 70 72.72727 22.2 Hope this helps, Pascal On 05/21/2013 04:16 PM, Suparna Mitra wrote: Hello R Experts, I need a bit of help in using loop. I have a matrix onto which I need to use several functions. In a simplified form suppose my matrix is mdat [,1] [,2] [,3] [,4] [,5] [1,]12345 [2,] 11 12 13 10 10 [3,]23456 [4,] 10989 10 [5,]56784 And I have one vector x [1] 14 15 10 11 18 Now suppose in simple form I want to create a matrix in which each col value will be divided with consecutive no from vector x. For example column 1 of new vector will be C1=mdat[,1]*100/x[1] C1 [1] 7.142857 78.571429 14.285714 71.428571 35.714286 Now how can I use the loop to have the complete vector at a time? I tried something like this, but in vain. for(i in 1:5) { Data=(mdat[,i]*100/x[i], add=T) } Any help will be really great. Thanks, Mitra [[alternative HTML version deleted]] R-help@r-project.org mailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/__listinfo/r-help https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/__posting-guide.html 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] Increasing time of simulation
Hi maybe someone could help Program: NS=10 ONS=100 . some declarations ## f. START . functions definitions ## f. STOP for (osym in 1:ONS) { wnk_sym=array(0,c(49,10,NS)) for (sym in 1:NS) { . counting wnk (matrix 49x10) based on the random numbers wnk_sym[,,sym]=wnk } save(wnk_sym,file=paste(where,file,osym,'.RData',sep='')) rm(wnk_sym) } The problem is first simulations takes ca 20s each, but time is constantly increasing, up to 150s. Any idea why? RAM is not a problem (8GB) on win7 x64 Tomasz Jurkiewicz [[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] Using loop for applying function on matrix
Thanks for your reply Pascal. I am presently using it with sweep. But here in the question I just gave one simple example. In reality I need several functions to run. Thus I was wondering, if without sweep, I can use loop. Also want to learn how to do this using loop. Any help will be really great, Thanks, Mitra Dr. Suparna Mitra Department of Molecular and Clinical Pharmacology Institute of Translational Medicine University of Liverpool Block A: Waterhouse Buildings 1-5 Brownlow Street Liverpool L69 3GL Tel. +44 (0)151 795 5414 M: +44 (0) 7523228621 Internal ext: 55401 On 21 May 2013 16:29, Pascal Oettli kri...@ymail.com wrote: Hi, ?sweep mdat - matrix(c(1,11,2,10,5,2,12,3,9,**6,3,13,4,8,7,4,10,5,9,8,5,10,** 6,10,4),5,5) x - c(14,15,10,11,18) sweep(mdat*100, 2, x, FUN='/') [,1] [,2] [,3] [,4] [,5] [1,] 7.142857 13.3 30 36.36364 27.8 [2,] 78.571429 80.0 130 90.90909 55.6 [3,] 14.285714 20.0 40 45.45455 33.3 [4,] 71.428571 60.0 80 81.81818 55.6 [5,] 35.714286 40.0 70 72.72727 22.2 Hope this helps, Pascal On 05/21/2013 04:16 PM, Suparna Mitra wrote: Hello R Experts, I need a bit of help in using loop. I have a matrix onto which I need to use several functions. In a simplified form suppose my matrix is mdat [,1] [,2] [,3] [,4] [,5] [1,]12345 [2,] 11 12 13 10 10 [3,]23456 [4,] 10989 10 [5,]56784 And I have one vector x [1] 14 15 10 11 18 Now suppose in simple form I want to create a matrix in which each col value will be divided with consecutive no from vector x. For example column 1 of new vector will be C1=mdat[,1]*100/x[1] C1 [1] 7.142857 78.571429 14.285714 71.428571 35.714286 Now how can I use the loop to have the complete vector at a time? I tried something like this, but in vain. for(i in 1:5) { Data=(mdat[,i]*100/x[i], add=T) } Any help will be really great. Thanks, Mitra [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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] Sum first 3 non zero elements of row
Hi there, I've got this matrix D with, say 10 rows and 20 columns. For each row I want to sum the first 3 non zero elements and put them in a vector z. So if the first row D[1,] is 0 3 5 0 8 9 3 2 4 0 then I want z z-D[1,2]+D[1,3]+D[1,5] But if there are less than 3 non zero elements, those should be summed. If there are no non zero elements, the result must be zero. So if the first row D[1,] is 0 0 3 0 1 0 0 0 0 0 then I want z z-D[1,3]+D[1,5] Hope someone can help me out! [[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] Gamma curve fit to data with specific bins
Hi Riu, Very helpful. Thanks a million! Andrew -Original Message- From: Rui Barradas [mailto:ruipbarra...@sapo.pt] Sent: 20 May 2013 23:49 To: Lorentz, Andrew Cc: r-help@r-project.org Subject: Re: [R] Gamma curve fit to data with specific bins Hello, You are fitting a vector other than the vector 'x'. And you are mistaking the parameter scale for rate. est - fitdistr(x,gamma)$estimate #plot the gamma curve with the found parameters hist(x, breaks=Size, freq=FALSE, xlab=Drop Size, ylab=No. of Drops) curve(dgamma(x, rate=est[rate], shape=est[shape]),from=0, to=16, main=Gamma distribution, ylab=Probability, add = TRUE, col = red) Hope this helps, Rui Barradas Em 20-05-2013 16:44, Lorentz, Andrew escreveu: Good afternoon, I have some rainfall drop size data (frequency count within drop size) that is already arranged into specific bins (Size). I am looking to fit a gamma curve onto a histogram of the data. At the moment I have been able to create estimate the gamma parameters from the PDF of the frequencies. And plot the points on the gamma curve. However, the x-axis is only a count and not the specific drop size values. Nor have I been able to plot the histogram and the curve together. Could you advise? Many thanks. Code: # Load the probability data from the Drop Size Distribution PDF=c(0.0941,0.2372,0.2923,0.1750,0.0863,0.0419,0.0207,0.0128,0.0142,0.0071,0.0041,0.0031,0.0032,0.0057,0.0022,0.0001) Freq = c(0,0,197284,497395,613062,366975,181037,87926,43432,26889,29728,14877,8691,6457,6778,1926,4543,123,37,0) Size = c(0.0625,0.1875,0.3125,0.4375,0.5625,0.6875,0.8125,0.937,1.063,1.188,1.375,1.625,1.875,2.125,2.375,2.75,3.25,3.75,4.25,4.75) x-rep(Size, Freq) # histogram of probability hist(x, breaks=Size, freq=TRUE, xlab=Drop Size, ylab=No. of Drops) dev.new() # Find the parameters of the gamma curve from the PDF library(MASS) fitdistr(PDF,gamma) # scale=0.4495207, shape=7.1923309 #plot the gamma curve with the found parameters curve(dgamma(x, scale=.4495207, shape=7.1923309),from=0, to=16, main=Gamma distribution, ylab=Probability) # add the points of the PDF from the data points(PDF) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Sum first 3 non zero elements of row
Does this work? Probably not the fastest, but I think it does the job. foo-function(x){ temp=x[x0] if(length(temp)=3) sum(temp[1:3]) else sum(temp) set.seed(2) mat-matrix(sample(0:4, 25, replace=T, prob=c(1/2,rep(1/8,4)), ncol=5) mat # [,1] [,2] [,3] [,4] [,5] #[1,]01243 #[2,]30010 #[3,]24404 #[4,]00000 #[5,]12000 apply(mat, 1, foo)#Apply the function to each row of the matrix #[1] 7 4 10 0 3 On Tue, May 21, 2013 at 2:16 AM, José Verhoeven j...@memo2.nl wrote: Hi there, I've got this matrix D with, say 10 rows and 20 columns. For each row I want to sum the first 3 non zero elements and put them in a vector z. So if the first row D[1,] is 0 3 5 0 8 9 3 2 4 0 then I want z z-D[1,2]+D[1,3]+D[1,5] But if there are less than 3 non zero elements, those should be summed. If there are no non zero elements, the result must be zero. So if the first row D[1,] is 0 0 3 0 1 0 0 0 0 0 then I want z z-D[1,3]+D[1,5] Hope someone can help me out! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sum first 3 non zero elements of row
Oops, a couple of missing brackets in the previous reply: foo-function(x){ temp=x[x0] if(length(temp)=3) sum(temp[1:3]) else sum(temp) } #This was missing in the previous post set.seed(2) mat-matrix(sample(0:4, 25, replace=T, prob=c(1/2,rep(1/8,4))), ncol=5) #add a right parenthesis. mat On Tue, May 21, 2013 at 3:47 AM, Xiao He praguewaterme...@gmail.com wrote: Does this work? Probably not the fastest, but I think it does the job. foo-function(x){ temp=x[x0] if(length(temp)=3) sum(temp[1:3]) else sum(temp) set.seed(2) mat-matrix(sample(0:4, 25, replace=T, prob=c(1/2,rep(1/8,4)), ncol=5) mat # [,1] [,2] [,3] [,4] [,5] #[1,]01243 #[2,]30010 #[3,]24404 #[4,]00000 #[5,]12000 apply(mat, 1, foo)#Apply the function to each row of the matrix #[1] 7 4 10 0 3 On Tue, May 21, 2013 at 2:16 AM, José Verhoeven j...@memo2.nl wrote: Hi there, I've got this matrix D with, say 10 rows and 20 columns. For each row I want to sum the first 3 non zero elements and put them in a vector z. So if the first row D[1,] is 0 3 5 0 8 9 3 2 4 0 then I want z z-D[1,2]+D[1,3]+D[1,5] But if there are less than 3 non zero elements, those should be summed. If there are no non zero elements, the result must be zero. So if the first row D[1,] is 0 0 3 0 1 0 0 0 0 0 then I want z z-D[1,3]+D[1,5] Hope someone can help me out! [[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] Lattice, ggplot, and pointsize
Hi! When inserting R plots into a document using odfWeave, I fought for a while to get Lattice plots use the same text size as base plots. I eventually discovered that specifying a point size via e.g. svg(pointsize=10) has no effect on Lattice plots. One needs to adjust the size manually via: trellis.par.set(fontsize=list(text=10, points=8)) This is also developed for both Lattice and ggplot2 by this blog post: http://gforge.se/2013/03/exporting-plain-lattice-or-ggplot/ So I am wondering whether is a by-design limitation or whether this could be improved. I find it very useful to be able to adapt text size to the output device instead of changing plotting parameters for each plotting system (especially when you change the resolution of PNG output, or move from one output device to another). Thanks in advance __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] problem in reading GDX file
Dear R-Users, While reading a GDX file from GAMS-software, the R-program does not read the string (text) observations. Instead, it assigns some numerical values to each text. Do you have some idea on how to read string observations? Example in GDX file: fid out year value 1_2_3 RICE 1995 130.54 1_2_3 WHEAT 1996 115-40 1_2_4 RICE 1995 120.20 1_2_4 WHEAT 1996 115.40 But, the R-software reads the above data as: fid out year value 2721 10281 2155 130.54 2721 10284 2156 115-40 2726 10281 2155 120.20 2726 10284 2156 115.40 I want read the GDX file in as it is condition. Thanks, Shyam Basnet Nepal [[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] numeric not equal its value
Dear R users, I ran into the strange situation where a number does not seem to equal its value. Try this: a - seq(0.05,0.7,0.05)[3] b - 0.15 a == b Should this not be TRUE? a-b yields a very small number (and not 0) so this most probably is a numerical error, but why does seq create such numbers? Thanks a lot Jannis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] microarray analysis: contrast matrix problem
Hi! I'm sorry for bothering you. I'm a new R-user and I'm having some problems while doing a microarray analysis. I'm comparing the whole genome array of a Salmonella serovar to another 25, and my goal is to determine which genes are differentially expressed. I'm using limma package and running the next code, DIFFERENTIAL EXPRESSION i #several groups comparisson (by serovars) groups - read.table(ClusteringSamples.txt, head=T, sep='\t') f - factor(groups$Serovar) design - model.matrix(~0 + f) colnames(design) - c(Abortusovis, Agona, Anatum, Arizonae, Braenderup, Bredeney, Cholerasuis, Derby, Enteritidis, Gallinarum, Goelzau, Hadar, Havana, Infantis, Kedougou, Mbandaka, Mikawasima, Ohio, ParatiphyA, ParatiphyB, Pos.Control, Pullorum, Typhi, Typhimurium, Virchow) #Convertir a vectores! summary(is.na(data)) #check if there is any missing value in the dataset. fit - lmFit(data, design) contrast.matrix - makeContrasts(Abortusovis-Pos.Control, Agona-Pos.Control, Anatum-Pos.Control, Arizonae-Pos.Control, Braenderup-Pos.Control, Bredeney-Pos.Control, Cholerasuis-Pos.Control, Derby-Pos.Control, Enteritidis-Pos.Control, Gallinarum-Pos.Control, Goelzau-Pos.Control, Hadar-Pos.Control, Havana-Pos.Control, Infantis-Pos.Control, Kedougou-Pos.Control, Mbandaka-Pos.Control, Mikawasima-Pos.Control, Ohio-Pos.Control, ParatiphyA-Pos.Control, ParatiphyB-Pos.Control, Pos.Control-Pos.Control, Pullorum-Pos.Control, Typhi-Pos.Control, Typhimurium-Pos.Control, Virchow-Pos.Control, levels=design) fit1 - contrasts.fit(fit, contrast.matrix) fit2 - eBayes(fit1) But when I try to run eBayes correction to then compute topTable and get those differentially expressed genes, I get and error back: Error in eigen(cor.matrix, symmetric = TRUE) : infinite or missing values in 'x' In addition: Warning messages: 1: In ebayes(fit = fit, proportion = proportion, stdev.coef.lim = stdev.coef.lim, : Estimation of var.prior failed - set to default value 2: In cov2cor(object$cov.coefficients) : diag(.) had 0 or NA entries; non-finite result is doubtful I try to eliminate those missing values, but then I only can compute the contrast matrix of 13 of my 25 different serovars. How can I solve the problem? I'll appreciate the all the help and advices. Oihane __ Oihane Irazoki Sanchez PhD Student, Molecular Microbiology Depart. de Genètica i Microbiologia (Facultat de Biociències) UAB, 08193 Bellaterra (Barcelona), Spain Phone: 34-660938553 E-mail: oihane.iraz...@uab.cat / o.iraz...@gmail.com [[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] keep the centre fixed in K-means clustering
Dear R users I have the matrix of the centres of some clusters, e.g. 20 clusters each with 100 dimentions, so this matrix contains 20 rows * 100 columns numeric values. I have collected new data (each with 100 numeric values) and would like to keep the above 20 centres fixed/'unmoved' whilst just see how my new data fit in this grouping system, e.g. if the data is close to cluster 1 than lable it 'cluster 1'. If the above matrix of centre is called 'Centre' (a 20*100 matrix) and my new data 'NewData' has 500 observations, by using kmeans() will update the centres: kmeans(NewData, Centre) I wondered if there is other R packages out there can keep the centres fixed and lable each observations of my new data? Or I have to write my own function? To illustrate my task using a simpler example: I have Centre- matrix(c(0,1,0,1), nrow=2) # the two created centres in a two dimentional case are Centre [,1] [,2] [1,]00 [2,]11 NewData-rbind(matrix(rnorm(100, sd = 0.3), ncol = 2), matrix(rnorm(100, mean = 1, sd = 0.3), ncol = 2)) NewData1-cbind(c1:100), NewData) colnames(NewData1)-c(ID,x,y) # my data head(NewData1) ID x y [1,] 1 -0.3974660 0.1541685 [2,] 2 0.5321347 0.2497867 [3,] 3 0.2550276 0.1691720 [4,] 4 -0.1162162 0.6754874 [5,] 5 0.1570996 0.1175119 [6,] 6 0.4816195 -0.6836226 ## I'd like to have outcome as below (whilst keep the tow centers fixed): IDx y Cluster [1,] 1 -0.3974660 0.1541685 1 [2,] 20.5321347 0.2497867 1 [3,] 30.2550276 0.1691720 1 [4,] 4 -0.1162162 0.6754874 1 ... [55,] 55 1.1570996 1.1175119 2 [56,] 56 1.4816195 1.6836226 2 p.s. I use Euclidian to obtain/calculate distance matrix. Many thanks in advance HJ [[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] Arules: getting rules with only one item in the left-hand side
Hello, I am using the package arules to generate association rules. I would like to restrict the rules so that in the left-hand side there's only one particular element, let's call it potatoe. If I do this: rules - apriori(dtm.mat, parameter = list(sup = 0.4, conf = 0.9,target=rules), appearance = list(lhs = c(potatoe))) I get potatoe on the lhs, but also all other kinds of things. How can I force that the rules contain only one element? The parameter maxlen don't do what I want, because, as far as I can see, I cannot specify the maxlen to apply to the elements on the left. Thanks! Laia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] numeric not equal its value
Hi. Check R FAQ, section 7.31 Why doesn't R think these numbers are equal? http://cran.r-project.org/doc/FAQ/R-FAQ.html all.equal(a,b) Andrija On Mon, May 20, 2013 at 2:36 PM, Jannis bt_jan...@yahoo.de wrote: Dear R users, I ran into the strange situation where a number does not seem to equal its value. Try this: a - seq(0.05,0.7,0.05)[3] b - 0.15 a == b Should this not be TRUE? a-b yields a very small number (and not 0) so this most probably is a numerical error, but why does seq create such numbers? Thanks a lot Jannis __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] numeric not equal its value
Hello, That's FAQ 7.31. Note that the increment, 0.05, is not a power of 2 so the third value of the sequence is not exactly equal to 0.15. Hope this helps, Rui Barradas Em 20-05-2013 13:36, Jannis escreveu: Dear R users, I ran into the strange situation where a number does not seem to equal its value. Try this: a - seq(0.05,0.7,0.05)[3] b - 0.15 a == b Should this not be TRUE? a-b yields a very small number (and not 0) so this most probably is a numerical error, but why does seq create such numbers? Thanks a lot Jannis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] ordered and unordered variables
On May 20, 2013, at 10:35 PM, meng wrote: Hi all: If the explainary variables are ordinal,the result of regression is different from unordered variables.But I can't understand the result of regression from ordered variable. The data is warpbreaks,which belongs to R. If I use the unordered variable(tension):Levels: L M H The result is easy to understand: Estimate Std. Error t value Pr(|t|) (Intercept)36.39 2.80 12.995 2e-16 *** tensionM -10.00 3.96 -2.525 0.014717 * tensionH -14.72 3.96 -3.718 0.000501 *** If I use the ordered variable(tension):Levels: L M H I don't know how to explain the result: Estimate Std. Error t value Pr(|t|) (Intercept) 28.148 1.617 17.410 2e-16 *** tension.L-10.410 2.800 -3.718 0.000501 *** tension.Q 2.155 2.800 0.769 0.445182 What's tension.L and tension.Q stands for?And how to explain the result then? Ordered factors are handled by the R regression mechanism with orthogonal polynomial contrasts: .L for linear and .Q for quadratic. If the term had 4 levels there would also have been a .C (cubic) term. Treatment contrasts are used for unordered factors. Generally one would want to do predictions for explanations of the results. Trying to explain the individual coefficient values from polynomial contrasts is similar to and just as unproductive as trying to explain the individual coefficients involving interaction terms. -- David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] as.vector with mode=list and POSIXct
You are absolutely right. I am storing POSIXct objects into a hash (from the hash package). However, if I try to get them out as a vector using the values() function, they are unclassed. And that breaks my (highly vectorized) code. Take a look at this: h = hash() h[[a]] = Sys.time() str(h[[a]]) POSIXct[1:1], format: 2013-05-20 16:54:28 str(values(h)) Named num 1.37e+09 - attr(*, names)= chr a I have reported this to the hash package maintainers. In the meantime, however, I am storing, for each key, a list containing a single POSIXct. Then, when I extract all using values(), I get a list containing all POSIXct entries with class preserved. h = hash() h[[a]] = list( Sys.time() ) h[[b]] = list( Sys.time() ) h[[c]] = list( Sys.time() ) values(h) $a [1] 2013-05-21 09:54:03 BRT $b [1] 2013-05-21 09:54:07 BRT $c [1] 2013-05-21 09:54:11 BRT str(values(h)) List of 3 $ a: POSIXct[1:1], format: 2013-05-21 09:54:03 $ b: POSIXct[1:1], format: 2013-05-21 09:54:07 $ c: POSIXct[1:1], format: 2013-05-21 09:54:11 However, the next thing I need to do is a min() over that list, so I need to convert the list into a vector again. I agree completely with you that this is horrible for performance, but it is a temporary workaround until values() is fixed. -- Alexandre Sieira CISA, CISSP, ISO 27001 Lead Auditor The truth is rarely pure and never simple. Oscar Wilde, The Importance of Being Earnest, 1895, Act I On 20 de maio de 2013 at 19:40:14, Jeff Newmiller (jdnew...@dcn.davis.ca.us) wrote: I don't know what you plan to do with this list, but lists are quite a bit less efficient than fixed-mode vectors, so you are likely losing a lot of computational speed by using this list. I don't hesitate to use simple data frames (lists of vectors), but processing lists is on par with for loops, not vectorized computation. It may still support a simpler model of computation, but that is an analyst comprehension benefit rather than a computational efficiency benefit. --- Jeff Newmiller The . . Go Live... DCN:jdnew...@dcn.davis.ca.us Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Alexandre Sieira alexandre.sie...@gmail.com wrote: I was trying to convert a vector of POSIXct into a list of POSIXct, However, I had a problem that I wanted to share with you. Works fine with, say, numeric: v = c(1, 2, 3) v [1] 1 2 3 str(v) num [1:3] 1 2 3 l = as.vector(v, mode=list) l [[1]] [1] 1 [[2]] [1] 2 [[3]] [1] 3 str(l) List of 3 $ : num 1 $ : num 2 $ : num 3 If you try it with POSIXct, on the other hand… v = c(Sys.time(), Sys.time()) v [1] 2013-05-20 18:02:07 BRT 2013-05-20 18:02:07 BRT str(v) POSIXct[1:2], format: 2013-05-20 18:02:07 2013-05-20 18:02:07 l = as.vector(v, mode=list) l [[1]] [1] 1369083728 [[2]] [1] 1369083728 str(l) List of 2 $ : num 1.37e+09 $ : num 1.37e+09 The POSIXct values are coerced to numeric, which is unexpected. The documentation for as.vector says: The default method handles 24 input types and 12 values of type: the details of most coercions are undocumented and subject to change. It would appear that treatment for POSIXct is either missing or needs adjustment. Unlist (for the reverse) is documented to converting to base types, so I can't complain. Just wanted to share that I ended up giving up on vectorization and writing the two following functions: unlistPOSIXct - function(x) { retval = rep(Sys.time(), length(x)) for (i in 1:length(x)) retval[i] = x[[i]] return(retval) } listPOSIXct - function(x) { retval = list() for (i in 1:length(x)) retval[[i]] = x[i] return(retval) } Is there a better way to do this (other than using *apply instead of for above) that better leverages vectorization? Am I missing something here? Thanks! -- Alexandre Sieira CISA, CISSP, ISO 27001 Lead Auditor The truth is rarely pure and never simple. Oscar Wilde, The Importance of Being Earnest, 1895, Act I __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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
Re: [R] Using loop for applying function on matrix
You could also use: sapply(seq_len(ncol(mdat)),function(i) mdat[,i]*100/x[i]) # [,1] [,2] [,3] [,4] [,5] #[1,] 7.142857 13.3 30 36.36364 27.8 #[2,] 78.571429 80.0 130 90.90909 55.6 #[3,] 14.285714 20.0 40 45.45455 33.3 #[4,] 71.428571 60.0 80 81.81818 55.6 #[5,] 35.714286 40.0 70 72.72727 22.2 A.K. - Original Message - From: Suparna Mitra suparna.mitra...@gmail.com To: Pascal Oettli kri...@ymail.com Cc: r-help@r-project.org Sent: Tuesday, May 21, 2013 5:19 AM Subject: Re: [R] Using loop for applying function on matrix Thanks for your reply Pascal. I am presently using it with sweep. But here in the question I just gave one simple example. In reality I need several functions to run. Thus I was wondering, if without sweep, I can use loop. Also want to learn how to do this using loop. Any help will be really great, Thanks, Mitra Dr. Suparna Mitra Department of Molecular and Clinical Pharmacology Institute of Translational Medicine University of Liverpool Block A: Waterhouse Buildings 1-5 Brownlow Street Liverpool L69 3GL Tel. +44 (0)151 795 5414 M: +44 (0) 7523228621 Internal ext: 55401 On 21 May 2013 16:29, Pascal Oettli kri...@ymail.com wrote: Hi, ?sweep mdat - matrix(c(1,11,2,10,5,2,12,3,9,**6,3,13,4,8,7,4,10,5,9,8,5,10,** 6,10,4),5,5) x - c(14,15,10,11,18) sweep(mdat*100, 2, x, FUN='/') [,1] [,2] [,3] [,4] [,5] [1,] 7.142857 13.3 30 36.36364 27.8 [2,] 78.571429 80.0 130 90.90909 55.6 [3,] 14.285714 20.0 40 45.45455 33.3 [4,] 71.428571 60.0 80 81.81818 55.6 [5,] 35.714286 40.0 70 72.72727 22.2 Hope this helps, Pascal On 05/21/2013 04:16 PM, Suparna Mitra wrote: Hello R Experts, I need a bit of help in using loop. I have a matrix onto which I need to use several functions. In a simplified form suppose my matrix is mdat [,1] [,2] [,3] [,4] [,5] [1,] 1 2 3 4 5 [2,] 11 12 13 10 10 [3,] 2 3 4 5 6 [4,] 10 9 8 9 10 [5,] 5 6 7 8 4 And I have one vector x [1] 14 15 10 11 18 Now suppose in simple form I want to create a matrix in which each col value will be divided with consecutive no from vector x. For example column 1 of new vector will be C1=mdat[,1]*100/x[1] C1 [1] 7.142857 78.571429 14.285714 71.428571 35.714286 Now how can I use the loop to have the complete vector at a time? I tried something like this, but in vain. for(i in 1:5) { Data=(mdat[,i]*100/x[i], add=T) } Any help will be really great. Thanks, Mitra [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 reading GDX file
On 21-05-2013, at 13:16, shyam basnet shyamabc2...@yahoo.com wrote: Dear R-Users, While reading a GDX file from GAMS-software, the R-program does not read the string (text) observations. Instead, it assigns some numerical values to each text. Do you have some idea on how to read string observations? Example in GDX file: fid out year value 1_2_3 RICE 1995 130.54 1_2_3 WHEAT 1996 115-40 Is the 115-40 correct? 1_2_4 RICE 1995 120.20 1_2_4 WHEAT 1996 115.40 But, the R-software reads the above data as: fidout year value 2721 10281 2155 130.54 2721 10284 2156 115-40 2726 10281 2155 120.20 2726 10284 2156 115.40 I want read the GDX file in as it is condition. You have not shown which function you have used to read in the file. If you have used read.table or one of the alternatives: ?read.table and look at argument stringsAsFactors: set it to FALSE. The strings have been treated as factors. Berend __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Lattice, ggplot, and pointsize
Hi See par.settings in xyplot Things are also controlled by trellis.par.get() to see values trellis.par.set() eg xyplot(~Freq|Year, data = sheep2, groups = farm, par.settings = list(strip.background = list(col = transparent), axis.text = list(cex = 0.75), par.xlab.text = list(cex = 0.80), par.ylab.text = list(cex = 0.80)) , ...) HTH Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 21:18 21/05/2013, you wrote: Hi! When inserting R plots into a document using odfWeave, I fought for a while to get Lattice plots use the same text size as base plots. I eventually discovered that specifying a point size via e.g. svg(pointsize=10) has no effect on Lattice plots. One needs to adjust the size manually via: trellis.par.set(fontsize=list(text=10, points=8)) This is also developed for both Lattice and ggplot2 by this blog post: http://gforge.se/2013/03/exporting-plain-lattice-or-ggplot/ So I am wondering whether is a by-design limitation or whether this could be improved. I find it very useful to be able to adapt text size to the output device instead of changing plotting parameters for each plotting system (especially when you change the resolution of PNG output, or move from one output device to another). Thanks in advance __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] microarray analysis: contrast matrix problem
Hi Oihane lmFit is from the limma package, and the limma package is part of the Bioconductor project; the Bioconductor mailing list http://bioconductor.org/help/mailing-list/ (follow the 'Post' link) may be a more appropriate place to post this question (after searching the archive) if there is no answer here. Martin On 05/21/2013 04:49 AM, Oihane Irazoki wrote: Hi! I'm sorry for bothering you. I'm a new R-user and I'm having some problems while doing a microarray analysis. I'm comparing the whole genome array of a Salmonella serovar to another 25, and my goal is to determine which genes are differentially expressed. I'm using limma package and running the next code, DIFFERENTIAL EXPRESSION i #several groups comparisson (by serovars) groups - read.table(ClusteringSamples.txt, head=T, sep='\t') f - factor(groups$Serovar) design - model.matrix(~0 + f) colnames(design) - c(Abortusovis, Agona, Anatum, Arizonae, Braenderup, Bredeney, Cholerasuis, Derby, Enteritidis, Gallinarum, Goelzau, Hadar, Havana, Infantis, Kedougou, Mbandaka, Mikawasima, Ohio, ParatiphyA, ParatiphyB, Pos.Control, Pullorum, Typhi, Typhimurium, Virchow) #Convertir a vectores! summary(is.na(data)) #check if there is any missing value in the dataset. fit - lmFit(data, design) contrast.matrix - makeContrasts(Abortusovis-Pos.Control, Agona-Pos.Control, Anatum-Pos.Control, Arizonae-Pos.Control, Braenderup-Pos.Control, Bredeney-Pos.Control, Cholerasuis-Pos.Control, Derby-Pos.Control, Enteritidis-Pos.Control, Gallinarum-Pos.Control, Goelzau-Pos.Control, Hadar-Pos.Control, Havana-Pos.Control, Infantis-Pos.Control, Kedougou-Pos.Control, Mbandaka-Pos.Control, Mikawasima-Pos.Control, Ohio-Pos.Control, ParatiphyA-Pos.Control, ParatiphyB-Pos.Control, Pos.Control-Pos.Control, Pullorum-Pos.Control, Typhi-Pos.Control, Typhimurium-Pos.Control, Virchow-Pos.Control, levels=design) fit1 - contrasts.fit(fit, contrast.matrix) fit2 - eBayes(fit1) But when I try to run eBayes correction to then compute topTable and get those differentially expressed genes, I get and error back: Error in eigen(cor.matrix, symmetric = TRUE) : infinite or missing values in 'x' In addition: Warning messages: 1: In ebayes(fit = fit, proportion = proportion, stdev.coef.lim = stdev.coef.lim, : Estimation of var.prior failed - set to default value 2: In cov2cor(object$cov.coefficients) : diag(.) had 0 or NA entries; non-finite result is doubtful I try to eliminate those missing values, but then I only can compute the contrast matrix of 13 of my 25 different serovars. How can I solve the problem? I'll appreciate the all the help and advices. Oihane __ Oihane Irazoki Sanchez PhD Student, Molecular Microbiology Depart. de Genètica i Microbiologia (Facultat de Biociències) UAB, 08193 Bellaterra (Barcelona), Spain Phone: 34-660938553 E-mail: oihane.iraz...@uab.cat / o.iraz...@gmail.com [[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. -- Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M1 B861 Phone: (206) 667-2793 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Sum first 3 non zero elements of row
Hi, You could try: set.seed(24) mat1- matrix(sample(0:5,10*20,replace=TRUE),ncol=20) mat2- mat1 mat2[2,1:19]-0 sapply(split(mat2,row(mat2)),function(x) sum(x[x!=0][1:3],na.rm=TRUE)) # 1 2 3 4 5 6 7 8 9 10 # 5 2 12 8 5 14 6 10 10 8 mat3- mat2 mat3[2,]- 0 sapply(split(mat3,row(mat3)),function(x) sum(x[x!=0][1:3],na.rm=TRUE)) # 1 2 3 4 5 6 7 8 9 10 # 5 0 12 8 5 14 6 10 10 8 A.K. - Original Message - From: José Verhoeven j...@memo2.nl To: r-help@r-project.org Cc: Sent: Tuesday, May 21, 2013 5:16 AM Subject: [R] Sum first 3 non zero elements of row Hi there, I've got this matrix D with, say 10 rows and 20 columns. For each row I want to sum the first 3 non zero elements and put them in a vector z. So if the first row D[1,] is 0 3 5 0 8 9 3 2 4 0 then I want z z-D[1,2]+D[1,3]+D[1,5] But if there are less than 3 non zero elements, those should be summed. If there are no non zero elements, the result must be zero. So if the first row D[1,] is 0 0 3 0 1 0 0 0 0 0 then I want z z-D[1,3]+D[1,5] Hope someone can help me out! [[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] Sum first 3 non zero elements of row
That's a good one, Using cumsum + rowsum would definitely be faster, On Tue, May 21, 2013 at 6:40 AM, José Verhoeven j...@memo2.nl wrote: Thank you, that really worked. Actually received an even shorter version: rowSums((t(apply(D 0, 1, cumsum)) = 3) * D) 2013/5/21 Xiao He praguewaterme...@gmail.com Oops, a couple of missing brackets in the previous reply: foo-function(x){ temp=x[x0] if(length(temp)=3) sum(temp[1:3]) else sum(temp) } #This was missing in the previous post set.seed(2) mat-matrix(sample(0:4, 25, replace=T, prob=c(1/2,rep(1/8,4))), ncol=5) #add a right parenthesis. mat On Tue, May 21, 2013 at 3:47 AM, Xiao He praguewaterme...@gmail.comwrote: Does this work? Probably not the fastest, but I think it does the job. foo-function(x){ temp=x[x0] if(length(temp)=3) sum(temp[1:3]) else sum(temp) set.seed(2) mat-matrix(sample(0:4, 25, replace=T, prob=c(1/2,rep(1/8,4)), ncol=5) mat # [,1] [,2] [,3] [,4] [,5] #[1,]01243 #[2,]30010 #[3,]24404 #[4,]00000 #[5,]12000 apply(mat, 1, foo)#Apply the function to each row of the matrix #[1] 7 4 10 0 3 On Tue, May 21, 2013 at 2:16 AM, José Verhoeven j...@memo2.nl wrote: Hi there, I've got this matrix D with, say 10 rows and 20 columns. For each row I want to sum the first 3 non zero elements and put them in a vector z. So if the first row D[1,] is 0 3 5 0 8 9 3 2 4 0 then I want z z-D[1,2]+D[1,3]+D[1,5] But if there are less than 3 non zero elements, those should be summed. If there are no non zero elements, the result must be zero. So if the first row D[1,] is 0 0 3 0 1 0 0 0 0 0 then I want z z-D[1,3]+D[1,5] Hope someone can help me out! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Lattice, ggplot, and pointsize
Le mardi 21 mai 2013 à 23:30 +1000, Duncan Mackay a écrit : Hi See par.settings in xyplot Things are also controlled by trellis.par.get() to see values trellis.par.set() eg xyplot(~Freq|Year, data = sheep2, groups = farm, par.settings = list(strip.background = list(col = transparent), axis.text = list(cex = 0.75), par.xlab.text = list(cex = 0.80), par.ylab.text = list(cex = 0.80)) , ...) HTH Thanks, but that's not really my question. I've already found the way to change text size. What I'm wondering is whether something could be done so that the pointsize argument that is passed to graphical devices has an effect on Lattice and ggplot2 plots. Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 21:18 21/05/2013, you wrote: Hi! When inserting R plots into a document using odfWeave, I fought for a while to get Lattice plots use the same text size as base plots. I eventually discovered that specifying a point size via e.g. svg(pointsize=10) has no effect on Lattice plots. One needs to adjust the size manually via: trellis.par.set(fontsize=list(text=10, points=8)) This is also developed for both Lattice and ggplot2 by this blog post: http://gforge.se/2013/03/exporting-plain-lattice-or-ggplot/ So I am wondering whether is a by-design limitation or whether this could be improved. I find it very useful to be able to adapt text size to the output device instead of changing plotting parameters for each plotting system (especially when you change the resolution of PNG output, or move from one output device to another). Thanks in advance __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using metafor for meta-analysis of before-after studies (escalc, SMCC)
Please see my answers below. Best, Wolfgang -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Moon Qiang Sent: Thursday, May 16, 2013 19:12 To: r-help Subject: [R] using metafor for meta-analysis of before-after studies (escalc, SMCC) Hello. I am trying to perform meta-analysis on some before-after studies. These studies are designed to clarify if there is any significant metabolic change before and after an intervention. There is only one group in these studies, i.e., no control group. I followed the e-mail communication of R-help (https://stat.ethz.ch/pipermail/r-help/2012-April/308946.html ) and the Metafor Manual (version 1.8-0, released 2013-04-11, relevant contents can be found on pages of 59-61 under 'Outcome Measures for Individual Groups '). I made a trial analysis and attached the output here, I wonder if anyone can look through it and give me some comments. I have three questions about the analysis: 1) Most studies reported the before-and-after raw change as Mean+/-SD, but few of them have reported the values of before-intervention (mean_r and sd_r) and the values of after-intervention (mean_s and sd_s), and none of them reported the r value (correlation for the before- and after- intervention measurements). Based on the guideline of the Metafor manual, I set the raw mean change as m1i (i.e., raw mean change=mean_s=m1i), and set the standard deviation of raw change as sd1i (i.e., the standard deviation of raw change =sd_s=sd1i), and set all other arguments including m2i, sd2i, ri as 0, and then calculated the standardized mean change using change score (SMCC). I am not sure if all these settings are correct. This is correct. The escalc() function still will compute (m1i-m2i)/sqrt(sd1i^2 + sd2i^2 - 2*ri*sd1i*sd2i), but since m2i=sd2i=ri=0, this is equivalent to mean_change / SD_change, which is what you want. Make sure that mean_s is NOT the standard error (SE) of the change scores, but really the SD. 2) A few studies have specified individual values of m1i, m2i, sd1i, sd2i , but did not report the change score or its sd. So can I set r=0 and use these values to calculate SMCC? Since SMCC is not calculated in the same way like 1), will this be a problem? Yes, this will be a problem, since you now really assume that r=0, which is not correct. Maybe you can back-calculate r from other information (e.g., the p or t value from a t-test -- see https://stat.ethz.ch/pipermail/r-help/2012-April/308946.html). Or you could try to get r from the authors (then you could also just directly ask for the change score mean and SD). If that is not successful, you will have to impute some kind of reasonable value for r and do a sensitivity analysis in the end. 3) some studies reported the percentage mean changes instead of raw mean change (percentage change=(value of after-intervention - value of before intervention) / value of before intervention), I think it may not be the right way to simply substitute the raw mean change with the percentage mean changes. Is there any method to deal with this problem? Don't know anything off the top of my head. Any comments are welcome. With best regards. -- Qiang Yue __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Sum first 3 non zero elements of row
Thank you, that really worked. Actually received an even shorter version: rowSums((t(apply(D 0, 1, cumsum)) = 3) * D) 2013/5/21 Xiao He praguewaterme...@gmail.com Oops, a couple of missing brackets in the previous reply: foo-function(x){ temp=x[x0] if(length(temp)=3) sum(temp[1:3]) else sum(temp) } #This was missing in the previous post set.seed(2) mat-matrix(sample(0:4, 25, replace=T, prob=c(1/2,rep(1/8,4))), ncol=5) #add a right parenthesis. mat On Tue, May 21, 2013 at 3:47 AM, Xiao He praguewaterme...@gmail.comwrote: Does this work? Probably not the fastest, but I think it does the job. foo-function(x){ temp=x[x0] if(length(temp)=3) sum(temp[1:3]) else sum(temp) set.seed(2) mat-matrix(sample(0:4, 25, replace=T, prob=c(1/2,rep(1/8,4)), ncol=5) mat # [,1] [,2] [,3] [,4] [,5] #[1,]01243 #[2,]30010 #[3,]24404 #[4,]00000 #[5,]12000 apply(mat, 1, foo)#Apply the function to each row of the matrix #[1] 7 4 10 0 3 On Tue, May 21, 2013 at 2:16 AM, José Verhoeven j...@memo2.nl wrote: Hi there, I've got this matrix D with, say 10 rows and 20 columns. For each row I want to sum the first 3 non zero elements and put them in a vector z. So if the first row D[1,] is 0 3 5 0 8 9 3 2 4 0 then I want z z-D[1,2]+D[1,3]+D[1,5] But if there are less than 3 non zero elements, those should be summed. If there are no non zero elements, the result must be zero. So if the first row D[1,] is 0 0 3 0 1 0 0 0 0 0 then I want z z-D[1,3]+D[1,5] Hope someone can help me out! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] tt function and coxph
On 05/18/2013 05:00 AM, r-help-requ...@r-project.org wrote: hi all this command used tt function for all variables. How can i define a different function for each variable? exCox.all-coxph(Surv(SURVT,STATUS) ~ RX+LOGWBC+SEX+tt(RX)+tt(LOGWBC)+tt(SEX), data=rem.data,tt=function(x,t,...) log(t)*x)) thank you There is currently no way to do what you ask. Could you give me an example of why it is necessary? I'd never thought of adding such a feature. 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] Calculating AIC for the whole model in VAR
Hello! I am using package VAR. I've fitted my model: mymodel-VAR(mydata,myp,type=const) I can extract the Log Liklihood for THE WHOLE MODEL: logLik(mymodel) How could I calculate (other than manually) the corresponding Akaike Information Criterion (AIC)? I tried AIC - but it does not take mymodel: AIC(mymodel) # numeric(0) Thank you! -- Dimitri Liakhovitski [[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] Calculating AIC for the whole model in VAR
On 21/05/2013 16:00, Dimitri Liakhovitski wrote: Hello! I am using package VAR. What is that? There is no such package on CRAN nor BioC. I've fitted my model: mymodel-VAR(mydata,myp,type=const) I can extract the Log Liklihood for THE WHOLE MODEL: logLik(mymodel) How could I calculate (other than manually) the corresponding Akaike Information Criterion (AIC)? I tried AIC - but it does not take mymodel: AIC(mymodel) # numeric(0) Thank you! This is not reproducible, pace the posting guide. The default method for AIC() should work if the logLik() method is written correctly, so I guess it was not. -- 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.
Re: [R] Calculating AIC for the whole model in VAR
Sorry, I am using package vars On Tue, May 21, 2013 at 11:09 AM, Prof Brian Ripley rip...@stats.ox.ac.ukwrote: On 21/05/2013 16:00, Dimitri Liakhovitski wrote: Hello! I am using package VAR. What is that? There is no such package on CRAN nor BioC. I've fitted my model: mymodel-VAR(mydata,myp,type=**const) I can extract the Log Liklihood for THE WHOLE MODEL: logLik(mymodel) How could I calculate (other than manually) the corresponding Akaike Information Criterion (AIC)? I tried AIC - but it does not take mymodel: AIC(mymodel) # numeric(0) Thank you! This is not reproducible, pace the posting guide. The default method for AIC() should work if the logLik() method is written correctly, so I guess it was not. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~**ripley/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 -- Dimitri Liakhovitski [[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] Lattice, ggplot, and pointsize
That is like complaining that your hammer does not fit these newfangled Philips screws. These are different tools. Do not expect them to interoperate. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Milan Bouchet-Valat nalimi...@club.fr wrote: Le mardi 21 mai 2013 à 23:30 +1000, Duncan Mackay a écrit : Hi See par.settings in xyplot Things are also controlled by trellis.par.get() to see values trellis.par.set() eg xyplot(~Freq|Year, data = sheep2, groups = farm, par.settings = list(strip.background = list(col = transparent), axis.text = list(cex = 0.75), par.xlab.text = list(cex = 0.80), par.ylab.text = list(cex = 0.80)) , ...) HTH Thanks, but that's not really my question. I've already found the way to change text size. What I'm wondering is whether something could be done so that the pointsize argument that is passed to graphical devices has an effect on Lattice and ggplot2 plots. Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 21:18 21/05/2013, you wrote: Hi! When inserting R plots into a document using odfWeave, I fought for a while to get Lattice plots use the same text size as base plots. I eventually discovered that specifying a point size via e.g. svg(pointsize=10) has no effect on Lattice plots. One needs to adjust the size manually via: trellis.par.set(fontsize=list(text=10, points=8)) This is also developed for both Lattice and ggplot2 by this blog post: http://gforge.se/2013/03/exporting-plain-lattice-or-ggplot/ So I am wondering whether is a by-design limitation or whether this could be improved. I find it very useful to be able to adapt text size to the output device instead of changing plotting parameters for each plotting system (especially when you change the resolution of PNG output, or move from one output device to another). Thanks in advance __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Calculating AIC for the whole model in VAR
On 21/05/2013 16:11, Dimitri Liakhovitski wrote: Sorry, I am using package vars So you need to report the bug in that package to its maintainer. ?logLik says Value: Returns an object of class ‘logLik’. This is a number with at least one attribute, ‘df’ (*d*egrees of *f*reedom), giving the number of (estimated) parameters in the model. and the methods in vars do not comply. On Tue, May 21, 2013 at 11:09 AM, Prof Brian Ripley rip...@stats.ox.ac.uk mailto:rip...@stats.ox.ac.uk wrote: On 21/05/2013 16:00, Dimitri Liakhovitski wrote: Hello! I am using package VAR. What is that? There is no such package on CRAN nor BioC. I've fitted my model: mymodel-VAR(mydata,myp,type=__const) I can extract the Log Liklihood for THE WHOLE MODEL: logLik(mymodel) How could I calculate (other than manually) the corresponding Akaike Information Criterion (AIC)? I tried AIC - but it does not take mymodel: AIC(mymodel) # numeric(0) Thank you! This is not reproducible, pace the posting guide. The default method for AIC() should work if the logLik() method is written correctly, so I guess it was not. -- Brian D. Ripley, rip...@stats.ox.ac.uk mailto:rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~__ripley/ http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 tel:%2B44%201865%20272861 (self) 1 South Parks Road, +44 1865 272866 tel:%2B44%201865%20272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 tel:%2B44%201865%20272595 -- Dimitri Liakhovitski -- 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.
Re: [R] numeric not equal its value
Jannis, Not strange. Try with numbers that can be exactly represented in binary (that's what computers use), e.g., a-seq(5,70,by=5) b-15 a==b or fractions, a-seq(1/32,14/32,by=1/32) b-3/32 a==b Most decimal fractions cannot be represented exactly although a bit of magic will display them as if they are. A little digging into the r-help archives will find further explanation. Clint Clint BowmanINTERNET: cl...@ecy.wa.gov Air Quality Modeler INTERNET: cl...@math.utah.edu Department of Ecology VOICE: (360) 407-6815 PO Box 47600FAX:(360) 407-7534 Olympia, WA 98504-7600 USPS: PO Box 47600, Olympia, WA 98504-7600 Parcels:300 Desmond Drive, Lacey, WA 98503-1274 On Mon, 20 May 2013, Jannis wrote: Dear R users, I ran into the strange situation where a number does not seem to equal its value. Try this: a - seq(0.05,0.7,0.05)[3] b - 0.15 a == b Should this not be TRUE? a-b yields a very small number (and not 0) so this most probably is a numerical error, but why does seq create such numbers? Thanks a lot Jannis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Calculating AIC for the whole model in VAR
Here is a reproducible example: library(vars) data(Canada) mymodel - VAR(Canada, p = 2, type = const) myLL-logLik(mymodel) AIC(myLL) Why does logLik(mymodel) say that df=NULL? Might this be the reason for AIC(myLL) being numeric(0)? Dimitri On Tue, May 21, 2013 at 11:17 AM, Prof Brian Ripley rip...@stats.ox.ac.ukwrote: On 21/05/2013 16:11, Dimitri Liakhovitski wrote: Sorry, I am using package vars So you need to report the bug in that package to its maintainer. ?logLik says Value: Returns an object of class logLik. This is a number with at least one attribute, df (*d*egrees of *f*reedom), giving the number of (estimated) parameters in the model. and the methods in vars do not comply. On Tue, May 21, 2013 at 11:09 AM, Prof Brian Ripley rip...@stats.ox.ac.uk mailto:rip...@stats.ox.ac.uk** wrote: On 21/05/2013 16:00, Dimitri Liakhovitski wrote: Hello! I am using package VAR. What is that? There is no such package on CRAN nor BioC. I've fitted my model: mymodel-VAR(mydata,myp,type=**__const) I can extract the Log Liklihood for THE WHOLE MODEL: logLik(mymodel) How could I calculate (other than manually) the corresponding Akaike Information Criterion (AIC)? I tried AIC - but it does not take mymodel: AIC(mymodel) # numeric(0) Thank you! This is not reproducible, pace the posting guide. The default method for AIC() should work if the logLik() method is written correctly, so I guess it was not. -- Brian D. Ripley, rip...@stats.ox.ac.uk mailto:rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~__**ripley/http://www.stats.ox.ac.uk/~__ripley/ http://www.stats.ox.ac.uk/~**ripley/http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 tel:%2B44%201865%20272861 (self) 1 South Parks Road, +44 1865 272866 tel:%2B44%201865%20272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 tel:%2B44%201865%20272595 -- Dimitri Liakhovitski -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~**ripley/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 -- Dimitri Liakhovitski [[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] Log scales
Thanks a million Uwe. I used the following from a forum to do it and it worked out: mylevels -c(-150,-100,-50,-20,-10,-5,-2,-1,1,2,5,10,20,50,100,150) cols - jet.colors(length(mylevels) - 1) customAxis - function() { n - length(mylevels) y - seq(min(mylevels), max(mylevels), length.out=n) rect(0, y[1:(n-1)], 1, y[2:n], col=cols) axis(4, at=y, labels=mylevels) } Many thanks, Emily Uwe Ligges wrote: On 17.05.2013 13:34, Emily Gleeson wrote: Dear All, I have a query about using log scales for filled.contour plots. I have used log values on the x and y axes but labelled the axes with their linear (non-log) values. I's like to do the same with the contour values. I want the range to go from -100% to +100%. To use log I just added 1000 to the % values before taking the log. I'd like the original % values to appear on the contour lines and in the contour colourbar labelling. One way would be to keep the original scale and set explicit breaks for the levels of contour lines as needed. Best, Uwe Ligges I'd appreciate any suggestions you have. Many thanks, Emily Gleeson * This e-mail and any files transmitted with it are confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. * This e-mail and any files transmitted with it are confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] problems with saving plots from loop
Greetings, I cannot find solution for this problem (I was searching on web, but without success): I want to plot dose-response models for one concentration and many responses (lets say 200) and I don´t want to do it manually. So I use loop for this: for (i in mydata[,2:201]){#first column is concentration pdf(paste(plot_,i,.pdf,sep = )) plot(i~concentration,log='x') ht - seq(0,5000,1) lines(ht, predict(selectedmodel, data.frame(concentration = ht))) #I previously selected appropriate model for each column within loop #(I don´t want to write here the whole loop with model selection) dev.off() } This seems, that it works (I obtain many pdf files with plots), but there is problem with names of these files. R uses random numbers as names , but after some files (more than 49) one of the selected names is '0' . And after few other files, there is the same name ('0') again. So the previous file is overwritten and it is lost. And this is repeated many times (so many plots are lost). And there is also name '1' doing the same thing... I really do not know how to solve it... I also tried pdf(paste(plot_,names[i],.pdf,sep = )) But it does not help (still random number as names are selected) ... I would be really happy if someone could help me with this... Thank you very much, Sona -- View this message in context: http://r.789695.n4.nabble.com/problems-with-saving-plots-from-loop-tp4667616.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 with data.frame
Dear All I have the following code for list a: a -list(structure(c(0, 4, 8, 12, 0, 19.5581076131386, 10.7499105081144, 5.91923975728553, 0, 4.08916328337685, 2.26872955281708, 1.24929641535359 ), .Dim = c(4L, 3L), .Dimnames = list(NULL, c(time, y, b )), istate = c(2L, 107L, 250L, NA, 5L, 5L, 0L, 52L, 22L, NA, NA, NA, NA, 0L, 1L, 1L, NA, NA, NA, NA, NA), rstate = c(0.867511261090201, 0.867511261090201, 12.7772879103809, 0, 0), lengthvar = 2L, class = c(deSolve, matrix), type = lsoda), structure(c(0, 4, 8, 12, 0, 17.0238115689622, 9.02425032330714, 4.7893314106951, 0, 4.45067278743554, 2.37140075611636, 1.25855947034654), .Dim = c(4L, 3L), .Dimnames = list(NULL, c(time, y, b)), istate = c(2L, 106L, 251L, NA, 4L, 4L, 0L, 52L, 22L, NA, NA, NA, NA, 0L, 1L, 1L, NA, NA, NA, NA, NA), rstate = c(0.662055762167652, 0.662055762167652, 12.3096826617166, 0, 0), lengthvar = 2L, class = c(deSolve, matrix), type = lsoda), structure(c(0, 4, 8, 12, 0, 15.3548797334796, 8.17712839316703, 4.36718847853436, 0, 5.15624657530424, 2.77411694866808, 1.48166036763212), .Dim = c(4L, 3L), .Dimnames = list(NULL, c(time, y, b)), istate = c(2L, 108L, 260L, NA, 5L, 5L, 0L, 52L, 22L, NA, NA, NA, NA, 0L, 1L, 1L, NA, NA, NA, NA, NA), rstate = c(0.735884123193699, 0.735884123193699, 12.1878866053931, 0, 0), lengthvar = 2L, class = c(deSolve, matrix), type = lsoda)) then I convert it to b b -data.frame(a) and manually I would extract the y variables (y, y.1 and y.2) as follows d -t(cbind(b$y,b$y.1,b$y.2)) Currently I only have 3 y variables, so manual solution is very easy. I would like to ask if you have any thoughts on how I could automate (or extract all ys) this so that I could achieve the same goal even if I have 5000 ys (from y, y.1, y.2 to y.5000) or any other number of ys for that matter with a simple code (as opposed to something like d -t(cbind(b$y,b$y.1,b$y.2,b$y.5000))). your help is greatly appreciated, thanks, Andras __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with data.frame
So if I understand you correctly, and I may not, you want to extract the columns from a dataframe that start with y? Using your reproducible example (thanks!): b[, grepl(^y, colnames(b))] y y.1 y.2 1 0.0 0.00 0.00 2 19.55811 17.023812 15.354880 3 10.74991 9.024250 8.177128 4 5.91924 4.789331 4.367188 Sarah On Tue, May 21, 2013 at 2:01 PM, Andras Farkas motyoc...@yahoo.com wrote: Dear All I have the following code for list a: a -list(structure(c(0, 4, 8, 12, 0, 19.5581076131386, 10.7499105081144, 5.91923975728553, 0, 4.08916328337685, 2.26872955281708, 1.24929641535359 ), .Dim = c(4L, 3L), .Dimnames = list(NULL, c(time, y, b )), istate = c(2L, 107L, 250L, NA, 5L, 5L, 0L, 52L, 22L, NA, NA, NA, NA, 0L, 1L, 1L, NA, NA, NA, NA, NA), rstate = c(0.867511261090201, 0.867511261090201, 12.7772879103809, 0, 0), lengthvar = 2L, class = c(deSolve, matrix), type = lsoda), structure(c(0, 4, 8, 12, 0, 17.0238115689622, 9.02425032330714, 4.7893314106951, 0, 4.45067278743554, 2.37140075611636, 1.25855947034654), .Dim = c(4L, 3L), .Dimnames = list(NULL, c(time, y, b)), istate = c(2L, 106L, 251L, NA, 4L, 4L, 0L, 52L, 22L, NA, NA, NA, NA, 0L, 1L, 1L, NA, NA, NA, NA, NA), rstate = c(0.662055762167652, 0.662055762167652, 12.3096826617166, 0, 0), lengthvar = 2L, class = c(deSolve, matrix), type = lsoda), structure(c(0, 4, 8, 12, 0, 15.3548797334796, 8.17712839316703, 4.36718847853436, 0, 5.15624657530424, 2.77411694866808, 1.48166036763212), .Dim = c(4L, 3L), .Dimnames = list(NULL, c(time, y, b)), istate = c(2L, 108L, 260L, NA, 5L, 5L, 0L, 52L, 22L, NA, NA, NA, NA, 0L, 1L, 1L, NA, NA, NA, NA, NA), rstate = c(0.735884123193699, 0.735884123193699, 12.1878866053931, 0, 0), lengthvar = 2L, class = c(deSolve, matrix), type = lsoda)) then I convert it to b b -data.frame(a) and manually I would extract the y variables (y, y.1 and y.2) as follows d -t(cbind(b$y,b$y.1,b$y.2)) Currently I only have 3 y variables, so manual solution is very easy. I would like to ask if you have any thoughts on how I could automate (or extract all ys) this so that I could achieve the same goal even if I have 5000 ys (from y, y.1, y.2 to y.5000) or any other number of ys for that matter with a simple code (as opposed to something like d -t(cbind(b$y,b$y.1,b$y.2,b$y.5000))). your help is greatly appreciated, thanks, Andras -- 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] problems with saving plots from loop
I don't think the problem is with the plotting, I think the problem is with your loop. R isn't selecting random numbers, it's doing exactly what you told, but what you told it doesn't make sense. Hint: use the same loop but simply print out i at each iteration. Here's a better way to do it, assuming you really want to have a loop: for (i in 2:201){#first column is concentration pdf(paste(plot_,i,.pdf,sep = )) plot(mydata[,i] ~concentration,log='x') } On Tue, May 21, 2013 at 11:57 AM, SonaJ 184...@mail.muni.cz wrote: Greetings, I cannot find solution for this problem (I was searching on web, but without success): I want to plot dose-response models for one concentration and many responses (lets say 200) and I don´t want to do it manually. So I use loop for this: for (i in mydata[,2:201]){#first column is concentration pdf(paste(plot_,i,.pdf,sep = )) plot(i~concentration,log='x') ht - seq(0,5000,1) lines(ht, predict(selectedmodel, data.frame(concentration = ht))) #I previously selected appropriate model for each column within loop #(I don´t want to write here the whole loop with model selection) dev.off() } This seems, that it works (I obtain many pdf files with plots), but there is problem with names of these files. R uses random numbers as names , but after some files (more than 49) one of the selected names is '0' . And after few other files, there is the same name ('0') again. So the previous file is overwritten and it is lost. And this is repeated many times (so many plots are lost). And there is also name '1' doing the same thing... I really do not know how to solve it... I also tried pdf(paste(plot_,names[i],.pdf,sep = )) But it does not help (still random number as names are selected) ... I would be really happy if someone could help me with this... Thank you very much, Sona -- 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] help with data.frame
that is exactly what I wanted! Thank you Sarah! Andras --- On Tue, 5/21/13, Sarah Goslee sarah.gos...@gmail.com wrote: From: Sarah Goslee sarah.gos...@gmail.com Subject: Re: [R] help with data.frame To: Andras Farkas motyoc...@yahoo.com Cc: r-help@r-project.org Date: Tuesday, May 21, 2013, 2:07 PM So if I understand you correctly, and I may not, you want to extract the columns from a dataframe that start with y? Using your reproducible example (thanks!): b[, grepl(^y, colnames(b))] y y.1 y.2 1 0.0 0.00 0.00 2 19.55811 17.023812 15.354880 3 10.74991 9.024250 8.177128 4 5.91924 4.789331 4.367188 Sarah On Tue, May 21, 2013 at 2:01 PM, Andras Farkas motyoc...@yahoo.com wrote: Dear All I have the following code for list a: a -list(structure(c(0, 4, 8, 12, 0, 19.5581076131386, 10.7499105081144, 5.91923975728553, 0, 4.08916328337685, 2.26872955281708, 1.24929641535359 ), .Dim = c(4L, 3L), .Dimnames = list(NULL, c(time, y, b )), istate = c(2L, 107L, 250L, NA, 5L, 5L, 0L, 52L, 22L, NA, NA, NA, NA, 0L, 1L, 1L, NA, NA, NA, NA, NA), rstate = c(0.867511261090201, 0.867511261090201, 12.7772879103809, 0, 0), lengthvar = 2L, class = c(deSolve, matrix), type = lsoda), structure(c(0, 4, 8, 12, 0, 17.0238115689622, 9.02425032330714, 4.7893314106951, 0, 4.45067278743554, 2.37140075611636, 1.25855947034654), .Dim = c(4L, 3L), .Dimnames = list(NULL, c(time, y, b)), istate = c(2L, 106L, 251L, NA, 4L, 4L, 0L, 52L, 22L, NA, NA, NA, NA, 0L, 1L, 1L, NA, NA, NA, NA, NA), rstate = c(0.662055762167652, 0.662055762167652, 12.3096826617166, 0, 0), lengthvar = 2L, class = c(deSolve, matrix), type = lsoda), structure(c(0, 4, 8, 12, 0, 15.3548797334796, 8.17712839316703, 4.36718847853436, 0, 5.15624657530424, 2.77411694866808, 1.48166036763212), .Dim = c(4L, 3L), .Dimnames = list(NULL, c(time, y, b)), istate = c(2L, 108L, 260L, NA, 5L, 5L, 0L, 52L, 22L, NA, NA, NA, NA, 0L, 1L, 1L, NA, NA, NA, NA, NA), rstate = c(0.735884123193699, 0.735884123193699, 12.1878866053931, 0, 0), lengthvar = 2L, class = c(deSolve, matrix), type = lsoda)) then I convert it to b b -data.frame(a) and manually I would extract the y variables (y, y.1 and y.2) as follows d -t(cbind(b$y,b$y.1,b$y.2)) Currently I only have 3 y variables, so manual solution is very easy. I would like to ask if you have any thoughts on how I could automate (or extract all ys) this so that I could achieve the same goal even if I have 5000 ys (from y, y.1, y.2 to y.5000) or any other number of ys for that matter with a simple code (as opposed to something like d -t(cbind(b$y,b$y.1,b$y.2,b$y.5000))). your help is greatly appreciated, thanks, Andras -- 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] problems with saving plots from loop
Hi, Try: set.seed(28) dat1- as.data.frame(matrix(c(rep(c(5,10,15,20,25),each=3),sample(1:20,15,replace=TRUE),sample(15:35,15,replace=TRUE),sample(20:40,15,replace=TRUE)),ncol=4)) names(dat1)[1]- concentration lapply(seq_len(ncol(dat1[,-1]))+1,function(i) {x1- cbind(dat1[,1],dat1[,i]);colnames(x1)-c(colnames(dat1)[1],colnames(dat1)[i]);pdf(paste(plot_,colnames(x1)[2],.pdf,sep=));plot(x1[,1],x1[,2],xlab=colnames(x1)[1],ylab=colnames(x1)[2]);dev.off() }) A.K. - Original Message - From: SonaJ 184...@mail.muni.cz To: r-help@r-project.org Cc: Sent: Tuesday, May 21, 2013 11:57 AM Subject: [R] problems with saving plots from loop Greetings, I cannot find solution for this problem (I was searching on web, but without success): I want to plot dose-response models for one concentration and many responses (lets say 200) and I don´t want to do it manually. So I use loop for this: for (i in mydata[,2:201]){ #first column is concentration pdf(paste(plot_,i,.pdf,sep = )) plot(i~concentration,log='x') ht - seq(0,5000,1) lines(ht, predict(selectedmodel, data.frame(concentration = ht))) #I previously selected appropriate model for each column within loop #(I don´t want to write here the whole loop with model selection) dev.off() } This seems, that it works (I obtain many pdf files with plots), but there is problem with names of these files. R uses random numbers as names , but after some files (more than 49) one of the selected names is '0' . And after few other files, there is the same name ('0') again. So the previous file is overwritten and it is lost. And this is repeated many times (so many plots are lost). And there is also name '1' doing the same thing... I really do not know how to solve it... I also tried pdf(paste(plot_,names[i],.pdf,sep = )) But it does not help (still random number as names are selected) ... I would be really happy if someone could help me with this... Thank you very much, Sona -- View this message in context: http://r.789695.n4.nabble.com/problems-with-saving-plots-from-loop-tp4667616.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. plot_V2.pdf Description: Adobe PDF document plot_V3.pdf Description: Adobe PDF document __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with data.frame
Hi, library(stringr) b[str_detect(colnames(b),^y)] # y y.1 y.2 #1 0.0 0.00 0.00 #2 19.55811 17.023812 15.354880 #3 10.74991 9.024250 8.177128 #4 5.91924 4.789331 4.367188 #or b[,!is.na(match(gsub(\\..*,,names(b)),y))] # y y.1 y.2 #1 0.0 0.00 0.00 #2 19.55811 17.023812 15.354880 #3 10.74991 9.024250 8.177128 #4 5.91924 4.789331 4.367188 A.K. Dear All I have the following code for list a: a -list(structure(c(0, 4, 8, 12, 0, 19.5581076131386, 10.7499105081144, 5.91923975728553, 0, 4.08916328337685, 2.26872955281708, 1.24929641535359 ), .Dim = c(4L, 3L), .Dimnames = list(NULL, c(time, y, b )), istate = c(2L, 107L, 250L, NA, 5L, 5L, 0L, 52L, 22L, NA, NA, NA, NA, 0L, 1L, 1L, NA, NA, NA, NA, NA), rstate = c(0.867511261090201, 0.867511261090201, 12.7772879103809, 0, 0), lengthvar = 2L, class = c(deSolve, matrix), type = lsoda), structure(c(0, 4, 8, 12, 0, 17.0238115689622, 9.02425032330714, 4.7893314106951, 0, 4.45067278743554, 2.37140075611636, 1.25855947034654), .Dim = c(4L, 3L), .Dimnames = list(NULL, c(time, y, b)), istate = c(2L, 106L, 251L, NA, 4L, 4L, 0L, 52L, 22L, NA, NA, NA, NA, 0L, 1L, 1L, NA, NA, NA, NA, NA), rstate = c(0.662055762167652, 0.662055762167652, 12.3096826617166, 0, 0), lengthvar = 2L, class = c(deSolve, matrix), type = lsoda), structure(c(0, 4, 8, 12, 0, 15.3548797334796, 8.17712839316703, 4.36718847853436, 0, 5.15624657530424, 2.77411694866808, 1.48166036763212), .Dim = c(4L, 3L), .Dimnames = list(NULL, c(time, y, b)), istate = c(2L, 108L, 260L, NA, 5L, 5L, 0L, 52L, 22L, NA, NA, NA, NA, 0L, 1L, 1L, NA, NA, NA, NA, NA), rstate = c(0.735884123193699, 0.735884123193699, 12.1878866053931, 0, 0), lengthvar = 2L, class = c(deSolve, matrix), type = lsoda)) then I convert it to b b -data.frame(a) and manually I would extract the y variables (y, y.1 and y.2) as follows d -t(cbind(b$y,b$y.1,b$y.2)) Currently I only have 3 y variables, so manual solution is very easy. I would like to ask if you have any thoughts on how I could automate (or extract all ys) this so that I could achieve the same goal even if I have 5000 ys (from y, y.1, y.2 to y.5000) or any other number of ys for that matter with a simple code (as opposed to something like d -t(cbind(b$y,b$y.1,b$y.2,b$y.5000))). your help is greatly appreciated, thanks, Andras __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Lattice, ggplot, and pointsize
Le mardi 21 mai 2013 à 08:17 -0700, Jeff Newmiller a écrit : That is like complaining that your hammer does not fit these newfangled Philips screws. These are different tools. Do not expect them to interoperate. I understand that Lattice and ggplot2 do not use settings from par(). I'm fine with this, as these packages are different from base graphics and have they own equivalent to tweak settings. What I do not understand is that one argument passed to output devices, which are _not_ provided by package graphics, is ignored by these two packages. Lattice and ggplot2 do not provide an alternative output system, so they indeed already interoperate with existing output devices to a certain extent; though they require you to set a separate option in at least one case. Since package graphics has a way to hook into the device parameters, maybe Lattice and ggplot2 could have a way to adapt they default settings to respect them. And BTW, please provide quotations where I am actually complaining. I'm willing to work on improving things where possible. Please do not consider any remark or question as a rant -- except if you want to scare potential contributors away, of course. Regards --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Milan Bouchet-Valat nalimi...@club.fr wrote: Le mardi 21 mai 2013 à 23:30 +1000, Duncan Mackay a écrit : Hi See par.settings in xyplot Things are also controlled by trellis.par.get() to see values trellis.par.set() eg xyplot(~Freq|Year, data = sheep2, groups = farm, par.settings = list(strip.background = list(col = transparent), axis.text = list(cex = 0.75), par.xlab.text = list(cex = 0.80), par.ylab.text = list(cex = 0.80)) , ...) HTH Thanks, but that's not really my question. I've already found the way to change text size. What I'm wondering is whether something could be done so that the pointsize argument that is passed to graphical devices has an effect on Lattice and ggplot2 plots. Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 21:18 21/05/2013, you wrote: Hi! When inserting R plots into a document using odfWeave, I fought for a while to get Lattice plots use the same text size as base plots. I eventually discovered that specifying a point size via e.g. svg(pointsize=10) has no effect on Lattice plots. One needs to adjust the size manually via: trellis.par.set(fontsize=list(text=10, points=8)) This is also developed for both Lattice and ggplot2 by this blog post: http://gforge.se/2013/03/exporting-plain-lattice-or-ggplot/ So I am wondering whether is a by-design limitation or whether this could be improved. I find it very useful to be able to adapt text size to the output device instead of changing plotting parameters for each plotting system (especially when you change the resolution of PNG output, or move from one output device to another). Thanks in advance __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] add identifier column by row
I want to add identifier column (Date) to a time series data frame. I want to name the Date column be from 1 to 30 every 1440 rows. Say I have a data like this (I simply my actual data here): $dat ID Var 1 1 2 4 3 6 4 7 5 7 6 8 How can I add identifier column (Date) from 1 to 3 every 2 rows and have output like this: ID Var Date 1 1 1 2 4 1 3 6 2 4 7 2 5 7 3 6 8 3 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.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] add identifier column by row
You can use rep() to create the Date column, and data.frame() to combine it. For your simple example, newdata - data.frame(dat, Date=rep(1:3, each=2)) On Tue, May 21, 2013 at 4:16 PM, Ye Lin ye...@lbl.gov wrote: I want to add identifier column (Date) to a time series data frame. I want to name the Date column be from 1 to 30 every 1440 rows. Say I have a data like this (I simply my actual data here): $dat ID Var 1 1 2 4 3 6 4 7 5 7 6 8 How can I add identifier column (Date) from 1 to 3 every 2 rows and have output like this: ID Var Date 1 1 1 2 4 1 3 6 2 4 7 2 5 7 3 6 8 3 -- 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] Lattice, ggplot, and pointsize
At the risk of misunderstanding... (inline) On Tue, May 21, 2013 at 12:17 PM, Milan Bouchet-Valat nalimi...@club.fr wrote: Le mardi 21 mai 2013 à 08:17 -0700, Jeff Newmiller a écrit : That is like complaining that your hammer does not fit these newfangled Philips screws. These are different tools. Do not expect them to interoperate. I understand that Lattice and ggplot2 do not use settings from par(). I'm fine with this, as these packages are different from base graphics and have they own equivalent to tweak settings. What I do not understand is that one argument passed to output devices, which are _not_ provided by package graphics, is ignored by these two packages. Lattice and ggplot2 do not provide an alternative output system, False, I believe, depending on what you mean by output system. They both use grid graphics, not base graphics and with lattice, anyway, you require a lattice specific device call: ?trellis.device ## this is called automatically when plotting if such a device is not open already. Of course, everything works in R, so if that is what you mean by output system ... Cheers, Bert so they indeed already interoperate with existing output devices to a certain extent; though they require you to set a separate option in at least one case. Since package graphics has a way to hook into the device parameters, maybe Lattice and ggplot2 could have a way to adapt they default settings to respect them. And BTW, please provide quotations where I am actually complaining. I'm willing to work on improving things where possible. Please do not consider any remark or question as a rant -- except if you want to scare potential contributors away, of course. Regards --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Milan Bouchet-Valat nalimi...@club.fr wrote: Le mardi 21 mai 2013 à 23:30 +1000, Duncan Mackay a écrit : Hi See par.settings in xyplot Things are also controlled by trellis.par.get() to see values trellis.par.set() eg xyplot(~Freq|Year, data = sheep2, groups = farm, par.settings = list(strip.background = list(col = transparent), axis.text = list(cex = 0.75), par.xlab.text = list(cex = 0.80), par.ylab.text = list(cex = 0.80)) , ...) HTH Thanks, but that's not really my question. I've already found the way to change text size. What I'm wondering is whether something could be done so that the pointsize argument that is passed to graphical devices has an effect on Lattice and ggplot2 plots. Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 21:18 21/05/2013, you wrote: Hi! When inserting R plots into a document using odfWeave, I fought for a while to get Lattice plots use the same text size as base plots. I eventually discovered that specifying a point size via e.g. svg(pointsize=10) has no effect on Lattice plots. One needs to adjust the size manually via: trellis.par.set(fontsize=list(text=10, points=8)) This is also developed for both Lattice and ggplot2 by this blog post: http://gforge.se/2013/03/exporting-plain-lattice-or-ggplot/ So I am wondering whether is a by-design limitation or whether this could be improved. I find it very useful to be able to adapt text size to the output device instead of changing plotting parameters for each plotting system (especially when you change the resolution of PNG output, or move from one output device to another). Thanks in advance __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
Re: [R] add identifier column by row
Do you want each number in Date to be repeated once (as in your example) or appear 48 times (so that you start over every 1440 rows, as in your request). For the former, rep(c(1:30),each=48) fills the first 1440 rows. On 21-May-13, at 1:16 PM, Ye Lin wrote: I want to add identifier column (Date) to a time series data frame. I want to name the Date column be from 1 to 30 every 1440 rows. Say I have a data like this (I simply my actual data here): $dat ID Var 1 1 2 4 3 6 4 7 5 7 6 8 How can I add identifier column (Date) from 1 to 3 every 2 rows and have output like this: ID Var Date 1 1 1 2 4 1 3 6 2 4 7 2 5 7 3 6 8 3 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.html and provide commented, minimal, self-contained, reproducible code. Don McKenzie, Research Ecologist Pacific Wildland Fire Sciences Lab US Forest Service phone: 206-732-7824 Affiliate Professor School of Environmental and Forest Sciences University of Washington __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] add identifier column by row
Duh -- I mean for the latter On 21-May-13, at 1:25 PM, Don McKenzie wrote: Do you want each number in Date to be repeated once (as in your example) or appear 48 times (so that you start over every 1440 rows, as in your request). For the former, rep(c(1:30),each=48) fills the first 1440 rows. On 21-May-13, at 1:16 PM, Ye Lin wrote: I want to add identifier column (Date) to a time series data frame. I want to name the Date column be from 1 to 30 every 1440 rows. Say I have a data like this (I simply my actual data here): $dat ID Var 1 1 2 4 3 6 4 7 5 7 6 8 How can I add identifier column (Date) from 1 to 3 every 2 rows and have output like this: ID Var Date 1 1 1 2 4 1 3 6 2 4 7 2 5 7 3 6 8 3 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.html and provide commented, minimal, self-contained, reproducible code. Don McKenzie, Research Ecologist Pacific Wildland Fire Sciences Lab US Forest Service phone: 206-732-7824 Affiliate Professor School of Environmental and Forest Sciences University of Washington __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. Don McKenzie, Research Ecologist Pacific Wildland Fire Sciences Lab US Forest Service phone: 206-732-7824 Affiliate Professor School of Environmental and Forest Sciences University of Washington __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] add identifier column by row
May be this helps: dat- read.table(text= ID Var 1 1 2 4 3 6 4 7 5 7 6 8 7 9 ,sep=,header=TRUE) dat$Date-cumsum(seq_len(nrow(dat))%%2) dat # ID Var Date #1 1 1 1 #2 2 4 1 #3 3 6 2 #4 4 7 2 #5 5 7 3 #6 6 8 3 #7 7 9 4 A.K. - Original Message - From: Ye Lin ye...@lbl.gov To: R help r-help@r-project.org Cc: Sent: Tuesday, May 21, 2013 4:16 PM Subject: [R] add identifier column by row I want to add identifier column (Date) to a time series data frame. I want to name the Date column be from 1 to 30 every 1440 rows. Say I have a data like this (I simply my actual data here): $dat ID Var 1 1 2 4 3 6 4 7 5 7 6 8 How can I add identifier column (Date) from 1 to 3 every 2 rows and have output like this: ID Var Date 1 1 1 2 4 1 3 6 2 4 7 2 5 7 3 6 8 3 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.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] Calculating AIC for the whole model in VAR
Am Dienstag, den 21.05.2013, 16:17 +0100 schrieb Prof Brian Ripley: On 21/05/2013 16:11, Dimitri Liakhovitski wrote: Sorry, I am using package vars So you need to report the bug in that package to its maintainer. ?logLik says Value: Returns an object of class ‘logLik’. This is a number with at least one attribute, ‘df’ (*d*egrees of *f*reedom), giving the number of (estimated) parameters in the model. and the methods in vars do not comply. Dear Prof. Ripley, many thanks for pointing this out. The attributes 'df' and 'nobs' have been added to logLik.varest() on R-Forge (project 'AICTS II', revision = 90); soon to be released on CRAN (package version 1.5-1). Best, Bernhard On Tue, May 21, 2013 at 11:09 AM, Prof Brian Ripley rip...@stats.ox.ac.uk mailto:rip...@stats.ox.ac.uk wrote: On 21/05/2013 16:00, Dimitri Liakhovitski wrote: Hello! I am using package VAR. What is that? There is no such package on CRAN nor BioC. I've fitted my model: mymodel-VAR(mydata,myp,type=__const) I can extract the Log Liklihood for THE WHOLE MODEL: logLik(mymodel) How could I calculate (other than manually) the corresponding Akaike Information Criterion (AIC)? I tried AIC - but it does not take mymodel: AIC(mymodel) # numeric(0) Thank you! This is not reproducible, pace the posting guide. The default method for AIC() should work if the logLik() method is written correctly, so I guess it was not. -- Brian D. Ripley, rip...@stats.ox.ac.uk mailto:rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~__ripley/ http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 tel:%2B44%201865%20272861 (self) 1 South Parks Road, +44 1865 272866 tel:%2B44%201865%20272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 tel:%2B44%201865%20272595 -- Dimitri Liakhovitski __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Lattice, ggplot, and pointsize
On 21/05/2013 21:24, Bert Gunter wrote: At the risk of misunderstanding... (inline) On Tue, May 21, 2013 at 12:17 PM, Milan Bouchet-Valat nalimi...@club.fr wrote: Le mardi 21 mai 2013 à 08:17 -0700, Jeff Newmiller a écrit : That is like complaining that your hammer does not fit these newfangled Philips screws. These are different tools. Do not expect them to interoperate. I understand that Lattice and ggplot2 do not use settings from par(). I'm fine with this, as these packages are different from base graphics and have they own equivalent to tweak settings. What I do not understand is that one argument passed to output devices, which are _not_ provided by package graphics, is ignored by these two packages. Lattice and ggplot2 do not provide an alternative output system, False, I believe, depending on what you mean by output system. They both use grid graphics, not base graphics and with lattice, anyway, Indeed. The issue is a design difference between the base and grid graphics subsystems. See the 'R Internals' manual for more details. you require a lattice specific device call: ?trellis.device ## this is called automatically when plotting if such a device is not open already. Of course, everything works in R, so if that is what you mean by output system ... Cheers, Bert so they indeed already interoperate with existing output devices to a certain extent; though they require you to set a separate option in at least one case. Since package graphics has a way to hook into the device parameters, maybe Lattice and ggplot2 could have a way to adapt they default settings to respect them. And BTW, please provide quotations where I am actually complaining. I'm willing to work on improving things where possible. Please do not consider any remark or question as a rant -- except if you want to scare potential contributors away, of course. Regards --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Milan Bouchet-Valat nalimi...@club.fr wrote: Le mardi 21 mai 2013 à 23:30 +1000, Duncan Mackay a écrit : Hi See par.settings in xyplot Things are also controlled by trellis.par.get() to see values trellis.par.set() eg xyplot(~Freq|Year, data = sheep2, groups = farm, par.settings = list(strip.background = list(col = transparent), axis.text = list(cex = 0.75), par.xlab.text = list(cex = 0.80), par.ylab.text = list(cex = 0.80)) , ...) HTH Thanks, but that's not really my question. I've already found the way to change text size. What I'm wondering is whether something could be done so that the pointsize argument that is passed to graphical devices has an effect on Lattice and ggplot2 plots. Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 21:18 21/05/2013, you wrote: Hi! When inserting R plots into a document using odfWeave, I fought for a while to get Lattice plots use the same text size as base plots. I eventually discovered that specifying a point size via e.g. svg(pointsize=10) has no effect on Lattice plots. One needs to adjust the size manually via: trellis.par.set(fontsize=list(text=10, points=8)) This is also developed for both Lattice and ggplot2 by this blog post: http://gforge.se/2013/03/exporting-plain-lattice-or-ggplot/ So I am wondering whether is a by-design limitation or whether this could be improved. I find it very useful to be able to adapt text size to the output device instead of changing plotting parameters for each plotting system (especially when you change the resolution of PNG output, or move from one output device to another). Thanks in advance __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list
Re: [R] Lattice xyplot multipanels
Dear Rxperts, Using the same example above, is there a way to remove the borders of multi-panel strips and control the display of the borders of each panel.. for example, I would like to keep only side 1 2 of a panel... Thanks, Santosh On Wed, May 1, 2013 at 11:11 PM, Santosh santosh2...@gmail.com wrote: Thanks for all tips/suggestions.. Just a few more comments.. The same code I use with a different data set in another project does not create those curly braces! Regards, Santosh On Wed, May 1, 2013 at 8:16 PM, Santosh santosh2...@gmail.com wrote: Sorry about the word brackets.. Yes, I meant curly braces! I have not heard of curley braces! :). Curly braces surrounding the values of strip.levels appear on the strip of multipanel plots. Thanks, Santosh On Wed, May 1, 2013 at 7:44 PM, David Winsemius dwinsem...@comcast.netwrote: On May 1, 2013, at 6:16 PM, Santosh wrote: Dear Rxperts, I have a strange situation.. I see curly brackets Wait right here. What do you mean by brackets? In some locales, such as mine, that might mean [ ; in other domains... well, who knows? I don't see any [. The Urban Legends Newsgroup used to have a saying: TWIAVBP, which is an initialism for: The World Is A Very Big Place. Pleas realize that language is local. around strip.levels in multipanel strips while using lattice::xyplot. .How do I get rid of the curly brackets? Curly brackets? You mean curley braces? I see some of them in the code, but why in the world would one want to remove valid curley-braces in code? They just function as delimiters. For some reason, I am not able to reproduce the problem using an example below... What problem? .. are you unable to reproduce? The code runs without error on my machine. Any suggestions are highly welcome! Thanks, Santosh q - data.frame(G=rep(paste(G,1:3,sep=),each=50),D=rep(paste(D,1:5,sep=),each=30),a=rep(1:15,each=10),t=rep(seq(10),15),b=round(runif(150,10,20))) q$grp - paste(q$D,q$a,sep=:) q$grp - ordered(q$grp, levels=unique(q$grp)) q$dcol - unlist(sapply(q$D,function(x) switch(x,D1=orange,D2=blue,D3=red, D4=seagreen, D5=black))) q2 - q[order(q$G,q$D,q$a,q$t),] ref3 - subset(q2, !duplicated(a)) xyplot(b~t|G,data=q2,groups=grp,type=l,as.table=T, layout=c(3,1), par.strip.text = list(lines = 2), panel=panel.superpose, panel.groups=function(x=x,y=y,subscripts=subscripts,groups=groups,...,group.number) { require(grid) panel.xyplot(x=x,y=y,subscripts=subscripts,pch=NA,lwd=1,type=l, col=q2$dcol[subscripts],lty=1,cex=0.7) rv0 -ref3[ref3$G%in%unique(q2$G)[panel.number()],] tids- paste(as.character(unique(rv0$D))) tcols - unique(rv0$dcol) tlty- 1 draw.key(list(columns=1,between=1,between.col=0.5, text=list(lab=tids,col=tcols,cex=0.8),title=Classes,cex.title=1.1 ), draw = T,vp = viewport(x = unit(0.8, npc), y = unit(0.9, npc))) }, strip=strip.custom(strip.names=T,strip.levels=T,par.strip.text=list(cex=1.7,font=2),bg=0, var.name=School), xlab=deparse(substitute(x)), ylab=deparse(substitute(y)), main=Overlay of Profiles by Schools and Classes, ) [[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] point.in.polygon help
I am new to mapping with R, and I would like to use the point.in.polygon function from the sp package, but I am unsure of how to get my data in the correct format for the function. The generic form of the function is as follows: point.in.polygon(point.x, point.y, pol.x, pol.y, mode.checked=FALSE) I have no problem with the point.x and point.y inputs. I have a list of gps longitudes and latitudes that will go in fine. My problem is with the pol.x and pol.y input. My polygon is currently in the form of a SpatialPolygonsDataFrame created by inputting shp files with the rgdal package. How do I get a numerical array of the x- and y-coordinates from my polygon that will go into the point.in.polygon function? -- View this message in context: http://r.789695.n4.nabble.com/point-in-polygon-help-tp4667645.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] problem with transform and get functions
Hello, I'm having a problem using the transform and get functions. I'm probably making a dumb mistake, and I need help! I start by making a small simulated dataset. I save the names of the variables in var.names. Without getting into the details of it, I have to create a custom function to perform some statistics. As part of this, I need to sequentially set all variables in the dataset (one at a time) to a value of 0. I tried using the get function, to automate this (I need to automate this because my real dataset has 100's of variables). However, I get the following error message: Error: unexpected '=' in: { test0 - transform(test, (get(predictor.names[i])) = } Error: unexpected '}' in } Here is my code: n-200 set.seed(111) X1 - rbinom(n,1,0.4) X2 - rbinom(n,1,0.5) X3 - rbinom(n,1,0.5) X4 - rbinom(n,1,(0.5 + 0.2*X1 - 0.3*X2 + 0.005*X3)) Y - rnorm(n,(3 + X1 + 0.3*X2 + 0.1*X3 + 0.05*X4),.4) data.frame(Y,X1,X2,X3,X4) - test var.names - colnames(test) for (i in (1:5)) { test0 - transform(test, (get(var.names[i])) = 0) } ## NO ERROR MESSAGE WHEN I DON'T USE GET, AND INSTEAD DO IT EXPLICITLY test0 - transform(test, X1 = 0) [[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] metafor matrix error
hi I've been using this code to set a reference level for uni and multivariate analysis rmix$interviewmethodcode-relevel(mix$interviewmethodcode,ref=SAQ) summary(rma.1-rma(yi,vi,mods=~interviewmethodcode,data=rmix,method=SJ,knha=F,weighted=F,intercept=T)) giving this output: Model Results: estimate se zvalpvalci.lb ci.ub intrcpt 0.1437 0.0176 8.1485 .0001 0.1091 0.1783 *** interviewmethodcodeACASI0.0022 0.0412 0.0545 0.9566 -0.0784 0.0829 interviewmethodcodeFTFI-0.0926 0.0656 -1.4112 0.1582 -0.2213 0.0360 However, when i use the same code with a different variable (below) I get the error message - Error in qr.solve(wX, diag(k)) : singular matrix 'a' in solve. rmix$continent-relevel(mix$continent,ref=North America) summary(rma.1-rma(yi,vi,mods=~continent,data=rmix,method=SJ,knha=F,weighted=F,intercept=T)) Can anyone help to see where the problem is? thanks Branwen hi I've been using this code to set a reference level for uni and multivariate analysis rmix$interviewmethodcode-relevel(mix$interviewmethodcode,ref=SAQ) summary(rma.1-rma(yi,vi,mods=~interviewmethodcode,data=rmix,method=SJ,knha=F,weighted=F,intercept=T)) giving this output: Model Results: estimate se zvalpvalci.lb ci.ub intrcpt 0.1437 0.0176 8.1485 .0001 0.1091 0.1783 *** interviewmethodcodeACASI0.0022 0.0412 0.0545 0.9566 -0.0784 0.0829 interviewmethodcodeFTFI-0.0926 0.0656 -1.4112 0.1582 -0.2213 0.0360 However, when i use the same code with a different variable (below) I get the error message - Error in qr.solve(wX, diag(k)) : singular matrix 'a' in solve. rmix$continent-relevel(mix$continent,ref=North America) summary(rma.1-rma(yi,vi,mods=~continent,data=rmix,method=SJ,knha=F,weighted=F,intercept=T)) Can anyone help to see where the problem is? thanks Branwen -- View this message in context: http://r.789695.n4.nabble.com/metafor-matrix-error-tp4667653.html Sent from the R help mailing list archive at Nabble.com. [[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] x axis problem when plotting
Hey I have a dataset like this: Date Var day 1/1/2013 1 Tue 1/2/2013 2 Wed 1/3/2013 3 Thu 1/4/2013 4 Fri 1/5/2013 5 Sat 1/6/2013 6 Sun 1/7/2013 7 Mon 1/8/2013 8 Tue 1/9/2013 9 Wed 1/10/2013 10 Thu And I want to plot Var~day Here is the code I use: plot(Dataset$Var~Dataset$day,xlab='Day of a week') Then I get this error message: ERROR: need finite 'xlim' values When I use similar code to plot Var~Date, it works fine. I have tired plot the line first then add X axis using axis(1,Dataset$day), it doesnt work either. Really appreciate your help! [[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] add identifier column by row
rep(c(1:30),each=1440) works! On Tue, May 21, 2013 at 1:25 PM, Don McKenzie d...@u.washington.edu wrote: Do you want each number in Date to be repeated once (as in your example) or appear 48 times (so that you start over every 1440 rows, as in your request). For the former, rep(c(1:30),each=48) fills the first 1440 rows. On 21-May-13, at 1:16 PM, Ye Lin wrote: I want to add identifier column (Date) to a time series data frame. I want to name the Date column be from 1 to 30 every 1440 rows. Say I have a data like this (I simply my actual data here): $dat ID Var 1 1 2 4 3 6 4 7 5 7 6 8 How can I add identifier column (Date) from 1 to 3 every 2 rows and have output like this: ID Var Date 1 1 1 2 4 1 3 6 2 4 7 2 5 7 3 6 8 3 Thanks, [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Don McKenzie, Research Ecologist Pacific Wildland Fire Sciences Lab US Forest Service phone: 206-732-7824 Affiliate Professor School of Environmental and Forest Sciences University of Washington [[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] add identifier column by row
it works! Thanks! On Tue, May 21, 2013 at 1:24 PM, Sarah Goslee sarah.gos...@gmail.comwrote: You can use rep() to create the Date column, and data.frame() to combine it. For your simple example, newdata - data.frame(dat, Date=rep(1:3, each=2)) On Tue, May 21, 2013 at 4:16 PM, Ye Lin ye...@lbl.gov wrote: I want to add identifier column (Date) to a time series data frame. I want to name the Date column be from 1 to 30 every 1440 rows. Say I have a data like this (I simply my actual data here): $dat ID Var 1 1 2 4 3 6 4 7 5 7 6 8 How can I add identifier column (Date) from 1 to 3 every 2 rows and have output like this: ID Var Date 1 1 1 2 4 1 3 6 2 4 7 2 5 7 3 6 8 3 -- Sarah Goslee http://www.functionaldiversity.org [[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] problem with transform and get functions
On May 21, 2013, at 12:40 PM, Roni Kobrosly wrote: Hello, I'm having a problem using the transform and get functions. I'm probably making a dumb mistake, and I need help! I start by making a small simulated dataset. I save the names of the variables in var.names. Without getting into the details of it, I have to create a custom function to perform some statistics. As part of this, I need to sequentially set all variables in the dataset (one at a time) to a value of 0. I tried using the get function, to automate this (I need to automate this because my real dataset has 100's of variables). However, I get the following error message: Error: unexpected '=' in: { test0 - transform(test, (get(predictor.names[i])) = } Error: unexpected '}' in } Here is my code: n-200 set.seed(111) X1 - rbinom(n,1,0.4) X2 - rbinom(n,1,0.5) X3 - rbinom(n,1,0.5) X4 - rbinom(n,1,(0.5 + 0.2*X1 - 0.3*X2 + 0.005*X3)) Y - rnorm(n,(3 + X1 + 0.3*X2 + 0.1*X3 + 0.05*X4),.4) data.frame(Y,X1,X2,X3,X4) - test var.names - colnames(test) for (i in (1:5)) { test0 - transform(test, (get(var.names[i])) = 0) There is no `get-` function. You need to use assign. } ## NO ERROR MESSAGE WHEN I DON'T USE GET, AND INSTEAD DO IT EXPLICITLY test0 - transform(test, X1 = 0) Right. There is a `-` function [[alternative HTML version deleted]] Please learn to post in plain text. It's really quite easy. -- David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Lattice xyplot multipanels
Dear Rxperts, Ok The curly braces as we talked before,... They appear if the group argument of xyplot function is entered as a numeric value; and don't when the values are letters. I just figured how to hide the strip borders...and also control the ticks in different axes... Any suggestions to remove the *curly braces* are highly welcome. q - data.frame(G = rep(paste(G,1:3,sep = ),each = 50), D = rep(paste(D,1:5,sep = ),each = 30), a = rep(1:15,each = 10), t = rep(seq(10),15), b = round(runif(150,10,20))) q$grp - paste(q$D,q$a,sep = :) q$grp - ordered(q$grp, levels = unique(q$grp)) q$dcol - unlist(sapply(q$D,function(x) switch(x, D1 = orange, D2 = blue, D3 = red, D4 = seagreen, D5 = black))) q2 - q[order(q$G,q$D,q$a,q$t),] ref3 - subset(q2, !duplicated(a)) my.theme = list(strip.border = list(col = NA), strip.background = list(col = NA)) # Of course, I can add a series of $.. I don't have too many $s! xyplot(b ~ t | G,data = q2,groups = grp,type = l,as.table = T, layout = c(3,1), par.strip.text = list(lines = 2), panel = panel.superpose, par.settings = my.theme, panel.groups = function(x = x, y = y, subscripts = subscripts, groups = groups,..., group.number) { require(grid) panel.xyplot(x = x,y = y, subscripts = subscripts,pch = NA,lwd = 1,type = l, col = q2$dcol[subscripts],lty = 1,cex = 0.7) rv0- ref3[ref3$G%in%unique(q2$G)[panel.number()],] tids - paste(as.character(unique(rv0$D))) tcols - unique(rv0$dcol) tlty - 1 draw.key(list(columns = 1,between = 1,between.col = 0.5, text = list(lab = tids,col = tcols,cex = 0.8),title = Classes,cex.title = 1.1 ), draw = T,vp = viewport(x = unit(0.8, npc), y = unit(0.9, npc))) }, strip = strip.custom(strip.names = T,strip.levels = T,par.strip.text = list(cex = 1.7,font = 2),bg = 0,var.name = School), xlab = deparse(substitute(x)), ylab = deparse(substitute(y)), main = Overlay of Profiles by Schools and Classes, ) On Tue, May 21, 2013 at 3:00 PM, Santosh santosh2...@gmail.com wrote: Dear Rxperts, Using the same example above, is there a way to remove the borders of multi-panel strips and control the display of the borders of each panel.. for example, I would like to keep only side 1 2 of a panel... Thanks, Santosh On Wed, May 1, 2013 at 11:11 PM, Santosh santosh2...@gmail.com wrote: Thanks for all tips/suggestions.. Just a few more comments.. The same code I use with a different data set in another project does not create those curly braces! Regards, Santosh On Wed, May 1, 2013 at 8:16 PM, Santosh santosh2...@gmail.com wrote: Sorry about the word brackets.. Yes, I meant curly braces! I have not heard of curley braces! :). Curly braces surrounding the values of strip.levels appear on the strip of multipanel plots. Thanks, Santosh On Wed, May 1, 2013 at 7:44 PM, David Winsemius dwinsem...@comcast.netwrote: On May 1, 2013, at 6:16 PM, Santosh wrote: Dear Rxperts, I have a strange situation.. I see curly brackets Wait right here. What do you mean by brackets? In some locales, such as mine, that might mean [ ; in other domains... well, who knows? I don't see any [. The Urban Legends Newsgroup used to have a saying: TWIAVBP, which is an initialism for: The World Is A Very Big Place. Pleas realize that language is local. around strip.levels in multipanel strips while using lattice::xyplot. .How do I get rid of the curly brackets? Curly brackets? You mean curley braces? I see some of them in the code, but why in the world would one want to remove valid curley-braces in code? They just function as delimiters. For some reason, I am not able to reproduce the problem using an example below... What problem? .. are you unable to reproduce? The code runs without error on my machine. Any suggestions are highly welcome! Thanks, Santosh q - data.frame(G=rep(paste(G,1:3,sep=),each=50),D=rep(paste(D,1:5,sep=),each=30),a=rep(1:15,each=10),t=rep(seq(10),15),b=round(runif(150,10,20))) q$grp - paste(q$D,q$a,sep=:) q$grp - ordered(q$grp, levels=unique(q$grp)) q$dcol - unlist(sapply(q$D,function(x) switch(x,D1=orange,D2=blue,D3=red, D4=seagreen, D5=black))) q2 - q[order(q$G,q$D,q$a,q$t),] ref3 - subset(q2, !duplicated(a)) xyplot(b~t|G,data=q2,groups=grp,type=l,as.table=T, layout=c(3,1), par.strip.text = list(lines = 2), panel=panel.superpose, panel.groups=function(x=x,y=y,subscripts=subscripts,groups=groups,...,group.number) { require(grid) panel.xyplot(x=x,y=y,subscripts=subscripts,pch=NA,lwd=1,type=l, col=q2$dcol[subscripts],lty=1,cex=0.7) rv0 -ref3[ref3$G%in%unique(q2$G)[panel.number()],] tids- paste(as.character(unique(rv0$D))) tcols - unique(rv0$dcol) tlty- 1
Re: [R] x axis problem when plotting
Hi, May be this helps: dat1-read.table(text= Date Var day 1/1/2013 1 Tue 1/2/2013 2 Wed 1/3/2013 3 Thu 1/4/2013 4 Fri 1/5/2013 5 Sat 1/6/2013 6 Sun 1/7/2013 7 Mon 1/8/2013 8 Tue 1/9/2013 9 Wed 1/10/2013 10 Thu ,sep=,header=TRUE,stringsAsFactors=FALSE) dat1$days-as.numeric(format(as.Date(dat1$Date,format=%m/%d/%Y),%w)) plot(Var~days,data=dat1,xaxt=n,xlab=Day of week) axis(1,at=dat1$days,labels=dat1$day) A.K. - Original Message - From: Ye Lin ye...@lbl.gov To: R help r-help@r-project.org Cc: Sent: Tuesday, May 21, 2013 7:22 PM Subject: [R] x axis problem when plotting Hey I have a dataset like this: Date Var day 1/1/2013 1 Tue 1/2/2013 2 Wed 1/3/2013 3 Thu 1/4/2013 4 Fri 1/5/2013 5 Sat 1/6/2013 6 Sun 1/7/2013 7 Mon 1/8/2013 8 Tue 1/9/2013 9 Wed 1/10/2013 10 Thu And I want to plot Var~day Here is the code I use: plot(Dataset$Var~Dataset$day,xlab='Day of a week') Then I get this error message: ERROR: need finite 'xlim' values When I use similar code to plot Var~Date, it works fine. I have tired plot the line first then add X axis using axis(1,Dataset$day), it doesnt work either. Really appreciate your help! [[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] as.vector with mode=list and POSIXct
I recommend that you not plan on waiting for the hash package to be redesigned to meet your expectations. Also, your response to discovering this feature of the hash package seems illogical. From a computer science perspective, the hash mechanism is an implementation trick that is intended to improve lookup speed. It does not actually represent a fundamental data structure like a vector or a set does. You can always put your keys in a vector and search through them (e.g. vector indexing by string) to get an equivalent data retrieval. If the hash package is not improving the speed of your data access, adding an extra layer of data structure is hardly an appropriate solution. Why are you not using normal vectors or data frames and accessing with string or logical indexing? If you are avoiding vectors because they seem slow in loops, perhaps you just need to preallocate the vectors you will store your results in before your loop to regain acceptable speed. Or, perhaps the duplicated() or merge() functions could save you from this mess of incremental data processing. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Alexandre Sieira alexandre.sie...@gmail.com wrote: You are absolutely right. I am storing POSIXct objects into a hash (from the hash package). However, if I try to get them out as a vector using the values() function, they are unclassed. And that breaks my (highly vectorized) code. Take a look at this: h = hash() h[[a]] = Sys.time() str(h[[a]]) POSIXct[1:1], format: 2013-05-20 16:54:28 str(values(h)) Named num 1.37e+09 - attr(*, names)= chr a I have reported this to the hash package maintainers. In the meantime, however, I am storing, for each key, a list containing a single POSIXct. Then, when I extract all using values(), I get a list containing all POSIXct entries with class preserved. h = hash() h[[a]] = list( Sys.time() ) h[[b]] = list( Sys.time() ) h[[c]] = list( Sys.time() ) values(h) $a [1] 2013-05-21 09:54:03 BRT $b [1] 2013-05-21 09:54:07 BRT $c [1] 2013-05-21 09:54:11 BRT str(values(h)) List of 3 $ a: POSIXct[1:1], format: 2013-05-21 09:54:03 $ b: POSIXct[1:1], format: 2013-05-21 09:54:07 $ c: POSIXct[1:1], format: 2013-05-21 09:54:11 However, the next thing I need to do is a min() over that list, so I need to convert the list into a vector again. I agree completely with you that this is horrible for performance, but it is a temporary workaround until values() is fixed. -- Alexandre Sieira CISA, CISSP, ISO 27001 Lead Auditor The truth is rarely pure and never simple. Oscar Wilde, The Importance of Being Earnest, 1895, Act I On 20 de maio de 2013 at 19:40:14, Jeff Newmiller (jdnew...@dcn.davis.ca.us) wrote: I don't know what you plan to do with this list, but lists are quite a bit less efficient than fixed-mode vectors, so you are likely losing a lot of computational speed by using this list. I don't hesitate to use simple data frames (lists of vectors), but processing lists is on par with for loops, not vectorized computation. It may still support a simpler model of computation, but that is an analyst comprehension benefit rather than a computational efficiency benefit. --- Jeff Newmiller The . . Go Live... DCN:jdnew...@dcn.davis.ca.us Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Alexandre Sieira alexandre.sie...@gmail.com wrote: I was trying to convert a vector of POSIXct into a list of POSIXct, However, I had a problem that I wanted to share with you. Works fine with, say, numeric: v = c(1, 2, 3) v [1] 1 2 3 str(v) num [1:3] 1 2 3 l = as.vector(v, mode=list) l [[1]] [1] 1 [[2]] [1] 2 [[3]] [1] 3 str(l) List of 3 $ : num 1 $ : num 2 $ : num 3 If you try it with POSIXct, on the other hand… v = c(Sys.time(), Sys.time()) v [1] 2013-05-20 18:02:07 BRT 2013-05-20 18:02:07 BRT str(v) POSIXct[1:2], format: 2013-05-20 18:02:07 2013-05-20 18:02:07 l = as.vector(v, mode=list) l [[1]] [1] 1369083728 [[2]] [1] 1369083728 str(l) List of 2 $ : num 1.37e+09 $ : num 1.37e+09
Re: [R] Writing to a file
Hi, Try this: lst1-lapply(1:5,function(i) {pdf(paste0(i,.pdf)); hist(rnorm(100),main=paste0(Histogram_,i));dev.off()}) #you can change the numbers A.K. I'm trying to generate a pdf called 1.pdf, 2.pdf, 3.pdf etc and it isn't working. My code is: x - 0 for(i in 1:1000){ x - x + 1 pdf(as.character(x),.pdf) #writes out to pdf for(i in 1:100){ hist(rnorm(1)) # graphs histogram, writen to the file } dev.off() } Also, I triedto just do a- 1 a between the pdf() and dev.off() line and it wouldnt add it to the file, even with a name as foo.pdf. 1.pdf Description: Adobe PDF document __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Something Very Easy
HI, I am not sure about what you expect as output. dat1- read.table(text= Offense Play Y A N B Y A Y C N B N C ,sep=,header=TRUE,stringsAsFactors=FALSE) with(dat1,tapply(Play,list(Offense),table)) #$N # #B C #2 1 # #$Y # #A C #2 1 #or with(dat1,tapply(factor(Play),list(Offense),table)) #$N # #A B C #0 2 1 # #$Y # #A B C #2 0 1 A.K. I have lines of data that look like this: Offense Play YA NB YA YC NB NC with a bunch of other variables. I just want to get a table like table(Play[Offense==Y]) but one that would return, for the data above: A 2 C 1 Instead of what I get now, from table(Play[Offense==Y]): A 2 B 2 C 2 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] eRm package, RSM: Error in solve.default(parets$hessian) :
I want to make an index using IRT, I use eRm package. I have a data frame (24 items, 4 categories, 427 cases) that works if I use PCM (partial credit model), but, when I run RSM (rating scale model) this appear: Error in solve.default(parest$hessian) : Lapack routine dgesv: system is exactly singular: U[14,14] = 0 By mistake I recoded the items in three categories, and works the RSM, but when I realized I recoded to four again and nothing... the same error. Anyone? 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.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using loop for applying function on matrix
Thanks a lot for all your help. best wishes, Mitra On 21 May 2013 21:04, arun smartpink...@yahoo.com wrote: You could also use: sapply(seq_len(ncol(mdat)),function(i) mdat[,i]*100/x[i]) # [,1] [,2] [,3] [,4] [,5] #[1,] 7.142857 13.3 30 36.36364 27.8 #[2,] 78.571429 80.0 130 90.90909 55.6 #[3,] 14.285714 20.0 40 45.45455 33.3 #[4,] 71.428571 60.0 80 81.81818 55.6 #[5,] 35.714286 40.0 70 72.72727 22.2 A.K. - Original Message - From: Suparna Mitra suparna.mitra...@gmail.com To: Pascal Oettli kri...@ymail.com Cc: r-help@r-project.org Sent: Tuesday, May 21, 2013 5:19 AM Subject: Re: [R] Using loop for applying function on matrix Thanks for your reply Pascal. I am presently using it with sweep. But here in the question I just gave one simple example. In reality I need several functions to run. Thus I was wondering, if without sweep, I can use loop. Also want to learn how to do this using loop. Any help will be really great, Thanks, Mitra Dr. Suparna Mitra Department of Molecular and Clinical Pharmacology Institute of Translational Medicine University of Liverpool Block A: Waterhouse Buildings 1-5 Brownlow Street Liverpool L69 3GL Tel. +44 (0)151 795 5414 M: +44 (0) 7523228621 Internal ext: 55401 On 21 May 2013 16:29, Pascal Oettli kri...@ymail.com wrote: Hi, ?sweep mdat - matrix(c(1,11,2,10,5,2,12,3,9,**6,3,13,4,8,7,4,10,5,9,8,5,10,** 6,10,4),5,5) x - c(14,15,10,11,18) sweep(mdat*100, 2, x, FUN='/') [,1] [,2] [,3] [,4] [,5] [1,] 7.142857 13.3 30 36.36364 27.8 [2,] 78.571429 80.0 130 90.90909 55.6 [3,] 14.285714 20.0 40 45.45455 33.3 [4,] 71.428571 60.0 80 81.81818 55.6 [5,] 35.714286 40.0 70 72.72727 22.2 Hope this helps, Pascal On 05/21/2013 04:16 PM, Suparna Mitra wrote: Hello R Experts, I need a bit of help in using loop. I have a matrix onto which I need to use several functions. In a simplified form suppose my matrix is mdat [,1] [,2] [,3] [,4] [,5] [1,]12345 [2,] 11 12 13 10 10 [3,]23456 [4,] 10989 10 [5,]56784 And I have one vector x [1] 14 15 10 11 18 Now suppose in simple form I want to create a matrix in which each col value will be divided with consecutive no from vector x. For example column 1 of new vector will be C1=mdat[,1]*100/x[1] C1 [1] 7.142857 78.571429 14.285714 71.428571 35.714286 Now how can I use the loop to have the complete vector at a time? I tried something like this, but in vain. for(i in 1:5) { Data=(mdat[,i]*100/x[i], add=T) } Any help will be really great. Thanks, Mitra [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-help https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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. [[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] inverse for formula transformations on LHS
On Sat, May 18, 2013 at 7:05 AM, Stephen Milborrow mi...@sonic.net wrote: Paul Johnson pauljoh...@gmail.com wrote: m1 - lm(log(y) ~ log(x), data = dat) termplot shows log(y) on the vertical. What if I want y on the vertical? plotmo in the plotmo package has an inverse.func argument, so something like the following might work for you? Thanks, I will read plotmo. I did not hear of that one before. It looks like we have been working on same problem. Take at look at my package rockchalk and run the examples for plotSlopes and plotCurves. Exact same ideas you are thinking about. I don't think it will help in this case because it still relies on the user to know about exp as the inverse of log. When users do predict on glm, it just knows how to put predictions on the response or link scales, and I am aiming for something automagical like that. library(MASS) library(plotmo) log.brain - log(Animals$brain) log.body - log(Animals$body) m2 - lm(log.brain ~ log.body) myplot - function(...) plotmo(m2, do.par=F, nrug=-1, col.resp=2, pch=20,se=1, main=, xlab=log(body), ...) par(mfrow = c(2, 2)) myplot(ylab=log(brain)) myplot(ylab=brain, inverse.func=exp) termplot(m2, se=T, rug=T) # for comparison -- Paul E. Johnson Professor, Political Science Assoc. Director 1541 Lilac Lane, Room 504 Center for Research Methods University of Kansas University of Kansas http://pj.freefaculty.org http://quant.ku.edu [[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] Lattice xyplot multipanels
Dear Rxperts, Sorry about that..forgot to update the numeric part of the multipanel group indicator... Below is the updated code... in addition to getting rid of the curly braces, is there a better way to control the position of panel.text flexibly instead of hardcoding. Thanks, santosh q - data.frame(GL = rep(paste(G,1:3,sep = ),each = 50), G = rep(1:3,each = 50), D = rep(paste(D,1:5,sep = ),each = 30), a = rep(1:15,each = 10), t = rep(seq(10),15), b = round(runif(150,10,20))) q$grp - paste(q$D,q$a,sep = :) q$grp - ordered(q$grp, levels = unique(q$grp)) q$dcol - unlist(sapply(q$D,function(x) switch(x, D1 = orange, D2 = blue, D3 = red, D4 = seagreen, D5 = black))) q2 - q[order(q$G,q$D,q$a,q$t),] ref3 - subset(q2, !duplicated(a)) my.theme = list(strip.border = list(col = NA), strip.background = list(col = NA)) # Of course, I can add a series of $.. I don't have too many $s! xyplot(b ~ t | G,data = q2,groups = grp,type = l,as.table = T, layout = c(3,1), par.strip.text = list(lines = 2), panel = panel.superpose, par.settings = my.theme, panel.groups = function(x = x, y = y, subscripts = subscripts, groups = groups,..., group.number) { require(grid) panel.xyplot(x = x,y = y, subscripts = subscripts,pch = NA,lwd = 1,type = l, col = q2$dcol[subscripts],lty = 1,cex = 0.7) rv0- ref3[ref3$G%in%unique(q2$G)[panel.number()],] panel.text(x=5,y=15,label=unique(rv0$GL)) tids - paste(as.character(unique(rv0$D))) tcols - unique(rv0$dcol) tlty- 1 draw.key(list(columns = 1,between = 1,between.col = 0.5, text = list(lab = tids,col = tcols,cex = 0.8),title = Classes,cex.title = 1.1 ), draw = T,vp = viewport(x = unit(0.8, npc), y = unit(0.9, npc))) }, strip = strip.custom(strip.names = T,strip.levels = T,par.strip.text = list(cex = 1.7,font = 2),bg = 0,var.name = School), xlab = deparse(substitute(x)), ylab = deparse(substitute(y)), main = Overlay of Profiles by Schools and Classes, ) On Tue, May 21, 2013 at 8:21 PM, David Winsemius dwinsem...@comcast.netwrote: On May 21, 2013, at 5:07 PM, Santosh wrote: Dear Rxperts, Ok The curly braces as we talked before,... They appear if the group argument of xyplot function is entered as a numeric value; and don't when the values are letters. At the moment you are offering an example where the group argument is neither numeric, nor character, but rather is a factor-classed variable. I cannot make any curley items appear if I change the argument to numeric. On my machine (a Mac running R 3.0.0 RC) there are no curley braces ... on the strips (or anywhere else.) I do not know what you mean by keep only side 1 and 2 of the borders. It is possible that you want to avoid alternating tick labels and need to find the switch to suppress ticks labels on the upper and right sides of the plotting borders. Try: ?xyplot # scales section scales=list(alternating=c(1,1,1) ), # 1 choice repeated for the number of columns -- David. I just figured how to hide the strip borders...and also control the ticks in different axes... Any suggestions to remove the *curly braces* are highly welcome. q - data.frame(G = rep(paste(G,1:3,sep = ),each = 50), D = rep(paste(D,1:5,sep = ),each = 30), a = rep(1:15,each = 10), t = rep(seq(10),15), b = round(runif(150,10,20))) q$grp - paste(q$D,q$a,sep = :) q$grp - ordered(q$grp, levels = unique(q$grp)) q$dcol - unlist(sapply(q$D,function(x) switch(x, D1 = orange, D2 = blue, D3 = red, D4 = seagreen, D5 = black))) q2 - q[order(q$G,q$D,q$a,q$t),] ref3 - subset(q2, !duplicated(a)) my.theme = list(strip.border = list(col = NA), strip.background = list(col = NA)) # Of course, I can add a series of $.. I don't have too many $s! xyplot(b ~ t | G,data = q2,groups = grp,type = l,as.table = T, layout = c(3,1), par.strip.text = list(lines = 2), panel = panel.superpose, par.settings = my.theme, panel.groups = function(x = x, y = y, subscripts = subscripts, groups = groups,..., group.number) { require(grid) panel.xyplot(x = x,y = y, subscripts = subscripts,pch = NA,lwd = 1,type = l, col = q2$dcol[subscripts],lty = 1,cex = 0.7) rv0- ref3[ref3$G%in%unique(q2$G)[panel.number()],] tids - paste(as.character(unique(rv0$D))) tcols - unique(rv0$dcol) tlty - 1 draw.key(list(columns = 1,between = 1,between.col = 0.5, text = list(lab = tids,col = tcols,cex = 0.8),title = Classes,cex.title = 1.1 ), draw = T,vp = viewport(x = unit(0.8, npc), y = unit(0.9, npc))) }, strip = strip.custom(strip.names = T,strip.levels = T,par.strip.text = list(cex = 1.7,font = 2),bg = 0,var.name = School), xlab = deparse(substitute(x)), ylab = deparse(substitute(y)),