[R] Point estimate from loess contour plot
Hi, I was wondering if anyone knows of a way by which one can estimate values from a contour plot created by using the loess function? I am hoping to use the loess contour plot as a means of interpolation to identify the loess created values at points at pre-defined (x,y) locations. Could anyone point me in the right direction please? Thanks. Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Saving surface3d Output
Hello, Please could someone advise if it's possible to save the graphical output from the surface3d() function? I have tried the dev.copy() function to save as a pdf but an error message says I cannot copy from the null device. Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] slightly off-topic re prcomp()
Hi, I was wondering if anyone could tell me why prcomp() will Invent modes of variation in a PCA on identical replicates of data? I would have expected 50 (or whatever number) of identical replicates to return a null score in such an analysis (or at the least, all variables would share the same PC score). This is not the case and I was wondering could someone point me in the direction of some literature to explain the reason behind this? Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Creating 3D Gaussian Plot
Hello, I requested help a couple of weeks ago creating a dipole field in R but receieved no responses. Eventually I opted to create a 3d sinusoidal plot and concatenate this with its inverse as a means for a next best situation. It seems that this isn't sufficient for my needs and I'm really after creating a continuous 3d gaussian mesh with a positive and negative dipole. Can anyone offer any pointers at all? Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Creating 3D Gaussian Plot
My apologies. With further apologies for the poor graphics, this link demonstrates the sort of 3d mesh which I am hoping to replicate - I would like to be able to replicate a number of these of varying intensity. Demonstrating different levels of potential via the steepness of the slopes. http://maxwell.ucdavis.edu/~electro/potential/images/steep.jpg I then wish to pick a number of grid points at random from the output to perform a further analysis upon. I hope this makes things a little clearer! Again, any help gratefully received, thank you. Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] On Sat, 28 Jan 2006, Duncan Murdoch wrote: On 1/28/2006 8:55 AM, Laura Quinn wrote: Hello, I requested help a couple of weeks ago creating a dipole field in R but receieved no responses. Eventually I opted to create a 3d sinusoidal plot and concatenate this with its inverse as a means for a next best situation. It seems that this isn't sufficient for my needs and I'm really after creating a continuous 3d gaussian mesh with a positive and negative dipole. The names you're using don't mean anything to me; perhaps there just aren't enough atmospheric scientists on the list and that's why you didn't get any response. If you don't get a response this time, you should describe what you want in basic terms, and/or point to examples of it on the web. Duncan Murdoch Can anyone offer any pointers at all? Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Selecting Random Subset From Matrix - retaining indices
Hello, I was wondering whether there is a way to select random samples from a data matrix, retaining the indexing for the rows and columns? I have looked at using the sample() function. Applied directly to my matrix this returns a vector of absolute values but the indices are lost, alternatively I can select a random sample from a length equal to the number of elements in the matrix and then translate each number into an element withing the array but this seems to require a lot of work to ascertain the position and value of each element. Is there a better way of performing this operation? Further to my earlier query I am hoping to pick a random selection of grid points (with (x,y,z) coords) from a 3d map matrix. Thanks in advance. Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] White Noise
I'm wanting to create a series of near-identical matrices via the addition of white noise to my starting matrix. Is there a function within R which will allow me to do this? Thank you Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Creating dipole field
Hello, I'm looking to perform some statistical analysis on some idealised data cases, and was wondering if someone could point me in the direction of how to create a simple dipole field within R? I basically require a rectangular grid with a distinct high/low pressure dipole. Any pointers appreciated, thank you! Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Mental Block with PCA of multivariate time series!
Sorry, I don't think I made myself clear enough with my initial query! I am wishing to investigate the temporal evolution of the pca: if we assume that every 50 rows of my data frame is representitive of, for instance, 1 day of data, I am hoping to automate a process whereby a pca is performed on every 50 rows of data and the loading for PC1 and PC2 for each variable (i.e. each column) is represented as a point on a plot - so a years' data will be represented as two lines (representing PC1 and PC2) on a time series plot for each variable. Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] On Mon, 16 May 2005, Gavin Simpson wrote: Laura Quinn wrote: Please could someone point me in the right direction as I appear to be having a total mental block with fairly basic PCA problem! I have a large dataframe where rows represent independent observations and columns are variables. I am wanting to perform PCA sequentially on blocks of nrows at a time and produce a graphical output of the loadings for the first 2 EOFs for each variable. I'm sure I've performed a very similar routine in the past, but the method is currently escaping me. Any help gratefully received! Hi Laura, data(iris) iris.dat - iris[,1:4] pca.1 - prcomp(iris.dat[1:50, ], scale = TRUE) pca.2 - prcomp(iris.dat[51:100, ], scale = TRUE) pca.3 - prcomp(iris.dat[100:150, ], scale = TRUE) biplot(pca.1) etc... There is a better way of subsetting this data set as the 5th col of iris is a factor and we could use the subset argument to prcomp to do the subsetting without having to know that there are 50 rows per species. Take a look at that argument if you have a variable that defines the blocks for you. Is this what you were after? All the best, Gav -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [T] +44 (0)20 7679 5522 ENSIS Research Fellow [F] +44 (0)20 7679 7565 ENSIS Ltd. ECRC [E] gavin.simpsonATNOSPAMucl.ac.uk UCL Department of Geography [W] http://www.ucl.ac.uk/~ucfagls/cv/ 26 Bedford Way[W] http://www.ucl.ac.uk/~ucfagls/ London. WC1H 0AP. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Fitting Contour to Data Points
Apologies for the mass mailing today! I am attempting to produce a contour plot for phsical data on a map matrix. I have a small number of data points which each has an (x,y) co-ordinate together with a corresponding value which I would like to cvreate a contour plot for. I have tried the following code: contour(data$x,data$y,data$value) but am told: Error in contour.default(data$x, data$y, data$value) : increasing x and y values expected I have re-ordered the matrix so that the x values are increasing, but these do not necessarrily correspond with increasing y values (as this is not a regular grid)...can anyone offer a way around this?? Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Finding Gradient from Contour map
I have a detailed map matrix in R (x,y,z co-ords), and am wishing to calculate the physical gradient at a number of points on the map wrt different axes and averaged over a number of distances (i.e. slope in N-S direction averaged over 10m, 50m, 100m respectively). Is there any function within R which will allow for this? Thanks, Laura Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Conditional Interpolation
I am looking to perform a simple linear interpolation to fill a few small gaps in a large data set. The data set tends to be either continous with one or two gaps in it (where I hope to perform the interpolation), or else it has large chunks of data missing where I'd need to return an NA. Also, I'm wanting to perform this on sequential windows in the data - ie to return daily interpolated data from a year-long data set, or return an NA for a day where insufficienty data is available. This interpolation needs to be performed on a columwise basis (where missing data points in adjacent columns are not related), on a 52000x22 matrix - with windows of 144 each. Can someone please offer some advice, [EMAIL PROTECTED] getting confused with the nesting of my loops! I'm using V2.0.1 on linux. Thanks, Laura Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Reconstructing Datasets
Hi, Is it possible to recreate smoothed data sets in R, by performing a PCA and then reconstructing a data set from say the first 2/3 EOFs? I've had a look in the help pages and don't seem to find anything relevant. Thanks in advance, Laura Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Passing colnames to graphics title
Hi, Just a quick query - if I'm creating a function to produce a number of histograms per page of output (one per column from a matrix), how can I pass the column name of the matrix into the title (or indeed to form part of the x-axis label)? TIA, Laura Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Passing colnames to graphics title
Obviously I have been trying to use the colnames() function! However, when I try to subscript ie: for(i in 1:20){ main=paste(Site:,colnames(i),sep=) } this doesn't work! I thought that as.character(colnames(i)) or substitute(colnames(i)) might work, but to no avail... Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] On Wed, 16 Feb 2005, Uwe Ligges wrote: Laura Quinn wrote: Hi, Just a quick query - if I'm creating a function to produce a number of histograms per page of output (one per column from a matrix), how can I pass the column name of the matrix into the title (or indeed to form part of the x-axis label)? By extracting them using colnames()? Uwe Ligges TIA, Laura Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Passing colnames to graphics title
Wonderful, thank you very much! Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] On Wed, 16 Feb 2005, Dimitris Rizopoulos wrote: a simple thing to do is: mat - matrix(...) # your matrix nams - dimnames(mat)[[2]] for(j in 1:ncol(mat)) hist(mat[,j], main=nams[j]) # or hist(mat[,j], xlab=paste(..., nams[j], ...)) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm - Original Message - From: Laura Quinn [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Wednesday, February 16, 2005 2:56 PM Subject: [R] Passing colnames to graphics title Hi, Just a quick query - if I'm creating a function to produce a number of histograms per page of output (one per column from a matrix), how can I pass the column name of the matrix into the title (or indeed to form part of the x-axis label)? TIA, Laura Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Interpretation of PC loadings
Hello, Following on from a paper by Ludwig, Horel and Whiteman in 2004, I have been using PCA to identify surface wind patterns. In the paper they approach the problem using the real vector approach, that is, they create paired (u,v) vectors for the wind data, in effect artificially doubling the number of variables, then perform the pca, subsequently repairing the output and plotting the paired site loadings onto a geographical map and interpreting the plotted vectors as dominant wind flow patterns. I have followed their approach, using prcomp() in R, using retx=FALSE and plotting the pairings from the pca$rotation output. When I replot these vectors onto a map it seems that a spurious angle has been introduced into the data (ie the data seem to be angled at approx 45 degrees from where I would expect them to lie). Due to this I've also tried switching retx=TRUE and plotting pca$x though the output seems quite different. I have looked at the help section for prcomp but it doesn't seem very explicit in it's explanation (ie does $x take the same form as $rotation - will it be analagous to plot them in the same fashion for instance?) Could someone advise me which method will be more reliable in terms of revealing underlying flow direction when remapping onto the original (x,y) map? Any advice most welcome! Thank you, Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Runnning R remotely
Hi, I was wondering if anyone might be able to help. I am trying to run R on a remote machine, part of the model run I am attempting writes an external file output as a png (about 48 iterations per model run). I am running R 1.9.1 on SuSe9.0, and am accessing this via ssh from a Debian machine. Initially I used the command ssh -X IP.address and whilst I was able to run the model successfully the model run was extremely slow (which I could not understand as the output was being written to the remote machine), but tried to log in again, this time without the X windows facility and found that I couldn't run the model: Error in X11(paste(png::, filename, sep = ), width, height, pointsize, : unable to start device PNG In addition: Warning message: unable to open connection to X11 display`' Could somebody please advise a way around this? Thanks in advance, Laura Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Runnning R remotely
I wasn't aware that it was possible to use postscript in the same fashion as png, eg: png(file,width=x,height=y,) image(map) text(text) title(title) box() dev.off() As there are a large number of iterations png has been working nicely (when not working remotely!), especially as it has proven easy to convery into gifs and then into movie gifs. Could anyone suggest an alternative approach in this case? TIA, Laura Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] On Wed, 2 Feb 2005, Jean Eid wrote: Why do you use png? I think that yu need X11 to save a png file. why not use a postscript? This is what ?png says R can be compiled without support for either or both of these devices: this will be reported if you attempt to use them on a system where they are not supported. They will not be available if R has been started with --gui=none (and will give a different error message), and they may not be usable unless the X11 display is available to the owner of the R process. In addition I think the only thing slowing the machine is png. Jean On Wed, 2 Feb 2005, Laura Quinn wrote: Hi, I was wondering if anyone might be able to help. I am trying to run R on a remote machine, part of the model run I am attempting writes an external file output as a png (about 48 iterations per model run). I am running R 1.9.1 on SuSe9.0, and am accessing this via ssh from a Debian machine. Initially I used the command ssh -X IP.address and whilst I was able to run the model successfully the model run was extremely slow (which I could not understand as the output was being written to the remote machine), but tried to log in again, this time without the X windows facility and found that I couldn't run the model: Error in X11(paste(png::, filename, sep = ), width, height, pointsize, : unable to start device PNG In addition: Warning message: unable to open connection to X11 display`' Could somebody please advise a way around this? Thanks in advance, Laura Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Runnning R remotely
Aha, of course! Thanks for your help - 10 minutes down to 5 seconds, superb. Laura Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] On Wed, 2 Feb 2005, Jean Eid wrote: look intp ?postscript. these is nothingin your code below that you cannot do in postscript. to convert the images you can use convert (this is ImageMagick) on your machine. On my debian machine it was preinstalled if not apt-get imagemagick should do it. After this you can use convert blbla.eps blabla.gif Jean On Wed, 2 Feb 2005, Laura Quinn wrote: I wasn't aware that it was possible to use postscript in the same fashion as png, eg: png(file,width=x,height=y,) image(map) text(text) title(title) box() dev.off() As there are a large number of iterations png has been working nicely (when not working remotely!), especially as it has proven easy to convery into gifs and then into movie gifs. Could anyone suggest an alternative approach in this case? TIA, Laura Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] On Wed, 2 Feb 2005, Jean Eid wrote: Why do you use png? I think that yu need X11 to save a png file. why not use a postscript? This is what ?png says R can be compiled without support for either or both of these devices: this will be reported if you attempt to use them on a system where they are not supported. They will not be available if R has been started with --gui=none (and will give a different error message), and they may not be usable unless the X11 display is available to the owner of the R process. In addition I think the only thing slowing the machine is png. Jean On Wed, 2 Feb 2005, Laura Quinn wrote: Hi, I was wondering if anyone might be able to help. I am trying to run R on a remote machine, part of the model run I am attempting writes an external file output as a png (about 48 iterations per model run). I am running R 1.9.1 on SuSe9.0, and am accessing this via ssh from a Debian machine. Initially I used the command ssh -X IP.address and whilst I was able to run the model successfully the model run was extremely slow (which I could not understand as the output was being written to the remote machine), but tried to log in again, this time without the X windows facility and found that I couldn't run the model: Error in X11(paste(png::, filename, sep = ), width, height, pointsize, : unable to start device PNG In addition: Warning message: unable to open connection to X11 display`' Could somebody please advise a way around this? Thanks in advance, Laura Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Exporting to file: passing source name to file name in loop
Hi, I'm having a mental block as to how I can automatically assign filenames to the output of the following code. I am wishing to create a separate .png file for every image created, each of them having a sequential filename ie sourcefile_index.png so that I can create a movie from them. Please could someone tell me where I am going wrong? the following code works fine and outputs to screen: fun_pca_vector_movie_plot-function(x,y,z,t){ zz=seq(1,(nrow(x)-t),by=t);jj=seq(t+1,(nrow(x)),by=t) for(i in seq(along=zz)){ pca-prcomp(x[zz[i]:jj[i],], retx=T, center=T,scale=T) { par(mfrow=c(1,z)) for(i in 1:z){ image(east,north,t(map.matrix),col=my.colors,axes=T, xlab=,ylab=) text(y[,3],y[,2],labels=as.character(y[,1])) title(paste(Component,i,Step:)) arrows(y[,3],y[,2],(y[,3]+50*(pca$rotation[i,1:(ncol(x)/2)])), (y[,2]+50*(pca$rotation[i,((ncol(x)/2)+1):(ncol(x))])), angle=30,length=0.05,code=2) } box() } }} but when I try to save to file as follows it doesn't work: fun_pca_vector_movie_plot-function(x,y,z,t){ zz=seq(1,(nrow(x)-t),by=t);jj=seq(t+1,(nrow(x)),by=t) for(i in seq(along=zz)){ pca-prcomp(x[zz[i]:jj[i],], retx=T, center=T,scale=T) { par(mfrow=c(1,z)) for(i in 1:z){ plot.new() png(file=(paste(x.,i,_,zz,.png,sep=)),width=240,height=240) image(east,north,t(map.matrix),col=my.colors,axes=T, xlab=,ylab=) text(y[,3],y[,2],labels=as.character(y[,1])) title(paste(Component,i,Step:)) arrows(y[,3],y[,2],(y[,3]+50*(pca$rotation[i,1:(ncol(x)/2)])), (y[,2]+50*(pca$rotation[i,((ncol(x)/2)+1):(ncol(x))])), angle=30,length=0.05,code=2) dev.off() } box() } }} many thanks in advance! Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Exporting to file: passing source name to file name in loop
Apologies - Sunday afternoon coding, not my forte. I am trying to pass the name of my input variable x (my.data) into the name of my output file, and am wanting to combine this with a count value. I hope that this code is a little more readable (though I seem to be having problems pasting the formatting into my email composition): fun_pca_vector_movie_plot - function (x,y,z,t) { zz=seq(1,(nrow(x)-t),by=t);jj=seq(t+1,(nrow(x)),by=t) for(i in seq(along=zz)){ plot.new() png(file=(paste(as.character(x),.,i,.png,sep=)),width=240,height=240) pca-prcomp(x[zz[i]:jj[i],], retx=T, center=T,scale=T) { par(mfrow=c(1,z)) for(i in 1:z){ image(east,north,t(map.matrix),col=my.colors,axes=T, xlab=,ylab=) text(y[,3],y[,2],labels=as.character(y[,1])) title(paste(Component,i,Step:)) arrows(y[,3],y[,2],(y[,3]+50*(pca$rotation[i,1:(ncol(x)/2)])), (y[,2]+50*(pca$rotation[i,((ncol(x)/2)+1):(ncol(x))])), angle=30,length=0.05,code=2) } box() } dev.off() } } I get a syntax error relating to the as.character(x) part of the file name - if I remove this, the code works fine for the rest of the file extension. I have tried deparse(x) but this returns a file extension of the following nature: structure(list(f1 = c(5.56358661715647, 6.10364037003176, 6.24040147126807, .10.png Thanks, Laura Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Slope of surface
Hi, Is there a neat way of working out the slope of a flat surface in R? Given (x,y,z) co-ordinates of the four corners of a square, is there a function which will allow me to calculate the mean slope of the surface in a given direction? Thanks in advance.. Laura Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Performing Analysis on Subset of External data
Hi, I want to perform some analysis on subsets of huge data files. There are 20 of the files and I want to select the same subsets of each one (each subset is a chunk of 1500 or so consecutive rows from several million). To save time and processing power is there a method to tell R to *only* read in these rows, rather than reading in the entire dataset then selecting subsets and deleting the extraneous data? This method takes a rather silly amount of time and results in memory problems. I am using R 1.9.0 on SuSe 9.0 Thanks in advance! Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Further png() question
Ok, I have reinstalled R-1.9.0 and this appears to have fixed the problems I was having with png(). However, I have a further question regarding png() Is it possible to pass a par() argument to the png() command? I am wanting to produce 4 plots per object, which I normally acheive on an X window by par(mfrow=c(1,4)). I have tried calling a new plot and setting par in this way but this has no bearing when I call png(). Any suggestions? Thanks in advance, Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Further png() question
Thanks all! It appears I just had the par in the wrong place in my loop. Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] On Tue, 7 Sep 2004, Petr Pikal wrote: On 7 Sep 2004 at 15:37, Laura Quinn wrote: Ok, I have reinstalled R-1.9.0 and this appears to have fixed the problems I was having with png(). However, I have a further question regarding png() Is it possible to pass a par() argument to the png() command? I am wanting to produce 4 plots per object, which I normally acheive on an X window by par(mfrow=c(1,4)). I have tried calling a new plot and setting par in this way but this has no bearing when I call png(). Hi png(myplot.png, 800,800) par(mfrow=c(1,4)) for (i in 1:4) boxplot(rnorm(10)*i) dev.off() seems to work or seems to produce 4 graphs on 1 png device. Is this what you want? Cheers Petr Any suggestions? Thanks in advance, Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Petr Pikal [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Problems with png()
I am trying to save a series of plots as .png files by using png(file=myfile.png,bg=transparent) dev.off() for each image plot I produce. Unfortunately when I have tried this I am unable to open the files, and am told they are corrupted. I have tried to use the jpeg() function but have the same problem. The only way I have managed to export a graphic successfully is as dev.copy2eps. Aside from producing unwieldy files, this is also unhelpful as [EMAIL PROTECTED] hoping to create a movie of the images via ImageMagick. Any suggestions? Thanks in advance, Laura Quinn Institute of Atmospheric Science School of the Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Problems with png()
Sorry! Tried to save the .png from both R-1.9.1 and R-1.8.0 to no avail. I am running R-1.9.1 on SusE 9.0, and R-1.8.0 on Debian. I have tried to view the images with Gimp and Kview (on both systems), to no avail. Laura Quinn Institute of Atmospheric Science School of the Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] On Mon, 6 Sep 2004, Uwe Ligges wrote: Laura Quinn wrote: I am trying to save a series of plots as .png files by using png(file=myfile.png,bg=transparent) dev.off() More details please, we cannot help otherwise. At least version of R, operating system, and version of libpng, as well as the program that told you the file is corrupted ... Uwe Ligges for each image plot I produce. Unfortunately when I have tried this I am unable to open the files, and am told they are corrupted. I have tried to use the jpeg() function but have the same problem. The only way I have managed to export a graphic successfully is as dev.copy2eps. Aside from producing unwieldy files, this is also unhelpful as [EMAIL PROTECTED] hoping to create a movie of the images via ImageMagick. Any suggestions? Thanks in advance, Laura Quinn Institute of Atmospheric Science School of the Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Problems with png()
A windows machine?? If you could suggest where I might get my hands on one... AFAIK I'm running the code interactively. Laura Quinn Institute of Atmospheric Science School of the Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] On Mon, 6 Sep 2004, Adaikalavan Ramasamy wrote: Try running the codes on a windows machine just to rule out any code-related errors. Also are you running the codes interactively or in the background ? Regards, Adai On Mon, 2004-09-06 at 11:05, Laura Quinn wrote: On Mon, 6 Sep 2004, Barry Rowlingson wrote: Laura Quinn wrote: I am trying to save a series of plots as .png files by using png(file=myfile.png,bg=transparent) dev.off() for each image plot I produce. Unfortunately when I have tried this I am unable to open the files, and am told they are corrupted. I have tried to use the jpeg() function but have the same problem. The only way I have managed to export a graphic successfully is as dev.copy2eps. Aside from producing unwieldy files, this is also unhelpful as [EMAIL PROTECTED] hoping to create a movie of the images via ImageMagick. This sounds a bit obvious, but are you doing your plot commands _between_ the png() call and the dev.off() call? Try: png(file=foo.png) plot(1:10) dev.off() What version/platform are you using? Yes, I have been using the above call to no avail. I'd be suprised if my libpng wasn't up-to-date on SuSe 9.0, but I'm not sure how to check which version I have? Laura Barry __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Applying function to lots of separate data sets
I have a total mental block and can't find my way around this seemingly simple problem: I have created a function such that: my_answer_1=myfuntion(my_input_1) I am wanting to perform this calculation over a large number of datasets, but am having real difficulty calling and assigning - i think the problem les in the fact that I need to paste for call and assign. this is my best attempt so far..I can't seem to find a way around this... for(i in 1:50) eval(parse(text=paste(my_answer_,i, -myfunction(text=paste(my_input_,i,sep=)),sep=))) can someone please point out where i am going wrong? Thanks in advance.. Laura Quinn Institute of Atmospheric Science School of the Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Applying function to lots of separate data sets
Thank you - I have followed your advice but it then begs a further question! I am wanting to plot elements from within the list, but I don't know how to subscript down so far, I want to plot values from rows(1:10) within, for instance, mylist[[20]], for columns (1:5). how can I define these?? Laura Quinn Institute of Atmospheric Science School of the Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] On Sun, 5 Sep 2004, Duncan Murdoch wrote: On Mon, 6 Sep 2004 01:14:40 +0100 (BST), Laura Quinn [EMAIL PROTECTED] wrote: I have a total mental block and can't find my way around this seemingly simple problem: I have created a function such that: my_answer_1=myfuntion(my_input_1) I am wanting to perform this calculation over a large number of datasets, but am having real difficulty calling and assigning - i think the problem les in the fact that I need to paste for call and assign. this is my best attempt so far..I can't seem to find a way around this... for(i in 1:50) eval(parse(text=paste(my_answer_,i, -myfunction(text=paste(my_input_,i,sep=)),sep=))) can someone please point out where i am going wrong? Using paste() to construct variable names is overdone. It's much better to put all of your data into a list in one object, then just use lapply() to apply a function to each element of the list. For examples, see ?lapply. Duncan Murdoch __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Applying function to lots of separate data sets
Aha, apologies...I have just answered my own question - thanks for showing me the light with lists, lots of time saving ahead!! Laura Laura Quinn Institute of Atmospheric Science School of the Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] On Sun, 5 Sep 2004, Duncan Murdoch wrote: On Mon, 6 Sep 2004 01:14:40 +0100 (BST), Laura Quinn [EMAIL PROTECTED] wrote: I have a total mental block and can't find my way around this seemingly simple problem: I have created a function such that: my_answer_1=myfuntion(my_input_1) I am wanting to perform this calculation over a large number of datasets, but am having real difficulty calling and assigning - i think the problem les in the fact that I need to paste for call and assign. this is my best attempt so far..I can't seem to find a way around this... for(i in 1:50) eval(parse(text=paste(my_answer_,i, -myfunction(text=paste(my_input_,i,sep=)),sep=))) can someone please point out where i am going wrong? Using paste() to construct variable names is overdone. It's much better to put all of your data into a list in one object, then just use lapply() to apply a function to each element of the list. For examples, see ?lapply. Duncan Murdoch __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Mapping PCA loadings on to map
Hello all, I have performed PCA on stacked wind vector data for 20 different spatial locations. In this case I therefore am in effect working out a PCA for 40 different stations (2 paired pieces of information [ie u and v vector information] for each station), so have 40 PCs. In my previous PCA (for none vector data) i have plotted the PC loadings onto a map of the area of concern, and would like to represent the results of this PCA in a similar way. My previous code looks like this: east-sort(unique(alt$east)) north-sort(unique(alt$north)) map.matrix-matrix(alt$Alt,nrow=length(north),byrow=TRUE) site.data-read.table(siteinfo.dat,header=TRUE) ts.data-read.table(met.dat,header=TRUE) library(mva) met.pca-prcomp(ts.data,retx=FALSE,scale=TRUE,center=TRUE) scale-2 for(i in 1:4){ image(east,north,t(map.matrix),col=terrain.colors(50),axes=TRUE, xlab=,ylab=) text(site.data$east,site.data$north,labels=as.character(site.data$site)) pc-met.pca$rotation[,i] pc.pos-(pc0) if(any(pc.pos)){ symbols(site.data$east[pc.pos],site.data$north[pc.pos], circles=scale*pc[pc.pos],lwd=2,fg=red,inches=FALSE,add=TRUE)} if(any(!pc.pos)){ symbols(site.data$east[!pc.pos],site.data$north[!pc.pos], circles=-scale*pc[!pc.pos],lwd=2,fg=blue,inches=FALSE,add=TRUE)} box() } My problem is, how can i adjust this code so that I get a pair of loadings at each site? I've been having real problems trying to sort the subscripting out, as i need to be able to recognise the PC loadings as pairs, (so have made a further u and v subscript to each station name before the analysis) but then I they aren't in the same format as needed to plot onto the map. I guess there is probably a very obvious way around this and would be extremely grateful if anyone could help me out! Also, it occurs to me that another way of representing this information is by using the arrows() function to add a vector to the map - but again this relies on my subscripting problem TIA, Laura Laura Quinn Institute of Atmospheric Science School of the Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] Stacking Vectors/Dataframes
As our IT man is currently on holiday I am not able to upgrade to version 1.9.0(or 1.9.1) at the moment, and I see that the gregmisc library will not work on earlier versions (I am using 1.8.0). Does anyone have any other suggestions how I might be able to acheive this? Thank you Laura Quinn Institute of Atmospheric Science School of the Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] On Sun, 15 Aug 2004, Liaw, Andy wrote: I believe interleave() in the `gregmisc' package can do what you want. Cheers, Andy From: Laura Quinn Hello, Is there a simple way of stacking/merging two dataframes in R? I want to stack them piece-wise, not simply add one whole dataframe to the bottom of the other. I want to create as follows: x.frame: aX1 bX1 cX1 ... zX1 aX2 bX2 cX2 ... zX2 ... ... ... ... ... aX99 bX99 cX99 ... zX99 y.frame: aY1 bY1 cY1 ... zY1 aY2 bY2 cY2 ... zY2 ... ... ... ... ... aY99 bY99 cY99 ... zY99 new.frame: aX1 bX1 cX1 ... zX1 aY1 bY1 cY1 ... zY1 aX2 bX2 cX2 ... zX2 aY2 bY2 cY2 ... tY2 ... ... ... ... ... aX99 bX99 cX99 ... tX99 aY99 bY99 cY99 ... tY99 I have tried to use a for loop (simply assigning and also with rbind) to do this but am having difficulty correctly assigning the destination in the new dataframe. Can anyone offer a quick and easy way of doing this (or even a long winded one if it works!!) Thank you in advance, Laura Quinn Institute of Atmospheric Science School of the Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Notice: This e-mail message, together with any attachments, contains information of Merck Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp Dohme or MSD and in Japan, as Banyu) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system. -- __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Stacking Vectors/Dataframes
Hello, Is there a simple way of stacking/merging two dataframes in R? I want to stack them piece-wise, not simply add one whole dataframe to the bottom of the other. I want to create as follows: x.frame: aX1 bX1 cX1 ... zX1 aX2 bX2 cX2 ... zX2 ... ... ... ... ... aX99 bX99 cX99 ... zX99 y.frame: aY1 bY1 cY1 ... zY1 aY2 bY2 cY2 ... zY2 ... ... ... ... ... aY99 bY99 cY99 ... zY99 new.frame: aX1 bX1 cX1 ... zX1 aY1 bY1 cY1 ... zY1 aX2 bX2 cX2 ... zX2 aY2 bY2 cY2 ... tY2 ... ... ... ... ... aX99 bX99 cX99 ... tX99 aY99 bY99 cY99 ... tY99 I have tried to use a for loop (simply assigning and also with rbind) to do this but am having difficulty correctly assigning the destination in the new dataframe. Can anyone offer a quick and easy way of doing this (or even a long winded one if it works!!) Thank you in advance, Laura Quinn Institute of Atmospheric Science School of the Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Vector to complex scalar
Is there an R function to convert vectors into complex scalars? Thanks Laura Quinn Institute of Atmospheric Science School of the Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] PCA of vectors
Hello, Is it possible to perform PCA using princomp or prcomp on two-component wind data - ie wind vectors? If not, is anyone able to advise on a suitable methodology for acheiving this? My data is a time series of observations taken at different locations. Thank you in advance for any hints! Laura Laura Quinn Institute of Atmospheric Science School of the Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] further problems with arima..
Sorry to keep quizzing the r-helpers but I'm having real difficulty with arima. I am happy that i have chosen the best fitting arima model for my data,(in this case arima(1,1,1) but when i use the predict function the forecast damps to a constant value after just two or three values, and from a time series of almost 3000 values i am left with only a couple of predicted values. I have tried aggregating my data to condense finely spaced time points into larger clumps but to no avail. please can someone offer a little advise on how i might improve on this? thank you, Laura Quinn Institute of Atmospheric Science School of the Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Problem with predict arima
I have fitted an arima(0,0,2) model to my data, and am trying to plot a forecast for the next 15 time steps, but each time i try I am given the following error message: Error in .cbind.ts(list(...), makeNames(...), dframe = dframe, union = TRUE) : non-time series not of the correct length I am calculating as follows: my.arima-arima(my.list,order=c(0,0,2)) my.forecast-predict(my.arima,15) ts.plot(my.list,my.forecast$pred,my.forecast$pred+2*my.forecast$se, myforecast$pred-2*my.forecast$se) my.list has 1 column and 2880 rows...I don't understand why I am getting this error message - any advice? Thanks, Laura Laura Quinn Institute of Atmospheric Science School of the Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Contour plots of PCA loadings
Hi, I was wondering if there is a way of plotting smoothed contours of PCA loadings onto a map. At the moment I have the loadings plotted as positive/negative (red/blue) scaled circles centred around where the physical stations are on a map - but I was wondering if there is a nicer way of plotting this data, perhaps as contours of regions of influence or somesuch? Any suggestions would be gratefully received! Thank you in advance, Laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] multiple plots for data sets of inconsistent size
I am wanting to plot pca loadings onto sites superimposed on a contour map. There are a maximum of 20 sites at which loadings might appear - however due to the nature of my data, missing data has meant that some stations have not been included in some of the pca. For example, I am performing pca for 5 different variables at 20 different sites for a number of different time intervals and want to perform a cross comparison to see where key trends lie. Where data is not available for any particular station at any given time interval I am still keen to analyse the principal components on the others. I have been using the following code to produce the plots I want: for (i in 1:4) { image(east.grid,north.grid,t(map.matrix),col=my.colors, axes=TRUE,xlab=,ylab=) text(stations$x.axis,stations$y.axis,labels=as.character(stations$station)) title(paste(Component,i)) pc - p6.5am.pca$rotation[,i] pc.pos - (pc 0) if (any(pc.pos)) { symbols(stations$x.axis[pc.pos],stations$y.axis[pc.pos], circles=scale*pc[pc.pos],lwd=2,fg=red,inches=FALSE,add=TRUE) } if (any(!pc.pos)) { symbols(stations$x.axis[!pc.pos],stations$y.axis[!pc.pos], circles=-scale*pc[!pc.pos],lwd=2,lty=2,fg=blue,inches=FALSE, add=TRUE) } box() } My problem is this - due to the large number of plots required I would like to be able to batch process the results, but in the case of applying the above code when one (or more) station(s) is missing from the pca I get an error message as the x and y lengths differ. Is there a way I can get the code to simply return a zero loading at a site if it hasn't been included in the calculation of the pca? (or is there another better way around this problem?) I hope that this question makes some sense. Any ideas? Thanks, laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] PCA and AR on circular data
Could anyone advise the best method of performing PCA and/or AR modelling on circular data? Until now I have been working with vectors (speed*direction), but am now wanting to look purely at the directional aspect. Thanks in advance.. Laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] dev() error
I don't know what I have done!! When I try to invoke a display function via plot(), image() or whatever, my X11 window doesn't appear. I have tried to type X11() but the following error message is displayed: x11() Error in X11(display, width, height, pointsize, gamma, colortype, maxcubesize, : unable to start device X11 In addition: Warning message: unable to open connection to X11 display`' I have tried dev.cur() and dev.list() but these suggest that only my null device is active and I am unsure how to activate my X11 device by any other means! I'm sure this is a stupid question but could anyone please help? Thanks in advance.. Laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] dev() error
No nothing like that, I am running two parallel R sessions (something I often do) and the other one is working absolutely fine - I am working directly from my network, not via ssh, and certainly am not privvy to any super user passwords! On Wed, 16 Jun 2004, Uwe Ligges wrote: Laura Quinn wrote: I don't know what I have done!! When I try to invoke a display function via plot(), image() or whatever, my X11 window doesn't appear. I have tried to type X11() but the following error message is displayed: x11() Error in X11(display, width, height, pointsize, gamma, colortype, maxcubesize, : unable to start device X11 In addition: Warning message: unable to open connection to X11 display`' I guess you have logged via ssh by not allowing X forwarding, or you ave changed your UID using su or something like that... Has R been compiled with X11 support? Can you start any other program that uses X? Uwe Ligges I have tried dev.cur() and dev.list() but these suggest that only my null device is active and I am unsure how to activate my X11 device by any other means! I'm sure this is a stupid question but could anyone please help? Thanks in advance.. Laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] dev() error
Thank you for all your help! I have finally solved the issue by simply externally saving all my R session info and restarting the session from another place, it seems to be working this time. It seems I was getting my pathways a little mixed up. Thanks again. Laura On Wed, 16 Jun 2004 [EMAIL PROTECTED] wrote: On 16-Jun-04 Laura Quinn wrote: No nothing like that, I am running two parallel R sessions (something I often do) and the other one is working absolutely fine - I am working directly from my network, not via ssh, and certainly am not privvy to any super user passwords! It looks as though you may be logged in to two different machines for your two R sessions, in which case it looks as though one of them has ascertained the X display for your machine (i.e. the one you are sitting at), and the other has not. (Indeed, the one that works might be your machine itself, in which case it knows anyway). Test: 1. In the xterm logged in to the machine which works, before starting R, enter echo $DISPLAY 2. On the xterm logged in to the machine which does not work, before starting R, enter echo $DISPLAY For example, I'm using machine compo here on which is an xterm logged in to another machine called brandy. So, in this xterm, [EMAIL PROTECTED]:~ echo $DISPLAY compo.fort.knox.uk:0.0 showing that brandy knows the X display destination for compo. So, when you do (1) above, you should see something similar. If I'm right, when you do (2) above, you will probably just get a blank response. If that happens, then you have to see about getting the (2) machine to set the DISPLAY variable when you log in to it. This can be tricky: I've known cases where the cause was quite deeply hidden. Basically, the information for the DISPLAY variable is ascertained by a script which is run when you log in to the remote machine, which may be a sub-script of some other script, ... I hope this helps, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 167 1972 Date: 16-Jun-04 Time: 11:58:12 -- XFMail -- __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] apply/looping query
I have several large matrices each having perhaps one or two data points missing. For instance one point in 2881 is missing. As I want to perform various analyses on these matrices I feel it is not unreasonable to linearly interpolate over the missing points. I want to basically fill in the gaps of the original matrix - the following piece of code doesn't work and i'm not sure where i'm going wrong: x=1:2881 my.new.matrix-matrix(nrow=2881,ncol=20) for(i in 1:20){ my.new.matrix[[i]]-approx(x,my.matrix[,i],n=2881) } the error message says: Error: more elements supplied than there are to replace where am I going wrong?? Thanks in advance.. Laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] overlaying text() onto image() or filled.contour()
I am trying to add some markers onto a contour map image I have created, by using the text() function when I have already produced the map using either image() or filled.contour(). For some reason the points appear to be shifted considerably to the right of where they should be appearing, despite me using exactly the same co-ordinate systems for both. This offset is also dependent on the aspect ratio I use. The map I am looking at is around 3.5x larger in height than width and I need to maximise this in an X window. If I simply use asp=1 the map is pretty unreadable, is there a way I can drastically reduce the margin sizes perhaps? The par() commands [EMAIL PROTECTED] tried haven;t made an appreciable difference - and i'M still very puzzled as to why my data markers are appearing in the wrong place...any suggestions? Thanks, Laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] filled.contour - color palette so z=0 ONLY is blue
I am trying to create a topographic map of an island - the filled.contour function works fine except i am experiencing difficulty trying to represent the sea properly. Basically I want the default colour blue for any instance where z=0, if I simply use the default topo.color I get shades of blue for z values up to 220 metres. Is there a way in which I can specify terrain.color for all values of z0 but blue for z=0 - or is there another way of acheiving this simply? Thanks, Laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Adding key to simple plot() function
I am generating a simple x,y plot to show geographical positions where point data has been taken. Rather than plot a graph and lay points on top I've opted to generate the map from the point data, ie plot(-x,-y). This works fine, though I am wanting to label each point 1:20 and have a key alongside - is this possible without getting into trellis plots? I have very limited time available so don't want to embark on trellis functions which I've never used before.. Also, my x,y labels currently have a negative sign in front of them which I'd like to remove, but if I negate the labels they no longer fit on the graph as my data points are -x and -y... Any suggestions? Thanks, Laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] multi read.table function and read.table function not accepting col.names
I am using R-1.8.0 on Debian. I'm trying to read in a large table (1441*16) which currently has no header line. I have set up a list of column names which is 16 names long. when i try the following: myfiledate.01-read.table(filenamedate.01,row.names=NULL,col.names=names,na.strings=-999.00) I am returned with an error saying there are more columsh than column names. I am sure I have done this successfully in the past so can't understand the problem. I have done the read.table function without specifying col.names and it works fine and i end up with a 1441*16 data.frame. Also as I have several hundred of these tables to read into R, all having the same dimension and all having the same column names, is it possible to automate R so they will all be read in at once - each table represents a different days worth of data. Thanks Laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] multi read.table function and read.table function not accepting col.names
Thank you for your earlier help, I have a couple of related questions. With the lapply function, is it still possible to assign column names to each column of every data frame, again I have tried and it doesn't seem to like it.. and is it also possible to assign names to each data frame when I do lapply rather than each one being a subset of a larger frame (I don't seem to be able to attach these as individual objects). Thanks again, Laura On Wed, 26 May 2004, Wolski wrote: Hi! 1. assuning that names is the vector with the names. try col.names=names instead of names 2. Several ways a) use lapply(listwithpathstofiles,read.tabel,remaining, options) //u will get it stored in the list. b) or use for loop and append to list. mylist-list() c) or look ?assing to generate several hundred objects in the envrovment. Sincerely Eryk *** REPLY SEPARATOR *** On 5/26/2004 at 12:51 PM Laura Quinn wrote: I am using R-1.8.0 on Debian. I'm trying to read in a large table (1441*16) which currently has no header line. I have set up a list of column names which is 16 names long. when i try the following: myfiledate.01-read.table(filenamedate.01,row.names=NULL,col.names=names,na.strings=-999.00) I am returned with an error saying there are more columsh than column names. I am sure I have done this successfully in the past so can't understand the problem. I have done the read.table function without specifying col.names and it works fine and i end up with a 1441*16 data.frame. Also as I have several hundred of these tables to read into R, all having the same dimension and all having the same column names, is it possible to automate R so they will all be read in at once - each table represents a different days worth of data. Thanks Laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Dipl. bio-chem. Eryk Witold Wolski@MPI-Moleculare Genetic Ihnestrasse 63-73 14195 Berlin 'v' tel: 0049-30-83875219 / \ mail: [EMAIL PROTECTED]---W-Whttp://www.molgen.mpg.de/~wolski __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Problem with filled.contour/image
Quick question - I am having problems creating an orographic image (similar to volcano example). I have created a map matrix with 3 columns and over 2million rows. I have created the matrix as follows: map-read.table(map.dat,header=TRUE) long.grid-sort(unique(map$long) lat.grid-sort(unique(map$lat) map.matrix-matrix(map$height,nrow=length(lat.grid),byrow=TRUE) The problem is when I type the filled.contour command I get the following error message: filled.contour(long.grid,lat.grid,t(map.matrix),color=terrain.colors) Error in filledcontour(as.double(x), as.double(y), z, as.double(levels), : dimension mismatch and when I try using the image function: image(long.grid,lat.grid,t(map.matrix),col=terrain.colors(50),axes=TRUE) I get the following error: Error in image.default(long.grid, lat.grid, t(map.matrix), col = terrain.colors(50), : dimensions of z are not length(x)(+1) times length(y)(+1) Each long and lat point are unique and have a corresponding height component so these messages don't make any sense to me - can anyone please advise? Thanks Laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] prcomp - error code 18
I am attempting to perform a pca on a data frame of dimension 5000x19, but when I execute pcapres-prcomp(pres,center=TRUE) the following error message is returned: Error in La.svd(x, nu, nv, method) : error code 18 from Lapack routine dgesdd Where am I going wrong? I am running R-1.8.0 on Debian. Regards, Laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Returning data in matrix form
I am trying to perform the following calculation for a very large time series data set: x-unit(length*data.frame.a*data.frame.b,cm) data.frame.a and data.frame.b are of the same dimension, and I wish to perform the calculation in one step so that x is returned as a matrix/data.frame of equal dimension. I have tried a couple of methods for this, (subsetting data.frame.a and data.frame.b and performing the calculation on a column by column basis for instance, and trying to loop a function over column data), but each time I am returned with a list for x rather than a data frame. Sorry if this is a stupid question, I have looked through some R literature but don't seem able to find the answer. Thank you for any help. Laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Saving jpg of plot with grid.arrows
I am having problems exporting a plot to a jpg file. I am first setting up a basic plot, and then opening up a viewport and overlaying grid.arrows onto the plot - I don't seem able to save this plot with the overlaid arrows to a file, can anyone offer any advice? I am using R-1.8.0 on Debian Linux. Thank you in advance, Laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Non-standard axis plotting
I am trying to plot positions on a grid where the x and y axis equate to longitudinal and latitudinal co-prdinates respectively. As these co-ordinates are southings and westings, i need the origin of my graph to contain the two highest values of each co0ordinate, with the values decreasing in both respects along both axes - I cannot seem to find any function within r to allow me to do this. Also, how can i avoid r automatically rescaling my data - my data points are not evenly clustered and I want the scalings on the x and y axes to be the same, so that they represent a true picture of the spatial scattering. R rescales the data to fit the best square in each case - misrepresenting the scaling of my data. I have looked at all the options within par() and axis() and nothing here appears appropriate. Thanks in advance.. Laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Visualising Moving Vectors
I am wanting to plot a series of wind vectors onto a contoured area map for a series of weather stations (eg arrows showing wind speed/direction for a particular time snapshot), can someone please advise me how best to approach this? My desired end point is to be able to link a time series of such data together so that I will in effect have a movie displaying the evolution of these wind vectors over time - can anyone suggest how this can be achieved? I believe that there is a function within Image Magick whereby I might be able to acheive this? Thanks in advance! __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] selecting subsets of data from matrix
Thanks for your help everyone, My data is a matrix. However if i use the command: x[(x[,20] 315 | x[,20] 45), ] and then request a summary, I get a warning message saying that a large number of the row names have been duplicated - I don't understand this? On 20 Oct 2003, Douglas Bates wrote: Laura Quinn [EMAIL PROTECTED] writes: Probably a stupid question, but I don't seem to be able to find the answer I'm looking for from any of the R literature. Basically I have a matrix with several thousand rows and 20 columns(weather stations) of wind direction data. Is it a matrix or a data frame? I am wanting to extract a matrix which contains data for all columns conditional on column 20 having a value of _either_ less than 45 or greater than 315. (ie I want to extract a matrix which contains wind direction data for all columns {weather stations} when there is a prevailing northerly wind for one of the stations). I have tried a few different methods of doing this, none with any success, can anyone please advise? If x is a matrix they you want mysubset - x[x[,20] 45 | x[,20] 315,] If x is a data frame and column 20 is named col20 then you can use mysubset - subset(x, col20 45 | col20 315) __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Naive Q re applying AR(p) models to matrix data
As a total beginner still, I am having great difficulty trying to apply ar models to column data in a matrix. As each matrix has 20 columns (and some of these contain NA data) it is obviously a long, slow process to calculate ar models for each column individually, though I am (probably extremely stupidly) struggling to see how I am doing this wrong. I have tried using: for (i in 1:20) apply(mydata,c(,i),ar(mydata[!is.na(mydata)],order.max=3)) and apply(mydata,ar(mydata[!is.na(mydata)],order.max=3)) and apply(mydata,c(,1:20),ar(mydata[,1:20][!is.na(mydata[,1:20])],order.max=3)) and none of these work - can someone tell me what I am doing wrong?? Thank you in advance, and excuse me for my stupidity.. Laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Fitting AR(p) models
I am wanting to fit AR(p) models to column data for a series of matrices I have. Rather than trying to compute the AR models per column I was hoping to be able to do this per matrix (i.e. one AR model for each column in said matrix). However, when i attempt this, if there is just one NA value in any of the columns, the program refuses to compute AR models for any of the columns.(I am using na.action=na.omit) Is there a way I can force the calculation to provide AR models for complete columns, or alternatively, a better way to deal with NA's to provide an AR model, (eg via interpolation?) despite some missing values? I hope this makes some sense, thanks in advance, Laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Beginner's query - segmentation fault
I am dealing with a huge matrix in R (20 columns, 54000 rows) and have lots of missing values within the dataset which are currently displayed as the value -999.00 I am trying to create a new matrix (or change the existing one) to display these values as NA so that I can then perform the necessary analysis on the columns within the matrix. The matrix name is temp and the column names are t1 to t20 inclusive. I have tried the following command: temp$t1[temp$t1 == -999.00] - NA and it returns a segmentation fault, can someone tell me what I am doing wrong? Thanks Laura __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] Beginner's query - segmentation fault
thanks, have used temp [temp==0]- NA and this seems to have worked, though it won't let me access individual columns (ie temp$t1 etc) to work on - is there any real advantage in using a matrix, or would i be better advised to deal with dataframes? (I have double checked and temp is currently a matrix). On Tue, 7 Oct 2003, Prof Brian Ripley wrote: On Tue, 7 Oct 2003, Laura Quinn wrote: I am dealing with a huge matrix in R (20 columns, 54000 rows) and have lots of missing values within the dataset which are currently displayed as the value -999.00 I am trying to create a new matrix (or change the existing one) to display these values as NA so that I can then perform the necessary analysis on the columns within the matrix. The matrix name is temp and the column names are t1 to t20 inclusive. I have tried the following command: temp$t1[temp$t1 == -999.00] - NA and it returns a segmentation fault, can someone tell me what I am doing wrong? Well, R should not segfault, so there is bug here somewhere. However, I don't think what you have described can actually work. Is temp really a matrix? If so temp$t1 will return NULL, and you should get an error message. If temp is a matrix temp[temp == -999.00] - NA will do what you want. If as is more likely temp is a data frame with all columns numeric, there are several ways to do this, e.g. temp[] - lapply(temp, function(x) ifelse(x == -999, NA, x)) temp[as.matrix(temp) == -999] - NA # only in recent versions of R as well as explicit looping over columns. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help