[R] How to apply a two-place function to each combination of elements in two vectors of different lengths?

2011-01-29 Thread Marius Hofert
Dear expeRts, I somehow can't manage to do the following: Given two vectors x and y of lengths 3 and 2, respectively, I would like to apply a function to each combination of the entries of x and y and receive a 3-by-2 matrix containing the results. Now outer() seems to be the way to go, but

Re: [R] R-/Text-editor for Windows?

2011-01-29 Thread Liviu Andronic
Hello On Fri, Jan 28, 2011 at 8:03 PM, Jonathan P Daily jda...@usgs.gov wrote: Geany also handles a ton of filetypes, but lacks a direct interface to R in the windows version - I wrote an AutoHotKey script that did this for me in about 5 minutes. Could you please expand on that? I prefer to

[R] data extrapolation function

2011-01-29 Thread e-letter
Readers, Data was imported using the read csv command: dataimport-read.csv(/path/to/dataimport.csv) 10,2000 12,2001 13,2002 15,2003 17,2004 Using the help contents for 'predict.lm' (i.e. ?predict.lm) a new data frame was created dataimportextra-data.frame(x=seq(1990,2010,1))

Re: [R] How to apply a two-place function to each combination of elements in two vectors of different lengths?

2011-01-29 Thread Petr Savicky
On Sat, Jan 29, 2011 at 08:59:44AM +0100, Marius Hofert wrote: Dear expeRts, I somehow can't manage to do the following: Given two vectors x and y of lengths 3 and 2, respectively, I would like to apply a function to each combination of the entries of x and y and receive a 3-by-2 matrix

[R] Subset using grepl

2011-01-29 Thread Kang Min
Hi all, I would like to subset a dataframe by using part of the level name. x - rep(LETTERS[1:20],3) y - rep(1:3, 20) z - paste(x,y, sep=) random.data - rnorm(60) data - as.data.frame(cbind(z, random.data)) I need rows that contain the letters A to J, so I tried: subset(data,

Re: [R] Problem in weighting standard deviations

2011-01-29 Thread Duncan Murdoch
On 11-01-28 10:46 PM, Fernando Lima wrote: Dear all, I have a problem that has been driving me nuts. I have searched everywhere but could not find a comprehensive answer. I only get (sometimes contradictory) bits of information. I have a series of measurements with associated standard

Re: [R] data extrapolation function

2011-01-29 Thread Dennis Murphy
Hi: This 'works': di - read.csv(textConnection( + 10,2000 + 12,2001 + 13,2002 + 15,2003 + 17,2004), header = FALSE) names(di) - c('y', 'year') m - lm(y ~ year, data = di) diextra - data.frame(year = c(1990, 1991, 1993)) predict(m, new = diextra) 123 -7.0 -5.3 -1.9 You didn't

Re: [R] Subset using grepl

2011-01-29 Thread Prof Brian Ripley
The grep comdition is [A-J] BTW, why there are lots of unnecessary steps here, including using cbind() and subset(): x - rep(LETTERS[1:20],3) y - rep(1:3, 20) z - paste(x,y, sep=) random.data - rnorm(60) data - data.frame(z, random.data) data[grepl([A-J], z), ] Now (for the paranoid and not

[R] Positive Definite Matrix

2011-01-29 Thread Alex Smith
Hello I am trying to determine wether a given matrix is symmetric and positive matrix. The matrix has real valued elements. I have been reading about the cholesky method and another method is to find the eigenvalues. I cant understand how to implement either of the two. Can someone point me to

Re: [R] adding text to y-axis per row of panels (lattice)

2011-01-29 Thread E Hofstadler
Hello again, many thanks for your help! after upgrading the lattice package to the latest version, your solution works perfectly. Deepayan Sarkar wrote: On Fri, Jan 28, 2011 at 5:21 PM, E Hofstadler e.hofstad...@gmail.com wrote: Hello Deepayan, many thanks for your reply and help. Does

Re: [R] Problem with R Installation - .RData

2011-01-29 Thread Iva
Many thanks for the answers. They helped me resolve my .RData problem. -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-R-Installation-RData-tp3244121p3246036.html Sent from the R help mailing list archive at Nabble.com. __

Re: [R] Subset using grepl

2011-01-29 Thread Kang Min
Thanks Prof Ripley, the condition worked! Btw I tried to search ?repl but I don't have documentation for it. Is it in a non-basic package? On Jan 29, 6:54 pm, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: The grep comdition is [A-J] BTW, why there are lots of unnecessary steps here,

Re: [R] R-/Text-editor for Windows?

2011-01-29 Thread Gabor Grothendieck
On Sat, Jan 29, 2011 at 4:08 AM, Liviu Andronic landronim...@gmail.com wrote: Hello On Fri, Jan 28, 2011 at 8:03 PM, Jonathan P Daily jda...@usgs.gov wrote: Geany also handles a ton of filetypes, but lacks a direct interface to R in the windows version - I wrote an AutoHotKey script that did

Re: [R] Positive Definite Matrix

2011-01-29 Thread David Winsemius
On Jan 29, 2011, at 7:22 AM, Alex Smith wrote: Hello I am trying to determine wether a given matrix is symmetric and positive matrix. The matrix has real valued elements. I have been reading about the cholesky method and another method is to find the eigenvalues. I cant understand how to

Re: [R] R-/Text-editor for Windows?

2011-01-29 Thread Eduardo de Oliveira Horta
Sascha, I guess the software you wan't is RKWard: http://rkward.sourceforge.net/ I have tested a few R front-ends and to me this one seemed the most adequate. I suppose as an ex-matlab user my interface preferences are biased, but still RKWard has a good editor with syntax highlighting, code

[R] Multilevel

2011-01-29 Thread martanair
Why this? I write: radon.data - list (n, J, x, y, county) radon.inits - function (){ list (a=rnorm(J), b=rnorm(1), mu.a=rnorm(1), sigma.y=runif(1), sigma.a=runif(1)) } radon.parameters - c (a, b, mu.a, sigma.y, sigma.a) # with 10 iterations radon.1 - bugs (radon.data, radon.inits,

Re: [R] package R2WinBUGS question; was: Multilevel

2011-01-29 Thread Uwe Ligges
On 29.01.2011 15:06, martanair wrote: Why this? I write: radon.data- list (n, J, x, y, county) radon.inits- function (){ list (a=rnorm(J), b=rnorm(1), mu.a=rnorm(1), sigma.y=runif(1), sigma.a=runif(1)) } radon.parameters- c (a, b, mu.a, sigma.y, sigma.a) # with 10 iterations

Re: [R] Subset using grepl

2011-01-29 Thread Prof Brian Ripley
On Sat, 29 Jan 2011, Kang Min wrote: Thanks Prof Ripley, the condition worked! Btw I tried to search ?repl but I don't have documentation for it. Is it in a non-basic package? I meant grepl: the edit messed up (but not on my screen, as sometimes happens when working remotely). The point is

Re: [R] Positive Definite Matrix

2011-01-29 Thread David Winsemius
On Jan 29, 2011, at 7:58 AM, David Winsemius wrote: On Jan 29, 2011, at 7:22 AM, Alex Smith wrote: Hello I am trying to determine wether a given matrix is symmetric and positive matrix. The matrix has real valued elements. I have been reading about the cholesky method and another method is

Re: [R] Positive Definite Matrix

2011-01-29 Thread John Fox
Dear David and Alex, I'd be a little careful about testing exact equality as in all(M == t(M) and careful as well about a test such as all(eigen(M)$values 0) since real arithmetic on a computer can't be counted on to be exact. Best, John John Fox Senator

Re: [R] Positive Definite Matrix

2011-01-29 Thread David Winsemius
On Jan 29, 2011, at 9:59 AM, John Fox wrote: Dear David and Alex, I'd be a little careful about testing exact equality as in all(M == t(M) and careful as well about a test such as all(eigen(M)$values 0) since real arithmetic on a computer can't be counted on to be exact. Which was why

Re: [R] Positive Definite Matrix

2011-01-29 Thread David Winsemius
On Jan 29, 2011, at 10:11 AM, David Winsemius wrote: On Jan 29, 2011, at 9:59 AM, John Fox wrote: Dear David and Alex, I'd be a little careful about testing exact equality as in all(M == t(M) and careful as well about a test such as all(eigen(M)$values 0) since real arithmetic on a

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread Russell Pierce
Just in case someone else stumbles onto this thread and is facing a similar issue:  The quick solution for me turned out to be using Glm and Predict in the rms package. Thanks go to Joshua and Ista for helping me out with this issue. Double thanks go to Joshua for suggesting I take a closer look

Re: [R] Positive Definite Matrix

2011-01-29 Thread Prof Brian Ripley
On Sat, 29 Jan 2011, David Winsemius wrote: On Jan 29, 2011, at 10:11 AM, David Winsemius wrote: On Jan 29, 2011, at 9:59 AM, John Fox wrote: Dear David and Alex, I'd be a little careful about testing exact equality as in all(M == t(M) and careful as well about a test such as

Re: [R] package R2WinBUGS question; was: Multilevel

2011-01-29 Thread martanair
I have R2WinBUGS and this is my radon1.bug # Bugs code for multilevel model for radon # with bsmt as an individual predictor # varying-intercept model model { for (i in 1:n){ y[i] ~ dnorm (y.hat[i], tau.y) y.hat[i] - a[county[i]] + b*x[i] } b ~ dnorm (0, .0001) tau.y -

Re: [R] package R2WinBUGS question; was: Multilevel

2011-01-29 Thread Uwe Ligges
Can you please 1. reply to me personally, not only to the list (which I won't read all the time) and 2. cite what you wrote before. I tend to delete messages that are not of importance for me and rely on the fact that old information is cited. Now I do not have the data nor the code anymore

[R] Using 'contour' to compare concentration profiles on the same plot

2011-01-29 Thread emorway
Hello, Using the data and code below I've been using R to compare output from two different solute transport codes, the red contours are from verified code while the blue contours come from some modified code I've been working on. The goal is for the contours to match, and although there is

Re: [R] text labels in Trellis plot

2011-01-29 Thread Deepayan Sarkar
On Wed, Jan 26, 2011 at 4:24 PM, Markus Damian m.dam...@bristol.ac.uk wrote: Dear all, I need to generate plots in which the points of the plot are replaced by text labels, such as dog and cat. The usual way of specifying the plotting symbol with pch works only if the labels are single

[R] Spare matrix multiplication

2011-01-29 Thread Feng Li
Dear R, I have a simple question concerning with a special case of spare matrix multiplications. Say A is a 200-by-1 dense matrix. B is a 1-by-1 block- diagonal matrix, and each diagonal block B_i is 100-by-100. The usual way I did A%*%B will take about 30 seconds which is to time

Re: [R] package R2WinBUGS question; was: Multilevel

2011-01-29 Thread Ben Bolker
Uwe Ligges ligges at statistik.tu-dortmund.de writes: On 29.01.2011 15:06, martanair wrote: [snip] I write: radon.data- list (n, J, x, y, county) radon.inits- function (){ list (a=rnorm(J), b=rnorm(1), mu.a=rnorm(1), sigma.y=runif(1), sigma.a=runif(1)) }

Re: [R] Spare matrix multiplication

2011-01-29 Thread Feng Li
I meant sparse matrix, sorry for the typo. Feng On Sat, Jan 29, 2011 at 7:02 PM, Feng Li m...@feng.li wrote: Dear R, I have a simple question concerning with a special case of sparse matrix multiplications. Say A is a 200-by-1 dense matrix. B is a 1-by-1 block- diagonal matrix,

Re: [R] Positive Definite Matrix

2011-01-29 Thread David Winsemius
On Jan 29, 2011, at 12:17 PM, Prof Brian Ripley wrote: On Sat, 29 Jan 2011, David Winsemius wrote: On Jan 29, 2011, at 10:11 AM, David Winsemius wrote: On Jan 29, 2011, at 9:59 AM, John Fox wrote: Dear David and Alex, I'd be a little careful about testing exact equality as in all(M ==

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread David Winsemius
On Jan 29, 2011, at 12:12 PM, Russell Pierce wrote: Just in case someone else stumbles onto this thread and is facing a similar issue: The quick solution for me turned out to be using Glm and Predict in the rms package. Thanks go to Joshua and Ista for helping me out with this issue. Double

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread Joshua Wiley
On Sat, Jan 29, 2011 at 11:10 AM, David Winsemius dwinsem...@comcast.net wrote: On Jan 29, 2011, at 12:12 PM, Russell Pierce wrote: Just in case someone else stumbles onto this thread and is facing a similar issue:  The quick solution for me turned out to be using Glm and Predict in the rms

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread Ista Zahn
Another option is set.seed(10) dat - data.frame(xxA = rnorm(20,10), xxB = rnorm(20,20)) dat$out - with(dat,xxA+xxB+xxA*xxB+rnorm(20,20)) lm.mod - lm(out ~ I(scale(xxA))*I(scale(xxB)), data=dat) newdata - data.frame(xxA=c(-1,0,1),xxB=c(-1,0,1)) preds - predict(lm.mod, newdata) Best, Ista On

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread Russell Pierce
David, Thanks for your feedback. However, I think if you look at the mean of your output (which, as a minor point, doesn't provide the same data to predict as expand.grid(X1=c(-1,0,1),X2=c(-1,0,1)), you'll see it is very different from the mean of dat$out. Like Ista's previous answer, I think in

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread David Winsemius
On Jan 29, 2011, at 2:36 PM, Joshua Wiley wrote: On Sat, Jan 29, 2011 at 11:10 AM, David Winsemius dwinsem...@comcast.net wrote: On Jan 29, 2011, at 12:12 PM, Russell Pierce wrote: Just in case someone else stumbles onto this thread and is facing a similar issue: The quick solution for me

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread Joshua Wiley
On Sat, Jan 29, 2011 at 12:31 PM, David Winsemius dwinsem...@comcast.net wrote: Huh?. With the same model and data, they should be the same: I must be missing something, because that is what I would have expected too, but it is not what I get (at least when I run the code as shown below).

Re: [R] Positive Definite Matrix

2011-01-29 Thread Prof Brian Ripley
On Sat, 29 Jan 2011, David Winsemius wrote: On Jan 29, 2011, at 12:17 PM, Prof Brian Ripley wrote: On Sat, 29 Jan 2011, David Winsemius wrote: On Jan 29, 2011, at 10:11 AM, David Winsemius wrote: On Jan 29, 2011, at 9:59 AM, John Fox wrote: Dear David and Alex, I'd be a little careful

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread David Winsemius
On Jan 29, 2011, at 3:49 PM, Joshua Wiley wrote: On Sat, Jan 29, 2011 at 12:31 PM, David Winsemius dwinsem...@comcast.net wrote: Huh?. With the same model and data, they should be the same: I must be missing something, because that is what I would have expected too, but it is not what I get

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread Joshua Wiley
On Sat, Jan 29, 2011 at 1:05 PM, David Winsemius dwinsem...@comcast.net wrote: On Jan 29, 2011, at 3:49 PM, Joshua Wiley wrote: On Sat, Jan 29, 2011 at 12:31 PM, David Winsemius dwinsem...@comcast.net wrote: Huh?. With the same model and data, they should be the same: I must be missing

[R] runsd {caTools} crashes R 64bit on winxp64bit with a very large vector

2011-01-29 Thread MM
Hello I have a 3.5 million elements numeric vector x. I'm trying to calculate the rolling std dev of the previous 144 elements. rsd144-runsd(x, 144, center=0, endrule=NA) this crashes R (ie on the console disappears and the Rgui.exe process is not there anymore) with smaller vectors,

Re: [R] Mean from confidence intervals

2011-01-29 Thread Peter Francis
Dear all, The data is generated from 1000 random samples of a phylogenetic tree to calculate phylogenetic diversity. I sampled the tree 1000 times at with various species communities (600) to get a random PD per community. I then want to test my observed PD with that of a random sample to test

Re: [R] Problem in weighting standard deviations

2011-01-29 Thread Fernando Lima
Dear all: I am going to explain better the problem I have. I would greatly appreciate an answer because I cannot advance further in my project while I do not solve this problem. I have a series of mean sea surface temperatures measured by satellites. These data are reported in degrees longitude

[R] Help -- Error in clusterApplyLB

2011-01-29 Thread kparamas
I am running this in a cluster, I am trying to calculate this in a cluster, cdata = replicate(2000,rnorm(6)) c1 = cor(cdata) m1 = as.matrix(cdata) cl = makeCluster(64) out = clusterApplyLB(cl,m1,cor) Error in checkForRemoteErrors(val) : 12000 nodes produced errors; first error: supply both

Re: [R] Positive Definite Matrix

2011-01-29 Thread Alex Smith
Thank you for the links and the information.You have been very helpful On Sat, Jan 29, 2011 at 2:45 PM, David Winsemius dwinsem...@comcast.netwrote: On Jan 29, 2011, at 7:58 AM, David Winsemius wrote: On Jan 29, 2011, at 7:22 AM, Alex Smith wrote: Hello I am trying to determine wether a

[R] environment question: changing variables from a formula through model.frame?

2011-01-29 Thread Tal Galili
Hello all, I came across a behavior of R with environments that I'm not sure what is causing it. It involves changing variables that are found through using model.frame on a formula inside a function. I wonder if it's a bug or a feature. And in either case, how it might be managed. Here is a

[R] Basic Help with Zoo objects and trading days

2011-01-29 Thread john nicholas
All, I have been just recently working with zoo objects for trading systems. Can someone please help with these basic questions? Given a daily time series downloaded using get.hist.quote() from the tseries package, ie.. startDate= as.Date(2000-01-01) endDate= as.Date(2011-01-29)

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread Joshua Wiley
On Sat, Jan 29, 2011 at 1:23 PM, Joshua Wiley jwiley.ps...@gmail.com wrote: xxAB - dat$xxA * dat$xxB meanAB - meanA * meanB sdAB - sqrt(sdA^2 + sdB^2 + meanA^2 * sdB^2 + meanB^2 * sdA^2) don't know why I did that the hard way (besides I think I messed up the formula slightly), but the point is

Re: [R] Mean from confidence intervals

2011-01-29 Thread David Winsemius
On Jan 29, 2011, at 9:39 AM, Peter Francis wrote: Dear all, The data is generated from 1000 random samples of a phylogenetic tree to calculate phylogenetic diversity. I sampled the tree 1000 times at with various species communities (600) to get a random PD per community. I then want to

Re: [R] Basic Help with Zoo objects and trading days

2011-01-29 Thread Gabor Grothendieck
On Sat, Jan 29, 2011 at 2:03 PM, john nicholas jbnich...@sbcglobal.net wrote: All, I have been just recently working with zoo objects for trading systems. Can someone please help with these basic questions? Given a daily time series downloaded using get.hist.quote() from the tseries

Re: [R] Positive Definite Matrix

2011-01-29 Thread Martin Maechler
Prof Brian Ripley rip...@stats.ox.ac.uk on Sat, 29 Jan 2011 21:00:19 + (GMT) writes: On Sat, 29 Jan 2011, David Winsemius wrote: On Jan 29, 2011, at 12:17 PM, Prof Brian Ripley wrote: On Sat, 29 Jan 2011, David Winsemius wrote: On Jan 29,

Re: [R] Sparse matrix multiplication

2011-01-29 Thread Martin Maechler
FL == Feng Li m...@feng.li on Sat, 29 Jan 2011 19:46:48 +0100 writes: FL I meant sparse matrix, sorry for the typo. aha.. :-) FL On Sat, Jan 29, 2011 at 7:02 PM, Feng Li m...@feng.li wrote: Dear R, I have a simple question concerning with a special case of

Re: [R] Mean from confidence intervals

2011-01-29 Thread peterfrancis
Sorry for not being more explicit in my emails, the code I am using was not generated by me therefore I was not in the position to share it. Sorry if the information i have provided is insufficient or if I have wasted peoples time. Basically I have the information listed below I.e n and the

Re: [R] runsd {caTools} crashes R 64bit on winxp64bit with a very large vector

2011-01-29 Thread Duncan Murdoch
On 11-01-29 1:11 PM, MM wrote: Hello I have a 3.5 million elements numeric vector x. I'm trying to calculate the rolling std dev of the previous 144 elements. rsd144-runsd(x, 144, center=0, endrule=NA) this crashes R (ie on the console disappears and the Rgui.exe process is not there

Re: [R] runsd {caTools} crashes R 64bit on winxp64bit with a very large vector

2011-01-29 Thread Duncan Murdoch
On 11-01-29 8:19 PM, Duncan Murdoch wrote: On 11-01-29 1:11 PM, MM wrote: Hello I have a 3.5 million elements numeric vector x. I'm trying to calculate the rolling std dev of the previous 144 elements. rsd144-runsd(x, 144, center=0, endrule=NA) this crashes R (ie on the console

[R] SMA and EMA in package TTR

2011-01-29 Thread Anyi Zhu
Hi, Just wondering for the SMA and EMA in package TTR, is it possible to me to code it so that, say if I need to calculate SMA (x, n=100), when the sample size is less than 100, it will give me the SMA (x, k) where k is the sample size of the data? Right now it only gives me an invalid n error.

Re: [R] Mean from confidence intervals

2011-01-29 Thread David Winsemius
On Jan 29, 2011, at 5:21 PM, peterfran...@me.com wrote: Sorry for not being more explicit in my emails, the code I am using was not generated by me therefore I was not in the position to share it. Sorry if the information i have provided is insufficient or if I have wasted peoples

Re: [R] Mean from confidence intervals

2011-01-29 Thread csrabak
Em 28/1/2011 20:15, Peter Francis escreveu: Dear List, I am not sure if A) this is possible or B) the correct place to ask. I am looking to find the mean - i have n, and the two-tailed confidence intervals 0.95 0.25 with a p-value of 0.05. Can i find the mean from this data ? Thanks

Re: [R] agnes clustering and NAs

2011-01-29 Thread Dario Strbenac
Hello, Thankyou for the clarification about the NAs. For your interest, thankfully my end goal was not to plot a dendrogram with 23371 elements, but just to use the output of the clustering to re-order the rows of a matrix before plotting it with image(). Since clara() and pam() are

[R] Extract time only from POSIXlt object

2011-01-29 Thread Simon Goodman
How can I extract only the time component from an POSIXlt object? For example if I try the following it still returns both the date and time... as.POSIXlt(tr.date[1]) [1] 2010-10-18 21:46:53 as.POSIXlt(tr.date[1],%H:%M:%S) [1] 2010-10-18 21:46:53 round and trunc don't help... is there an

Re: [R] predict and arima

2011-01-29 Thread bdp
Some code I have been playing with to do this follows ... get.best.arima - function(x.ts, minord=c(0,0,0,0,0,0), maxord=c(2,1,1,2,1,1)) { # function based on 'Introductory Time Series with R' best.aic - 1e8 # a big number n - length(x.ts) for(p in

Re: [R] Extract time only from POSIXlt object

2011-01-29 Thread David Winsemius
On Jan 29, 2011, at 7:45 PM, Simon Goodman wrote: How can I extract only the time component from an POSIXlt object? For example if I try the following it still returns both the date and time... as.POSIXlt(tr.date[1]) [1] 2010-10-18 21:46:53 as.POSIXlt(tr.date[1],%H:%M:%S) [1] 2010-10-18