From pdalgd at gmail.com Thu Dec 1 00:08:44 2011 From: pdalgd at gmail.com (peter dalgaard) Date: Thu, 1 Dec 2011 00:08:44 +0100 Subject: [R] Problem installing the package tkrplot In-Reply-To: References: Message-ID: <1A41EF30-6C24-466E-B46B-F5CBC3E6B94F@gmail.com> On Nov 30, 2011, at 15:31 , Marcos Amaris Gonzalez wrote: > Hello people. My problem is that when I try to install the package > tkrplot, I got the next problem: You seem to be missing the tk.h file. This is, most likely, in a tcl/tk development package that you haven't installed. This is part of your Linux distribution, not R. (You're not telling us which Linux you are running, and it can't be pinpointed any further without that information, but look for something like tk-devel and tcl-devel.) > >> install.packages("tkrplot") > Installing package(s) into ?/home/marcos/R/i686-pc-linux-gnu-library/2.13? > (as ?lib? is unspecified) > probando la URL > 'http://www.vps.fmvz.usp.br/CRAN/src/contrib/tkrplot_0.0-23.tar.gz' > Content type 'application/x-gzip' length 39037 bytes (38 Kb) > URL abierta > ================================================== > downloaded 38 Kb > > * installing *source* package ?tkrplot? ... > configure: creating ./config.status > config.status: creating src/Makevars > ** libs > gcc -I/usr/share/R/include -I/usr/include/tcl8.5 -I/usr/include/tcl8.5 > -fpic -std=gnu99 -O3 -pipe -g -c tcltkimg.c -o tcltkimg.o > tcltkimg.c:2:16: fatal error: tk.h: No existe el fichero o el directorio > compilation terminated. > make: *** [tcltkimg.o] Error 1 > ERROR: compilation failed for package ?tkrplot? > * removing ?/home/marcos/R/i686-pc-linux-gnu-library/2.13/tkrplot? > Warning in install.packages : > installation of package 'tkrplot' had non-zero exit status > > The downloaded packages are in > ?/tmp/RtmpHRfZ1k/downloaded_packages? > > In this moment I have R version 2.13.2 (2011-09-30). I stayed > thankfull for the any help. > > --- > Marcos Amaris Gonzalez > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com From dwinsemius at comcast.net Thu Dec 1 00:23:19 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Wed, 30 Nov 2011 18:23:19 -0500 Subject: [R] Bootstrapping for residuals In-Reply-To: <1322670663989-4123657.post@n4.nabble.com> References: <1322670663989-4123657.post@n4.nabble.com> Message-ID: On Nov 30, 2011, at 11:31 AM, bubbles1990 wrote: > > Hi, Ive been trying to write a program for bootstrapping residuals > in R but > without much success. > > A lecturer wants to predict the performance of students in an end-of- > year > physics exam, y. The lecturer has the students results from a mid-term > physics exam, x, and a mid-term biology exam, z. > He proposes the following linear model for the end-of-year exam result > yi = ? + ?xi + ?zi + qi, where q is the error. > Y is a matrix of the data and we have y=first column of the data and > X=second 2 columns(the x & z data) > Now I need to write a program for obtaining bootstrap estimates, You replied but included no context, a common and not appreciated (in both senses of that verb) failing in posts from Nabble. My question would be: bootstrap estimate ... of what? -- David. > i have: > > x=scan(data) > Y=matrix(x,ncol=3,byrow=T) > y=Y[,1] > X=Y[,2:3] > > ls=lsfit(X,y) > beta=ls$coef > > yest=beta[1]+beta[2]*X[,1]+beta[3]*X[,2] > res=y-yest > > boot=function(X,res,beta,b) > { > n=24 > output=matrix(0,ncol=2,nrow=b) > for(i in 1:b) > { > error=sample(res,n,replace=T) > ystar=beta[1]+beta[2]*X[,1]+beta[3]*X[,2]+error > ls=lsfit(X,ystar) > output[i,]=ls$coef > } > output > } > > I think the first 8 lines are right but my function might be wrong? > Any help? > > -- > View this message in context: http://r.789695.n4.nabble.com/Bootstrapping-for-residuals-tp4123657p4123657.html > Sent from the R help mailing list archive at Nabble.com. > David Winsemius, MD West Hartford, CT From ggrothendieck at gmail.com Thu Dec 1 00:33:44 2011 From: ggrothendieck at gmail.com (Gabor Grothendieck) Date: Wed, 30 Nov 2011 18:33:44 -0500 Subject: [R] forecasting linear regression from lagged variable In-Reply-To: <1322689204697-4125091.post@n4.nabble.com> References: <1322689204697-4125091.post@n4.nabble.com> Message-ID: On Wed, Nov 30, 2011 at 4:40 PM, AaronB wrote: > I'm currently working with some time series data with the xts package, and > would like to generate a forecast 12 periods into the future. There are > limited observations, so I am unable to use an ARIMA model for the forecast. > Here's the regression setup, after converting everything from zoo objects to > vectors. > > hire.total.lag1 <- lag(hire.total, lag=-1, na.pad=TRUE) > lm.model <- lm(hire.total ~ case.total + hire.total.lag1) > > hire.total is a monthly historical time series from Jan 2010 to Oct 2011. > hire.total.lag1 is the same time series, lagged 1 period backwards. > case.total is a monthly historical time series from Jan 2010 to Oct 2011, > plus forecasts forward another 12 periods. > > I'd like to use this model to forecast hire.total for the next period, and > use each successive prediction of hire.total as the lag1 "observation" for > the next prediction. I have enough "observed" values for case.total to > forecast out as far as I need. I might be able to construct this using a > loop, but I have a feeling it will be messy and slow. Any suggestions? > Its not clear that you can't use an arima model. You would use the n.ahead= argument of predict.Arima. The dyn and dynlm packages handle lagged lm's of zoo objects but you will have to do a predict and then append the prediction to the data and repeat in a loop as you describe. If you want to be careful about error terms then its more complex. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com From michael.weylandt at gmail.com Thu Dec 1 00:51:42 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Wed, 30 Nov 2011 18:51:42 -0500 Subject: [R] Invalid number of components, ncomp In-Reply-To: <1322647845.69137.YahooMailNeo@web121516.mail.ne1.yahoo.com> References: <1322647845.69137.YahooMailNeo@web121516.mail.ne1.yahoo.com> Message-ID: I'm not familiar with the package and I don't currently have it loaded, but looking at the examples in the documentation here http://www.stat.ucl.ac.be/ISdidactique/Rhelp/library/pls.pcr/html/mvr.html it seems that you need ncomp = 1:6. Saying you want to do multivariate regression on only a single variable is probably the source of the error. Does that help? Michael On Wed, Nov 30, 2011 at 5:10 AM, Vytautas Rakeviius wrote: > Error in mvr(Kd_nM ~ qsar, ncomp = 6, data = my, validation = "CV", method = "kernelpls") : > ? Invalid number of components, ncomp > > How I can fix this? > > ? ? ? ?[[alternative HTML version deleted]] > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > From flodel at gmail.com Thu Dec 1 01:51:26 2011 From: flodel at gmail.com (Florent D.) Date: Wed, 30 Nov 2011 19:51:26 -0500 Subject: [R] how to call a function for each row In-Reply-To: <002501ccaf70$a67f72b0$f37e5810$@edu> References: <1322658608657-4122906.post@n4.nabble.com> <002501ccaf70$a67f72b0$f37e5810$@edu> Message-ID: if you want to store the result in a column of your data.frame: within(df, Y <- 6*X1+7*X2+8*X3) On Wed, Nov 30, 2011 at 9:59 AM, David L Carlson wrote: > Isn't this even easier? > >> X1 <- c(1:3) >> X2 <- c(3, 4, 6) >> X3 <- c(5, 6, 1) >> Y <- 6*X1 + 7*X2 + 8*X3 >> Y > [1] 67 88 68 > > Or if you really need a function: > >> MakeY <- function(x, y, z) 6*x + 7*y + 8*z >> MakeY(X1, X2, X3) > [1] 67 88 68 > > > ---------------------------------------------- > David L Carlson > Associate Professor of Anthropology > Texas A&M University > College Station, TX 77843-4352 > > > > -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On > Behalf Of R. Michael Weylandt > Sent: Wednesday, November 30, 2011 8:17 AM > To: arunkumar1111 > Cc: r-help at r-project.org > Subject: Re: [R] how to call a function for each row > > Read ?apply > > This is easiest: > > df <- matrix(c(1,2,3,3,4,6,5,6,1), 3) > apply(df, 1, function(x) 6*x[1]+7*x[2]+8*x[3]) > > But it's much more efficient to do it with matrix multiplication. In keeping > with the best of tradition, this is left as an exercise to the reader. > > Michael > > On Wed, Nov 30, 2011 at 8:10 AM, arunkumar1111 wrote: >> Hi >> >> ?I have ?a data-frame which look like this >> >> X1 X2 X3 >> 1 ? 3 ?5 >> 2 ? 4 ?6 >> 3 ? 6 ?1 >> >> I want to apply a formula Y=6*X1 + 7*X2 + 8*X3 ?for every row >> >> >> Thanks in Advance >> >> >> >> >> >> >> >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/how-to-call-a-function-for-each-row-tp41 >> 22906p4122906.html Sent from the R help mailing list archive at >> Nabble.com. >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From fife.dustin at gmail.com Thu Dec 1 03:50:58 2011 From: fife.dustin at gmail.com (Dustin Fife) Date: Wed, 30 Nov 2011 20:50:58 -0600 Subject: [R] FIML with missing data in sem package Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From axel.urbiz at gmail.com Thu Dec 1 04:48:23 2011 From: axel.urbiz at gmail.com (Axel Urbiz) Date: Wed, 30 Nov 2011 22:48:23 -0500 Subject: [R] Random Forests in R Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From mattcstats at gmail.com Thu Dec 1 04:56:58 2011 From: mattcstats at gmail.com (Matt Cooper) Date: Thu, 1 Dec 2011 11:56:58 +0800 Subject: [R] R endnote entry Message-ID: I know citation() gives the R citation to be used in publications. Has anyone put this into endnote nicely? I'm not very experienced with endnote, and the way I have it at the momeny the 'R Development Core Team' becomes R. D. C. T. etc. Cheers. From lists at remoteinformation.com.au Thu Dec 1 04:56:57 2011 From: lists at remoteinformation.com.au (Ben Madin) Date: Thu, 1 Dec 2011 10:56:57 +0700 Subject: [R] R logo in eps formt Message-ID: G'day all, Sorry if this message has been posted before, but searching for R is always difficult... I was hoping for a copy of the logo in eps format? Can I do this from R, or is one available for download? cheers Ben From millerlp at gmail.com Thu Dec 1 05:12:22 2011 From: millerlp at gmail.com (Luke Miller) Date: Wed, 30 Nov 2011 23:12:22 -0500 Subject: [R] R endnote entry In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From peter.langfelder at gmail.com Thu Dec 1 06:32:51 2011 From: peter.langfelder at gmail.com (Peter Langfelder) Date: Wed, 30 Nov 2011 21:32:51 -0800 Subject: [R] Random Forests in R In-Reply-To: References: Message-ID: On Wed, Nov 30, 2011 at 7:48 PM, Axel Urbiz wrote: > I understand the original implementation of Random Forest was done in > Fortran code. In the source files of the R implementation there is a note > "C wrapper for random forests: ?get input from R and drive ?the Fortran > routines.". I'm far from an expert on this...does that mean that the > implementation in R is through calls to C functions only (not Fortran)? > > So, would knowing C be enough to understand this code, or Fortran is also > necessary? I haven't seen the C and Fortran code for Random Forest but I understand the note to say that R code calls some C functions that pre-process (possibly re-format etc) the data, then call the actual Random Forest method that's written in Fortran, then possibly post-process the output and return it to R. It would imply that to understand the actual Random Forest code, you will have to read the Fortran source code. Best, Peter From leavestonebodt at yahoo.com Thu Dec 1 08:06:41 2011 From: leavestonebodt at yahoo.com (yuying shi) Date: Wed, 30 Nov 2011 23:06:41 -0800 (PST) Subject: [R] ordinal data simulation Message-ID: <1322723201.36177.YahooMailClassic@web161705.mail.bf1.yahoo.com> Dear all, I am doing an ordinal data simulation. I?have a question regarding the cut off values between categories. Suppose I have three categories, if I do regression, there should be two cut off values. I find some simulation code for the ordinal data. However, they usually only generate a uniform random number and compare the probability with the random number. Could any one be so kind to tell me the rational behind it. I don't know why we need a random number rather than just two fixed cut off values. Thanks very much! Myckel From nsaraf at gmail.com Thu Dec 1 01:48:02 2011 From: nsaraf at gmail.com (nsaraf) Date: Wed, 30 Nov 2011 16:48:02 -0800 (PST) Subject: [R] R code Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From tylerdrudolph at gmail.com Thu Dec 1 04:22:35 2011 From: tylerdrudolph at gmail.com (T.D. Rudolph) Date: Wed, 30 Nov 2011 19:22:35 -0800 (PST) Subject: [R] Average of Two Matrices In-Reply-To: <0101EF7F-9DEB-43BC-9758-EAD334B848C7@sjtu.edu.cn> References: <73f827b50806241919p736086dcoa54049d55ecbc5d@mail.gmail.com> <0101EF7F-9DEB-43BC-9758-EAD334B848C7@sjtu.edu.cn> Message-ID: <1322709755163-4126615.post@n4.nabble.com> What if you have over 50 matrices and you don't want to write them all out one-by-one? I know there's something really quite simple, but I haven't found it yet!... -- View this message in context: http://r.789695.n4.nabble.com/Average-of-Two-Matrices-tp860672p4126615.html Sent from the R help mailing list archive at Nabble.com. From xdchen at hutc.zj.cn Thu Dec 1 06:37:08 2011 From: xdchen at hutc.zj.cn (chenandfuok) Date: Wed, 30 Nov 2011 21:37:08 -0800 (PST) Subject: [R] error in ZIGP package and optim Message-ID: <1322717828592-4127053.post@n4.nabble.com> Dear all: I am trying to use the response.zigp and est.zigp from the ZIGP package. Firstly, I generated a simple data via response.zigp and then I try to fit them by est.zigp function, this is the code: --------------------------------- > library(ZIGP) > #try-ZIGP-1 > n<-100 > X<-matrix(c(rep(1,n),runif(n*2,0,1)),n,3) > W<-matrix(c(rep(1,n),rbinom(n,1,0.5)),n,2) > Z<-matrix(c(rep(1,n),rbinom(n,1,0.5)),n,2) > beta<-c(1,-2,1) > alpha<-c(1,1.5) > gamma<-c(-1,2) > y<-response.zigp(X,W,Z,beta,alpha,gamma) > x1<-as.vector(X[,1]) > x2<-as.vector(X[,2]) > x3<-as.vector(X[,3]) > w1<-as.vector(W[,1]) > w2<-as.vector(W[,2]) > z1<-as.vector(Z[,1]) > z2<-as.vector(Z[,2]) > fm.X<-~x1+x2+x3 > fm.W<-~1 > fm.Z<-~z1+z2 > est.zigp(y,fm.X,fm.W,fm.Z,Offset=rep(1,length(y)),init=FALSE) ----------------------------- Then I get the *error:* ---------------------------- Error in optim(par = start.delta, fn = loglikelihood.zigp, gr = gradient, : initial value in 'vmmin' is not finite -------------------------------- Any help you can give me would be greatly appreciated. -- View this message in context: http://r.789695.n4.nabble.com/error-in-ZIGP-package-and-optim-tp4127053p4127053.html Sent from the R help mailing list archive at Nabble.com. From oana.tomescu at student.tugraz.at Thu Dec 1 08:24:23 2011 From: oana.tomescu at student.tugraz.at (Oana Tomescu) Date: Thu, 1 Dec 2011 08:24:23 +0100 Subject: [R] Generalized singular value decomposition In-Reply-To: <1322666007362-4123335.post@n4.nabble.com> References: <4ED61F0A.3060904@knmi.nl> <1322666007362-4123335.post@n4.nabble.com> Message-ID: Am 30.11.2011 16:13, schrieb Berend Hasselman: > > tom wrote > > I don't think you have to install "something". > You have not told us how you are trying to load the dll's. > > You can use the GSVD function from > http://r.789695.n4.nabble.com/problem-with-generalized-singular-value-decomposition-using-LAPACK-td834930.html > but you will need the exact path to the Lapack dll in the dyn.load call. > Something like dyn.load("C:\\R\\.....\\libRlapack.dll"). This was just what I was looking for, thank you very much! When I read the post before I did not notice the line with the dyn.load. > You do not need to dyn.load the Blas dll. > > I have tried this GSVD function with Mac OS X with success. I tried the GSVD with the folowing matrices: A = matrix(rnorm(100,100,20),10,10) B = matrix(rnorm(200,10,3),20,10) res = GSVD(A,B) The resulted U and V have all entries equal to zero. This seems a little wired since A=U*E1*Q' and B=V*E2*Q'. If U and V are zero then A and B should also be zero. Are my example matrices a special case for the decomposition? I just started working with it, so I am a completely newbie ... Thank you again very much for your help! (I was already thinking about doing the decomposition with Matlab and loading the result into R.) Regards, Oana > > Berend > > > -- > View this message in context: http://r.789695.n4.nabble.com/Generalized-singular-value-decomposition-tp4122542p4123335.html > Sent from the R help mailing list archive at Nabble.com. > From jwiley.psych at gmail.com Thu Dec 1 08:25:32 2011 From: jwiley.psych at gmail.com (Joshua Wiley) Date: Wed, 30 Nov 2011 23:25:32 -0800 Subject: [R] Average of Two Matrices In-Reply-To: <1322709755163-4126615.post@n4.nabble.com> References: <73f827b50806241919p736086dcoa54049d55ecbc5d@mail.gmail.com> <0101EF7F-9DEB-43BC-9758-EAD334B848C7@sjtu.edu.cn> <1322709755163-4126615.post@n4.nabble.com> Message-ID: Well, you're rather stuck writing them all out unless you have them in some other data structure. ## three dimensional array (50 4 x 4 matrices) x <- array(rnorm(16 * 50), dim = c(4, 4, 50)) > apply(x, 1:2, mean) [,1] [,2] [,3] [,4] [1,] -0.09460574 0.01572077 -0.166194625 -0.28176540 [2,] -0.26649044 -0.23546332 -0.003559647 -0.09857819 [3,] 0.12657883 0.10979631 0.368414189 -0.13653997 [4,] -0.02827496 0.07634844 -0.088057890 0.06208034 ## list of length 50 each element is 4 x 4 matrix > y <- rep(list(matrix(rnorm(16), 4, 4)), 50) > length(y) [1] 50 > Reduce(`+`, y)/length(y) [,1] [,2] [,3] [,4] [1,] -1.8334660 0.67812999 0.20159314 1.6163501 [2,] -0.6716821 -0.23942474 -0.50482638 -0.5765309 [3,] 0.7991496 0.38674047 -0.02128386 -1.1868209 [4,] -1.1654429 0.06773386 0.13538268 0.3847375 See ?array ?apply ?Reduce for documentation Hope this helps, Josh On Wed, Nov 30, 2011 at 7:22 PM, T.D. Rudolph wrote: > > What if you have over 50 matrices and you don't want to write them all out > one-by-one? ?I know there's something really quite simple, but I haven't > found it yet!... > > -- > View this message in context: http://r.789695.n4.nabble.com/Average-of-Two-Matrices-tp860672p4126615.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/ From ripley at stats.ox.ac.uk Thu Dec 1 08:42:07 2011 From: ripley at stats.ox.ac.uk (Prof Brian Ripley) Date: Thu, 1 Dec 2011 07:42:07 +0000 (GMT) Subject: [R] RTisean executable problem in STLperArea In-Reply-To: <1322692437699-4125382.post@n4.nabble.com> References: <1322692437699-4125382.post@n4.nabble.com> Message-ID: It is one of the rather confusing things about the RTisean package. It does not say what your subject says: it says 'TISEAN executables'. The DESCRIPTION *should* have a SystemRequirements line (and this has been reported), It does say It requires that you have the Tisean-3.0.1 algorithms available on your computer. (It means the Tisean-3.0.1 binary programs ....) Have you? If so, that is what you should be seting setTISEANpath to point to. On Wed, 30 Nov 2011, lglew wrote: > Hi, > > I?m trying to use the STLperArea function in the ndvits package. I can run > the sample data (?SLPSAs_full?) without any problem. However, when I come to > run the function on my own data, I get the following message. > > Waiting to confirm page change... > Error in .checkPath(path) : no TISEAN executables found in that directory. > Please set a proper TISEAN executables path using 'setTISEANpath' > > I?ve tried setting the TISEANpath to the directory where the RTisean library > is on my computer. > > Could someone please suggest what the problem might be? > > Many thanks, > > Louise > > -- > View this message in context: http://r.789695.n4.nabble.com/RTisean-executable-problem-in-STLperArea-tp4125382p4125382.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 From crosspide at hotmail.com Thu Dec 1 08:54:09 2011 From: crosspide at hotmail.com (agent dunham) Date: Wed, 30 Nov 2011 23:54:09 -0800 (PST) Subject: [R] Replace columns in a data.frame randomly splitted In-Reply-To: References: <1322658929391-4122926.post@n4.nabble.com> Message-ID: <1322726049879-4127405.post@n4.nabble.com> The thing is that I've already been working with df1, and I was looking for a function that could replace values knowing rows and columns. Does it exist? Thank you, user at host.com -- View this message in context: http://r.789695.n4.nabble.com/Replace-columns-in-a-data-frame-randomly-splitted-tp4122926p4127405.html Sent from the R help mailing list archive at Nabble.com. From ligges at statistik.tu-dortmund.de Thu Dec 1 10:29:15 2011 From: ligges at statistik.tu-dortmund.de (Uwe Ligges) Date: Thu, 01 Dec 2011 10:29:15 +0100 Subject: [R] Error adding Bigmemory package In-Reply-To: <1322686407008-4124863.post@n4.nabble.com> References: <1322686407008-4124863.post@n4.nabble.com> Message-ID: <4ED748EB.6080006@statistik.tu-dortmund.de> On 30.11.2011 21:53, RogerP wrote: > I am trying to add the bigmemory packages but I get the following error > message: > > In file included from bigmemory.cpp:14:0: > ../inst/include/bigmemory/isna.hpp: In function 'bool neginf(double)': > ../inst/include/bigmemory/isna.hpp:22:57: error: 'isinf' was not declared in > this scope > make: *** [bigmemory.o] Error 1 > ERROR: compilation failed for package 'bigmemory' > * removing '/usr/local/lib/R/library/bigmemory' > * restoring previous '/usr/local/lib/R/library/bigmemory' > > The downloaded packages are in > '/tmp/RtmpNrkt2a/downloaded_packages' > Updating HTML index of packages in '.Library' > Warning message: > In install.packages("bigmemory") : > installation of package 'bigmemory' had non-zero exit status >> install.packages(gsl) > Error in install.packages(gsl) : object 'gsl' not found >> install.packages(gnulib) > Error in install.packages(gnulib) : object 'gnulib' not found > > > I am using the GNU compiler version 4.5.1 from blastwave on a Solaris 10 > box. > I can't seem to find how to compile bigmembory successfully. I can complile > and add > other packages. See http://cran.r-project.org/web/checks/check_results_bigmemory.html and find it also fails the Solaris based CRAN checks. Hence please report to the package maintainer directly, since reports from CRAN maintainers and the CRAN results are obviously ignored. Best, Uwe Ligges > > roger > > -- > View this message in context: http://r.789695.n4.nabble.com/Error-adding-Bigmemory-package-tp4124863p4124863.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From ravi.kulk at gmail.com Thu Dec 1 10:10:18 2011 From: ravi.kulk at gmail.com (Ravi Kulkarni) Date: Thu, 1 Dec 2011 01:10:18 -0800 (PST) Subject: [R] References for book "R In Action" by Kabacoff Message-ID: <1322730618592-4127625.post@n4.nabble.com> I know this is not really an R question - it is a query about a recent book on R ("R In Action") by Robert Kabacoff, (Manning Publications 2011). There are many references to interesting topics in R in the book, BUT, I do not find a bibliography/list of references in the book! Does anybody know if there are errata for the book available some place? Thanks, Ravi -- View this message in context: http://r.789695.n4.nabble.com/References-for-book-R-In-Action-by-Kabacoff-tp4127625p4127625.html Sent from the R help mailing list archive at Nabble.com. From ligges at statistik.tu-dortmund.de Thu Dec 1 10:48:45 2011 From: ligges at statistik.tu-dortmund.de (Uwe Ligges) Date: Thu, 01 Dec 2011 10:48:45 +0100 Subject: [R] References for book "R In Action" by Kabacoff In-Reply-To: <1322730618592-4127625.post@n4.nabble.com> References: <1322730618592-4127625.post@n4.nabble.com> Message-ID: <4ED74D7D.2050205@statistik.tu-dortmund.de> On 01.12.2011 10:10, Ravi Kulkarni wrote: > I know this is not really an R question - it is a query about a recent book > on R ("R In Action") by Robert Kabacoff, (Manning Publications 2011). > There are many references to interesting topics in R in the book, BUT, I do > not find a bibliography/list of references in the book! > Does anybody know if there are errata for the book available some place? I'd ask the author! Uwe Ligges > Thanks, > Ravi > > -- > View this message in context: http://r.789695.n4.nabble.com/References-for-book-R-In-Action-by-Kabacoff-tp4127625p4127625.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From petr.pikal at precheza.cz Thu Dec 1 10:48:55 2011 From: petr.pikal at precheza.cz (Petr PIKAL) Date: Thu, 1 Dec 2011 10:48:55 +0100 Subject: [R] Odp: R code In-Reply-To: References: Message-ID: Hi > > Hi everybody, > > I am unable to resolve this error using the following for loop. Would > appreciate help. The same loop works with for(i in 1:92) strangely. I > checked the .raw input file and everything is kosher, even Line 547 > mentioned in the error message. > > I wonder if there is any problem with the paste function. I do not believe it. In that case the message will be, that R can not open the file. You speak about input file but actually you are reading 93 files. Which one is wrong? Did you check that one? And how did you checked it? There could be some unseen characters in this row. Without some more info I doubt you get any better advice. Petr > > Thanks very much in advance. > > > ********************** > for(i in 1:93) > { > inputdta<- read.table(file=gsub(" ","",paste("JSR_network_[",i,"].RAW"), > fixed=TRUE), header=TRUE) > colnames(inputdta) <- c("jsrid","firmid","jsrstart","injsr") > print(nrow(inputdta)) > } > > *************** > Message: Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, > na.strings, : line 547 did not have 4 elements > > > -- > View this message in context: http://r.789695.n4.nabble.com/R-code- > tp4125904p4125904.html > Sent from the R help mailing list archive at Nabble.com. > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From ligges at statistik.tu-dortmund.de Thu Dec 1 10:54:05 2011 From: ligges at statistik.tu-dortmund.de (Uwe Ligges) Date: Thu, 01 Dec 2011 10:54:05 +0100 Subject: [R] how "big" (in RAM and/or disk storage) is each of these objects in a list? In-Reply-To: <20111126113623.63d9a77c@draco> References: <20111126113623.63d9a77c@draco> Message-ID: <4ED74EBD.1010109@statistik.tu-dortmund.de> On 26.11.2011 20:36, John wrote: > On Sat, 26 Nov 2011 12:41:08 -0600 > Paul Johnson wrote: > >> Greetings, friends (and others :) ) >> >> We generated a bunch of results and saved them in an RData file. We >> can open, use, all is well, except that the size of the saved file is >> quite a bit larger than we expected. I suspect there's something >> floating about in there that one of the packages we are using puts in, >> such as a spare copy of a data frame that is saved in some subtle way >> that has escaped my attention. >> >> Consider a list of objects. Are there ways to do these things: >> >> 1. ask R how much memory is used by the things inside the list? A bit late, but hopefully still helpful: See ?object.size and particularly note Associated space (e.g. the environment of a function and what the pointer in a ?EXTPTRSXP? points to) is not included in the calculation. >> 2. Does "as.expression(anObject)" print everything in there? Or, is >> there a better way to convert each thing to text or some other format >> that you can actually read line by line to see what is in there, to >> "see" everything? See ?dump and also carefully read the notes. >> >> If there's no giant hidden data frame floating about, I figure I'll >> have to convert symmetric matrices to lower triangles or such to save >> space. Unless R already is automatically saving a matrix in that way >> but just showing me the full matrix, which I suppose is possible. If >> you have other ideas about general ways to make saved objects smaller, >> I'm open for suggestions. Look carefully for environments attached to one or more of the objects. Best, Uwe Ligges >> > > As an initial step, what is the result of running ls() with your RData > file loaded? You should get a list of what is in memory. Using RData > files can be as space-efficient or costly as the user's habits. Did you > use save() or the save.image() command to produce the file? The > save.image() command stashes what is in memory and if you've run a > number of experimental procedures that did not pan out and you did not > discard with the results with rm(), they were saved to the rdata file > along with the information you did want, a procedure rather like filing > away all your work in a file drawer and then emptying the waste basket > into the drawer as well. If you save the data with ascii = TRUE as an > option, you can troll through the file and read what you saved. > > JWD > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From jholtman at gmail.com Thu Dec 1 11:01:48 2011 From: jholtman at gmail.com (Jim Holtman) Date: Thu, 1 Dec 2011 05:01:48 -0500 Subject: [R] R code In-Reply-To: References: Message-ID: <631A98B7-2288-4548-AD21-4B3979F9BCAF@gmail.com> the problem might be a missing quote. Try quote = '' Or it might be a comment character, so try comment.char = '' This happens a lot if your data is not clean Sent from my iPad On Nov 30, 2011, at 19:48, nsaraf wrote: > ) From ashimkapoor at gmail.com Thu Dec 1 11:22:42 2011 From: ashimkapoor at gmail.com (Ashim Kapoor) Date: Thu, 1 Dec 2011 15:52:42 +0530 Subject: [R] Drawing ticks in the 3rd and 4th row of a lattice In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From nalimilan at club.fr Thu Dec 1 12:08:01 2011 From: nalimilan at club.fr (Milan Bouchet-Valat) Date: Thu, 01 Dec 2011 12:08:01 +0100 Subject: [R] "Non-finite finite-difference value" error in eha's aftreg In-Reply-To: References: <1321452360.13624.2.camel@milan> Message-ID: <1322737682.7835.17.camel@milan> Le mercredi 30 novembre 2011 ? 18:41 +0100, G?ran Brostr?m a ?crit : > On Wed, Nov 16, 2011 at 3:06 PM, Milan Bouchet-Valat > wrote: > Hi list! > > > I'm getting an error message when trying to fit an accelerated > failure > time parametric model using the aftreg() function from package > eha: > > Error in optim(beta, Fmin, method = "BFGS", control = > list(trace = > > as.integer(printlevel)), : > > non-finite finite-difference value [2] > > This only happens when adding four specific covariates at the > same time > in the model (see below). I understand that kind of problem > can come > from a too high correlations between my covariates, but is > there > anything I can do to avoid it? > > Yes, remove one (or more) covariate(s). The design matrix is almost > certainly singular. Ah, thanks, that's what I feared. ;-) What do you mean, though, by "almost"? Is there a way to measure that? > Does something need to be improved in aftreg.fit? > > Yes, error messages. I'll look at it. Cool. It's always good to get a clear message saying that you're asking for something impossible, so that you don't try to fix it (like I did). Regards > My data set is constituted of 34,505 observations (years) of 2,717 > individuals, which seems reasonable to me to fit a complex model like > that (covariates are all factors with less than 10 levels). > I can send > it by private mail if somebody wants to help debugging this. > > The details of the model and errors follow, but feel free to ask for > more testing. I'm using R 2.13.1 (x86_64-redhat-linux-gnu), eha 2.0-5 > and survival 2.36-9. > > > Thanks for your help! > > > > m <-aftreg(Surv(start, end, event) ~ homo1 + sexego + dipref1 > + + t.since.school.q, > + data=ms, dist="loglogistic", id=ident) > Error in optim(beta, Fmin, method = "BFGS", control = list(trace = > as.integer(printlevel)), : > non-finite finite-difference value [2] > Calls: aftreg -> aftreg.fit -> aftp0 -> optim > > > traceback() > 4: optim(beta, Fmin, method = "BFGS", control = list(trace = > as.integer(printlevel)), > hessian = TRUE) > 3: aftp0(printlevel, ns, nn, id, strata, Y, X, offset, dis, means) > 2: aftreg.fit(X, Y, dist, strats, offset, init, shape, id, control, > center) > 1: aftreg(Surv(start, end, event) ~ homo1 + sexego + dipref1 + > t.since.school.q, data = ms, dist = "loglogistic", id = ident) > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > > > -- > G?ran Brostr?m > From hwborchers at googlemail.com Thu Dec 1 12:13:49 2011 From: hwborchers at googlemail.com (Hans W Borchers) Date: Thu, 1 Dec 2011 12:13:49 +0100 Subject: [R] x, y for point of intersection In-Reply-To: References: Message-ID: Monica has sent me some data and code for taking a quick look. As it turned out, there was a simple programming error on her side. The segm_distance() function in package 'pracma' is working correctly. And there is no minimization procedure in here, it simply solves some equations from plane geometry. Maybe the function suggested by Don is faster, I haven't checked that. Regards, Hans Werner 2011/11/29 Monica Pisica > > Hi again, > > Working with my real data and not with the little example i sent to the list i discovered that segm_distance function from package "pracma" does not converge to 0 in all cases, even if i increase the number of iteration to 10,000 for example. It seems that it depends on the "initialization" point - most like a minimization function. > > So my thanks? go to Don who's suggestion works for the real data as well without any problems - so far ;-) He suggested to use the function crossing.psp from package "spatstat". > > Thanks again to all who have answered and helped to solve my problem. I certainly learned few new things. > > Monica > > > > > > > From: macqueen1 at llnl.gov > > To: pisicandru at hotmail.com > > CC: r-help at r-project.org > > Date: Wed, 23 Nov 2011 14:03:42 -0800 > > > Subject: Re: [R] x, y for point of intersection > > > > The function crossing.psp() in the spatstat package might be of use. > > Here's an excerpt from its help page: > > > > crossing.psp package:spatstat R Documentation > > Crossing Points of Two Line Segment PatternsDescription: > > Finds any crossing points between two line segment patterns. > > Usage: > > crossing.psp(A,B) > > -Don > > > > > > -- > > Don MacQueen > > > > Lawrence Livermore National Laboratory > > 7000 East Ave., L-627 > > Livermore, CA 94550 > > 925-423-1062 > > > From yvonnick.noel at uhb.fr Thu Dec 1 12:37:30 2011 From: yvonnick.noel at uhb.fr (Yvonnick Noel) Date: Thu, 01 Dec 2011 12:37:30 +0100 Subject: [R] SPSS -> R In-Reply-To: References: Message-ID: <4ED766FA.2000807@uhb.fr> Dear Kristi, > Also. can anyone recommend any resources to help SPSS users learn to things in R? You may want to have a look at the R2STATS package, a simple GUI for linear models. Best, Yvonnick Noel University of Brittany Department of Psychology Rennes, France From jjcabrera20 at yahoo.com.mx Thu Dec 1 11:02:47 2011 From: jjcabrera20 at yahoo.com.mx (jjcabrera20) Date: Thu, 1 Dec 2011 02:02:47 -0800 (PST) Subject: [R] Raster manipulation in R Message-ID: <1322733767614-4127768.post@n4.nabble.com> Hello everyone in the forum For introducing myself I would say I have a basic knowledge of R. Now I am intended to implement a flood algorithm using R. I have some MatLab experience doing these, and as an example to explain more or less what I want, I have a m code to calculate the slope from a Digital elevation model: slope=zeros(row,col); for i=2:row-1 for j=2:col-1 dzdx=(raster(i,j+1)-raster(i,j-1))/(2*res); dzdy=(raster(i+1,j)-raster(i-1,j))/(2*res); slope(i,j)=sqrt(dzdx^2+dzdy^2); end end; The question is to know how to do the similar procedure on R. All suggestions are welcome Thanks All best, Jorge PD:I am using R on windows system 64 bits -- View this message in context: http://r.789695.n4.nabble.com/Raster-manipulation-in-R-tp4127768p4127768.html Sent from the R help mailing list archive at Nabble.com. From benzerfa at gmx.ch Thu Dec 1 10:57:20 2011 From: benzerfa at gmx.ch (Samir Benzerfa) Date: Thu, 1 Dec 2011 10:57:20 +0100 Subject: [R] combining arima and ar function Message-ID: <000601ccb00f$9e403db0$dac0b910$@ch> Hi everyone I've got a problem regarding the arima() and the ar() function for autoregressive series. I would simply like to combine them. To better understand my question, I first show you how I'm using these two functions individually (see file in the attachement). 1) apply(TSX,2, function(x) ar(na.omit(x),method="mle")$order # this function finds the optimal (autoregressive) order for each series (briefly speaking: for each series I get a specific number) 2) apply(TSX,2,function(x)arima(x,order=c(1,0,0))$residuals # this function puts an autoregressive model of order 1 on each series What I'd like to do, is to combine them, such that the resulting orders (numbers) from the first function are used as orders in the second function. So in the specific example attached the results from the first function are 6,5,1 and these numbers should be used as the order in function two. I tried to simply put the two functions together as follows: apply(TSX,2,function(x) arima(x,order=c((apply(TSX,2, function(x)ar(na.omit(x),method="mle")$order))),0,0)) However, I get the error message " 'order' must be a non-negative numeric vector of length 3". Any hints? I hope you can help me with this issue. Many thanks and best regards, S.B. From wendy2.qiao at gmail.com Thu Dec 1 11:27:09 2011 From: wendy2.qiao at gmail.com (Wendy) Date: Thu, 1 Dec 2011 02:27:09 -0800 (PST) Subject: [R] permutate elements in a vector Message-ID: <1322735229427-4127821.post@n4.nabble.com> Hi all, I have a vector, e.g., A = c(10, 20, 30, 40). This 4 numbers have 4! = 24 different combination. I want to generate a matrix with one combination in one row, so the output would be B = 10 20 30 40 10 40 20 30 ... Does anyone know how to do this easily in R? Thank you very much. Wendy -- View this message in context: http://r.789695.n4.nabble.com/permutate-elements-in-a-vector-tp4127821p4127821.html Sent from the R help mailing list archive at Nabble.com. From heather.wright at maine.edu Thu Dec 1 11:46:16 2011 From: heather.wright at maine.edu (hwright) Date: Thu, 1 Dec 2011 02:46:16 -0800 (PST) Subject: [R] R endnote entry In-Reply-To: References: Message-ID: <1322736376118-4127866.post@n4.nabble.com> 1. May I suggest that you try Mendeley for bibliographic management 2. There are also citations for specific R packages when you download each version. Let's use the ade4 package as an example: http://cran.r-project.org/web/packages/ade4/index.html if you selection citation info the corresponding bibtex input has been provided. @Article{, title = {The ade4 package: implementing the duality diagram for ecologists}, author = {S. Dray and A.B. Dufour}, journal = {Journal of Statistical Software}, year = {2007}, volume = {22}, pages = {1-20}, number = {4}, } This is a reliable way to deal with references in other programs ie: LaTeX...etc. I save all my references as bibtex into mendeley and then have a subfolders for R analysis/methods that contain the package citations. Using a .txt (bibtex file made from the ade4 package citation), my inserted citation in a word document from Mendeley looks like this: (R Development Core Team, 2011) and the formal reference in the bibliography is: R Development Core Team. 2011. R: A Language and Environment for Statistical Computing. If however, you are still determined to use endnote, then you have 2 ways to configure your reference, manually add a reference by copy/paste the correct title from the citation, etc. Then configure your .ens style for the appropriate journal, etc. If you insert the citation and it becomes R.D.C.T then it's likely the original input is fine and you have to configure your style output. good luck! ----- ------------------------------- Heather A. Wright, PhD candidate Ecology and Evolution of Plankton Stazione Zoologica Anton Dohrn Villa Comunale 80121 - Napoli, Italy -- View this message in context: http://r.789695.n4.nabble.com/R-endnote-entry-tp4126826p4127866.html Sent from the R help mailing list archive at Nabble.com. From elebrija at hotmail.com Thu Dec 1 12:15:41 2011 From: elebrija at hotmail.com (Edwin) Date: Thu, 1 Dec 2011 03:15:41 -0800 (PST) Subject: [R] I cannot get species scores to plot with site scores in MDS when I use a distance matrix as input. Problems with NA's? In-Reply-To: <1322603094.2726.27.camel@chrysothemis.geog.ucl.ac.uk> References: <1322603094.2726.27.camel@chrysothemis.geog.ucl.ac.uk> Message-ID: <1322738141376-4127949.post@n4.nabble.com> Dear Gavin, Thanks a lot for your reply. I am still not sure if your suggestion can help me or not because I have got different types of errors while trying it. I have tried my best to troubleshoot them and made some progress, but I have reached a dead end (I don?t know how to go on). Below I am copping my TinnR script. It contains not only the R script but also the errors returned in the R console. I apologize that the script is still not really reproducible but I just do not know how to create a sample data frame for it. Thanks again for your help. Edwin. ##Load required packages## library(vegan) library(MASS) library (FD) library(dummies) ##Load full table of species traits and taxonomic data## AllTraits<-read.delim("SpeciesTraitsFullTbl.txt",header=T) ##Edit data## row.names(AllTraits)<-AllTraits$species.code TraitsNMDS<-AllTraits[,c(8:12,14:18,23,25,30)] ##Check variable class using function "allClass" from http://gettinggeneticsdone.blogspot.com/2010 /08/quickly-find-class-of-dataframe-vectors.html## allClass <- function(x) {unlist(lapply(unclass(x),class))} allClass(TraitsNMDS) ##Change variables to fulfill requirements for gowdis() function## #Define ordinal variables# TraitsNMDS$leaf.type<-ordered(TraitsNMDS$leaf.type, levels = c("simple", "pinnate", "bipinnate")) TraitsNMDS$dispersal.rank<-ordered(TraitsNMDS$dispersal.rank, levels = c("s_disp","m_disp","l_disp")) # 0, wascores) && any(comm < 0)) { : missing value where TRUE/FALSE needed'## #Set autotransform, noshare and wascores to FALSE (even if TRUE is desired) to see if problems is with metaMDS function# WrapTest2<-metaMDS(TraitsNMDS, distfun = wrapper, x=TraitsNMDS, asym.bin = "heterospory", ord= "podani", autotransform =FALSE, noshare = FALSE, wascores = FALSE) #Returned error: 'Error in FUN(X[[1L]], ...) : only defined on a data frame with all numeric variables'# #transform factors to dummies and numeric# TraitsNMDSCompleteDumm<-dummy.data.frame(TraitsNMDSComplete, c("leaf.type","dispersal.rank")) TraitsNMDSCompleteDumm$leaf.typesimple<-as.numeric(TraitsNMDSCompleteDumm$leaf.typesimple) TraitsNMDSCompleteDumm$leaf.typepinnate<-as.numeric(TraitsNMDSCompleteDumm$leaf.typepinnate) TraitsNMDSCompleteDumm$leaf.typebipinnate<-as.numeric(TraitsNMDSCompleteDumm$leaf.typebipinnate) TraitsNMDSCompleteDumm$dispersal.ranks_disp<-as.numeric(TraitsNMDSCompleteDumm$dispersal.ranks_disp) TraitsNMDSCompleteDumm$dispersal.rankm_disp<-as.numeric(TraitsNMDSCompleteDumm$dispersal.rankm_disp) TraitsNMDSCompleteDumm$dispersal.rankl_disp<-as.numeric(TraitsNMDSCompleteDumm$dispersal.rankl_disp) ##Re-test wrapping function## WrapTest3<-metaMDS(TraitsNMDSCompleteDumm, distfun = wrapper, x=TraitsNMDSCompleteDumm,asym.bin = "heterospory", ord = "podani") #The function runs but returns an error related to the gowdis() function after the transformation of the data is done: #'Square root transformation Wisconsin double standardization. Error in gowdis(x, ...) : w needs to be a numeric vector of length = number of variables in x' # But testing the wrapper alone does work!# DistMatrixWrapper<-wrapper(x=TraitsNMDSCompleteDumm,asym.bin = "heterospory", ord = "podani") class(DistMatrixWrapper) [1] "dist" # I do not know why the error is produced -- View this message in context: http://r.789695.n4.nabble.com/I-cannot-get-species-scores-to-plot-with-site-scores-in-MDS-when-I-use-a-distance-matrix-as-input-Pr-tp4103699p4127949.html Sent from the R help mailing list archive at Nabble.com. From miseno77 at hotmail.com Thu Dec 1 12:34:25 2011 From: miseno77 at hotmail.com (lincoln) Date: Thu, 1 Dec 2011 03:34:25 -0800 (PST) Subject: [R] Resampling with replacement on a binary (0, 1) dataset to get Cis Message-ID: <1322739265192-4127990.post@n4.nabble.com> ...is it possible to do that? I apologize for something that must be a very trivial question for most of you but, unfortunately, it is not for me. A binary variable is measured, say, 50 times each year during 10 year. My interest is focused on the percentage of 1s with respect to the total if each year. There is no way to repeat those measure within each year and getting the CIs by the "normal way". By the way, it would be important to get even a rough estimate of the CIs of these estimates (/n/1//n/1+/n/0). In case this is not a blasphemy, how might be done in R? Thanks in advance for any help -- View this message in context: http://r.789695.n4.nabble.com/Resampling-with-replacement-on-a-binary-0-1-dataset-to-get-Cis-tp4127990p4127990.html Sent from the R help mailing list archive at Nabble.com. From matteo.richiardi at unito.it Thu Dec 1 12:34:49 2011 From: matteo.richiardi at unito.it (Matteo Richiardi) Date: Thu, 1 Dec 2011 12:34:49 +0100 Subject: [R] efficient ways to dynamically grow a dataframe Message-ID: Hi, I'm trying to write a small microsimulation in R: that is, I have a dataframe with info on N individuals for the base-year and I have to grow it dynamically for T periods: df = data.frame( id = 1:N, x =.... ) The most straightforward way to solve the problem that came to my mind is to create for every period a new dataframe: for(t in 1:T){ for(i in 1:N){ row = data.frame( id = i, t = t, x = ... ) df = rbind(df,row) } } This is very inefficient and my pc gets immediately stucked as N is raised above some thousands. As an alternative, I created an empty dataframe for all the projected periods, and then filled it: df1 = data.frame( id = rep(1:N,T), t = rep(1:T, each = N), x = rep(NA,N*T) ) for(t in 1:T){ for(i in 1:N){ x = ... df1[df1$id==i & df1$t==t,"x"] = x } } df = rbind(df,df1) This is also too slow, and my PC gets stucked. I don't want to go for a matrix, because I'd loose the column names and everything will become too much error-prone. Any suggestions on how to do it? Thanks in advance, Matteo -- Matteo Richiardi University of Turin Faculty of Law Department of Economics "Cognetti De Martiis" via Po 53, 10124 Torino Email: matteo.richiardi at unito.it Tel. +39 011 670 3870 Web page: http://www.personalweb.unito.it/matteo.richiardi/ From void1999 at gmail.com Thu Dec 1 12:51:27 2011 From: void1999 at gmail.com (zz dd) Date: Thu, 1 Dec 2011 12:51:27 +0100 Subject: [R] nipals in the chemometrics package in R Message-ID: Hello i need some precision about nipals in the chemometrics package in R . When i use nipals in chemometrics i obtain T and P matrix. I really don't understand what to do with these two matrix to obtain the scores for every the component (like in spss fo example) Comp1 Comp2 Comp3 quest1 0,8434 0,54333 0,3466 quest2 0,665 0,7655 0,433 Thank you very much for your help (I know that X=TP+E)... But don't understand else.... From jonasjae at pik-potsdam.de Thu Dec 1 13:14:32 2011 From: jonasjae at pik-potsdam.de (=?ISO-8859-1?Q?Jonas_J=E4germeyr?=) Date: Thu, 01 Dec 2011 13:14:32 +0100 Subject: [R] How to speed up int2bin conversion? Message-ID: <4ED76FA8.7030007@pik-potsdam.de> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From sarah.goslee at gmail.com Thu Dec 1 13:18:15 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Thu, 1 Dec 2011 07:18:15 -0500 Subject: [R] Bayesian Quantile regression installation In-Reply-To: References: <1322568957812-4118947.post@n4.nabble.com> Message-ID: Please send your questions to the R-help list, and not directly to me. You provide your OS this time, but not any of the other information requested in the posting guide, like your version of R. What you did would be nice too. Used the menu option? Or used install.packages() at the command line? If this is an internet-enabled computer, the latter is by far the easiest option: it will download and install the package for you. On Thu, Dec 1, 2011 at 6:34 AM, kalam narendar reddy wrote: > Dear?Sarah Goslee, > The following?i sthe error if i tried to?use the install packages from > local?zip files ven though i have loacated the?bayesQR_1.3 which is > ?winRAR zip archieve? fie. > ?Error in read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) > : > ? cannot open the connection > In addition: Warning message: > In read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) : > ? cannot open compressed file 'bayesQR_1.3(1)/DESCRIPTION', probable reason > 'No such file or directory' The filename shown here is not the one that's in the CRAN archive - did you try to download it more than once? That may confuse Windows, I don't know. I don't use Windows (another reason you shouldn't be emailing me directly). But try renaming it without the (1) and see if that works. > tell me what is the reason for it. i have tried to install the package from > local zip file(binary version for windows of bayesian quantile regression > ).my os is windows7 and i have followed the procedure as it is told in the > manual for windows for package installation.still i am unanle to install.pls > understand my problem. > thanks in advance for your kind reply.pls reply as early as possible. > Sarah From jfox at mcmaster.ca Thu Dec 1 13:18:20 2011 From: jfox at mcmaster.ca (John Fox) Date: Thu, 1 Dec 2011 07:18:20 -0500 Subject: [R] FIML with missing data in sem package In-Reply-To: References: Message-ID: <000d01ccb023$510f1a70$f32d4f50$@mcmaster.ca> Dear Dustin, > -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Dustin Fife > Sent: November-30-11 9:51 PM > To: r-help at r-project.org > Subject: [R] FIML with missing data in sem package > > Is there a way to use full information maximum likelihood (FIML) to > estimate missing data in the sem package? For example, suppose I have a > dataset with complete information on X1-X3, but missing data (MAR) on > X4. > Is there a way to use FIML in this case? I know lavaan and openmx allow No, the sem package doesn't handle missing data. You could, however, use another package, such as mice, for multiple imputation of the missing data. Best, John -------------------------------- John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox > you to do it, but I couldn't find anything in the documentation for the > sem package. Thanks! > > -- > Dustin Fife > Graduate Student > Quantitative Psychology > University of Oklahoma > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. From jayemerson at gmail.com Thu Dec 1 13:45:36 2011 From: jayemerson at gmail.com (Jay Emerson) Date: Thu, 1 Dec 2011 07:45:36 -0500 Subject: [R] bigmemory on Solaris Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From bhh at xs4all.nl Thu Dec 1 14:05:58 2011 From: bhh at xs4all.nl (Berend Hasselman) Date: Thu, 1 Dec 2011 05:05:58 -0800 (PST) Subject: [R] permutate elements in a vector In-Reply-To: <1322735229427-4127821.post@n4.nabble.com> References: <1322735229427-4127821.post@n4.nabble.com> Message-ID: <1322744758343-4128227.post@n4.nabble.com> Wendy wrote > > Hi all, > > I have a vector, e.g., A = c(10, 20, 30, 40). This 4 numbers have 4! = 24 > different combination. I want to generate a matrix with one combination in > one row, so the output would be > > B = > 10 20 30 40 > 10 40 20 30 > ... > > Does anyone know how to do this easily in R? Thank you very much. > > Wendy > You want permutations not combinations. library(e1071) permutations(4) * 10 or library(gtools) A <- 10*(1:4) permutations(4,4,A) Berend -- View this message in context: http://r.789695.n4.nabble.com/permutate-elements-in-a-vector-tp4127821p4128227.html Sent from the R help mailing list archive at Nabble.com. From mayer at psychologie.tu-dresden.de Thu Dec 1 14:24:47 2011 From: mayer at psychologie.tu-dresden.de (=?iso-8859-1?b?UmVu6Q==?= Mayer) Date: Thu, 01 Dec 2011 14:24:47 +0100 Subject: [R] how to get inflection point in binomial glm Message-ID: <20111201142447.202239j1pkf17h9b@psy2.psych.tu-dresden.de> Dear All, I have a binomial response with one continuous predictor (d) and one factor (g) (8 levels dummy-coded). glm(resp~d*g, data, family=binomial) Y=b0+b1*X1+b2*X2 ... b7*X7 how can I get the inflection point per group, e.g., P(d)=.5 I would be grateful for any help. Thanks in advance, Ren? From jvadams at usgs.gov Thu Dec 1 14:27:43 2011 From: jvadams at usgs.gov (Jean V Adams) Date: Thu, 1 Dec 2011 07:27:43 -0600 Subject: [R] Raster manipulation in R In-Reply-To: <1322733767614-4127768.post@n4.nabble.com> References: <1322733767614-4127768.post@n4.nabble.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From dwinsemius at comcast.net Thu Dec 1 14:34:11 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Thu, 1 Dec 2011 08:34:11 -0500 Subject: [R] Resampling with replacement on a binary (0, 1) dataset to get Cis In-Reply-To: <1322739265192-4127990.post@n4.nabble.com> References: <1322739265192-4127990.post@n4.nabble.com> Message-ID: <69C9F7F8-E011-470C-B89D-D21611ED0FA4@comcast.net> On Dec 1, 2011, at 6:34 AM, lincoln wrote: > ...is it possible to do that? > > I apologize for something that must be a very trivial question for > most of > you but, unfortunately, it is not for me. > A binary variable is measured, say, 50 times each year during 10 > year. My > interest is focused on the percentage of 1s with respect to the > total if > each year. > There is no way to repeat those measure within each year and getting > the CIs > by the "normal way". > By the way, it would be important to get even a rough estimate of > the CIs of > these estimates (/n/1//n/1+/n/0). > > In case this is not a blasphemy, how might be done in R? ?prop.test > > Thanks in advance for any help > David Winsemius, MD West Hartford, CT From ckluss at email.uni-kiel.de Thu Dec 1 14:34:14 2011 From: ckluss at email.uni-kiel.de (=?ISO-8859-1?Q?Christof_Klu=DF?=) Date: Thu, 1 Dec 2011 14:34:14 +0100 Subject: [R] simplify source code In-Reply-To: References: Message-ID: <4ED78256.2030801@email.uni-kiel.de> Hi now I'd like to do for (colname in c('ColName1','ColName2','ColName3')) { dat <- measurements$colname But that does not work, though I can write measurements$"C1" (same as measurements$C1) (but different to measurements["C1"]!) Can you give me a hint? greetings Christof Am 26-11-2011 23:30, schrieb Christof Klu?: > Hi > > I would like to shorten > > mod1 <- nls(ColName2 ~ ColName1, data = table, ...) > mod2 <- nls(ColName3 ~ ColName1, data = table, ...) > mod3 <- nls(ColName4 ~ ColName1, data = table, ...) > ... > > is there something like > > cols = c(ColName2,ColName3,ColName4,...) > > for i in ... > mod[i-1] <- nls(ColName[i] ~ ColName1, data = table, ...) > > I am looking forward to help > > Christof > From ckluss at email.uni-kiel.de Thu Dec 1 14:34:14 2011 From: ckluss at email.uni-kiel.de (=?ISO-8859-1?Q?Christof_Klu=DF?=) Date: Thu, 1 Dec 2011 14:34:14 +0100 Subject: [R] simplify source code In-Reply-To: References: Message-ID: <4ED78256.2030801@email.uni-kiel.de> Hi now I'd like to do for (colname in c('ColName1','ColName2','ColName3')) { dat <- measurements$colname But that does not work, though I can write measurements$"C1" (same as measurements$C1) (but different to measurements["C1"]!) Can you give me a hint? greetings Christof Am 26-11-2011 23:30, schrieb Christof Klu?: > Hi > > I would like to shorten > > mod1 <- nls(ColName2 ~ ColName1, data = table, ...) > mod2 <- nls(ColName3 ~ ColName1, data = table, ...) > mod3 <- nls(ColName4 ~ ColName1, data = table, ...) > ... > > is there something like > > cols = c(ColName2,ColName3,ColName4,...) > > for i in ... > mod[i-1] <- nls(ColName[i] ~ ColName1, data = table, ...) > > I am looking forward to help > > Christof > From jvadams at usgs.gov Thu Dec 1 14:36:39 2011 From: jvadams at usgs.gov (Jean V Adams) Date: Thu, 1 Dec 2011 07:36:39 -0600 Subject: [R] permutate elements in a vector In-Reply-To: <1322735229427-4127821.post@n4.nabble.com> References: <1322735229427-4127821.post@n4.nabble.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From jholtman at gmail.com Thu Dec 1 14:46:39 2011 From: jholtman at gmail.com (jim holtman) Date: Thu, 1 Dec 2011 08:46:39 -0500 Subject: [R] How to speed up int2bin conversion? In-Reply-To: <4ED76FA8.7030007@pik-potsdam.de> References: <4ED76FA8.7030007@pik-potsdam.de> Message-ID: If we assume that you are just convert 8 bits, here is one way with a table lookup. If more than 8 bits, just partition the data and repeat. This sets up a mapping table one time for the lookup. Does 1M in 0.3 seconds on my computer; is this fast enough? > # initialize a matrix with 8 bit binary values > # one time > require(bitops) > b2c <- character(256) > for (i in 0:255){ + b2c[i + 1] <- sprintf("%1d%1d%1d%1d%1d%1d%1d%1d" + , bitAnd(i, 0x80) != 0 + , bitAnd(i, 0x40) != 0 + , bitAnd(i, 0x20) != 0 + , bitAnd(i, 0x10) != 0 + , bitAnd(i, 0x8) != 0 + , bitAnd(i, 0x4) != 0 + , bitAnd(i, 0x2) != 0 + , bitAnd(i, 0x1) != 0 + ) + } > > # create vector with 1M values > x <- as.integer(1:1e6) > > int2bin <- function(val) + { + b2c[bitAnd(val, 0xff) + 1] + } > > system.time(int2bin(x)) user system elapsed 0.31 0.00 0.32 On Thu, Dec 1, 2011 at 7:14 AM, Jonas J?germeyr wrote: > Dear R-help members, > > I'm processing a large amount of MODIS data where quality assessment > information is stored as an integer value for each pixel. I have to > converted this number to an 8 digit binary flag to get access to the > stored quality code (e.g. in2bin(165,8) = 1 0 1 0 0 1 0 1). > > Unfortunately, I did not manage to find a package providing a fast > function to do so. I need to run this on millions of pixels and thus > wrote the following function. > > int2bin <- function(x,ndigits){ > ? ? base <- array(NA, dim=c(length(x), ndigits)) > ? ? for(q in 1:ndigits){ > ? ? ? ? ? base[, ndigits-q+1] <- (x %% 2) > ? ? ? ? ? x <- (x %/% 2) > ? ? ? } > ? ? bin<- apply(base,1,paste,collapse="") > ? ? return(bin) > } > > Since it is still slow, I have to find a way to express this more > elegantly. I'd really appreciate any help. > > Thanking you, with best regards > > Jonas J?germeyr > > Potsdam Institute for Climate Impact Research > Research Domain II > > ? ? ? ?[[alternative HTML version deleted]] > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. From piratamarck at gmail.com Thu Dec 1 14:48:22 2011 From: piratamarck at gmail.com (Marcos Amaris Gonzalez) Date: Thu, 1 Dec 2011 11:48:22 -0200 Subject: [R] Problem installing the package tkrplot In-Reply-To: <1A41EF30-6C24-466E-B46B-F5CBC3E6B94F@gmail.com> References: <1A41EF30-6C24-466E-B46B-F5CBC3E6B94F@gmail.com> Message-ID: Thanks Peter. I was knowing that R had not found the header tk.h file. But i did not where it was. I opened my Manage Packages Synaptic and installed tk-dev and other similar packages, and voila! It work. I coul install tkrplot and the other packages that i was needing. THANKS, for your answer, "This is part of your Linux distribution". On Wed, Nov 30, 2011 at 9:08 PM, peter dalgaard wrote: > > On Nov 30, 2011, at 15:31 , Marcos Amaris Gonzalez wrote: > >> Hello people. My problem is that when I try to install the package >> tkrplot, I got the next problem: > > You seem to be missing the tk.h file. This is, most likely, in a tcl/tk development package that you haven't installed. This is part of your Linux distribution, not R. (You're not telling us which Linux you are running, and it can't be pinpointed any further without that information, but look for something like tk-devel and tcl-devel.) > >> >>> install.packages("tkrplot") >> Installing package(s) into ?/home/marcos/R/i686-pc-linux-gnu-library/2.13? >> (as ?lib? is unspecified) >> probando la URL >> 'http://www.vps.fmvz.usp.br/CRAN/src/contrib/tkrplot_0.0-23.tar.gz' >> Content type 'application/x-gzip' length 39037 bytes (38 Kb) >> URL abierta >> ================================================== >> downloaded 38 Kb >> >> * installing *source* package ?tkrplot? ... >> configure: creating ./config.status >> config.status: creating src/Makevars >> ** libs >> gcc -I/usr/share/R/include -I/usr/include/tcl8.5 -I/usr/include/tcl8.5 >> ? ?-fpic ?-std=gnu99 -O3 -pipe ?-g -c tcltkimg.c -o tcltkimg.o >> tcltkimg.c:2:16: fatal error: tk.h: No existe el fichero o el directorio >> compilation terminated. >> make: *** [tcltkimg.o] Error 1 >> ERROR: compilation failed for package ?tkrplot? >> * removing ?/home/marcos/R/i686-pc-linux-gnu-library/2.13/tkrplot? >> Warning in install.packages : >> ?installation of package 'tkrplot' had non-zero exit status >> >> The downloaded packages are in >> ? ? ? ?/tmp/RtmpHRfZ1k/downloaded_packages? >> >> In this moment I have R version 2.13.2 (2011-09-30). I stayed >> thankfull for the any help. >> >> --- >> Marcos Amaris Gonzalez >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > -- > Peter Dalgaard, Professor, > Center for Statistics, Copenhagen Business School > Solbjerg Plads 3, 2000 Frederiksberg, Denmark > Phone: (+45)38153501 > Email: pd.mes at cbs.dk ?Priv: PDalgd at gmail.com > > > > > > > > > --- Marcos Amaris Gonzalez From rab45 at pitt.edu Thu Dec 1 14:50:35 2011 From: rab45 at pitt.edu (Rick Bilonick) Date: Thu, 01 Dec 2011 08:50:35 -0500 Subject: [R] FIML with missing data in sem package In-Reply-To: <000d01ccb023$510f1a70$f32d4f50$@mcmaster.ca> References: <000d01ccb023$510f1a70$f32d4f50$@mcmaster.ca> Message-ID: <4ED7862B.6050103@pitt.edu> On 12/01/2011 07:18 AM, John Fox wrote: > > To:r-help at r-project.org > > Subject: [R] FIML with missing data in sem package > > You should check out the OpenMx R package. Just search for OpenMx and SEM. You can download from the web site. It does FIML and is an excellent SEM package. Rick B . From jholtman at gmail.com Thu Dec 1 14:53:14 2011 From: jholtman at gmail.com (jim holtman) Date: Thu, 1 Dec 2011 08:53:14 -0500 Subject: [R] simplify source code In-Reply-To: <4ED78256.2030801@email.uni-kiel.de> References: <4ED78256.2030801@email.uni-kiel.de> Message-ID: measurements[[colname]] ?'[[' On Thu, Dec 1, 2011 at 8:34 AM, Christof Klu? wrote: > Hi > > now I'd like to do > > for (colname in c('ColName1','ColName2','ColName3')) { > ? ?dat <- measurements$colname > > But that does not work, though I can write > > measurements$"C1" (same as measurements$C1) > (but different to measurements["C1"]!) > > Can you give me a hint? > > greetings > Christof > > > > Am 26-11-2011 23:30, schrieb Christof Klu?: >> >> Hi >> >> I would like to shorten >> >> mod1 <- nls(ColName2 ~ ColName1, data = table, ...) >> mod2 <- nls(ColName3 ~ ColName1, data = table, ...) >> mod3 <- nls(ColName4 ~ ColName1, data = table, ...) >> ... >> >> is there something like >> >> cols = c(ColName2,ColName3,ColName4,...) >> >> for i in ... >> mod[i-1] <- nls(ColName[i] ~ ColName1, data = table, ...) >> >> I am looking forward to help >> >> Christof >> > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. From narendarcse007 at gmail.com Thu Dec 1 14:12:16 2011 From: narendarcse007 at gmail.com (narendarreddy kalam) Date: Thu, 1 Dec 2011 05:12:16 -0800 (PST) Subject: [R] hi all.regarding quantile regression results.. Message-ID: <1322745136019-4128248.post@n4.nabble.com> i know this is not about R. After applying quantile regression with t=0.5,0.6 on the data set WBC( Wisconsin Breast Cancer)with 678 observations and 9 independent variables(inp1,inp2,...inp9) and 1 dependent variable(op) i have got the following results for beta values. when t=0.5(median regression) beta values b1=0.002641,b2=0.045746,b3=0. 005282,b4=0.004397,b5=0.002641,b6=0.065807,b7=0.005282 ,b8=0.031394,b9=0.004993 and intercept is -0.181388 and when t=0.6 beta values are b1=0,b2=0.01,b3=0,b4=-0.002,b5=0.004,b6=0.1111,b7=0.002,b8=0,b9=0 and intercept is -0.009 . sir,how to interpret the above beta coefficients and what do they mean exactly??. t=0.5 means are we considering first 50% of the total data? t=0.6 means are we considering the first 60% of the total data? can we write a equation like y=intercept+b1*inp11+b2*inp29+b3*inp3+b4*inp4+b5*inp5+b6*inp6+b7*inp7+b8*inp8+b9*inp9 as in Linear Regression to calculate the predicted output of y or not?? If we are taking into consideration 5 quantiles of data ,Does it mean that we are dividing data it into 5 parts??which variables i have to consider if the data is to be divided into 5 parts? And i got 5 equations for 5 quantiles, what exactly each equation represents? Can i write single equation for the data set as in mean regression by combining the 5 equations of each quantile. Please reply me. Thanks In advance, With regards Kalam Naerndar Reddy M.Tech(IT), University of Hyderabad. -- View this message in context: http://r.789695.n4.nabble.com/hi-all-regarding-quantile-regression-results-tp4128248p4128248.html Sent from the R help mailing list archive at Nabble.com. From tyler_rinker at hotmail.com Thu Dec 1 14:33:40 2011 From: tyler_rinker at hotmail.com (Tyler Rinker) Date: Thu, 1 Dec 2011 08:33:40 -0500 Subject: [R] References for book "R In Action" by Kabacoff In-Reply-To: <4ED74D7D.2050205@statistik.tu-dortmund.de> References: <1322730618592-4127625.post@n4.nabble.com>, <4ED74D7D.2050205@statistik.tu-dortmund.de> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From aodhanol at gmail.com Thu Dec 1 14:43:37 2011 From: aodhanol at gmail.com (AOLeary) Date: Thu, 1 Dec 2011 05:43:37 -0800 (PST) Subject: [R] Writing a function, want a string argument to define the name of the excel sheet to be called Message-ID: <1322747017324-4128384.post@n4.nabble.com> My question is this: is there a way I can make one of the arguments of the function be a string the user can enter, and then have that be the excel filename? ie, foo <- function(x,y,NAME){ #make a matrix with x rows and y cols M <- matrix(nrow=x,ncol=y) #write the matrix write.table(M, file = "result.csv",append=TRUE, sep = ",") } I've had a look but I couldn't find help for this particular problem and it's one I'd like to solve, so I can change make several excel files to solve the analysis my actual function does. Thank you very much, Aodh?n -- View this message in context: http://r.789695.n4.nabble.com/Writing-a-function-want-a-string-argument-to-define-the-name-of-the-excel-sheet-to-be-called-tp4128384p4128384.html Sent from the R help mailing list archive at Nabble.com. From hanson at depauw.edu Thu Dec 1 14:59:00 2011 From: hanson at depauw.edu (Bryan Hanson) Date: Thu, 1 Dec 2011 08:59:00 -0500 Subject: [R] nipals in the chemometrics package in R In-Reply-To: References: Message-ID: <652A6462-E4D1-4780-9919-D08AD5B0157F@depauw.edu> zz dd: If you want a typical score plot, say PC1 vs PC2, then plot the first and second columns of your score matrix (T) against each other and label the points with the row names (if available) or create a text label from where ever you have this information stored. To get an unlabeled score plot, you could simply do: plot(T[,1], T[,2]) If you are using the package chemometrics, you should take a look at the book that goes with it too: Varmuza and Filzmoser, "Multivariate Statistical Analysis in Chemometrics". If you need more guidance than this, you should probably give us more details about what you are doing. Bryan **************** Prof. Bryan Hanson Dept of Chemistry & Biochemistry DePauw University Greencastle IN 46135 USA academic.depauw.edu/~hanson/deadpezsociety.html github.com/bryanhanson academic.depauw.edu/~hanson/UMP/Index.html On Dec 1, 2011, at 6:51 AM, zz dd wrote: > Hello > i need some precision about nipals in the chemometrics package in R . > > When i use nipals in chemometrics i obtain T and P matrix. > > I really don't understand what to do with these two matrix to obtain > the scores for every the component (like in spss fo example) > > Comp1 Comp2 Comp3 > quest1 0,8434 0,54333 0,3466 > quest2 0,665 0,7655 0,433 > > Thank you very much for your help > (I know that X=TP+E)... But don't understand else.... > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From hanson at depauw.edu Thu Dec 1 15:02:00 2011 From: hanson at depauw.edu (Bryan Hanson) Date: Thu, 1 Dec 2011 09:02:00 -0500 Subject: [R] Writing a function, want a string argument to define the name of the excel sheet to be called In-Reply-To: <1322747017324-4128384.post@n4.nabble.com> References: <1322747017324-4128384.post@n4.nabble.com> Message-ID: <1DE876CE-60DE-46B7-A0AF-CF40B7E9BE12@depauw.edu> Sure, change your example as follows and then you can pass the name properly: foo <- function(x,y,NAME = "filename.csv"){ #make a matrix with x rows and y cols M <- matrix(nrow=x,ncol=y) #write the matrix write.table(M, file = NAME,append=TRUE, sep = ",") } Bryan **************** Prof. Bryan Hanson Dept of Chemistry & Biochemistry DePauw University Greencastle IN 46135 USA academic.depauw.edu/~hanson/deadpezsociety.html github.com/bryanhanson academic.depauw.edu/~hanson/UMP/Index.html On Dec 1, 2011, at 8:43 AM, AOLeary wrote: > My question is this: is there a way I can make one of the arguments of the > function be a string the user can enter, and then have that be the excel > filename? ie, > > foo <- function(x,y,NAME){ > > #make a matrix with x rows and y cols > M <- matrix(nrow=x,ncol=y) > #write the matrix > write.table(M, file = "result.csv",append=TRUE, sep = ",") > } > > I've had a look but I couldn't find help for this particular problem and > it's one I'd like to solve, so I can change make several excel files to > solve the analysis my actual function does. > > Thank you very much, > Aodh?n > > -- > View this message in context: http://r.789695.n4.nabble.com/Writing-a-function-want-a-string-argument-to-define-the-name-of-the-excel-sheet-to-be-called-tp4128384p4128384.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From jholtman at gmail.com Thu Dec 1 15:02:23 2011 From: jholtman at gmail.com (jim holtman) Date: Thu, 1 Dec 2011 09:02:23 -0500 Subject: [R] efficient ways to dynamically grow a dataframe In-Reply-To: References: Message-ID: First, dataframes can be much slower than matrices, for example, if you are changing/accessing values a lot. I would suggest that you use a matrix since is seems that all your values are numeric. Allocate a large empty matrix to start (hopefully as large as you need). If you exceed this, you have the option of 'rbind'ing more empty rows on and continuing. This might depend on how large your final matrix might be (you did not state the boundary conditions). On Thu, Dec 1, 2011 at 6:34 AM, Matteo Richiardi wrote: > Hi, > I'm trying to write a small microsimulation in R: that is, I have a > dataframe with info on N individuals for the base-year and I have to > grow it dynamically for T periods: > > df = data.frame( > ?id = 1:N, > ?x =.... > ) > > The most straightforward way to solve the problem that came to my mind > is to create for every period a new dataframe: > > for(t in 1:T){ > ?for(i in 1:N){ > ?row = data.frame( > ? id = i, > ? t = t, > ? x = ... > ? ) > ? df = rbind(df,row) > ?} > } > > This is very inefficient and my pc gets immediately stucked as N is > raised above some thousands. > As an alternative, I created an empty dataframe for all the projected > periods, and then filled it: > > df1 = data.frame( > ?id = rep(1:N,T), > ?t = rep(1:T, each = N), > ?x = rep(NA,N*T) > ) > > for(t in 1:T){ > ?for(i in 1:N){ > ?x = ... > ?df1[df1$id==i & df1$t==t,"x"] = x > ?} > } > df = rbind(df,df1) > > This is also too slow, and my PC gets stucked. I don't want to go for > a matrix, because I'd loose the column names and everything will > become too much error-prone. > Any suggestions on how to do it? > Thanks in advance, > Matteo > > > > > -- > Matteo Richiardi > University of Turin > Faculty of Law > Department of Economics "Cognetti De Martiis" > via Po 53, 10124 Torino > Email: matteo.richiardi at unito.it > Tel. +39 011 670 3870 > Web page: http://www.personalweb.unito.it/matteo.richiardi/ > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. From dwinsemius at comcast.net Thu Dec 1 15:02:50 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Thu, 1 Dec 2011 09:02:50 -0500 Subject: [R] ordinal data simulation In-Reply-To: <1322723201.36177.YahooMailClassic@web161705.mail.bf1.yahoo.com> References: <1322723201.36177.YahooMailClassic@web161705.mail.bf1.yahoo.com> Message-ID: <6E3EA7EB-29EE-4E0A-8AEC-7D1909C14650@comcast.net> On Dec 1, 2011, at 2:06 AM, yuying shi wrote: > Dear all, > I am doing an ordinal data simulation. I?have a question > regarding the cut off values between categories. Suppose I have > three categories, if I do regression, there should be two cut off > values. I find some simulation code for the ordinal data. However, > they usually only generate a uniform random number and compare the > probability with the random number. That's not a good description of what they are doing. > Could any one be so kind to tell me the rational behind it. I don't > know why we need a random number rather than just two fixed cut > off values. One way to generate a random categorical variable constrained to three values would just be to take a uniform variate on the interval [0,1] and classify it based on whether which of the three segments it is in for 0 < a < b < 1. This really is not an appropriate question for rhelp so you are advised to submit further such questions somewhere they are solicited such as statsexchange.com. -- David Winsemius, MD West Hartford, CT From jon.skoien at jrc.ec.europa.eu Thu Dec 1 15:05:27 2011 From: jon.skoien at jrc.ec.europa.eu (jon.skoien at jrc.ec.europa.eu) Date: Thu, 01 Dec 2011 15:05:27 +0100 Subject: [R] Raster manipulation in R In-Reply-To: References: <1322733767614-4127768.post@n4.nabble.com> Message-ID: <4ED789A7.6060708@jrc.ec.europa.eu> Hi, Alternatively you could have a look at the function "terrain" in the raster package, it can calculate the slope for you using different algorithms, not sure if the one below is included though. For typical spatial requests like this, you could also use the mailing-list r-sig-geo. Cheers, Jon On 01-Dec-11 14:27, Jean V Adams wrote: > jjcabrera20 wrote on 12/01/2011 04:02:47 AM: > >> Hello everyone in the forum >> For introducing myself I would say I have a basic knowledge of R. >> Now I am intended to implement a flood algorithm using R. I have some > MatLab >> experience doing these, and as an example to explain more or less what I >> want, I have a m code to calculate the slope from a Digital elevation > model: >> slope=zeros(row,col); >> for i=2:row-1 >> for j=2:col-1 >> dzdx=(raster(i,j+1)-raster(i,j-1))/(2*res); >> dzdy=(raster(i+1,j)-raster(i-1,j))/(2*res); >> slope(i,j)=sqrt(dzdx^2+dzdy^2); >> end >> end; >> >> The question is to know how to do the similar procedure on R. All >> suggestions are welcome >> Thanks >> >> All best, >> >> Jorge >> PD:I am using R on windows system 64 bits > > If I am interpreting your code correctly (I don't use MatLab myself), > something like this should give you the same result in R: > > # example matrix of heights > raster<- matrix(runif(20, 10, 30), nrow=4, ncol=5) > > # example resolution > res<- 8.5 > > # dimensions of matrix > drast<- dim(raster) > > # for every non-boundary point in the matrix, > # calculate the distances between its adjacent columns (dzdx) and rows > (dzdy) > dzdx<- raster[2:(drast[1]-1), 3:drast[2]] - raster[2:(drast[1]-1), > 1:(drast[2]-2)] > dzdy<- raster[3:drast[1], 2:(drast[2]-1)] - raster[1:(drast[1]-2), > 2:(drast[2]-1)] > > # calculate the slope from these distances and the resolution > slope<- sqrt(dzdx^2 + dzdy^2) / (2*res) > > > Jean > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Jon Olav Sk?ien Joint Research Centre - European Commission Institute for Environment and Sustainability (IES) Global Environment Monitoring Unit Via Fermi 2749, TP 440, I-21027 Ispra (VA), ITALY jon.skoien at jrc.ec.europa.eu Tel: +39 0332 789206 Disclaimer: Views expressed in this email are those of the individual and do not necessarily represent official views of the European Commission. From matt at biostatmatt.com Thu Dec 1 15:18:45 2011 From: matt at biostatmatt.com (Matt Shotwell) Date: Thu, 01 Dec 2011 08:18:45 -0600 Subject: [R] R logo in eps formt In-Reply-To: References: Message-ID: <1322749125.2203.3.camel@pal> See this earlier post for SVG logos: http://tolstoy.newcastle.edu.au/R/e12/devel/10/10/0112.html Using Image Magick, do something like convert logo.svg logo.eps On Thu, 2011-12-01 at 10:56 +0700, Ben Madin wrote: > G'day all, > > Sorry if this message has been posted before, but searching for R is always difficult... > > I was hoping for a copy of the logo in eps format? Can I do this from R, or is one available for download? > > cheers > > Ben > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From fife.dustin at gmail.com Thu Dec 1 15:27:12 2011 From: fife.dustin at gmail.com (Dustin Fife) Date: Thu, 1 Dec 2011 08:27:12 -0600 Subject: [R] FIML with missing data in sem package In-Reply-To: <000d01ccb023$510f1a70$f32d4f50$@mcmaster.ca> References: <000d01ccb023$510f1a70$f32d4f50$@mcmaster.ca> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From rroa at azti.es Thu Dec 1 15:31:08 2011 From: rroa at azti.es (=?iso-8859-1?Q?Rub=E9n_Roa?=) Date: Thu, 1 Dec 2011 15:31:08 +0100 Subject: [R] how to get inflection point in binomial glm In-Reply-To: <20111201142447.202239j1pkf17h9b@psy2.psych.tu-dresden.de> References: <20111201142447.202239j1pkf17h9b@psy2.psych.tu-dresden.de> Message-ID: <5CD78996B8F8844D963C875D3159B94A02DFF6E4@DSRCORREO.azti.local> Assuming a logistic model, for each group solve for d at Y=0, or solve for d at p=0.5, where d is your continuous predictor, Y is the logit score, and p is the probability of success in the binomial model. After that you can get the standard error of the inflection point by Taylor series (aka delta method). Another idea is to re-parameterize the logistic model to include explicitly the inflection point, thus you'll get its estimate and standard error directly as a result of the fit. For example, disregarding the g factor predictor (or for each group), a logistic model such as P(d) = 1/(1+exp(log(1/19)(d-d50)/(d95-d50)) includes the inflection point directly (d50) and is a re-parameterized version of the usual logistic model P(d) =1/(1+exp(b0+b1*d)) where parameters b0 and b1 have been replaced by d95 and d50, the predictor at 50% probability (inflection point), and the predictor at 95% probability, respectively. HTH Rub?n -----Mensaje original----- De: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] En nombre de Ren? Mayer Enviado el: jueves, 01 de diciembre de 2011 14:25 Para: r-help at r-project.org Asunto: [R] how to get inflection point in binomial glm Dear All, I have a binomial response with one continuous predictor (d) and one factor (g) (8 levels dummy-coded). glm(resp~d*g, data, family=binomial) Y=b0+b1*X1+b2*X2 ... b7*X7 how can I get the inflection point per group, e.g., P(d)=.5 I would be grateful for any help. Thanks in advance, Ren? ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. From pisicandru at hotmail.com Thu Dec 1 15:37:09 2011 From: pisicandru at hotmail.com (Monica Pisica) Date: Thu, 1 Dec 2011 14:37:09 +0000 Subject: [R] x, y for point of intersection In-Reply-To: References: , , , Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From michael.weylandt at gmail.com Thu Dec 1 16:43:04 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt ) Date: Thu, 1 Dec 2011 10:43:04 -0500 Subject: [R] hi all.regarding quantile regression results.. In-Reply-To: <1322745136019-4128248.post@n4.nabble.com> References: <1322745136019-4128248.post@n4.nabble.com> Message-ID: This really isn't the appropriate forum for most of your questions: I'd suggest you work through the Wikipedia article on quantiles regression and direct follow up to stats.stackexchange.com. As to the R question: use the predict() function. Michael On Dec 1, 2011, at 8:12 AM, narendarreddy kalam wrote: > i know this is not about R. > After applying quantile regression with t=0.5,0.6 on the data set WBC( > Wisconsin Breast Cancer)with 678 observations and 9 independent > variables(inp1,inp2,...inp9) and 1 dependent variable(op) i have got the > following results for beta values. > > when t=0.5(median regression) beta values b1=0.002641,b2=0.045746,b3=0. > 005282,b4=0.004397,b5=0.002641,b6=0.065807,b7=0.005282 > ,b8=0.031394,b9=0.004993 and intercept is -0.181388 > > and when t=0.6 beta values are > b1=0,b2=0.01,b3=0,b4=-0.002,b5=0.004,b6=0.1111,b7=0.002,b8=0,b9=0 and > intercept is -0.009 . > > sir,how to interpret the above beta coefficients and what do they mean > exactly??. > t=0.5 means are we considering first 50% of the total data? > t=0.6 means are we considering the first 60% of the total data? > can we write a equation like > > > y=intercept+b1*inp11+b2*inp29+b3*inp3+b4*inp4+b5*inp5+b6*inp6+b7*inp7+b8*inp8+b9*inp9 > as in Linear Regression > to calculate the predicted output of y or not?? > > If we are taking into consideration 5 quantiles of data ,Does it mean > that we are dividing data it into 5 parts??which variables i have to > consider if the data is to be divided into 5 parts? > > And > i got 5 equations for 5 quantiles, what exactly each equation represents? > Can i write single equation for the data set as in mean regression by > combining the 5 equations of each quantile. > Please reply me. > > Thanks In advance, > > With regards > > Kalam Naerndar Reddy > M.Tech(IT), > University of Hyderabad. > > -- > View this message in context: http://r.789695.n4.nabble.com/hi-all-regarding-quantile-regression-results-tp4128248p4128248.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From michael.weylandt at gmail.com Thu Dec 1 16:48:12 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Thu, 1 Dec 2011 10:48:12 -0500 Subject: [R] efficient ways to dynamically grow a dataframe In-Reply-To: References: Message-ID: I'd also suggest you read circle 2 of the "R inferno" (just google it) which has some helpful tips on how to deal with these sorts of problems. Also, did you know that matrices can have column names and that rbind() preserves them? E.g., m <- matrix(1:6, 3); colnames(m) <- letters[1:2] print(m) print(rbind(m, c(10, 11))) Michael On Thu, Dec 1, 2011 at 9:02 AM, jim holtman wrote: > First, dataframes can be much slower than matrices, for example, if > you are changing/accessing values a lot. ?I would suggest that you use > a matrix since is seems that all your values are numeric. ?Allocate a > large empty matrix to start (hopefully as large as you need). ?If you > exceed this, you have the option of 'rbind'ing more empty rows on and > continuing. ?This might depend on how large your final matrix might be > (you did not state the boundary conditions). > > On Thu, Dec 1, 2011 at 6:34 AM, Matteo Richiardi > wrote: >> Hi, >> I'm trying to write a small microsimulation in R: that is, I have a >> dataframe with info on N individuals for the base-year and I have to >> grow it dynamically for T periods: >> >> df = data.frame( >> ?id = 1:N, >> ?x =.... >> ) >> >> The most straightforward way to solve the problem that came to my mind >> is to create for every period a new dataframe: >> >> for(t in 1:T){ >> ?for(i in 1:N){ >> ?row = data.frame( >> ? id = i, >> ? t = t, >> ? x = ... >> ? ) >> ? df = rbind(df,row) >> ?} >> } >> >> This is very inefficient and my pc gets immediately stucked as N is >> raised above some thousands. >> As an alternative, I created an empty dataframe for all the projected >> periods, and then filled it: >> >> df1 = data.frame( >> ?id = rep(1:N,T), >> ?t = rep(1:T, each = N), >> ?x = rep(NA,N*T) >> ) >> >> for(t in 1:T){ >> ?for(i in 1:N){ >> ?x = ... >> ?df1[df1$id==i & df1$t==t,"x"] = x >> ?} >> } >> df = rbind(df,df1) >> >> This is also too slow, and my PC gets stucked. I don't want to go for >> a matrix, because I'd loose the column names and everything will >> become too much error-prone. >> Any suggestions on how to do it? >> Thanks in advance, >> Matteo >> >> >> >> >> -- >> Matteo Richiardi >> University of Turin >> Faculty of Law >> Department of Economics "Cognetti De Martiis" >> via Po 53, 10124 Torino >> Email: matteo.richiardi at unito.it >> Tel. +39 011 670 3870 >> Web page: http://www.personalweb.unito.it/matteo.richiardi/ >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > > > -- > Jim Holtman > Data Munger Guru > > What is the problem that you are trying to solve? > Tell me what you want to do, not how you want to do it. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From mkao006rmail at gmail.com Thu Dec 1 16:55:21 2011 From: mkao006rmail at gmail.com (Michael Kao) Date: Thu, 01 Dec 2011 16:55:21 +0100 Subject: [R] round to specific intervals Message-ID: <4ED7A369.4050206@gmail.com> Dear R users/helpers, I am wondering is there an existing function in which you can round numbers to a set of values. I know you can use 5 * round(x/5) for rounding to the nearest 5 or so, but what if the interval size is not constant. For example: ## Not run test <- rnorm(100) round(test, c(1, 5, 10, 20, 50)) so that the test is rounded to the closest value in the vector. Thanks for the help. Cheers, From f.harrell at vanderbilt.edu Thu Dec 1 17:14:58 2011 From: f.harrell at vanderbilt.edu (Frank Harrell) Date: Thu, 1 Dec 2011 08:14:58 -0800 (PST) Subject: [R] Nomogram with stratified cph in rms package, how to get failure probability In-Reply-To: <1322664449417-4123249.post@n4.nabble.com> References: <1322664449417-4123249.post@n4.nabble.com> Message-ID: <1322756098970-4129173.post@n4.nabble.com> Hazard() is not implemented except for parametric survival models. You are not calling nomogram() correctly; in rms the plotting step is separated from the nomogram computations. To plot cumulative event rates do something like: mort10 <- function(lp) 1 - surv(10,lp) and tell nomogram about mort10 using fun=. Frank min wrote > > Hello, > > I am using Dr. Harrell's rms package to make a nomogram. I was able to > make a beautiful one. However, I want to change 5-year survival > probability to 5-year failure probability. > > I couldn?t get hazard rate from Hazard(f1) because I used cph for the > model. > > Here is my code: > > library(rms) > f1 <- cph(Surv(retime,dfs) ~ > age+her2+t_stage+n_stage+er+grade+cytcyt+Cyt_PCDK2 , data=data11, > surv=T, x=T, y=T, time.inc=5) > > surv<- Survival(f1) > haz<- Hazard(f1) > Here is the Error in UseMethod("Hazard") : > no applicable method for 'Hazard' applied to an object of class > "c('cph', 'Design', 'coxph')" > > > surv10 <- function(lp) surv(10,lp) > surv5 <- function(lp) surv(5,lp) > quant <- Quantile(f1) > > at.surv <- c(0.1, 0.3, 0.5, 0.7, 0.9) > > at.med1<-c(2,3,4, 5,6,7,8, 10,15,20,25, 30) > > > par(cex=0.8) > nom<- nomogram(f1, conf.int=F, > fun=list(surv5, surv10), funlabel=c('5-Year Survival Probability', > '10-Year Survival Probability' ), lp=F, > fun.at=c(at.surv, at.surv),label.every=1, force.label=FALSE, cex.axis=0.8, > verbose=TRUE, cex.var=0.8) > > How can I show failure probability instead of survival probability? > > I would very much appreciate any assistance in this matter. > Thank you Very much. > ----- Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/Nomogram-with-stratified-cph-in-rms-package-how-to-get-failure-probability-tp4123249p4129173.html Sent from the R help mailing list archive at Nabble.com. From gunter.berton at gene.com Thu Dec 1 17:17:02 2011 From: gunter.berton at gene.com (Bert Gunter) Date: Thu, 1 Dec 2011 08:17:02 -0800 Subject: [R] round to specific intervals In-Reply-To: <4ED7A369.4050206@gmail.com> References: <4ED7A369.4050206@gmail.com> Message-ID: ?findInterval .. would get you the endpoints and then you could determine which is nearer. Of course in your "example", everything would get "rounded" to 1. -- Bert On Thu, Dec 1, 2011 at 7:55 AM, Michael Kao wrote: > Dear R users/helpers, > > I am wondering is there an existing function in which you can round numbers > to a set of values. I know you can use 5 * round(x/5) for rounding to the > nearest 5 or so, but what if the interval size is not constant. > > For example: > ## Not run > test <- rnorm(100) > round(test, c(1, 5, 10, 20, 50)) > > so that the test is rounded to the closest value in the vector. > > Thanks for the help. > > Cheers, > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm From aodhanol at gmail.com Thu Dec 1 15:10:01 2011 From: aodhanol at gmail.com (AOLeary) Date: Thu, 1 Dec 2011 06:10:01 -0800 (PST) Subject: [R] Writing a function, want a string argument to define the name of the excel sheet to be called In-Reply-To: <1DE876CE-60DE-46B7-A0AF-CF40B7E9BE12@depauw.edu> References: <1322747017324-4128384.post@n4.nabble.com> <1DE876CE-60DE-46B7-A0AF-CF40B7E9BE12@depauw.edu> Message-ID: <1322748601119-4128495.post@n4.nabble.com> Thank you very much, that does exactly what I want it to! :) Aodh?n -- View this message in context: http://r.789695.n4.nabble.com/Writing-a-function-want-a-string-argument-to-define-the-name-of-the-excel-sheet-to-be-called-tp4128384p4128495.html Sent from the R help mailing list archive at Nabble.com. From john-paul.quinn at ncl.ac.uk Thu Dec 1 15:51:55 2011 From: john-paul.quinn at ncl.ac.uk (jpquinn91) Date: Thu, 1 Dec 2011 06:51:55 -0800 (PST) Subject: [R] How to do Hotelling's t2 test? Message-ID: <1322751115231-4128748.post@n4.nabble.com> Hi, I want to do a 2 sample hotelling's test but i can't figure out how. When i type T2.test it says there is no such test and when i tried library(rrcov) it says there is no such program. Cheers. -- View this message in context: http://r.789695.n4.nabble.com/How-to-do-Hotelling-s-t2-test-tp4128748p4128748.html Sent from the R help mailing list archive at Nabble.com. From dyb at noc.ac.uk Thu Dec 1 16:02:20 2011 From: dyb at noc.ac.uk (Berry, David I.) Date: Thu, 1 Dec 2011 15:02:20 +0000 Subject: [R] R, PostgresSQL and poor performance Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From jonasjae at pik-potsdam.de Thu Dec 1 16:16:59 2011 From: jonasjae at pik-potsdam.de (=?ISO-8859-1?Q?Jonas_J=E4germeyr?=) Date: Thu, 01 Dec 2011 16:16:59 +0100 Subject: [R] How to speed up int2bin conversion? In-Reply-To: References: <4ED76FA8.7030007@pik-potsdam.de> Message-ID: <4ED79A6B.5060201@pik-potsdam.de> On 12/01/2011 02:46 PM, jim holtman wrote: > If we assume that you are just convert 8 bits, here is one way with a > table lookup. If more than 8 bits, just partition the data and > repeat. This sets up a mapping table one time for the lookup. Does > 1M in 0.3 seconds on my computer; is this fast enough? > >> # initialize a matrix with 8 bit binary values >> # one time >> require(bitops) >> b2c<- character(256) >> for (i in 0:255){ > + b2c[i + 1]<- sprintf("%1d%1d%1d%1d%1d%1d%1d%1d" > + , bitAnd(i, 0x80) != 0 > + , bitAnd(i, 0x40) != 0 > + , bitAnd(i, 0x20) != 0 > + , bitAnd(i, 0x10) != 0 > + , bitAnd(i, 0x8) != 0 > + , bitAnd(i, 0x4) != 0 > + , bitAnd(i, 0x2) != 0 > + , bitAnd(i, 0x1) != 0 > + ) > + } >> # create vector with 1M values >> x<- as.integer(1:1e6) >> >> int2bin<- function(val) > + { > + b2c[bitAnd(val, 0xff) + 1] > + } >> system.time(int2bin(x)) > user system elapsed > 0.31 0.00 0.32 > > On Thu, Dec 1, 2011 at 7:14 AM, Jonas J?germeyr wrote: >> Dear R-help members, >> >> I'm processing a large amount of MODIS data where quality assessment >> information is stored as an integer value for each pixel. I have to >> converted this number to an 8 digit binary flag to get access to the >> stored quality code (e.g. in2bin(165,8) = 1 0 1 0 0 1 0 1). >> >> Unfortunately, I did not manage to find a package providing a fast >> function to do so. I need to run this on millions of pixels and thus >> wrote the following function. >> >> int2bin<- function(x,ndigits){ >> base<- array(NA, dim=c(length(x), ndigits)) >> for(q in 1:ndigits){ >> base[, ndigits-q+1]<- (x %% 2) >> x<- (x %/% 2) >> } >> bin<- apply(base,1,paste,collapse="") >> return(bin) >> } >> >> Since it is still slow, I have to find a way to express this more >> elegantly. I'd really appreciate any help. >> >> Thanking you, with best regards >> >> Jonas J?germeyr >> >> Potsdam Institute for Climate Impact Research >> Research Domain II >> >> [[alternative HTML version deleted]] >> >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > Great Jim! Thanks a lot. New way of thinking, appreciated. I also need 16 and 32 bit flags and hence I just added those two lines: int2bin16<- function(val) { paste(int2bin(val%/%256),int2bin(val),sep="") } int2bin32<- function(val) { paste(int2bin(val%/%256^3),int2bin(val%/%256^2),int2bin(val%/%256),int2bin(val),sep="") } Best, Jonas J?germeyr Potsdam Institute for Climate Impact Research Research Domain II From golden_boy110 at yahoo.com Thu Dec 1 16:35:04 2011 From: golden_boy110 at yahoo.com ( Majid ) Date: Thu, 1 Dec 2011 07:35:04 -0800 (PST) Subject: [R] vector Message-ID: <1322753704.39854.YahooMailNeo@web113611.mail.gq1.yahoo.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From miseno77 at hotmail.com Thu Dec 1 16:49:09 2011 From: miseno77 at hotmail.com (lincoln) Date: Thu, 1 Dec 2011 07:49:09 -0800 (PST) Subject: [R] Resampling with replacement on a binary (0, 1) dataset to get Cis In-Reply-To: <69C9F7F8-E011-470C-B89D-D21611ED0FA4@comcast.net> References: <1322739265192-4127990.post@n4.nabble.com> <69C9F7F8-E011-470C-B89D-D21611ED0FA4@comcast.net> Message-ID: <1322754549513-4129048.post@n4.nabble.com> Thanks. So, suppose for one specific year (first year over 10) the percentage of successes deriving from 100 trials with 38 successes (and 62 failures), its value would be 38/100=0.38. I could calculate its confidence intervals this way: > success<-38 > total<-100 > prop.test(success,total,p=0.5,alternative="two.sided") 1-sample proportions test with continuity correction data: success out of total, null probability 0.5 X-squared = 5.29, df = 1, p-value = 0.02145 alternative hypothesis: true p is not equal to 0.5 95 percent confidence interval: 0.2863947 0.4829411 sample estimates: p 0.38 So it would be var$1=0.38 , CI=0.286-0.483 Is it correct? -- View this message in context: http://r.789695.n4.nabble.com/Resampling-with-replacement-on-a-binary-0-1-variable-to-get-CIs-tp4127990p4129048.html Sent from the R help mailing list archive at Nabble.com. From myi at mdanderson.org Thu Dec 1 17:17:33 2011 From: myi at mdanderson.org (min) Date: Thu, 1 Dec 2011 08:17:33 -0800 (PST) Subject: [R] Nomogram with stratified cph in rms package, how to get failure probability In-Reply-To: <1322756098970-4129173.post@n4.nabble.com> References: <1322664449417-4123249.post@n4.nabble.com> <1322756098970-4129173.post@n4.nabble.com> Message-ID: <3484DB596CEF284A9948D8A8F121AFC38626886526@DCPWVMBXC0VS3.mdanderson.edu> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From murdoch.duncan at gmail.com Thu Dec 1 17:20:37 2011 From: murdoch.duncan at gmail.com (Duncan Murdoch) Date: Thu, 01 Dec 2011 11:20:37 -0500 Subject: [R] round to specific intervals In-Reply-To: <4ED7A369.4050206@gmail.com> References: <4ED7A369.4050206@gmail.com> Message-ID: <4ED7A955.7040205@gmail.com> On 01/12/2011 10:55 AM, Michael Kao wrote: > Dear R users/helpers, > > I am wondering is there an existing function in which you can round > numbers to a set of values. I know you can use 5 * round(x/5) for > rounding to the nearest 5 or so, but what if the interval size is not > constant. > > For example: > ## Not run > test<- rnorm(100) > round(test, c(1, 5, 10, 20, 50)) > > so that the test is rounded to the closest value in the vector. I think you could put together such a thing using cut(). Duncan Murdoch From jdnewmil at dcn.davis.ca.us Thu Dec 1 17:25:34 2011 From: jdnewmil at dcn.davis.ca.us (Jeff Newmiller) Date: Thu, 01 Dec 2011 08:25:34 -0800 Subject: [R] How to speed up int2bin conversion? In-Reply-To: <4ED76FA8.7030007@pik-potsdam.de> References: <4ED76FA8.7030007@pik-potsdam.de> Message-ID: <61894f42-103d-4bb5-a04c-8d6e6e63a727@email.android.com> You might be interested in package "bit". --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN: Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. "Jonas J?germeyr" wrote: >Dear R-help members, > >I'm processing a large amount of MODIS data where quality assessment >information is stored as an integer value for each pixel. I have to >converted this number to an 8 digit binary flag to get access to the >stored quality code (e.g. in2bin(165,8) = 1 0 1 0 0 1 0 1). > >Unfortunately, I did not manage to find a package providing a fast >function to do so. I need to run this on millions of pixels and thus >wrote the following function. > >int2bin <- function(x,ndigits){ > base <- array(NA, dim=c(length(x), ndigits)) > for(q in 1:ndigits){ > base[, ndigits-q+1] <- (x %% 2) > x <- (x %/% 2) > } > bin<- apply(base,1,paste,collapse="") > return(bin) >} > >Since it is still slow, I have to find a way to express this more >elegantly. I'd really appreciate any help. > >Thanking you, with best regards > >Jonas J?germeyr > >Potsdam Institute for Climate Impact Research >Research Domain II > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. From fife.dustin at gmail.com Thu Dec 1 17:25:36 2011 From: fife.dustin at gmail.com (Dustin Fife) Date: Thu, 1 Dec 2011 10:25:36 -0600 Subject: [R] FIML with missing data in sem package In-Reply-To: References: <000d01ccb023$510f1a70$f32d4f50$@mcmaster.ca> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From andy_liaw at merck.com Thu Dec 1 17:29:55 2011 From: andy_liaw at merck.com (Liaw, Andy) Date: Thu, 1 Dec 2011 11:29:55 -0500 Subject: [R] Random Forests in R In-Reply-To: References: Message-ID: The first version of the package was created by re-writing the main program in the original Fortran as C, and calls other Fortran subroutines that were mostly untouched, so dynamic memory allocation can be done. Later versions have most of the Fortran code translated/re-written in C. Currently the only Fortran part is the node splitting in classification trees. Andy > -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Peter Langfelder > Sent: Thursday, December 01, 2011 12:33 AM > To: Axel Urbiz > Cc: R-help at r-project.org > Subject: Re: [R] Random Forests in R > > On Wed, Nov 30, 2011 at 7:48 PM, Axel Urbiz > wrote: > > I understand the original implementation of Random Forest > was done in > > Fortran code. In the source files of the R implementation > there is a note > > "C wrapper for random forests: ?get input from R and drive ? the Fortran > > routines.". I'm far from an expert on this...does that mean that the > > implementation in R is through calls to C functions only > (not Fortran)? > > > > So, would knowing C be enough to understand this code, or > Fortran is also > > necessary? > > I haven't seen the C and Fortran code for Random Forest but I > understand the note to say that R code calls some C functions that > pre-process (possibly re-format etc) the data, then call the actual > Random Forest method that's written in Fortran, then possibly > post-process the output and return it to R. It would imply that to > understand the actual Random Forest code, you will have to read the > Fortran source code. > > Best, > > Peter > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > Notice: This e-mail message, together with any attachme...{{dropped:11}} From mkao006rmail at gmail.com Thu Dec 1 17:33:01 2011 From: mkao006rmail at gmail.com (Michael Kao) Date: Thu, 01 Dec 2011 17:33:01 +0100 Subject: [R] round to specific intervals In-Reply-To: <4ED7A955.7040205@gmail.com> References: <4ED7A369.4050206@gmail.com> <4ED7A955.7040205@gmail.com> Message-ID: <4ED7AC3D.9070006@gmail.com> Thanks for all the response, I manage to write a small function to complete what I want based on the wonderful helps. iround <- function(x, interval){ ## Round numbers to desired interval ## ## Args: ## x: Numeric vector to be rounded ## interval: The interval the values should be rounded towards. ## Retunrs: ## a numeric vector with x rounded to the desired interval. ## interval[ifelse(x < min(interval), 1, findInterval(x, interval))] } iround(0:100, c(1, 5, 10, 20, 50)) Cheers, and thanks for all the help again. On 1/12/2011 5:20 p.m., Duncan Murdoch wrote: > On 01/12/2011 10:55 AM, Michael Kao wrote: >> Dear R users/helpers, >> >> I am wondering is there an existing function in which you can round >> numbers to a set of values. I know you can use 5 * round(x/5) for >> rounding to the nearest 5 or so, but what if the interval size is not >> constant. >> >> For example: >> ## Not run >> test<- rnorm(100) >> round(test, c(1, 5, 10, 20, 50)) >> >> so that the test is rounded to the closest value in the vector. > > > I think you could put together such a thing using cut(). > > Duncan Murdoch From dwinsemius at comcast.net Thu Dec 1 17:34:59 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Thu, 1 Dec 2011 11:34:59 -0500 Subject: [R] how to get inflection point in binomial glm In-Reply-To: <20111201142447.202239j1pkf17h9b@psy2.psych.tu-dresden.de> References: <20111201142447.202239j1pkf17h9b@psy2.psych.tu-dresden.de> Message-ID: <115F31EC-7960-4157-B70E-A4DB76D5C2DE@comcast.net> On Dec 1, 2011, at 8:24 AM, Ren? Mayer wrote: > Dear All, > > I have a binomial response with one continuous predictor (d) and one > factor (g) (8 levels dummy-coded). > > glm(resp~d*g, data, family=binomial) > > Y=b0+b1*X1+b2*X2 ... b7*X7 Dear Dr Mayer; I think it might be a bit more complex than that. I think you should get 15 betas rather than 8. Have you done it? > > how can I get the inflection point per group, e.g., P(d)=.5 Wouldn't that just be at d=1/beta in each group? (Thinking, perhaps naively, in the case of X=X1 that (Pr[y==1])/(1-Pr[y==1])) = 1 = exp( beta *d*(X==X1) ) # all other terms = 0 And taking the log of both sides, and then use "middle school" math to solve. Oh, wait. Muffed my first try on that for sure. Need to add back both the constant intercept and the baseline "d" coefficient for the non-b0 levels. (Pr[y==1])/(1-Pr[y==1])) = 1 = exp( beta_0 + beta_d_0*d + beta_n + beta_d_n *d*(X==Xn) ) And just (Pr[y==1])/(1-Pr[y==1])) = 1 = exp( beta_0 + beta_d_0*d ) # for the reference level. This felt like an exam question in my categorical analysis course 25 years ago. (Might have gotten partial credit for my first stab, depending on how forgiving the TA was that night.) > > I would be grateful for any help. > > Thanks in advance, > Ren? > -- David Winsemius, MD West Hartford, CT From S.Ellison at LGCGroup.com Thu Dec 1 17:36:09 2011 From: S.Ellison at LGCGroup.com (S Ellison) Date: Thu, 1 Dec 2011 16:36:09 +0000 Subject: [R] How to do Hotelling's t2 test? In-Reply-To: <1322751115231-4128748.post@n4.nabble.com> References: <1322751115231-4128748.post@n4.nabble.com> Message-ID: > Hi, I want to do a 2 sample hotelling's test but i can't > figure out how. When i type T2.test it says there is no such > test and when i tried library(rrcov) it says there is no such > program. Have you installed rrcov using install.packages? S Ellison******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}} From dwinsemius at comcast.net Thu Dec 1 17:38:30 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Thu, 1 Dec 2011 11:38:30 -0500 Subject: [R] Resampling with replacement on a binary (0, 1) dataset to get Cis In-Reply-To: <1322754549513-4129048.post@n4.nabble.com> References: <1322739265192-4127990.post@n4.nabble.com> <69C9F7F8-E011-470C-B89D-D21611ED0FA4@comcast.net> <1322754549513-4129048.post@n4.nabble.com> Message-ID: On Dec 1, 2011, at 10:49 AM, lincoln wrote: > Thanks. > > So, suppose for one specific year (first year over 10) the > percentage of > successes deriving from 100 trials with 38 successes (and 62 > failures), its > value would be 38/100=0.38. > I could calculate its confidence intervals this way: >> success<-38 >> total<-100 >> prop.test(success,total,p=0.5,alternative="two.sided") > > 1-sample proportions test with continuity > correction > > data: success out of total, null probability 0.5 > X-squared = 5.29, df = 1, p-value = 0.02145 > alternative hypothesis: true p is not equal to 0.5 > 95 percent confidence interval: > 0.2863947 0.4829411 > sample estimates: > p > 0.38 > > So it would be var$1=0.38 , CI=0.286-0.483 > > Is it correct? > I couldn't tell if this were homework, so I just threw out a starting point. If you were told to do a resampling method then this would just be a starting point and you would be expected to go further with the boot function. > -- > View this message in context: http://r.789695.n4.nabble.com/Resampling-with-replacement-on-a-binary-0-1-variable-to-get-CIs-tp4127990p4129048.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT From emorway at usgs.gov Thu Dec 1 17:54:42 2011 From: emorway at usgs.gov (emorway) Date: Thu, 1 Dec 2011 08:54:42 -0800 (PST) Subject: [R] legend, "lheight", and alignment Message-ID: <1322758482556-4129402.post@n4.nabble.com> Hello, A bit of fairly simple code, yet I don't seem to be able to manipulate it quite as much as I would like: 1) It would be nice if the objects appearing in the legend were aligned, and by aligned I mean the boxes are centered over the lines. Do I need to adjust the use of "NA" in the code below to accomplish this? Here's how it appears on my machine: http://r.789695.n4.nabble.com/file/n4129402/example.png 2) Because I'm using a call to 'expression' in the text contained in the legend, it would be nice to space the lines of text a bit more. My feeble attempt was to increase the lheight parameter in the hopes this would affect the legend...to no avail. Further, lheight cannot be added to the argument list of legend. I've been unable to track down another parameter applicable to legend, suggestions very much appreciated. par(lheight=2) plot(1,1,col="white") legend("center", legend=c(expression(paste("Observed ",italic(bar(EC)[e]))),expression(paste("Simulated ",italic(bar(EC)[e]))),"test1","test2"), lty = c(NA,NA,1,1), col = c("black","black","red","blue"), density = c(NA,25,NA,NA), border=c("black","black",NA,NA), fill = c("grey","black",NA,NA), angle = c(NA,45,NA,NA), cex = 1.25, bty = "n", xpd = TRUE) > sessionInfo() R version 2.13.2 (2011-09-30) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.13.2 > -- View this message in context: http://r.789695.n4.nabble.com/legend-lheight-and-alignment-tp4129402p4129402.html Sent from the R help mailing list archive at Nabble.com. From yrosseel at gmail.com Thu Dec 1 17:56:00 2011 From: yrosseel at gmail.com (yrosseel) Date: Thu, 01 Dec 2011 17:56:00 +0100 Subject: [R] FIML with missing data in sem package In-Reply-To: References: <000d01ccb023$510f1a70$f32d4f50$@mcmaster.ca> Message-ID: <4ED7B1A0.6070401@gmail.com> On 12/01/2011 05:25 PM, Dustin Fife wrote: >> >> What is your goal? I have used and like mice pretty well, but using >> mice + sem to try to address missingness seems like more work than >> using FIML in OpenMx or lavaan to try to address it. Is there a >> reason you want to use the sem package or a reason you do not want to >> use the others? >> >> I tried lavaan and couldn't get it to work. I noticed it was in beta so I > figured it wasn't a good idea to use for simulations I intend to publish > (especially when I can't get them to work properly). Either way, whether I > use OpenMX or lavaan, it will require me to learn a new syntax, and I guess > I'm just lazy. I'm comfortable with sem. The 'beta' status of lavaan implies that things (eg function arguments) may change from one version to another, until most planned features are implemented. However, the computations/results themselves are pretty stable. Many SEM reseachers do use lavaan today for simulation studies, and some have been published already. I can provide you with some references off-list if you are interested. Yves Rosseel. http://lavaan.org From ggrothendieck at gmail.com Thu Dec 1 18:01:53 2011 From: ggrothendieck at gmail.com (Gabor Grothendieck) Date: Thu, 1 Dec 2011 12:01:53 -0500 Subject: [R] R, PostgresSQL and poor performance In-Reply-To: References: Message-ID: On Thu, Dec 1, 2011 at 10:02 AM, Berry, David I. wrote: > Hi List > > Apologies if this isn't the correct place for this query (I've tried a search of the mail archives but not had much joy). > > I'm running R (2.14.0) ?on a Mac (OSX v 10.5.8, 2.66GHz, 4GB memory) and am having a few performance issues with reading data in from a Postres database (using RPostgreSQL). My query / code are as below > > # ----------------------------- > library('RPostgreSQL') > > drv <- dbDriver("PostgreSQL") > > dbh <- dbConnect(drv,user="?",password="?",dbname="?",host="?") > > sql <- "select id, date, lon, lat, date_trunc('day' , date) as jday, extract('hour' from date) as hour, extract('year' from date) as year from observations where pt = 6 and date >= '1990-01-01' and date < '1995-01-01' and lon > 180 and lon < 290 and lat > -30 and lat < 30 and sst is not null" > > dataIn <- dbGetQuery(dbh,sql) If this is a large table of which the desired rows are a small fraction of all rows then be sure there indexes on the variables in your where clause. You can also try it with the RpgSQL driver although there is no reason to think that that would be faster. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com From msuzen at mango-solutions.com Thu Dec 1 18:03:11 2011 From: msuzen at mango-solutions.com (Mehmet Suzen) Date: Thu, 1 Dec 2011 17:03:11 -0000 Subject: [R] R package source branching In-Reply-To: References: <1322751115231-4128748.post@n4.nabble.com> Message-ID: <3CBFCFB1FEFFA841BA83ADF2F2A9C6FA01E92350@mango-data1.Mango.local> Dear List, I was wondering if any of you worked on an R package which has many branches on a repository i.e. SVN. Is it recommended to branch an R package source tree based on a specific project? I know it depends on project but it would be great to hear opinions from R community. Best, Mehmet S?zen, PhD LEGAL NOTICE This message is intended for the use o...{{dropped:10}} From sarah.goslee at gmail.com Thu Dec 1 18:11:47 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Thu, 1 Dec 2011 12:11:47 -0500 Subject: [R] vector In-Reply-To: <1322753704.39854.YahooMailNeo@web113611.mail.gq1.yahoo.com> References: <1322753704.39854.YahooMailNeo@web113611.mail.gq1.yahoo.com> Message-ID: Hi, On Thu, Dec 1, 2011 at 10:35 AM, " Majid " wrote: > Hi. > Can you please answer to my questions about R ? > 1.how can I write command for vector ? > > for exaple in this sample : > I have this : > a1 <- c (1:10) > now how can I put in the vector ? I'm afraid I don't understand your question. a1 is a vector that you've created. What do you want to do with it? Sarah > > bye for now, > Thanks a lot. > Majid. -- Sarah Goslee http://www.functionaldiversity.org From a.schlicker at nki.nl Thu Dec 1 18:00:25 2011 From: a.schlicker at nki.nl (Andreas Schlicker) Date: Thu, 1 Dec 2011 18:00:25 +0100 Subject: [R] What's the baseline model when using coxph with factor variables? Message-ID: <4ED7B2A9.1090607@nki.nl> Hi all, I'm trying to fit a Cox regression model with two factor variables but have some problems with the interpretation of the results. Considering the following model, where var1 and var2 can assume value 0 and 1: coxph(Surv(time, cens) ~ factor(var1) * factor(var2), data=temp) What is the baseline model? Is that considering the whole population or the case when both var1 and var2 = 0? Kind regards, andi From desviostandard at gmail.com Thu Dec 1 17:27:07 2011 From: desviostandard at gmail.com (=?ISO-8859-1?Q?Pablo_Dom=EDnguez_Vaselli?=) Date: Thu, 1 Dec 2011 13:27:07 -0300 Subject: [R] References for book "R In Action" by Kabacoff (Uwe Ligges) Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From Douglas.Esneault at mecglobal.com Thu Dec 1 17:32:30 2011 From: Douglas.Esneault at mecglobal.com (Douglas Esneault) Date: Thu, 1 Dec 2011 16:32:30 +0000 Subject: [R] Counting the occurences of a charater within a string Message-ID: <974A7A659261804FA954D102472EA32E03D37A85@NYCEMBP01101.ad.insidemedia.net> I am new to R but am experienced SAS user and I was hoping to get some help on counting the occurrences of a character within a string at a row level. My dataframe, x, is structured as below: Col1 abc/def ghi/jkl/mno I found this code on the board but it counts all occurrences of "/" in the dataframe. chr.pos <- which(unlist(strsplit(x,NULL))=='/') chr.count <- length(chr.pos) chr.count [1] 3 I'd like to append a column, say cnt, that has the count of "/" for each row. Can anyone point me in the right direction or offer some code to do this? Thanks in advance for the help. Doug Esneault Privileged/Confidential Information may be contained in this message. If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone. In such case, you should destroy this message and kindly notify the sender by reply email. Please advise immediately if you or your employer does not consent to email for messages of this kind. Opinions, conclusions and other information in this message that do not relate to the official business of the GroupM companies shall be understood as neither given nor endorsed by it. GroupM companies are a member of WPP plc. For more information on our business ethical standards and Corporate Responsibility policies please refer to our website at http://www.wpp.com/WPP/About/ From rpickeri at mail.nih.gov Thu Dec 1 17:36:48 2011 From: rpickeri at mail.nih.gov (RogerP) Date: Thu, 1 Dec 2011 08:36:48 -0800 (PST) Subject: [R] bigmemory on Solaris In-Reply-To: References: Message-ID: <1322757408424-4129290.post@n4.nabble.com> Thanks again for your help. I've been able to add several packages, bigmemory seems to be the only one to fail and it fails on isinf. Is there a way I can download the code and change it to include a ininf function or definition? I'm using the GNU compiler; should I have been using the SUN Studio compiler? Roger -- View this message in context: http://r.789695.n4.nabble.com/bigmemory-on-Solaris-tp4128179p4129290.html Sent from the R help mailing list archive at Nabble.com. From n.j.apps22 at gmail.com Thu Dec 1 17:58:00 2011 From: n.j.apps22 at gmail.com (napps22) Date: Thu, 1 Dec 2011 08:58:00 -0800 (PST) Subject: [R] Estimation of AR(1) Model with Markov Switching Message-ID: <1322758680372-4129417.post@n4.nabble.com> Dear R users, I have been trying to obtain the MLE of the following model state 0: y_t = 2 + 0.5 * y_{t-1} + e_t state 1: y_t = 0.5 + 0.9 * y_{t-1} + e_t where e_t ~ iidN(0,1) transition probability between states is 0.2 I've generated some fake data and tried to estimate the parameters using the constrOptim() function but I can't get sensible answers using it. I've tried using nlminb and maxLik but they haven't helped. Any tips on how I could possibly rewrite my likelihood in a better way to improve my results would be welcome. Given below is my R code # markov switching regime model # generate data for a AR(1) markov switching model with the following pars # state 0: y_t = 2 + 0.5 * y_{t-1} + e_t # state 1: y_t = 0.5 + 0.9 * y_{t-1} + e_t # where e_t ~ N(0,1) # transition probabilities p_s0_s1 = p_s1_s0 = 0.20 # generate realisations of the state gamma_s0 <- qnorm(0.8) gamma_s1 <- qnorm(0.2) gamma <- rep(0,100) state <- rep(0,100) # choose initial state at t=0 to be state 0 gamma[1] <- gamma_s0 state[1] <- 0 for(i in 2:100) { if(rnorm(1) < gamma[i-1]) { gamma[i] <- gamma_s0 state[i] <- 0 } else { gamma[i] <- gamma_s1 state[i] <- 1 } } # generate observations # choose y_0 = 0 # recall state at t=1 was set to 0 y1 <- 2 + 0.5 * 0 + rnorm(1) y <- rep(0,100) y[1] <- y1 for(i in 2:100) { if(state[i]==0) { y[i] <- 2 + 0.5 * y[i-1] + rnorm(1) } else { y[i] <- 0.5 + 0.9 * y[i-1] + rnorm(1) } } # convert into time series object y <- ts(y, start = 1, freq = 1) # construct negative conditional likelihood function neg.logl <- function(theta, data) { # construct parameters beta_s0 <- theta[1:2] beta_s1 <- theta[3:4] sigma2 <- exp(theta[5]) gamma0 <- theta[6] gamma1 <- theta[7] # construct probabilities #probit specification p_s0_s0 <- pnorm(gamma_s0) p_s0_s1 <- pnorm(gamma_s1) p_s1_s0 <- 1-pnorm(gamma_s0) p_s1_s1 <- 1-pnorm(gamma_s1) # create data matrix X <- cbind(1,y) # assume erogodicity of the markov chain # use unconditional probabilities p0_s0 <- (1 - p_s1_s1) / (2 -p_s0_s0 -p_s1_s1) p0_s1 <- 1-p0_s0 # create variables p_s0_t_1 <- rep(0, nrow(X)) p_s1_t_1 <- rep(0, nrow(X)) p_s0_t <- rep(0, nrow(X)) p_s1_t <- rep(0, nrow(X)) f_s0 <- rep(0,nrow(X)-1) f_s1 <- rep(0,nrow(X)-1) f <- rep(0,nrow(X)-1) logf <- rep(0, nrow(X)-1) p_s0_t[1] <- p0_s0 p_s1_t[1] <- p0_s1 # initiate hamilton filter for(i in 2:nrow(X)) { # calculate prior probabilities using the TPT # TPT for this example gives us # p_si_t_1 = p_si_t_1_si * p_si_t + p_si_t_1_sj * p_si_t # where p_si_t_1 is the prob state_t = i given information @ time t-1 # p_si_t_1_sj is the prob state_t = i given state_t_1 = j, and all info @ time t-1 # p_si_t is the prob state_t = i given information @ time t # in this simple example p_si_t_1_sj = p_si_sj p_s0_t_1[i] <- (p_s0_s0 * p_s0_t[i-1]) + (p_s0_s1 * p_s1_t[i-1]) p_s1_t_1[i] <- (p_s1_s0 * p_s0_t[i-1]) + (p_s1_s1 * p_s1_t[i-1]) # calculate density function for observation i # f_si is density conditional on state = i # f is the density f_s0[i] <- dnorm(y[i]-X[i-1,]%*%beta_s0, sd = sqrt(sigma2)) f_s1[i] <- dnorm(y[i]-X[i-1,]%*%beta_s1, sd = sqrt(sigma2)) f[i] <- (f_s0[i] * p_s0_t_1[i]) + (f_s1[i] * p_s1_t_1[i]) # calculate filtered/posterior probabilities using bayes rule # p_si_t is the prob that state = i given information @ time t p_s0_t[i] <- (f_s0[i] * p_s0_t_1[i]) / f[i] p_s1_t[i] <- (f_s1[i] * p_s1_t_1[i]) / f[i] logf[i] <- log(f[i]) } logl <-sum(logf) return(-logl) } # restrict intercept in state model 0 to be greater than intercept in state model 1 # thus matrix of restrictions R is [1 0 -1 0 0 0 0] R <- matrix(c(1,0,-1,0,0,0,0), nrow = 1) # pick start values for the 7 unknown parameters start_val <- matrix(runif(7), nrow = 7) # ensures starting values are in the feasible set start_val[1,] <- start_val[3,] + 0.1 # estimate pars results <-constrOptim(start_val,neg.logl,grad = NULL, ui = R, ci = 0) Regards, N -- View this message in context: http://r.789695.n4.nabble.com/Estimation-of-AR-1-Model-with-Markov-Switching-tp4129417p4129417.html Sent from the R help mailing list archive at Nabble.com. From dwinsemius at comcast.net Thu Dec 1 18:35:42 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Thu, 1 Dec 2011 12:35:42 -0500 Subject: [R] What's the baseline model when using coxph with factor variables? In-Reply-To: <4ED7B2A9.1090607@nki.nl> References: <4ED7B2A9.1090607@nki.nl> Message-ID: <5BC18E4E-FF2B-4689-AEB9-A755B027B986@comcast.net> On Dec 1, 2011, at 12:00 PM, Andreas Schlicker wrote: > Hi all, > > I'm trying to fit a Cox regression model with two factor variables > but have some problems with the interpretation of the results. > Considering the following model, where var1 and var2 can assume > value 0 and 1: > > coxph(Surv(time, cens) ~ factor(var1) * factor(var2), data=temp) > > What is the baseline model? Is that considering the whole population > or the case when both var1 and var2 = 0? This has been discussed several times in the past on rhelp. My suggestion would be to search your favorite rhelp archive using "baseline hazard Therneau", since Terry Therneau is the author of survival. (The answer is closer to the first than to the second.) > > Kind regards, > andi > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT From ccquant at gmail.com Thu Dec 1 18:54:28 2011 From: ccquant at gmail.com (Ben quant) Date: Thu, 1 Dec 2011 10:54:28 -0700 Subject: [R] logistic regression - glm.fit: fitted probabilities numerically 0 or 1 occurred Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From wdunlap at tibco.com Thu Dec 1 19:00:20 2011 From: wdunlap at tibco.com (William Dunlap) Date: Thu, 1 Dec 2011 18:00:20 +0000 Subject: [R] What's the baseline model when using coxph with factor variables? In-Reply-To: <5BC18E4E-FF2B-4689-AEB9-A755B027B986@comcast.net> References: <4ED7B2A9.1090607@nki.nl> <5BC18E4E-FF2B-4689-AEB9-A755B027B986@comcast.net> Message-ID: Terry will correct me if I'm wrong, but I don't think the answer to this question is specific to the coxph function. For all the [well-written] formula-based modelling functions (essentially, those that call model.frame and model.matrix to interpret the formula) the option "contrasts" controls how factor variables are parameterized in the model matrix. contr.treatment makes the baseline the first factor level, contr.SAS makes the baseline the last, contr.sum makes the baseline the mean, etc. E.g., > df <- data.frame(time=sin(1:20)+2, cens=rep(c(0,0,1), len=20), var1=factor(rep(0:1, each=10)), var2=factor(rep(0:1, 10))) > options(contrasts=c("contr.treatment", "contr.treatment")) > coxph(Surv(time, cens) ~ var1 + var2, data=df) Call: coxph(formula = Surv(time, cens) ~ var1 + var2, data = df) coef exp(coef) se(coef) z p var11 0.1640 1.18 0.822 0.1995 0.84 var21 0.0806 1.08 0.830 0.0971 0.92 Likelihood ratio test=0.05 on 2 df, p=0.974 n= 20, number of events= 6 > options(contrasts=c("contr.SAS", "contr.SAS")) > coxph(Surv(time, cens) ~ var1 + var2, data=df) Call: coxph(formula = Surv(time, cens) ~ var1 + var2, data = df) coef exp(coef) se(coef) z p var10 -0.1640 0.849 0.822 -0.1995 0.84 var20 -0.0806 0.923 0.830 -0.0971 0.92 Likelihood ratio test=0.05 on 2 df, p=0.974 n= 20, number of events= 6 > options(contrasts=c("contr.sum", "contr.sum")) > coxph(Surv(time, cens) ~ var1 + var2, data=df) Call: coxph(formula = Surv(time, cens) ~ var1 + var2, data = df) coef exp(coef) se(coef) z p var11 -0.0820 0.921 0.411 -0.1995 0.84 var21 -0.0403 0.960 0.415 -0.0971 0.92 Likelihood ratio test=0.05 on 2 df, p=0.974 n= 20, number of events= 6 (lm() has a contrasts argument that can override getOption("contrasts") and set different contrasts for each variable but coxph() does not have that argument.) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of David Winsemius > Sent: Thursday, December 01, 2011 9:36 AM > To: a.schlicker at nki.nl > Cc: r-help at r-project.org > Subject: Re: [R] What's the baseline model when using coxph with factor variables? > > > On Dec 1, 2011, at 12:00 PM, Andreas Schlicker wrote: > > > Hi all, > > > > I'm trying to fit a Cox regression model with two factor variables > > but have some problems with the interpretation of the results. > > Considering the following model, where var1 and var2 can assume > > value 0 and 1: > > > > coxph(Surv(time, cens) ~ factor(var1) * factor(var2), data=temp) > > > > What is the baseline model? Is that considering the whole population > > or the case when both var1 and var2 = 0? > > This has been discussed several times in the past on rhelp. My > suggestion would be to search your favorite rhelp archive using > "baseline hazard Therneau", since Terry Therneau is the author of > survival. (The answer is closer to the first than to the second.) > > > > > Kind regards, > > andi > > > > ______________________________________________ > > R-help at r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > David Winsemius, MD > West Hartford, CT > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From gunter.berton at gene.com Thu Dec 1 19:05:03 2011 From: gunter.berton at gene.com (Bert Gunter) Date: Thu, 1 Dec 2011 10:05:03 -0800 Subject: [R] Counting the occurences of a charater within a string In-Reply-To: <974A7A659261804FA954D102472EA32E03D37A85@NYCEMBP01101.ad.insidemedia.net> References: <974A7A659261804FA954D102472EA32E03D37A85@NYCEMBP01101.ad.insidemedia.net> Message-ID: ## It's not a data frame -- it's just a vector. > x [1] "abc/def" "ghi/jkl/mno" > gsub("[^/]","",x) [1] "/" "//" > nchar(gsub("[^/]","",x)) [1] 1 2 > ?gsub ?nchar -- Bert On Thu, Dec 1, 2011 at 8:32 AM, Douglas Esneault wrote: > I am new to R but am experienced SAS user and I was hoping to get some help on counting the occurrences of a character within a string at a row level. > > My dataframe, x, ?is structured as below: > > Col1 > abc/def > ghi/jkl/mno > > I found this code on the board but it counts all occurrences of "/" in the dataframe. > > chr.pos <- which(unlist(strsplit(x,NULL))=='/') > chr.count <- length(chr.pos) > chr.count > [1] 3 > > I'd like to append a column, say cnt, that has the count of "/" for each row. > > Can anyone point me in the right direction or offer some code to do this? > > Thanks in advance for the help. > > Doug Esneault > > > > > > > Privileged/Confidential Information may be contained in this message. If you > are not the addressee indicated in this message (or responsible for delivery > of the message to such person), you may not copy or deliver this message to > anyone. In such case, you should destroy this message and kindly notify the > sender by reply email. Please advise immediately if you or your employer > does not consent to email for messages of this kind. Opinions, conclusions > and other information in this message that do not relate to the official > business of the GroupM companies shall be understood as neither given nor > endorsed by it. ? GroupM companies are a member of WPP plc. For more > information on our business ethical standards and Corporate Responsibility > policies please refer to our website at > http://www.wpp.com/WPP/About/ > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm From michael.weylandt at gmail.com Thu Dec 1 19:29:13 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Thu, 1 Dec 2011 13:29:13 -0500 Subject: [R] Writing a function, want a string argument to define the name of the excel sheet to be called In-Reply-To: <1322748601119-4128495.post@n4.nabble.com> References: <1322747017324-4128384.post@n4.nabble.com> <1DE876CE-60DE-46B7-A0AF-CF40B7E9BE12@depauw.edu> <1322748601119-4128495.post@n4.nabble.com> Message-ID: Just a heads up -- I don't think your code will work with an actual .xls(x) file, only .txt, .csv, etc (aka, plain text files). I may be wrong about that, but if you actually need to work with Excel files directly you will need an additional package. Michael On Thu, Dec 1, 2011 at 9:10 AM, AOLeary wrote: > Thank you very much, that does exactly what I want it to! :) > > Aodh?n > > -- > View this message in context: http://r.789695.n4.nabble.com/Writing-a-function-want-a-string-argument-to-define-the-name-of-the-excel-sheet-to-be-called-tp4128384p4128495.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From saschaview at gmail.com Thu Dec 1 19:30:18 2011 From: saschaview at gmail.com (saschaview at gmail.com) Date: Thu, 1 Dec 2011 19:30:18 +0100 Subject: [R] transform data.frame holding answers --> data.frame holding logicals Message-ID: <4ED7C7BA.7040408@gmail.com> Hello Hello I have a data frame, x, holding 5 persons answering the question which cars they have used: # the data frame x <- as.data.frame( matrix( c('BMW', '', '', 'Mercedes', 'VW', '', 'Skoda', 'VW', 'BMW', '', '', '', 'VW', 'Skoda', '' ), ncol=3, dimnames=list( NULL, paste( 'v', 1:3, sep='' ) ) ) ) How do I transform this data frame to a data frame stating whether they have used the presented car: BMW Mercedes VW Skoda 1 T F F F 2 F T T F 3 T F T T 4 F F F F 5 F F T T My idea was to first find all levels by: v <- unique(unlist(lapply(x, levels))) But then I am stuck. Thanks for help, *S* -- Sascha Vieweg, saschaview at gmail.com From michael.weylandt at gmail.com Thu Dec 1 19:41:18 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Thu, 1 Dec 2011 13:41:18 -0500 Subject: [R] Replace columns in a data.frame randomly splitted In-Reply-To: <1322726049879-4127405.post@n4.nabble.com> References: <1322658929391-4122926.post@n4.nabble.com> <1322726049879-4127405.post@n4.nabble.com> Message-ID: I repeat myself: Any more automated solution will depend on whether your data has rownames or not. [...] create a plain text representation of R data using the dput() command. Another way that might make more sense is to cbind() the data you need later on before the split and then it will be carried through. Michael On Thu, Dec 1, 2011 at 2:54 AM, agent dunham wrote: > > > The thing is that I've already been working with df1, and I was looking for > a function that could replace values knowing rows and columns. Does it > exist? > > Thank you, user at host.com > > -- > View this message in context: http://r.789695.n4.nabble.com/Replace-columns-in-a-data-frame-randomly-splitted-tp4122926p4127405.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From pdalgd at gmail.com Thu Dec 1 19:55:18 2011 From: pdalgd at gmail.com (peter dalgaard) Date: Thu, 1 Dec 2011 19:55:18 +0100 Subject: [R] logistic regression - glm.fit: fitted probabilities numerically 0 or 1 occurred In-Reply-To: References: Message-ID: <2F36BA38-DD8B-4660-ACA1-709750BE0D35@gmail.com> On Dec 1, 2011, at 18:54 , Ben quant wrote: > Sorry if this is a duplicate: This is a re-post because the pdf's mentioned > below did not go through. Still not there. Sometimes it's because your mailer doesn't label them with the appropriate mime-type (e.g. as application/octet-stream, which is "arbitrary binary"). Anyways, see below [snip] > > With the above data I do: >> l_logit = glm(y~x, data=as.data.frame(l_yx), > family=binomial(link="logit")) > Warning message: > glm.fit: fitted probabilities numerically 0 or 1 occurred > > Why am I getting this warning when I have data points of varying values for > y=1 and y=0? In other words, I don't think I have the linear separation > issue discussed in one of the links I provided. I bet that you do... You can get the warning without that effect (one of my own examples is the probability of menarche in a data set that includes infants and old age pensioners), but not with a huge odds ratio as well. Take a look at d <- as.data.frame(l_yx) with(d, y[order(x)]) if it comes out as all zeros followed by all ones or vice versa, then you have the problem. > > PS - Then I do this and I get a odds ratio a crazy size: >> l_sm = summary(l_logit) # coef pval is $coefficients[8], log odds > $coefficients[2] >> l_exp_coef = exp(l_logit$coefficients)[2] # exponentiate the > coeffcients >> l_exp_coef > x > 3161.781 > > So for one unit increase in the predictor variable I get 3160.781% > (3161.781 - 1 = 3160.781) increase in odds? That can't be correct either. > How do I correct for this issue? (I tried multiplying the predictor > variables by a constant and the odds ratio goes down, but the warning above > still persists and shouldn't the odds ratio be predictor variable size > independent?) -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com From javier.cano at urjc.es Thu Dec 1 19:12:03 2011 From: javier.cano at urjc.es (jcano) Date: Thu, 1 Dec 2011 10:12:03 -0800 (PST) Subject: [R] Change the limits of a plot "a posteriori" Message-ID: <1322763123687-4129750.post@n4.nabble.com> Hi all How can I change the limits (xlim or ylim) in a plot that has been already created? For example, consider this naive example curve(dbeta(x,2,4)) curve(dbeta(x,8,13),add=T,col=2) When adding the second curve, it goes off the original limits computed by R for the first graph, which are roughly, c(0,2.1) I know two obvious solutions for this, which are: 1) passing a sufficiently large parameter e.g. ylim=c(0,4) to the first graphic curve(dbeta(x,2,4),ylim=c(0,4)) curve(dbeta(x,8,13),add=T,col=2) or 2) switch the order in which I plot the curves curve(dbeta(x,8,13),col=2) curve(dbeta(x,2,4),add=T) but I guess if there is any way of adjusting the limits of the graphic "a posteriori", once you have a plot with the undesired limits, forcing R to redraw it with the new limits, but without having to execute again the "curve" commands Hope I made myself clear Best regards and thank you very much in advance -- View this message in context: http://r.789695.n4.nabble.com/Change-the-limits-of-a-plot-a-posteriori-tp4129750p4129750.html Sent from the R help mailing list archive at Nabble.com. From l.glew at soton.ac.uk Thu Dec 1 19:13:18 2011 From: l.glew at soton.ac.uk (lglew) Date: Thu, 1 Dec 2011 10:13:18 -0800 (PST) Subject: [R] Assign name to object for each iteration in a loop. Message-ID: <1322763198075-4129752.post@n4.nabble.com> Hi R-users, I'm trying to produce decompositions of a multiple time-series, grouped by a factor (called "area"). I'm modifying the code in the STLperArea function of package ndvits, as this function only plots produces stl plots, it does not return the underlying data. I want to extract the trend component of each decomposition ("x$time.series[,trend]), assign a name based on the factor "area". My input data look like this: Area is a factor, with three (but could be many more) levels. area 1 2 3 Ystart=2000 TS is a timeseries: X2000049 X2000065 X2000081 X2000097 X2000113 1 0.2080 0.2165 0.2149 0.2314 0.2028 2 0.1578 0.1671 0.1577 0.1593 0.1672 3 0.1897 0.1948 0.2290 0.2292 0.2067 Here's the function: STLpA<-function(TS, area, Ystart, period=23, nSG="5,5", DSG=0) { require (RTisean) for(i in 1:unique(area)){ vi.metric=TS[area==i] filt.vi<-sav_gol(vi.metric,n=nSG,D=DSG) vi.sg<-ts(filt.vi[,1], start=Ystart,frequency=period) stld.tmp<-stl(vi.sg, s.window="periodic", robust=TRUE, na.action=na.approx) stld.trend<-stld.temp$time.series[,trend] } assign(paste("stld", i , sep= "."), stld.trend) vi.trend<-ls(pattern= "^stld..$") return(vi.trend) } When I call this function with signal=STLpA(TS,area,Ystart=2000,period=23, nSG= "5,5", DSG="0")) I get this error: Error in cat(list(...), file, sep, fill, labels, append) : argument 1 (type 'list') cannot be handled by 'cat' In addition: Warning message: In 1:unique(area) : numerical expression has 3 elements: only the first used I'm guessing this is because I'm assigning names to each temporary stl.trend file incorrectly. Can anyone improve on my rather poor efforts here? Many thanks, Louise -- View this message in context: http://r.789695.n4.nabble.com/Assign-name-to-object-for-each-iteration-in-a-loop-tp4129752p4129752.html Sent from the R help mailing list archive at Nabble.com. From chl2016 at med.cornell.edu Thu Dec 1 19:38:17 2011 From: chl2016 at med.cornell.edu (Charles Li) Date: Thu, 01 Dec 2011 13:38:17 -0500 Subject: [R] nested random effects with lmer Message-ID: <002201ccb058$649a0d90$2dce28b0$@med.cornell.edu> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From vytautas1987 at yahoo.com Thu Dec 1 20:26:51 2011 From: vytautas1987 at yahoo.com (Vytautas Rakeviius) Date: Thu, 1 Dec 2011 11:26:51 -0800 (PST) Subject: [R] question about plsr() results Message-ID: <1322767611.79460.YahooMailNeo@web121513.mail.ne1.yahoo.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From jvadams at usgs.gov Thu Dec 1 20:30:51 2011 From: jvadams at usgs.gov (Jean V Adams) Date: Thu, 1 Dec 2011 13:30:51 -0600 Subject: [R] Change the limits of a plot "a posteriori" In-Reply-To: <1322763123687-4129750.post@n4.nabble.com> References: <1322763123687-4129750.post@n4.nabble.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From michael.weylandt at gmail.com Thu Dec 1 20:33:31 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Thu, 1 Dec 2011 14:33:31 -0500 Subject: [R] Assign name to object for each iteration in a loop. In-Reply-To: <1322763198075-4129752.post@n4.nabble.com> References: <1322763198075-4129752.post@n4.nabble.com> Message-ID: I think part of your problem is the loop: you probably mean for(i in unique(area)) Michael On Thu, Dec 1, 2011 at 1:13 PM, lglew wrote: > Hi R-users, > > I'm trying to produce decompositions of a multiple time-series, grouped by a > factor (called "area"). I'm modifying the code in the STLperArea function of > package ndvits, as this function only plots produces stl plots, it does not > return the underlying data. > > I want to extract the trend component of each decomposition > ("x$time.series[,trend]), assign a name based on the factor "area". > > My input data look like this: > Area is a factor, with three (but could be many more) levels. > area > 1 > 2 > 3 > > Ystart=2000 > > TS is a timeseries: > > ?X2000049 ? X2000065 ?X2000081 ?X2000097 ?X2000113 > 1 ? ? 0.2080 ? ? ?0.2165 ? ? ?0.2149 ? ? 0.2314 ? ? ?0.2028 > 2 ? ? 0.1578 ? ? ?0.1671 ? ? ?0.1577 ? ? 0.1593 ? ? ?0.1672 > 3 ? ? 0.1897 ? ? ?0.1948 ? ? ?0.2290 ? ? 0.2292 ? ? ?0.2067 > > Here's the function: > > STLpA<-function(TS, area, Ystart, period=23, nSG="5,5", DSG=0) > { > require (RTisean) > for(i in 1:unique(area)){ > vi.metric=TS[area==i] > filt.vi<-sav_gol(vi.metric,n=nSG,D=DSG) > vi.sg<-ts(filt.vi[,1], start=Ystart,frequency=period) > stld.tmp<-stl(vi.sg, s.window="periodic", robust=TRUE, na.action=na.approx) > stld.trend<-stld.temp$time.series[,trend] > } > assign(paste("stld", i , sep= "."), stld.trend) > vi.trend<-ls(pattern= "^stld..$") > return(vi.trend) > } > > When I call this function with signal=STLpA(TS,area,Ystart=2000,period=23, > nSG= "5,5", DSG="0")) > > I get this error: > > Error in cat(list(...), file, sep, fill, labels, append) : > ?argument 1 (type 'list') cannot be handled by 'cat' > In addition: Warning message: > In 1:unique(area) : > ?numerical expression has 3 elements: only the first used > > I'm guessing this is because I'm assigning names to each temporary stl.trend > file incorrectly. Can anyone > improve on my rather poor efforts here? > > Many thanks, > > Louise > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Assign-name-to-object-for-each-iteration-in-a-loop-tp4129752p4129752.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From mayer at psychologie.tu-dresden.de Thu Dec 1 20:33:58 2011 From: mayer at psychologie.tu-dresden.de (=?iso-8859-1?b?UmVu6Q==?= Mayer) Date: Thu, 01 Dec 2011 20:33:58 +0100 Subject: [R] how to get inflection point in binomial glm In-Reply-To: <115F31EC-7960-4157-B70E-A4DB76D5C2DE@comcast.net> References: <20111201142447.202239j1pkf17h9b@psy2.psych.tu-dresden.de> <115F31EC-7960-4157-B70E-A4DB76D5C2DE@comcast.net> Message-ID: <20111201203358.19674ghe8483ub3a@psy2.psych.tu-dresden.de> Thanks David and Rub?n! @David: indeed 15 betas I forgot the interaction terms, thanks for correcting! @Rub?n: the re-parameterize would be done within nls()? how to do this practically with including the factor predictor? and yes, we can solve within each group for Y=0 getting 0=b0+b1*X |-b0 -b0=b1*X |/b1 -b0/b1=X but I was hoping there might a more general solution for the case of multiple logistic regression. HTH Ren? Zitat von "David Winsemius" : > > On Dec 1, 2011, at 8:24 AM, Ren? Mayer wrote: > >> Dear All, >> >> I have a binomial response with one continuous predictor (d) and >> one factor (g) (8 levels dummy-coded). >> >> glm(resp~d*g, data, family=binomial) >> >> Y=b0+b1*X1+b2*X2 ... b7*X7 > > Dear Dr Mayer; > > I think it might be a bit more complex than that. I think you should > get 15 betas rather than 8. Have you done it? > >> >> how can I get the inflection point per group, e.g., P(d)=.5 > > Wouldn't that just be at d=1/beta in each group? (Thinking, perhaps > naively, in the case of X=X1 that > > (Pr[y==1])/(1-Pr[y==1])) = 1 = exp( beta *d*(X==X1) ) # all other terms = 0 > > And taking the log of both sides, and then use "middle school" math to solve. > > Oh, wait. Muffed my first try on that for sure. Need to add back > both the constant intercept and the baseline "d" coefficient for the > non-b0 levels. > > (Pr[y==1])/(1-Pr[y==1])) = 1 = exp( beta_0 + beta_d_0*d + > beta_n + beta_d_n *d*(X==Xn) ) > > And just > > (Pr[y==1])/(1-Pr[y==1])) = 1 = exp( beta_0 + beta_d_0*d ) # for the > reference level. > > This felt like an exam question in my categorical analysis course 25 > years ago. (Might have gotten partial credit for my first stab, > depending on how forgiving the TA was that night.) > >> >> I would be grateful for any help. >> >> Thanks in advance, >> Ren? >> > -- > > David Winsemius, MD > West Hartford, CT > > From murdoch.duncan at gmail.com Thu Dec 1 20:34:46 2011 From: murdoch.duncan at gmail.com (Duncan Murdoch) Date: Thu, 01 Dec 2011 14:34:46 -0500 Subject: [R] Change the limits of a plot "a posteriori" In-Reply-To: <1322763123687-4129750.post@n4.nabble.com> References: <1322763123687-4129750.post@n4.nabble.com> Message-ID: <4ED7D6D6.9030507@gmail.com> On 01/12/2011 1:12 PM, jcano wrote: > Hi all > > How can I change the limits (xlim or ylim) in a plot that has been already > created? You can't, if you're using classic R graphics. They use an "ink on paper" model of graphics. If you want to change what you've drawn, you get a new piece of paper. Your two solutions below are the usual methods to work around this limitation. The first is the easiest method in general, though it's not particularly easy if you're using curve(). Generally if you're planning to plot y1 vs x1 and y2 vs x2, you can set your ylim to range(c(y1, y2)) and your xlim to range(c(x1, x2)) and things are fine. If you want to follow this strategy with curve(), you need to call it twice for each curve: once to find the range of points it would plot (they are in the return value of the function), and a second time to redo the plot with the calculated xlim and ylim. Duncan Murdoch > For example, consider this naive example > curve(dbeta(x,2,4)) > curve(dbeta(x,8,13),add=T,col=2) > > When adding the second curve, it goes off the original limits computed by R > for the first graph, which are roughly, c(0,2.1) > > I know two obvious solutions for this, which are: > 1) passing a sufficiently large parameter e.g. ylim=c(0,4) to the first > graphic > curve(dbeta(x,2,4),ylim=c(0,4)) > curve(dbeta(x,8,13),add=T,col=2) > > or > > 2) switch the order in which I plot the curves > curve(dbeta(x,8,13),col=2) > curve(dbeta(x,2,4),add=T) > > but I guess if there is any way of adjusting the limits of the graphic "a > posteriori", once you have a plot with the undesired limits, forcing R to > redraw it with the new limits, but without having to execute again the > "curve" commands > > Hope I made myself clear > > Best regards and thank you very much in advance > > > -- > View this message in context: http://r.789695.n4.nabble.com/Change-the-limits-of-a-plot-a-posteriori-tp4129750p4129750.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From jvadams at usgs.gov Thu Dec 1 20:42:54 2011 From: jvadams at usgs.gov (Jean V Adams) Date: Thu, 1 Dec 2011 13:42:54 -0600 Subject: [R] transform data.frame holding answers --> data.frame holding logicals In-Reply-To: <4ED7C7BA.7040408@gmail.com> References: <4ED7C7BA.7040408@gmail.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From sarah.goslee at gmail.com Thu Dec 1 20:51:55 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Thu, 1 Dec 2011 14:51:55 -0500 Subject: [R] vector In-Reply-To: <1322768580.9896.YahooMailNeo@web113613.mail.gq1.yahoo.com> References: <1322753704.39854.YahooMailNeo@web113611.mail.gq1.yahoo.com> <1322768580.9896.YahooMailNeo@web113613.mail.gq1.yahoo.com> Message-ID: Hi, On Thu, Dec 1, 2011 at 2:43 PM, " Majid " wrote: > Dear Sarah. > Thanks so much,Really I am new in this software,I am wrking to learn the > software. First, you should always send your replies to the list. That way information can help others, and more people are available to provide advice. Second, is this homework? Third, see below. > I have this sample and I was checking it : > #========Generating data=============== > > # in here we produce patterned data > #Do this and see what will happen: > > 1:10 > > # now put this seri in a vector > > a1 <- c (1:10) > > #====================================== > > > > #Do this and see what will happen: > seq(1, 5, 0.5) > > # now put this seri in a vector > > a2 <- c (seq(1, 5, 0.5)) > > Can you please learn me what is the matter? about these orders ? Nothing is wrong with these commands. Both make vectors. The c() is unnecessary in both cases, but still works. If this is not homework, you still need to explain what you *expect* to have happen, otherwise nobody can help you. Sarah -- Sarah Goslee http://www.functionaldiversity.org From dwinsemius at comcast.net Thu Dec 1 20:56:13 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Thu, 1 Dec 2011 14:56:13 -0500 Subject: [R] What's the baseline model when using coxph with factor variables? In-Reply-To: References: <4ED7B2A9.1090607@nki.nl> <5BC18E4E-FF2B-4689-AEB9-A755B027B986@comcast.net> Message-ID: On Dec 1, 2011, at 1:00 PM, William Dunlap wrote: > Terry will correct me if I'm wrong, but I don't think the > answer to this question is specific to the coxph function. It depends on our interpretation of the questioner's intent. My answer was predicated on the assumption that the phrase "baseline model" meant baseline survival function, ... S_0(t) in survival analysis notation. > For all the [well-written] formula-based modelling functions > (essentially, those that call model.frame and model.matrix to > interpret > the formula) the option "contrasts" controls how factor > variables are parameterized in the model matrix. contr.treatment > makes the baseline the first factor level, contr.SAS makes > the baseline the last, contr.sum makes the baseline the mean, > etc. E.g., > >> df <- data.frame(time=sin(1:20)+2, > cens=rep(c(0,0,1), len=20), > var1=factor(rep(0:1, each=10)), > var2=factor(rep(0:1, 10))) >> options(contrasts=c("contr.treatment", "contr.treatment")) >> coxph(Surv(time, cens) ~ var1 + var2, data=df) > Call: > coxph(formula = Surv(time, cens) ~ var1 + var2, data = df) > > > coef exp(coef) se(coef) z p > var11 0.1640 1.18 0.822 0.1995 0.84 > var21 0.0806 1.08 0.830 0.0971 0.92 > > Likelihood ratio test=0.05 on 2 df, p=0.974 n= 20, number of > events= 6 >> options(contrasts=c("contr.SAS", "contr.SAS")) >> coxph(Surv(time, cens) ~ var1 + var2, data=df) > Call: > coxph(formula = Surv(time, cens) ~ var1 + var2, data = df) > > > coef exp(coef) se(coef) z p > var10 -0.1640 0.849 0.822 -0.1995 0.84 > var20 -0.0806 0.923 0.830 -0.0971 0.92 > > Likelihood ratio test=0.05 on 2 df, p=0.974 n= 20, number of > events= 6 >> options(contrasts=c("contr.sum", "contr.sum")) >> coxph(Surv(time, cens) ~ var1 + var2, data=df) > Call: > coxph(formula = Surv(time, cens) ~ var1 + var2, data = df) > > > coef exp(coef) se(coef) z p > var11 -0.0820 0.921 0.411 -0.1995 0.84 > var21 -0.0403 0.960 0.415 -0.0971 0.92 > > Likelihood ratio test=0.05 on 2 df, p=0.974 n= 20, number of > events= 6 > > (lm() has a contrasts argument that can override > getOption("contrasts") > and set different contrasts for each variable but coxph() does not > have > that argument.) > > Bill Dunlap > Spotfire, TIBCO Software > wdunlap tibco.com > >> -----Original Message----- >> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org >> ] On Behalf Of David Winsemius >> Sent: Thursday, December 01, 2011 9:36 AM >> To: a.schlicker at nki.nl >> Cc: r-help at r-project.org >> Subject: Re: [R] What's the baseline model when using coxph with >> factor variables? >> >> >> On Dec 1, 2011, at 12:00 PM, Andreas Schlicker wrote: >> >>> Hi all, >>> >>> I'm trying to fit a Cox regression model with two factor variables >>> but have some problems with the interpretation of the results. >>> Considering the following model, where var1 and var2 can assume >>> value 0 and 1: >>> >>> coxph(Surv(time, cens) ~ factor(var1) * factor(var2), data=temp) >>> >>> What is the baseline model? Is that considering the whole population >>> or the case when both var1 and var2 = 0? >> >> This has been discussed several times in the past on rhelp. My >> suggestion would be to search your favorite rhelp archive using >> "baseline hazard Therneau", since Terry Therneau is the author of >> survival. (The answer is closer to the first than to the second.) >> >>> >>> Kind regards, >>> andi >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> >> David Winsemius, MD >> West Hartford, CT >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT From sarah.goslee at gmail.com Thu Dec 1 21:28:42 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Thu, 1 Dec 2011 15:28:42 -0500 Subject: [R] vector In-Reply-To: <1322770304.65123.YahooMailNeo@web113615.mail.gq1.yahoo.com> References: <1322753704.39854.YahooMailNeo@web113611.mail.gq1.yahoo.com> <1322768580.9896.YahooMailNeo@web113613.mail.gq1.yahoo.com> <1322770304.65123.YahooMailNeo@web113615.mail.gq1.yahoo.com> Message-ID: On Thu, Dec 1, 2011 at 3:11 PM, " Majid " wrote: > Hi, > yes, It is homework, Then ask your TA/instructor for help. > > These are 2 command: > first for generating data: > (1:10) > that output is 1 2 3....10 > ok ? > second is : > a1<-c( 1:10) > what is the output ?I didnot see any thing. Exactly as it should be. There's no problem here, except that you need to read help("<-") > Thanks, > Majid. > -- Sarah Goslee http://www.functionaldiversity.org From ccquant at gmail.com Thu Dec 1 21:32:35 2011 From: ccquant at gmail.com (Ben quant) Date: Thu, 1 Dec 2011 13:32:35 -0700 Subject: [R] logistic regression - glm.fit: fitted probabilities numerically 0 or 1 occurred In-Reply-To: <2F36BA38-DD8B-4660-ACA1-709750BE0D35@gmail.com> References: <2F36BA38-DD8B-4660-ACA1-709750BE0D35@gmail.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From jabezwuk at yahoo.co.uk Thu Dec 1 21:45:14 2011 From: jabezwuk at yahoo.co.uk (Jabez Wilson) Date: Thu, 1 Dec 2011 20:45:14 +0000 Subject: [R] calculate mean of multiple rows in a data frame Message-ID: <1322772314.57483.YahooMailClassic@web28515.mail.ukl.yahoo.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From michael.weylandt at gmail.com Thu Dec 1 22:10:21 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Thu, 1 Dec 2011 16:10:21 -0500 Subject: [R] combining arima and ar function In-Reply-To: <000601ccb00f$9e403db0$dac0b910$@ch> References: <000601ccb00f$9e403db0$dac0b910$@ch> Message-ID: I think your attachment got scrubbed so I can't verify this, but i think the difficulty is that the "inner" apply returns a whole set of orders, instead of just one and that throws arima off: would this work? getOrder <- function(x) ar(na.omit(x), method = "mle")$order all.equal(apply(TSX, 2, getOrder), apply(TSX,2, function(x) ar(na.omit(x),method="mle")$order) # Verify it works. apply(TSX,2,function(x)arima(x,order=c(getOrder(x),0,0))$residuals Michael On Thu, Dec 1, 2011 at 4:57 AM, Samir Benzerfa wrote: > Hi everyone > > > > I've got a problem regarding the arima() and the ar() function for > autoregressive series. I would simply like to combine them. > > > > To better understand my question, I first show you how I'm using these two > functions individually (see file in the attachement). > > > > 1) ? ? ?apply(TSX,2, function(x) ar(na.omit(x),method="mle")$order > # this function finds the optimal (autoregressive) order for each series > (briefly speaking: for each series I get a specific number) > > 2) ? ? ?apply(TSX,2,function(x)arima(x,order=c(1,0,0))$residuals > # this function puts an autoregressive model of order 1 on each series > > > > > > What I'd like to do, is to combine them, such that the resulting orders > (numbers) from the first function are used as orders in the second function. > So in the specific example attached the results from the first function are > 6,5,1 and these numbers should be used as the order in function two. I tried > to simply put the two functions together as follows: > > > > apply(TSX,2,function(x) arima(x,order=c((apply(TSX,2, > function(x)ar(na.omit(x),method="mle")$order))),0,0)) > > > > However, I get the error message " 'order' must be a non-negative numeric > vector of length 3". > > > > Any hints? I hope you can help me with this issue. > > > > Many thanks and best regards, S.B. > > > > > > > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > From jabezwuk at yahoo.co.uk Thu Dec 1 22:15:39 2011 From: jabezwuk at yahoo.co.uk (Jabez Wilson) Date: Thu, 1 Dec 2011 21:15:39 +0000 Subject: [R] Fw: calculate mean of multiple rows in a data frame Message-ID: <1322774139.12733.YahooMailClassic@web28501.mail.ukl.yahoo.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From pdalgd at gmail.com Thu Dec 1 22:24:20 2011 From: pdalgd at gmail.com (peter dalgaard) Date: Thu, 1 Dec 2011 22:24:20 +0100 Subject: [R] logistic regression - glm.fit: fitted probabilities numerically 0 or 1 occurred In-Reply-To: References: <2F36BA38-DD8B-4660-ACA1-709750BE0D35@gmail.com> Message-ID: On Dec 1, 2011, at 21:32 , Ben quant wrote: > Thank you for the feedback, but my data looks fine to me. Please tell me if I'm not understanding. Hum, then maybe it really is a case of a transition region being short relative to the range of your data. Notice that the warning is just that: a warning. I do notice that the distribution of your x values is rather extreme -- you stated a range of 0--14 and a mean of 0.01. And after all, an odds ratio of 3000 per unit is only a tad over a doubling per 0.1 units. Have a look at range(x[y==0]) and range(x[y==1]). > > I followed your instructions and here is a sample of the first 500 values : (info on 'd' is below that) > > > d <- as.data.frame(l_yx) > > x = with(d, y[order(x)]) > > x[1:500] # I have 1's and 0's dispersed throughout > [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 > [101] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > [201] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 1 0 0 > [301] 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > [401] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 > > # I get the warning still > > l_df = as.data.frame(l_yx) > > l_logit = glm(y~x, data=l_df, family=binomial(link="logit")) > > Warning message: > glm.fit: fitted probabilities numerically 0 or 1 occurred > > # some info on 'd' above: > > > d[1:500,1] > [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > [101] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > [201] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > [301] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > [401] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > > d[1:500,2] > [1] 3.023160e-03 7.932130e-02 0.000000e+00 1.779657e-02 1.608374e-01 0.000000e+00 5.577064e-02 7.753926e-03 4.018553e-03 4.760918e-02 2.080511e-02 1.642404e-01 3.703720e-03 8.901981e-02 1.260415e-03 > [16] 2.202523e-02 3.750940e-02 4.441975e-04 9.351171e-03 8.374567e-03 0.000000e+00 8.440448e-02 5.081017e-01 2.538640e-05 1.806017e-02 2.954641e-04 1.434859e-03 6.964976e-04 0.000000e+00 1.202162e-02 > [31] 3.420300e-03 4.276100e-02 1.457324e-02 4.140121e-03 1.349180e-04 1.525292e-03 4.817502e-02 9.515717e-03 2.232953e-02 1.227908e-01 3.293581e-02 1.454352e-02 1.176011e-03 6.274138e-02 2.879205e-02 > [46] 6.900926e-03 1.414648e-04 3.446349e-02 8.807174e-03 3.549332e-02 2.828509e-03 2.935003e-02 7.162872e-03 5.650050e-03 1.221191e-02 0.000000e+00 2.126334e-02 2.052020e-02 7.542409e-02 2.586269e-04 > [61] 5.258664e-02 1.213126e-02 1.493275e-02 8.152657e-03 1.774966e-02 2.433198e-02 1.371257e-02 6.732339e-02 9.747677e-03 8.180594e-03 1.882473e-01 1.682596e-03 1.410170e-02 8.429676e-03 3.520589e-01 > [76] 1.865160e-02 2.389941e-02 3.301558e-02 4.896605e-03 6.826244e-03 9.151337e-02 1.722270e-02 1.764039e-01 3.554063e-02 7.338532e-03 9.577793e-03 3.632366e-03 1.422400e-02 3.020497e-02 1.797096e-02 > [91] 2.577899e-03 1.338365e-01 8.202223e-03 1.088335e-02 2.137259e-02 6.829797e-03 3.104860e-04 8.927160e-03 5.626881e-02 1.197682e-02 6.140553e-02 2.729364e-02 1.377913e-02 3.018277e-03 1.188304e-02 > [106] 2.029268e-03 2.108815e-02 1.765503e-03 2.449253e-02 3.677046e-03 1.013463e-02 4.286642e-02 1.238931e-02 3.072090e-03 1.509613e-02 3.609885e-02 5.537268e-03 3.151614e-02 3.703148e-03 1.409401e-01 > [121] 1.473365e-02 9.160461e-03 1.035099e-01 3.005865e-02 1.332199e-02 6.936535e-03 2.433539e-02 4.935373e-03 4.822740e-03 1.597643e-03 3.805619e-03 1.092683e-02 1.760635e-01 5.565614e-03 7.739213e-04 > [136] 4.529198e-03 5.110359e-03 7.391258e-02 5.018207e-03 2.071417e-02 1.825787e-02 9.141405e-03 1.078386e-01 2.171470e-04 7.164583e-03 2.522077e-02 1.994428e-03 6.044653e-03 1.778078e-04 5.797706e-03 > [151] 1.526778e-02 1.595897e-02 1.995627e-01 1.946735e-03 6.711582e-02 2.722350e-02 3.127499e-02 1.074904e-01 2.477414e-03 5.015375e-02 3.417810e-02 2.046643e-02 1.644832e-02 5.220166e-03 1.217752e-02 > [166] 1.187352e-02 1.634016e-02 2.349568e-03 3.451811e-02 2.593540e-03 6.868595e-03 1.311236e-02 6.457757e-03 2.942391e-04 1.628352e-02 8.288831e-03 3.170856e-04 1.251331e+00 1.706954e-02 1.063723e-03 > [181] 1.374416e-02 2.140507e-02 2.817009e-02 2.272793e-02 4.365562e-02 6.089414e-03 2.498083e-02 1.360471e-02 1.884079e-02 1.448660e-02 2.341314e-02 8.167064e-03 4.109117e-02 2.660633e-02 7.711723e-03 > [196] 9.590278e-03 2.515490e-03 1.978033e-02 3.454990e-02 8.072748e-03 4.718885e-03 1.621131e-01 4.547743e-03 1.081195e-02 9.572051e-04 1.790391e-02 1.618026e-02 1.910230e-02 1.861914e-02 3.485475e-02 > [211] 2.844890e-03 1.866889e-02 1.378208e-02 2.451514e-02 2.535044e-03 3.921364e-04 1.557266e-03 3.315892e-03 1.752821e-03 6.786187e-03 1.360921e-02 9.550702e-03 8.114506e-03 5.068741e-03 1.729822e-02 > [226] 1.902033e-02 8.196564e-03 2.632880e-03 1.587969e-02 8.354079e-04 1.050023e-03 4.236195e-04 9.181120e-03 4.995919e-04 1.092234e-02 1.207544e-02 2.187243e-01 3.251349e-02 1.269134e-03 1.557751e-04 > [241] 1.232498e-02 2.654449e-02 1.049324e-03 8.442729e-03 6.331691e-03 1.715609e-02 1.017800e-03 9.230006e-03 1.331373e-02 5.596195e-02 1.296551e-03 5.272687e-03 2.805640e-02 4.790665e-02 2.043011e-02 > [256] 1.047226e-02 1.866499e-02 9.323001e-03 8.920536e-03 1.582911e-03 2.776238e-03 2.914762e-02 4.402356e-03 9.555274e-04 1.681966e-03 7.584319e-04 6.758914e-02 1.505431e-02 2.213308e-02 1.329330e-02 > [271] 7.284363e-03 2.687818e-02 2.997535e-03 7.470007e-03 2.070569e-03 3.441944e-02 1.717768e-02 4.523364e-02 1.003558e-02 1.365111e-02 1.906845e-02 1.676223e-02 3.506809e-04 9.164257e-02 9.008416e-03 > [286] 1.073903e-02 4.855937e-03 8.618043e-03 2.529247e-02 1.059375e-02 5.834253e-03 2.004309e-02 1.460387e-02 2.899190e-02 5.867984e-03 1.983956e-02 6.834339e-03 1.925821e-03 9.231870e-03 6.839616e-03 > [301] 1.029972e-02 2.009769e-02 9.458785e-03 1.183901e-02 8.911549e-03 1.264745e-02 2.995451e-03 7.657983e-04 5.315853e-03 1.325039e-02 1.044103e-02 2.307236e-02 2.780789e-02 1.735145e-02 9.053126e-03 > [316] 5.847638e-02 3.815715e-03 5.087690e-03 1.040513e-02 4.475672e-02 6.564791e-02 3.233571e-03 1.076193e-02 8.283819e-02 5.370256e-03 3.533256e-02 1.302812e-02 1.896783e-02 2.055282e-02 3.572239e-03 > [331] 5.867681e-03 5.864974e-04 9.715807e-03 1.665469e-02 5.082044e-02 3.547168e-03 3.069631e-03 1.274717e-02 1.858226e-03 3.104809e-04 1.247831e-02 2.073575e-03 3.544110e-04 7.240736e-03 8.452117e-05 > [346] 8.149151e-04 4.942461e-05 1.142303e-03 6.265512e-04 3.666717e-04 3.244669e-02 7.242018e-03 6.335951e-04 2.329072e-02 3.719716e-03 2.803425e-02 1.623981e-02 6.387102e-03 8.807679e-03 1.214914e-02 > [361] 6.699341e-03 1.148082e-02 1.329736e-02 1.537364e-03 2.004390e-02 1.562065e-02 1.655465e-02 9.960172e-02 2.174588e-02 1.209472e-02 2.328413e-02 2.012760e-04 1.422327e-02 2.194455e-03 2.307362e-02 > [376] 4.315764e-03 3.208576e-02 3.826598e-02 1.828001e-02 3.935978e-03 5.294211e-04 1.392423e-02 6.588394e-03 1.040147e-03 1.260787e-02 9.051757e-04 5.353215e-02 6.049058e-02 1.382630e-01 1.064124e-01 > [391] 3.380742e-03 1.798038e-02 1.557048e-01 1.217146e-02 4.140520e-02 4.707564e-02 2.786042e-02 8.836988e-03 5.542879e-03 1.862664e-02 8.858770e-03 1.026681e-03 1.692105e-02 8.849238e-03 7.143816e-03 > [406] 1.630118e-02 1.165920e-01 9.471496e-03 4.879998e-02 1.388216e-02 1.453267e-02 4.845224e-04 1.415190e-03 1.208627e-02 1.372348e-02 2.573131e-02 1.169595e-02 1.825447e-02 2.574299e-02 5.301360e-02 > [421] 6.961110e-03 7.781891e-03 1.013308e-03 3.160916e-03 1.090344e-02 1.530841e-02 9.398088e-04 9.143726e-04 1.286683e-02 2.006193e-02 1.774378e-02 5.681591e-02 9.584676e-03 7.957152e-02 4.485609e-03 > [436] 1.086684e-02 2.930273e-03 6.085481e-03 4.342320e-03 1.319999e-02 2.120402e-02 4.477545e-02 1.991814e-02 8.893947e-03 7.790133e-03 1.610199e-02 2.441280e-02 2.781231e-03 1.410080e-02 1.639912e-02 > [451] 1.797498e-02 1.185382e-02 2.775063e-02 3.797315e-02 1.428883e-02 1.272659e-02 2.390500e-03 7.503478e-03 8.965356e-03 2.139452e-02 2.028536e-02 6.916416e-02 1.615986e-02 4.837412e-02 1.561731e-02 > [466] 7.130332e-03 9.208406e-05 1.099934e-02 2.003469e-02 1.395857e-02 9.883482e-03 4.110852e-02 1.202052e-02 2.833039e-02 1.233236e-02 2.145801e-02 7.900161e-03 4.663819e-02 4.410819e-03 5.115056e-04 > [481] 9.100270e-04 4.013683e-03 1.227139e-02 3.304697e-03 2.919099e-03 6.112390e-03 1.922229e-02 1.208282e-03 1.164037e-02 2.166888e-02 4.381615e-02 5.318929e-03 7.226343e-03 2.732819e-02 2.385092e-04 > [496] 4.905250e-02 1.159876e-02 4.068228e-03 3.349013e-02 1.273468e-03 > > > Thanks for your help, > > Ben > > On Thu, Dec 1, 2011 at 11:55 AM, peter dalgaard wrote: > > On Dec 1, 2011, at 18:54 , Ben quant wrote: > > > Sorry if this is a duplicate: This is a re-post because the pdf's mentioned > > below did not go through. > > Still not there. Sometimes it's because your mailer doesn't label them with the appropriate mime-type (e.g. as application/octet-stream, which is "arbitrary binary"). Anyways, see below > > [snip] > > > > With the above data I do: > >> l_logit = glm(y~x, data=as.data.frame(l_yx), > > family=binomial(link="logit")) > > Warning message: > > glm.fit: fitted probabilities numerically 0 or 1 occurred > > > > Why am I getting this warning when I have data points of varying values for > > y=1 and y=0? In other words, I don't think I have the linear separation > > issue discussed in one of the links I provided. > > I bet that you do... You can get the warning without that effect (one of my own examples is the probability of menarche in a data set that includes infants and old age pensioners), but not with a huge odds ratio as well. Take a look at > > d <- as.data.frame(l_yx) > with(d, y[order(x)]) > > if it comes out as all zeros followed by all ones or vice versa, then you have the problem. > > > > > > PS - Then I do this and I get a odds ratio a crazy size: > >> l_sm = summary(l_logit) # coef pval is $coefficients[8], log odds > > $coefficients[2] > >> l_exp_coef = exp(l_logit$coefficients)[2] # exponentiate the > > coeffcients > >> l_exp_coef > > x > > 3161.781 > > > > So for one unit increase in the predictor variable I get 3160.781% > > (3161.781 - 1 = 3160.781) increase in odds? That can't be correct either. > > How do I correct for this issue? (I tried multiplying the predictor > > variables by a constant and the odds ratio goes down, but the warning above > > still persists and shouldn't the odds ratio be predictor variable size > > independent?) > > > -- > Peter Dalgaard, Professor, > Center for Statistics, Copenhagen Business School > Solbjerg Plads 3, 2000 Frederiksberg, Denmark > Phone: (+45)38153501 > Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com > > > > > > > > > -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com From haavard.kongsgaard at gmail.com Thu Dec 1 22:26:31 2011 From: haavard.kongsgaard at gmail.com (=?ISO-8859-1?Q?H=E5vard_Wahl_Kongsg=E5rd?=) Date: Thu, 1 Dec 2011 22:26:31 +0100 Subject: [R] MCMCglmm error with multinomial distribution Message-ID: With binomial/binary responses (0|1) running MCMCglmm with family="multinomial" terminates with Error in if (nJ < 1) { : missing value where TRUE/FALSE needed with family="categorical" there are no errors I have not looked in the code, do I need format the responses TRUE/FALSE , or is this just a bug? -- H?vard Wahl Kongsg?rd From seth at userprimary.net Thu Dec 1 22:48:59 2011 From: seth at userprimary.net (Seth Falcon) Date: Thu, 1 Dec 2011 13:48:59 -0800 Subject: [R] [R-pkgs] RSQLite 0.11.0 Message-ID: <509CC1B4-BCC2-4AA1-B3E7-838379DC57A4@userprimary.net> A new version of RSQLite has been uploaded to CRAN. Details on the enhancements and fixes are below. Please direct questions to the R-sig-db mailing list. Version 0.11.0 - Enhance type detection in sqliteDataType (dbDataType). The storage mode of a data.frame column is now used as part of the type detection. Prior to this patch, all vectors with class other than numeric or logical were mapped to a TEXT column. This patch uses the output of storage.mode to map to integer and double vectors to INTEGER and REAL columns, respectively. All other modes are mapped to a TEXT column. - Detection of BLOBs was narrowed slightly. The code now treats only objects with data.class(obj) == "list" as BLOBs. Previously, is.list was used which could return TRUE for lists of various classes. - Fix bug in sqliteImportFile (used by dbWriteTable) that prevented a comment character from being specified for the input file. - Increase compile-time SQLite limits for maximum number of columns in a table to 30000 and maximum number of parameters (?N) in a SELECT to 40000. Use of wide tables is not encouraged. The default values for SQLite are 2000 and 999, respectively. Databases containing tables with more than 2000 columns may not be compatible with versions of SQLite compiled with default settings. - Upgrade to SQLite 3.7.9. -- Seth Falcon | @sfalcon | http://userprimary.net/ _______________________________________________ R-packages mailing list R-packages at r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages From ggrothendieck at gmail.com Thu Dec 1 22:53:36 2011 From: ggrothendieck at gmail.com (Gabor Grothendieck) Date: Thu, 1 Dec 2011 16:53:36 -0500 Subject: [R] legend, "lheight", and alignment In-Reply-To: <1322758482556-4129402.post@n4.nabble.com> References: <1322758482556-4129402.post@n4.nabble.com> Message-ID: On Thu, Dec 1, 2011 at 11:54 AM, emorway wrote: > Hello, > > A bit of fairly simple code, yet I don't seem to be able to manipulate it > quite as much as I would like: > > 1) ?It would be nice if the objects appearing in the legend were aligned, > and by aligned I mean the boxes are centered over the lines. ?Do I need to > adjust the use of "NA" in the code below to accomplish this? ?Here's how it > appears on my machine: > > http://r.789695.n4.nabble.com/file/n4129402/example.png > > 2) ?Because I'm using a call to 'expression' in the text contained in the > legend, it would be nice to space ?the lines of text a bit more. ?My feeble > attempt was to increase the lheight parameter in the hopes this would affect > the legend...to no avail. ?Further, lheight cannot be added to the argument > list of legend. ?I've been unable to track down another parameter applicable > to legend, suggestions very much appreciated. > > par(lheight=2) > plot(1,1,col="white") > > legend("center", legend=c(expression(paste("Observed > ",italic(bar(EC)[e]))),expression(paste("Simulated > ",italic(bar(EC)[e]))),"test1","test2"), > ? ? ? lty = c(NA,NA,1,1), > ? ? ? col = c("black","black","red","blue"), > ? ? ? density = c(NA,25,NA,NA), > ? ? ? border=c("black","black",NA,NA), > ? ? ? fill = c("grey","black",NA,NA), > ? ? ? angle = c(NA,45,NA,NA), > ? ? ? cex = 1.25, bty = "n", xpd = TRUE) > For #1 it would be easier to just use 2 columns so that there is no question of alignment in the first place, i.e. ncol = 2. For #2 try drawing the legend from lower level functions such as text since text does respect lheight. See the source of legendg in plotrix for how to do that. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com From aodhanol at gmail.com Thu Dec 1 21:07:45 2011 From: aodhanol at gmail.com (AOLeary) Date: Thu, 1 Dec 2011 12:07:45 -0800 (PST) Subject: [R] Writing a function, want a string argument to define the name of the excel sheet to be called In-Reply-To: References: <1322747017324-4128384.post@n4.nabble.com> <1DE876CE-60DE-46B7-A0AF-CF40B7E9BE12@depauw.edu> <1322748601119-4128495.post@n4.nabble.com> Message-ID: <1322770065316-4130233.post@n4.nabble.com> Thanks Michael, I'll keep that in mind if I want to do anything more complicated. -- View this message in context: http://r.789695.n4.nabble.com/Writing-a-function-want-a-string-argument-to-define-the-name-of-the-excel-sheet-to-be-called-tp4128384p4130233.html Sent from the R help mailing list archive at Nabble.com. From salerno.franco73 at gmail.com Thu Dec 1 22:07:46 2011 From: salerno.franco73 at gmail.com (franco salerno) Date: Thu, 1 Dec 2011 22:07:46 +0100 Subject: [R] mixed effect model (multilevel) Message-ID: Hi, I have a problem with mixed effect model (multilevel). My model that is written in following formulation using the lme4 package and Zelig package: mylogit<- lmer(OVERFLOW ~ ALTEZZA + INTENSITA + ( 1 | CODICE), family= binomial(link = "probit"),data = dati) OVERFLOW can be 0 or 1 and represents the activation of a combined sewer overflow ALTEZZA is integer and reppresents the total precipitation occured during an event INTENSITA is integer and reppresents the maximun precipitation intensity occured during an event CODICE are different (13) combined sewer overflows I am analysing 480 OVERFLOWs. Summary Generalized linear mixed model fit by the Laplace approximation Formula: OVERFLOW ~ ALTEZZA + INTENSITA + (1 | CODICE) Data: dati AIC BIC logLik deviance 509.2 525.9 -250.6 501.2 Random effects: Groups Name Variance Std.Dev. CODICE (Intercept) 0.73159 0.85533 Number of obs: 480, groups: CODICE, 13 Fixed effects: Estimate Std. Error z value Pr(>|z|) (Intercept) -0.818969 0.264502 -3.096 0.00196 ** ALTEZZA 0.023416 0.004184 5.596 2.19e-08 *** INTENSITA 0.069759 0.021693 3.216 0.00130 ** --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 Correlation of Fixed Effects: (Intr) ALTEZZ ALTEZZA -0.155 INTENSITA -0.201 -0.399 I would like to have: 1) an indicator of performarce of my model (is it good the fitness of my model?? 2) a sort of cross-validation 3) information on relative importance of predictors (marginal effects???) Please, help me!!!!! Thanks From Jean-Paul.Vallee at unige.ch Thu Dec 1 22:29:57 2011 From: Jean-Paul.Vallee at unige.ch (jean-paul.vallee) Date: Thu, 01 Dec 2011 22:29:57 +0100 Subject: [R] pb with 4D dicom data and oro.dicom Message-ID: <186E4C4A-7F9D-4BE7-8697-CA4CC1002C8D@unige.ch> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From stephg0809 at gmail.com Thu Dec 1 22:51:38 2011 From: stephg0809 at gmail.com (stephg0809) Date: Thu, 1 Dec 2011 13:51:38 -0800 (PST) Subject: [R] Error message: object 'A' not found Message-ID: <1322776298315-4140237.post@n4.nabble.com> I ran the following code: And I run into problems with the last line of code (when it says hn<-......). I keep getting an error code: Error in distsamp(~hab ~ 1, peldist, keyfun = "halfnorm", output = "density", : object 'A' not found I would appreciate any and all help. rm(list=ls(all=TRUE)) #clear the computer's memory of variables setwd("E:\\Analysis") # Part 1 library(unmarked) # this loads the 'unmarked' package in R Pellet <- read.table("PelletDistance.csv", sep=",", header=T) # read in the data head(Pellet) # this provides a header of the first few lines of data and variable names Treatment <- Pellet[66:166,] # Isolates data for just the good habitat Control <- Pellet[1:65,] # same for bad habitat hist(Pellet$Distance,freq=F,xlim=c(0,7)) # plots a histogram, or frequency distribution of the data # Part 2 # Create formated distance response matrix cp <- c(0,0.50,2,3.50,5.00,6.50) # Distance cut points defining distance intervals yDat <- formatDistData(Pellet, "Distance", "Line", cp) # This creates a formatted data matrix for number of observations at each distance interval for each transect yDat # Prepare habitat covariates for each transect based on the stratum they reside in hab <- matrix(c("C","C","C","C","C","C","C","C","C","T","T","T","T","T","T","T","T","T"),nrow=18,ncol=1) #CHANGE THIS!!! nrow=# of T and Cs or A-Ks (same #) hab <- data.frame(hab) #Year effects year <- matrix(c("Year1","Year1","Year1","Year1","Year2","Year2","Year2","Year2","Year2","Year1","Year1","Year1","Year1","Year2","Year2","Year2","Year2","Year2"),nrow=18,ncol=1) #CHANGE THIS!!! to match number of A-Ks And change nrow year <- data.frame(year) # Prepare transect lengths len <- as.numeric(c(100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100)) #Make this equal A, AA....KK for number of 10000s # Organize distance data along with covariates and metadata, MAKE SURE THESE COVARIATES ARE RIGHT, MAYBE I CAN ADD MINE HERE peldist <- unmarkedFrameDS(y=yDat, siteCovs = data.frame(hab, year), dist.breaks=cp, tlength=len, survey="Line", unitsIn="m") peldist # look at the data summary(peldist) # get a summary of the data # Part 3 # Fit models without covariates hn <- distsamp(~1 ~1, peldist, keyfun="halfnorm", output="density", unitsOut="ha") -- View this message in context: http://r.789695.n4.nabble.com/Error-message-object-A-not-found-tp4140237p4140237.html Sent from the R help mailing list archive at Nabble.com. From ccquant at gmail.com Thu Dec 1 23:07:57 2011 From: ccquant at gmail.com (Ben quant) Date: Thu, 1 Dec 2011 15:07:57 -0700 Subject: [R] logistic regression - glm.fit: fitted probabilities numerically 0 or 1 occurred In-Reply-To: References: <2F36BA38-DD8B-4660-ACA1-709750BE0D35@gmail.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From ccquant at gmail.com Thu Dec 1 23:25:50 2011 From: ccquant at gmail.com (Ben quant) Date: Thu, 1 Dec 2011 15:25:50 -0700 Subject: [R] logistic regression - glm.fit: fitted probabilities numerically 0 or 1 occurred In-Reply-To: References: <2F36BA38-DD8B-4660-ACA1-709750BE0D35@gmail.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From ccquant at gmail.com Thu Dec 1 23:43:59 2011 From: ccquant at gmail.com (Ben quant) Date: Thu, 1 Dec 2011 15:43:59 -0700 Subject: [R] logistic regression - glm.fit: fitted probabilities numerically 0 or 1 occurred In-Reply-To: References: <2F36BA38-DD8B-4660-ACA1-709750BE0D35@gmail.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From carl at witthoft.com Fri Dec 2 00:13:16 2011 From: carl at witthoft.com (Carl Witthoft) Date: Thu, 01 Dec 2011 18:13:16 -0500 Subject: [R] strange row numbering after rbind-ing a list Message-ID: <4ED80A0C.10802@witthoft.com> "Not that it really matters, but" Can someone explain how the row numbers get assigned in the following sequence? It looks like something funky happens when rbind() coerces 'bar' into a dataframe. In either sequence of rbind below, once you get past the first two rows, the row numbers count normally. Rgames> (foo<-data.frame(x=5,y=4,r=3)) x y r 1 5 4 3 Rgames> (bar<-list(x=4,y=5,r=6)) $x [1] 4 $y [1] 5 $r [1] 6 Rgames> (foobar<- rbind(foo,bar)) x y r 1 5 4 3 2 4 5 6 Rgames> (foobar<- rbind(foobar,bar)) x y r 1 5 4 3 2 4 5 6 3 4 5 6 Rgames> (barfoo<-rbind(bar,foo)) x y r 2 4 5 6 21 5 4 3 Rgames> (barfoo<-rbind(barfoo,foo)) x y r 2 4 5 6 21 5 4 3 3 5 4 3 -- Sent from my Cray XK6 "Pendeo-navem mei anguillae plena est." From bps0002 at auburn.edu Fri Dec 2 00:23:59 2011 From: bps0002 at auburn.edu (B77S) Date: Thu, 1 Dec 2011 15:23:59 -0800 (PST) Subject: [R] Summarizing elements of a list In-Reply-To: <1322777855869-4142479.post@n4.nabble.com> References: <1322777855869-4142479.post@n4.nabble.com> Message-ID: <1322781839766-4142884.post@n4.nabble.com> Someone is bound to know a better way, but... subset(unlist(Version1_), subset=names(unlist(Version1_))=="First") LCOG1 wrote > > Hi everyone, > I looked around the list for a while but couldn't find a solution to my > problem. I am storing some results to a simulation in a list and for each > element i have two separate vectors(is that what they are called, correct > my vocab if necessary). See below > > Version1_<-list() > for(i in 1:5){ > Version1_[[i]]<-list(First=rnorm(1),Second=rnorm(1)) > } > > What I want is to put all of the elements' 'First' vectors into a single > list to box plot. But whats a more elegant solution to the below? > > c(Version1_[[1]]$First,Version1_[[2]]$First,Version1_[[3]]$First,Version1_[[4]]$First,Version1_[[5]]$First) > > since i have 50 or more simulations this is impractical and sloppy. Do I > need to store my data differently or is their a solution on the back end? > Thanks all. > > Josh > -- View this message in context: http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4142884.html Sent from the R help mailing list archive at Nabble.com. From sarah.goslee at gmail.com Fri Dec 2 00:26:18 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Thu, 1 Dec 2011 18:26:18 -0500 Subject: [R] strange row numbering after rbind-ing a list In-Reply-To: <4ED80A0C.10802@witthoft.com> References: <4ED80A0C.10802@witthoft.com> Message-ID: Those are row *names*, not row *numbers*. It's just that if you don't specify, numbers are assigned by default when creating a data frame. Your rbind() statements are implicitly creating a data frame, so the likely information is in ?data.frame: check.names: logical. If ?TRUE? then the names of the variables in the data frame are checked to ensure that they are syntactically valid variable names and are not duplicated. If necessary they are adjusted (by ?make.names?) so that they are. By default, row.names=NULL and check.names=TRUE. See also ?rbind.data.frame Sarah On Thu, Dec 1, 2011 at 6:13 PM, Carl Witthoft wrote: > "Not that it really matters, but" > Can someone explain how the row numbers get assigned in the following > sequence? It looks like something funky happens when rbind() coerces 'bar' > into a dataframe. > In either sequence of rbind below, once you get past the first two rows, the > row numbers count normally. > > > Rgames> (foo<-data.frame(x=5,y=4,r=3)) > ?x y r > 1 5 4 3 > Rgames> (bar<-list(x=4,y=5,r=6)) > $x > [1] 4 > > $y > [1] 5 > > $r > [1] 6 > > Rgames> (foobar<- rbind(foo,bar)) > ?x y r > 1 5 4 3 > 2 4 5 6 > > Rgames> (foobar<- rbind(foobar,bar)) > ?x y r > 1 5 4 3 > 2 4 5 6 > 3 4 5 6 > > > Rgames> (barfoo<-rbind(bar,foo)) > ? x y r > 2 ?4 5 6 > 21 5 4 3 > > Rgames> (barfoo<-rbind(barfoo,foo)) > ? x y r > 2 ?4 5 6 > 21 5 4 3 > 3 ?5 4 3 -- Sarah Goslee http://www.functionaldiversity.org From pdalgd at gmail.com Fri Dec 2 00:32:07 2011 From: pdalgd at gmail.com (peter dalgaard) Date: Fri, 2 Dec 2011 00:32:07 +0100 Subject: [R] logistic regression - glm.fit: fitted probabilities numerically 0 or 1 occurred In-Reply-To: References: <2F36BA38-DD8B-4660-ACA1-709750BE0D35@gmail.com> Message-ID: <3684DD42-A6F4-487C-B7C0-220C044FF843@gmail.com> On Dec 1, 2011, at 23:43 , Ben quant wrote: > I'm not proposing this as a permanent solution, just investigating the warning. I zeroed out the three outliers and received no warning. Can someone tell me why I am getting no warning now? It's easier to explain why you got the warning before. If the OR for a one unit change is 3000, the OR for a 14 unit change is on the order of 10^48 and that causes over/underflow in the conversion to probabilities. I'm still baffled at how you can get that model fitted to your data, though. One thing is that you can have situations where there are fitted probabilities of one corresponding to data that are all one and/or fitted zeros where data are zero, but you seem to have cases where you have both zeros and ones at both ends of the range of x. Fitting a zero to a one or vice versa would make the likelihood zero, so you'd expect that the algorithm would find a better set of parameters rather quickly. Perhaps the extremely large number of observations that you have has something to do with it? You'll get the warning if the fitted zeros or ones occur at any point of the iterative procedure. Maybe it isn't actually true for the final model, but that wouldn't seem consistent with the OR that you cited. Anyways, your real problem lies with the distribution of the x values. I'd want to try transforming it to something more sane. Taking logarithms is the obvious idea, but you'd need to find out what to do about the zeros -- perhaps log(x + 1e-4) ? Or maybe just cut the outliers down to size with pmin(x,1). > > I did this 3 times to get rid of the 3 outliers: > mx_dims = arrayInd(which.max(l_yx), dim(l_yx)) > l_yx[mx_dims] = 0 > > Now this does not produce an warning: > l_logit = glm(y~x, data=as.data.frame(l_yx), family=binomial(link="logit")) > > Can someone tell me why occurred? > > Also, again, here are the screen shots of my data that I tried to send earlier (two screen shots, two pages): > http://scientia.crescat.net/static/ben/warn%20num%200%20or%201.pdf > > Thank you for your help, > > Ben > > On Thu, Dec 1, 2011 at 3:25 PM, Ben quant wrote: > Oops! Please ignore my last post. I mistakenly gave you different data I was testing with. This is the correct data: > > Here you go: > > > attach(as.data.frame(l_yx)) > > range(x[y==0]) > [1] 0.00000 14.66518 > > range(x[y==1]) > [1] 0.00000 13.49791 > > > How do I know what is acceptable? > > Also, here are the screen shots of my data that I tried to send earlier (two screen shots, two pages): > http://scientia.crescat.net/static/ben/warn%20num%200%20or%201.pdf > > Thank you, > > Ben > > On Thu, Dec 1, 2011 at 3:07 PM, Ben quant wrote: > Here you go: > > > attach(as.data.frame(l_yx)) > > range(x[y==1]) > [1] -22500.0000 746.6666 > > range(x[y==0]) > [1] -10076.5303 653.0228 > > How do I know what is acceptable? > > Also, here are the screen shots of my data that I tried to send earlier (two screen shots, two pages): > http://scientia.crescat.net/static/ben/warn%20num%200%20or%201.pdf > > Thank you, > > Ben > > > On Thu, Dec 1, 2011 at 2:24 PM, peter dalgaard wrote: > > On Dec 1, 2011, at 21:32 , Ben quant wrote: > > > Thank you for the feedback, but my data looks fine to me. Please tell me if I'm not understanding. > > Hum, then maybe it really is a case of a transition region being short relative to the range of your data. Notice that the warning is just that: a warning. I do notice that the distribution of your x values is rather extreme -- you stated a range of 0--14 and a mean of 0.01. And after all, an odds ratio of 3000 per unit is only a tad over a doubling per 0.1 units. > > Have a look at range(x[y==0]) and range(x[y==1]). > > > > > > I followed your instructions and here is a sample of the first 500 values : (info on 'd' is below that) > > > > > d <- as.data.frame(l_yx) > > > x = with(d, y[order(x)]) > > > x[1:500] # I have 1's and 0's dispersed throughout > > [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 > > [101] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > > [201] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 1 0 0 > > [301] 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > > [401] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 > > > > # I get the warning still > > > l_df = as.data.frame(l_yx) > > > l_logit = glm(y~x, data=l_df, family=binomial(link="logit")) > > > > Warning message: > > glm.fit: fitted probabilities numerically 0 or 1 occurred > > > > # some info on 'd' above: > > > > > d[1:500,1] > > [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > > [101] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > > [201] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > > [301] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > > [401] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > > > d[1:500,2] > > [1] 3.023160e-03 7.932130e-02 0.000000e+00 1.779657e-02 1.608374e-01 0.000000e+00 5.577064e-02 7.753926e-03 4.018553e-03 4.760918e-02 2.080511e-02 1.642404e-01 3.703720e-03 8.901981e-02 1.260415e-03 > > [16] 2.202523e-02 3.750940e-02 4.441975e-04 9.351171e-03 8.374567e-03 0.000000e+00 8.440448e-02 5.081017e-01 2.538640e-05 1.806017e-02 2.954641e-04 1.434859e-03 6.964976e-04 0.000000e+00 1.202162e-02 > > [31] 3.420300e-03 4.276100e-02 1.457324e-02 4.140121e-03 1.349180e-04 1.525292e-03 4.817502e-02 9.515717e-03 2.232953e-02 1.227908e-01 3.293581e-02 1.454352e-02 1.176011e-03 6.274138e-02 2.879205e-02 > > [46] 6.900926e-03 1.414648e-04 3.446349e-02 8.807174e-03 3.549332e-02 2.828509e-03 2.935003e-02 7.162872e-03 5.650050e-03 1.221191e-02 0.000000e+00 2.126334e-02 2.052020e-02 7.542409e-02 2.586269e-04 > > [61] 5.258664e-02 1.213126e-02 1.493275e-02 8.152657e-03 1.774966e-02 2.433198e-02 1.371257e-02 6.732339e-02 9.747677e-03 8.180594e-03 1.882473e-01 1.682596e-03 1.410170e-02 8.429676e-03 3.520589e-01 > > [76] 1.865160e-02 2.389941e-02 3.301558e-02 4.896605e-03 6.826244e-03 9.151337e-02 1.722270e-02 1.764039e-01 3.554063e-02 7.338532e-03 9.577793e-03 3.632366e-03 1.422400e-02 3.020497e-02 1.797096e-02 > > [91] 2.577899e-03 1.338365e-01 8.202223e-03 1.088335e-02 2.137259e-02 6.829797e-03 3.104860e-04 8.927160e-03 5.626881e-02 1.197682e-02 6.140553e-02 2.729364e-02 1.377913e-02 3.018277e-03 1.188304e-02 > > [106] 2.029268e-03 2.108815e-02 1.765503e-03 2.449253e-02 3.677046e-03 1.013463e-02 4.286642e-02 1.238931e-02 3.072090e-03 1.509613e-02 3.609885e-02 5.537268e-03 3.151614e-02 3.703148e-03 1.409401e-01 > > [121] 1.473365e-02 9.160461e-03 1.035099e-01 3.005865e-02 1.332199e-02 6.936535e-03 2.433539e-02 4.935373e-03 4.822740e-03 1.597643e-03 3.805619e-03 1.092683e-02 1.760635e-01 5.565614e-03 7.739213e-04 > > [136] 4.529198e-03 5.110359e-03 7.391258e-02 5.018207e-03 2.071417e-02 1.825787e-02 9.141405e-03 1.078386e-01 2.171470e-04 7.164583e-03 2.522077e-02 1.994428e-03 6.044653e-03 1.778078e-04 5.797706e-03 > > [151] 1.526778e-02 1.595897e-02 1.995627e-01 1.946735e-03 6.711582e-02 2.722350e-02 3.127499e-02 1.074904e-01 2.477414e-03 5.015375e-02 3.417810e-02 2.046643e-02 1.644832e-02 5.220166e-03 1.217752e-02 > > [166] 1.187352e-02 1.634016e-02 2.349568e-03 3.451811e-02 2.593540e-03 6.868595e-03 1.311236e-02 6.457757e-03 2.942391e-04 1.628352e-02 8.288831e-03 3.170856e-04 1.251331e+00 1.706954e-02 1.063723e-03 > > [181] 1.374416e-02 2.140507e-02 2.817009e-02 2.272793e-02 4.365562e-02 6.089414e-03 2.498083e-02 1.360471e-02 1.884079e-02 1.448660e-02 2.341314e-02 8.167064e-03 4.109117e-02 2.660633e-02 7.711723e-03 > > [196] 9.590278e-03 2.515490e-03 1.978033e-02 3.454990e-02 8.072748e-03 4.718885e-03 1.621131e-01 4.547743e-03 1.081195e-02 9.572051e-04 1.790391e-02 1.618026e-02 1.910230e-02 1.861914e-02 3.485475e-02 > > [211] 2.844890e-03 1.866889e-02 1.378208e-02 2.451514e-02 2.535044e-03 3.921364e-04 1.557266e-03 3.315892e-03 1.752821e-03 6.786187e-03 1.360921e-02 9.550702e-03 8.114506e-03 5.068741e-03 1.729822e-02 > > [226] 1.902033e-02 8.196564e-03 2.632880e-03 1.587969e-02 8.354079e-04 1.050023e-03 4.236195e-04 9.181120e-03 4.995919e-04 1.092234e-02 1.207544e-02 2.187243e-01 3.251349e-02 1.269134e-03 1.557751e-04 > > [241] 1.232498e-02 2.654449e-02 1.049324e-03 8.442729e-03 6.331691e-03 1.715609e-02 1.017800e-03 9.230006e-03 1.331373e-02 5.596195e-02 1.296551e-03 5.272687e-03 2.805640e-02 4.790665e-02 2.043011e-02 > > [256] 1.047226e-02 1.866499e-02 9.323001e-03 8.920536e-03 1.582911e-03 2.776238e-03 2.914762e-02 4.402356e-03 9.555274e-04 1.681966e-03 7.584319e-04 6.758914e-02 1.505431e-02 2.213308e-02 1.329330e-02 > > [271] 7.284363e-03 2.687818e-02 2.997535e-03 7.470007e-03 2.070569e-03 3.441944e-02 1.717768e-02 4.523364e-02 1.003558e-02 1.365111e-02 1.906845e-02 1.676223e-02 3.506809e-04 9.164257e-02 9.008416e-03 > > [286] 1.073903e-02 4.855937e-03 8.618043e-03 2.529247e-02 1.059375e-02 5.834253e-03 2.004309e-02 1.460387e-02 2.899190e-02 5.867984e-03 1.983956e-02 6.834339e-03 1.925821e-03 9.231870e-03 6.839616e-03 > > [301] 1.029972e-02 2.009769e-02 9.458785e-03 1.183901e-02 8.911549e-03 1.264745e-02 2.995451e-03 7.657983e-04 5.315853e-03 1.325039e-02 1.044103e-02 2.307236e-02 2.780789e-02 1.735145e-02 9.053126e-03 > > [316] 5.847638e-02 3.815715e-03 5.087690e-03 1.040513e-02 4.475672e-02 6.564791e-02 3.233571e-03 1.076193e-02 8.283819e-02 5.370256e-03 3.533256e-02 1.302812e-02 1.896783e-02 2.055282e-02 3.572239e-03 > > [331] 5.867681e-03 5.864974e-04 9.715807e-03 1.665469e-02 5.082044e-02 3.547168e-03 3.069631e-03 1.274717e-02 1.858226e-03 3.104809e-04 1.247831e-02 2.073575e-03 3.544110e-04 7.240736e-03 8.452117e-05 > > [346] 8.149151e-04 4.942461e-05 1.142303e-03 6.265512e-04 3.666717e-04 3.244669e-02 7.242018e-03 6.335951e-04 2.329072e-02 3.719716e-03 2.803425e-02 1.623981e-02 6.387102e-03 8.807679e-03 1.214914e-02 > > [361] 6.699341e-03 1.148082e-02 1.329736e-02 1.537364e-03 2.004390e-02 1.562065e-02 1.655465e-02 9.960172e-02 2.174588e-02 1.209472e-02 2.328413e-02 2.012760e-04 1.422327e-02 2.194455e-03 2.307362e-02 > > [376] 4.315764e-03 3.208576e-02 3.826598e-02 1.828001e-02 3.935978e-03 5.294211e-04 1.392423e-02 6.588394e-03 1.040147e-03 1.260787e-02 9.051757e-04 5.353215e-02 6.049058e-02 1.382630e-01 1.064124e-01 > > [391] 3.380742e-03 1.798038e-02 1.557048e-01 1.217146e-02 4.140520e-02 4.707564e-02 2.786042e-02 8.836988e-03 5.542879e-03 1.862664e-02 8.858770e-03 1.026681e-03 1.692105e-02 8.849238e-03 7.143816e-03 > > [406] 1.630118e-02 1.165920e-01 9.471496e-03 4.879998e-02 1.388216e-02 1.453267e-02 4.845224e-04 1.415190e-03 1.208627e-02 1.372348e-02 2.573131e-02 1.169595e-02 1.825447e-02 2.574299e-02 5.301360e-02 > > [421] 6.961110e-03 7.781891e-03 1.013308e-03 3.160916e-03 1.090344e-02 1.530841e-02 9.398088e-04 9.143726e-04 1.286683e-02 2.006193e-02 1.774378e-02 5.681591e-02 9.584676e-03 7.957152e-02 4.485609e-03 > > [436] 1.086684e-02 2.930273e-03 6.085481e-03 4.342320e-03 1.319999e-02 2.120402e-02 4.477545e-02 1.991814e-02 8.893947e-03 7.790133e-03 1.610199e-02 2.441280e-02 2.781231e-03 1.410080e-02 1.639912e-02 > > [451] 1.797498e-02 1.185382e-02 2.775063e-02 3.797315e-02 1.428883e-02 1.272659e-02 2.390500e-03 7.503478e-03 8.965356e-03 2.139452e-02 2.028536e-02 6.916416e-02 1.615986e-02 4.837412e-02 1.561731e-02 > > [466] 7.130332e-03 9.208406e-05 1.099934e-02 2.003469e-02 1.395857e-02 9.883482e-03 4.110852e-02 1.202052e-02 2.833039e-02 1.233236e-02 2.145801e-02 7.900161e-03 4.663819e-02 4.410819e-03 5.115056e-04 > > [481] 9.100270e-04 4.013683e-03 1.227139e-02 3.304697e-03 2.919099e-03 6.112390e-03 1.922229e-02 1.208282e-03 1.164037e-02 2.166888e-02 4.381615e-02 5.318929e-03 7.226343e-03 2.732819e-02 2.385092e-04 > > [496] 4.905250e-02 1.159876e-02 4.068228e-03 3.349013e-02 1.273468e-03 > > > > > > Thanks for your help, > > > > Ben > > > > On Thu, Dec 1, 2011 at 11:55 AM, peter dalgaard wrote: > > > > On Dec 1, 2011, at 18:54 , Ben quant wrote: > > > > > Sorry if this is a duplicate: This is a re-post because the pdf's mentioned > > > below did not go through. > > > > Still not there. Sometimes it's because your mailer doesn't label them with the appropriate mime-type (e.g. as application/octet-stream, which is "arbitrary binary"). Anyways, see below > > > > [snip] > > > > > > With the above data I do: > > >> l_logit = glm(y~x, data=as.data.frame(l_yx), > > > family=binomial(link="logit")) > > > Warning message: > > > glm.fit: fitted probabilities numerically 0 or 1 occurred > > > > > > Why am I getting this warning when I have data points of varying values for > > > y=1 and y=0? In other words, I don't think I have the linear separation > > > issue discussed in one of the links I provided. > > > > I bet that you do... You can get the warning without that effect (one of my own examples is the probability of menarche in a data set that includes infants and old age pensioners), but not with a huge odds ratio as well. Take a look at > > > > d <- as.data.frame(l_yx) > > with(d, y[order(x)]) > > > > if it comes out as all zeros followed by all ones or vice versa, then you have the problem. > > > > > > > > > > PS - Then I do this and I get a odds ratio a crazy size: > > >> l_sm = summary(l_logit) # coef pval is $coefficients[8], log odds > > > $coefficients[2] > > >> l_exp_coef = exp(l_logit$coefficients)[2] # exponentiate the > > > coeffcients > > >> l_exp_coef > > > x > > > 3161.781 > > > > > > So for one unit increase in the predictor variable I get 3160.781% > > > (3161.781 - 1 = 3160.781) increase in odds? That can't be correct either. > > > How do I correct for this issue? (I tried multiplying the predictor > > > variables by a constant and the odds ratio goes down, but the warning above > > > still persists and shouldn't the odds ratio be predictor variable size > > > independent?) > > > > > > -- > > Peter Dalgaard, Professor, > > Center for Statistics, Copenhagen Business School > > Solbjerg Plads 3, 2000 Frederiksberg, Denmark > > Phone: (+45)38153501 > > Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com > > > > > > > > > > > > > > > > > > > > -- > Peter Dalgaard, Professor, > Center for Statistics, Copenhagen Business School > Solbjerg Plads 3, 2000 Frederiksberg, Denmark > Phone: (+45)38153501 > Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com > > > > > > > > > > > -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com From bps0002 at auburn.edu Fri Dec 2 01:13:17 2011 From: bps0002 at auburn.edu (B77S) Date: Thu, 1 Dec 2011 16:13:17 -0800 (PST) Subject: [R] Moving column averaging In-Reply-To: <1322769191236-4130179.post@n4.nabble.com> References: <1322769191236-4130179.post@n4.nabble.com> Message-ID: <1322784797785-4143329.post@n4.nabble.com> # need zoo to use rollapply() # your data (I called df) df <- structure(list(a = 1:2, b = 2:3, c = c(5L, 9L), d = c(9L, 6L), e = c(1L, 5L), f = c(4, 7)), .Names = c("a", "b", "c", "d", "e", "f"), class = "data.frame", row.names = c(NA, -2L)) # transpose and make a zoo object df2 <- zoo(t(df)) #rollapply to get means and transpose back means <- t(rollapply(df2, width=2, by=2, FUN=mean)) # adding the combined column names you requested colnames(means) <- apply(matrix(names(df), nrow=2), 2, paste, collapse=", ") HTH -- View this message in context: http://r.789695.n4.nabble.com/Moving-column-averaging-tp4130179p4143329.html Sent from the R help mailing list archive at Nabble.com. From ccquant at gmail.com Fri Dec 2 02:00:23 2011 From: ccquant at gmail.com (Ben quant) Date: Thu, 1 Dec 2011 18:00:23 -0700 Subject: [R] logistic regression - glm.fit: fitted probabilities numerically 0 or 1 occurred In-Reply-To: <3684DD42-A6F4-487C-B7C0-220C044FF843@gmail.com> References: <2F36BA38-DD8B-4660-ACA1-709750BE0D35@gmail.com> <3684DD42-A6F4-487C-B7C0-220C044FF843@gmail.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From ehlers at ucalgary.ca Fri Dec 2 02:01:31 2011 From: ehlers at ucalgary.ca (Peter Ehlers) Date: Thu, 01 Dec 2011 17:01:31 -0800 Subject: [R] legend, "lheight", and alignment In-Reply-To: <1322758482556-4129402.post@n4.nabble.com> References: <1322758482556-4129402.post@n4.nabble.com> Message-ID: <4ED8236B.5060506@ucalgary.ca> On 2011-12-01 08:54, emorway wrote: > Hello, > > A bit of fairly simple code, yet I don't seem to be able to manipulate it > quite as much as I would like: > > 1) It would be nice if the objects appearing in the legend were aligned, > and by aligned I mean the boxes are centered over the lines. Do I need to > adjust the use of "NA" in the code below to accomplish this? Here's how it > appears on my machine: > > http://r.789695.n4.nabble.com/file/n4129402/example.png > > 2) Because I'm using a call to 'expression' in the text contained in the > legend, it would be nice to space the lines of text a bit more. My feeble > attempt was to increase the lheight parameter in the hopes this would affect > the legend...to no avail. Further, lheight cannot be added to the argument > list of legend. I've been unable to track down another parameter applicable > to legend, suggestions very much appreciated. > > par(lheight=2) > plot(1,1,col="white") > > legend("center", legend=c(expression(paste("Observed > ",italic(bar(EC)[e]))),expression(paste("Simulated > ",italic(bar(EC)[e]))),"test1","test2"), > lty = c(NA,NA,1,1), > col = c("black","black","red","blue"), > density = c(NA,25,NA,NA), > border=c("black","black",NA,NA), > fill = c("grey","black",NA,NA), > angle = c(NA,45,NA,NA), > cex = 1.25, bty = "n", xpd = TRUE) > You can adjust the alignment a little by adding 'merge = TRUE'; this will left-align both the boxes and the lines. For your second question, use the y.intersp argument, e.g. 'y.intersp = 2'. You might also avoid using 'paste' in your expressions; Try replacing expression(paste("Observed",italic(bar(EC)[e]))) with expression("Observed"~italic(bar(EC)[e])) Peter Ehlers > >> sessionInfo() > R version 2.13.2 (2011-09-30) > Platform: x86_64-pc-mingw32/x64 (64-bit) > > locale: > [1] LC_COLLATE=English_United States.1252 > [2] LC_CTYPE=English_United States.1252 > [3] LC_MONETARY=English_United States.1252 > [4] LC_NUMERIC=C > [5] LC_TIME=English_United States.1252 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > loaded via a namespace (and not attached): > [1] tools_2.13.2 >> > > > -- > View this message in context: http://r.789695.n4.nabble.com/legend-lheight-and-alignment-tp4129402p4129402.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From bps0002 at auburn.edu Fri Dec 2 02:11:39 2011 From: bps0002 at auburn.edu (B77S) Date: Thu, 1 Dec 2011 17:11:39 -0800 (PST) Subject: [R] calculate mean of multiple rows in a data frame In-Reply-To: <1322772314.57483.YahooMailClassic@web28515.mail.ukl.yahoo.com> References: <1322772314.57483.YahooMailClassic@web28515.mail.ukl.yahoo.com> Message-ID: <1322788299530-4143875.post@n4.nabble.com> -- View this message in context: http://r.789695.n4.nabble.com/calculate-mean-of-multiple-rows-in-a-data-frame-tp4130468p4143875.html Sent from the R help mailing list archive at Nabble.com. From ggrothendieck at gmail.com Fri Dec 2 02:14:17 2011 From: ggrothendieck at gmail.com (Gabor Grothendieck) Date: Thu, 1 Dec 2011 20:14:17 -0500 Subject: [R] Moving column averaging In-Reply-To: <1322784797785-4143329.post@n4.nabble.com> References: <1322769191236-4130179.post@n4.nabble.com> <1322784797785-4143329.post@n4.nabble.com> Message-ID: On Thu, Dec 1, 2011 at 7:13 PM, B77S wrote: > # need zoo to use rollapply() > > # your data (I called df) > df <- structure(list(a = 1:2, b = 2:3, c = c(5L, 9L), d = c(9L, 6L), > ? ?e = c(1L, 5L), f = c(4, 7)), .Names = c("a", "b", "c", "d", > "e", "f"), class = "data.frame", row.names = c(NA, -2L)) > > # transpose and make a zoo object > df2 <- zoo(t(df)) > > #rollapply to get means and transpose back > means <- t(rollapply(df2, width=2, by=2, FUN=mean)) > > # adding the combined column names you requested > colnames(means) <- apply(matrix(names(df), nrow=2), 2, paste, collapse=", ") > Note that zoo's rollapply also works on plain matrices and vectors. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com From bps0002 at auburn.edu Fri Dec 2 02:16:44 2011 From: bps0002 at auburn.edu (B77S) Date: Thu, 1 Dec 2011 17:16:44 -0800 (PST) Subject: [R] Moving column averaging In-Reply-To: References: <1322769191236-4130179.post@n4.nabble.com> <1322784797785-4143329.post@n4.nabble.com> Message-ID: <1322788604791-4143909.post@n4.nabble.com> Sorry for that, and thanks Gabor, I could have sworn that it wouldn't. Gabor Grothendieck wrote > > On Thu, Dec 1, 2011 at 7:13 PM, B77S <bps0002@> wrote: >> # need zoo to use rollapply() >> >> # your data (I called df) >> df <- structure(list(a = 1:2, b = 2:3, c = c(5L, 9L), d = c(9L, 6L), >> ? ?e = c(1L, 5L), f = c(4, 7)), .Names = c("a", "b", "c", "d", >> "e", "f"), class = "data.frame", row.names = c(NA, -2L)) >> >> # transpose and make a zoo object >> df2 <- zoo(t(df)) >> >> #rollapply to get means and transpose back >> means <- t(rollapply(df2, width=2, by=2, FUN=mean)) >> >> # adding the combined column names you requested >> colnames(means) <- apply(matrix(names(df), nrow=2), 2, paste, collapse=", >> ") >> > > Note that zoo's rollapply also works on plain matrices and vectors. > > -- > Statistics & Software Consulting > GKX Group, GKX Associates Inc. > tel: 1-877-GKX-GROUP > email: ggrothendieck at gmail.com > > ______________________________________________ > R-help@ mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- View this message in context: http://r.789695.n4.nabble.com/Moving-column-averaging-tp4130179p4143909.html Sent from the R help mailing list archive at Nabble.com. From carl at witthoft.com Fri Dec 2 02:54:14 2011 From: carl at witthoft.com (Carl Witthoft) Date: Thu, 01 Dec 2011 20:54:14 -0500 Subject: [R] strange row numbering after rbind-ing a list In-Reply-To: References: <4ED80A0C.10802@witthoft.com> Message-ID: <4ED82FC6.9070805@witthoft.com> Sorry -- I meant to write 'row names,' but the question specifically is where those unlikely numbers come from. So I guess it comes down to why, when 'bar' is the first item, the row name is assigned '2' rather than '1' . On 12/1/11 6:26 PM, Sarah Goslee wrote: > Those are row *names*, not row *numbers*. It's just that if you don't specify, > numbers are assigned by default when creating a data frame. > > Your rbind() statements are implicitly creating a data frame, so the likely > information is in ?data.frame: > > check.names: logical. If ?TRUE? then the names of the variables in the > data frame are checked to ensure that they are syntactically > valid variable names and are not duplicated. If necessary > they are adjusted (by ?make.names?) so that they are. > > By default, row.names=NULL and check.names=TRUE. > > See also ?rbind.data.frame > > Sarah > > On Thu, Dec 1, 2011 at 6:13 PM, Carl Witthoft wrote: >> "Not that it really matters, but" >> Can someone explain how the row numbers get assigned in the following >> sequence? It looks like something funky happens when rbind() coerces 'bar' >> into a dataframe. >> In either sequence of rbind below, once you get past the first two rows, the >> row numbers count normally. >> >> >> Rgames> (foo<-data.frame(x=5,y=4,r=3)) >> x y r >> 1 5 4 3 >> Rgames> (bar<-list(x=4,y=5,r=6)) >> $x >> [1] 4 >> >> $y >> [1] 5 >> >> $r >> [1] 6 >> >> Rgames> (foobar<- rbind(foo,bar)) >> x y r >> 1 5 4 3 >> 2 4 5 6 >> >> Rgames> (foobar<- rbind(foobar,bar)) >> x y r >> 1 5 4 3 >> 2 4 5 6 >> 3 4 5 6 >> >> >> Rgames> (barfoo<-rbind(bar,foo)) >> x y r >> 2 4 5 6 >> 21 5 4 3 >> >> Rgames> (barfoo<-rbind(barfoo,foo)) >> x y r >> 2 4 5 6 >> 21 5 4 3 >> 3 5 4 3 > > -- Sent from my Cray XK6 "Pendeo-navem mei anguillae plena est." From l.glew at soton.ac.uk Thu Dec 1 23:51:37 2011 From: l.glew at soton.ac.uk (lglew) Date: Thu, 1 Dec 2011 14:51:37 -0800 (PST) Subject: [R] Assign name to object for each iteration in a loop. In-Reply-To: References: <1322763198075-4129752.post@n4.nabble.com> Message-ID: <1322779897063-4142684.post@n4.nabble.com> Thanks Michael! Yeah, that dealt with one of the problems. I still get the following error message: Error in cat(list(...), file, sep, fill, labels, append) : argument 1 (type 'list') cannot be handled by 'cat' I know that this has something to do with writing the names of the output file, and returning them from the function.... L. -- View this message in context: http://r.789695.n4.nabble.com/Assign-name-to-object-for-each-iteration-in-a-loop-tp4129752p4142684.html Sent from the R help mailing list archive at Nabble.com. From jroll at lcog.org Thu Dec 1 23:17:35 2011 From: jroll at lcog.org (LCOG1) Date: Thu, 1 Dec 2011 14:17:35 -0800 (PST) Subject: [R] Summarizing elements of a list Message-ID: <1322777855869-4142479.post@n4.nabble.com> Hi everyone, I looked around the list for a while but couldn't find a solution to my problem. I am storing some results to a simulation in a list and for each element i have two separate vectors(is that what they are called, correct my vocab if necessary). See below Version1_<-list() for(i in 1:5){ Version1_[[i]]<-list(First=rnorm(1),Second=rnorm(1)) } What I want is to put all of the elements' 'First' vectors into a single list to box plot. But whats a more elegant solution to the below? c(Version1_[[1]]$First,Version1_[[2]]$First,Version1_[[3]]$First,Version1_[[4]]$First,Version1_[[5]]$First) since i have 50 or more simulations this is impractical and sloppy. Do I need to store my data differently or is their a solution on the back end? Thanks all. Josh -- View this message in context: http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4142479.html Sent from the R help mailing list archive at Nabble.com. From lara_bio13 at hotmail.com Fri Dec 2 01:48:21 2011 From: lara_bio13 at hotmail.com (lara) Date: Thu, 1 Dec 2011 16:48:21 -0800 (PST) Subject: [R] Plot coordinates with gradien colour according to a different column Message-ID: <1322786901097-4143712.post@n4.nabble.com> Hi everyone, I'm having problems with plotting my data. I have a set of positions with different attributes and I'm wondering if I can plot it, as x,y plot, with gradient colours according to a 3rd factor. Is it possible to show gradient segments between postions and not one-coloured segment between each one? I've been trying plotrix color.scale.lines with no luck. I'm very thankful for any help!! Cheers, Lara -- View this message in context: http://r.789695.n4.nabble.com/Plot-coordinates-with-gradien-colour-according-to-a-different-column-tp4143712p4143712.html Sent from the R help mailing list archive at Nabble.com. From sarah.goslee at gmail.com Fri Dec 2 03:41:26 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Thu, 1 Dec 2011 21:41:26 -0500 Subject: [R] Summarizing elements of a list In-Reply-To: <1322777855869-4142479.post@n4.nabble.com> References: <1322777855869-4142479.post@n4.nabble.com> Message-ID: How about: lapply(Version1_, subset, subset=c(TRUE, FALSE)) or sapply() depending on what you want the result to look like. Thanks for the reproducible example. Sarah On Thu, Dec 1, 2011 at 5:17 PM, LCOG1 wrote: > Hi everyone, > ? I looked around the list for a while but couldn't find a solution to my > problem. ?I am storing some results to a simulation in a list and for each > element i have two separate vectors(is that what they are called, correct my > vocab if necessary). See below > > Version1_<-list() > for(i in 1:5){ > ? ? ? ?Version1_[[i]]<-list(First=rnorm(1),Second=rnorm(1)) > } > > What I want is to put all of the elements' 'First' vectors into a single > list to box plot. But whats a more elegant solution to the below? > > c(Version1_[[1]]$First,Version1_[[2]]$First,Version1_[[3]]$First,Version1_[[4]]$First,Version1_[[5]]$First) > > since i have 50 or more simulations this is impractical and sloppy. ?Do I > need to store my data differently or is their a solution on the back end? > Thanks all. > > Josh > -- Sarah Goslee http://www.functionaldiversity.org From flodel at gmail.com Fri Dec 2 04:32:44 2011 From: flodel at gmail.com (Florent D.) Date: Thu, 1 Dec 2011 22:32:44 -0500 Subject: [R] Counting the occurences of a charater within a string In-Reply-To: References: <974A7A659261804FA954D102472EA32E03D37A85@NYCEMBP01101.ad.insidemedia.net> Message-ID: I used within and vapply: x <- data.frame(Col1 = c("abc/def", "ghi/jkl/mno"), stringsAsFactors = FALSE) count.slashes <- function(string)sum(unlist(strsplit(string, NULL)) == "/")within(x, Col2 <- vapply(Col1, count.slashes, 1)) ? ? ? ? ?Col1 Col21 ? ? abc/def ? ?12 ghi/jkl/mno ? ?2 On Thu, Dec 1, 2011 at 1:05 PM, Bert Gunter wrote: > ## It's not a data frame -- it's just a vector. > >> x > [1] "abc/def" ? ? "ghi/jkl/mno" >> gsub("[^/]","",x) > [1] "/" ?"//" >> nchar(gsub("[^/]","",x)) > [1] 1 2 >> > > ?gsub > ?nchar > > -- Bert > > On Thu, Dec 1, 2011 at 8:32 AM, Douglas Esneault > wrote: >> I am new to R but am experienced SAS user and I was hoping to get some help on counting the occurrences of a character within a string at a row level. >> >> My dataframe, x, ?is structured as below: >> >> Col1 >> abc/def >> ghi/jkl/mno >> >> I found this code on the board but it counts all occurrences of "/" in the dataframe. >> >> chr.pos <- which(unlist(strsplit(x,NULL))=='/') >> chr.count <- length(chr.pos) >> chr.count >> [1] 3 >> >> I'd like to append a column, say cnt, that has the count of "/" for each row. >> >> Can anyone point me in the right direction or offer some code to do this? >> >> Thanks in advance for the help. >> >> Doug Esneault >> >> >> >> >> >> >> Privileged/Confidential Information may be contained in this message. If you >> are not the addressee indicated in this message (or responsible for delivery >> of the message to such person), you may not copy or deliver this message to >> anyone. In such case, you should destroy this message and kindly notify the >> sender by reply email. Please advise immediately if you or your employer >> does not consent to email for messages of this kind. Opinions, conclusions >> and other information in this message that do not relate to the official >> business of the GroupM companies shall be understood as neither given nor >> endorsed by it. ? GroupM companies are a member of WPP plc. For more >> information on our business ethical standards and Corporate Responsibility >> policies please refer to our website at >> http://www.wpp.com/WPP/About/ >> >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > > > -- > > Bert Gunter > Genentech Nonclinical Biostatistics > > Internal Contact Info: > Phone: 467-7374 > Website: > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From flodel at gmail.com Fri Dec 2 04:44:48 2011 From: flodel at gmail.com (Florent D.) Date: Thu, 1 Dec 2011 22:44:48 -0500 Subject: [R] Counting the occurences of a charater within a string In-Reply-To: References: <974A7A659261804FA954D102472EA32E03D37A85@NYCEMBP01101.ad.insidemedia.net> Message-ID: Resending my code, not sure why the linebreaks got eaten: > x <- data.frame(Col1 = c("abc/def", "ghi/jkl/mno"), stringsAsFactors = FALSE) > count.slashes <- function(string)sum(unlist(strsplit(string, NULL)) == "/") > within(x, Col2 <- vapply(Col1, count.slashes, 1)) Col1 Col2 1 abc/def 1 2 ghi/jkl/mno 2 On Thu, Dec 1, 2011 at 10:32 PM, Florent D. wrote: > I used within and vapply: > > x <- data.frame(Col1 = c("abc/def", "ghi/jkl/mno"), stringsAsFactors = FALSE) > count.slashes <- function(string)sum(unlist(strsplit(string, NULL)) == > "/")within(x, Col2 <- vapply(Col1, count.slashes, 1)) > ? ? ? ? ?Col1 Col21 ? ? abc/def ? ?12 ghi/jkl/mno ? ?2 > > On Thu, Dec 1, 2011 at 1:05 PM, Bert Gunter wrote: >> ## It's not a data frame -- it's just a vector. >> >>> x >> [1] "abc/def" ? ? "ghi/jkl/mno" >>> gsub("[^/]","",x) >> [1] "/" ?"//" >>> nchar(gsub("[^/]","",x)) >> [1] 1 2 >>> >> >> ?gsub >> ?nchar >> >> -- Bert >> >> On Thu, Dec 1, 2011 at 8:32 AM, Douglas Esneault >> wrote: >>> I am new to R but am experienced SAS user and I was hoping to get some help on counting the occurrences of a character within a string at a row level. >>> >>> My dataframe, x, ?is structured as below: >>> >>> Col1 >>> abc/def >>> ghi/jkl/mno >>> >>> I found this code on the board but it counts all occurrences of "/" in the dataframe. >>> >>> chr.pos <- which(unlist(strsplit(x,NULL))=='/') >>> chr.count <- length(chr.pos) >>> chr.count >>> [1] 3 >>> >>> I'd like to append a column, say cnt, that has the count of "/" for each row. >>> >>> Can anyone point me in the right direction or offer some code to do this? >>> >>> Thanks in advance for the help. >>> >>> Doug Esneault >>> >>> >>> >>> >>> >>> >>> Privileged/Confidential Information may be contained in this message. If you >>> are not the addressee indicated in this message (or responsible for delivery >>> of the message to such person), you may not copy or deliver this message to >>> anyone. In such case, you should destroy this message and kindly notify the >>> sender by reply email. Please advise immediately if you or your employer >>> does not consent to email for messages of this kind. Opinions, conclusions >>> and other information in this message that do not relate to the official >>> business of the GroupM companies shall be understood as neither given nor >>> endorsed by it. ? GroupM companies are a member of WPP plc. For more >>> information on our business ethical standards and Corporate Responsibility >>> policies please refer to our website at >>> http://www.wpp.com/WPP/About/ >>> >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> >> >> >> -- >> >> Bert Gunter >> Genentech Nonclinical Biostatistics >> >> Internal Contact Info: >> Phone: 467-7374 >> Website: >> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. From worikr at gmail.com Fri Dec 2 04:50:53 2011 From: worikr at gmail.com (Worik R) Date: Fri, 2 Dec 2011 16:50:53 +1300 Subject: [R] simple lm question Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From flodel at gmail.com Fri Dec 2 04:59:01 2011 From: flodel at gmail.com (Florent D.) Date: Thu, 1 Dec 2011 22:59:01 -0500 Subject: [R] transform data.frame holding answers --> data.frame holding logicals In-Reply-To: References: <4ED7C7BA.7040408@gmail.com> Message-ID: I have this. I have modified your input structure to be a matrix. I think it is generally recommended to use matrices over data.frames when your data allows it, i.e., when you only have one type of data, here character(). Matrices are easier to work with. x <- matrix(? c('BMW', '', '',? ? 'Mercedes', 'VW', '',? ? 'Skoda', 'VW', 'BMW',? ? '', '', '',? ? 'VW', 'Skoda', ''? ),? ncol=3, dimnames=list(? ? paste('person', 1:5, sep=''),? ? paste( 'v', 1:3, sep='' )? )) brands <- sort(unique(array(x)))[-1]has.used <- t(apply(x, 1, function(a, b){b %in% a}, brands))colnames(has.used) <- brandshas.used On Thu, Dec 1, 2011 at 2:42 PM, Jean V Adams wrote: > saschaview wrote on 12/01/2011 12:30:18 PM: > >> Hello >> >> I have a data frame, x, holding 5 persons answering the question which >> cars they have used: >> >> # the data frame >> x <- as.data.frame( >> ? ?matrix( >> ? ? ?c('BMW', '', '', >> ? ? ? ?'Mercedes', 'VW', '', >> ? ? ? ?'Skoda', 'VW', 'BMW', >> ? ? ? ?'', '', '', >> ? ? ? ?'VW', 'Skoda', '' >> ? ? ?), >> ? ? ?ncol=3, >> ? ? ?dimnames=list( >> ? ? ? ?NULL, >> ? ? ? ?paste( 'v', 1:3, sep='' ) >> ? ? ?) >> ? ?) >> ) >> >> How do I transform this data frame to a data frame stating whether they >> have used the presented car: >> >> ? ? BMW ?Mercedes ?VW ?Skoda >> 1 ?T ? ?F ? ? ? ? F ? F >> 2 ?F ? ?T ? ? ? ? T ? F >> 3 ?T ? ?F ? ? ? ? T ? T >> 4 ?F ? ?F ? ? ? ? F ? F >> 5 ?F ? ?F ? ? ? ? T ? T >> >> My idea was to first find all levels by: >> >> v <- unique(unlist(lapply(x, levels))) >> >> But then I am stuck. >> >> Thanks for help, *S* >> >> -- >> Sascha Vieweg, saschaview at gmail.com > > > Try this: > > uniq.cars <- sort(unique(unlist(x))) > y <- t(apply(x, 1, function(xrow) match(uniq.cars, unique(xrow)))) > dimnames(y)[[2]] <- uniq.cars > y2 <- !is.na(y[, -1]) > y2 > > Jean > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From michael.weylandt at gmail.com Fri Dec 2 05:09:24 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Thu, 1 Dec 2011 23:09:24 -0500 Subject: [R] Summarizing elements of a list In-Reply-To: References: <1322777855869-4142479.post@n4.nabble.com> Message-ID: Similarly, this might work: unlist(lapply(Version1_, `[`,"First")) Michael On Thu, Dec 1, 2011 at 9:41 PM, Sarah Goslee wrote: > How about: > > lapply(Version1_, subset, subset=c(TRUE, FALSE)) > or sapply() depending on what you want the result to look like. > > Thanks for the reproducible example. > > Sarah > > On Thu, Dec 1, 2011 at 5:17 PM, LCOG1 wrote: >> Hi everyone, >> ? I looked around the list for a while but couldn't find a solution to my >> problem. ?I am storing some results to a simulation in a list and for each >> element i have two separate vectors(is that what they are called, correct my >> vocab if necessary). See below >> >> Version1_<-list() >> for(i in 1:5){ >> ? ? ? ?Version1_[[i]]<-list(First=rnorm(1),Second=rnorm(1)) >> } >> >> What I want is to put all of the elements' 'First' vectors into a single >> list to box plot. But whats a more elegant solution to the below? >> >> c(Version1_[[1]]$First,Version1_[[2]]$First,Version1_[[3]]$First,Version1_[[4]]$First,Version1_[[5]]$First) >> >> since i have 50 or more simulations this is impractical and sloppy. ?Do I >> need to store my data differently or is their a solution on the back end? >> Thanks all. >> >> Josh >> > -- > Sarah Goslee > http://www.functionaldiversity.org > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From gunter.berton at gene.com Fri Dec 2 05:11:07 2011 From: gunter.berton at gene.com (Bert Gunter) Date: Thu, 1 Dec 2011 20:11:07 -0800 Subject: [R] Counting the occurences of a charater within a string In-Reply-To: References: <974A7A659261804FA954D102472EA32E03D37A85@NYCEMBP01101.ad.insidemedia.net> Message-ID: strsplit is certainly an alternative, but your approach is unnecessarily complicated and inefficient. Do this, instead: sapply(strsplit(x,"/"),length)-1 Cheers, Bert On Thu, Dec 1, 2011 at 7:44 PM, Florent D. wrote: > Resending my code, not sure why the linebreaks got eaten: > >> x <- data.frame(Col1 = c("abc/def", "ghi/jkl/mno"), stringsAsFactors = FALSE) >> count.slashes <- function(string)sum(unlist(strsplit(string, NULL)) == "/") >> within(x, Col2 <- vapply(Col1, count.slashes, 1)) > ? ? ? ? Col1 Col2 > 1 ? ? abc/def ? ?1 > 2 ghi/jkl/mno ? ?2 > > > On Thu, Dec 1, 2011 at 10:32 PM, Florent D. wrote: >> I used within and vapply: >> >> x <- data.frame(Col1 = c("abc/def", "ghi/jkl/mno"), stringsAsFactors = FALSE) >> count.slashes <- function(string)sum(unlist(strsplit(string, NULL)) == >> "/")within(x, Col2 <- vapply(Col1, count.slashes, 1)) >> ? ? ? ? ?Col1 Col21 ? ? abc/def ? ?12 ghi/jkl/mno ? ?2 >> >> On Thu, Dec 1, 2011 at 1:05 PM, Bert Gunter wrote: >>> ## It's not a data frame -- it's just a vector. >>> >>>> x >>> [1] "abc/def" ? ? "ghi/jkl/mno" >>>> gsub("[^/]","",x) >>> [1] "/" ?"//" >>>> nchar(gsub("[^/]","",x)) >>> [1] 1 2 >>>> >>> >>> ?gsub >>> ?nchar >>> >>> -- Bert >>> >>> On Thu, Dec 1, 2011 at 8:32 AM, Douglas Esneault >>> wrote: >>>> I am new to R but am experienced SAS user and I was hoping to get some help on counting the occurrences of a character within a string at a row level. >>>> >>>> My dataframe, x, ?is structured as below: >>>> >>>> Col1 >>>> abc/def >>>> ghi/jkl/mno >>>> >>>> I found this code on the board but it counts all occurrences of "/" in the dataframe. >>>> >>>> chr.pos <- which(unlist(strsplit(x,NULL))=='/') >>>> chr.count <- length(chr.pos) >>>> chr.count >>>> [1] 3 >>>> >>>> I'd like to append a column, say cnt, that has the count of "/" for each row. >>>> >>>> Can anyone point me in the right direction or offer some code to do this? >>>> >>>> Thanks in advance for the help. >>>> >>>> Doug Esneault >>>> >>>> >>>> >>>> >>>> >>>> >>>> Privileged/Confidential Information may be contained in this message. If you >>>> are not the addressee indicated in this message (or responsible for delivery >>>> of the message to such person), you may not copy or deliver this message to >>>> anyone. In such case, you should destroy this message and kindly notify the >>>> sender by reply email. Please advise immediately if you or your employer >>>> does not consent to email for messages of this kind. Opinions, conclusions >>>> and other information in this message that do not relate to the official >>>> business of the GroupM companies shall be understood as neither given nor >>>> endorsed by it. ? GroupM companies are a member of WPP plc. For more >>>> information on our business ethical standards and Corporate Responsibility >>>> policies please refer to our website at >>>> http://www.wpp.com/WPP/About/ >>>> >>>> >>>> ______________________________________________ >>>> R-help at r-project.org mailing list >>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>>> and provide commented, minimal, self-contained, reproducible code. >>> >>> >>> >>> -- >>> >>> Bert Gunter >>> Genentech Nonclinical Biostatistics >>> >>> Internal Contact Info: >>> Phone: 467-7374 >>> Website: >>> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm From Peter.Alspach at plantandfood.co.nz Fri Dec 2 05:13:36 2011 From: Peter.Alspach at plantandfood.co.nz (Peter Alspach) Date: Fri, 2 Dec 2011 17:13:36 +1300 Subject: [R] Plot coordinates with gradien colour according to a different column In-Reply-To: <1322786901097-4143712.post@n4.nabble.com> References: <1322786901097-4143712.post@n4.nabble.com> Message-ID: <3CD374BF2C285940A54C0A71225AF7DB02CAE633DF@AKLEXM01.PFR.CO.NZ> Tena koe Lara If I understand your question correctly, I use the colorspace package for that sort of thing, but you could also use the built-in colour palettes such as rainbow and topo.colors HTH .... Peter Alspach > -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of lara > Sent: Friday, 2 December 2011 1:48 p.m. > To: r-help at r-project.org > Subject: [R] Plot coordinates with gradien colour according to a > different column > > Hi everyone, > > I'm having problems with plotting my data. I have a set of positions > with > different attributes and I'm wondering if I can plot it, as x,y plot, > with > gradient colours according to a 3rd factor. Is it possible to show > gradient > segments between postions and not one-coloured segment between each > one? > I've been trying plotrix color.scale.lines with no luck. > I'm very thankful for any help!! > > Cheers, > > Lara > > -- > View this message in context: http://r.789695.n4.nabble.com/Plot- > coordinates-with-gradien-colour-according-to-a-different-column- > tp4143712p4143712.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. The contents of this e-mail are confidential and may be subject to legal privilege. If you are not the intended recipient you must not use, disseminate, distribute or reproduce all or any part of this e-mail or attachments. If you have received this e-mail in error, please notify the sender and delete all material pertaining to this e-mail. Any opinion or views expressed in this e-mail are those of the individual sender and may not represent those of The New Zealand Institute for Plant and Food Research Limited. From flodel at gmail.com Fri Dec 2 05:26:20 2011 From: flodel at gmail.com (Florent D.) Date: Thu, 1 Dec 2011 23:26:20 -0500 Subject: [R] Counting the occurences of a charater within a string In-Reply-To: References: <974A7A659261804FA954D102472EA32E03D37A85@NYCEMBP01101.ad.insidemedia.net> Message-ID: Inefficient, maybe, but what you suggest does not work if a string starts or ends with a slash. On Thu, Dec 1, 2011 at 11:11 PM, Bert Gunter wrote: > strsplit is certainly an alternative, but your approach is > unnecessarily complicated and inefficient. Do this, instead: > > sapply(strsplit(x,"/"),length)-1 > > Cheers, > Bert > > On Thu, Dec 1, 2011 at 7:44 PM, Florent D. wrote: >> Resending my code, not sure why the linebreaks got eaten: >> >>> x <- data.frame(Col1 = c("abc/def", "ghi/jkl/mno"), stringsAsFactors = FALSE) >>> count.slashes <- function(string)sum(unlist(strsplit(string, NULL)) == "/") >>> within(x, Col2 <- vapply(Col1, count.slashes, 1)) >> ? ? ? ? Col1 Col2 >> 1 ? ? abc/def ? ?1 >> 2 ghi/jkl/mno ? ?2 >> >> >> On Thu, Dec 1, 2011 at 10:32 PM, Florent D. wrote: >>> I used within and vapply: >>> >>> x <- data.frame(Col1 = c("abc/def", "ghi/jkl/mno"), stringsAsFactors = FALSE) >>> count.slashes <- function(string)sum(unlist(strsplit(string, NULL)) == >>> "/")within(x, Col2 <- vapply(Col1, count.slashes, 1)) >>> ? ? ? ? ?Col1 Col21 ? ? abc/def ? ?12 ghi/jkl/mno ? ?2 >>> >>> On Thu, Dec 1, 2011 at 1:05 PM, Bert Gunter wrote: >>>> ## It's not a data frame -- it's just a vector. >>>> >>>>> x >>>> [1] "abc/def" ? ? "ghi/jkl/mno" >>>>> gsub("[^/]","",x) >>>> [1] "/" ?"//" >>>>> nchar(gsub("[^/]","",x)) >>>> [1] 1 2 >>>>> >>>> >>>> ?gsub >>>> ?nchar >>>> >>>> -- Bert >>>> >>>> On Thu, Dec 1, 2011 at 8:32 AM, Douglas Esneault >>>> wrote: >>>>> I am new to R but am experienced SAS user and I was hoping to get some help on counting the occurrences of a character within a string at a row level. >>>>> >>>>> My dataframe, x, ?is structured as below: >>>>> >>>>> Col1 >>>>> abc/def >>>>> ghi/jkl/mno >>>>> >>>>> I found this code on the board but it counts all occurrences of "/" in the dataframe. >>>>> >>>>> chr.pos <- which(unlist(strsplit(x,NULL))=='/') >>>>> chr.count <- length(chr.pos) >>>>> chr.count >>>>> [1] 3 >>>>> >>>>> I'd like to append a column, say cnt, that has the count of "/" for each row. >>>>> >>>>> Can anyone point me in the right direction or offer some code to do this? >>>>> >>>>> Thanks in advance for the help. >>>>> >>>>> Doug Esneault >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> Privileged/Confidential Information may be contained in this message. If you >>>>> are not the addressee indicated in this message (or responsible for delivery >>>>> of the message to such person), you may not copy or deliver this message to >>>>> anyone. In such case, you should destroy this message and kindly notify the >>>>> sender by reply email. Please advise immediately if you or your employer >>>>> does not consent to email for messages of this kind. Opinions, conclusions >>>>> and other information in this message that do not relate to the official >>>>> business of the GroupM companies shall be understood as neither given nor >>>>> endorsed by it. ? GroupM companies are a member of WPP plc. For more >>>>> information on our business ethical standards and Corporate Responsibility >>>>> policies please refer to our website at >>>>> http://www.wpp.com/WPP/About/ >>>>> >>>>> >>>>> ______________________________________________ >>>>> R-help at r-project.org mailing list >>>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>>>> and provide commented, minimal, self-contained, reproducible code. >>>> >>>> >>>> >>>> -- >>>> >>>> Bert Gunter >>>> Genentech Nonclinical Biostatistics >>>> >>>> Internal Contact Info: >>>> Phone: 467-7374 >>>> Website: >>>> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm >>>> >>>> ______________________________________________ >>>> R-help at r-project.org mailing list >>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>>> and provide commented, minimal, self-contained, reproducible code. > > > > -- > > Bert Gunter > Genentech Nonclinical Biostatistics > > Internal Contact Info: > Phone: 467-7374 > Website: > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm From dwinsemius at comcast.net Fri Dec 2 05:38:04 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Thu, 1 Dec 2011 23:38:04 -0500 Subject: [R] Counting the occurences of a charater within a string In-Reply-To: References: <974A7A659261804FA954D102472EA32E03D37A85@NYCEMBP01101.ad.insidemedia.net> Message-ID: On Dec 1, 2011, at 11:11 PM, Bert Gunter wrote: > strsplit is certainly an alternative, but your approach is > unnecessarily complicated and inefficient. Do this, instead: > > sapply(strsplit(x,"/"),length)-1 Definitely more compact that the regex alternates I came up with, but one of these still might appeal in situations where it was desireable to have the source strings as labels: > sapply( sapply(x$Col1, gregexpr, patt="/"), length) abc/def ghi/jkl/mno 1 2 > nchar( sapply(x$Col1, gsub, patt="[^/]", rep="" ) ) abc/def ghi/jkl/mno 1 2 -- David > > Cheers, > Bert > > On Thu, Dec 1, 2011 at 7:44 PM, Florent D. wrote: >> Resending my code, not sure why the linebreaks got eaten: >> >>> x <- data.frame(Col1 = c("abc/def", "ghi/jkl/mno"), >>> stringsAsFactors = FALSE) >>> count.slashes <- function(string)sum(unlist(strsplit(string, >>> NULL)) == "/") >>> within(x, Col2 <- vapply(Col1, count.slashes, 1)) >> Col1 Col2 >> 1 abc/def 1 >> 2 ghi/jkl/mno 2 >> >> >> On Thu, Dec 1, 2011 at 10:32 PM, Florent D. wrote: >>> I used within and vapply: >>> >>> x <- data.frame(Col1 = c("abc/def", "ghi/jkl/mno"), >>> stringsAsFactors = FALSE) >>> count.slashes <- function(string)sum(unlist(strsplit(string, >>> NULL)) == >>> "/")within(x, Col2 <- vapply(Col1, count.slashes, 1)) >>> Col1 Col21 abc/def 12 ghi/jkl/mno 2 >>> >>> On Thu, Dec 1, 2011 at 1:05 PM, Bert Gunter >>> wrote: >>>> ## It's not a data frame -- it's just a vector. >>>> >>>>> x >>>> [1] "abc/def" "ghi/jkl/mno" >>>>> gsub("[^/]","",x) >>>> [1] "/" "//" >>>>> nchar(gsub("[^/]","",x)) >>>> [1] 1 2 >>>>> >>>> >>>> ?gsub >>>> ?nchar >>>> >>>> -- Bert >>>> >>>> On Thu, Dec 1, 2011 at 8:32 AM, Douglas Esneault >>>> wrote: >>>>> I am new to R but am experienced SAS user and I was hoping to >>>>> get some help on counting the occurrences of a character within >>>>> a string at a row level. >>>>> >>>>> My dataframe, x, is structured as below: >>>>> >>>>> Col1 >>>>> abc/def >>>>> ghi/jkl/mno >>>>> >>>>> I found this code on the board but it counts all occurrences of >>>>> "/" in the dataframe. >>>>> >>>>> chr.pos <- which(unlist(strsplit(x,NULL))=='/') >>>>> chr.count <- length(chr.pos) >>>>> chr.count >>>>> [1] 3 >>>>> >>>>> I'd like to append a column, say cnt, that has the count of "/" >>>>> for each row. >>>>> >>>>> Can anyone point me in the right direction or offer some code to >>>>> do this? >>>>> >>>>> Thanks in advance for the help. >>>>> >>>>> Doug Esneault >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> Privileged/Confidential Information may be contained in this >>>>> message. If you >>>>> are not the addressee indicated in this message (or responsible >>>>> for delivery >>>>> of the message to such person), you may not copy or deliver this >>>>> message to >>>>> anyone. In such case, you should destroy this message and kindly >>>>> notify the >>>>> sender by reply email. Please advise immediately if you or your >>>>> employer >>>>> does not consent to email for messages of this kind. Opinions, >>>>> conclusions >>>>> and other information in this message that do not relate to the >>>>> official >>>>> business of the GroupM companies shall be understood as neither >>>>> given nor >>>>> endorsed by it. GroupM companies are a member of WPP plc. For >>>>> more >>>>> information on our business ethical standards and Corporate >>>>> Responsibility >>>>> policies please refer to our website at >>>>> http://www.wpp.com/WPP/About/ >>>>> >>>>> >>>>> ______________________________________________ >>>>> R-help at r-project.org mailing list >>>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>>>> and provide commented, minimal, self-contained, reproducible code. >>>> >>>> >>>> >>>> -- >>>> >>>> Bert Gunter >>>> Genentech Nonclinical Biostatistics >>>> >>>> Internal Contact Info: >>>> Phone: 467-7374 >>>> Website: >>>> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm >>>> >>>> ______________________________________________ >>>> R-help at r-project.org mailing list >>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>>> and provide commented, minimal, self-contained, reproducible code. > > > > -- > > Bert Gunter > Genentech Nonclinical Biostatistics > > Internal Contact Info: > Phone: 467-7374 > Website: > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT From dwinsemius at comcast.net Fri Dec 2 05:42:58 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Thu, 1 Dec 2011 23:42:58 -0500 Subject: [R] simple lm question In-Reply-To: References: Message-ID: On Dec 1, 2011, at 10:50 PM, Worik R wrote: > I really would like to be able to read about this in a document but I > cannot find my way around the documentation properly > > Given the code... > > M <- matrix(runif(5*20), nrow=20) > colnames(M) <- c('a', 'b', 'c', 'd', 'e') > ind <- c(1,2,3,4) > dep <- 5 > > I can then do... > l2 <- lm(M[,dep]~M[,ind]) ## Clearly not useful! > summary(l2) > > I am not sure what my regression formula is. > > The results are (edited for brevity) > >> summary(l2)$coefficients > > Coefficients: > Estimate Std. Error t value Pr(>|t|) > (Intercept) 0.63842 0.16036 3.981 0.00120 ** > M[, ind]a -0.02912 0.17566 -0.166 0.87054 > M[, ind]b -0.21172 0.19665 -1.077 0.29865 > M[, ind]c 0.00752 0.18551 0.041 0.96820 > M[, ind]d 0.06357 0.18337 0.347 0.73366 > > Is there some way I can do this so the coefficients have better > names ('a' > through 'd')? > Use `lm` the way it is designed to be used, with a data argument: > l2 <- lm(e~. , data=as.data.frame(M)) > summary(l2) Call: lm(formula = e ~ ., data = as.data.frame(M)) Residuals: Min 1Q Median 3Q Max -0.5558 -0.2396 0.1257 0.2213 0.4586 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.41110 0.25484 1.613 0.128 a -0.03258 0.28375 -0.115 0.910 b 0.09088 0.25971 0.350 0.731 c 0.09382 0.29555 0.317 0.755 d 0.14725 0.33956 0.434 0.671 Residual standard error: 0.3317 on 15 degrees of freedom Multiple R-squared: 0.04667, Adjusted R-squared: -0.2076 F-statistic: 0.1836 on 4 and 15 DF, p-value: 0.9433 -- David. > As for what I am doing it is not... > > l3 <- lm(M[,1]+M[,2]+M[,3]+M[,4]~M[,5]) > > or > > l4 <- lm(M[,1]*M[,2]*M[,3]*M[,4]~M[,5]) > > cheers > W > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT From dwinsemius at comcast.net Fri Dec 2 05:55:43 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Thu, 1 Dec 2011 23:55:43 -0500 Subject: [R] Assign name to object for each iteration in a loop. In-Reply-To: <1322763198075-4129752.post@n4.nabble.com> References: <1322763198075-4129752.post@n4.nabble.com> Message-ID: On Dec 1, 2011, at 1:13 PM, lglew wrote: > Hi R-users, > > I'm trying to produce decompositions of a multiple time-series, > grouped by a > factor (called "area"). I'm modifying the code in the STLperArea > function of > package ndvits, as this function only plots produces stl plots, it > does not > return the underlying data. > > I want to extract the trend component of each decomposition > ("x$time.series[,trend]), assign a name based on the factor "area". > > My input data look like this: > Area is a factor, with three (but could be many more) levels. > area > 1 > 2 > 3 > > Ystart=2000 > > TS is a timeseries: > > X2000049 X2000065 X2000081 X2000097 X2000113 > 1 0.2080 0.2165 0.2149 0.2314 0.2028 > 2 0.1578 0.1671 0.1577 0.1593 0.1672 > 3 0.1897 0.1948 0.2290 0.2292 0.2067 > > Here's the function: > > STLpA<-function(TS, area, Ystart, period=23, nSG="5,5", DSG=0) > { > require (RTisean) > for(i in 1:unique(area)){ > vi.metric=TS[area==i] > filt.vi<-sav_gol(vi.metric,n=nSG,D=DSG) > vi.sg<-ts(filt.vi[,1], start=Ystart,frequency=period) > stld.tmp<-stl(vi.sg, s.window="periodic", robust=TRUE, > na.action=na.approx) > stld.trend<-stld.temp$time.series[,trend] The line above will probably fail. It is more likely to succeed with: stld.trend<-stld.temp$time.series[ ,"trend"] Unless you have defined a variable named `trend` with a value of "trend". > } > assign(paste("stld", i , sep= "."), stld.trend) > vi.trend<-ls(pattern= "^stld..$") > return(vi.trend) > } > > When I call this function with > signal=STLpA(TS,area,Ystart=2000,period=23, > nSG= "5,5", DSG="0")) > > I get this error: > > Error in cat(list(...), file, sep, fill, labels, append) : You might want to use traceback() at this point to see which of hte functions you did call is sending lists to `cat`. > argument 1 (type 'list') cannot be handled by 'cat' > In addition: Warning message: > In 1:unique(area) : > numerical expression has 3 elements: only the first used > > I'm guessing this is because I'm assigning names to each temporary > stl.trend > file incorrectly. I'm guessing it's not that since I think that step would fail if you got to it for the reasons described above. > Can anyone > improve on my rather poor efforts here? > > Many thanks, > > Louise > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Assign-name-to-object-for-each-iteration-in-a-loop-tp4129752p4129752.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT From sachin.abeywardana at gmail.com Fri Dec 2 06:09:32 2011 From: sachin.abeywardana at gmail.com (Sachinthaka Abeywardana) Date: Fri, 2 Dec 2011 16:09:32 +1100 Subject: [R] =?windows-1252?q?R2Cuba_package=2C_failed_with_message_=91Dim?= =?windows-1252?q?ension_out_of_range=92?= Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From akpbond007 at gmail.com Fri Dec 2 05:53:58 2011 From: akpbond007 at gmail.com (arunkumar1111) Date: Thu, 1 Dec 2011 20:53:58 -0800 (PST) Subject: [R] help in dbWriteTable Message-ID: <1322801638400-4145110.post@n4.nabble.com> hi I need some help in dbWriteTable. I'm not able to insert the rows in the table if the column order are not same in the database and in the dataframe which i'm inserting. Also facing issue if the table is already created externally and inserting it thru dbWrite. is there some way that we can sepecify the rownames in the dbwrite..or any method which will solve my problem -- View this message in context: http://r.789695.n4.nabble.com/help-in-dbWriteTable-tp4145110p4145110.html Sent from the R help mailing list archive at Nabble.com. From rroa at azti.es Fri Dec 2 09:19:36 2011 From: rroa at azti.es (=?iso-8859-1?Q?Rub=E9n_Roa?=) Date: Fri, 2 Dec 2011 09:19:36 +0100 Subject: [R] how to get inflection point in binomial glm In-Reply-To: <20111201203358.19674ghe8483ub3a@psy2.psych.tu-dresden.de> References: <20111201142447.202239j1pkf17h9b@psy2.psych.tu-dresden.de><115F31EC-7960-4157-B70E-A4DB76D5C2DE@comcast.net> <20111201203358.19674ghe8483ub3a@psy2.psych.tu-dresden.de> Message-ID: <5CD78996B8F8844D963C875D3159B94A02DFF9F8@DSRCORREO.azti.local> Ren?, Yes, to fit a re-parameterized logistic model I think you'd have to code the whole enchilada yourself, not relying on glm (but not nls() as nls() deals with least squares minimization whereas here we want to minimize a minus log binomial likelihood). I did that and have the re-parameterized logistic model in a package I wrote for a colleague (this package has the logistic fit fully functional and documented). My code though only considers one continuous predictor. If you want I may email you this package and you figure out how to deal with the categorical predictor. One thing I believe at this point is that you'd have to do the inference on the continuous predictor _conditional_ on certain level(s) of the categorical predictor. Rub?n -----Mensaje original----- De: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] En nombre de Ren? Mayer Enviado el: jueves, 01 de diciembre de 2011 20:34 Para: David Winsemius CC: r-help Help Asunto: Re: [R] how to get inflection point in binomial glm Thanks David and Rub?n! @David: indeed 15 betas I forgot the interaction terms, thanks for correcting! @Rub?n: the re-parameterize would be done within nls()? how to do this practically with including the factor predictor? and yes, we can solve within each group for Y=0 getting 0=b0+b1*X |-b0 -b0=b1*X |/b1 -b0/b1=X but I was hoping there might a more general solution for the case of multiple logistic regression. HTH Ren? Zitat von "David Winsemius" : > > On Dec 1, 2011, at 8:24 AM, Ren? Mayer wrote: > >> Dear All, >> >> I have a binomial response with one continuous predictor (d) and one >> factor (g) (8 levels dummy-coded). >> >> glm(resp~d*g, data, family=binomial) >> >> Y=b0+b1*X1+b2*X2 ... b7*X7 > > Dear Dr Mayer; > > I think it might be a bit more complex than that. I think you should > get 15 betas rather than 8. Have you done it? > >> >> how can I get the inflection point per group, e.g., P(d)=.5 > > Wouldn't that just be at d=1/beta in each group? (Thinking, perhaps > naively, in the case of X=X1 that > > (Pr[y==1])/(1-Pr[y==1])) = 1 = exp( beta *d*(X==X1) ) # all other > terms = 0 > > And taking the log of both sides, and then use "middle school" math to solve. > > Oh, wait. Muffed my first try on that for sure. Need to add back both > the constant intercept and the baseline "d" coefficient for the > non-b0 levels. > > (Pr[y==1])/(1-Pr[y==1])) = 1 = exp( beta_0 + beta_d_0*d + > beta_n + beta_d_n *d*(X==Xn) ) > > And just > > (Pr[y==1])/(1-Pr[y==1])) = 1 = exp( beta_0 + beta_d_0*d ) # for the > reference level. > > This felt like an exam question in my categorical analysis course 25 > years ago. (Might have gotten partial credit for my first stab, > depending on how forgiving the TA was that night.) > >> >> I would be grateful for any help. >> >> Thanks in advance, >> Ren? >> > -- > > David Winsemius, MD > West Hartford, CT > > ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. From paul.hiemstra at knmi.nl Fri Dec 2 09:26:52 2011 From: paul.hiemstra at knmi.nl (Paul Hiemstra) Date: Fri, 02 Dec 2011 08:26:52 +0000 Subject: [R] =?windows-1252?q?R2Cuba_package=2C_failed_with_message_=91Dim?= =?windows-1252?q?ension_out_of_range=92?= In-Reply-To: References: Message-ID: <4ED88BCC.8050005@knmi.nl> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From andreas.borg at unimedizin-mainz.de Fri Dec 2 09:53:10 2011 From: andreas.borg at unimedizin-mainz.de (Andreas Borg) Date: Fri, 02 Dec 2011 09:53:10 +0100 Subject: [R] help in dbWriteTable In-Reply-To: <1322801638400-4145110.post@n4.nabble.com> References: <1322801638400-4145110.post@n4.nabble.com> Message-ID: <4ED891F6.6040205@unimedizin-mainz.de> Hello, you can fetch the column names of a table with dbListFields and then reorder or rename the data frame according to those. If you want more specific help, provide an example (RSQLite would be a good choice as database engine to make it easily reproducible for others). Best regards, Andreas arunkumar1111 schrieb: > hi > > I need some help in dbWriteTable. > I'm not able to insert the rows in the table if the column order are not > same in the database and in the dataframe which i'm inserting. Also facing > issue if the table is already created externally and inserting it thru > dbWrite. > > is there some way that we can sepecify the rownames in the dbwrite..or any > method which will solve my problem > > > > -- > View this message in context: http://r.789695.n4.nabble.com/help-in-dbWriteTable-tp4145110p4145110.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > -- Andreas Borg Abteilung Medizinische Informatik Universit?tsmedizin der Johannes Gutenberg-Universit?t Mainz Institut f?r Med. Biometrie, Epidemiologie und Informatik (IMBEI) Obere Zahlbacher Stra?e 69, 55131 Mainz Tel: +49 (0) 6131 17-5062 E-Mail: andreas.borg at uni-mainz.de From a.schlicker at nki.nl Fri Dec 2 09:03:23 2011 From: a.schlicker at nki.nl (Andreas Schlicker) Date: Fri, 2 Dec 2011 09:03:23 +0100 Subject: [R] What's the baseline model when using coxph with factor variables? In-Reply-To: References: <4ED7B2A9.1090607@nki.nl> <5BC18E4E-FF2B-4689-AEB9-A755B027B986@comcast.net> Message-ID: <4ED8864B.4070109@nki.nl> William and David, thanks for your help. The contrasts option was indeed what I was looking for but didn't find. andi On 01.12.2011 20:56, David Winsemius wrote: > > On Dec 1, 2011, at 1:00 PM, William Dunlap wrote: > >> Terry will correct me if I'm wrong, but I don't think the >> answer to this question is specific to the coxph function. > > It depends on our interpretation of the questioner's intent. My answer > was predicated on the assumption that the phrase "baseline model" > meant baseline survival function, ... S_0(t) in survival analysis > notation. > > >> For all the [well-written] formula-based modelling functions >> (essentially, those that call model.frame and model.matrix to >> interpret >> the formula) the option "contrasts" controls how factor >> variables are parameterized in the model matrix. contr.treatment >> makes the baseline the first factor level, contr.SAS makes >> the baseline the last, contr.sum makes the baseline the mean, >> etc. E.g., >> >>> df<- data.frame(time=sin(1:20)+2, >> cens=rep(c(0,0,1), len=20), >> var1=factor(rep(0:1, each=10)), >> var2=factor(rep(0:1, 10))) >>> options(contrasts=c("contr.treatment", "contr.treatment")) >>> coxph(Surv(time, cens) ~ var1 + var2, data=df) >> Call: >> coxph(formula = Surv(time, cens) ~ var1 + var2, data = df) >> >> >> coef exp(coef) se(coef) z p >> var11 0.1640 1.18 0.822 0.1995 0.84 >> var21 0.0806 1.08 0.830 0.0971 0.92 >> >> Likelihood ratio test=0.05 on 2 df, p=0.974 n= 20, number of >> events= 6 >>> options(contrasts=c("contr.SAS", "contr.SAS")) >>> coxph(Surv(time, cens) ~ var1 + var2, data=df) >> Call: >> coxph(formula = Surv(time, cens) ~ var1 + var2, data = df) >> >> >> coef exp(coef) se(coef) z p >> var10 -0.1640 0.849 0.822 -0.1995 0.84 >> var20 -0.0806 0.923 0.830 -0.0971 0.92 >> >> Likelihood ratio test=0.05 on 2 df, p=0.974 n= 20, number of >> events= 6 >>> options(contrasts=c("contr.sum", "contr.sum")) >>> coxph(Surv(time, cens) ~ var1 + var2, data=df) >> Call: >> coxph(formula = Surv(time, cens) ~ var1 + var2, data = df) >> >> >> coef exp(coef) se(coef) z p >> var11 -0.0820 0.921 0.411 -0.1995 0.84 >> var21 -0.0403 0.960 0.415 -0.0971 0.92 >> >> Likelihood ratio test=0.05 on 2 df, p=0.974 n= 20, number of >> events= 6 >> >> (lm() has a contrasts argument that can override >> getOption("contrasts") >> and set different contrasts for each variable but coxph() does not >> have >> that argument.) >> >> Bill Dunlap >> Spotfire, TIBCO Software >> wdunlap tibco.com >> >>> -----Original Message----- >>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org >>> ] On Behalf Of David Winsemius >>> Sent: Thursday, December 01, 2011 9:36 AM >>> To: a.schlicker at nki.nl >>> Cc: r-help at r-project.org >>> Subject: Re: [R] What's the baseline model when using coxph with >>> factor variables? >>> >>> >>> On Dec 1, 2011, at 12:00 PM, Andreas Schlicker wrote: >>> >>>> Hi all, >>>> >>>> I'm trying to fit a Cox regression model with two factor variables >>>> but have some problems with the interpretation of the results. >>>> Considering the following model, where var1 and var2 can assume >>>> value 0 and 1: >>>> >>>> coxph(Surv(time, cens) ~ factor(var1) * factor(var2), data=temp) >>>> >>>> What is the baseline model? Is that considering the whole population >>>> or the case when both var1 and var2 = 0? >>> >>> This has been discussed several times in the past on rhelp. My >>> suggestion would be to search your favorite rhelp archive using >>> "baseline hazard Therneau", since Terry Therneau is the author of >>> survival. (The answer is closer to the first than to the second.) >>> >>>> >>>> Kind regards, >>>> andi >>>> >>>> ______________________________________________ >>>> R-help at r-project.org mailing list >>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>>> and provide commented, minimal, self-contained, reproducible code. >>> >>> David Winsemius, MD >>> West Hartford, CT >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. > > David Winsemius, MD > West Hartford, CT > From aurelien.philippot at gmail.com Fri Dec 2 08:20:00 2011 From: aurelien.philippot at gmail.com (=?ISO-8859-1?Q?Aur=E9lien_PHILIPPOT?=) Date: Thu, 1 Dec 2011 23:20:00 -0800 Subject: [R] Problem subsetting: undefined columns Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From miseno77 at hotmail.com Fri Dec 2 09:55:45 2011 From: miseno77 at hotmail.com (lincoln) Date: Fri, 2 Dec 2011 00:55:45 -0800 (PST) Subject: [R] Resampling with replacement on a binary (0, 1) dataset to get Cis In-Reply-To: References: <1322739265192-4127990.post@n4.nabble.com> <69C9F7F8-E011-470C-B89D-D21611ED0FA4@comcast.net> <1322754549513-4129048.post@n4.nabble.com> Message-ID: <1322816145585-4145733.post@n4.nabble.com> Thanks. Anyway, it is not homework and I was not told to do that. My question has not been answered yet, I'll try to reformulate it: Does it make (statistical) sense to resample with replacement in this situation to get an estimate of the CIs? In case it does, how could I do it in R? Some further details on my real case study: 10 independent samples from a population in ten sessions. Each sample consists of a number (somehow variable) of random individuals that are classified as 0 or 1 depending on one specific state (presence or absence of a disease). I can calculate, for each session, the percentage of individuals diseased but I have nothing about the CIs, any suggestion? -- View this message in context: http://r.789695.n4.nabble.com/Resampling-with-replacement-on-a-binary-0-1-variable-to-get-CIs-tp4127990p4145733.html Sent from the R help mailing list archive at Nabble.com. From rrasterr at gmail.com Fri Dec 2 10:27:58 2011 From: rrasterr at gmail.com (Ana) Date: Fri, 2 Dec 2011 10:27:58 +0100 Subject: [R] export array Message-ID: What is the best way to export 1 array?? the array i am trying to export has 3 dimensions (long,lat,observations) how can i export each dimension independently? e.g. one csv file with only the long From jholtman at gmail.com Fri Dec 2 11:00:47 2011 From: jholtman at gmail.com (Jim Holtman) Date: Fri, 2 Dec 2011 05:00:47 -0500 Subject: [R] export array In-Reply-To: References: Message-ID: What do you want to do with it after you export; that will probably define what the data format would look like. Why would you want each dimension separately? How would you correlate them later? Is it really 3 dimensions, or is your data just three columns where each row is long, lat and observation? A small subset of the data would be helpful. Are you going to read it back into R, or send it somewhere else? More information would be useful because you can create almost any output format that you want. Sent from my iPad On Dec 2, 2011, at 4:27, Ana wrote: > What is the best way to export 1 array?? > > the array i am trying to export has 3 dimensions (long,lat,observations) > > how can i export each dimension independently? > e.g. one csv file with only the long > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From jholtman at gmail.com Fri Dec 2 11:07:17 2011 From: jholtman at gmail.com (Jim Holtman) Date: Fri, 2 Dec 2011 05:07:17 -0500 Subject: [R] Problem subsetting: undefined columns In-Reply-To: References: Message-ID: ?try If you know that you might have a problem with undefined columns, or whatever, then trap the error with 'try' so your program can recover. You could also validate the data that you are going to use before entering the loop; standard defensive programming - errors are always going to happen, so guard against them. Sent from my iPad On Dec 2, 2011, at 2:20, Aur?lien PHILIPPOT wrote: > Dear R-users, > -I am new to R, and I am struggling with the following problem. > > -I am repeating the following operations hundreds of times, within a loop: > I want to subset a data frame by columns. I am interested in the columns > names that are given by the rows of another data frame that was built in > parallel. The solution I have so far works well as long as the elements of > the second data frame are included in the column names of the first data > frame but if an element from the second object is not a column name of the > first one, then it bugs. > > > -More concretely, I have the following data frames d and v: > yyyymmdd<-c("19720601", "19720602", "19720605") > sret.10006<-c(1,2,3) > sret.10014<-c(5,9,7) > sret.10065<-c(10,2,11) > > > d<- data.frame(yyyymmdd=yyyymmdd, sret.10006=sret.10006, > sret.10014=sret.10014, sret.10065=sret.10065) > > v<- data.frame(V1="sret.10006", V2="sret.10090") > v<- sapply(v, function(x) levels(x)[x]) > > -I want to do the following subsetting: > sub<- subset(d, select=c(v)) > > > and I get the following error message: > Error in `[.data.frame`(x, r, vars, drop = drop) : > undefined columns selected > > > > Any help would be very much appreciated, > > Best, > Aurelien > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From paul.hiemstra at knmi.nl Fri Dec 2 11:07:09 2011 From: paul.hiemstra at knmi.nl (Paul Hiemstra) Date: Fri, 02 Dec 2011 10:07:09 +0000 Subject: [R] Problem subsetting: undefined columns In-Reply-To: References: Message-ID: <4ED8A34D.1030800@knmi.nl> On 12/02/2011 07:20 AM, Aur?lien PHILIPPOT wrote: > Dear R-users, > -I am new to R, and I am struggling with the following problem. > > -I am repeating the following operations hundreds of times, within a loop: > I want to subset a data frame by columns. I am interested in the columns > names that are given by the rows of another data frame that was built in > parallel. The solution I have so far works well as long as the elements of > the second data frame are included in the column names of the first data > frame but if an element from the second object is not a column name of the > first one, then it bugs. Hi Aurelien, I would call this a feature, not a bug. I think R does what it should do, you request a non-existent column and it throws an error. What kind of behavior are you looking for instead of this error? regards, Paul > > -More concretely, I have the following data frames d and v: > yyyymmdd<-c("19720601", "19720602", "19720605") > sret.10006<-c(1,2,3) > sret.10014<-c(5,9,7) > sret.10065<-c(10,2,11) > > > d<- data.frame(yyyymmdd=yyyymmdd, sret.10006=sret.10006, > sret.10014=sret.10014, sret.10065=sret.10065) > > v<- data.frame(V1="sret.10006", V2="sret.10090") > v<- sapply(v, function(x) levels(x)[x]) > > -I want to do the following subsetting: > sub<- subset(d, select=c(v)) > > > and I get the following error message: > Error in `[.data.frame`(x, r, vars, drop = drop) : > undefined columns selected > > > > Any help would be very much appreciated, > > Best, > Aurelien > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Paul Hiemstra, Ph.D. Global Climate Division Royal Netherlands Meteorological Institute (KNMI) Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39 P.O. Box 201 | 3730 AE | De Bilt tel: +31 30 2206 494 http://intamap.geo.uu.nl/~paul http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770 From rrasterr at gmail.com Fri Dec 2 11:07:41 2011 From: rrasterr at gmail.com (Ana) Date: Fri, 2 Dec 2011 11:07:41 +0100 Subject: [R] export array In-Reply-To: References: Message-ID: Hi! I would just like to have a way to check if my functions are working ok. If the subset I am extracting is ok (both coordinates and dataset). The files are nectdf format that I import into R (I only import a small geographic subset). Is there another software that will allow me to do this just to check if my code is ok? On Fri, Dec 2, 2011 at 11:00 AM, Jim Holtman wrote: > What do you want to do with it after you export; that will probably define what the data format would look like. ?Why would you want each dimension separately? ?How would you correlate them later? ?Is it really 3 dimensions, or is your data just three columns where each row is long, lat and observation? ?A small subset of the data would be helpful. Are you going to read it back into R, or send it somewhere else? ?More information would be useful because you can create almost any output format that you want. > > Sent from my iPad > > On Dec 2, 2011, at 4:27, Ana wrote: > >> What is the best way to export 1 array?? >> >> the array i am trying to export has 3 dimensions (long,lat,observations) >> >> how can i export each dimension independently? >> e.g. one csv file with only the long >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. From jholtman at gmail.com Fri Dec 2 11:17:19 2011 From: jholtman at gmail.com (Jim Holtman) Date: Fri, 2 Dec 2011 05:17:19 -0500 Subject: [R] export array In-Reply-To: References: Message-ID: <7720466E-8023-488D-960E-4743ACEBCE88@gmail.com> Depends on how you want to 'check'. I usually use 'View' to see if the data looks OK. You could write some more code to check the 'reasonableness' of the data. It sounds like you have to learn some ways of 'debugging' your code. Checking your data depends on what the criteria is for determining correctness. I will also export to Excel to let other people see if it is reasonable, but again it depends on the problem you are trying to solve. Sent from my iPad On Dec 2, 2011, at 5:07, Ana wrote: > Hi! > > I would just like to have a way to check if my functions are working ok. > If the subset I am extracting is ok (both coordinates and dataset). > > The files are nectdf format that I import into R (I only import a > small geographic subset). > Is there another software that will allow me to do this just to check > if my code is ok? > > > > > On Fri, Dec 2, 2011 at 11:00 AM, Jim Holtman wrote: >> What do you want to do with it after you export; that will probably define what the data format would look like. Why would you want each dimension separately? How would you correlate them later? Is it really 3 dimensions, or is your data just three columns where each row is long, lat and observation? A small subset of the data would be helpful. Are you going to read it back into R, or send it somewhere else? More information would be useful because you can create almost any output format that you want. >> >> Sent from my iPad >> >> On Dec 2, 2011, at 4:27, Ana wrote: >> >>> What is the best way to export 1 array?? >>> >>> the array i am trying to export has 3 dimensions (long,lat,observations) >>> >>> how can i export each dimension independently? >>> e.g. one csv file with only the long >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. From b.h.mevik at usit.uio.no Fri Dec 2 11:59:07 2011 From: b.h.mevik at usit.uio.no (=?iso-8859-1?Q?Bj=F8rn-Helge_Mevik?=) Date: Fri, 02 Dec 2011 11:59:07 +0100 Subject: [R] question about plsr() results In-Reply-To: <1322767611.79460.YahooMailNeo@web121513.mail.ne1.yahoo.com> (Vytautas Rakeviius's message of "Thu\, 1 Dec 2011 11\:26\:51 -0800 \(PST\)") References: <1322767611.79460.YahooMailNeo@web121513.mail.ne1.yahoo.com> Message-ID: Vytautas Rakeviius writes: > But still I have question about results interpretation. In the end I > want to construct prediction function in form: > Y=a1x1+a2x2 The predict() function does the prediction for you. If you want to construct the prediction _equation_, you can extract the coefficients from the model with coef(yourmodel, ncomp = thenumberofcomponents, intercept = TRUE) See ?coef.mvr for details. > Documentation do not describe this. The pls package is designed to work as much as possible like the lm() function and its methods, helpers. So read any introduction to linear models in R, and you will come a long way. There is also a paper in JSS about the pls package: http://www.jstatsoft.org/v18/i02/ -- Cheers, Bj?rn-Helge Mevik From alaios at yahoo.com Fri Dec 2 12:30:44 2011 From: alaios at yahoo.com (Alaios) Date: Fri, 2 Dec 2011 03:30:44 -0800 (PST) Subject: [R] find and replace string Message-ID: <1322825444.44008.YahooMailNeo@web120103.mail.ne1.yahoo.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From jholtman at gmail.com Fri Dec 2 13:51:13 2011 From: jholtman at gmail.com (jim holtman) Date: Fri, 2 Dec 2011 07:51:13 -0500 Subject: [R] find and replace string In-Reply-To: <1322825444.44008.YahooMailNeo@web120103.mail.ne1.yahoo.com> References: <1322825444.44008.YahooMailNeo@web120103.mail.ne1.yahoo.com> Message-ID: try this: > x <- c('sta_+1+0_field2ndtry_0000$01.cfg' + , 'sta_+1+0_field2ndtry_0000$01.cfg' + , 'sta_+1-0_field2ndtry_0000$01.cfg' + , 'sta_+1+0_field2ndtry_0000$01.cfg' + ) > # find matching fields > values <- grep("[^+]*\\+[^+]*\\+0", x, value = TRUE) > # split into two pieces > splitValues <- sub("([^+]*\\+[^+]*\\+)0(.*)", "\\1^\\2", values) > for (i in splitValues){ + for (j in 0:3){ + print(sub("\\^", j, i)) + } + } [1] "sta_+1+0_field2ndtry_0000$01.cfg" [1] "sta_+1+1_field2ndtry_0000$01.cfg" [1] "sta_+1+2_field2ndtry_0000$01.cfg" [1] "sta_+1+3_field2ndtry_0000$01.cfg" [1] "sta_+1+0_field2ndtry_0000$01.cfg" [1] "sta_+1+1_field2ndtry_0000$01.cfg" [1] "sta_+1+2_field2ndtry_0000$01.cfg" [1] "sta_+1+3_field2ndtry_0000$01.cfg" [1] "sta_+1+0_field2ndtry_0000$01.cfg" [1] "sta_+1+1_field2ndtry_0000$01.cfg" [1] "sta_+1+2_field2ndtry_0000$01.cfg" [1] "sta_+1+3_field2ndtry_0000$01.cfg" On Fri, Dec 2, 2011 at 6:30 AM, Alaios wrote: > Dear all, > I would like to search in a string for the second occurrence of a symbol and replace the symbol after it > > For example my strings look like > > sta_+1+0_field2ndtry_0000$01.cfg > > I want to find the digit that comes after the second +, in that case is zero > and then over a loop create the strings below > > sta_+1+0_field2ndtry_0000$01.cfg > > sta_+1+1_field2ndtry_0000$01.cfg > > sta_+1+2_field2ndtry_0000$01.cfg > > sta_+1+3_field2ndtry_0000$01.cfg > > and so on.. > I have already tried strsplit but this will make things more complex... > > Could you please help me with that? > > B.R > Alex > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. From wolemi2 at yahoo.com Fri Dec 2 10:20:53 2011 From: wolemi2 at yahoo.com (oluwole oyebamiji) Date: Fri, 2 Dec 2011 01:20:53 -0800 (PST) Subject: [R] Intersection of 2 matrices Message-ID: <1322817653.56306.YahooMailNeo@web38408.mail.mud.yahoo.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From jos at yuliuskitchen.com Fri Dec 2 10:19:50 2011 From: jos at yuliuskitchen.com (Jos Elkink) Date: Fri, 2 Dec 2011 09:19:50 +0000 Subject: [R] Rmpi installation problems In-Reply-To: References: Message-ID: <20111202091950.GA28128@kaliurang> Hi all, I am trying to install the Rmpi package in R and, while the installation itself works, it breaks down when trying to load the library. I think it has something to do with shared vs static loading of helper libraries, or the order in which shared libraries are loaded, but I am not sure. R version: 2.14.0 Linux version: Gentoo, i686-pc-linux-gnu (32-bit) GCC version: 4.5.3 (Gentoo 4.5.3-r1 p1.0) OpenMPI version: 1.5.4 Output from R CMD INSTALL . in Rmpi source directory: * installing to library ?/home/jos/R/i686-pc-linux-gnu-library/2.14? * installing *source* package ?Rmpi? ... checking for gcc... i686-pc-linux-gnu-gcc -std=gnu99 checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether i686-pc-linux-gnu-gcc -std=gnu99 accepts -g... yes checking for i686-pc-linux-gnu-gcc -std=gnu99 option to accept ISO C89... none needed I am here /usr and it is OpenMPI Trying to find mpi.h ... Found in /usr/include Trying to find libmpi.so or libmpich.a ... Found libmpi in /usr/lib checking for openpty in -lutil... yes checking for main in -lpthread... yes configure: creating ./config.status config.status: creating src/Makevars ** Creating default NAMESPACE file ** libs make: Nothing to be done for `all'. installing to /home/jos/R/i686-pc-linux-gnu-library/2.14/Rmpi/libs ** R ** demo ** inst ** preparing package for lazy loading ** help *** installing help indices ** building package indices ... ** testing if installed package can be loaded /usr/lib/R/bin/exec/R: symbol lookup error: /usr/lib/openmpi/mca_paffinity_hwloc.so: undefined symbol: mca_base_param_reg_int ERROR: loading failed * removing ?/home/jos/R/i686-pc-linux-gnu-library/2.14/Rmpi? Any help would be greatly appreciated! Jos From cjpauw at gmail.com Fri Dec 2 13:52:36 2011 From: cjpauw at gmail.com (christiaan pauw) Date: Fri, 2 Dec 2011 14:52:36 +0200 Subject: [R] find and replace string In-Reply-To: <1322825444.44008.YahooMailNeo@web120103.mail.ne1.yahoo.com> References: <1322825444.44008.YahooMailNeo@web120103.mail.ne1.yahoo.com> Message-ID: If the length of the fists part is constant (the "sta_+1+" part) the you can use substr() On 2 December 2011 13:30, Alaios wrote: > Dear all, > I would like to search in a string for the second occurrence of a symbol and replace the symbol after it > > For example my strings look like > > sta_+1+0_field2ndtry_0000$01.cfg > > I want to find the digit that comes after the second +, in that case is zero > and then over a loop create the strings below > > sta_+1+0_field2ndtry_0000$01.cfg > > sta_+1+1_field2ndtry_0000$01.cfg > > sta_+1+2_field2ndtry_0000$01.cfg > > sta_+1+3_field2ndtry_0000$01.cfg > > and so on.. > I have already tried strsplit but this will make things more complex... > > Could you please help me with that? > > B.R > Alex > -- Christiaan Pauw Nova Institute www.nova.org.za From narendarcse007 at gmail.com Fri Dec 2 12:23:03 2011 From: narendarcse007 at gmail.com (narendarreddy kalam) Date: Fri, 2 Dec 2011 03:23:03 -0800 (PST) Subject: [R] about quantreg() package loading Message-ID: <1322824983856-4146366.post@n4.nabble.com> Hi all, i have installed the quantreg Package using the install packages from local zip fiels option. then i got the following message utils:::menuInstallLocal() package ?quantreg? successfully unpacked and MD5 sums checked is that mean quantreg package got installed on my machine?? if so why i am encountered the following error when loading quantreg package using library(quantreg) command Loading required package: SparseM Error: package ?SparseM? could not be loaded In addition: Warning message: In library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc = lib.loc) : there is no package called ?SparseM? what is the reason for it.. pls reply as early as possible -- View this message in context: http://r.789695.n4.nabble.com/about-quantreg-package-loading-tp4146366p4146366.html Sent from the R help mailing list archive at Nabble.com. From narendarcse007 at gmail.com Fri Dec 2 12:30:21 2011 From: narendarcse007 at gmail.com (narendarreddy kalam) Date: Fri, 2 Dec 2011 03:30:21 -0800 (PST) Subject: [R] about quantreg() package loading In-Reply-To: <1322824983856-4146366.post@n4.nabble.com> References: <1322824983856-4146366.post@n4.nabble.com> Message-ID: <1322825421006-4146390.post@n4.nabble.com> Hi all, my os is windows 7 and R version is 2.14.and i used the qunatreg zip file(binary version for windows) to install. -- View this message in context: http://r.789695.n4.nabble.com/about-quantreg-package-loading-tp4146366p4146390.html Sent from the R help mailing list archive at Nabble.com. From shyamabc2002 at yahoo.com Fri Dec 2 12:56:13 2011 From: shyamabc2002 at yahoo.com (shyam basnet) Date: Fri, 2 Dec 2011 03:56:13 -0800 (PST) Subject: [R] Error message in Genetic Matching Message-ID: <1322826973.76013.YahooMailNeo@web161703.mail.bf1.yahoo.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From alaios at yahoo.com Fri Dec 2 14:04:43 2011 From: alaios at yahoo.com (Alaios) Date: Fri, 2 Dec 2011 05:04:43 -0800 (PST) Subject: [R] find and replace string In-Reply-To: References: <1322825444.44008.YahooMailNeo@web120103.mail.ne1.yahoo.com> Message-ID: <1322831083.83340.YahooMailNeo@web120104.mail.ne1.yahoo.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From michael.weylandt at gmail.com Fri Dec 2 14:40:35 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt ) Date: Fri, 2 Dec 2011 08:40:35 -0500 Subject: [R] about quantreg() package loading In-Reply-To: <1322825421006-4146390.post@n4.nabble.com> References: <1322824983856-4146366.post@n4.nabble.com> <1322825421006-4146390.post@n4.nabble.com> Message-ID: <9F1B41A6-46AD-46A1-AFE0-6ACEBCC06234@gmail.com> It means you also need to install SparseM on which quantreg depends. This can be done in exactly the same way, either by direct download using install.packages() or local install. Michael On Dec 2, 2011, at 6:30 AM, narendarreddy kalam wrote: > Hi all, > my os is windows 7 and R version is 2.14.and i used the qunatreg zip > file(binary version for windows) to install. > > -- > View this message in context: http://r.789695.n4.nabble.com/about-quantreg-package-loading-tp4146366p4146390.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From dwinsemius at comcast.net Fri Dec 2 14:48:59 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Fri, 2 Dec 2011 08:48:59 -0500 Subject: [R] Intersection of 2 matrices In-Reply-To: <1322817653.56306.YahooMailNeo@web38408.mail.mud.yahoo.com> References: <1322817653.56306.YahooMailNeo@web38408.mail.mud.yahoo.com> Message-ID: <63DA3A2C-BEA8-4E80-AD40-550BB915686F@comcast.net> On Dec 2, 2011, at 4:20 AM, oluwole oyebamiji wrote: > Hi all, > I have matrix A of 67420 by 2 and another matrix B of 59199 by > 2. I would like to find the number of rows of matrix B that I can > find in matrix A (rows that are common to both matrices with or > without sorting). > > I have tried the "intersection" and "is.element" functions in R but > it only working for the vectors and not matrix > i.e, intersection(A,B) and is.element(A,B). Have you considered the 'duplicated' function? -- David Winsemius, MD West Hartford, CT From patrick.breheny at uky.edu Fri Dec 2 15:08:18 2011 From: patrick.breheny at uky.edu (Patrick Breheny) Date: Fri, 2 Dec 2011 09:08:18 -0500 Subject: [R] logistic regression - glm.fit: fitted probabilities numerically 0 or 1 occurred In-Reply-To: References: <2F36BA38-DD8B-4660-ACA1-709750BE0D35@gmail.com> <3684DD42-A6F4-487C-B7C0-220C044FF843@gmail.com> Message-ID: <4ED8DBD2.3080505@uky.edu> On 12/01/2011 08:00 PM, Ben quant wrote: > The data I am using is the last file called l_yx.RData at this link (the > second file contains the plots from earlier): > http://scientia.crescat.net/static/ben/ The logistic regression model you are fitting assumes a linear relationship between x and the log odds of y; that does not seem to be the case for your data. To illustrate: x <- l_yx[,"x"] y <- l_yx[,"y"] ind1 <- x <= .002 ind2 <- (x > .002 & x <= .0065) ind3 <- (x > .0065 & x <= .13) ind4 <- (x > .0065 & x <= .13) > summary(glm(y[ind1]~x[ind1],family=binomial)) ... Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -2.79174 0.02633 -106.03 <2e-16 *** x[ind1] 354.98852 22.78190 15.58 <2e-16 *** > summary(glm(y[ind2]~x[ind2],family=binomial)) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -2.15805 0.02966 -72.766 <2e-16 *** x[ind2] -59.92934 6.51650 -9.197 <2e-16 *** > summary(glm(y[ind3]~x[ind3],family=binomial)) ... Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -2.367206 0.007781 -304.22 <2e-16 *** x[ind3] 18.104314 0.346562 52.24 <2e-16 *** > summary(glm(y[ind4]~x[ind4],family=binomial)) ... Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -1.31511 0.08549 -15.383 <2e-16 *** x[ind4] 0.06261 0.08784 0.713 0.476 To summarize, the relationship between x and the log odds of y appears to vary dramatically in both magnitude and direction depending on which interval of x's range we're looking at. Trying to summarize this complicated pattern with a single line is leading to the fitted probabilities near 0 and 1 you are observing (note that only 0.1% of the data is in region 4 above, although region 4 accounts for 99.1% of the range of x). -- Patrick Breheny Assistant Professor Department of Biostatistics Department of Statistics University of Kentucky From dwinsemius at comcast.net Fri Dec 2 15:22:05 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Fri, 2 Dec 2011 09:22:05 -0500 Subject: [R] Resampling with replacement on a binary (0, 1) dataset to get Cis In-Reply-To: <1322816145585-4145733.post@n4.nabble.com> References: <1322739265192-4127990.post@n4.nabble.com> <69C9F7F8-E011-470C-B89D-D21611ED0FA4@comcast.net> <1322754549513-4129048.post@n4.nabble.com> <1322816145585-4145733.post@n4.nabble.com> Message-ID: On Dec 2, 2011, at 3:55 AM, lincoln wrote: > Thanks. > Anyway, it is not homework and I was not told to do that. My > question has > not been answered yet, I'll try to reformulate it: > Does it make (statistical) sense to resample with replacement in this > situation to get an estimate of the CIs? In case it does, how could > I do it > in R? > Some further details on my real case study: > 10 independent samples from a population in ten sessions. Each sample > consists of a number (somehow variable) of random individuals that are > classified as 0 or 1 depending on one specific state (presence or > absence of > a disease). > I can calculate, for each session, the percentage of individuals > diseased > but I have nothing about the CIs, any suggestion? I do not see much advantage to using resampling in this instance. The variance of a proportion is not theoretically complicated and you have introduced no further complicating factors that would call into question the validity of the estimates you would get from prop.test. -- David Winsemius, MD West Hartford, CT From sarah.goslee at gmail.com Fri Dec 2 15:25:57 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Fri, 2 Dec 2011 09:25:57 -0500 Subject: [R] find and replace string In-Reply-To: <1322825444.44008.YahooMailNeo@web120103.mail.ne1.yahoo.com> References: <1322825444.44008.YahooMailNeo@web120103.mail.ne1.yahoo.com> Message-ID: You've been given a workable solution already, but here's a one-liner: > x <- c('sta_+1+0_field2ndtry_0000$01.cfg' , 'sta_+B+0_field2ndtry_0000$01.cfg' , 'sta_+1+0_field2ndtry_0000$01.cfg' , 'sta_+9+0_field2ndtry_0000$01.cfg') > sapply(1:length(x), function(i)gsub("\\+(.*)\\+.", paste("\\+\\1\\+", i, sep=""), x[i])) [1] "sta_+1+1_field2ndtry_0000$01.cfg" "sta_+B+2_field2ndtry_0000$01.cfg" [3] "sta_+1+3_field2ndtry_0000$01.cfg" "sta_+9+4_field2ndtry_0000$01.cfg" Sarah, fan of regular expressions On Fri, Dec 2, 2011 at 6:30 AM, Alaios wrote: > Dear all, > I would like to search in a string for the second occurrence of a symbol and replace the symbol after it > > For example my strings look like > > sta_+1+0_field2ndtry_0000$01.cfg > > I want to find the digit that comes after the second +, in that case is zero > and then over a loop create the strings below > > sta_+1+0_field2ndtry_0000$01.cfg > > sta_+1+1_field2ndtry_0000$01.cfg > > sta_+1+2_field2ndtry_0000$01.cfg > > sta_+1+3_field2ndtry_0000$01.cfg > > and so on.. > I have already tried strsplit but this will make things more complex... > > Could you please help me with that? > > B.R > Alex > -- Sarah Goslee http://www.functionaldiversity.org From jvadams at usgs.gov Fri Dec 2 15:29:38 2011 From: jvadams at usgs.gov (Jean V Adams) Date: Fri, 2 Dec 2011 08:29:38 -0600 Subject: [R] Fw: calculate mean of multiple rows in a data frame In-Reply-To: <1322774139.12733.YahooMailClassic@web28501.mail.ukl.yahoo.com> References: <1322774139.12733.YahooMailClassic@web28501.mail.ukl.yahoo.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From tal.galili at gmail.com Fri Dec 2 15:51:33 2011 From: tal.galili at gmail.com (Tal Galili) Date: Fri, 2 Dec 2011 16:51:33 +0200 Subject: [R] Unexplained behavior of level names when using ordered factors in lm? Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From james.foadi at diamond.ac.uk Fri Dec 2 16:03:58 2011 From: james.foadi at diamond.ac.uk (james.foadi at diamond.ac.uk) Date: Fri, 2 Dec 2011 15:03:58 +0000 Subject: [R] what is used as height in hclust for ward linkage? Message-ID: Dear R community, I am trying to understand how the ward linkage works from a quantitative point of view. To test it I have devised a simple 3-members set: G = c(0,2,10) The distances between all couples are: d(0,2) = 2 d(0,10) = 10 d(2,10) = 8 The smallest distance corresponds to merging 0 and 2. The corresponding ESS are: ESS(0,2) = 2*var(c(0,2)) = 4 ESS(0,10) = 2*var(c(0,10)) = 100 ESS(2,10) = 2*var(c(2,10)) = 64 and, indeed, the smallest ESS corresponds to merging 0 and 2. The next element that should be added to 0 and 2 is obviously 10. This is where I don't understand how the hclust algorithm in R works. We have > G <- c(0,2,10) > G.dist <- dist(G) > G.hc <- hclust(G.dist,method="ward") > G.hc$merge [,1] [,2] [1,] -1 -2 [2,] -3 1 > G.hc$height [1] 2.00000 11.33333 Now, according to standard definitions, the distance between two clusters with elements Nr and Ns is: d(Rs,Rr) = sqrt(2*Nr*Ns/(Nr+Ns))*|| - || where < > in the last expression indicates averages (centroids). If I carry out this operation to merge cluster c(0,2) with 10, I get: d(c(0,2),10) = sqrt(2*2*1/(2+1))*|1-9| = 9.237604 This is different from 11.3333 in the R output. Does anyone know what's the exact value for the ward linkage, as displayed in the hclust height output? Thanks in advance for any help! J -- This e-mail and any attachments may contain confidential...{{dropped:8}} From gunter.berton at gene.com Fri Dec 2 16:06:30 2011 From: gunter.berton at gene.com (Bert Gunter) Date: Fri, 2 Dec 2011 07:06:30 -0800 Subject: [R] Unexplained behavior of level names when using ordered factors in lm? In-Reply-To: References: Message-ID: ?ordered ?C ?contr.poly If you don't know what polynomial contrasts are, consult any good linear models text. MASS has a good, though a bit terse, section on this. -- Bert On Fri, Dec 2, 2011 at 6:51 AM, Tal Galili wrote: > Hello dear all, > > I am unable to understand why when I run the following three lines: > > set.seed(4254) >> a <- data.frame(y = rnorm(40), x=ordered(sample(1:5, 40, T))) >> summary(lm(y ~ x, a)) > > > The output I get includes factor levels which are not relevant to what I am > actually using: > > Call: >> lm(formula = y ~ x, data = a) >> Residuals: >> ? ? Min ? ? ?1Q ?Median ? ? ?3Q ? ? Max >> -1.4096 -0.6400 -0.1244 ?0.5886 ?2.1891 >> Coefficients: >> ? ? ? ? ? ? Estimate Std. Error t value Pr(>|t|) >> (Intercept) -0.03276 ? ?0.15169 ?-0.216 ? ?0.830 >> x.L ? ? ? ? -0.28968 ? ?0.33866 ?-0.855 ? ?0.398 >> x.Q ? ? ? ? -0.38813 ? ?0.33851 ?-1.147 ? ?0.259 >> x.C ? ? ? ? -0.27183 ? ?0.34027 ?-0.799 ? ?0.430 >> x^4 ? ? ? ? ?0.25993 ? ?0.33935 ? 0.766 ? ?0.449 >> Residual standard error: 0.9564 on 35 degrees of freedom >> Multiple R-squared: 0.08571, Adjusted R-squared: -0.01878 >> F-statistic: 0.8202 on 4 and 35 DF, ?p-value: 0.5211 > > > I am guessing that this is having something to do with the contrast matrix > that is used, but this is not clear to me. > Can anyone suggest a good read, or an explanation? > > Thanks. > > > ----------------Contact > Details:------------------------------------------------------- > Contact me: Tal.Galili at gmail.com | ?972-52-7275845 > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | > www.r-statistics.com (English) > ---------------------------------------------------------------------------------------------- > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm From gunter.berton at gene.com Fri Dec 2 16:08:49 2011 From: gunter.berton at gene.com (Bert Gunter) Date: Fri, 2 Dec 2011 07:08:49 -0800 Subject: [R] Unexplained behavior of level names when using ordered factors in lm? In-Reply-To: References: Message-ID: Maybe should have explicitly said: > C(ordered(1:5)) [1] 1 2 3 4 5 attr(,"contrasts") ordered contr.poly Levels: 1 < 2 < 3 < 4 < 5 -- Bert On Fri, Dec 2, 2011 at 7:06 AM, Bert Gunter wrote: > ?ordered > ?C > ?contr.poly > > If you don't know what polynomial contrasts are, consult any good > linear models text. MASS has a good, though a bit terse, section on > this. > > -- Bert > > On Fri, Dec 2, 2011 at 6:51 AM, Tal Galili wrote: >> Hello dear all, >> >> I am unable to understand why when I run the following three lines: >> >> set.seed(4254) >>> a <- data.frame(y = rnorm(40), x=ordered(sample(1:5, 40, T))) >>> summary(lm(y ~ x, a)) >> >> >> The output I get includes factor levels which are not relevant to what I am >> actually using: >> >> Call: >>> lm(formula = y ~ x, data = a) >>> Residuals: >>> ? ? Min ? ? ?1Q ?Median ? ? ?3Q ? ? Max >>> -1.4096 -0.6400 -0.1244 ?0.5886 ?2.1891 >>> Coefficients: >>> ? ? ? ? ? ? Estimate Std. Error t value Pr(>|t|) >>> (Intercept) -0.03276 ? ?0.15169 ?-0.216 ? ?0.830 >>> x.L ? ? ? ? -0.28968 ? ?0.33866 ?-0.855 ? ?0.398 >>> x.Q ? ? ? ? -0.38813 ? ?0.33851 ?-1.147 ? ?0.259 >>> x.C ? ? ? ? -0.27183 ? ?0.34027 ?-0.799 ? ?0.430 >>> x^4 ? ? ? ? ?0.25993 ? ?0.33935 ? 0.766 ? ?0.449 >>> Residual standard error: 0.9564 on 35 degrees of freedom >>> Multiple R-squared: 0.08571, Adjusted R-squared: -0.01878 >>> F-statistic: 0.8202 on 4 and 35 DF, ?p-value: 0.5211 >> >> >> I am guessing that this is having something to do with the contrast matrix >> that is used, but this is not clear to me. >> Can anyone suggest a good read, or an explanation? >> >> Thanks. >> >> >> ----------------Contact >> Details:------------------------------------------------------- >> Contact me: Tal.Galili at gmail.com | ?972-52-7275845 >> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | >> www.r-statistics.com (English) >> ---------------------------------------------------------------------------------------------- >> >> ? ? ? ?[[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > > > -- > > Bert Gunter > Genentech Nonclinical Biostatistics > > Internal Contact Info: > Phone: 467-7374 > Website: > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm From dwinsemius at comcast.net Fri Dec 2 16:04:42 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Fri, 2 Dec 2011 10:04:42 -0500 Subject: [R] Unexplained behavior of level names when using ordered factors in lm? In-Reply-To: References: Message-ID: <10642CFF-6870-4674-A1BE-7F78520B4878@comcast.net> On Dec 2, 2011, at 9:51 AM, Tal Galili wrote: > Hello dear all, > > I am unable to understand why when I run the following three lines: > > set.seed(4254) >> a <- data.frame(y = rnorm(40), x=ordered(sample(1:5, 40, T))) >> summary(lm(y ~ x, a)) > > > The output I get includes factor levels which are not relevant to > what I am > actually using: > > Call: >> lm(formula = y ~ x, data = a) >> Residuals: >> Min 1Q Median 3Q Max >> -1.4096 -0.6400 -0.1244 0.5886 2.1891 >> Coefficients: >> Estimate Std. Error t value Pr(>|t|) >> (Intercept) -0.03276 0.15169 -0.216 0.830 >> x.L -0.28968 0.33866 -0.855 0.398 >> x.Q -0.38813 0.33851 -1.147 0.259 >> x.C -0.27183 0.34027 -0.799 0.430 >> x^4 0.25993 0.33935 0.766 0.449 Those are polynomial contrasts: linear, quadratic, cubic and quartic. If you don't want contrasts based on ordered factors then just use regular factors. You should probably be looking at: ?"C" (...yet another function whose name should be avoided in naming data- objects.) -- David. >> Residual standard error: 0.9564 on 35 degrees of freedom >> Multiple R-squared: 0.08571, Adjusted R-squared: -0.01878 >> F-statistic: 0.8202 on 4 and 35 DF, p-value: 0.5211 > > > I am guessing that this is having something to do with the contrast > matrix > that is used, but this is not clear to me. > Can anyone suggest a good read, or an explanation? > > Thanks. > > > ----------------Contact > Details:------------------------------------------------------- > Contact me: Tal.Galili at gmail.com | 972-52-7275845 > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il > (Hebrew) | > www.r-statistics.com (English) > ---------------------------------------------------------------------------------------------- > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT From sonja.braaker at wsl.ch Fri Dec 2 14:39:22 2011 From: sonja.braaker at wsl.ch (Sonja Braaker) Date: Fri, 02 Dec 2011 14:39:22 +0100 Subject: [R] Save Venn-diagram (Vennerable) together with table and plot in single pdf page Message-ID: <4ED8D50A.4050707@wsl.ch> Dear R-users I want to save a list with characters a point plot and a Venn diagram in a single pdf page. I am successful to do this when I use a character list and two point plots. However when I try to replace the first point plots with my Venn diagram (built with Vennerable package, compute.Venn() and plot.Venn()) the Venn plot will not position at the right place in the pdf. I guess there are some parameters in the plot.Venn function, that I need to change but I did not find out which ones. Here an example of the pdf with two point plots as I want it: library(gplots) library(Vennerable) Varnames<-c("A","B","C") x <- Venn(SetNames = Varnames,Weight = c(`100`=2,`010`=6,`001`=10,`110`=1, `011`=0.2, `101`=0.5,`111`=1)) cx<-compute.Venn(x,doWeights = TRUE) tabletext<-paste("Variable: ",letters[1:8],sep="") pdf("path/plot_test.pdf", fillOddEven=TRUE,paper="a4", onefile=TRUE,width=7,height=10) layout(matrix(c(1,2,2,1,2,2,3,3,3), 3, 3, byrow = TRUE),heights=c(1,1,2)) par(mar=c(6,2,2,4)) textplot(tabletext,valign="top",halign="left",cex=2) plot(rnorm(100),main="Random 1") plot(rnorm(100),col="red",main="Random2") dev.off() And here the example of the pdf with where I try to replace the "Random1" point plot with a Venn diagram (wrong size and position of Venn diagram): pdf("path/venn_test.pdf", fillOddEven=TRUE,paper="a4", onefile=TRUE,width=7,height=10) layout(matrix(c(1,2,2,1,2,2,3,3,3), 3, 3, byrow = TRUE),heights=c(1,1,2)) par(mar=c(6,2,2,4)) textplot(tabletext,valign="top",halign="left",cex=2) plot(cx) plot(rnorm(100),col="red",main="Random2") dev.off() Would be thankful for any hints Sonja -- Sonja Braaker Swiss Federal Research Institute WSL Community Ecology Z?rcherstrasse 111 CH-8903 Birmensdorf Tel. +41 44 7392 230 Fax +41 44 7392 215 sonja.braaker at wsl.ch http://www.wsl.ch/info/mitarbeitende/braaker/index_EN From dyb at noc.ac.uk Fri Dec 2 14:46:19 2011 From: dyb at noc.ac.uk (Berry, David I.) Date: Fri, 2 Dec 2011 13:46:19 +0000 Subject: [R] R, PostgresSQL and poor performance In-Reply-To: Message-ID: On 01/12/2011 17:01, "Gabor Grothendieck" wrote: >On Thu, Dec 1, 2011 at 10:02 AM, Berry, David I. wrote: >> Hi List >> >> Apologies if this isn't the correct place for this query (I've tried a >>search of the mail archives but not had much joy). >> >> I'm running R (2.14.0) on a Mac (OSX v 10.5.8, 2.66GHz, 4GB memory) >>and am having a few performance issues with reading data in from a >>Postres database (using RPostgreSQL). My query / code are as below >> >> # ----------------------------- >> library('RPostgreSQL') >> >> drv <- dbDriver("PostgreSQL") >> >> dbh <- dbConnect(drv,user="?",password="?",dbname="?",host="?") >> >> sql <- "select id, date, lon, lat, date_trunc('day' , date) as jday, >>extract('hour' from date) as hour, extract('year' from date) as year >>from observations where pt = 6 and date >= '1990-01-01' and date < >>'1995-01-01' and lon > 180 and lon < 290 and lat > -30 and lat < 30 and >>sst is not null" >> >> dataIn <- dbGetQuery(dbh,sql) > >If this is a large table of which the desired rows are a small >fraction of all rows then be sure there indexes on the variables in >your where clause. > >You can also try it with the RpgSQL driver although there is no reason >to think that that would be faster. > >-- >Statistics & Software Consulting >GKX Group, GKX Associates Inc. >tel: 1-877-GKX-GROUP >email: ggrothendieck at gmail.com Thanks for the reply and suggestions. I've tried the RpgSQL drivers and the results are pretty similar in terms of performance. The ~1.5M records I'm trying to read into R are being extracted from a table with ~300M rows (and ~60 columns) that has been indexed on the relevant columns and horizontally partitioned (with constraint checking on). I do need to try and optimize the database a bit more but I don?t think this is the cause of the performance issues. As an example, when I run the query purely in R it takes 273s to run (using system.time() to time it). When I extract the data via psql and system() and then import it into R using read.table() it takes 32s. The code I've used for both are below. The second way of doing it (psql and read.table()) is less than ideal but does seem to have a big performance advantage at the moment ? the only difference in the results is that the date variables are stored as strings in the second example. # Query purely in R # ------------------------ dbh <- dbConnect(drv,user="?",password="?", dbname="?",host="?") sql <- "select id, date, lon, lat, date_trunc('day' , date) as jday, extract('hour' from date) as hour, extract('year' from date) as year from observations where pt = 6 and date >= '1990-01-01' and date < '1995-01-01' and lon > 180 and lon < 290 and lat > -30 and lat < 30 and sst is not null;" dataIn <- dbGetQuery(dbh,sql) # Query via command line # ---------------------------------- system('psql ?h myhost ?d mydb ?U myuid ?f getData.sql') system('cat tmp.csv | sed 's/^,/""&/g;s/^[0-9a-zA-Z]\+/"&"/g' > tmp2.csv') # This just ensures the first column is quoted dataIn <- read.table('tmp2.csv',sep=',' ,col.names=c( "id","date","lon","lat","jday","hour","year") ) # Contents of getData.sql # --------------------------------- \o ./tmp.csv \pset format unaligned \pset fieldsep ',' \pset tuples_only select id, date, lon, lat, date_trunc('day' , date) as jday, extract('hour' from date) as hour, extract('year' from date) as year from observations where pt = 6 and date >= '1990-01-01' and date < '1995-01-01' and lon > 180 and lon < 290 and lat > -30 and lat < 30 and sst is not null; \q ---------------------------------------------- David Berry National Oceanography Centre, UK -- This message (and any attachments) is for the recipient only. NERC is subject to the Freedom of Information Act 2000 and the contents of this email and any reply you make may be disclosed by NERC unless it is exempt from release under the Act. Any material supplied to NERC may be stored in an electronic records management system. From shyamabc2002 at yahoo.com Fri Dec 2 15:16:12 2011 From: shyamabc2002 at yahoo.com (shyam basnet) Date: Fri, 2 Dec 2011 06:16:12 -0800 (PST) Subject: [R] Error in Genetic Matching Message-ID: <1322835372.39181.YahooMailNeo@web161706.mail.bf1.yahoo.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From richardtoss at hotmail.com Fri Dec 2 15:43:00 2011 From: richardtoss at hotmail.com (RToss) Date: Fri, 2 Dec 2011 06:43:00 -0800 (PST) Subject: [R] How to test for Poisson? Message-ID: <1322836980746-4147356.post@n4.nabble.com> Hi! I am sitting with a school assignment, but I got stuck on this one. I am suppose to test if my data is Poisson-distributed. The data I?m using is the studie "Bids", found in the Ecdat-package, and the variable of interest is the dependent "numbids". How do I practically perform a test for this? Kind regards/ Richard -- View this message in context: http://r.789695.n4.nabble.com/How-to-test-for-Poisson-tp4147356p4147356.html Sent from the R help mailing list archive at Nabble.com. From irene_vrbik at hotmail.com Fri Dec 2 16:09:21 2011 From: irene_vrbik at hotmail.com (statfan) Date: Fri, 2 Dec 2011 07:09:21 -0800 (PST) Subject: [R] breaking up n object into random groups Message-ID: <1322838561294-4147476.post@n4.nabble.com> say n = 100 I want to partition this into 4 random groups wheren n1 + n2 + n3 + n4 = n and ni is the number of elements in group i. Thank you for you help -- View this message in context: http://r.789695.n4.nabble.com/breaking-up-n-object-into-random-groups-tp4147476p4147476.html Sent from the R help mailing list archive at Nabble.com. From bps0002 at auburn.edu Fri Dec 2 16:18:25 2011 From: bps0002 at auburn.edu (B77S) Date: Fri, 2 Dec 2011 07:18:25 -0800 (PST) Subject: [R] How to test for Poisson? In-Reply-To: <1322836980746-4147356.post@n4.nabble.com> References: <1322836980746-4147356.post@n4.nabble.com> Message-ID: <1322839105718-4147519.post@n4.nabble.com> A simple way to determine if it is NOT is to see if the mean (the single parameter of a poisson: lambda) and variance are the same. This really has nothing to do with R (other than the data source), and since it is homework, you will likely get no further help here. Good luck. RToss wrote > > Hi! > > I am sitting with a school assignment, but I got stuck on this one. > I am suppose to test if my data is Poisson-distributed. > The data I?m using is the studie "Bids", found in the Ecdat-package, and > the variable of interest is the dependent "numbids". > How do I practically perform a test for this? > > Kind regards/ Richard > -- View this message in context: http://r.789695.n4.nabble.com/How-to-test-for-Poisson-tp4147356p4147519.html Sent from the R help mailing list archive at Nabble.com. From dwinsemius at comcast.net Fri Dec 2 16:22:34 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Fri, 2 Dec 2011 10:22:34 -0500 Subject: [R] breaking up n object into random groups In-Reply-To: <1322838561294-4147476.post@n4.nabble.com> References: <1322838561294-4147476.post@n4.nabble.com> Message-ID: On Dec 2, 2011, at 10:09 AM, statfan wrote: > say n = 100 > I want to partition this into 4 random groups wheren n1 + n2 + n3 + > n4 = n > and ni is the number of elements in group i. > Try assigning with a sample() from: unlist(mapply(rep, c(1:4), each=c(n1,n2,n3,n4))) -- David Winsemius, MD West Hartford, CT From gunter.berton at gene.com Fri Dec 2 16:28:15 2011 From: gunter.berton at gene.com (Bert Gunter) Date: Fri, 2 Dec 2011 07:28:15 -0800 Subject: [R] breaking up n object into random groups In-Reply-To: <1322838561294-4147476.post@n4.nabble.com> References: <1322838561294-4147476.post@n4.nabble.com> Message-ID: There are a million ways to do this, probably. brks <- c(1,sort(sample(seq_len(99),3)),100) ## 4 random groups and then use brks as the breaks parameter in cut() with include.lowest = TRUE ?cut -- Bert On Fri, Dec 2, 2011 at 7:09 AM, statfan wrote: > say n = 100 > I want to partition this into 4 random groups wheren n1 + n2 + n3 + n4 = n > and ni is the number of elements in group i. > > Thank you for you help > > -- > View this message in context: http://r.789695.n4.nabble.com/breaking-up-n-object-into-random-groups-tp4147476p4147476.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm From kendejan at yahoo.fr Fri Dec 2 17:15:24 2011 From: kendejan at yahoo.fr (kende jan) Date: Fri, 2 Dec 2011 16:15:24 +0000 (GMT) Subject: [R] CART with rpart Message-ID: <1322842524.46799.YahooMailNeo@web25401.mail.ukl.yahoo.com> Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible URL : From tal.galili at gmail.com Fri Dec 2 17:40:49 2011 From: tal.galili at gmail.com (Tal Galili) Date: Fri, 2 Dec 2011 18:40:49 +0200 Subject: [R] CART with rpart In-Reply-To: <1322842524.46799.YahooMailNeo@web25401.mail.ukl.yahoo.com> References: <1322842524.46799.YahooMailNeo@web25401.mail.ukl.yahoo.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From tal.galili at gmail.com Fri Dec 2 17:42:43 2011 From: tal.galili at gmail.com (Tal Galili) Date: Fri, 2 Dec 2011 18:42:43 +0200 Subject: [R] Unexplained behavior of level names when using ordered factors in lm? In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From karajamu at hotmail.com Fri Dec 2 17:43:35 2011 From: karajamu at hotmail.com (karajamu) Date: Fri, 2 Dec 2011 17:43:35 +0100 Subject: [R] Willkommen bei der "R-help" Mailingliste In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From mjekel at uni-bonn.de Fri Dec 2 16:17:49 2011 From: mjekel at uni-bonn.de (Marc Jekel) Date: Fri, 02 Dec 2011 16:17:49 +0100 Subject: [R] R + memory of objects Message-ID: <4ED8EC1D.1060806@uni-bonn.de> Dear R community, I am still struggling a bit on how R does memory allocation and how to optimize my code to minimize working memory load. Simon (thanks!) and others gave me a hint to use the command "gc()" to clean up memory which works quite nice but appears to me to be more like a "fix" to a problem. To give you an impression of what I am talking, here is a short code example + I will give rough measure (system track app) of my working memory needed for each computational step (R64bit latest version on WIN 7 64 bit system, 2 Cores, approx 4 GB Ram): ########################## # example 1: y= matrix(rep(1,50000000), nrow = 50000000/2 , ncol = 2) # used working memory increases from 1044 --> 1808 MB # (same command again, i.e.) y= matrix(rep(1,50000000), nrow = 50000000/2 , ncol = 2) # 1808 MB --> 2178 MB Why does memory increase? # (give the matrix column names) colnames(y) = c("col1", "col2") # 2178 MB --> 1781 MB Why does the size of an object decrease if I assign column labels? ### # example 2: y= matrix(rep(1,50000000), nrow = 50000000/2 , ncol = 2) 1016 --> 1780 MB y = data.frame(y) # increase from 1780 MB --> 3315 MB ########################## Why does it take so much extra memory to store this matrix as a data.frame? It is not the object per se (i.e. that data.frames need more memory) because if I use gc() memory size drops to 1387 MB. Does this mean that it may be more memory-efficient not to use any data.frames but matrices only? etc. This puzzles me a lot. From my experience these effects are also accentuated for larger objects. As an anecdotal comparison: I also used Stata in my last project due to these memory problems and I could do a lot of variable manipulations of the same (!) data with significant (I am talking about GB) less memory needed. Best, Marc From robgriffin247 at hotmail.com Fri Dec 2 17:41:00 2011 From: robgriffin247 at hotmail.com (robgriffin247) Date: Fri, 2 Dec 2011 08:41:00 -0800 (PST) Subject: [R] Graphics - Axis Labels overlap window edges Message-ID: <1322844060868-4147897.post@n4.nabble.com> Hi, I am trying to put larger axis labels on my graphs (using cex.axis and cex.label) but when I do this the top of the text on the Y axis goes outside of the window which you can see in this picture -http://twitter.com/#!/robgriffin247/status/142642881436450816/photo/1 - (if you click on the picture it opens a larger version so it is easier to see the problem) is there anyway I can get R to not cut the top off the letters? Thanks, Rob -- View this message in context: http://r.789695.n4.nabble.com/Graphics-Axis-Labels-overlap-window-edges-tp4147897p4147897.html Sent from the R help mailing list archive at Nabble.com. From aurelien.philippot at gmail.com Fri Dec 2 18:01:36 2011 From: aurelien.philippot at gmail.com (=?ISO-8859-1?Q?Aur=E9lien_PHILIPPOT?=) Date: Fri, 2 Dec 2011 09:01:36 -0800 Subject: [R] Problem subsetting: undefined columns In-Reply-To: <4ED8A34D.1030800@knmi.nl> References: <4ED8A34D.1030800@knmi.nl> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From ligges at statistik.tu-dortmund.de Fri Dec 2 18:13:11 2011 From: ligges at statistik.tu-dortmund.de (Uwe Ligges) Date: Fri, 02 Dec 2011 18:13:11 +0100 Subject: [R] R + memory of objects In-Reply-To: <4ED8EC1D.1060806@uni-bonn.de> References: <4ED8EC1D.1060806@uni-bonn.de> Message-ID: <4ED90727.2060206@statistik.tu-dortmund.de> I guess the numbers your report are what your OS shows you? R runs garbage collection (which can be manually triggred by gc()) after certain fuzzy rules. So what you report below is not always the current required memory but what was allocated and not yet garbnage collected. See ?object.size to get the memory consumption of objects. Uwe Ligges On 02.12.2011 16:17, Marc Jekel wrote: > Dear R community, > > I am still struggling a bit on how R does memory allocation and how to > optimize my code to minimize working memory load. Simon (thanks!) and > others gave me a hint to use the command "gc()" to clean up memory which > works quite nice but appears to me to be more like a "fix" to a problem. > > To give you an impression of what I am talking, here is a short code > example + I will give rough measure (system track app) of my working > memory needed for each computational step (R64bit latest version on WIN > 7 64 bit system, 2 Cores, approx 4 GB Ram): > > ########################## > > # example 1: > > y= matrix(rep(1,50000000), nrow = 50000000/2 , ncol = 2) > > # used working memory increases from 1044 --> 1808 MB > > # (same command again, i.e.) > > y= matrix(rep(1,50000000), nrow = 50000000/2 , ncol = 2) > > # 1808 MB --> 2178 MB Why does memory increase? > > # (give the matrix column names) > > colnames(y) = c("col1", "col2") > > # 2178 MB --> 1781 MB Why does the size of an object decrease if I > assign column labels? > > ### > > # example 2: > > y= matrix(rep(1,50000000), nrow = 50000000/2 , ncol = 2) > > 1016 --> 1780 MB > > y = data.frame(y) > > # increase from 1780 MB --> 3315 MB > > ########################## > > Why does it take so much extra memory to store this matrix as a data.frame? > > It is not the object per se (i.e. that data.frames need more memory) > because if I use gc() memory size drops to 1387 MB. Does this mean that > it may be more memory-efficient not to use any data.frames but matrices > only? etc. > > This puzzles me a lot. From my experience these effects are also > accentuated for larger objects. > > As an anecdotal comparison: I also used Stata in my last project due to > these memory problems and I could do a lot of variable manipulations of > the same (!) data with significant (I am talking about GB) less memory > needed. > > Best, > > Marc > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From ligges at statistik.tu-dortmund.de Fri Dec 2 18:18:22 2011 From: ligges at statistik.tu-dortmund.de (Uwe Ligges) Date: Fri, 02 Dec 2011 18:18:22 +0100 Subject: [R] Graphics - Axis Labels overlap window edges In-Reply-To: <1322844060868-4147897.post@n4.nabble.com> References: <1322844060868-4147897.post@n4.nabble.com> Message-ID: <4ED9085E.2070504@statistik.tu-dortmund.de> On 02.12.2011 17:41, robgriffin247 wrote: > Hi, > > I am trying to put larger axis labels on my graphs (using cex.axis and > cex.label) but when I do this the top of the text on the Y axis goes outside > of the window which you can see in this picture > -http://twitter.com/#!/robgriffin247/status/142642881436450816/photo/1 - (if > you click on the picture it opens a larger version so it is easier to see > the problem) is there anyway I can get R to not cut the top off the letters? Increase the margins. See ?par and its "mar" argument. Uwe Ligges > Thanks, > Rob > > -- > View this message in context: http://r.789695.n4.nabble.com/Graphics-Axis-Labels-overlap-window-edges-tp4147897p4147897.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From axel.urbiz at gmail.com Fri Dec 2 18:21:21 2011 From: axel.urbiz at gmail.com (Axel Urbiz) Date: Fri, 2 Dec 2011 12:21:21 -0500 Subject: [R] Random Forests in R In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From mailinglist.honeypot at gmail.com Fri Dec 2 18:22:47 2011 From: mailinglist.honeypot at gmail.com (Steve Lianoglou) Date: Fri, 2 Dec 2011 12:22:47 -0500 Subject: [R] Unexplained behavior of level names when using ordered factors in lm? In-Reply-To: References: Message-ID: Hi Bert, Since you opened the door ... On Fri, Dec 2, 2011 at 10:06 AM, Bert Gunter wrote: > ?ordered > ?C > ?contr.poly > > If you don't know what polynomial contrasts are, consult any good > linear models text. MASS has a good, though a bit terse, section on > this. Do you have a "favorite" liner model text with a bit more exposition than MASS? Even though this list isn't for teaching stats, whenever I can catch some of the tried and true statisticians talking about texts on specific subject matter, I like to take advantage of it to see what I need to add to my amazon wish list to help sharpen the old saw :-) Thanks, -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology ?| Memorial Sloan-Kettering Cancer Center ?| Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact From michael.weylandt at gmail.com Fri Dec 2 18:30:05 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt ) Date: Fri, 2 Dec 2011 12:30:05 -0500 Subject: [R] Problem subsetting: undefined columns In-Reply-To: References: <4ED8A34D.1030800@knmi.nl> Message-ID: <33DACDEA-8EF7-4414-A81B-D869C0AB94FD@gmail.com> How about this? d[, v[v %in% colnames(d)]] Michael On Dec 2, 2011, at 12:01 PM, Aur?lien PHILIPPOT wrote: > Hi Paul and Jim, > Thanks for your messages. > > I just wanted R to give me the columns of my data frame d, whose names > appear in v. I do not care about the names of v that are not in d. In > addition, every time, there will be at least one element of v that has a > corresponding column in d, for sure, so I know there is at least one match > between the 2. > > Initially, I tried something in the spirit: > sub<- subset(d, colnames(d) %in% v) > > but I could not make it work properly. > > > Best, > Aurelien > > 2011/12/2 Paul Hiemstra > >> On 12/02/2011 07:20 AM, Aur?lien PHILIPPOT wrote: >>> Dear R-users, >>> -I am new to R, and I am struggling with the following problem. >>> >>> -I am repeating the following operations hundreds of times, within a >> loop: >>> I want to subset a data frame by columns. I am interested in the columns >>> names that are given by the rows of another data frame that was built in >>> parallel. The solution I have so far works well as long as the elements >> of >>> the second data frame are included in the column names of the first data >>> frame but if an element from the second object is not a column name of >> the >>> first one, then it bugs. >> >> Hi Aurelien, >> >> I would call this a feature, not a bug. I think R does what it should >> do, you request a non-existent column and it throws an error. What kind >> of behavior are you looking for instead of this error? >> >> regards, >> Paul >> >>> >>> -More concretely, I have the following data frames d and v: >>> yyyymmdd<-c("19720601", "19720602", "19720605") >>> sret.10006<-c(1,2,3) >>> sret.10014<-c(5,9,7) >>> sret.10065<-c(10,2,11) >>> >>> >>> d<- data.frame(yyyymmdd=yyyymmdd, sret.10006=sret.10006, >>> sret.10014=sret.10014, sret.10065=sret.10065) >>> >>> v<- data.frame(V1="sret.10006", V2="sret.10090") >>> v<- sapply(v, function(x) levels(x)[x]) >>> >>> -I want to do the following subsetting: >>> sub<- subset(d, select=c(v)) >>> >>> >>> and I get the following error message: >>> Error in `[.data.frame`(x, r, vars, drop = drop) : >>> undefined columns selected >>> >>> >>> >>> Any help would be very much appreciated, >>> >>> Best, >>> Aurelien >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> >> >> -- >> Paul Hiemstra, Ph.D. >> Global Climate Division >> Royal Netherlands Meteorological Institute (KNMI) >> Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39 >> P.O. Box 201 | 3730 AE | De Bilt >> tel: +31 30 2206 494 >> >> http://intamap.geo.uu.nl/~paul >> http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770 >> >> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From sas0025 at auburn.edu Fri Dec 2 18:39:21 2011 From: sas0025 at auburn.edu (Stephen Sefick) Date: Fri, 02 Dec 2011 11:39:21 -0600 Subject: [R] Partitioning Around Mediods then rpart to follow - is this sensible Message-ID: <4ED90D49.8050803@auburn.edu> The problem: There are no a priori groupings to run a classification on My solution: This is a non-R code question, so I appreciate any thoughts. I have used pam in the cluster package proceeded by sillohouette to find the optimum number of clusters on scaled and centered data. I have followed this by a classification tree analysis with rpart to discern which variables drive the clustering on the original data. Is this a sensible approach? many thanks, Stephen Sefick From momadou at yahoo.fr Fri Dec 2 18:15:56 2011 From: momadou at yahoo.fr (Komine) Date: Fri, 2 Dec 2011 09:15:56 -0800 (PST) Subject: [R] Problem with loop Message-ID: <1322846156594-4148083.post@n4.nabble.com> Hi, I try to build a loop difficultly. I have in a folder called Matrices several files (.csv) called Mat2002273, Mat2002274 to Mat2002361. I want to calculate for each file the mean of the column called Pixelvalues. I try this code but as result, I have this message: Mat2002273 not found >essai<-read.table("C:\\Users\\Desktop\\Matrices\\Mat2002273.csv",sep=";",dec=",",header=TRUE) >essai >a <- NULL >for(i in Mat2002273:Mat2002361){ >paste(mean(essai$Pixelvalues)) >a[i] <- paste(mean(essai$Pixelvalues)) >print(a[i]) >} Thank you for your help -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-loop-tp4148083p4148083.html Sent from the R help mailing list archive at Nabble.com. From mkao006rmail at gmail.com Fri Dec 2 18:47:07 2011 From: mkao006rmail at gmail.com (Michael Kao) Date: Fri, 02 Dec 2011 18:47:07 +0100 Subject: [R] Intersection of 2 matrices In-Reply-To: <63DA3A2C-BEA8-4E80-AD40-550BB915686F@comcast.net> References: <1322817653.56306.YahooMailNeo@web38408.mail.mud.yahoo.com> <63DA3A2C-BEA8-4E80-AD40-550BB915686F@comcast.net> Message-ID: <4ED90F1B.8090706@gmail.com> On 2/12/2011 2:48 p.m., David Winsemius wrote: > > On Dec 2, 2011, at 4:20 AM, oluwole oyebamiji wrote: > >> Hi all, >> I have matrix A of 67420 by 2 and another matrix B of 59199 by 2. >> I would like to find the number of rows of matrix B that I can find >> in matrix A (rows that are common to both matrices with or without >> sorting). >> >> I have tried the "intersection" and "is.element" functions in R but >> it only working for the vectors and not matrix >> i.e, intersection(A,B) and is.element(A,B). > > Have you considered the 'duplicated' function? > Here is an example based on the duplicated function test.mat1 <- matrix(1:20, nc = 5) test.mat2 <- rbind(test.mat1[sample(1:5, 2), ], matrix(101:120, nc = 5)) compMat <- function(mat1, mat2){ nr1 <- nrow(mat1) nr2 <- nrow(mat2) mat2[duplicated(rbind(mat1, mat2))[(nr1 + 1):(nr1 + nr2)], ] } compMat(test.mat1, test.mat2) From michael.weylandt at gmail.com Fri Dec 2 18:55:31 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Fri, 2 Dec 2011 12:55:31 -0500 Subject: [R] Problem with loop In-Reply-To: <1322846156594-4148083.post@n4.nabble.com> References: <1322846156594-4148083.post@n4.nabble.com> Message-ID: You never create a variable called "Mat2002273" or "Mat2002361" so you can't ask R to loop over all the values between them. If I were you, I'd code something like this: lf <- list.files() # PUT IN SOME CODE TO REMOVE FILES YOU DON'T WANT TO USE pv <- vector("numeric", length(lf)) for(i in lf) pv[i] <- mean( read.csv(lf, header = TRUE)[,"Pixelvalues"]) print(pv) Michael On Fri, Dec 2, 2011 at 12:15 PM, Komine wrote: > Hi, > I try to build a loop difficultly. > I have in a folder called Matrices several files (.csv) called Mat2002273, > Mat2002274 ?to Mat2002361. > I want to calculate for each file the mean of the column called Pixelvalues. > I try this code but as result, I have this message: ?Mat2002273 not found > >>essai<-read.table("C:\\Users\\Desktop\\Matrices\\Mat2002273.csv",sep=";",dec=",",header=TRUE) >>essai >>a <- NULL >>for(i in Mat2002273:Mat2002361){ >>paste(mean(essai$Pixelvalues)) >>a[i] <- paste(mean(essai$Pixelvalues)) >>print(a[i]) >>} > > Thank you for your help > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Problem-with-loop-tp4148083p4148083.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From desviostandard at gmail.com Fri Dec 2 19:01:43 2011 From: desviostandard at gmail.com (=?ISO-8859-1?Q?Pablo_Dom=EDnguez_Vaselli?=) Date: Fri, 2 Dec 2011 15:01:43 -0300 Subject: [R] References for book "R In Action" by Kabacoff Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From dschruth at u.washington.edu Fri Dec 2 18:46:27 2011 From: dschruth at u.washington.edu (David M. Schruth) Date: Fri, 02 Dec 2011 09:46:27 -0800 Subject: [R] help in dbWriteTable In-Reply-To: <1322801638400-4145110.post@n4.nabble.com> References: <1322801638400-4145110.post@n4.nabble.com> Message-ID: <4ED90EF3.4030109@u.washington.edu> Hi, The following code should work: fields <- dbListFields(con, db.table.name) reordered.names <- names(df)[match(fields, names(df))] df <- df[ ,reordered.names] But, you might want to try using the function 'dbWriteTable2' in the 'caroline' package. (In fact the three lines above have been copied verbatim out of said function). It works much like the original dbWriteTable but also addresses the column reordering frustration you mention and more: na's in NOT NULL columns, length mismatches, adding NA columns for missing fields, type checking as well as primary key support for PostgreSQL. I use it mainly with Postgres so I can't say for sure if it'll work for you. But let me know if it doesn't! -Dave Schruth On 12/1/2011 8:53 PM, arunkumar1111 wrote: > hi > > I need some help in dbWriteTable. > I'm not able to insert the rows in the table if the column order are not > same in the database and in the dataframe which i'm inserting. Also facing > issue if the table is already created externally and inserting it thru > dbWrite. > > is there some way that we can sepecify the rownames in the dbwrite..or any > method which will solve my problem > > > > -- > View this message in context: http://r.789695.n4.nabble.com/help-in-dbWriteTable-tp4145110p4145110.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From rpickeri at mail.nih.gov Fri Dec 2 19:25:32 2011 From: rpickeri at mail.nih.gov (RogerP) Date: Fri, 2 Dec 2011 10:25:32 -0800 (PST) Subject: [R] Compiling R using Solaris Studio Message-ID: <1322850332340-4148407.post@n4.nabble.com> I am trying to compile R using Solaris Studio, but it keeps trying to use the GNU compiler! I've tried editing all the Makeconf files I can find, but configure keeps changing them back! I tried to rename the GNU directory so it could not find gcc, but then I got a missing lib error. How does one change the compiler used to compile R? Thanks! Roger -- View this message in context: http://r.789695.n4.nabble.com/Compiling-R-using-Solaris-Studio-tp4148407p4148407.html Sent from the R help mailing list archive at Nabble.com. From michael.weylandt at gmail.com Fri Dec 2 19:42:35 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Fri, 2 Dec 2011 13:42:35 -0500 Subject: [R] Error in Genetic Matching In-Reply-To: <1322835372.39181.YahooMailNeo@web161706.mail.bf1.yahoo.com> References: <1322835372.39181.YahooMailNeo@web161706.mail.bf1.yahoo.com> Message-ID: The error message is pretty explicit: your problem is taht one of your inputs has NA (missing value) in it and the GenMatch() function is not prepared to handle the. You can find which one by running: any(is.na(Tr)) any(is.na(X.binarynp) any(is.na(BalanceMatrix.binarynp)) and then use View() on the object with NAs to take a look and see where they are coming from. Michael On Fri, Dec 2, 2011 at 9:16 AM, shyam basnet wrote: > Dear R Users, > > I am a novice learner of R software. I am working with Genetic Matching -?GenMatch(), but I am getting an Error message as follows: > > Error in GenMatch(Tr = Tr, X = X.binarynp, BalanceMatrix = BalanceMatrix.binarynp, ?: > ? GenMatch(): input includes NAs > > Could you please suggest me correcting the above problem? > > My GenMatch command is, > >> gen1 <- GenMatch(Tr = Tr, X = X.binarynp, BalanceMatrix = BalanceMatrix.binarynp, popsize = 1000) > > Thanking you, > > Sincerely Yours, > > Shyam Kumar Basnet > SLU,?Uppsala > Sweden > > ? ? ? ?[[alternative HTML version deleted]] > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > From hadley at rice.edu Fri Dec 2 20:04:59 2011 From: hadley at rice.edu (Hadley Wickham) Date: Fri, 2 Dec 2011 13:04:59 -0600 Subject: [R] Project local libraries (reproducible research) Message-ID: Hi all, I was wondering if any one had scripts that they could share for capturing the current version of R packages used for a project. I'm interested in creating a project local library so that you're safe if someone (e.g. the ggplot2 author) updates a package you're relying on and breaks your code. I could fairly easily hack together, but I was wondering if any one had any neat scripts they'd care to share. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ From hwborchers at googlemail.com Fri Dec 2 20:22:31 2011 From: hwborchers at googlemail.com (Hans W Borchers) Date: Fri, 2 Dec 2011 19:22:31 +0000 Subject: [R] Intersection of 2 matrices References: <1322817653.56306.YahooMailNeo@web38408.mail.mud.yahoo.com> <63DA3A2C-BEA8-4E80-AD40-550BB915686F@comcast.net> <4ED90F1B.8090706@gmail.com> Message-ID: Michael Kao gmail.com> writes: > Your solution is fast, but not completely correct, because you are also counting possible duplicates within the second matrix. The 'refitted' function could look as follows: compMat2 <- function(A, B) { # rows of B present in A B0 <- B[!duplicated(B), ] na <- nrow(A); nb <- nrow(B0) AB <- rbind(A, B0) ab <- duplicated(AB)[(na+1):(na+nb)] return(sum(ab)) } and testing an example the size the OR was asking for: set.seed(8237) A <- matrix(sample(1:1000, 2*67420, replace=TRUE), 67420, 2) B <- matrix(sample(1:1000, 2*59199, replace=TRUE), 59199, 2) system.time(n <- compMat2(A, B)) # n = 3790 while compMat() will return 5522 rows, with 1732 duplicates within B ! A 3.06 GHz iMac needs about 2 -- 2.5 seconds. Hans Werner > On 2/12/2011 2:48 p.m., David Winsemius wrote: > > > > On Dec 2, 2011, at 4:20 AM, oluwole oyebamiji wrote: > > > >> Hi all, > >> I have matrix A of 67420 by 2 and another matrix B of 59199 by 2. > >> I would like to find the number of rows of matrix B that I can find > >> in matrix A (rows that are common to both matrices with or without > >> sorting). > >> > >> I have tried the "intersection" and "is.element" functions in R but > >> it only working for the vectors and not matrix > >> i.e, intersection(A,B) and is.element(A,B). > > > > Have you considered the 'duplicated' function? > > > > Here is an example based on the duplicated function > > test.mat1 <- matrix(1:20, nc = 5) > > test.mat2 <- rbind(test.mat1[sample(1:5, 2), ], matrix(101:120, nc = 5)) > > compMat <- function(mat1, mat2){ > nr1 <- nrow(mat1) > nr2 <- nrow(mat2) > mat2[duplicated(rbind(mat1, mat2))[(nr1 + 1):(nr1 + nr2)], ] > } > > compMat(test.mat1, test.mat2) > > From ihok at hotmail.com Fri Dec 2 20:28:33 2011 From: ihok at hotmail.com (Jack Tanner) Date: Fri, 2 Dec 2011 19:28:33 +0000 Subject: [R] RFE: vectorized behavior for as.POSIXct tz argument Message-ID: x <- 1472562988 + 1:10; tz <- rep("EST",10) # Case 1: Works as documented ct <- as.POSIXct(x, tz=tz[1], origin="1960-01-01") # Case 2: Fails ct <- as.POSIXct(x, tz=tz, origin="1960-01-01") If case 2 worked, it'd be a little easier to process paired (time, time zone) vectors from different time zones. From hwborchers at googlemail.com Fri Dec 2 20:46:11 2011 From: hwborchers at googlemail.com (Hans W Borchers) Date: Fri, 2 Dec 2011 19:46:11 +0000 Subject: [R] Intersection of 2 matrices References: <1322817653.56306.YahooMailNeo@web38408.mail.mud.yahoo.com> <63DA3A2C-BEA8-4E80-AD40-550BB915686F@comcast.net> <4ED90F1B.8090706@gmail.com> Message-ID: Michael Kao gmail.com> writes: > Well, taking a second look, I'd say it depends on the exact formulation. In the applications I have in mind, I would like to count each occurrence in B only once. Perhaps the OP never thought about duplicates in B Hans Werner > > Here is an example based on the duplicated function > > test.mat1 <- matrix(1:20, nc = 5) > > test.mat2 <- rbind(test.mat1[sample(1:5, 2), ], matrix(101:120, nc = 5)) > > compMat <- function(mat1, mat2){ > nr1 <- nrow(mat1) > nr2 <- nrow(mat2) > mat2[duplicated(rbind(mat1, mat2))[(nr1 + 1):(nr1 + nr2)], ] > } > > compMat(test.mat1, test.mat2) > From aurelien.philippot at gmail.com Fri Dec 2 19:28:35 2011 From: aurelien.philippot at gmail.com (=?ISO-8859-1?Q?Aur=E9lien_PHILIPPOT?=) Date: Fri, 2 Dec 2011 10:28:35 -0800 Subject: [R] Problem subsetting: undefined columns In-Reply-To: <33DACDEA-8EF7-4414-A81B-D869C0AB94FD@gmail.com> References: <4ED8A34D.1030800@knmi.nl> <33DACDEA-8EF7-4414-A81B-D869C0AB94FD@gmail.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From jroll at lcog.org Fri Dec 2 20:03:51 2011 From: jroll at lcog.org (LCOG1) Date: Fri, 2 Dec 2011 11:03:51 -0800 (PST) Subject: [R] Summarizing elements of a list In-Reply-To: References: <1322777855869-4142479.post@n4.nabble.com> Message-ID: <506F591A54F21D4480EE337F77369C056B10085E@LCEXG03.lc100.net> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From jroll at lcog.org Fri Dec 2 20:04:21 2011 From: jroll at lcog.org (LCOG1) Date: Fri, 2 Dec 2011 11:04:21 -0800 (PST) Subject: [R] Summarizing elements of a list In-Reply-To: References: <1322777855869-4142479.post@n4.nabble.com> Message-ID: <506F591A54F21D4480EE337F77369C056B10085F@LCEXG03.lc100.net> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From Bauermartin at gmx.at Fri Dec 2 20:45:13 2011 From: Bauermartin at gmx.at (Martin Bauer) Date: Fri, 02 Dec 2011 20:45:13 +0100 Subject: [R] order function give back row name Message-ID: <20111202194513.13370@gmx.net> Hello, I have a matrix results with dimension 1x9 double matrix XLB XLE XLF XLI 1 53.3089 55.77923 37.64458 83.08646 I'm trying to order this matrix > print(order(results)) [1] 3 1 2 4 how can the function order return the columnname XLF XLB XLE XLI instead of 3 1 2 4 any idea ? Thank you in advance -- From jholtman at gmail.com Fri Dec 2 21:05:32 2011 From: jholtman at gmail.com (jim holtman) Date: Fri, 2 Dec 2011 15:05:32 -0500 Subject: [R] Intersection of 2 matrices In-Reply-To: References: <1322817653.56306.YahooMailNeo@web38408.mail.mud.yahoo.com> <63DA3A2C-BEA8-4E80-AD40-550BB915686F@comcast.net> <4ED90F1B.8090706@gmail.com> Message-ID: Here is one way of doing it: > compMat2 <- function(A, B) { # rows of B present in A + B0 <- B[!duplicated(B), ] + na <- nrow(A); nb <- nrow(B0) + AB <- rbind(A, B0) + ab <- duplicated(AB)[(na+1):(na+nb)] + return(sum(ab)) + } > > > set.seed(8237) > A <- matrix(sample(1:1000, 2*67420, replace=TRUE), 67420, 2) > B <- matrix(sample(1:1000, 2*59199, replace=TRUE), 59199, 2) > > system.time({ + # convert for comparison + A.1 <- apply(A, 1, function(x) paste(x, collapse = ' ')) + B.1 <- apply(B, 1, function(x) paste(x, collapse = ' ')) + count <- sum(B.1 %in% A.1) + }) user system elapsed 1.77 0.00 1.79 > > > count [1] 3905 > On Fri, Dec 2, 2011 at 2:46 PM, Hans W Borchers wrote: > Michael Kao gmail.com> writes: > >> > Well, taking a second look, I'd say it depends on the exact formulation. > > In the applications I have in mind, I would like to count each occurrence > in B only once. Perhaps the OP never thought about duplicates in B > > Hans Werner > >> >> Here is an example based on the duplicated function >> >> test.mat1 <- matrix(1:20, nc = 5) >> >> test.mat2 <- rbind(test.mat1[sample(1:5, 2), ], matrix(101:120, nc = 5)) >> >> compMat <- function(mat1, mat2){ >> ? ? ?nr1 <- nrow(mat1) >> ? ? ?nr2 <- nrow(mat2) >> ? ? ?mat2[duplicated(rbind(mat1, mat2))[(nr1 + 1):(nr1 + nr2)], ] >> } >> >> compMat(test.mat1, test.mat2) >> > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. From michael.weylandt at gmail.com Fri Dec 2 21:09:54 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Fri, 2 Dec 2011 15:09:54 -0500 Subject: [R] order function give back row name In-Reply-To: <20111202194513.13370@gmx.net> References: <20111202194513.13370@gmx.net> Message-ID: names(results)[order(results)] Michael On Fri, Dec 2, 2011 at 2:45 PM, Martin Bauer wrote: > Hello, > > > I have a matrix results with dimension 1x9 double matrix > > ? ? ? ? XLB ? ? ? XLE ? ? ? ? ? ? XLF ? ? ? ? XLI > 1 ? ? ? 53.3089 ?55.77923 ? ? ? 37.64458 ? ? 83.08646 > > I'm trying to order this matrix > >> print(order(results)) > [1] 3 1 2 4 > > how can the function order return the columnname XLF ? XLB ? XLE ?XLI ?instead of 3 1 2 4 > > any idea ? > > Thank you in advance > -- > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From sarah.goslee at gmail.com Fri Dec 2 21:12:00 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Fri, 2 Dec 2011 15:12:00 -0500 Subject: [R] order function give back row name In-Reply-To: <20111202194513.13370@gmx.net> References: <20111202194513.13370@gmx.net> Message-ID: With similar data, since you didn't include reproducible example of your own: > results <- matrix(c(53, 55, 37, 83), nrow=1) > colnames(results) <- letters[1:4] > results a b c d [1,] 53 55 37 83 > order(results) [1] 3 1 2 4 > colnames(results)[order(results)] [1] "c" "a" "b" "d" On Fri, Dec 2, 2011 at 2:45 PM, Martin Bauer wrote: > Hello, > > > I have a matrix results with dimension 1x9 double matrix > > ? ? ? ? XLB ? ? ? XLE ? ? ? ? ? ? XLF ? ? ? ? XLI > 1 ? ? ? 53.3089 ?55.77923 ? ? ? 37.64458 ? ? 83.08646 > > I'm trying to order this matrix > >> print(order(results)) > [1] 3 1 2 4 > > how can the function order return the columnname XLF ? XLB ? XLE ?XLI ?instead of 3 1 2 4 > > any idea ? > > Thank you in advance > -- > -- Sarah Goslee http://www.functionaldiversity.org From michael.weylandt at gmail.com Fri Dec 2 21:19:56 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Fri, 2 Dec 2011 15:19:56 -0500 Subject: [R] Summarizing elements of a list In-Reply-To: <506F591A54F21D4480EE337F77369C056B10085F@LCEXG03.lc100.net> References: <1322777855869-4142479.post@n4.nabble.com> <506F591A54F21D4480EE337F77369C056B10085F@LCEXG03.lc100.net> Message-ID: Here's a slight modification that is even faster if speed is a consideration: sapply(Version1_, `[[`, "First") The thought process is to go through the list "Version1_" and apply the operation `[[` to each element individually. This requires a second operator (here the element name "First") which we pass through the "..." of sapply() -- I hope that helps you get a sense of the mechanics. We use sapply() instead of lapply() because it does some internal simplification for us to get one big vector back, effectively cutting out the "unlist" of the first solution I gave you. Michael On Fri, Dec 2, 2011 at 2:04 PM, LCOG1 wrote: > Great, this worked the fastest of all the suggestions. ?Cheers, > > Josh > > ________________________________ > From: Michael Weylandt [via R] [mailto:ml-node+s789695n4144941h1 at n4.nabble.com] > Sent: Thursday, December 01, 2011 8:11 PM > To: ROLL Josh F > Subject: Re: Summarizing elements of a list > > Similarly, this might work: > > unlist(lapply(Version1_, `[`,"First")) > > Michael > > On Thu, Dec 1, 2011 at 9:41 PM, Sarah Goslee <[hidden email]> wrote: > >> How about: >> >> lapply(Version1_, subset, subset=c(TRUE, FALSE)) >> or sapply() depending on what you want the result to look like. >> >> Thanks for the reproducible example. >> >> Sarah >> >> On Thu, Dec 1, 2011 at 5:17 PM, LCOG1 <[hidden email]> wrote: >>> Hi everyone, >>> ? I looked around the list for a while but couldn't find a solution to my >>> problem. ?I am storing some results to a simulation in a list and for each >>> element i have two separate vectors(is that what they are called, correct my >>> vocab if necessary). See below >>> >>> Version1_<-list() >>> for(i in 1:5){ >>> ? ? ? ?Version1_[[i]]<-list(First=rnorm(1),Second=rnorm(1)) >>> } >>> >>> What I want is to put all of the elements' 'First' vectors into a single >>> list to box plot. But whats a more elegant solution to the below? >>> >>> c(Version1_[[1]]$First,Version1_[[2]]$First,Version1_[[3]]$First,Version1_[[4]]$First,Version1_[[5]]$First) >>> >>> since i have 50 or more simulations this is impractical and sloppy. ?Do I >>> need to store my data differently or is their a solution on the back end? >>> Thanks all. >>> >>> Josh >>> >> -- >> Sarah Goslee >> http://www.functionaldiversity.org >> >> ______________________________________________ >> [hidden email] mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > > ________________________________ > If you reply to this email, your message will be added to the discussion below: > http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4144941.html > To unsubscribe from Summarizing elements of a list, click here. > NAML > > > -- > View this message in context: http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4148571.html > Sent from the R help mailing list archive at Nabble.com. > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From dwinsemius at comcast.net Fri Dec 2 21:54:44 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Fri, 2 Dec 2011 15:54:44 -0500 Subject: [R] RFE: vectorized behavior for as.POSIXct tz argument In-Reply-To: References: Message-ID: <1A760C01-FF69-42DC-8DF2-474E6B771572@comcast.net> On Dec 2, 2011, at 2:28 PM, Jack Tanner wrote: > x <- 1472562988 + 1:10; tz <- rep("EST",10) > > # Case 1: Works as documented > ct <- as.POSIXct(x, tz=tz[1], origin="1960-01-01") > > # Case 2: Fails > ct <- as.POSIXct(x, tz=tz, origin="1960-01-01") sapply(tz, function(ttt) as.POSIXct(x=x, tz=ttt, origin="1960-01-01"),simplify=FALSE) > > If case 2 worked, it'd be a little easier to process paired (time, > time zone) > vectors from different time zones. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT From santosh2005 at gmail.com Fri Dec 2 22:03:37 2011 From: santosh2005 at gmail.com (Santosh) Date: Fri, 2 Dec 2011 13:03:37 -0800 Subject: [R] Plot and polygon in log scale Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From ihok at hotmail.com Fri Dec 2 22:06:38 2011 From: ihok at hotmail.com (Jack Tanner) Date: Fri, 2 Dec 2011 21:06:38 +0000 Subject: [R] RFE: vectorized behavior for as.POSIXct tz argument References: <1A760C01-FF69-42DC-8DF2-474E6B771572@comcast.net> Message-ID: David Winsemius comcast.net> writes: > sapply(tz, function(ttt) as.POSIXct(x=x, tz=ttt, > origin="1960-01-01"),simplify=FALSE) Sure, there's no end of workarounds. It would just be consistent to treat both the x and the tz arguments as vectors. From dwinsemius at comcast.net Fri Dec 2 22:47:49 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Fri, 2 Dec 2011 16:47:49 -0500 Subject: [R] RFE: vectorized behavior for as.POSIXct tz argument In-Reply-To: References: <1A760C01-FF69-42DC-8DF2-474E6B771572@comcast.net> Message-ID: <6CA5D915-90A9-40D6-8DA1-8EE87E16B935@comcast.net> On Dec 2, 2011, at 4:06 PM, Jack Tanner wrote: > David Winsemius comcast.net> writes: > >> sapply(tz, function(ttt) as.POSIXct(x=x, tz=ttt, >> origin="1960-01-01"),simplify=FALSE) > > Sure, there's no end of workarounds. It would just be consistent to > treat both > the x and the tz arguments as vectors. I've wondered abut that too. The function where I would like to see a dual vectorized application is 'rep'. In cases where the x argument is the same length as the 'times' or 'each' arguments I would like to see it produce a vector that is sum(each) or tume(times) long. The problem is most likely in the ambiguity of how to apply the arguments: > unlist(sapply(1:5, function(tt) rep(1:5, each=tt))) [1] 1 2 3 4 5 1 1 2 2 3 3 4 4 5 5 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 1 1 1 1 2 2 2 2 3 [40] 3 3 3 4 4 4 4 5 5 5 5 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 > mapply("rep", x=1:5, each=1:5) [[1]] [1] 1 [[2]] [1] 2 2 [[3]] [1] 3 3 3 [[4]] [1] 4 4 4 4 [[5]] [1] 5 5 5 5 5 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT From mark.heckmann at gmx.de Fri Dec 2 23:08:04 2011 From: mark.heckmann at gmx.de (Mark Heckmann) Date: Fri, 2 Dec 2011 23:08:04 +0100 Subject: [R] Sweave problem on Mac OS when using umlauts and summary() Message-ID: <94D1C064-31EA-41EA-981A-81DA7E650BCF@gmx.de> Ein eingebundener Text mit undefiniertem Zeichensatz wurde abgetrennt. Name: nicht verf?gbar URL: From jabezwuk at yahoo.co.uk Fri Dec 2 23:17:56 2011 From: jabezwuk at yahoo.co.uk (Jabez Wilson) Date: Fri, 2 Dec 2011 22:17:56 +0000 Subject: [R] Fw: calculate mean of multiple rows in a data frame In-Reply-To: Message-ID: <1322864276.97726.YahooMailClassic@web28515.mail.ukl.yahoo.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From khlam at ucsc.edu Fri Dec 2 23:16:24 2011 From: khlam at ucsc.edu (khlam) Date: Fri, 2 Dec 2011 14:16:24 -0800 (PST) Subject: [R] Imputing data Message-ID: <1322864184144-4150041.post@n4.nabble.com> So I have a very big matrix of about 900 by 400 and there are a couple of NA in the list. I have used the following functions to impute the missing data data(pc) pc.na<-pc pc.roughfix <- na.roughfix(pc.na) pc.narf <- randomForest(pc.na, na.action=na.roughfix) yet it does not replace the NA in the list. Presently I want to replace the NA with maybe the mean of the rows or columns or some type of correlation. Any help would be appreciated. -- View this message in context: http://r.789695.n4.nabble.com/Imputing-data-tp4150041p4150041.html Sent from the R help mailing list archive at Nabble.com. From mcooganj at gmail.com Fri Dec 2 23:50:27 2011 From: mcooganj at gmail.com (Matthew Johnson) Date: Sat, 3 Dec 2011 09:50:27 +1100 Subject: [R] Writing data including NAs to access using RODBC Message-ID: <-2627912397493008455@unknownmsgid> Hi, I have run into a problem writing data using RODBC. The dataframe i have read in from access includes some NAs. I have put the data into an xts object, manipulated the data, and would now like to append two columns of the manipulated data to the original table in access. I cannot append the data, nor write a new table. After some fiddling about i think that it is that the vectors i wish to append to the original dataframe /write include some NAs. Is there a work around? Thanks Matt Johnson From xie at yihui.name Fri Dec 2 23:55:32 2011 From: xie at yihui.name (Yihui Xie) Date: Fri, 2 Dec 2011 16:55:32 -0600 Subject: [R] Sweave problem on Mac OS when using umlauts and summary() In-Reply-To: <94D1C064-31EA-41EA-981A-81DA7E650BCF@gmx.de> References: <94D1C064-31EA-41EA-981A-81DA7E650BCF@gmx.de> Message-ID: This problem comes up so frequently that I have made options(useFancyQuotes=FALSE) by default in my knitr package: http://yihui.github.com/knitr/ You can also use options(useFancyQuotes='TeX'). Regards, Yihui -- Yihui Xie Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Fri, Dec 2, 2011 at 4:08 PM, Mark Heckmann wrote: > I have the following Sweave file which gets sweaved correctly. > > <<>>= > m <- lm(y1 ~x1, anscombe) > summary(m) > @ > > I include the sweaved .tex file into another .tex file via include. > When I use a single umlaut in the .snw file a warning occurs. > As a result part of the summary output is not contained in the .tex file. > > ? > <<>>= > m <- lm(y1 ~x1, anscombe) > summary(m) > @ > > You can now run (pdf)latex on 'ch1.tex' > Warnmeldungen: > 1: ?ch1.Snw? has unknown encoding: assuming Latin-1 > 2: ung?ltige Zeichenkette in Konvertierung der Ausgabe (wrong character in conversion of output) > > Interestingly, this error does NOT occur, when I omit the summary(m) statement. > > ? > <<>>= > m <- lm(y1 ~x1, anscombe) > #summary(m) > @ > > You can now run (pdf)latex on 'ch1.tex' > Warnmeldung: > ?ch1.Snw? has unknown encoding: assuming Latin-1 > > I know that I can prevent this by adding a line at the beginning of the .snw file: > > \usepackage[utf8]{inputenc} > > ? > <<>>= > m <- lm(y1 ~x1, anscombe) > summary(m) > @ > > This gets sweaved correctly without warnings: > > But this solution is not good as it is not the preamble of the .tex document where I add the usepackage line. > This will cause an error when processing the entire document with tex. > > How can I achieve the last result in another way? > I tried: > > Sweave('/Users/markheckmann/Desktop/test_sweave/ch1.Snw', encoding="UFT-8") > > But this does not work either when the usepackage line is omitted. > > I am stuck here. Can anyone help? > > TIA > Mark > > > ???????????????????????????????????? > Mark Heckmann > Blog: www.markheckmann.de > R-Blog: http://ryouready.wordpress.com > > > > > > > > > > > > ? ? ? ?[[alternative HTML version deleted]] > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > From peter.langfelder at gmail.com Sat Dec 3 00:00:03 2011 From: peter.langfelder at gmail.com (Peter Langfelder) Date: Fri, 2 Dec 2011 15:00:03 -0800 Subject: [R] Imputing data In-Reply-To: <1322864184144-4150041.post@n4.nabble.com> References: <1322864184144-4150041.post@n4.nabble.com> Message-ID: On Fri, Dec 2, 2011 at 2:16 PM, khlam wrote: > So I have a very big matrix of about 900 by 400 and there are a couple of NA > in the list. I have used the following functions to impute the missing data > > data(pc) > pc.na<-pc > pc.roughfix <- na.roughfix(pc.na) > pc.narf <- randomForest(pc.na, na.action=na.roughfix) > > > yet it does not replace the NA in the list. ?Presently I want to replace the > NA with maybe the mean of the rows or columns or some type of correlation. > > Any help would be appreciated. There are several imputation functions available in the various packages - for example, packages Hmisc and e1071 both contain a function called impute, and the package impute contains the function impute.knn for nearest neighbor imputation. HTH, Peter From mail at joeconway.com Sat Dec 3 00:43:45 2011 From: mail at joeconway.com (Joe Conway) Date: Sat, 03 Dec 2011 07:43:45 +0800 Subject: [R] R, PostgresSQL and poor performance In-Reply-To: References: Message-ID: <4ED962B1.1080703@joeconway.com> On 12/02/2011 09:46 PM, Berry, David I. wrote: > Thanks for the reply and suggestions. I've tried the RpgSQL drivers and > the results are pretty similar in terms of performance. > > The ~1.5M records I'm trying to read into R are being extracted from a > table with ~300M rows (and ~60 columns) that has been indexed on the > relevant columns and horizontally partitioned (with constraint checking > on). I do need to try and optimize the database a bit more but I don?t > think this is the cause of the performance issues. With that much data you might want to consider PL/R: http://www.joeconway.com/plr/ HTH, Joe -- Joe Conway credativ LLC: http://www.credativ.us Linux, PostgreSQL, and general Open Source Training, Service, Consulting, & 24x7 Support From anopheles123 at gmail.com Sat Dec 3 01:08:58 2011 From: anopheles123 at gmail.com (Weidong Gu) Date: Fri, 2 Dec 2011 19:08:58 -0500 Subject: [R] Imputing data In-Reply-To: References: <1322864184144-4150041.post@n4.nabble.com> Message-ID: Hi, For imputation using randomForest package, check ?rfImpute Weidong On Fri, Dec 2, 2011 at 6:00 PM, Peter Langfelder wrote: > On Fri, Dec 2, 2011 at 2:16 PM, khlam wrote: >> So I have a very big matrix of about 900 by 400 and there are a couple of NA >> in the list. I have used the following functions to impute the missing data >> >> data(pc) >> pc.na<-pc >> pc.roughfix <- na.roughfix(pc.na) >> pc.narf <- randomForest(pc.na, na.action=na.roughfix) >> >> >> yet it does not replace the NA in the list. ?Presently I want to replace the >> NA with maybe the mean of the rows or columns or some type of correlation. >> >> Any help would be appreciated. > > There are several imputation functions available in the various > packages - for example, packages Hmisc and e1071 both contain a > function called impute, and the package impute contains the function > impute.knn for nearest neighbor imputation. > > HTH, > > Peter > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From ehlers at ucalgary.ca Sat Dec 3 02:29:28 2011 From: ehlers at ucalgary.ca (Peter Ehlers) Date: Fri, 02 Dec 2011 17:29:28 -0800 Subject: [R] Plot and polygon in log scale In-Reply-To: References: Message-ID: <4ED97B78.6000308@ucalgary.ca> On 2011-12-02 13:03, Santosh wrote: > Dear Experts, > > When using "plot" and "polygon", I can change the density and angle of the > shaded area lines when plotting is done in regular scale. It does not seem > to work in 'log' scale. Any suggestions would be highly appreciated! > > below is an example: > > plot(1:10,c(1:10)^2*20,log="y") > polygon(c(3:7,7:3),c((3:7)^2*20,c(7:3)^2*10),col='grey',angle=45,dens=30) > > Warning message: > In polygon.fullhatch(xy$x[start:(end - 1)], xy$y[start:(end - 1)], : > cannot hatch with logarithmic scale active > > Regards, > Santosh It looks like density is not implemented for log scales. (There is a comment in the source file.) Perhaps a note in the help file might be useful, but I would think that nowadays most users would want colour or shades of gray anyway. Of course, you can always do the logging on the data before plotting. You'll just have to use the axis() function to print appropriate axis labels. Peter Ehlers > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From comtech.usa at gmail.com Sat Dec 3 02:38:38 2011 From: comtech.usa at gmail.com (Michael) Date: Fri, 2 Dec 2011 19:38:38 -0600 Subject: [R] Help! Big problem when using "browser()" to do R debugging? Message-ID: Hi all, Could you please help me? I am having the following weird problem when debugging R programs using "browser()": In my function, I've inserted a "browser()" in front of Step 1. My function has 3 steps and at the end of each step, it will print out the message "Step i is done"... However, after I hit when the program stopped before Step 1 and entered into the debugging mode, it not only executed the next line(i.e. the Step 1), but also all the (many) remaining lines in that function, as shown below: Browse[1]> [1] "Step 1 is done.." [1] "Step 2 is done.." [1] "Step 3 is done.." Then it automatically quited the debugging mode and when I tried to check the value of "myobj", I've got the following error message: > names(myobj) Error: object 'myobj' not found No suitable frames for recover() ---------------------------------------------------- So my question is: why did one key stroke lead it to execute all the remaining lines in that function and then "returned" from the function and quited the debugging mode? Thanks a lot! From murdoch.duncan at gmail.com Sat Dec 3 02:43:59 2011 From: murdoch.duncan at gmail.com (Duncan Murdoch) Date: Fri, 2 Dec 2011 20:43:59 -0500 Subject: [R] Help! Big problem when using "browser()" to do R debugging? In-Reply-To: References: Message-ID: <4ED97EDF.2000700@gmail.com> On 11-12-02 8:38 PM, Michael wrote: > Hi all, > > Could you please help me? > > I am having the following weird problem when debugging R programs > using "browser()": > > In my function, I've inserted a "browser()" in front of Step 1. My > function has 3 steps and at the end of each step, it will print out > the message "Step i is done"... > > However, after I hit when the program stopped before Step 1 > and entered into the debugging mode, it not only executed the next > line(i.e. the Step 1), but also all the (many) remaining lines in that > function, as shown below: > > > Browse[1]> > [1] "Step 1 is done.." > [1] "Step 2 is done.." > [1] "Step 3 is done.." > > Then it automatically quited the debugging mode and when I tried to > check the value of "myobj", I've got the following error message: > >> names(myobj) > Error: object 'myobj' not found > No suitable frames for recover() > > ---------------------------------------------------- > > So my question is: why did one key stroke lead it to execute > all the remaining lines in that function and then "returned" from the > function and quited the debugging mode? See ?browser. Duncan Murdoch From davideps at umich.edu Sat Dec 3 03:39:47 2011 From: davideps at umich.edu (David Epstein) Date: Sat, 03 Dec 2011 04:39:47 +0200 Subject: [R] side-by-side map with different geographies using spplot Message-ID: <4ED98BF3.6060509@umich.edu> Hello, I want to create side-by-side maps of similar attribute data in two different cities using a single legend. To simply display side-by-side census block group boundary (non-thematic) maps for Minneapolis & Cleveland I do the following: library(rgdal) library(sp) Minneapolis=readOGR("../Minneapolis/Census/2010/Census_BlockGroup_GEO/","tl_2010_27053_bg10") Cleveland=readOGR("../Cleveland/Census/2010/Census_BlockGroup_GEO/","tl_2010_39035_bg10") par(mfrow=c(1,2)) plot(Minneapolis) plot(Cleveland) I can display a single thematic map for a city using spplot as follows: spplot(Minneapolis,"Thematic_Data_Column") But, calling the function again for Cleveland just overwrites the window. I am unsure how to use spplot's layout tools with two different geographies. Most examples use a single geography and multiple attribute columns. Alternatively, is there a way to use "par" together with spplot to allow for multiple spplot calls? thank you, -david From worikr at gmail.com Sat Dec 3 05:03:08 2011 From: worikr at gmail.com (Worik R) Date: Sat, 3 Dec 2011 17:03:08 +1300 Subject: [R] simple lm question In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From michael.weylandt at gmail.com Sat Dec 3 05:10:18 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Fri, 2 Dec 2011 23:10:18 -0500 Subject: [R] simple lm question In-Reply-To: References: Message-ID: In your code by supplying a vector M[,"e"] you are regressing "e" against all the variables provided in the data argument, including "e" itself -- this gives the very strange regression coefficients you observe. R has no way to know that that's somehow related to the "e" it sees in the data argument. In the suggested way, lm(formula = e ~ ., data = as.data.frame(M)) e is regressed against everything that is not e and sensible results are given. Michael On Fri, Dec 2, 2011 at 11:03 PM, Worik R wrote: >> >> Use `lm` the way it is designed to be used, with a data argument: >> >> > l2 <- lm(e~. , data=as.data.frame(M)) >> > summary(l2) >> >> Call: >> lm(formula = e ~ ., data = as.data.frame(M)) >> >> > And what is the regression being done in this case? ?How are the > independent ?variables used? > > It looks like M[,5]~M[,1]+M[,2]+M[,3]+M[,4] as those are the > coefficients. ? But the results are different when I do that explicitly: > >> M <- matrix(runif(5*20), nrow=20) >> colnames(M) <- c('a', 'b', 'c', 'd', 'e') >> l1 <- lm(df[,'e']~., data=df) >> summary(l1) > > Call: > lm(formula = df[, "e"] ~ ., data = df) > > Residuals: > ? ? ? Min ? ? ? ? 1Q ? ? Median ? ? ? ? 3Q ? ? ? ?Max > -9.580e-17 -3.360e-17 -8.596e-18 ?9.114e-18 ?2.032e-16 > > Coefficients: > ? ? ? ? ? ? ?Estimate Std. Error ? ?t value Pr(>|t|) > (Intercept) -7.505e-17 ?7.158e-17 -1.048e+00 ? ?0.312 > a ? ? ? ? ? -1.653e-17 ?7.117e-17 -2.320e-01 ? ?0.820 > b ? ? ? ? ? -5.042e-17 ?5.480e-17 -9.200e-01 ? ?0.373 > c ? ? ? ? ? ?4.236e-17 ?5.774e-17 ?7.340e-01 ? ?0.475 > d ? ? ? ? ? -3.878e-17 ?4.946e-17 -7.840e-01 ? ?0.446 > e ? ? ? ? ? ?1.000e+00 ?6.083e-17 ?1.644e+16 ? <2e-16 *** > --- > Signif. codes: ?0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > > Residual standard error: 6.763e-17 on 14 degrees of freedom > Multiple R-squared: ? ? 1, ? ?Adjusted R-squared: ? ? 1 > F-statistic: 6.435e+31 on 5 and 14 DF, ?p-value: < 2.2e-16 > >> l3 <- lm(M[,5]~M[,1]+M[,2]+M[,3]+M[,4]) >> summary(l3) > > Call: > lm(formula = M[, 5] ~ M[, 1] + M[, 2] + M[, 3] + M[, 4]) > > Residuals: > ? ? Min ? ? ? 1Q ? Median ? ? ? 3Q ? ? ?Max > -0.49398 -0.14203 ?0.01588 ?0.14157 ?0.31335 > > Coefficients: > ? ? ? ? ? ?Estimate Std. Error t value Pr(>|t|) > (Intercept) ? 0.6681 ? ? 0.1859 ? 3.594 ?0.00266 ** > M[, 1] ? ? ? -0.1767 ? ? 0.2419 ?-0.730 ?0.47644 > M[, 2] ? ? ? -0.3874 ? ? 0.2135 ?-1.814 ?0.08970 . > M[, 3] ? ? ? ?0.3695 ? ? 0.2180 ? 1.695 ?0.11078 > M[, 4] ? ? ? ?0.1361 ? ? 0.2366 ? 0.575 ?0.57360 > --- > Signif. codes: ?0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > > Residual standard error: 0.2449 on 15 degrees of freedom > Multiple R-squared: 0.2988, ? ?Adjusted R-squared: 0.1119 > F-statistic: 1.598 on 4 and 15 DF, ?p-value: 0.2261 > > > cheers > Worik > > ? ? ? ?[[alternative HTML version deleted]] > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > From worikr at gmail.com Sat Dec 3 05:20:28 2011 From: worikr at gmail.com (Worik R) Date: Sat, 3 Dec 2011 17:20:28 +1300 Subject: [R] simple lm question In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From dwinsemius at comcast.net Sat Dec 3 05:41:01 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Fri, 2 Dec 2011 23:41:01 -0500 Subject: [R] simple lm question In-Reply-To: References: Message-ID: <6D2E99CF-7BAB-4084-BAC6-662DF0BC27B9@comcast.net> On Dec 2, 2011, at 11:20 PM, Worik R wrote: > Duh! Silly me! But my confusion persits: What is the regression > being > done? See below.... Please note that your "df" and "M" are undoubtedly different objects by now: > M <- matrix(runif(5*20), nrow=20) > colnames(M) <- c('a', 'b', 'c', 'd', 'e') > l1 <- lm(e~., data=as.data.frame(M)) > l1 Call: lm(formula = e ~ ., data = as.data.frame(M)) Coefficients: (Intercept) a b c d 0.40139 -0.15032 -0.06242 0.13139 0.23905 > l3 <- lm(M[,5]~M[,1]+M[,2]+M[,3]+M[,4]) > l3 Call: lm(formula = M[, 5] ~ M[, 1] + M[, 2] + M[, 3] + M[, 4]) Coefficients: (Intercept) M[, 1] M[, 2] M[, 3] M[, 4] 0.40139 -0.15032 -0.06242 0.13139 0.23905 As expected. -- David. > > On Sat, Dec 3, 2011 at 5:10 PM, R. Michael Weylandt < > michael.weylandt at gmail.com> wrote: > >> In your code by supplying a vector M[,"e"] you are regressing "e" >> against all the variables provided in the data argument, including >> "e" >> itself -- this gives the very strange regression coefficients you >> observe. R has no way to know that that's somehow related to the "e" >> it sees in the data argument. >> > >> In the suggested way, >> >> lm(formula = e ~ ., data = as.data.frame(M)) >> >> e is regressed against everything that is not e and sensible >> results are >> given. >> > > But still 'l1 <- lm(e~., data=df)' is not the same as 'l3 <- > lm(M[,5]~M[,1]+M[,2]+M[,3]+M[,4])' > >> M <- matrix(runif(5*20), nrow=20) >> colnames(M) <- c('a', 'b', 'c', 'd', 'e') >> l1 <- lm(e~., data=df) >> summary(l1) > > Call: > lm(formula = e ~ ., data = df) > > Residuals: > Min 1Q Median 3Q Max > -0.38343 -0.21367 0.03067 0.13757 0.49080 > > Coefficients: > Estimate Std. Error t value Pr(>|t|) > (Intercept) 0.28521 0.29477 0.968 0.349 > a 0.09283 0.30112 0.308 0.762 > b 0.23921 0.22425 1.067 0.303 > c -0.16027 0.24154 -0.664 0.517 > d 0.24025 0.20054 1.198 0.250 > > Residual standard error: 0.2871 on 15 degrees of freedom > Multiple R-squared: 0.1602, Adjusted R-squared: -0.06375 > F-statistic: 0.7153 on 4 and 15 DF, p-value: 0.5943 > >> l3 <- lm(M[,5]~M[,1]+M[,2]+M[,3]+M[,4]) >> summary(l3) > > Call: > lm(formula = M[, 5] ~ M[, 1] + M[, 2] + M[, 3] + M[, 4]) > > Residuals: > Min 1Q Median 3Q Max > -0.36355 -0.22679 -0.01202 0.18462 0.37377 > > Coefficients: > Estimate Std. Error t value Pr(>|t|) > (Intercept) 0.76972 0.24501 3.142 0.00672 ** > M[, 1] -0.23830 0.24123 -0.988 0.33890 > M[, 2] -0.02046 0.21958 -0.093 0.92699 > M[, 3] -0.29518 0.22559 -1.308 0.21040 > M[, 4] -0.31545 0.24570 -1.284 0.21866 > --- > Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > > Residual standard error: 0.2668 on 15 degrees of freedom > Multiple R-squared: 0.2762, Adjusted R-squared: 0.08317 > F-statistic: 1.431 on 4 and 15 DF, p-value: 0.272 > >> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT From hcatbr at yahoo.co.in Sat Dec 3 05:47:36 2011 From: hcatbr at yahoo.co.in (HC) Date: Fri, 2 Dec 2011 20:47:36 -0800 (PST) Subject: [R] Downloading tab separated data from internet Message-ID: <1322887656326-4152318.post@n4.nabble.com> Hi all, I am trying to download some tab separated data from the internet. The data is not available directly at the URL that could be known apriori. There is an intermediate form where start and end dates have to be given to get to the required page. For example, I want to download data for a station 03015795. The form for this station is at: http://ida.water.usgs.gov/ida/available_records.cfm?sn=03015795 I could get the start date and end date from this form using: # # Specifying station and reading from the opening form stn<-"03015795" myurl<-paste("http://ida.water.usgs.gov/ida/available_records.cfm?sn=",stn,sep="") mypage1 = readLines(myurl) # Getting the start and end dates mypattern = '([^<]*)' datalines = grep(mypattern, mypage1[124], value=TRUE) getexpr = function(s,g)substring(s,g,g+attr(g,'match.length')-1) gg = gregexpr(mypattern, datalines) matches = mapply(getexpr,datalines,gg) result = gsub(mypattern,'\\1',matches) names(result)=NULL mydates<-result[1:2] I want to know how I can feed these start and end dates to the form and execute the button to go to the data page and then to download the data, either as displayed in the browser or by saving as a file. Any help on this is most appreciated. Thanks. HC -- View this message in context: http://r.789695.n4.nabble.com/Downloading-tab-separated-data-from-internet-tp4152318p4152318.html Sent from the R help mailing list archive at Nabble.com. From manoharan.arun at gmail.com Sat Dec 3 04:25:26 2011 From: manoharan.arun at gmail.com (stillerfan) Date: Fri, 2 Dec 2011 19:25:26 -0800 (PST) Subject: [R] Problem installing Rtools Message-ID: <1322882726581-4152013.post@n4.nabble.com> I'm a new user to R and recently installed R 2.14 for Windows 7 (64 bit). I have downloaded and ran Rtools 2.14 but do not see any new packages in the install packages section of R. I installed Rtools in a subdirectory to the /library/ directory. Does anyone have any idea what I could be doing wrong? Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Problem-installing-Rtools-tp4152013p4152013.html Sent from the R help mailing list archive at Nabble.com. From holland.aggie at gmail.com Sat Dec 3 05:51:05 2011 From: holland.aggie at gmail.com (James Holland) Date: Fri, 2 Dec 2011 22:51:05 -0600 Subject: [R] Reading multiple text files and then combining into a dataframe In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From worikr at gmail.com Sat Dec 3 06:05:26 2011 From: worikr at gmail.com (Worik R) Date: Sat, 3 Dec 2011 18:05:26 +1300 Subject: [R] simple lm question In-Reply-To: <6D2E99CF-7BAB-4084-BAC6-662DF0BC27B9@comcast.net> References: <6D2E99CF-7BAB-4084-BAC6-662DF0BC27B9@comcast.net> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From akpbond007 at gmail.com Sat Dec 3 08:06:50 2011 From: akpbond007 at gmail.com (arunkumar1111) Date: Fri, 2 Dec 2011 23:06:50 -0800 (PST) Subject: [R] help in removal of fixed pattern Message-ID: <1322896010158-4152524.post@n4.nabble.com> Hi I have column name as given below If the variable is in log(X1 + 1) pattern it should be removed and i need only X1 Input log(x1 + 1) x2 log(X3 +1) Expected Output X1 X2 X3 Please help me -- View this message in context: http://r.789695.n4.nabble.com/help-in-removal-of-fixed-pattern-tp4152524p4152524.html Sent from the R help mailing list archive at Nabble.com. From nevil.amos at gmail.com Sat Dec 3 08:26:00 2011 From: nevil.amos at gmail.com (Nevil Amos) Date: Sat, 3 Dec 2011 18:26:00 +1100 Subject: [R] partial mantel tests in ecodist with intential NA values. Message-ID: <6371C695-933D-49CE-875B-7DA23CAE28DD@gmail.com> I would like to perform partial mantel tests on only within group values, with "between group" values assigned to NA. This is possible in package ncf partial.mantel.test, however this sues a different permutation to that used in ecodist.ecodist will not accept data with NA values, returning a "matrix is not square error. is it possible to perform this test in ecodist? many thanks Nevil Amos > library(ecodist) > library(ncf) > x<-sample(1:1000,20) > y<-sample(1:1000,20) > z<-sample(1:1000,20) > M1<-as.matrix( distance(x)) > M2 <-as.matrix( distance(y )) > M3<-as.matrix( distance(z )) > D1<-(lower(M1)) > D2<-(lower(M2)) > D3<-(lower(M3)) > mantel(D1 ~ D2+D3, nperm=1000) mantelr pval1 pval2 pval3 llim.2.5% ulim.97.5% 0.09014696 0.10300000 0.89800000 0.18400000 0.01857311 0.18468621 > partial.mantel.test(M1,M2,M3,quiet=T) $MantelR r12 r13 r23 r12.3 r13.2 0.08977575 0.02170997 -0.01561346 0.09014696 0.02320821 $p [1] 0.09590410 0.30769231 0.47552448 0.09490509 0.30169830 $call [1] "partial.mantel.test(M1 = M1, M2 = M2, M3 = M3, quiet = T)" attr(,"class") [1] "partial.Mantel" > M1[1:10,11:20]<-NA > M1[11:20,1:10]<-NA > D1<-(lower(M1)) > mantel(D1 ~ D2+D3, nperm=1000) Error in mantel(D1 ~ D2 + D3, nperm = 1000) : Matrix not square. > partial.mantel.test(M1,M2,M3,quiet=T) $MantelR r12 r13 r23 r12.3 r13.2 0.054906562 0.003446670 -0.015613460 0.054967403 0.004310979 $p [1] 0.2837163 0.4275724 0.4555445 0.2857143 0.4235764 $call [1] "partial.mantel.test(M1 = M1, M2 = M2, M3 = M3, quiet = T)" attr(,"class") [1] "partial.Mantel" Warning message: In partial.mantel.test(M1, M2, M3, quiet = T) : Missing values exist; Pairwise deletion will be used From ripley at stats.ox.ac.uk Sat Dec 3 09:09:05 2011 From: ripley at stats.ox.ac.uk (Prof Brian Ripley) Date: Sat, 03 Dec 2011 08:09:05 +0000 Subject: [R] Downloading tab separated data from internet In-Reply-To: <1322887656326-4152318.post@n4.nabble.com> References: <1322887656326-4152318.post@n4.nabble.com> Message-ID: <4ED9D921.3080300@stats.ox.ac.uk> AFAICS what you mean is 'how can I fill in an HTML form using R'. Answer: use package RCurl. Do study the posting guide: none of the 'at a minimum' information was given here. On 03/12/2011 04:47, HC wrote: > Hi all, > > I am trying to download some tab separated data from the internet. The data > is not available directly at the URL that could be known apriori. There is > an intermediate form where start and end dates have to be given to get to > the required page. > > For example, I want to download data for a station 03015795. The form for > this station is at: > > http://ida.water.usgs.gov/ida/available_records.cfm?sn=03015795 > > I could get the start date and end date from this form using: > > # > # Specifying station and reading from the opening form > stn<-"03015795" > myurl<-paste("http://ida.water.usgs.gov/ida/available_records.cfm?sn=",stn,sep="") > mypage1 = readLines(myurl) > > # Getting the start and end dates > mypattern = '([^<]*)' > datalines = grep(mypattern, mypage1[124], value=TRUE) > getexpr = function(s,g)substring(s,g,g+attr(g,'match.length')-1) > gg = gregexpr(mypattern, datalines) > matches = mapply(getexpr,datalines,gg) > result = gsub(mypattern,'\\1',matches) > names(result)=NULL > mydates<-result[1:2] > > I want to know how I can feed these start and end dates to the form and > execute the button to go to the data page and then to download the data, > either as displayed in the browser or by saving as a file. > > Any help on this is most appreciated. > > Thanks. > HC -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 From landronimirc at gmail.com Sat Dec 3 09:15:56 2011 From: landronimirc at gmail.com (Liviu Andronic) Date: Sat, 3 Dec 2011 09:15:56 +0100 Subject: [R] Help! Big problem when using "browser()" to do R debugging? In-Reply-To: References: Message-ID: On Sat, Dec 3, 2011 at 2:38 AM, Michael wrote: > Hi all, > > Could you please help me? > > I am having the following weird problem when debugging R programs > using "browser()": > > In my function, I've inserted a "browser()" in front of Step 1. My > function has 3 steps and at the end of each step, it will print out > the message "Step i is done"... > > However, after I hit when the program stopped before Step 1 > and entered into the debugging mode, it not only executed the next > line(i.e. the Step 1), but also all the (many) remaining lines in that > function, as shown below: > > > Browse[1]> > [1] "Step 1 is done.." > [1] "Step 2 is done.." > [1] "Step 3 is done.." > > Then it automatically quited the debugging mode and when I tried to > check the value of "myobj", I've got the following error message: > >> names(myobj) > Error: object 'myobj' not found > No suitable frames for recover() > > ---------------------------------------------------- > > So my question is: why did one key stroke lead it to execute > all the remaining lines in that function and then "returned" from the > function and quited the debugging mode? > As soon as you get into 'debug' mode, type 'n', hit , then you can simply hit to evaluate the fun step by step. To exit the step-by-step, type 'c' and hit enter: this will evaluate the rest of the function. Regards Liviu > Thanks a lot! > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail From murdoch.duncan at gmail.com Sat Dec 3 11:10:25 2011 From: murdoch.duncan at gmail.com (Duncan Murdoch) Date: Sat, 03 Dec 2011 05:10:25 -0500 Subject: [R] Problem installing Rtools In-Reply-To: <1322882726581-4152013.post@n4.nabble.com> References: <1322882726581-4152013.post@n4.nabble.com> Message-ID: <4ED9F591.5050109@gmail.com> On 11-12-02 10:25 PM, stillerfan wrote: > I'm a new user to R and recently installed R 2.14 for Windows 7 (64 bit). I > have downloaded and ran Rtools 2.14 but do not see any new packages in the > install packages section of R. I installed Rtools in a subdirectory to the > /library/ directory. Does anyone have any idea what I could be doing wrong? > Rtools doesn't contain R packages, it contains various compilers and tools that you could use to build R and R packages. So you should install it in its own directory. I usually use c:/Rtools. Duncan Murdoch From jim at bitwrit.com.au Sat Dec 3 12:16:32 2011 From: jim at bitwrit.com.au (Jim Lemon) Date: Sat, 03 Dec 2011 22:16:32 +1100 Subject: [R] Project local libraries (reproducible research) In-Reply-To: References: Message-ID: <4EDA0510.9080003@bitwrit.com.au> On 12/03/2011 06:04 AM, Hadley Wickham wrote: > Hi all, > > I was wondering if any one had scripts that they could share for > capturing the current version of R packages used for a project. I'm > interested in creating a project local library so that you're safe if > someone (e.g. the ggplot2 author) updates a package you're relying on > and breaks your code. I could fairly easily hack together, but I was > wondering if any one had any neat scripts they'd care to share. > Hi Hadley, This makes quite a few assumptions, but I would build a list of packages called in R scripts: # get all calls to library or require in a subdirectory of scripts packagestrings<-c(system("grep library *.R",intern=TRUE), system("grep require *.R",intern=TRUE)) # get the unique package names packagenames<-unique(sapply(strsplit(packagestrings,"[()]"),"[",2)) # get the information on all installed packages in the system installedpackages<-installed.packages() # get the indices of the packages used in the subdirectory whichpackages<-which(match(rownames(installedpackages),packagenames,0)>0) # get the version information for each used package installedpackages[whichpackages,"Built"] Jim From mentor_ at gmx.net Sat Dec 3 12:43:26 2011 From: mentor_ at gmx.net (syrvn) Date: Sat, 3 Dec 2011 03:43:26 -0800 (PST) Subject: [R] Data alignment Message-ID: <1322912606118-4153024.post@n4.nabble.com> Hello! I have a data.frame which looks like: Name - Value A - 400 A - 300 B - 200 B - 350 C - 500 C - 350 D - 450 D - 600 E - 700 E - 750 F - 630 F - 650 I want to add another column where all A,B should get an index 1, all C,D an index of 2 and all E,F an index of 3 so that the data.frame looks like: ID - Name - Value 1 - A - 400 1 - A - 300 1 - B - 200 1 - B - 350 2 - C - 500 2 - C - 350 2 - D - 450 2 - D - 600 3 - E - 700 3 - E - 750 3 - F - 630 3 - F - 650 My data.frame is quite big so I cannot add all values by hand. Cheers -- View this message in context: http://r.789695.n4.nabble.com/Data-alignment-tp4153024p4153024.html Sent from the R help mailing list archive at Nabble.com. From Roger.bivand at nhh.no Sat Dec 3 12:50:03 2011 From: Roger.bivand at nhh.no (Roger Bivand) Date: Sat, 3 Dec 2011 11:50:03 +0000 Subject: [R] side-by-side map with different geographies using spplot References: <4ED98BF3.6060509@umich.edu> Message-ID: David Epstein umich.edu> writes: > > Hello, > > I want to create side-by-side maps of similar attribute data in two > different cities using a single legend. > > To simply display side-by-side census block group boundary > (non-thematic) maps for Minneapolis & Cleveland I do the following: > .... > > I can display a single thematic map for a city using spplot as follows: > > spplot(Minneapolis,"Thematic_Data_Column") > The spplot function uses lattice graphics, so you may use the standard methods for the "trellis" objects that it returns. If you did something like: sp_out_Minneapolis <- spplot(Minneapolis, "your_var") print(sp_out_Minneapolis, split=c(1, 1, 2, 1), more=TRUE) sp_out_Cleveland <- spplot(Cleveland, "your_var") print(sp_out_,Cleveland split=c(2, 1, 2, 1), more=FALSE) you will get some of the way there. If in addition you would like only one legend using the same breaks and colours, you'll need to use appropriate arguments to spplot() in both calls to handle this. It may be worth considering posting queries of this kind on R-sig-geo, as response may be forthcoming more quickly there. Hope this helps, Roger > > thank you, > -david > > From sarah.goslee at gmail.com Sat Dec 3 13:01:59 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Sat, 3 Dec 2011 07:01:59 -0500 Subject: [R] partial mantel tests in ecodist with intential NA values. In-Reply-To: <6371C695-933D-49CE-875B-7DA23CAE28DD@gmail.com> References: <6371C695-933D-49CE-875B-7DA23CAE28DD@gmail.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From sarah.goslee at gmail.com Sat Dec 3 13:06:39 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Sat, 3 Dec 2011 07:06:39 -0500 Subject: [R] Data alignment In-Reply-To: <1322912606118-4153024.post@n4.nabble.com> References: <1322912606118-4153024.post@n4.nabble.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From sarah.goslee at gmail.com Sat Dec 3 13:12:11 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Sat, 3 Dec 2011 07:12:11 -0500 Subject: [R] help in removal of fixed pattern In-Reply-To: <1322896010158-4152524.post@n4.nabble.com> References: <1322896010158-4152524.post@n4.nabble.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From jholtman at gmail.com Sat Dec 3 13:15:34 2011 From: jholtman at gmail.com (jim holtman) Date: Sat, 3 Dec 2011 07:15:34 -0500 Subject: [R] Data alignment In-Reply-To: References: <1322912606118-4153024.post@n4.nabble.com> Message-ID: try this: > match(x$Name> x <- read.table(text = "Name - Value + A - 400 + A - 300 + B - 200 + B - 350 + C - 500 + C - 350 + D - 450 + D - 600 + E - 700 + E - 750 + F - 630 + F - 650", header = TRUE, as.is = TRUE) > map <- data.frame(key = c("A", "B", "C", "D", "E", "F") + , value = c( 1, 1, 2, 2, 3, 3) + , stringsAsFactors = FALSE + ) > x$ID <- map$value[match(x$Name, map$key)] > x Name X. Value ID 1 A - 400 1 2 A - 300 1 3 B - 200 1 4 B - 350 1 5 C - 500 2 6 C - 350 2 7 D - 450 2 8 D - 600 2 9 E - 700 3 10 E - 750 3 11 F - 630 3 12 F - 650 3 On Sat, Dec 3, 2011 at 7:06 AM, Sarah Goslee wrote: > I doubt your data frame looks like that, with all the -, but regardless you > can use ifelse() to construct your column. > > Sarah > > On Saturday, December 3, 2011, syrvn wrote: >> Hello! >> >> I have a data.frame which looks like: >> >> Name - Value >> A - 400 >> A - 300 >> B - 200 >> B - 350 >> C - 500 >> C - 350 >> D - 450 >> D - 600 >> E - 700 >> E - 750 >> F - 630 >> F - 650 >> >> I want to add another column where all A,B should get an index 1, all C,D > an >> index of 2 and all E,F an index of 3 so that the data.frame looks like: >> >> ID - Name - Value >> 1 - A - 400 >> 1 - A - 300 >> 1 - B - 200 >> 1 - B - 350 >> 2 - C - 500 >> 2 - C - 350 >> 2 - D - 450 >> 2 - D - 600 >> 3 - E - 700 >> 3 - E - 750 >> 3 - F - 630 >> 3 - F - 650 >> >> My data.frame is quite big so I cannot add all values by hand. >> >> >> Cheers >> >> >> >> >> -- >> View this message in context: > http://r.789695.n4.nabble.com/Data-alignment-tp4153024p4153024.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > -- > Sarah Goslee > http://www.stringpage.com > http://www.sarahgoslee.com > http://www.functionaldiversity.org > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. From jholtman at gmail.com Sat Dec 3 13:22:42 2011 From: jholtman at gmail.com (jim holtman) Date: Sat, 3 Dec 2011 07:22:42 -0500 Subject: [R] Reading multiple text files and then combining into a dataframe In-Reply-To: References: Message-ID: Does this do it for you: > #Creating example data in similar format to data I have > sub <- rep(1,10) > trial <- seq(1,10,1) > size <- rep(3,10) > shortest <- rep(444,10) > startlab <- rep(444,10) > endlab <- rep(444,10) > startconf <- rep(444,10) > endconf <- rep(444,10) > steps <- sample(1:30,10) > time <- sample(1:300,10) > > #creating example of text file and saving into a shared director with other txt files > > subject1 <- + cbind(sub,trial,size,shortest,startlab,endlab,startconf,endconf,steps,time) > write.table(subject1, "/temp/subject1.txt", sep=" ") > > #2nd example of same text file > sub <- rep(2,10) > trial <- seq(1,10,1) > size <- rep(3,10) > shortest <- rep(444,10) > startlab <- rep(444,10) > endlab <- rep(444,10) > startconf <- rep(444,10) > endconf <- rep(444,10) > steps <- sample(1:30,10) > time <- sample(1:300,10) > > subject1 <- + cbind(sub,trial,size,shortest,startlab,endlab,startconf,endconf,steps,time) > write.table(subject1, "/temp/subject2.txt", sep=" ") > > > setwd("/temp") > > #Getting list of file names > file_name <- list.files(pattern="subject*") > > mydata <- lapply (file_name, read.table, sep=" ", header=T, row.names=NULL) > > # rbind to dataframe > mydf <- do.call(rbind, mydata) > > # or use the plyr package > require(plyr) > mydf.1 <- ldply(file_name, read.table, sep = ' ', header = TRUE, row.names = NULL) > > str(mydf) 'data.frame': 20 obs. of 11 variables: $ row.names: chr "1" "2" "3" "4" ... $ sub : int 1 1 1 1 1 1 1 1 1 1 ... $ trial : int 1 2 3 4 5 6 7 8 9 10 ... $ size : int 3 3 3 3 3 3 3 3 3 3 ... $ shortest : int 444 444 444 444 444 444 444 444 444 444 ... $ startlab : int 444 444 444 444 444 444 444 444 444 444 ... $ endlab : int 444 444 444 444 444 444 444 444 444 444 ... $ startconf: int 444 444 444 444 444 444 444 444 444 444 ... $ endconf : int 444 444 444 444 444 444 444 444 444 444 ... $ steps : int 10 28 20 18 4 21 5 3 8 7 ... $ time : int 225 188 205 189 103 227 148 221 275 14 ... > str(mydf.1) 'data.frame': 20 obs. of 11 variables: $ row.names: chr "1" "2" "3" "4" ... $ sub : int 1 1 1 1 1 1 1 1 1 1 ... $ trial : int 1 2 3 4 5 6 7 8 9 10 ... $ size : int 3 3 3 3 3 3 3 3 3 3 ... $ shortest : int 444 444 444 444 444 444 444 444 444 444 ... $ startlab : int 444 444 444 444 444 444 444 444 444 444 ... $ endlab : int 444 444 444 444 444 444 444 444 444 444 ... $ startconf: int 444 444 444 444 444 444 444 444 444 444 ... $ endconf : int 444 444 444 444 444 444 444 444 444 444 ... $ steps : int 10 28 20 18 4 21 5 3 8 7 ... $ time : int 225 188 205 189 103 227 148 221 275 14 ... > On Fri, Dec 2, 2011 at 11:51 PM, James Holland wrote: > I have a multiple text files, separated by a single space, that I need to > combine into a single data.frame. ?Below is the track I'm on using > list.files to capture the names of the files and then lapply with > read.table. ?But I run into problems making a usable dataframe out of the > data. > > > #Creating example data in similar format to data I have > sub <- rep(1,10) > trial <- seq(1,10,1) > size <- rep(3,10) > shortest <- rep(444,10) > startlab <- rep(444,10) > endlab <- rep(444,10) > startconf <- rep(444,10) > endconf <- rep(444,10) > steps <- sample(1:30,10) > time <- sample(1:300,10) > > #creating example of text file and saving into a shared director with other > txt files > > subject1 <- > cbind(sub1,trial,size,shortest,startlab,endlab,startconf,endconf,steps,time) > write.table(subject1, "C:Folder/R/subject1.txt", sep=" ") > > #2nd example of same text file > sub <- rep(2,10) > trial <- seq(1,10,1) > size <- rep(3,10) > shortest <- rep(444,10) > startlab <- rep(444,10) > endlab <- rep(444,10) > startconf <- rep(444,10) > endconf <- rep(444,10) > steps <- sample(1:30,10) > time <- sample(1:300,10) > > subject1 <- > cbind(sub1,trial,size,shortest,startlab,endlab,startconf,endconf,steps,time) > write.table(subject1, "C:Folder/R/subject2.txt", sep=" ") > > > setwd("C:Folder/R/") > > #Getting list of file names > file_name <- list.files(pattern="subject*") > > mydata <- lapply (file_name, read.table, sep=" ", header=T, row.names=NULL) > > > > Thank you, > James > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. From mark.heckmann at gmx.de Sat Dec 3 13:30:12 2011 From: mark.heckmann at gmx.de (Mark Heckmann) Date: Sat, 3 Dec 2011 13:30:12 +0100 Subject: [R] Sweave problem on Mac OS when using umlauts and summary() In-Reply-To: References: <94D1C064-31EA-41EA-981A-81DA7E650BCF@gmx.de> Message-ID: <4B251308-61D9-4DBE-B745-4CC2BBC073DE@gmx.de> Ein eingebundener Text mit undefiniertem Zeichensatz wurde abgetrennt. Name: nicht verf?gbar URL: From mentor_ at gmx.net Sat Dec 3 13:33:07 2011 From: mentor_ at gmx.net (syrvn) Date: Sat, 3 Dec 2011 04:33:07 -0800 (PST) Subject: [R] Data alignment In-Reply-To: References: <1322912606118-4153024.post@n4.nabble.com> Message-ID: <1322915587713-4153112.post@n4.nabble.com> Thanks for your suggestions. I will try them. The "-" in my original post was actually only there to serve as a separator so that it is easier for you to see the data structure but apparently it rather confused you... sorry :) -- View this message in context: http://r.789695.n4.nabble.com/Data-alignment-tp4153024p4153112.html Sent from the R help mailing list archive at Nabble.com. From Mintewab.Bezabih at economics.gu.se Sat Dec 3 13:03:30 2011 From: Mintewab.Bezabih at economics.gu.se (Mintewab Bezabih) Date: Sat, 3 Dec 2011 13:03:30 +0100 Subject: [R] problems using the thin plate spline method Message-ID: <4B46FB7EED800046A5952FCFA92D3BA0347DF578CD@HGUMAIL6.hgu.gu.se> Dear R users, I am a beginner in R trying to apply the thin plate spline method to my climate data. I used the example in R to do so, and the lines seem to run fine ( I am not getting errors) but I am not getting any output in the form of graph or anything. I got a warning message saying that 'surface extends beyond box'. Any help is much appreciated. thanks minti From hcatbr at yahoo.co.in Sat Dec 3 13:06:38 2011 From: hcatbr at yahoo.co.in (HC) Date: Sat, 3 Dec 2011 04:06:38 -0800 (PST) Subject: [R] Downloading tab separated data from internet In-Reply-To: <1322887656326-4152318.post@n4.nabble.com> References: <1322887656326-4152318.post@n4.nabble.com> Message-ID: <1322913998408-4153063.post@n4.nabble.com> Thanks for your reply. I tried to use the postForm function of RCurl as below but do not have much clue as to how to go further with what it does. library(RCurl) stn<-"03015795" myurl<-paste("http://ida.water.usgs.gov/ida/available_records.cfm?sn=",stn,sep="") mypage1 = readLines(myurl) # Getting the start and end dates mypattern = '([^<]*)' datalines = grep(mypattern, mypage1[124], value=TRUE) getexpr = function(s,g)substring(s,g,g+attr(g,'match.length')-1) gg = gregexpr(mypattern, datalines) matches = mapply(getexpr,datalines,gg) result = gsub(mypattern,'\\1',matches) names(result)=NULL mydates<-result[1:2] result = postForm(myurl,fromdate=mydates[1], todate=mydates[2],rtype="Save to File", submit1="Retrieve Data") I tried to read the RCurl's documentation but do not know what functions I should be using. Are there any examples available that could be helpful. Could you point me to those please. Thanks for the help. HC -- View this message in context: http://r.789695.n4.nabble.com/Downloading-tab-separated-data-from-internet-tp4152318p4153063.html Sent from the R help mailing list archive at Nabble.com. From mentor_ at gmx.net Sat Dec 3 14:41:07 2011 From: mentor_ at gmx.net (syrvn) Date: Sat, 3 Dec 2011 05:41:07 -0800 (PST) Subject: [R] replace values Message-ID: <1322919667580-4153301.post@n4.nabble.com> Hello, imagine the following data.frame: ID name 1 *_A 2 *_A 3 *_B 4 *_B * = can be any pattern I want to replace every row which ends with _A by 1 and every row which ends by _B with a 0 so that the data.frame looks like the following: ID name 1 1 2 1 3 0 4 0 Which function do I use best to achieve this? Cheers, Syrvn -- View this message in context: http://r.789695.n4.nabble.com/replace-values-tp4153301p4153301.html Sent from the R help mailing list archive at Nabble.com. From dwinsemius at comcast.net Sat Dec 3 15:33:17 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Sat, 3 Dec 2011 09:33:17 -0500 Subject: [R] replace values In-Reply-To: <1322919667580-4153301.post@n4.nabble.com> References: <1322919667580-4153301.post@n4.nabble.com> Message-ID: <3D879875-E506-4126-BCE5-46330B4A12BA@comcast.net> On Dec 3, 2011, at 8:41 AM, syrvn wrote: > Hello, > > > imagine the following data.frame: > > ID name > 1 *_A > 2 *_A > 3 *_B > 4 *_B > > * = can be any pattern > > I want to replace every row which ends with _A by 1 and every row > which ends > by _B with a 0 You can use grep(patt, x, value=TRUE) to return vlaues that can be used in the prior answers to your earlier question today. I would have worked it out and tested the strategy, but you continue to fail to produce workable examples.... and then apologize that people are "confused" by them. We are NOT confused... only annoyed ... that you fail to use dput() or code for constructing workable code. -- David. > > so that the data.frame looks like the following: > > ID name > 1 1 > 2 1 > 3 0 > 4 0 > > > Which function do I use best to achieve this? > > Cheers, > Syrvn > > > > -- > View this message in context: http://r.789695.n4.nabble.com/replace-values-tp4153301p4153301.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT From manoharan.arun at gmail.com Sat Dec 3 14:59:10 2011 From: manoharan.arun at gmail.com (stillerfan) Date: Sat, 3 Dec 2011 05:59:10 -0800 (PST) Subject: [R] Problem installing Rtools In-Reply-To: <4ED9F591.5050109@gmail.com> References: <1322882726581-4152013.post@n4.nabble.com> <4ED9F591.5050109@gmail.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From jdnewmil at dcn.davis.ca.us Sat Dec 3 17:45:02 2011 From: jdnewmil at dcn.davis.ca.us (Jeff Newmiller) Date: Sat, 03 Dec 2011 08:45:02 -0800 Subject: [R] problems using the thin plate spline method In-Reply-To: <4B46FB7EED800046A5952FCFA92D3BA0347DF578CD@HGUMAIL6.hgu.gu.se> References: <4B46FB7EED800046A5952FCFA92D3BA0347DF578CD@HGUMAIL6.hgu.gu.se> Message-ID: I can tell that you are puzzled and confused. Unfortunately, I am not psychic, so I cannot tell what you did, and therefore cannot tell where you went astray. The solution is for you to read the posting guide mentioned at the bottom of every R-help message. Spend a little time to create a small bit of data like yours if your actual data is large (subset and dput are useful for this). Remember to include the output of sessionInfo, and so on. Many times you are likely to find the answer yourself by going through these steps, but they are essential for communication. Good luck. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN: Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. Mintewab Bezabih wrote: >Dear R users, > >I am a beginner in R trying to apply the thin plate spline method to my >climate data. I used the example in R to do so, and the lines seem to >run fine ( I am not getting errors) but I am not getting any output in >the form of graph or anything. I got a warning message saying that >'surface extends beyond box'. > >Any help is much appreciated. >thanks >minti >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. From martin2005z at yahoo.com Sat Dec 3 19:10:38 2011 From: martin2005z at yahoo.com (Martin Zonyrah) Date: Sat, 3 Dec 2011 10:10:38 -0800 (PST) Subject: [R] Iteration in R Message-ID: <1322935838.52212.YahooMailNeo@web121702.mail.ne1.yahoo.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From momadou at yahoo.fr Sat Dec 3 19:19:19 2011 From: momadou at yahoo.fr (Komine) Date: Sat, 3 Dec 2011 10:19:19 -0800 (PST) Subject: [R] Problem with loop In-Reply-To: References: <1322846156594-4148083.post@n4.nabble.com> Message-ID: <1322936359572-4154147.post@n4.nabble.com> Hi, Thank Michael for your help. Komine -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-loop-tp4148083p4154147.html Sent from the R help mailing list archive at Nabble.com. From hadley at rice.edu Sat Dec 3 20:10:04 2011 From: hadley at rice.edu (Hadley Wickham) Date: Sat, 3 Dec 2011 13:10:04 -0600 Subject: [R] Counting the occurences of a charater within a string In-Reply-To: <974A7A659261804FA954D102472EA32E03D37A85@NYCEMBP01101.ad.insidemedia.net> References: <974A7A659261804FA954D102472EA32E03D37A85@NYCEMBP01101.ad.insidemedia.net> Message-ID: On Thu, Dec 1, 2011 at 10:32 AM, Douglas Esneault wrote: > I am new to R but am experienced SAS user and I was hoping to get some help on counting the occurrences of a character within a string at a row level. > > My dataframe, x, ?is structured as below: > > Col1 > abc/def > ghi/jkl/mno > > I found this code on the board but it counts all occurrences of "/" in the dataframe. > > chr.pos <- which(unlist(strsplit(x,NULL))=='/') > chr.count <- length(chr.pos) > chr.count > [1] 3 > > I'd like to append a column, say cnt, that has the count of "/" for each row. Here's an easy way from stringr: library(stringr) str_count( c("abc/def", "ghi/jkl/mno"), "/") # [1] 1 2 Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ From dwinsemius at comcast.net Sat Dec 3 20:11:02 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Sat, 3 Dec 2011 14:11:02 -0500 Subject: [R] Iteration in R In-Reply-To: <1322935838.52212.YahooMailNeo@web121702.mail.ne1.yahoo.com> References: <1322935838.52212.YahooMailNeo@web121702.mail.ne1.yahoo.com> Message-ID: <8B0DAD2A-966F-4BB5-B05E-D27FE71E8C34@comcast.net> On Dec 3, 2011, at 1:10 PM, Martin Zonyrah wrote: > Hi, > I need help. I am trying to iterate this command x <- rnorm(100, > 1.0, 2.0) one hundred times in R but I don't seem to have a clue. ?replicate > == David Winsemius, MD West Hartford, CT From michael.weylandt at gmail.com Sat Dec 3 20:11:46 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Sat, 3 Dec 2011 14:11:46 -0500 Subject: [R] Iteration in R In-Reply-To: <1322935838.52212.YahooMailNeo@web121702.mail.ne1.yahoo.com> References: <1322935838.52212.YahooMailNeo@web121702.mail.ne1.yahoo.com> Message-ID: ? replicate or a for loop or do all one hundred simulations at once x <- matrix(rnorm(100^2, 1, 2), 100) It's going to depend on what you want to do with the numbers. Michael On Sat, Dec 3, 2011 at 1:10 PM, Martin Zonyrah wrote: > Hi, > I need help. I am trying to iterate this command? x <- rnorm(100, 1.0, 2.0) one hundred times in R but I don't seem to have a clue. > Can anyone help? > Your help is very much appreciated. > > Martin > > ? ? ? ?[[alternative HTML version deleted]] > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > From djandrija at gmail.com Sat Dec 3 20:16:52 2011 From: djandrija at gmail.com (andrija djurovic) Date: Sat, 3 Dec 2011 20:16:52 +0100 Subject: [R] Iteration in R In-Reply-To: <1322935838.52212.YahooMailNeo@web121702.mail.ne1.yahoo.com> References: <1322935838.52212.YahooMailNeo@web121702.mail.ne1.yahoo.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From bps0002 at auburn.edu Sat Dec 3 20:21:05 2011 From: bps0002 at auburn.edu (B77S) Date: Sat, 3 Dec 2011 11:21:05 -0800 (PST) Subject: [R] Iteration in R In-Reply-To: References: <1322935838.52212.YahooMailNeo@web121702.mail.ne1.yahoo.com> Message-ID: <1322940065440-4154479.post@n4.nabble.com> Hi Michael, How would you do this with lapply to return a list? I can't seem to get that to work (I haven't used these much and am trying to learn). Thanks Brad Michael Weylandt wrote > > ? replicate > > or a for loop > > or do all one hundred simulations at once > > x <- matrix(rnorm(100^2, 1, 2), 100) > > It's going to depend on what you want to do with the numbers. > > Michael > > On Sat, Dec 3, 2011 at 1:10 PM, Martin Zonyrah <martin2005z@> wrote: >> Hi, >> I need help. I am trying to iterate this command? x <- rnorm(100, 1.0, >> 2.0) one hundred times in R but I don't seem to have a clue. >> Can anyone help? >> Your help is very much appreciated. >> >> Martin >> >> ? ? ? ?[[alternative HTML version deleted]] >> >> >> ______________________________________________ >> R-help@ mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > ______________________________________________ > R-help@ mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- View this message in context: http://r.789695.n4.nabble.com/Iteration-in-R-tp4154433p4154479.html Sent from the R help mailing list archive at Nabble.com. From djandrija at gmail.com Sat Dec 3 20:38:21 2011 From: djandrija at gmail.com (andrija djurovic) Date: Sat, 3 Dec 2011 20:38:21 +0100 Subject: [R] Iteration in R In-Reply-To: <1322940065440-4154479.post@n4.nabble.com> References: <1322935838.52212.YahooMailNeo@web121702.mail.ne1.yahoo.com> <1322940065440-4154479.post@n4.nabble.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From bps0002 at auburn.edu Sat Dec 3 20:42:37 2011 From: bps0002 at auburn.edu (B77S) Date: Sat, 3 Dec 2011 11:42:37 -0800 (PST) Subject: [R] Iteration in R In-Reply-To: References: <1322935838.52212.YahooMailNeo@web121702.mail.ne1.yahoo.com> <1322940065440-4154479.post@n4.nabble.com> Message-ID: <1322941357495-4154559.post@n4.nabble.com> Interesting and thank you; I'm confused as to why this doesn't work with: lapply(rep(1,6), FUN=rnorm, n=10, mean=1.0, sd=1) andrija djurovic wrote > > Hi Brad. Maybe something like this: > > lapply(rep(1,6), function(x) rnorm(10,0,1)) > > Andrija > > On Sat, Dec 3, 2011 at 8:21 PM, B77S <bps0002@> wrote: > >> Hi Michael, >> How would you do this with lapply to return a list? >> I can't seem to get that to work (I haven't used these much and am trying >> to >> learn). >> Thanks >> Brad >> >> >> Michael Weylandt wrote >> > >> > ? replicate >> > >> > or a for loop >> > >> > or do all one hundred simulations at once >> > >> > x <- matrix(rnorm(100^2, 1, 2), 100) >> > >> > It's going to depend on what you want to do with the numbers. >> > >> > Michael >> > >> > On Sat, Dec 3, 2011 at 1:10 PM, Martin Zonyrah <martin2005z@> >> wrote: >> >> Hi, >> >> I need help. I am trying to iterate this command x <- rnorm(100, 1.0, >> >> 2.0) one hundred times in R but I don't seem to have a clue. >> >> Can anyone help? >> >> Your help is very much appreciated. >> >> >> >> Martin >> >> >> >> [[alternative HTML version deleted]] >> >> >> >> >> >> ______________________________________________ >> >> R-help@ mailing list >> >> https://stat.ethz.ch/mailman/listinfo/r-help >> >> PLEASE do read the posting guide >> >> http://www.R-project.org/posting-guide.html >> >> and provide commented, minimal, self-contained, reproducible code. >> >> >> > >> > ______________________________________________ >> > R-help@ mailing list >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guide >> > http://www.R-project.org/posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code. >> > >> >> >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/Iteration-in-R-tp4154433p4154479.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> R-help@ mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@ mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- View this message in context: http://r.789695.n4.nabble.com/Iteration-in-R-tp4154433p4154559.html Sent from the R help mailing list archive at Nabble.com. From michael.weylandt at gmail.com Sat Dec 3 20:43:32 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Sat, 3 Dec 2011 14:43:32 -0500 Subject: [R] Iteration in R In-Reply-To: References: <1322935838.52212.YahooMailNeo@web121702.mail.ne1.yahoo.com> <1322940065440-4154479.post@n4.nabble.com> Message-ID: And with replicate: replicate(100, rnorm(100, 1,2), simplify = FALSE) Michael On Sat, Dec 3, 2011 at 2:38 PM, andrija djurovic wrote: > Hi Brad. Maybe something like this: > > lapply(rep(1,6), function(x) rnorm(10,0,1)) > > Andrija > > On Sat, Dec 3, 2011 at 8:21 PM, B77S wrote: > >> Hi Michael, >> How would you do this with lapply to return a list? >> I can't seem to get that to work (I haven't used these much and am trying >> to >> learn). >> Thanks >> Brad >> >> >> Michael Weylandt wrote >> > >> > ? replicate >> > >> > or a for loop >> > >> > or do all one hundred simulations at once >> > >> > x <- matrix(rnorm(100^2, 1, 2), 100) >> > >> > It's going to depend on what you want to do with the numbers. >> > >> > Michael >> > >> > On Sat, Dec 3, 2011 at 1:10 PM, Martin Zonyrah <martin2005z@> >> wrote: >> >> Hi, >> >> I need help. I am trying to iterate this command ?x <- rnorm(100, 1.0, >> >> 2.0) one hundred times in R but I don't seem to have a clue. >> >> Can anyone help? >> >> Your help is very much appreciated. >> >> >> >> Martin >> >> >> >> ? ? ? ?[[alternative HTML version deleted]] >> >> >> >> >> >> ______________________________________________ >> >> R-help@ mailing list >> >> https://stat.ethz.ch/mailman/listinfo/r-help >> >> PLEASE do read the posting guide >> >> http://www.R-project.org/posting-guide.html >> >> and provide commented, minimal, self-contained, reproducible code. >> >> >> > >> > ______________________________________________ >> > R-help@ mailing list >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guide >> > http://www.R-project.org/posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code. >> > >> >> >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/Iteration-in-R-tp4154433p4154479.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From michael.weylandt at gmail.com Sat Dec 3 20:45:39 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Sat, 3 Dec 2011 14:45:39 -0500 Subject: [R] Iteration in R In-Reply-To: <1322941357495-4154559.post@n4.nabble.com> References: <1322935838.52212.YahooMailNeo@web121702.mail.ne1.yahoo.com> <1322940065440-4154479.post@n4.nabble.com> <1322941357495-4154559.post@n4.nabble.com> Message-ID: Because lapply() tries to pass an argument to FUN and there's none that it can receive. This would work however: lapply(rep(100, 6), rnorm, mean = 1, sd = 2) Michael On Sat, Dec 3, 2011 at 2:42 PM, B77S wrote: > Interesting and thank you; I'm confused as to why this doesn't work with: > > lapply(rep(1,6), FUN=rnorm, n=10, mean=1.0, sd=1) > > > > andrija djurovic wrote >> >> Hi Brad. Maybe something like this: >> >> lapply(rep(1,6), function(x) rnorm(10,0,1)) >> >> Andrija >> >> On Sat, Dec 3, 2011 at 8:21 PM, B77S <bps0002@> wrote: >> >>> Hi Michael, >>> How would you do this with lapply to return a list? >>> I can't seem to get that to work (I haven't used these much and am trying >>> to >>> learn). >>> Thanks >>> Brad >>> >>> >>> Michael Weylandt wrote >>> > >>> > ? replicate >>> > >>> > or a for loop >>> > >>> > or do all one hundred simulations at once >>> > >>> > x <- matrix(rnorm(100^2, 1, 2), 100) >>> > >>> > It's going to depend on what you want to do with the numbers. >>> > >>> > Michael >>> > >>> > On Sat, Dec 3, 2011 at 1:10 PM, Martin Zonyrah <martin2005z@> >>> wrote: >>> >> Hi, >>> >> I need help. I am trying to iterate this command ?x <- rnorm(100, 1.0, >>> >> 2.0) one hundred times in R but I don't seem to have a clue. >>> >> Can anyone help? >>> >> Your help is very much appreciated. >>> >> >>> >> Martin >>> >> >>> >> ? ? ? ?[[alternative HTML version deleted]] >>> >> >>> >> >>> >> ______________________________________________ >>> >> R-help@ mailing list >>> >> https://stat.ethz.ch/mailman/listinfo/r-help >>> >> PLEASE do read the posting guide >>> >> http://www.R-project.org/posting-guide.html >>> >> and provide commented, minimal, self-contained, reproducible code. >>> >> >>> > >>> > ______________________________________________ >>> > R-help@ mailing list >>> > https://stat.ethz.ch/mailman/listinfo/r-help >>> > PLEASE do read the posting guide >>> > http://www.R-project.org/posting-guide.html >>> > and provide commented, minimal, self-contained, reproducible code. >>> > >>> >>> >>> -- >>> View this message in context: >>> http://r.789695.n4.nabble.com/Iteration-in-R-tp4154433p4154479.html >>> Sent from the R help mailing list archive at Nabble.com. >>> >>> ______________________________________________ >>> R-help@ mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >> >> ? ? ? [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help@ mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > > -- > View this message in context: http://r.789695.n4.nabble.com/Iteration-in-R-tp4154433p4154559.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From bps0002 at auburn.edu Sat Dec 3 21:39:18 2011 From: bps0002 at auburn.edu (B77S) Date: Sat, 3 Dec 2011 12:39:18 -0800 (PST) Subject: [R] Moving column averaging In-Reply-To: <1322943110.21725.YahooMailNeo@web122513.mail.ne1.yahoo.com> References: <1322769191236-4130179.post@n4.nabble.com> <1322784797785-4143329.post@n4.nabble.com> <1322788604791-4143909.post@n4.nabble.com> <1322943110.21725.YahooMailNeo@web122513.mail.ne1.yahoo.com> Message-ID: <1322944758336-4154770.post@n4.nabble.com> I don't know the answer, but would suppose not. You could test this for yourself using: system.time() example: system.time(rnorm(100000,0,1)) Chega wrote > > This solved my problem - Thanks a lot for your help! Please allow me one > more question: Works zoo's rollapply on a plain matrix faster than on a > zoo object? I am asking since I wanted to apply the provided averaging > code to a larger matrix (2500 rows x 200 cols), which is quite time > consuming... > > Thanks again! > > Chega > > ________________________________ > From: B77S [via R] <ml-node+s789695n4143909h3 at .nabble> > To: Chega <chegaga@> > Sent: Friday, December 2, 2011 6:16 AM > Subject: Re: Moving column averaging > > > Sorry for that, and thanks Gabor, > I could have sworn that it wouldn't. > > > > Gabor Grothendieck wrote >>On Thu, Dec 1, 2011 at 7:13 PM, B77S <[hidden email]> wrote: >>> # need zoo to use rollapply() >>> >>> # your data (I called df) >>> df <- structure(list(a = 1:2, b = 2:3, c = c(5L, 9L), d = c(9L, 6L), >>> ? ?e = c(1L, 5L), f = c(4, 7)), .Names = c("a", "b", "c", "d", >>> "e", "f"), class = "data.frame", row.names = c(NA, -2L)) >>> >>> # transpose and make a zoo object >>> df2 <- zoo(t(df)) >>> >>> #rollapply to get means and transpose back >>> means <- t(rollapply(df2, width=2, by=2, FUN=mean)) >>> >>> # adding the combined column names you requested >>> colnames(means) <- apply(matrix(names(df), nrow=2), 2, paste, >>> collapse=", ") >>> >> >>Note that zoo's rollapply also works on plain matrices and vectors. >> >>-- >>Statistics & Software Consulting >>GKX Group, GKX Associates Inc. >>tel: 1-877-GKX-GROUP >>email: ggrothendieck at gmail.com >> >>______________________________________________ >>[hidden email]?mailing list >>https://stat.ethz.ch/mailman/listinfo/r-help >>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>and provide commented, minimal, self-contained, reproducible code. > > ________________________________ > > If you reply to this email, your message will be added to the discussion > below: > http://r.789695.n4.nabble.com/Moving-column-averaging-tp4130179p4143909.html > To unsubscribe from Moving column averaging, click here. > NAML > -- View this message in context: http://r.789695.n4.nabble.com/Moving-column-averaging-tp4130179p4154770.html Sent from the R help mailing list archive at Nabble.com. From avinashbarnwal123 at gmail.com Sat Dec 3 22:08:12 2011 From: avinashbarnwal123 at gmail.com (avinash barnwal) Date: Sun, 4 Dec 2011 02:38:12 +0530 Subject: [R] Shading the plot Message-ID: Hi all, I have been trying to shade the specific part of the plot Part to be shaded 1. Any color whenever a2>a3 2. Any other color( Not same as 1) whenever a2 From michael.weylandt at gmail.com Sat Dec 3 22:16:07 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Sat, 3 Dec 2011 16:16:07 -0500 Subject: [R] Shading the plot In-Reply-To: References: Message-ID: ? polygon example(polygon) Michael On Sat, Dec 3, 2011 at 4:08 PM, avinash barnwal wrote: > Hi all, > > I have been trying to shade the specific part of the plot > > Part to be shaded > > 1. Any color whenever a2>a3 > > 2. Any other color( Not same as 1) whenever a2 > Suggest me some code for this task > > PLOT CODE for reference > > ###################################################################################################### > a2<-c("81.96392786","81.96392786","82.16432866","82.56513026","82.76553106","79.96593186","78.16633267", > "75.56713427","74.76753507","72.96793587","70.96793587","45.96793587","83.96793587","84.36873747", > "84.56913828","84.56913828","84.56913828","84.56913828","84.36873747","84.36873747") > a3<-c("81.96392786","81.96392786","81.96392786","70.96392786","68.16432866","66.16432866", > "62.16432866","58.56513026","56.56513026","54.56513026","48.56513026","49.76553106","52.76553106", > "54.76553106","57.96593186","59.36673347","83.36673347","83.36673347","83.36673347", > "83.56713427") > plot(a2,type='l',col='red',ylab='',xlab=" ",axes=FALSE) > lines(a3,col='blue',ylab='',xlab=" ") > ###################################################################################################### > > Thank you in the advance > -- > Avinash Barnwal > Final year undergraduate student > Statistics and informatics > Department of Mathematics > IIT Kharagpur > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > From robertf at uoregon.edu Sat Dec 3 23:11:39 2011 From: robertf at uoregon.edu (inferno846) Date: Sat, 3 Dec 2011 14:11:39 -0800 (PST) Subject: [R] Data Analysis for Gas Prices Message-ID: <1322950299124-4155078.post@n4.nabble.com> Hi there, I'm looking to analyze a set of data on local gas prices for a single day. I'm wondering what kind of questions I should be looking to ask and how to find and answer to them with R. Examples would be: Do prices differ between brands? Does location affect (NE, NW, SE, SW) price? Does the number of nearby (within .25 miles) competitors affect price? Do gas stations near shopping centers or highways have different prices? Also, could anyone help me figure out how to import a data table to R? When I try to create a .txt file from a word document and read it in R, the format of the first column always messes up. Any/all help is appreciated. -- View this message in context: http://r.789695.n4.nabble.com/Data-Analysis-for-Gas-Prices-tp4155078p4155078.html Sent from the R help mailing list archive at Nabble.com. From avinashbarnwal123 at gmail.com Sat Dec 3 23:28:50 2011 From: avinashbarnwal123 at gmail.com (avinash barnwal) Date: Sun, 4 Dec 2011 03:58:50 +0530 Subject: [R] Shading the plot In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From astareh at hotmail.com Sat Dec 3 23:27:19 2011 From: astareh at hotmail.com (set) Date: Sat, 3 Dec 2011 14:27:19 -0800 (PST) Subject: [R] pivot table help Message-ID: <1322951239541-4155144.post@n4.nabble.com> Hello R-users, I've got a huge table with about 20.00 rows and 50 columns. The table now has headers as Members1, Members2 etc. My data are 8 different individuals. And I've got a column with clusters. So each individual belongs to different clusters and can occurs multiple times within a cluster (that's the reason that there can be more than 8 members). I want a presence/ absence table for each individual within each cluster. So I want to go from: Cluster Member1 Member2 etc. 1 ind1 ind2 2 ind3 ind1 3 ind2 ind1 to cluster ind1 ind2 ind3 1 1 1 0 2 1 0 1 3 1 1 0 Has anybody any idea how I can do this? I already tried alot of things with pivottables (using cast()) But I think I'm missing out on something. thank you -- View this message in context: http://r.789695.n4.nabble.com/pivot-table-help-tp4155144p4155144.html Sent from the R help mailing list archive at Nabble.com. From bps0002 at auburn.edu Sat Dec 3 23:44:24 2011 From: bps0002 at auburn.edu (B77S) Date: Sat, 3 Dec 2011 14:44:24 -0800 (PST) Subject: [R] Data Analysis for Gas Prices In-Reply-To: <1322950299124-4155078.post@n4.nabble.com> References: <1322950299124-4155078.post@n4.nabble.com> Message-ID: <1322952264226-4155185.post@n4.nabble.com> use a < ? > to get help on a function; example: ?read.table If you do this you will see an option called "header"... use header=T if your top row contains column names. Learn how to read these help pages. Also, read thru a few beginner R manuals and see this website: http://www.statmethods.net/interface/io.html As for the rest of your questions..... Perhaps this is your sign to begin reading a intro-stats book, or inquire on a different forum. see: http://stats.stackexchange.com/questions good luck inferno846 wrote > > Hi there, > > I'm looking to analyze a set of data on local gas prices for a single day. > I'm wondering what kind of questions I should be looking to ask and how to > find and answer to them with R. Examples would be: > > Do prices differ between brands? > Does location affect (NE, NW, SE, SW) price? > Does the number of nearby (within .25 miles) competitors affect price? > Do gas stations near shopping centers or highways have different prices? > > Also, could anyone help me figure out how to import a data table to R? > When I try to create a .txt file from a word document and read it in R, > the format of the first column always messes up. Any/all help is > appreciated. > -- View this message in context: http://r.789695.n4.nabble.com/Data-Analysis-for-Gas-Prices-tp4155078p4155185.html Sent from the R help mailing list archive at Nabble.com. From rmh at temple.edu Sat Dec 3 23:53:59 2011 From: rmh at temple.edu (Richard M. Heiberger) Date: Sat, 3 Dec 2011 17:53:59 -0500 Subject: [R] pivot table help In-Reply-To: <1322951239541-4155144.post@n4.nabble.com> References: <1322951239541-4155144.post@n4.nabble.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From jholtman at gmail.com Sun Dec 4 01:02:19 2011 From: jholtman at gmail.com (jim holtman) Date: Sat, 3 Dec 2011 19:02:19 -0500 Subject: [R] pivot table help In-Reply-To: References: <1322951239541-4155144.post@n4.nabble.com> Message-ID: try this: > x <- read.table(text = "Cluster Member1 Member2 + 1 ind1 ind2 + 2 ind3 ind1 + 3 ind2 ind1", as.is = TRUE, header = TRUE) > require(reshape2) > x.m <- melt(x, id = "Cluster") > x.m Cluster variable value 1 1 Member1 ind1 2 2 Member1 ind3 3 3 Member1 ind2 4 1 Member2 ind2 5 2 Member2 ind1 6 3 Member2 ind1 > table(x.m$Cluster, x.m$value) ind1 ind2 ind3 1 1 1 0 2 1 0 1 3 1 1 0 > On Sat, Dec 3, 2011 at 5:53 PM, Richard M. Heiberger wrote: > Pivot tables are an Excel concept, not an R concept. > > That means you must give an example of your starting pivot table as an R > object (use dump() so we can pick it up from the email and execute it > immediately). > and an example of the R object you want as the result. > Use a trivial but complete example. > > An example of dump > > tmp <- matrix(1:6,2,3) > tmp > dump("tmp","") > Be sure to read the posting guide before sending your revised request. > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > Rich > On Sat, Dec 3, 2011 at 5:27 PM, set wrote: > >> Hello R-users, >> >> I've got a huge table with about 20.00 rows and 50 columns. The table now >> has headers as Members1, Members2 etc. My data are 8 different individuals. >> And I've got a column with clusters. So each individual belongs to >> different >> clusters and can occurs multiple times within a cluster (that's the reason >> that there can be more than 8 members). I want a presence/ absence table >> for >> each individual within each cluster. >> So I want to go from: >> Cluster ? Member1 ? ?Member2 ?etc. >> 1 ? ? ? ? ? ?ind1 ? ? ? ? ? ind2 >> 2 ? ? ? ? ? ?ind3 ? ? ? ? ? ind1 >> 3 ? ? ? ? ? ?ind2 ? ? ? ? ? ind1 >> >> to >> >> cluster ? ?ind1 ? ? ? ? ?ind2 ? ? ?ind3 >> 1 ? ? ? ? ? ?1 ? ? ? ? ? ? ? 1 ? ? ? ? ?0 >> 2 ? ? ? ? ? ?1 ? ? ? ? ? ? ? ?0 ? ? ? ? 1 >> 3 ? ? ? ? ? ?1 ? ? ? ? ? ? ? 1 ? ? ? ? ?0 >> >> Has anybody any idea how I can do this? I already tried alot of things with >> pivottables (using cast()) But I think I'm missing out on something. >> thank you >> >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/pivot-table-help-tp4155144p4155144.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. From jholtman at gmail.com Sun Dec 4 01:05:18 2011 From: jholtman at gmail.com (jim holtman) Date: Sat, 3 Dec 2011 19:05:18 -0500 Subject: [R] pivot table help In-Reply-To: References: <1322951239541-4155144.post@n4.nabble.com> Message-ID: Forgot, you can also do this: > dcast(x.m, Cluster ~ value, fun = length) Cluster ind1 ind2 ind3 1 1 1 1 0 2 2 1 0 1 3 3 1 1 0 > On Sat, Dec 3, 2011 at 7:02 PM, jim holtman wrote: > try this: > >> x <- read.table(text = "Cluster ? Member1 ? ?Member2 > + 1 ? ? ? ? ? ?ind1 ? ? ? ? ? ind2 > + 2 ? ? ? ? ? ?ind3 ? ? ? ? ? ind1 > + 3 ? ? ? ? ? ?ind2 ? ? ? ? ? ind1", as.is = TRUE, header = TRUE) >> require(reshape2) >> x.m <- melt(x, id = "Cluster") >> x.m > ?Cluster variable value > 1 ? ? ? 1 ?Member1 ?ind1 > 2 ? ? ? 2 ?Member1 ?ind3 > 3 ? ? ? 3 ?Member1 ?ind2 > 4 ? ? ? 1 ?Member2 ?ind2 > 5 ? ? ? 2 ?Member2 ?ind1 > 6 ? ? ? 3 ?Member2 ?ind1 >> table(x.m$Cluster, x.m$value) > > ? ?ind1 ind2 ind3 > ?1 ? ?1 ? ?1 ? ?0 > ?2 ? ?1 ? ?0 ? ?1 > ?3 ? ?1 ? ?1 ? ?0 >> > > > On Sat, Dec 3, 2011 at 5:53 PM, Richard M. Heiberger wrote: >> Pivot tables are an Excel concept, not an R concept. >> >> That means you must give an example of your starting pivot table as an R >> object (use dump() so we can pick it up from the email and execute it >> immediately). >> and an example of the R object you want as the result. >> Use a trivial but complete example. >> >> An example of dump >> >> tmp <- matrix(1:6,2,3) >> tmp >> dump("tmp","") >> Be sure to read the posting guide before sending your revised request. >> >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> Rich >> On Sat, Dec 3, 2011 at 5:27 PM, set wrote: >> >>> Hello R-users, >>> >>> I've got a huge table with about 20.00 rows and 50 columns. The table now >>> has headers as Members1, Members2 etc. My data are 8 different individuals. >>> And I've got a column with clusters. So each individual belongs to >>> different >>> clusters and can occurs multiple times within a cluster (that's the reason >>> that there can be more than 8 members). I want a presence/ absence table >>> for >>> each individual within each cluster. >>> So I want to go from: >>> Cluster ? Member1 ? ?Member2 ?etc. >>> 1 ? ? ? ? ? ?ind1 ? ? ? ? ? ind2 >>> 2 ? ? ? ? ? ?ind3 ? ? ? ? ? ind1 >>> 3 ? ? ? ? ? ?ind2 ? ? ? ? ? ind1 >>> >>> to >>> >>> cluster ? ?ind1 ? ? ? ? ?ind2 ? ? ?ind3 >>> 1 ? ? ? ? ? ?1 ? ? ? ? ? ? ? 1 ? ? ? ? ?0 >>> 2 ? ? ? ? ? ?1 ? ? ? ? ? ? ? ?0 ? ? ? ? 1 >>> 3 ? ? ? ? ? ?1 ? ? ? ? ? ? ? 1 ? ? ? ? ?0 >>> >>> Has anybody any idea how I can do this? I already tried alot of things with >>> pivottables (using cast()) But I think I'm missing out on something. >>> thank you >>> >>> -- >>> View this message in context: >>> http://r.789695.n4.nabble.com/pivot-table-help-tp4155144p4155144.html >>> Sent from the R help mailing list archive at Nabble.com. >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >> >> ? ? ? ?[[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > > > -- > Jim Holtman > Data Munger Guru > > What is the problem that you are trying to solve? > Tell me what you want to do, not how you want to do it. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. From dschruth at u.washington.edu Sun Dec 4 01:39:35 2011 From: dschruth at u.washington.edu (D. Schruth) Date: Sat, 3 Dec 2011 16:39:35 -0800 (PST) Subject: [R] help in removal of fixed pattern In-Reply-To: <1322896010158-4152524.post@n4.nabble.com> References: <1322896010158-4152524.post@n4.nabble.com> Message-ID: A great function for extracting pattern matches is 'm()' library(caroline) vect <- m('([xX][0-9])',df$Input) toupper(vect) #in case you really want all upper case x's It does the hard work of using 'sub' to remove the non-matching parts (sub, grep, regexpr, etc aren't very good for this sort of thing) It also can return a data.frame if you have multiple patterns you wish to match in each string vector element. -Dave On Fri, 2 Dec 2011, arunkumar1111 wrote: > Hi > > I have column name as given below > > If the variable is in log(X1 + 1) pattern it should be removed and i need > only X1 > > Input > log(x1 + 1) > x2 > log(X3 +1) > > Expected Output X1 X2 X3 > > Please help me > > > -- > View this message in context: http://r.789695.n4.nabble.com/help-in-removal-of-fixed-pattern-tp4152524p4152524.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > From dwinsemius at comcast.net Sun Dec 4 03:26:17 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Sat, 3 Dec 2011 21:26:17 -0500 Subject: [R] Shading the plot In-Reply-To: References: Message-ID: On Dec 3, 2011, at 5:28 PM, avinash barnwal wrote: > Hi Weylandt, > > > I tried it but i was not successful. > > Here is the full code > > Any help would be great. > ######################################################################## > time<-c("02-Jan-05","09-Jan-05","16-Jan-05","23-Jan-05","30- > Jan-05","06-Feb-05","13-Feb-05","20-Feb-05","27-Feb-05","06- > Mar-05","13-Mar-05", > "20-Mar-05","27-Mar-05","03-Apr-05","10-Apr-05","17-Apr-05","24- > Apr-05","01-May-05","08-May-05","15-May-05") > time<-as.Date(time,"%d-%b-%y") > a2<- > c > ("81.96392786 > ","81.96392786 > ","82.16432866 > ","82.56513026","82.76553106","79.96593186","78.16633267", > "75.56713427 > ","74.76753507 > ","72.96793587 > ","70.96793587","45.96793587","83.96793587","84.36873747", > "84.56913828 > ","84.56913828 > ","84.56913828","84.56913828","84.36873747","84.36873747") > a3<- > c > ("81.96392786 > ","81.96392786 > ","81.96392786","70.96392786","68.16432866","66.16432866", > "62.16432866 > ","58.56513026 > ","56.56513026 > ","54.56513026","48.56513026","49.76553106","52.76553106", > "54.76553106 > ","57.96593186 > ","59.36673347","83.36673347","83.36673347","83.36673347", > "83.56713427") > j<-0 > for(i in 1:length(a3)) > { > if(a2[i]>a3[i]) > { > j<-j+1 > x[j]<-a2[i] > y[j]<-a3[i] > temp_time[j]<-time[i] > } > } > plot(time,a2,type='l',col='red',ylab='',xlab=" ",axes=FALSE) > lines(time,a3,col='blue',ylab='',xlab=" ") > polygon(c(temp_time,rev(temp_time)),c(x,y),col="grey") > ######################################################################### What are the rules that govern requesting outside help in homework at your institution? Your current code does not recognize that there is line crossing. Nor do you describe what you mean by shading. If you wanted a rectangle within the lpot area it would drive one strategy and if you wanted only the area between the curves to be shaded it would drive a different strategy. AND you never define "x" or "y". -- David. > On Sun, Dec 4, 2011 at 2:46 AM, R. Michael Weylandt < > michael.weylandt at gmail.com> wrote: > >> ? polygon >> example(polygon) >> >> Michael >> >> On Sat, Dec 3, 2011 at 4:08 PM, avinash barnwal >> wrote: >>> Hi all, >>> >>> I have been trying to shade the specific part of the plot >>> >>> Part to be shaded >>> >>> 1. Any color whenever a2>a3 >>> >>> 2. Any other color( Not same as 1) whenever a2>> >>> Suggest me some code for this task >>> >>> PLOT CODE for reference >>> >>> >> ###################################################################################################### >>> >> a2<- >> c >> ("81.96392786 >> ","81.96392786 >> ","82.16432866 >> ","82.56513026","82.76553106","79.96593186","78.16633267", >>> >> "75.56713427 >> ","74.76753507 >> ","72.96793587 >> ","70.96793587","45.96793587","83.96793587","84.36873747", >>> >> "84.56913828 >> ","84.56913828 >> ","84.56913828","84.56913828","84.36873747","84.36873747") >>> >> a3<- >> c >> ("81.96392786 >> ","81.96392786 >> ","81.96392786","70.96392786","68.16432866","66.16432866", >>> >> "62.16432866 >> ","58.56513026 >> ","56.56513026 >> ","54.56513026","48.56513026","49.76553106","52.76553106", >>> >> "54.76553106 >> ","57.96593186 >> ","59.36673347","83.36673347","83.36673347","83.36673347", >>> "83.56713427") >>> plot(a2,type='l',col='red',ylab='',xlab=" ",axes=FALSE) >>> lines(a3,col='blue',ylab='',xlab=" ") >>> >> ###################################################################################################### >>> >>> Thank you in the advance >>> -- >>> Avinash Barnwal >>> Final year undergraduate student >>> Statistics and informatics >>> Department of Mathematics >>> IIT Kharagpur >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >> > > > > -- > Avinash Barnwal > Final year undergraduate student > Statistics and informatics > Department of Mathematics > IIT Kharagpur > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT From n.j.apps22 at gmail.com Sat Dec 3 23:42:52 2011 From: n.j.apps22 at gmail.com (napps22) Date: Sat, 3 Dec 2011 14:42:52 -0800 (PST) Subject: [R] density function always evaluating to zero Message-ID: <1322952172335-4155181.post@n4.nabble.com> Dear R users, I'm trying to carry out monte carlo integration of a posterior density function which is the product of a normal and a gamma distribution. The problem I have is that the density function always returns 0. How can I solve this problem? Here is my code #generate data x1 <- runif(100, min = -10, max = 10) y <- 2 * x1^2 + rnorm(100) # # # # # # # # Model 0 # # # # # # # z <- x1^2 M <- sum(z^2) MI <- 1/M zy <- crossprod(z,y) alpha.ols <- MI * zy resid_m0 <- y - z * alpha.ols s2_m0 <- sum(resid_m0^2)/v # use gibbs sampler to sample from posterior densities n <- length(y) k <- 1 v <- n - k # set up gibbs sampler nrDraws <- 10000 h_sample_m0 <- rgamma(nrDraws, v/2, v*s2_m0/2) alpha_sample <- matrix(0, nrow = nrDraws, ncol = 1) for(i in 1:nrDraws) { alpha_sample[i] <- rnorm(1,alpha.ols,(1/h_sample_m0[i]) * MI) } # define posterior density for model 0 f <- function(alpha,h) { e <- y - alpha * x1^2 const <- (2*pi)^(-n/2) / ( gamma(v/2) * (v*s2_m1/2)^(-v/2) ) kernel <- h^((v-1)/2) * exp((-(h/2) * sum(e^2)) - (v*s2_m0)*h) x <- const * kernel return(x) } # calculate approximation of p(y|m_0) m0 <-f(alpha_sample,h_sample_m0) post_m0 <- sum(m0) / nrDraws -- View this message in context: http://r.789695.n4.nabble.com/density-function-always-evaluating-to-zero-tp4155181p4155181.html Sent from the R help mailing list archive at Nabble.com. From dlduncan2 at alaska.edu Sun Dec 4 01:44:06 2011 From: dlduncan2 at alaska.edu (Danielle Duncan) Date: Sat, 3 Dec 2011 15:44:06 -0900 Subject: [R] Logistic Regression with genetic component Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From johnson.cheryl625 at gmail.com Sun Dec 4 01:46:42 2011 From: johnson.cheryl625 at gmail.com (Cheryl Johnson) Date: Sat, 3 Dec 2011 19:46:42 -0500 Subject: [R] rnorm command Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From zack.abrahamson at gmail.com Sun Dec 4 03:08:09 2011 From: zack.abrahamson at gmail.com (z2.0) Date: Sat, 3 Dec 2011 18:08:09 -0800 (PST) Subject: [R] Prediction from censReg? Message-ID: <1322964489802-4155855.post@n4.nabble.com> Hi - First post, so excuse any errors in protocol: Wanted to ask if there's an easy way to use 'predict' with objects of class 'censReg', 'maxLik', 'maxim' or 'list'. Have a left-censored dataset, attempting to use a Tobit model and am working with the censReg package. I like how easy it is to move from glm models to predictions with 'predict' and wanted to ask if there was a way to do so with objects output from 'censReg'. Thanks, Zack -- View this message in context: http://r.789695.n4.nabble.com/Prediction-from-censReg-tp4155855p4155855.html Sent from the R help mailing list archive at Nabble.com. From svezakal at gmail.com Sun Dec 4 04:23:35 2011 From: svezakal at gmail.com (grttt nbbfg) Date: Sun, 4 Dec 2011 04:23:35 +0100 Subject: [R] upper bound in the integrate function depends on a parameter Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From avinashbarnwal123 at gmail.com Sun Dec 4 05:37:03 2011 From: avinashbarnwal123 at gmail.com (avinash barnwal) Date: Sun, 4 Dec 2011 10:07:03 +0530 Subject: [R] Shading the plot In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From dwinsemius at comcast.net Sun Dec 4 05:50:15 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Sat, 3 Dec 2011 23:50:15 -0500 Subject: [R] density function always evaluating to zero In-Reply-To: <1322952172335-4155181.post@n4.nabble.com> References: <1322952172335-4155181.post@n4.nabble.com> Message-ID: On Dec 3, 2011, at 5:42 PM, napps22 wrote: > Dear R users, > > I'm trying to carry out monte carlo integration of a posterior density > function which is the product of a normal and a gamma distribution. > The > problem I have is that the density function always returns 0. How > can I > solve this problem? Your code throws errors due to several missing objects due in part to a missing "v", but moving that higher in the code does not cure everything. A missing 's2_m1' is also listed as a source of error. You might want to try in a clean session and redo your debugging so that you know what variables are in your workspace and their values. The usual debugging method is to sprinkle print() statements in your code to monitor where things might not be proceeding as planned. -- David. > > Here is my code > > #generate data > > x1 <- runif(100, min = -10, max = 10) > y <- 2 * x1^2 + rnorm(100) > > # # # # # # # # Model 0 # # # # # # # > > z <- x1^2 > M <- sum(z^2) > MI <- 1/M > zy <- crossprod(z,y) > alpha.ols <- MI * zy > resid_m0 <- y - z * alpha.ols > s2_m0 <- sum(resid_m0^2)/v > > # use gibbs sampler to sample from posterior densities > > n <- length(y) > k <- 1 > v <- n - k > > # set up gibbs sampler > > nrDraws <- 10000 > h_sample_m0 <- rgamma(nrDraws, v/2, v*s2_m0/2) > alpha_sample <- matrix(0, nrow = nrDraws, ncol = 1) > > for(i in 1:nrDraws) { > > alpha_sample[i] <- rnorm(1,alpha.ols,(1/h_sample_m0[i]) * MI) > > } > > # define posterior density for model 0 > > f <- function(alpha,h) { > > e <- y - alpha * x1^2 > const <- (2*pi)^(-n/2) / ( gamma(v/2) * (v*s2_m1/2)^(-v/2) ) > kernel <- h^((v-1)/2) * exp((-(h/2) * sum(e^2)) - (v*s2_m0)*h) > x <- const * kernel > return(x) > } > > # calculate approximation of p(y|m_0) > > m0 <-f(alpha_sample,h_sample_m0) > post_m0 <- sum(m0) / nrDraws > > > -- > View this message in context: http://r.789695.n4.nabble.com/density-function-always-evaluating-to-zero-tp4155181p4155181.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT From dwinsemius at comcast.net Sun Dec 4 06:06:17 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Sun, 4 Dec 2011 00:06:17 -0500 Subject: [R] upper bound in the integrate function depends on a parameter In-Reply-To: References: Message-ID: On Dec 3, 2011, at 10:23 PM, grttt nbbfg wrote: > Sorry for my English, is not my first language.. > > I have some trouble in terms of using integrate function in R. > fx is a function of m and x where m is supposed to be a unknown > parameter. R is not an algebraic solver (and R-help is not a homework list.). > >> fx=function(m,x){ > + x*2/(3*m)*(1-x/(3*m)) > + } > > The problem is in upper bound, it depends on parameter m. > >> integrate(fx,lower=0,upper=3*m)$value > > Is it possible to use the integrate function when bounds depend on a > parameter? If it is known, yes. You could also do some investigation: curve(x*2/(3*5)*(1-x/(3*5)), 0, 15) > > How to define m to solve this integral? The result should be m. As I said, no homework answers here. -- David Winsemius, MD West Hartford, CT From jdnewmil at dcn.davis.ca.us Sun Dec 4 06:11:43 2011 From: jdnewmil at dcn.davis.ca.us (Jeff Newmiller) Date: Sat, 03 Dec 2011 21:11:43 -0800 Subject: [R] rnorm command In-Reply-To: References: Message-ID: <23878a64-7f5d-469c-8a95-15cf6a0d0e87@email.android.com> No. If you want a more informative answer, try following the recommendations in the posting guide mentioned below. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN: Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. Cheryl Johnson wrote: >Hello, > >I use the command rnorm, and I feed these results into a lmer command. >Since I am using the rnorm command I expect to get different results >for >each iteration, yet for each iteration I am getting the same answer. If >someone understands why I am getting the same answer every time with a >random number generator, I would appreciate help in understanding why >this >is happening. Is the lmer command causing the answer to be the same >each >time? > >Thanks > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. From p_connolly at slingshot.co.nz Sun Dec 4 05:16:25 2011 From: p_connolly at slingshot.co.nz (Patrick Connolly) Date: Sun, 4 Dec 2011 17:16:25 +1300 Subject: [R] Assign name to object for each iteration in a loop. In-Reply-To: <1322763198075-4129752.post@n4.nabble.com> References: <1322763198075-4129752.post@n4.nabble.com> Message-ID: <20111204041624.GD28933@slingshot.co.nz> On Thu, 01-Dec-2011 at 10:13AM -0800, lglew wrote: |> Hi R-users, |> |> I'm trying to produce decompositions of a multiple time-series, grouped by a |> factor (called "area"). I'm modifying the code in the STLperArea function of |> package ndvits, as this function only plots produces stl plots, it does not |> return the underlying data. |> |> I want to extract the trend component of each decomposition |> ("x$time.series[,trend]), assign a name based on the factor "area". |> |> My input data look like this: |> Area is a factor, with three (but could be many more) levels. |> area |> 1 |> 2 |> 3 |> |> Ystart=2000 |> |> TS is a timeseries: |> |> X2000049 X2000065 X2000081 X2000097 X2000113 |> 1 0.2080 0.2165 0.2149 0.2314 0.2028 |> 2 0.1578 0.1671 0.1577 0.1593 0.1672 |> 3 0.1897 0.1948 0.2290 0.2292 0.2067 |> |> Here's the function: |> |> STLpA<-function(TS, area, Ystart, period=23, nSG="5,5", DSG=0) |> { |> require (RTisean) |> for(i in 1:unique(area)){ |> vi.metric=TS[area==i] |> filt.vi<-sav_gol(vi.metric,n=nSG,D=DSG) |> vi.sg<-ts(filt.vi[,1], start=Ystart,frequency=period) |> stld.tmp<-stl(vi.sg, s.window="periodic", robust=TRUE, na.action=na.approx) |> stld.trend<-stld.temp$time.series[,trend] |> } |> assign(paste("stld", i , sep= "."), stld.trend) |> vi.trend<-ls(pattern= "^stld..$") |> return(vi.trend) |> } |> |> When I call this function with signal=STLpA(TS,area,Ystart=2000,period=23, |> nSG= "5,5", DSG="0")) |> |> I get this error: |> |> Error in cat(list(...), file, sep, fill, labels, append) : |> argument 1 (type 'list') cannot be handled by 'cat' |> In addition: Warning message: |> In 1:unique(area) : |> numerical expression has 3 elements: only the first used |> |> I'm guessing this is because I'm assigning names to each temporary stl.trend |> file incorrectly. Can anyone |> improve on my rather poor efforts here? I would suggest putting your individual trends into a list and returning that at the end of your function rather than trying to assing individual objects. IMHO it's easier to do and more useful. Something along these lines: > trends <- list() > for(i in 1:unique(area)){ ... + trends[[i]] <- .... } Then you'll have an element in the list trends that you do with what you will. It creates less clutter also. HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___ Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) ..... Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. From mentor_ at gmx.net Sun Dec 4 12:49:00 2011 From: mentor_ at gmx.net (syrvn) Date: Sun, 4 Dec 2011 03:49:00 -0800 (PST) Subject: [R] xyplot squeezed together Message-ID: <1322999340150-4156661.post@n4.nabble.com> Hi, I created the following example of a xyplot. The plot actually looks ok apart from that the x-axis is pretty squeezed/clinched. I tried aspect="fill" already but I want to have all 3 sub plots next to each other. I tried loads of different scaling varieties but with no significant result... library(lattice) N <- 6 d <- data.frame(factor(rep(c("A1","A2","A3"),each=N), levels=c("A1","A2","A3")), factor(rep(c("B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9"), each=N/3), levels=c("B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9")), rep(c(0,1), each=N/3/2)) colnames(d) <- c("ID", "class", "group") value <- matrix(c(400,300, 320,380, 410,500, 800,670, 810,900, 560,750, 1100,1200, 1200,1300, 1300,1200)) d <- cbind(d, value) xyplot(value ~ group | ID, d, groups = class, type = c("g", "b"), auto.key = list(lines = TRUE, columns = 3), xlab = "blocked=0, released=1", ylab = "value", aspect = 'xy', scales=list(x=list(at=-1:2, labels=c("",0,1,"")))) Anyone any ideas how to enlarge the x-axis? Cheers -- View this message in context: http://r.789695.n4.nabble.com/xyplot-squeezed-together-tp4156661p4156661.html Sent from the R help mailing list archive at Nabble.com. From jwd at surwest.net Sun Dec 4 09:53:58 2011 From: jwd at surwest.net (John) Date: Sun, 4 Dec 2011 00:53:58 -0800 Subject: [R] Data Analysis for Gas Prices In-Reply-To: <1322950299124-4155078.post@n4.nabble.com> References: <1322950299124-4155078.post@n4.nabble.com> Message-ID: <20111204005358.7f1fa7a6@draco> On Sat, 3 Dec 2011 14:11:39 -0800 (PST) inferno846 wrote: ... > > Also, could anyone help me figure out how to import a data table to > R? When I try to create a .txt file from a word document and read it > in R, the format of the first column always messes up. Any/all help > is appreciated. > For reading in data, avoid using Word, a program that is overkill for almost all purposes. Either use Notepad, or grab a simple text editor off the internet - preferably capable of block selection. Since you do not say just how the "first column messes up," it is rather problematic trying suggest a solution the problem. The first line of the table and a couple data lines, the form of command you use to read in the data and the field separator in your table are all useful pieces of information. There are however a great many books about R out there and nearly all of them address at least briefly how to import data. Portland has one of the best bookstores on the planet. As a last resort you might try the command ??read.table from the R prompt. JD From astareh at hotmail.com Sun Dec 4 10:08:14 2011 From: astareh at hotmail.com (set) Date: Sun, 4 Dec 2011 01:08:14 -0800 (PST) Subject: [R] pivot table help In-Reply-To: References: <1322951239541-4155144.post@n4.nabble.com> Message-ID: <1322989694104-4156393.post@n4.nabble.com> Thank you very much! works perfectly! -- View this message in context: http://r.789695.n4.nabble.com/pivot-table-help-tp4155144p4156393.html Sent from the R help mailing list archive at Nabble.com. From astareh at hotmail.com Sun Dec 4 10:21:49 2011 From: astareh at hotmail.com (set) Date: Sun, 4 Dec 2011 01:21:49 -0800 (PST) Subject: [R] frequency table? Message-ID: <1322990509062-4156422.post@n4.nabble.com> Hello R-users, I've got a file with individuals as colums and the clusters where they occur in as rows. And I wanted a table which tells me how many times each individual occurs with another. I don't really know how such a table is called...it is not a frequency table....My eventual goal is to make Venn-diagrams from the occurence of my individuals. So I've this: cluster ind1 ind2 ind3 etc. 1 0 1 2 2 3 0 1 3 1 1 1 And I want to go to this: ind1 ind2 ind3 ind1 0 4 2 ind2 4 0 4 ind3 2 4 1 is there a way to do this? Thank you for your help -- View this message in context: http://r.789695.n4.nabble.com/frequency-table-tp4156422p4156422.html Sent from the R help mailing list archive at Nabble.com. From n.j.apps22 at gmail.com Sun Dec 4 13:47:45 2011 From: n.j.apps22 at gmail.com (napps22) Date: Sun, 4 Dec 2011 04:47:45 -0800 (PST) Subject: [R] density function always evaluating to zero In-Reply-To: <1322952172335-4155181.post@n4.nabble.com> References: <1322952172335-4155181.post@n4.nabble.com> Message-ID: <1323002865006-4156746.post@n4.nabble.com> Sorry that was my poor copying and pasting. Here's the correct R code. The problem does seem to be with the function I define as f. # Model selection example in a bayesian framework # two competiting non-nested models # M0: y_t = alpha * x1^2 + e_t # M1: y_t = beta * x1^4 + e_t # where e_t ~ iidN(0,1) #generate data x1 <- runif(100, min = -10, max = 10) y <- 2 * x1^2 + rnorm(100) n <- length(y) k <- 1 v <- n - k # want the posterior probabilities of the two models # postprob_mj = p(y|model j true) * priorprob_mj / p(y) # need to calculate the integral of p(y|alpha,h)p(alpha,h) # and the integral of p(y|beta,h)p(beta,h) # recall we chose p(alpha,h) = p(beta,h) = 1/h # need to sample from the posterior to get an approximation of the integral # # # # # # # # Model 0 # # # # # # # z <- x1^2 M <- sum(z^2) MI <- 1/M zy <- crossprod(z,y) alpha.ols <- MI * zy resid_m0 <- y - z * alpha.ols s2_m0 <- sum(resid_m0^2)/v # set up gibbs sampler nrDraws <- 10000 h_sample_m0 <- rgamma(nrDraws, v/2, v*s2_m0/2) alpha_sample <- matrix(0, nrow = nrDraws, ncol = 1) for(i in 1:nrDraws) { alpha_sample[i] <- rnorm(1,alpha.ols,(1/h_sample_m0[i]) * MI) } # define posterior density for m0 f <- function(alpha,h) { e <- y - alpha * x1^2 const <- (2*pi)^(-n/2) / ( gamma(v/2) * (v*s2_m0/2)^(-v/2) ) kernel <- h^((v-1)/2) * exp((-(h/2) * sum(e^2)) - (v*s2_m0)*h) x <- const * kernel return(x) } # calculate approximation of p(y|m_0) m0 <-f(alpha_sample,h_sample_m0) post_m0 <- sum(m0) / nrDraws -- View this message in context: http://r.789695.n4.nabble.com/density-function-always-evaluating-to-zero-tp4155181p4156746.html Sent from the R help mailing list archive at Nabble.com. From Mintewab.Bezabih at economics.gu.se Sun Dec 4 14:08:52 2011 From: Mintewab.Bezabih at economics.gu.se (Mintewab Bezabih) Date: Sun, 4 Dec 2011 14:08:52 +0100 Subject: [R] problems using the thin plate spline method In-Reply-To: References: <4B46FB7EED800046A5952FCFA92D3BA0347DF578CD@HGUMAIL6.hgu.gu.se>, Message-ID: <4B46FB7EED800046A5952FCFA92D3BA0347DF578D2@HGUMAIL6.hgu.gu.se> Dear R users and Jeff, Sorry for not being quite explicit in my earlier message. My main problem is while my data seem to be read into R well (I manage to graph them and all), I cannot get the following line to work. tpsfit <- Tps(cbind(x1, x2), y, scale.type="unscaled") and I get the following error message Error in as.matrix(x) : error in evaluating the argument 'x' in selecting a method for function 'as.matrix': Error: object 'x1' not found thanks for help minti ________________________________________ Fr?n: Jeff Newmiller [jdnewmil at dcn.davis.ca.us] Skickat: den 3 december 2011 17:45 Till: Mintewab Bezabih; r-help at r-project.org ?mne: Re: [R] problems using the thin plate spline method I can tell that you are puzzled and confused. Unfortunately, I am not psychic, so I cannot tell what you did, and therefore cannot tell where you went astray. The solution is for you to read the posting guide mentioned at the bottom of every R-help message. Spend a little time to create a small bit of data like yours if your actual data is large (subset and dput are useful for this). Remember to include the output of sessionInfo, and so on. Many times you are likely to find the answer yourself by going through these steps, but they are essential for communication. Good luck. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN: Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. Mintewab Bezabih wrote: >Dear R users, > >I am a beginner in R trying to apply the thin plate spline method to my >climate data. I used the example in R to do so, and the lines seem to >run fine ( I am not getting errors) but I am not getting any output in >the form of graph or anything. I got a warning message saying that >'surface extends beyond box'. > >Any help is much appreciated. >thanks >minti >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. From sarah.goslee at gmail.com Sun Dec 4 15:21:49 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Sun, 4 Dec 2011 09:21:49 -0500 Subject: [R] problems using the thin plate spline method In-Reply-To: <4B46FB7EED800046A5952FCFA92D3BA0347DF578D2@HGUMAIL6.hgu.gu.se> References: <4B46FB7EED800046A5952FCFA92D3BA0347DF578CD@HGUMAIL6.hgu.gu.se> <4B46FB7EED800046A5952FCFA92D3BA0347DF578D2@HGUMAIL6.hgu.gu.se> Message-ID: Hello, On Sun, Dec 4, 2011 at 8:08 AM, Mintewab Bezabih wrote: > Dear R users and Jeff, > > Sorry for not being quite explicit in my earlier message. And you are still not explicit. We have no idea what you've done. > My main problem is while my data seem to be read into R well (I manage to graph them and all), I cannot get the following line to work. > > tpsfit <- Tps(cbind(x1, x2), y, scale.type="unscaled") > > and I get the following error message > > Error in as.matrix(x) : > ?error in evaluating the argument 'x' in selecting a method for function 'as.matrix': Error: object 'x1' not found I'd have to guess that there's no object x1. What does ls() tell you? str(x1)? What do your data look like? You were already given instructions on how to include sample data to construct a reproducible example. You said that graphing your data worked; how did you do so? The posting guide and the advice you were already given were both offered for a reason. The querent needs to do the work of formulating an understandable and answerable question. Sarah > thanks for help > minti > ________________________________________ > Fr?n: Jeff Newmiller [jdnewmil at dcn.davis.ca.us] > Skickat: den 3 december 2011 17:45 > Till: Mintewab Bezabih; r-help at r-project.org > ?mne: Re: [R] problems using the thin plate spline method > > I can tell that you are puzzled and confused. Unfortunately, I am not psychic, so I cannot tell what you did, and therefore cannot tell where you went astray. > > The solution is for you to read the posting guide mentioned at the bottom of every R-help message. Spend a little time to create a small bit of data like yours if your actual data is large (subset and dput are useful for this). Remember to include the output of sessionInfo, and so on. Many times you are likely to find the answer yourself by going through these steps, but they are essential for communication. > > Good luck. > Sent from my phone. Please excuse my brevity. > > Mintewab Bezabih wrote: > >>Dear R users, >> >>I am a beginner in R trying to apply the thin plate spline method to my >>climate data. I used the example in R to do so, and the lines seem to >>run fine ( I am not getting errors) but I am not getting any output in >>the form of graph or anything. I got a warning message saying that >>'surface extends beyond box'. >> >>Any help is much appreciated. >>thanks >>minti -- Sarah Goslee http://www.functionaldiversity.org From sarah.goslee at gmail.com Sun Dec 4 15:27:06 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Sun, 4 Dec 2011 09:27:06 -0500 Subject: [R] density function always evaluating to zero In-Reply-To: <1323002865006-4156746.post@n4.nabble.com> References: <1322952172335-4155181.post@n4.nabble.com> <1323002865006-4156746.post@n4.nabble.com> Message-ID: I didn't try out your extensive code, but here's one potentially serious problem: You only pass two arguments to f(), alpha and h, but within f you nonetheless use x1 and y and several other things. This is bad practice, and dangerous: you should pass all the necessary arguments to f(), not rely on the environment to contain them. After you fix that, working through your function step by step at the command line and looking at the results of each line of code can be very educational. Sarah On Sun, Dec 4, 2011 at 7:47 AM, napps22 wrote: > Sorry that was my poor copying and pasting. Here's the correct R code. The > problem does seem to be with the function I define as f. > > # Model selection example in a bayesian framework > # two competiting non-nested models > # M0: y_t = alpha * x1^2 + e_t > # M1: y_t = beta * x1^4 + e_t > # where e_t ~ iidN(0,1) > > #generate data > > x1 <- runif(100, min = -10, max = 10) > y <- 2 * x1^2 + rnorm(100) > n <- length(y) > k <- 1 > v <- n - k > > # want the posterior probabilities of the two models > # postprob_mj = p(y|model j true) * priorprob_mj / p(y) > # need to calculate the integral of p(y|alpha,h)p(alpha,h) > # and the integral of p(y|beta,h)p(beta,h) > # recall we chose p(alpha,h) = p(beta,h) = 1/h > # need to sample from the posterior to get an approximation of the integral > > # # # # # # # # Model 0 # # # # # # # > > z <- x1^2 > M <- sum(z^2) > MI <- 1/M > zy <- crossprod(z,y) > alpha.ols <- MI * zy > resid_m0 <- y - z * alpha.ols > s2_m0 <- sum(resid_m0^2)/v > > # set up gibbs sampler > > nrDraws <- 10000 > h_sample_m0 <- rgamma(nrDraws, v/2, v*s2_m0/2) > alpha_sample <- matrix(0, nrow = nrDraws, ncol = 1) > > for(i in 1:nrDraws) { > > ? ? ? ?alpha_sample[i] <- rnorm(1,alpha.ols,(1/h_sample_m0[i]) * MI) > > ? ? ? ?} > > # define posterior density for m0 > > f <- function(alpha,h) { > > ? ? ? ?e <- y - alpha * x1^2 > ? ? ? ?const <- (2*pi)^(-n/2) / ( gamma(v/2) * (v*s2_m0/2)^(-v/2) ) > ? ? ? ?kernel <- h^((v-1)/2) * exp((-(h/2) * sum(e^2)) - (v*s2_m0)*h) > ? ? ? ?x <- const * kernel > ? ? ? ?return(x) > ? ? ? ?} > > # calculate approximation of p(y|m_0) > > m0 <-f(alpha_sample,h_sample_m0) > post_m0 <- sum(m0) / nrDraws > > > -- Sarah Goslee http://www.functionaldiversity.org From sarah.goslee at gmail.com Sun Dec 4 15:36:45 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Sun, 4 Dec 2011 09:36:45 -0500 Subject: [R] xyplot squeezed together In-Reply-To: <1322999340150-4156661.post@n4.nabble.com> References: <1322999340150-4156661.post@n4.nabble.com> Message-ID: You specified the aspect ratio, so your plots must have that ratio of width to height. It looks like you are trying to control layout by specifying aspect ratio? That, as you've discovered, is an ineffective way to do it. Instead, you should specify layout directly, using for your example layout=c(3,1,1) and deleting the aspect='xy' argument. Rereading the help for xyplot() more carefully would also be a good idea. Sarah On Sun, Dec 4, 2011 at 6:49 AM, syrvn wrote: > Hi, > > > I created the following example of a xyplot. The plot actually looks ok > apart from that the > > x-axis is pretty squeezed/clinched. I tried aspect="fill" already but I want > to have all 3 sub plots > > next to each other. I tried loads of different scaling varieties but with no > significant result... > > > > library(lattice) > > N <- 6 > > d <- data.frame(factor(rep(c("A1","A2","A3"),each=N), > levels=c("A1","A2","A3")), > > ? ? ? ? ? ? ? ? ? ? ? factor(rep(c("B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9"), > each=N/3), > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?levels=c("B1", "B2", "B3", "B4", "B5", "B6", "B7", > "B8", "B9")), > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?rep(c(0,1), each=N/3/2)) > > colnames(d) <- c("ID", "class", "group") > > value <- matrix(c(400,300, 320,380, 410,500, 800,670, 810,900, 560,750, > 1100,1200, 1200,1300, 1300,1200)) > > d <- cbind(d, value) > > xyplot(value ~ group | ID, d, groups = class, type = c("g", "b"), > > ? ? ? ? ?auto.key = list(lines = TRUE, columns = 3), xlab = "blocked=0, > released=1", > > ? ? ? ? ?ylab = "value", aspect = 'xy', scales=list(x=list(at=-1:2, > labels=c("",0,1,"")))) > > > > Anyone any ideas how to enlarge the x-axis? > > Cheers > > -- Sarah Goslee http://www.functionaldiversity.org From djandrija at gmail.com Sun Dec 4 15:40:21 2011 From: djandrija at gmail.com (andrija djurovic) Date: Sun, 4 Dec 2011 15:40:21 +0100 Subject: [R] RODBC connect to Excel (64-bit Windows 7) Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From tal.galili at gmail.com Sun Dec 4 15:57:51 2011 From: tal.galili at gmail.com (Tal Galili) Date: Sun, 4 Dec 2011 16:57:51 +0200 Subject: [R] LaTeX output for summary.lm object - while displaying the information outside the table Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From bps0002 at auburn.edu Sun Dec 4 16:17:53 2011 From: bps0002 at auburn.edu (B77S) Date: Sun, 4 Dec 2011 07:17:53 -0800 (PST) Subject: [R] Programming Statistical Functions In-Reply-To: <1323008850451-4157012.post@n4.nabble.com> References: <1280490786119-2307880.post@n4.nabble.com> <1323008850451-4157012.post@n4.nabble.com> Message-ID: <1323011873678-4157101.post@n4.nabble.com> As Stephen pointed out, this is easy to do. The word file the OP posted has all the necessary formulae. Now you just need to learn how to convert those formulae into R functions.... Stephen gave you an example of how to create a function for CV. Now run with it. perhaps something like this is what you need: http://cran.r-project.org/doc/contrib/Short-refcard.pdf It is time for you to do some reading on your own. Good luck. gvjones wrote > > Hello, > > Did you find anything helpful for calculating the statistical functions in > your list. I would like to also calculate these and have been looking for > some code to do so. > > Thanks > -- View this message in context: http://r.789695.n4.nabble.com/Programming-Statistical-Functions-tp2307880p4157101.html Sent from the R help mailing list archive at Nabble.com. From costas.vorlow at gmail.com Sun Dec 4 16:18:55 2011 From: costas.vorlow at gmail.com (Costas Vorlow) Date: Sun, 4 Dec 2011 17:18:55 +0200 Subject: [R] Vectorization instead of loops problem Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From GodinA at Dal.Ca Sun Dec 4 14:53:26 2011 From: GodinA at Dal.Ca (Aurelie Cosandey Godin) Date: Sun, 4 Dec 2011 09:53:26 -0400 Subject: [R] Polishing my geom_bar for publication References: <3467C1A6-020E-4E84-A456-C9BF8B964E8A@Dal.Ca> Message-ID: <8B1382E7-E7AA-4E0D-A6F7-7FFC623C819C@Dal.Ca> Dear list, I am new with ggplot2 and I have spend quiet some time putting together the following code to create the attached plot. However there's still a few things that I'm having trouble with! I would be grateful if someone can tell me how to fix (1) the colour of my bars into grey scales (2) removing the y-axis (species name) on the right figure to avoid duplication, and (3) fix the width, such that both figures have the same apparence regardless of the legend. Thank you very much in advance! The code is as follow: (a<-ggplot(Final2, aes(x=spp, y=CPUE, fill=season)) + geom_bar(position=position_dodge()) + geom_errorbar(aes(ymin=CPUE-cpue.se, ymax=CPUE+cpue.se), size=.3, width=.2, position=position_dodge(.9)) + xlab("Species") + scale_x_discrete(breaks=c("100","102","107","88","90","91","92","93","94","96","98","99"), labels=c("WINTER","SPINYTAIL","BIGELOW'S","SKATES (NS)","THORNY","SMOOTH","ABYSSAL","LITTLE","DEEPWATER","JENSEN'S","WHITE","SOFT")) + ylab("Abundance (fish/tow)") + coord_flip() + theme_bw() + opts(axis.title.x = theme_text(size = 10)) + opts(panel.grid.minor = theme_blank()) + opts(legend.position='none') ) (b<-ggplot(Final2, aes(x=spp, y=WPUE, fill=season)) + geom_bar(position=position_dodge()) + geom_errorbar(aes(ymin=WPUE-wpue.se, ymax=WPUE+wpue.se), size=.3, width=.2, position=position_dodge(.9)) + xlab(NULL)+ scale_x_discrete(breaks=c("100","102","107","88","90","91","92","93","94","96","98","99"), labels=c("WINTER","SPINYTAIL","BIGELOW'S","SKATES (NS)","THORNY","SMOOTH","ABYSSAL","LITTLE","DEEPWATER","JENSEN'S","WHITE","SOFT"))+ ylab("Biomass (Weight (kg)/tow)") + scale_fill_hue(name="Survey season", # Legend label, use darker colors breaks=c("summer", "winter"), labels=c("Spring", "Fall")) + coord_flip() + theme_bw() + opts(axis.title.x = theme_text(size = 10)) + opts(panel.grid.minor = theme_blank())) pdf("polishing-layout2.pdf", width = 10, height = 6) grid.newpage() pushViewport(viewport(layout = grid.layout(1, 2))) vplayout <- function(x, y) viewport(layout.pos.row = x, layout.pos.col = y) print(a, vp = vplayout(1, 1)) print(b, vp = vplayout(1, 2)) dev.off() Aurelie Cosandey-Godin Ph.D. student, Department of Biology Industrial Graduate Fellow, WWF-Canada Dalhousie University | Biology Dept. | 1459 Oxford Street |Halifax, NS | Canada B3H 4R2 Phone: 1-902-494-2478 | cell: 1-902-412-3404 |Fax: 1-902-494-3736 Email: godina at dal.ca | Skype: aureliegodinco | Web: wormlab.biology.dal.ca ---------------------------------------------------------------------------------------------------------------------------------------------------- Want to learn more about sharks in Atlantic Canada? Visit ShARCC! www.atlanticsharks.org From snes1982 at hotmail.com Sun Dec 4 14:18:21 2011 From: snes1982 at hotmail.com (nserdar) Date: Sun, 4 Dec 2011 05:18:21 -0800 (PST) Subject: [R] Linear quadratic Gaussian control with Kalman filter Message-ID: <1323004701350-4156813.post@n4.nabble.com> I need to generate Linear quadratic Gaussian control with Kalman filter in R programming. I only get matlab code. I think that R portfolio optimisation code ( quad..) is not adequate for this topic. Linear quadratic Gaussian control with Kalman filter http://en.wikipedia.org/wiki/Linear_quadratic_Gaussian_control Thanks. -- View this message in context: http://r.789695.n4.nabble.com/Linear-quadratic-Gaussian-control-with-Kalman-filter-tp4156813p4156813.html Sent from the R help mailing list archive at Nabble.com. From ngokangmin at gmail.com Sun Dec 4 14:38:29 2011 From: ngokangmin at gmail.com (Kang Min) Date: Sun, 4 Dec 2011 05:38:29 -0800 (PST) Subject: [R] Extract last 3 characters from numeric vector Message-ID: <2b0fce6a-ec23-4034-b80f-91e4a8440389@z1g2000yqa.googlegroups.com> Hi all, I have a numeric vector with 1 decimal place, and I'd like to extract the last 3 characters, including the decimal point. The vector ranges from 0 to 20. x <- round(runif(100)*20, digits=1) Some of numbers have 3 characters, and some have 4. I've read up on the substr() function but that extracts characters based on exact positions. How can I extract just the last 3 characters no matter the length of the number? e.g. from 16.7 I want 6.7, from 3.5 I want 3.5 as it is. Thanks, Kang Min From Miriam_Katharina at gmx.de Sun Dec 4 15:02:18 2011 From: Miriam_Katharina at gmx.de (Miriam ) Date: Sun, 04 Dec 2011 15:02:18 +0100 Subject: [R] problem merging data with different shapes Message-ID: <20111204140218.183110@gmx.net> I have been trying to merge datasets, one of which has a long format (Adata) and one has a (different) long format (Bdata): Adata Bdata subject order bpm subject order trial agegroup gender 1 1 70.2 1 1 3 2 1 1 1 69.5 1 2 1 2 1 1 1 68.8 1 3 2 2 1 1 2 69.1 2 1 2 1 2 1 2 70 2 2 3 1 2 1 2 70.5 2 3 1 1 2 1 3 70.2 ... 1 3 1 3 2 1 2 1 ... ... In the end I would like to have a dataset that contains A unchanged with the additional information from B added. subject order bpm trial agegroup gender 1 1 70.2 3 2 1 1 1 69.5 3 2 1 1 1 68.8 3 2 1 ... I have tried: newdataframe <- merge(Adata,Bdata, by= c("subject", "order"), sort = FALSE) For some reason, the trial column is not matched to the subject and order information, despite them being identified as key-variables for the merge. (The same is true for other variables, the actual dataset has more variables and trials, but this is essentially the problem.) So it results in something like: subject order bpm trial agegroup gender 1 1 70.2 3 2 1 1 1 69.5 2 2 1 1 1 68.8 1 2 1 What could be my mistake? Thank you VERY much. Miriam -- -- From gjones at sou.edu Sun Dec 4 15:27:30 2011 From: gjones at sou.edu (gvjones) Date: Sun, 4 Dec 2011 06:27:30 -0800 (PST) Subject: [R] Programming Statistical Functions In-Reply-To: <1280490786119-2307880.post@n4.nabble.com> References: <1280490786119-2307880.post@n4.nabble.com> Message-ID: <1323008850451-4157012.post@n4.nabble.com> Hello, Did you find anything helpful for calculating the statistical functions in your list. I would like to also calculate these and have been looking for some code to do so. Thanks -- View this message in context: http://r.789695.n4.nabble.com/Programming-Statistical-Functions-tp2307880p4157012.html Sent from the R help mailing list archive at Nabble.com. From svezakal at gmail.com Sun Dec 4 15:52:13 2011 From: svezakal at gmail.com (e eeyore) Date: Sun, 4 Dec 2011 15:52:13 +0100 Subject: [R] upper bound in the integrate function depends on a parameter In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From ligges at statistik.tu-dortmund.de Sun Dec 4 16:30:02 2011 From: ligges at statistik.tu-dortmund.de (Uwe Ligges) Date: Sun, 04 Dec 2011 16:30:02 +0100 Subject: [R] Vectorization instead of loops problem In-Reply-To: References: Message-ID: <4EDB91FA.1030200@statistik.tu-dortmund.de> On 04.12.2011 16:18, Costas Vorlow wrote: > Hello, > > I am having problems vectorizing the following (i/o using a for/next/while > loop): > > I have 2 sequences such as: > > x, y > 1, 30 > 2, -40 > 0, 50 > 0, 25 > 1, -5 > 2, -10 > 1, 5 > 0, 40 > > etc etc > > The first sequence (x) takes integer numbers only: 0, 1, 2 > The sequence y can be anything... > > I want to be able to retrieve (in a list if possible) the 3 last values of > the y sequence before a value of 1 is encountered on the x sequence, i.e: > > On line 5 in the above dataset, x is 1 so I need to capture values: 25, 50 > and -40 of the y sequence. > > So the outcome (if a list) should look something like: > > [1],[25,50,-40] > [2],[-10,-5,25] # as member #7 of x sequence is 1... > > etc. etc. > > Can I do the above avoiding for/next or while loops? > I am not sure I can explain it better. Any help/pointer extremely welcome. > > Best regards, > Costas > > One way is (assuming your data is in a data.frame called dat): wx <- which(dat$x==1) result <- lapply(wx[wx > 3], function(x) dat$y[x - (1:3)]) (where lapply is a loop, implicitly). Uwe Ligges From costas.vorlow at gmail.com Sun Dec 4 16:32:50 2011 From: costas.vorlow at gmail.com (Costas Vorlow) Date: Sun, 4 Dec 2011 17:32:50 +0200 Subject: [R] Vectorization instead of loops problem In-Reply-To: <4EDB91FA.1030200@statistik.tu-dortmund.de> References: <4EDB91FA.1030200@statistik.tu-dortmund.de> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From sarah.goslee at gmail.com Sun Dec 4 16:36:16 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Sun, 4 Dec 2011 10:36:16 -0500 Subject: [R] Extract last 3 characters from numeric vector In-Reply-To: <2b0fce6a-ec23-4034-b80f-91e4a8440389@z1g2000yqa.googlegroups.com> References: <2b0fce6a-ec23-4034-b80f-91e4a8440389@z1g2000yqa.googlegroups.com> Message-ID: You can use nchar() to get the length of the string, and use that in substring: mynum <- as.character(15.6) > substring(mynum, nchar(mynum)-2, nchar(mynum)) [1] "5.6" On Sun, Dec 4, 2011 at 8:38 AM, Kang Min wrote: > Hi all, > > I have a numeric vector with 1 decimal place, and I'd like to extract > the last 3 characters, including the decimal point. The vector ranges > from 0 to 20. > > x <- round(runif(100)*20, digits=1) > > Some of numbers have 3 characters, and some have 4. I've read up on > the substr() function but that extracts characters based on exact > positions. How can I extract just the last 3 characters no matter the > length of the number? e.g. from 16.7 I want 6.7, from 3.5 I want 3.5 > as it is. > > Thanks, > Kang Min > -- Sarah Goslee http://www.functionaldiversity.org From kindlychung at gmail.com Sun Dec 4 16:36:00 2011 From: kindlychung at gmail.com (Kaiyin Zhong) Date: Sun, 4 Dec 2011 23:36:00 +0800 Subject: [R] Complex multiple t tests in a data frame with several id factors Message-ID: I have assayed the concentrations of various metal elements in different anatomic regions of two strains of mice. Now, for each element, in each region, I want to do a t test to find whether there is any difference between the two strains. Here is what I did (using simulated data as an example): # create the data frame > elemconc = data.frame(expand.grid(id=1:3, geno=c('exp', 'wt'), region=c('brain', 'spine'), elem=c('fe', 'cu', 'zn')), conc=rnorm(36, 10)) > elemconc id geno region elem conc 1 1 exp brain fe 8.497498 2 2 exp brain fe 9.280944 3 3 exp brain fe 9.726271 4 1 wt brain fe 11.556397 5 2 wt brain fe 10.992550 6 3 wt brain fe 9.711200 7 1 exp spine fe 11.168603 8 2 exp spine fe 9.331127 9 3 exp spine fe 11.048226 10 1 wt spine fe 8.480867 11 2 wt spine fe 8.887062 12 3 wt spine fe 8.329797 13 1 exp brain cu 10.242652 14 2 exp brain cu 9.865984 15 3 exp brain cu 9.163728 16 1 wt brain cu 11.099385 17 2 wt brain cu 9.364261 18 3 wt brain cu 9.718322 19 1 exp spine cu 10.720157 20 2 exp spine cu 11.505430 21 3 exp spine cu 9.499359 22 1 wt spine cu 9.855950 23 2 wt spine cu 10.120489 24 3 wt spine cu 9.526252 25 1 exp brain zn 9.736196 26 2 exp brain zn 11.938710 27 3 exp brain zn 9.668625 28 1 wt brain zn 9.961574 29 2 wt brain zn 10.461621 30 3 wt brain zn 9.873667 31 1 exp spine zn 9.708067 32 2 exp spine zn 10.109309 33 3 exp spine zn 10.973387 34 1 wt spine zn 8.406536 35 2 wt spine zn 7.797746 36 3 wt spine zn 11.127984 # use tapply to aggregate > tapply(elemconc$conc, elemconc[c('elem', 'region')], function(x) x) region elem brain spine fe Numeric,6 Numeric,6 cu Numeric,6 Numeric,6 zn Numeric,6 Numeric,6 # check whether the order of data has been preserved after aggregation > x['fe', 'brain'] [[1]] [1] 8.497498 9.280944 9.726271 11.556397 10.992550 9.711200 # create an external factor for strain grouping > tmpgeno = rep(c('exp', 'wt'), each=3) > tmpgeno [1] "exp" "exp" "exp" "wt" "wt" "wt" # do the t test using the grouping factor > x = tapply(elemconc$conc, elemconc[c('elem', 'region')], function(x) t.test(x~tmpgeno) ) > x region elem brain spine fe List,9 List,9 cu List,9 List,9 zn List,9 List,9 I believe I have made no mistakes so far, but I wonder is there a better way of doing this? -- Kaiyin Zhong ------------------------------------------------------------------------------------------------------------------ Neuroscience Research Institute, Peking University, Beijing, P.R.China 100038 From ggrothendieck at gmail.com Sun Dec 4 16:41:14 2011 From: ggrothendieck at gmail.com (Gabor Grothendieck) Date: Sun, 4 Dec 2011 10:41:14 -0500 Subject: [R] Vectorization instead of loops problem In-Reply-To: References: Message-ID: On Sun, Dec 4, 2011 at 10:18 AM, Costas Vorlow wrote: > Hello, > > I am having problems vectorizing the following (i/o using a for/next/while > loop): > > I have 2 sequences such as: > > x, y > 1, 30 > 2, -40 > 0, 50 > 0, 25 > 1, -5 > 2, -10 > 1, 5 > 0, 40 > > etc etc > > The first sequence (x) takes integer numbers only: 0, 1, 2 > The sequence y can be anything... > > I want to be able to retrieve (in a list if possible) the 3 last values of > the y sequence before a value of 1 is encountered on the x sequence, i.e: > > On line 5 in the above dataset, x is 1 so I need to capture values: 25, 50 > and -40 of the y sequence. > > So the outcome (if a list) should look something like: > > [1],[25,50,-40] > [2],[-10,-5,25] # as member #7 of x sequence is 1... > > etc. etc. > > Can I do the above avoiding for/next or while loops? > I am not sure I can explain it better. Any help/pointer extremely welcome. Try this. embed(z, 4) places values 1,2,3,4 of vector z in the first row, values 2,3,4,5 in the second row and so on so we want the rows of embed(y, 4) for which embed(x, 4) is 1, i.e we want rows of embed(y, 4) for which embed(x, 4)[,1]==1, except the first column can be suppressed (-1). > embed(y, 4)[embed(x, 4)[, 1] == 1, -1] [,1] [,2] [,3] [1,] 25 50 -40 [2,] -10 -5 25 -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com From ligges at statistik.tu-dortmund.de Sun Dec 4 16:42:48 2011 From: ligges at statistik.tu-dortmund.de (Uwe Ligges) Date: Sun, 04 Dec 2011 16:42:48 +0100 Subject: [R] Extract last 3 characters from numeric vector In-Reply-To: <2b0fce6a-ec23-4034-b80f-91e4a8440389@z1g2000yqa.googlegroups.com> References: <2b0fce6a-ec23-4034-b80f-91e4a8440389@z1g2000yqa.googlegroups.com> Message-ID: <4EDB94F8.1040100@statistik.tu-dortmund.de> On 04.12.2011 14:38, Kang Min wrote: > Hi all, > > I have a numeric vector with 1 decimal place, and I'd like to extract > the last 3 characters, including the decimal point. The vector ranges > from 0 to 20. > > x<- round(runif(100)*20, digits=1) formatC(round(x%%10, 1), format="f", digits=1) Uwe Ligges > Some of numbers have 3 characters, and some have 4. I've read up on > the substr() function but that extracts characters based on exact > positions. How can I extract just the last 3 characters no matter the > length of the number? e.g. from 16.7 I want 6.7, from 3.5 I want 3.5 > as it is. > > Thanks, > Kang Min > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From gunter.berton at gene.com Sun Dec 4 16:45:57 2011 From: gunter.berton at gene.com (Bert Gunter) Date: Sun, 4 Dec 2011 07:45:57 -0800 Subject: [R] Vectorization instead of loops problem In-Reply-To: References: Message-ID: Costas: (and thanks for giving us your name) which(x == 1) gives you the indices where x is 1 (up to floating point equality -- you did not specify whether your x values are integers or calculated as floating point, and that certainly makes a difference). You can then use simple indexing to get the y values. No loops needed. However, let's explore why your question may have been too poorly formed to get the answer you seek: 1. What if the index of the first 1 is 3 or less? -- Do you want to ignore the (less than 3) preceding values or just choose as many as you can? 2. What if, as in your example, several 1's occur in x. Do you want the 3 preceding values for all of them or just the first? 3. If the answer to 2 is "all of them," what if several 1's are less than 3 indices apart -- do you want to include the overlapping sets of 3 y's -- or what? My point is that "etc. etc." is simply inadequate as a coherent or useful problem description in your post. You _must_ be explicit, complete, and concise. This can be hard. Indeed, it may require considerable thought and effort. I have found -- and others have often noted here -- that going through such an exercise itself often reveals a solution. But be that as it may, the Posting Guide is actually an excellent, comprehensive discussion of how to ask good questions in forums like this. Read it. Follow it. ... and to be fair, your post below is, imho, probably above average as posts go, allowing me to focus on specific points that I thought required clarification. Quite a few posts here of late have been so muddled and incoherent that I had no clue what the OP wanted. And it's not English as a second language. I am a language ignoramus and speak only English, so I am happy to tolerate poor grammar and vocabulary from someone for whom English is only one of several languages in which they can communicate. The problem is poor thinking, not poor English. Best, Bert On Sun, Dec 4, 2011 at 7:18 AM, Costas Vorlow wrote: > Hello, > > I am having problems vectorizing the following (i/o using a for/next/while > loop): > > I have 2 sequences such as: > > x, y > 1, 30 > 2, -40 > 0, 50 > 0, 25 > 1, -5 > 2, -10 > 1, 5 > 0, 40 > > etc etc > > The first sequence (x) takes integer numbers only: 0, 1, 2 > The sequence y can be anything... > > I want to be able to retrieve (in a list if possible) the 3 last values of > the y sequence before a value of 1 is encountered on the x sequence, i.e: > > On line 5 in the above dataset, x is 1 so I need to capture values: 25, 50 > and -40 of the y sequence. > > So the outcome (if a list) should look something like: > > [1],[25,50,-40] > [2],[-10,-5,25] # as member #7 of x sequence is 1... > > etc. etc. > > Can I do the above avoiding for/next or while loops? > I am not sure I can explain it better. Any help/pointer extremely welcome. > > Best regards, > Costas > > > -- > > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > |c|o|s|t|a|s|@|v|o|r|l|o|w|.|o|r|g| > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm From dwinsemius at comcast.net Sun Dec 4 16:47:48 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Sun, 4 Dec 2011 10:47:48 -0500 Subject: [R] upper bound in the integrate function depends on a parameter In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From bbolker at gmail.com Sun Dec 4 16:50:41 2011 From: bbolker at gmail.com (Ben Bolker) Date: Sun, 4 Dec 2011 15:50:41 +0000 Subject: [R] Logistic Regression with genetic component References: Message-ID: Danielle Duncan alaska.edu> writes: > Greetings, I have a question that I'd like to get input on. I have a > classic toxicology study where I artificially fertilized and exposed > embryos to a chemical and counted defects. In addition, I kept track of > male-female pairs that I used to artificially fertilize and generate > embryos with. I need to use logistic regression to model the response, but > also check that the genetics of the pairings did or did not have an effect > on the response. My data looks a bit like this: > > response matrix chemical concentration Genetic Matrix > Present Absent Male Female > 2 152 0.13 a 1 > 6 121 1 a 2 > 21 92 2 b 3 > 24 89 5 b 4 > 0 141 10 c 5 > 5 95 15 c 6 > > R code: > > DA<-cbind(Present, Absent) > glm<-(DA ~ chemical concentration) > > If I do glm<-(DA ~ chemical concentration + Male + Female, I get every > possible combination, but I only want specific pairs. So, I am thinking > about doing: > > MF<-cbind(Male, Female) > glm<-(DA ~ chemical concentration + MF) You're on the right track. paste() is probably what you want, although you can also use interaction() to get the interactions and then droplevels() to get rid of the unobserved crosses. d <- read.table(textConnection(" Present Absent conc Male Female 2 152 0.13 a 1 6 121 1 a 2 21 92 2 b 3 24 89 5 b 4 0 141 10 c 5 5 95 15 c 6"), header=TRUE) Either of these should give you what you want: d <- droplevels(transform(d,cross=interaction(Male,Female))) levels(d$cross) d <- transform(d,cross=paste(Male,Female,sep=".")) levels(d$cross) You should be a little careful -- if each cross is exposed only to a single concentration, and if you treat cross as a fixed effect, you will overparameterize your model. If you treat it as a random effect, e.g. using glmer in the lme4 package: glmer(cbind(Present,Absent)~conc+(1|cross),data=d) you will effectively be fitting a model for overdispersion (see the example in ?cbpp). From gunter.berton at gene.com Sun Dec 4 17:01:43 2011 From: gunter.berton at gene.com (Bert Gunter) Date: Sun, 4 Dec 2011 08:01:43 -0800 Subject: [R] Complex multiple t tests in a data frame with several id factors In-Reply-To: References: Message-ID: The concentrations of the different metals within an animal are correlated, so that doing as you suggest will almost certainly result in nonsense P values. So I suggest you seek local statistical help or, failing that, post on a statistical forum like stats.stackexchange.com . There are various multivariate packages -- check e.g. the ChemPhys and Multivariate task views -- that may be pertinent, but your post suggests that you probably need some help to use them. Ergo my suggestion above. Cheers, Bert On Sun, Dec 4, 2011 at 7:36 AM, Kaiyin Zhong wrote: > I have assayed the concentrations of various metal elements in > different anatomic regions of two strains of mice. Now, for each > element, in each region, I want to do a t test to find whether there > is any difference between the two strains. > > Here is what I did (using simulated data as an example): > > # create the data frame >> elemconc = data.frame(expand.grid(id=1:3, geno=c('exp', 'wt'), region=c('brain', 'spine'), elem=c('fe', 'cu', 'zn')), conc=rnorm(36, 10)) >> elemconc > ? id geno region elem ? ? ?conc > 1 ? 1 ?exp ?brain ? fe ?8.497498 > 2 ? 2 ?exp ?brain ? fe ?9.280944 > 3 ? 3 ?exp ?brain ? fe ?9.726271 > 4 ? 1 ? wt ?brain ? fe 11.556397 > 5 ? 2 ? wt ?brain ? fe 10.992550 > 6 ? 3 ? wt ?brain ? fe ?9.711200 > 7 ? 1 ?exp ?spine ? fe 11.168603 > 8 ? 2 ?exp ?spine ? fe ?9.331127 > 9 ? 3 ?exp ?spine ? fe 11.048226 > 10 ?1 ? wt ?spine ? fe ?8.480867 > 11 ?2 ? wt ?spine ? fe ?8.887062 > 12 ?3 ? wt ?spine ? fe ?8.329797 > 13 ?1 ?exp ?brain ? cu 10.242652 > 14 ?2 ?exp ?brain ? cu ?9.865984 > 15 ?3 ?exp ?brain ? cu ?9.163728 > 16 ?1 ? wt ?brain ? cu 11.099385 > 17 ?2 ? wt ?brain ? cu ?9.364261 > 18 ?3 ? wt ?brain ? cu ?9.718322 > 19 ?1 ?exp ?spine ? cu 10.720157 > 20 ?2 ?exp ?spine ? cu 11.505430 > 21 ?3 ?exp ?spine ? cu ?9.499359 > 22 ?1 ? wt ?spine ? cu ?9.855950 > 23 ?2 ? wt ?spine ? cu 10.120489 > 24 ?3 ? wt ?spine ? cu ?9.526252 > 25 ?1 ?exp ?brain ? zn ?9.736196 > 26 ?2 ?exp ?brain ? zn 11.938710 > 27 ?3 ?exp ?brain ? zn ?9.668625 > 28 ?1 ? wt ?brain ? zn ?9.961574 > 29 ?2 ? wt ?brain ? zn 10.461621 > 30 ?3 ? wt ?brain ? zn ?9.873667 > 31 ?1 ?exp ?spine ? zn ?9.708067 > 32 ?2 ?exp ?spine ? zn 10.109309 > 33 ?3 ?exp ?spine ? zn 10.973387 > 34 ?1 ? wt ?spine ? zn ?8.406536 > 35 ?2 ? wt ?spine ? zn ?7.797746 > 36 ?3 ? wt ?spine ? zn 11.127984 > > # use tapply to aggregate >> tapply(elemconc$conc, elemconc[c('elem', 'region')], function(x) x) > ? ?region > elem brain ? ? spine > ?fe Numeric,6 Numeric,6 > ?cu Numeric,6 Numeric,6 > ?zn Numeric,6 Numeric,6 > > # check whether the order of data has been preserved after aggregation >> x['fe', 'brain'] > [[1]] > [1] ?8.497498 ?9.280944 ?9.726271 11.556397 10.992550 ?9.711200 > > # create an external factor for strain grouping >> tmpgeno = rep(c('exp', 'wt'), each=3) >> tmpgeno > [1] "exp" "exp" "exp" "wt" ?"wt" ?"wt" > > # do the t test using the grouping factor >> x = tapply(elemconc$conc, elemconc[c('elem', 'region')], function(x) t.test(x~tmpgeno) ) >> x > ? ?region > elem brain ?spine > ?fe List,9 List,9 > ?cu List,9 List,9 > ?zn List,9 List,9 > > I believe I have made no mistakes so far, but I wonder is there a > better way of doing this? > > > -- > Kaiyin Zhong > ------------------------------------------------------------------------------------------------------------------ > Neuroscience Research Institute, Peking University, Beijing, P.R.China 100038 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm From svezakal at gmail.com Sun Dec 4 17:04:07 2011 From: svezakal at gmail.com (e eeyore) Date: Sun, 4 Dec 2011 17:04:07 +0100 Subject: [R] upper bound in the integrate function depends on a parameter In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From kindlychung at gmail.com Sun Dec 4 17:06:41 2011 From: kindlychung at gmail.com (Kaiyin Zhong) Date: Mon, 5 Dec 2011 00:06:41 +0800 Subject: [R] Complex multiple t tests in a data frame with several id factors In-Reply-To: References: Message-ID: Okay, thank you. On Mon, Dec 5, 2011 at 12:01 AM, Bert Gunter wrote: > The concentrations of the different metals within an animal are > correlated, so that doing as you suggest will almost certainly result > in nonsense P values. So I suggest you seek local statistical help or, > failing that, post on a statistical forum like stats.stackexchange.com > ?. > > There are ?various multivariate packages -- check e.g. the ChemPhys > and Multivariate task views -- that may be pertinent, but your post > suggests that you probably need some help to use them. Ergo my > suggestion above. > > Cheers, > Bert > > On Sun, Dec 4, 2011 at 7:36 AM, Kaiyin Zhong wrote: >> I have assayed the concentrations of various metal elements in >> different anatomic regions of two strains of mice. Now, for each >> element, in each region, I want to do a t test to find whether there >> is any difference between the two strains. >> >> Here is what I did (using simulated data as an example): >> >> # create the data frame >>> elemconc = data.frame(expand.grid(id=1:3, geno=c('exp', 'wt'), region=c('brain', 'spine'), elem=c('fe', 'cu', 'zn')), conc=rnorm(36, 10)) >>> elemconc >> ? id geno region elem ? ? ?conc >> 1 ? 1 ?exp ?brain ? fe ?8.497498 >> 2 ? 2 ?exp ?brain ? fe ?9.280944 >> 3 ? 3 ?exp ?brain ? fe ?9.726271 >> 4 ? 1 ? wt ?brain ? fe 11.556397 >> 5 ? 2 ? wt ?brain ? fe 10.992550 >> 6 ? 3 ? wt ?brain ? fe ?9.711200 >> 7 ? 1 ?exp ?spine ? fe 11.168603 >> 8 ? 2 ?exp ?spine ? fe ?9.331127 >> 9 ? 3 ?exp ?spine ? fe 11.048226 >> 10 ?1 ? wt ?spine ? fe ?8.480867 >> 11 ?2 ? wt ?spine ? fe ?8.887062 >> 12 ?3 ? wt ?spine ? fe ?8.329797 >> 13 ?1 ?exp ?brain ? cu 10.242652 >> 14 ?2 ?exp ?brain ? cu ?9.865984 >> 15 ?3 ?exp ?brain ? cu ?9.163728 >> 16 ?1 ? wt ?brain ? cu 11.099385 >> 17 ?2 ? wt ?brain ? cu ?9.364261 >> 18 ?3 ? wt ?brain ? cu ?9.718322 >> 19 ?1 ?exp ?spine ? cu 10.720157 >> 20 ?2 ?exp ?spine ? cu 11.505430 >> 21 ?3 ?exp ?spine ? cu ?9.499359 >> 22 ?1 ? wt ?spine ? cu ?9.855950 >> 23 ?2 ? wt ?spine ? cu 10.120489 >> 24 ?3 ? wt ?spine ? cu ?9.526252 >> 25 ?1 ?exp ?brain ? zn ?9.736196 >> 26 ?2 ?exp ?brain ? zn 11.938710 >> 27 ?3 ?exp ?brain ? zn ?9.668625 >> 28 ?1 ? wt ?brain ? zn ?9.961574 >> 29 ?2 ? wt ?brain ? zn 10.461621 >> 30 ?3 ? wt ?brain ? zn ?9.873667 >> 31 ?1 ?exp ?spine ? zn ?9.708067 >> 32 ?2 ?exp ?spine ? zn 10.109309 >> 33 ?3 ?exp ?spine ? zn 10.973387 >> 34 ?1 ? wt ?spine ? zn ?8.406536 >> 35 ?2 ? wt ?spine ? zn ?7.797746 >> 36 ?3 ? wt ?spine ? zn 11.127984 >> >> # use tapply to aggregate >>> tapply(elemconc$conc, elemconc[c('elem', 'region')], function(x) x) >> ? ?region >> elem brain ? ? spine >> ?fe Numeric,6 Numeric,6 >> ?cu Numeric,6 Numeric,6 >> ?zn Numeric,6 Numeric,6 >> >> # check whether the order of data has been preserved after aggregation >>> x['fe', 'brain'] >> [[1]] >> [1] ?8.497498 ?9.280944 ?9.726271 11.556397 10.992550 ?9.711200 >> >> # create an external factor for strain grouping >>> tmpgeno = rep(c('exp', 'wt'), each=3) >>> tmpgeno >> [1] "exp" "exp" "exp" "wt" ?"wt" ?"wt" >> >> # do the t test using the grouping factor >>> x = tapply(elemconc$conc, elemconc[c('elem', 'region')], function(x) t.test(x~tmpgeno) ) >>> x >> ? ?region >> elem brain ?spine >> ?fe List,9 List,9 >> ?cu List,9 List,9 >> ?zn List,9 List,9 >> >> I believe I have made no mistakes so far, but I wonder is there a >> better way of doing this? >> >> >> -- >> Kaiyin Zhong >> ------------------------------------------------------------------------------------------------------------------ >> Neuroscience Research Institute, Peking University, Beijing, P.R.China 100038 >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > > > -- > > Bert Gunter > Genentech Nonclinical Biostatistics > > Internal Contact Info: > Phone: 467-7374 > Website: > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm -- Kaiyin Zhong ------------------------------------------------------------------------------------------------------------------ Neuroscience Research Institute, Peking University, Beijing, P.R.China 100038 From dwinsemius at comcast.net Sun Dec 4 17:07:04 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Sun, 4 Dec 2011 11:07:04 -0500 Subject: [R] Programming Statistical Functions In-Reply-To: <1323008850451-4157012.post@n4.nabble.com> References: <1280490786119-2307880.post@n4.nabble.com> <1323008850451-4157012.post@n4.nabble.com> Message-ID: <4087A7AF-278C-45EE-9FDB-6613A711711B@comcast.net> On Dec 4, 2011, at 9:27 AM, gvjones wrote: > Hello, > > Did you find anything helpful for calculating the statistical > functions in > your list. I would like to also calculate these and have been > looking for > some code to do so. > A search at the site linked by the R function RSiteSearch() produces two (or more) candidate packages. Rather than naming them, I think it good exercise to do the looking and judging by yourself: http://search.r-project.org/cgi-bin/namazu.cgi?query=meteorology&max=100&result=normal&sort=score&idxname=functions&idxname=Rhelp08&idxname=Rhelp10&idxname=Rhelp02 -- David Winsemius, MD West Hartford, CT From dwinsemius at comcast.net Sun Dec 4 17:15:36 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Sun, 4 Dec 2011 11:15:36 -0500 Subject: [R] upper bound in the integrate function depends on a parameter In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From shyamabc2002 at yahoo.com Sun Dec 4 17:22:03 2011 From: shyamabc2002 at yahoo.com (shyam basnet) Date: Sun, 4 Dec 2011 08:22:03 -0800 (PST) Subject: [R] prediction in "conmode" class of Nonparametric binary models Message-ID: <1323015723.35294.YahooMailNeo@web161705.mail.bf1.yahoo.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From svezakal at gmail.com Sun Dec 4 17:23:26 2011 From: svezakal at gmail.com (e eeyore) Date: Sun, 4 Dec 2011 17:23:26 +0100 Subject: [R] upper bound in the integrate function depends on a parameter In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From janko.thyson.rstuff at googlemail.com Sun Dec 4 17:32:25 2011 From: janko.thyson.rstuff at googlemail.com (Janko Thyson) Date: Sun, 04 Dec 2011 17:32:25 +0100 Subject: [R] How to write (complex) coercion methods or "what's the reason to limit 'setAs()' the way it is limited"? Message-ID: <4EDBA099.6040306@googlemail.com> Dear list, I'd like to write coercion methods for some of my Reference Classes. However, using 'setAs()' is not a real option as its argument 'def' only allows for functions depending on one single argument. In some cases, that is simply too much of a limitation for me. And I don't really see why it needs to be this way, so I guess this question is also some sort of a feature request to make 'setAs' a bit more flexible (in case anyone from the Core Team is listening ;-)) A reproducible example can be found here: http://stackoverflow.com/questions/8346654/how-to-write-coercion-methods Thanks a lot for any replies! Janko From jorgeivanvelez at gmail.com Sun Dec 4 17:46:32 2011 From: jorgeivanvelez at gmail.com (Jorge I Velez) Date: Sun, 4 Dec 2011 11:46:32 -0500 Subject: [R] upper bound in the integrate function depends on a parameter In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From bps0002 at auburn.edu Sun Dec 4 18:23:36 2011 From: bps0002 at auburn.edu (B77S) Date: Sun, 4 Dec 2011 09:23:36 -0800 (PST) Subject: [R] problem merging data with different shapes In-Reply-To: <20111204140218.183110@gmx.net> References: <20111204140218.183110@gmx.net> Message-ID: <1323019416195-4157442.post@n4.nabble.com> Please use dput() to post your example data sets. dput(Adata) dput(Bdata) **then copy and paste the results of each so that we can "play" around with it easily. Miriam -2 wrote > > I have been trying to merge datasets, one of which has a long format > (Adata) and one has a (different) long format (Bdata): > > Adata Bdata > subject order bpm subject order trial agegroup gender > 1 1 70.2 1 1 3 2 1 > 1 1 69.5 1 2 1 2 1 > 1 1 68.8 1 3 2 2 1 > 1 2 69.1 2 1 2 1 2 > 1 2 70 2 2 3 1 2 > 1 2 70.5 2 3 1 1 2 > 1 3 70.2 ... > 1 3 > 1 3 > 2 1 > 2 1 > ... ... > > In the end I would like to have a dataset that contains A unchanged with > the additional information from B added. > > subject order bpm trial agegroup gender > 1 1 70.2 3 2 1 > 1 1 69.5 3 2 1 > 1 1 68.8 3 2 1 > ... > I have tried: > newdataframe <- merge(Adata,Bdata, by= c("subject", "order"), sort = > FALSE) > > For some reason, the trial column is not matched to the subject and order > information, despite them being identified as key-variables for the merge. > (The same is true for other variables, the actual dataset has more > variables and trials, but this is essentially the problem.) > So it results in something like: > subject order bpm trial agegroup gender > 1 1 70.2 3 2 1 > 1 1 69.5 2 2 1 > 1 1 68.8 1 2 1 > > What could be my mistake? > > Thank you VERY much. > Miriam > > > -- > > > > > -- > > ______________________________________________ > R-help@ mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- View this message in context: http://r.789695.n4.nabble.com/problem-merging-data-with-different-shapes-tp4157137p4157442.html Sent from the R help mailing list archive at Nabble.com. From GodinA at Dal.Ca Sun Dec 4 18:37:54 2011 From: GodinA at Dal.Ca (Aurelie Cosandey Godin) Date: Sun, 4 Dec 2011 13:37:54 -0400 Subject: [R] Polishing my geom_bar for publication In-Reply-To: References: <4E7779FE.7080203@gmail.com> <4E787B7B.2010900@gmail.com> <3467C1A6-020E-4E84-A456-C9BF8B964E8A@Dal.Ca> Message-ID: <05E468B5-55D6-4A71-99A3-2603DBF31893@Dal.Ca> Sorry Dennis, Didn't realized I went off the list! I found a solution for one of my problem: removing x-axis label! with this code: ggplot(Final2, aes(x=spp, y=WPUE, fill=season)) + geom_bar(position=position_dodge()) + geom_errorbar(aes(ymin=WPUE-wpue.se, ymax=WPUE+wpue.se), size=.3,width=.2,position=position_dodge(.9)) + scale_x_discrete("", breaks=c("102","90","91","94","96"), labels= rep("", 5)) + ylab("Biomass (Weight (kg)/tow)") + scale_fill_grey(name="Survey season", breaks=c("summer", "winter"), labels=c("Spring", "Fall"))+ coord_flip() + theme_bw() + opts(axis.title.x = theme_text(size = 10), panel.grid.minor = theme_blank()) However, I am still trying to figure out how to fix the width of my two plots on my final pdf. I would appreciate any help on this! Thank you. On 2011-12-04, at 12:59 PM, Aurelie Cosandey Godin wrote: > Thank you Denis, > > I changed my code as you suggested, however the "xlab" didn't work & I tried something else (see below my new code), but I still get my labels for my x-axis (coord_flip) in my b figure ("spp" 96, 94, 91, etc...). See figure below. > To answer your question, I would like that both of my figure a & b have the same width on the final pdf. Right now they aren't because of the legend. >> >> and (3) fix the width, such that both figures >>> have the same appearance regardless of the legend. >> >> I'm afraid I don't understand clearly what you mean my 'same >> appearance'. Could you provide a reproducible example, which includes >> (possibly fake) data as well as code? > > > > Here's my new code: > > (a<- ggplot(Final2, aes(x=spp, y=CPUE, fill=season)) + > geom_bar(position=position_dodge()) + > geom_errorbar(aes(ymin=CPUE-cpue.se, ymax=CPUE+cpue.se), > size=.3, width=.2, > position=position_dodge(.9)) + scale_x_discrete("Species", > breaks=c("102","90","91","94","96"), > labels=c("SPINYTAIL","THORNY","SMOOTH","DEEPWATER","JENSEN'S")) + ylab("Abundance (fish/tow)") + coord_flip() + > scale_fill_grey() + theme_bw() + opts(axis.title.x = > theme_text(size = 10), panel.grid.minor = theme_blank(), > legend.position='none') ) > > ##I added scale_x_discrete(NULL, breaks=c("102","90","91","94","96"), labels= rep(NULL, 5)) thinking that this would be able to remove my x-axis label (coord_flip) but it didn't... any other ideas of how I can achieve this? > > (b<- ggplot(Final2, aes(x=spp, y=WPUE, fill=season)) + geom_bar(position=position_dodge()) + geom_errorbar(aes(ymin=WPUE-wpue.se, ymax=WPUE+wpue.se), size=.3,width=.2,position=position_dodge(.9)) + scale_x_discrete(NULL, breaks=c("102","90","91","94","96"), labels= rep(NULL, 5)) + ylab("Biomass (Weight (kg)/tow)") + scale_fill_grey(name="Survey season", breaks=c("summer", "winter"), labels=c("Spring", "Fall"))+ coord_flip() + theme_bw() + opts(axis.title.x = theme_text(size = 10), panel.grid.minor = theme_blank()) ) > > pdf("polishing-layout3.pdf", width = 10, height = 6) > grid.newpage() > pushViewport(viewport(layout = grid.layout(1, 2))) > vplayout <- function(x, y) > viewport(layout.pos.row = x, layout.pos.col = y) > print(a, vp = vplayout(1, 1)) > print(b, vp = vplayout(1, 2)) > dev.off() > > > > Thank you very much! > Aurelie > > On 2011-12-04, at 11:33 AM, Dennis Murphy wrote: > >> Hi: >> >> On Sun, Dec 4, 2011 at 5:21 AM, Aurelie Cosandey Godin wrote: >>> Dear list, >>> >>> I am new with ggplot2 and I have spend quiet some time putting together the >>> following code to create the attached plot. However there's still a few >>> things that I'm having trouble with! >>> I would be grateful if someone can tell me how to fix (1) the colour of my >>> bars into grey scales >> >> One way is to provide greyscale values to scale_fill_discrete; e.g., >> values = c("grey50","grey20") >> >>> (2) removing the y-axis (species name) on the right >>> figure to avoid duplication, >> >> In the second figure, insert either >> ylab("") >> or if you have a labs() statement that defines several titles at once, >> labs(..., y = "", ...) >> >> and (3) fix the width, such that both figures >>> have the same appearance regardless of the legend. >> >> I'm afraid I don't understand clearly what you mean my 'same >> appearance'. Could you provide a reproducible example, which includes >> (possibly fake) data as well as code? >> >> Dennis >>> >>> Thank you very much in advance! >>> >>> -- >>> You received this message because you are subscribed to the ggplot2 mailing >>> list. >>> Please provide a reproducible example: http://gist.github.com/270442 >>> >>> To post: email ggplot2 at googlegroups.com >>> To unsubscribe: email ggplot2+unsubscribe at googlegroups.com >>> More options: http://groups.google.com/group/ggplot2 >>> >>> >>> The code is as follow: >>> >>> >>> (a<-ggplot(Final2, aes(x=spp, y=CPUE, fill=season)) + >>> geom_bar(position=position_dodge()) + >>> geom_errorbar(aes(ymin=CPUE-cpue.se, ymax=CPUE+cpue.se), >>> size=.3, >>> width=.2, >>> position=position_dodge(.9)) + >>> xlab("Species") + >>> scale_x_discrete(breaks=c("100","102","107","88","90","91","92","93","94","96","98","99"), >>> labels=c("WINTER","SPINYTAIL","BIGELOW'S","SKATES >>> (NS)","THORNY","SMOOTH","ABYSSAL","LITTLE","DEEPWATER","JENSEN'S","WHITE","SOFT")) >>> + >>> ylab("Abundance (fish/tow)") + coord_flip() + >>> theme_bw() + opts(axis.title.x = theme_text(size = 10)) + >>> opts(panel.grid.minor = theme_blank()) + opts(legend.position='none') ) >>> >>> (b<-ggplot(Final2, aes(x=spp, y=WPUE, fill=season)) + >>> geom_bar(position=position_dodge()) + >>> geom_errorbar(aes(ymin=WPUE-wpue.se, ymax=WPUE+wpue.se), >>> size=.3, >>> width=.2, >>> position=position_dodge(.9)) + xlab(NULL)+ >>> scale_x_discrete(breaks=c("100","102","107","88","90","91","92","93","94","96","98","99"), >>> labels=c("WINTER","SPINYTAIL","BIGELOW'S","SKATES >>> (NS)","THORNY","SMOOTH","ABYSSAL","LITTLE","DEEPWATER","JENSEN'S","WHITE","SOFT"))+ >>> ylab("Biomass (Weight (kg)/tow)") + scale_fill_hue(name="Survey season", >>> # Legend label, use darker colors >>> breaks=c("summer", "winter"), >>> labels=c("Spring", "Fall")) + coord_flip() + >>> theme_bw() + opts(axis.title.x = theme_text(size = 10)) + >>> opts(panel.grid.minor = theme_blank())) >>> >>> pdf("polishing-layout2.pdf", width = 10, height = 6) >>> grid.newpage() >>> pushViewport(viewport(layout = grid.layout(1, 2))) >>> vplayout <- function(x, y) >>> viewport(layout.pos.row = x, layout.pos.col = y) >>> print(a, vp = vplayout(1, 1)) >>> print(b, vp = vplayout(1, 2)) >>> dev.off() >>> >>> >>> Aurelie Cosandey-Godin >>> Ph.D. student, Department of Biology >>> Industrial Graduate Fellow, WWF-Canada >>> >>> Dalhousie University | Biology Dept. | 1459 Oxford Street | >>> Halifax, NS | >>> Canada >>> B3H 4R2 >>> >>> Phone: 1-902-494-2478 | >>> cell: 1-902-412-3404 | >>> Fax: 1-902-494-3736 >>> Email: godina at dal.ca | Skype: aureliegodinco | >>> Web: wormlab.biology.dal.ca >>> ---------------------------------------------------------------------------------------------------------------------------------------------------- >>> Want to learn more about sharks in Atlantic Canada? Visit >>> ShARCC! www.atlanticsharks.org >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >> >> -- >> You received this message because you are subscribed to the ggplot2 mailing list. >> Please provide a reproducible example: http://gist.github.com/270442 >> >> To post: email ggplot2 at googlegroups.com >> To unsubscribe: email ggplot2+unsubscribe at googlegroups.com >> More options: http://groups.google.com/group/ggplot2 >> > From bps0002 at auburn.edu Sun Dec 4 18:55:13 2011 From: bps0002 at auburn.edu (B77S) Date: Sun, 4 Dec 2011 09:55:13 -0800 (PST) Subject: [R] Export cols to single csv files In-Reply-To: <1323020175364-4157484.post@n4.nabble.com> References: <1323020175364-4157484.post@n4.nabble.com> Message-ID: <1323021313888-4157537.post@n4.nabble.com> just use indexing. without doing it all for you... df <- structure(list(AA = c(0.3, 0.1, 0.6), BB = c(0.9, 0.4, 0.2), CC = c(1, 0.8, 0.6), DD = c(0.7, 0.5, 0.5)), .Names = c("AA", "BB", "CC", "DD"), class = "data.frame", row.names = c(NA, -3L )) write.csv(df[,1], paste(colnames(df[1]), "csv", sep=".")) Chega wrote > > Hi > > I am trying to "batch export" the columns of a numeric matrix to separate > csv files by naming them according to the column names. > > So my matrix in R looks like this: > AA BB CC DD etc. > 1: 0.3 0.9 1.0 0.7 ... > 2: 0.1 0.4 0.8 0.5 ... > 3: 0.6 0.2 0.6 0.5 ... > etc. > > Now I am looking for a way to get these files (file names in quotes): > > "AA.csv" "BB.csv" "CC.csv" etc. > 1: 0.3 1: 0.9 1: 1.0 > 2: 0.1 2: 0.4 2: 0.8 > 3: 0.6 3: 0.2 3: 0.6 > etc. etc. etc. > > As I understand this may be done using write.csv and a loop with the > column names, but I have no idea how to export single columns. > > Thanks i.a. for help! > Chega > -- View this message in context: http://r.789695.n4.nabble.com/Export-cols-to-single-csv-files-tp4157484p4157537.html Sent from the R help mailing list archive at Nabble.com. From costas.vorlow at gmail.com Sun Dec 4 19:29:25 2011 From: costas.vorlow at gmail.com (Costas Vorlow) Date: Sun, 4 Dec 2011 20:29:25 +0200 Subject: [R] Vectorization instead of loops problem In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From vamshi999 at gmail.com Sun Dec 4 19:00:40 2011 From: vamshi999 at gmail.com (vamshi999) Date: Sun, 4 Dec 2011 10:00:40 -0800 (PST) Subject: [R] equating approximate values Message-ID: <1323021640135-4157551.post@n4.nabble.com> Hello List, I am having trouble finding the command for my problem. I have two arrays x and y. now i would like to compare the values of x and y and then get the index of x which is exactly or approximately equal(+/- some value ) to the values in y. x <- runif(100,min=0,max=5) y <- runif(10,min=0,max=5) the threshold value(+/-) value can vary. for this example lets take it to be .5 I know the regular method of doing this by writing different if and for loops. But i have very big dataframe the computation time is very high for this method. can anyone please tell me if there any functions to do this. thank you for your help. -- View this message in context: http://r.789695.n4.nabble.com/equating-approximate-values-tp4157551p4157551.html Sent from the R help mailing list archive at Nabble.com. From astareh at hotmail.com Sun Dec 4 19:11:05 2011 From: astareh at hotmail.com (set) Date: Sun, 4 Dec 2011 10:11:05 -0800 (PST) Subject: [R] similarity matrix Message-ID: <1323022265536-4157576.post@n4.nabble.com> Hello R-users, I've got a file with individuals as colums and the clusters where they occur in as rows. And I wanted a similarity matrix which tells me how many times each individual occurs with another. My eventual goal is to make Venn-diagrams from the occurence of my individuals. So I've this: cluster ind1 ind2 ind3 etc. 1 0 1 2 2 3 0 1 3 1 1 1 And I want to go to this: ind1 ind2 ind3 ind1 0 4 2 ind2 4 0 4 ind3 2 4 1 is there a way to do this? Thank you for your help -- View this message in context: http://r.789695.n4.nabble.com/similarity-matrix-tp4157576p4157576.html Sent from the R help mailing list archive at Nabble.com. From michael.weylandt at gmail.com Sun Dec 4 19:41:37 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt ) Date: Sun, 4 Dec 2011 13:41:37 -0500 Subject: [R] RODBC connect to Excel (64-bit Windows 7) In-Reply-To: References: Message-ID: <661B37ED-93B1-4434-ADE8-19FC1DE99D05@gmail.com> Do you need to use RODBC specifically? I've been using XLConnect quite a lot recently and have been quite pleased with it. Michael On Dec 4, 2011, at 9:40 AM, andrija djurovic wrote: > Hi to all. > I have a problem to connect to an Excel database using RODBC. > Namely, I am using 64-bit R 2.14.0, under Windows 7 and I tried following: > library(RODBC) >> channel <- odbcConnectExcel("results.xlsx") > Error in odbcConnectExcel("results.xlsx") : > odbcConnectExcel is only usable with 32-bit Windows # ok this is > clear why it doesn't work >> channel <- odbcConnectExcel2007("results.xlsx") # this was > one of proposals from old R help posts, but it doesn't work for me > Warning messages: > 1: In odbcDriverConnect(con, tabQuote = c("[", "]"), ...) : > [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver > Manager] Data source name not found and no default driver specified > 2: In odbcDriverConnect(con, tabQuote = c("[", "]"), ...) : > ODBC connection failed > > After that as it suggested in R data import/export manual I > installed AccessDatabaseEngine.exe. Also I used ODBC in > c:\Windows\SysWOW64\odbcad32 to create data source called result. I check > if it is created: >> odbcDataSources() > dBASE Files > "Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)" > MS Access Database > "Microsoft Access Driver (*.mdb, *.accdb)" > Excel file > "Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)" > * results* > "Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)" > > and tried again but it doesn't work: > >> channel <- odbcDriverConnect() > Warning messages: > 1: In odbcDriverConnect() : > [RODBC] ERROR: state IM014, code 0, message [Microsoft][ODBC Driver > Manager] The specified DSN contains an architecture mismatch between the > Driver and Application > 2: In odbcDriverConnect() : ODBC connection failed > > > Could someone guide me what should I try next to fix a problem? Is this > some problem with Drivers or not? > > Thanks in advance > > Andrija > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From djandrija at gmail.com Sun Dec 4 20:04:43 2011 From: djandrija at gmail.com (andrija djurovic) Date: Sun, 4 Dec 2011 20:04:43 +0100 Subject: [R] RODBC connect to Excel (64-bit Windows 7) In-Reply-To: <661B37ED-93B1-4434-ADE8-19FC1DE99D05@gmail.com> References: <661B37ED-93B1-4434-ADE8-19FC1DE99D05@gmail.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From djandrija at gmail.com Sun Dec 4 20:24:24 2011 From: djandrija at gmail.com (andrija djurovic) Date: Sun, 4 Dec 2011 20:24:24 +0100 Subject: [R] equating approximate values In-Reply-To: <1323021640135-4157551.post@n4.nabble.com> References: <1323021640135-4157551.post@n4.nabble.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From bps0002 at auburn.edu Sun Dec 4 20:39:22 2011 From: bps0002 at auburn.edu (B77S) Date: Sun, 4 Dec 2011 11:39:22 -0800 (PST) Subject: [R] similarity matrix In-Reply-To: <1323022265536-4157576.post@n4.nabble.com> References: <1323022265536-4157576.post@n4.nabble.com> Message-ID: <1323027562692-4157840.post@n4.nabble.com> I apologize to the list and you if I am mis-understanding something, but... As an example: ind2 occurs with ind1 only in cluster#3, so why does it get a value of 4 in your "similarity" matrix? Also, if this isn't a recognized similarity algorithm, perhaps you should at the very least put quotes around "similarity". Again, sorry if I am confused here. set wrote > > Hello R-users, > > I've got a file with individuals as colums and the clusters where they > occur in as rows. And I wanted a similarity matrix which tells me how many > times each individual occurs with another. My eventual goal is to make > Venn-diagrams from the occurence of my individuals. > > So I've this: > > cluster ind1 ind2 ind3 etc. > 1 0 1 2 > 2 3 0 1 > 3 1 1 1 > > And I want to go to this: > ind1 ind2 ind3 > ind1 0 4 2 > ind2 4 0 4 > ind3 2 4 1 > > is there a way to do this? > Thank you for your help > -- View this message in context: http://r.789695.n4.nabble.com/similarity-matrix-tp4157576p4157840.html Sent from the R help mailing list archive at Nabble.com. From gunter.berton at gene.com Sun Dec 4 21:07:48 2011 From: gunter.berton at gene.com (Bert Gunter) Date: Sun, 4 Dec 2011 12:07:48 -0800 Subject: [R] Vectorization instead of loops problem In-Reply-To: References: Message-ID: Inline below On Sun, Dec 4, 2011 at 10:29 AM, Costas Vorlow wrote: > Dear Bert, > > You are right (obviously). > > Apologies for any inconvenience caused. ?I thought my problem was simplistic > with a very obvious answer which eluded me. > > As per your justified questions : > > 2: Answer is "all", > > hence: > > 3. would be include overlapping set (I guess) but this does not matter for > the time being. I didn't give it too much thought?admittedly... If I got 1 & > 2 right I could have modified the code for point 3 (if answer in 2 != > "all'), so I did not consider it when I was?formulating?my query. However, I > can see now why this is confusing. > > Anyways, thanks again for the pointers. > > BTW, is there a good & quick read/guide on vectorization in R that one could > recommend? That would minimize my queries at least in the list. :-) Vectorization is a central paradigm in R, so practically all books on the S language discuss this. The "R language definition" manual that ships with R is pretty comprehensive, but V&R's MASS or S Programming Books, Patrick Burns's website tutorials (he has several well suited for beginners), John Chambers's "Programming with R " , etc. are just a few among many. It is impossible for me to be more specific than that. -- Bert > > Apologies again and best regards, > Costas > > On 4 December 2011 17:45, Bert Gunter wrote: >> >> Costas: (and thanks for giving us your name) >> >> which(x == 1) >> >> gives you the indices where x is 1 (up to floating point equality -- >> you did not specify whether your x values are integers or calculated >> as floating point, and that certainly makes a difference). You can >> then use simple indexing to get the y values. No loops needed. >> >> However, let's explore why your question may have been too poorly >> formed to get the answer you seek: >> >> 1. What if the index of the first 1 is 3 or less? -- Do you want to >> ignore the (less than 3) preceding values or just choose as many as >> you can? >> >> 2. What if, as in your example, several 1's occur in x. Do you want >> the 3 preceding values for all of them or just the first? >> >> 3. If the answer to 2 is "all of them," what if several 1's are less >> than 3 indices apart -- do you want to include the overlapping sets of >> 3 y's -- or what? >> >> My point is that "etc. etc." is simply inadequate as a coherent or >> useful problem description in your post. You _must_ be explicit, >> complete, and concise. This can be hard. Indeed, it may require >> considerable thought and effort. I have found -- and others have often >> noted here -- that going through such an exercise itself often reveals >> a solution. But be that as it may, the Posting Guide is actually an >> excellent, comprehensive discussion of how to ask good questions in >> forums like this. Read it. Follow it. >> >> ... and to be fair, your post below is, imho, probably above average >> as posts go, allowing me to focus on specific points that I thought >> required clarification. Quite a few posts here of late have been so >> muddled and incoherent that I had no clue what the OP wanted. And it's >> not English as a second language. I am a language ignoramus and speak >> only English, so I am happy to tolerate poor grammar and vocabulary >> from someone for whom English is only one of several languages in >> which they can communicate. The problem is poor thinking, not poor >> English. >> >> Best, >> Bert >> >> On Sun, Dec 4, 2011 at 7:18 AM, Costas Vorlow >> wrote: >> > Hello, >> > >> > I am having problems vectorizing the following (i/o using a >> > for/next/while >> > loop): >> > >> > I have 2 sequences such as: >> > >> > x, y >> > 1, 30 >> > 2, -40 >> > 0, 50 >> > 0, 25 >> > 1, -5 >> > 2, -10 >> > 1, 5 >> > 0, 40 >> > >> > etc etc >> > >> > The first sequence (x) takes integer numbers only: 0, 1, 2 >> > The sequence y can be anything... >> > >> > I want to be able to retrieve (in a list if possible) the 3 last values >> > of >> > the y sequence before a value of 1 is encountered on the x sequence, >> > i.e: >> > >> > On line 5 in the above dataset, x is 1 so I need to capture values: 25, >> > 50 >> > and -40 of the y sequence. >> > >> > So the outcome (if a list) should look something like: >> > >> > [1],[25,50,-40] >> > [2],[-10,-5,25] # as member #7 of x sequence is 1... >> > >> > etc. etc. >> > >> > Can I do the above avoiding for/next or while loops? >> > I am not sure I can explain it better. Any help/pointer extremely >> > welcome. >> > >> > Best regards, >> > Costas >> > >> > >> > -- >> > >> > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >> > |c|o|s|t|a|s|@|v|o|r|l|o|w|.|o|r|g| >> > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >> > >> > ? ? ? ?[[alternative HTML version deleted]] >> > >> > ______________________________________________ >> > R-help at r-project.org mailing list >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guide >> > http://www.R-project.org/posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code. >> >> >> >> -- >> >> Bert Gunter >> Genentech Nonclinical Biostatistics >> >> Internal Contact Info: >> Phone: 467-7374 >> Website: >> >> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm > > > > > -- > > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > |c|o|s|t|a|s|@|v|o|r|l|o|w|.|o|r|g| > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm From aurelien.philippot at gmail.com Sun Dec 4 21:32:28 2011 From: aurelien.philippot at gmail.com (=?ISO-8859-1?Q?Aur=E9lien_PHILIPPOT?=) Date: Sun, 4 Dec 2011 12:32:28 -0800 Subject: [R] Group several variables and apply a function to the group Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From mazatlanmexico at yahoo.com Sun Dec 4 21:51:22 2011 From: mazatlanmexico at yahoo.com (Felipe Carrillo) Date: Sun, 4 Dec 2011 12:51:22 -0800 (PST) Subject: [R] Group several variables and apply a function to the group In-Reply-To: References: Message-ID: <1323031882.21881.YahooMailNeo@web125506.mail.ne1.yahoo.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From aurelien.philippot at gmail.com Sun Dec 4 21:55:41 2011 From: aurelien.philippot at gmail.com (=?ISO-8859-1?Q?Aur=E9lien_PHILIPPOT?=) Date: Sun, 4 Dec 2011 12:55:41 -0800 Subject: [R] Group several variables and apply a function to the group In-Reply-To: <1323031882.21881.YahooMailNeo@web125506.mail.ne1.yahoo.com> References: <1323031882.21881.YahooMailNeo@web125506.mail.ne1.yahoo.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From Peter.Brecknock at bp.com Sun Dec 4 21:56:31 2011 From: Peter.Brecknock at bp.com (Pete Brecknock) Date: Sun, 4 Dec 2011 12:56:31 -0800 (PST) Subject: [R] Group several variables and apply a function to the group In-Reply-To: References: Message-ID: <1323032191189-4158090.post@n4.nabble.com> Aur?lien PHILIPPOT wrote > > Dear R-experts, > I am struggling with the following problem, and I am looking for advice > from more experienced R-users: I have a data frame with 2 identifying > variables (comn and mi), and an output variable (x). comn is a variable > for > a company and mi is a variable for a month. > > comn<-c("abc", "abc", "abc", "abc", "abc", "abc", "xyz", "xyz","xyz", > "xyz") > mi<- c("1", "1","1", "2", "2", "2", "1", "1", "3", "3") > x<- c("-0.0031", "0.0009", "-0.007", "0.1929","0.0087", "0.099","-0.089", > "0.005", "-0.0078", "0.67" ) > df<- data.frame(comn=comn, mi=mi, x=x) > > > For each company, within a particular month, I would like to compute the > standard deviation of x: for example, for abc, I would like to compute the > sd of x for month1 (when mi=1) and for month2 (when mi=2). > > In other languages (Stata for instance), I would create a grouping > variable > (group comnn and mi) and then, apply the sd function for each group. > > However, I don't find an elegant way to do the same in R: > > I was thinking about the following: I could subset my data frame by mi and > create one file per month, and then make a loop and in each file, use a > "by" operator for each comn. I am sure it would work, but I feel that it > would be like killing an ant with a tank. > > I was wondering if anyone knew a more straightforward way to implement > that > kind of operation? > > Thanks a lot, > > Best, > Aurelien > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@ mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > One way would be to use the aggregate function. # Your Data ... # Note: I have removed the quotes off the output variable x comn<-c("abc", "abc", "abc", "abc", "abc", "abc", "xyz", "xyz","xyz", "xyz") mi<- c("1", "1","1", "2", "2", "2", "1", "1", "3", "3") x<- c(-0.0031, 0.0009, -0.007, 0.1929,0.0087, 0.099,-0.089, 0.005, -0.0078, 0.67) df<- data.frame(comn=comn, mi=mi, x=x) # Aggregate Function aggregate(df$x, by=list(df$comn,df$mi),FUN=sd) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/Group-several-variables-and-apply-a-function-to-the-group-tp4158017p4158090.html Sent from the R help mailing list archive at Nabble.com. From jrkrideau at yahoo.ca Sun Dec 4 22:07:04 2011 From: jrkrideau at yahoo.ca (John Kane) Date: Sun, 4 Dec 2011 13:07:04 -0800 (PST) Subject: [R] Group several variables and apply a function to the group In-Reply-To: Message-ID: <1323032824.66527.YahooMailClassic@web38408.mail.mud.yahoo.com> ?aggregate should do it aggregate(df$x,list(df$comn, df$mi), sd) There are other ways of course Using the reshape2 package library(reshape2) x1 <- melt(df, id=c("comn", "mi")) dcast(x1, comn + mi ~ variable, sd) --- On Sun, 12/4/11, Aur?lien PHILIPPOT wrote: > From: Aur?lien PHILIPPOT > Subject: [R] Group several variables and apply a function to the group > To: R-help at r-project.org > Received: Sunday, December 4, 2011, 3:32 PM > Dear R-experts, > I am struggling with the following problem, and I am > looking for advice > from more experienced R-users: I have a data frame with 2 > identifying > variables (comn and mi), and an output variable (x). comn > is a variable for > a company and mi is a variable for a month. > > comn<-c("abc", "abc", "abc", "abc", "abc", "abc", "xyz", > "xyz","xyz", "xyz") > mi<- c("1", "1","1", "2", "2", "2", "1", "1", "3", "3") > x<- c("-0.0031", "0.0009", "-0.007", "0.1929","0.0087", > "0.099","-0.089", > "0.005", "-0.0078", "0.67" ) > df<- data.frame(comn=comn, mi=mi, x=x) > > > For each company, within a particular month, I would like > to compute the > standard deviation of x: for example, for abc, I would like > to compute the > sd of x for month1 (when mi=1) and for month2 (when mi=2). > > In other languages (Stata for instance), I would create a > grouping variable > (group comnn and mi) and then, apply the sd function for > each group. > > However, I don't find an elegant way to do the same in R: > > I was thinking about the following: I could subset my data > frame by mi and > create one file per month, and then make a loop and in each > file, use a > "by" operator for each comn. I am sure it would work, but I > feel that it > would be like killing an ant with a tank. > > I was wondering if anyone knew a more straightforward way > to implement that > kind of operation? > > Thanks a lot, > > Best, > Aurelien > > ??? [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org > mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, > reproducible code. > From erinm.hodgess at gmail.com Sun Dec 4 22:07:50 2011 From: erinm.hodgess at gmail.com (Erin Hodgess) Date: Sun, 4 Dec 2011 15:07:50 -0600 Subject: [R] trouble with installXLSXsupport() Message-ID: Dear R People: I'm using gdata and read.xls for a couple of projects. When I load gdata, it says to run installXLSXsupport() When I do that, I get a "not responding" error. I tried it with verbose=TRUE, but nothing appears. Has anyone else run into this, please? This is on Windows 7, 64 bit, compiled from source. Thanks, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodgess at gmail.com From erinm.hodgess at gmail.com Sun Dec 4 22:19:53 2011 From: erinm.hodgess at gmail.com (Erin Hodgess) Date: Sun, 4 Dec 2011 15:19:53 -0600 Subject: [R] a weird question about gdata::: Message-ID: Dear R People: If I put in: > findPerl Error: object 'findPerl' not found But if I use: > gdata:::findPerl function (perl, verbose = "FALSE") { errorMsg <- "perl executable not found. Use perl= argument to specify the correct path." if (missing(perl)) { perl = "perl" } perl = Sys.which(perl) if (perl == "" || perl == "perl") stop(errorMsg) if (.Platform$OS == "windows") { if (length(grep("rtools", tolower(perl))) > 0) { perl.ftype <- shell("ftype perl", intern = TRUE) if (length(grep("^perl=", perl.ftype)) > 0) { perl <- sub("^perl=\"([^\"]*)\".*", "\\1", perl.ftype) } } } if (verbose) cat("Using perl at", perl, "\n") perl } > Why does one work but not the other, please? Thanks, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodgess at gmail.com From i.visser at uva.nl Sun Dec 4 22:34:22 2011 From: i.visser at uva.nl (Ingmar Visser) Date: Sun, 4 Dec 2011 22:34:22 +0100 Subject: [R] Estimation of AR(1) Model with Markov Switching In-Reply-To: <1322758680372-4129417.post@n4.nabble.com> References: <1322758680372-4129417.post@n4.nabble.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From gunter.berton at gene.com Sun Dec 4 22:57:24 2011 From: gunter.berton at gene.com (Bert Gunter) Date: Sun, 4 Dec 2011 13:57:24 -0800 Subject: [R] a weird question about gdata::: In-Reply-To: References: Message-ID: ??namespace ?getAnywhere ?"::" See also: http://www.stat.uiowa.edu/~luke/R/namespaces/morenames.pdf Bottom line: namespaces provide a mechanism to "hide" certain variables within a package. Special measures as documented above are required to view them -- Bert On Sun, Dec 4, 2011 at 1:19 PM, Erin Hodgess wrote: > Dear R People: > > If I put in: > >> findPerl > Error: object 'findPerl' not found > > > But if I use: > >> gdata:::findPerl > function (perl, verbose = "FALSE") > { > ? ?errorMsg <- "perl executable not found. Use perl= argument to > specify the correct path." > ? ?if (missing(perl)) { > ? ? ? ?perl = "perl" > ? ?} > ? ?perl = Sys.which(perl) > ? ?if (perl == "" || perl == "perl") > ? ? ? ?stop(errorMsg) > ? ?if (.Platform$OS == "windows") { > ? ? ? ?if (length(grep("rtools", tolower(perl))) > 0) { > ? ? ? ? ? ?perl.ftype <- shell("ftype perl", intern = TRUE) > ? ? ? ? ? ?if (length(grep("^perl=", perl.ftype)) > 0) { > ? ? ? ? ? ? ? ?perl <- sub("^perl=\"([^\"]*)\".*", "\\1", perl.ftype) > ? ? ? ? ? ?} > ? ? ? ?} > ? ?} > ? ?if (verbose) > ? ? ? ?cat("Using perl at", perl, "\n") > ? ?perl > } > >> > > Why does one work but not the other, please? > > Thanks, > Erin > > -- > Erin Hodgess > Associate Professor > Department of Computer and Mathematical Sciences > University of Houston - Downtown > mailto: erinm.hodgess at gmail.com > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm From gunter.berton at gene.com Sun Dec 4 23:06:21 2011 From: gunter.berton at gene.com (Bert Gunter) Date: Sun, 4 Dec 2011 14:06:21 -0800 Subject: [R] Group several variables and apply a function to the group In-Reply-To: <1323032824.66527.YahooMailClassic@web38408.mail.mud.yahoo.com> References: <1323032824.66527.YahooMailClassic@web38408.mail.mud.yahoo.com> Message-ID: ... with() is useful here: e.g. in base R, simply tapply() or ave() with with() with(df,ave(x, comn,mi, FUN = sd)) -- Bert On Sun, Dec 4, 2011 at 1:07 PM, John Kane wrote: > ?aggregate should do it > > aggregate(df$x,list(df$comn, df$mi), sd) > > There are other ways of course > > Using the reshape2 package > > library(reshape2) > x1 <- melt(df, id=c("comn", "mi")) > dcast(x1, comn + mi ~ variable, sd) > > > > > --- On Sun, 12/4/11, Aur?lien PHILIPPOT wrote: > >> From: Aur?lien PHILIPPOT >> Subject: [R] Group several variables and apply a function to the group >> To: R-help at r-project.org >> Received: Sunday, December 4, 2011, 3:32 PM >> Dear R-experts, >> I am struggling with the following problem, and I am >> looking for advice >> from more experienced R-users: I have a data frame with 2 >> identifying >> variables (comn and mi), and an output variable (x). comn >> is a variable for >> a company and mi is a variable for a month. >> >> comn<-c("abc", "abc", "abc", "abc", "abc", "abc", "xyz", >> "xyz","xyz", "xyz") >> mi<- c("1", "1","1", "2", "2", "2", "1", "1", "3", "3") >> x<- c("-0.0031", "0.0009", "-0.007", "0.1929","0.0087", >> "0.099","-0.089", >> "0.005", "-0.0078", "0.67" ) >> df<- data.frame(comn=comn, mi=mi, x=x) >> >> >> For each company, within a particular month, I would like >> to compute the >> standard deviation of x: for example, for abc, I would like >> to compute the >> sd of x for month1 (when mi=1) and for month2 (when mi=2). >> >> In other languages (Stata for instance), I would create a >> grouping variable >> (group comnn and mi) and then, apply the sd function for >> each group. >> >> However, I don't find an elegant way to do the same in R: >> >> I was thinking about the following: I could subset my data >> frame by mi and >> create one file per month, and then make a loop and in each >> file, use a >> "by" operator for each comn. I am sure it would work, but I >> feel that it >> would be like killing an ant with a tank. >> >> I was wondering if anyone knew a more straightforward way >> to implement that >> kind of operation? >> >> Thanks a lot, >> >> Best, >> Aurelien >> >> ??? [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org >> mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, >> reproducible code. >> > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm From matthew-c.johnson at ubs.com Sun Dec 4 23:25:51 2011 From: matthew-c.johnson at ubs.com (mattjo) Date: Sun, 4 Dec 2011 14:25:51 -0800 (PST) Subject: [R] RODBC sqlSave / append problem (windows XP, R 2.13.2) Message-ID: <0B3D04B9A3E43D49807BE67A26D55CF81936D75C@NSYDC101PEX1.ubsw.net> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From michael.weylandt at gmail.com Mon Dec 5 00:25:32 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Sun, 4 Dec 2011 18:25:32 -0500 Subject: [R] equating approximate values In-Reply-To: References: <1323021640135-4157551.post@n4.nabble.com> Message-ID: Not sure what to make of the fact that your x, y are of different lengths: if you mean to check all possible pairings, this is probably what you need: which(outer(x, y, "-") < threshold, arr.ind = TRUE) Michael On Sun, Dec 4, 2011 at 2:24 PM, andrija djurovic wrote: > Hi. Maybe this can help you (you can try additionally to incorporate > threshold): > >> set.seed(1) >> x<-rnorm(10,10,1) >> values <- sample(1:10,10) ?#values that we are looking for >> mat <- matrix(c(x,values),ncol=2) >> >> closest<-function(x,values) ? ?#function is an example from The R book > (Crawley) > + { > + x[which(abs(x-values)==min(abs(x-values)))] > + } >> >> apply(mat[,2,drop=FALSE],1,function(y) closest(mat[,1],y)) > ?[1] 10.183643 ?9.164371 ?9.164371 ?9.164371 ?9.164371 ?9.164371 ?9.164371 > ?9.164371 > ?[9] ?9.164371 ?9.164371 > > > On Sun, Dec 4, 2011 at 7:00 PM, vamshi999 wrote: > >> Hello List, >> >> I am having trouble finding the command for my problem. >> >> I have two arrays x and y. now i would like to compare the values of x and >> y >> and then get the index of x which is exactly or approximately equal(+/- >> some >> value ) to the values in y. >> ?x <- runif(100,min=0,max=5) >> ?y <- runif(10,min=0,max=5) >> >> >> the threshold value(+/-) value can vary. for this example lets take it to >> be >> .5 >> >> I know the regular method of doing this by writing different if and for >> loops. But i have very big dataframe the computation time is very high for >> this method. can anyone please tell me if there any functions to do this. >> >> thank you for your help. >> >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/equating-approximate-values-tp4157551p4157551.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From michael.weylandt at gmail.com Mon Dec 5 00:27:56 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Sun, 4 Dec 2011 18:27:56 -0500 Subject: [R] equating approximate values In-Reply-To: References: <1323021640135-4157551.post@n4.nabble.com> Message-ID: My apologies: you need an abs() call as well: which(abs(outer(x, y, "-")) < threshold, arr.ind = TRUE) Michael On Sun, Dec 4, 2011 at 6:25 PM, R. Michael Weylandt wrote: > Not sure what to make of the fact that your x, y are of different > lengths: if you mean to check all possible pairings, this is probably > what you need: > > which(outer(x, y, "-") < threshold, arr.ind = TRUE) > > Michael > > On Sun, Dec 4, 2011 at 2:24 PM, andrija djurovic wrote: >> Hi. Maybe this can help you (you can try additionally to incorporate >> threshold): >> >>> set.seed(1) >>> x<-rnorm(10,10,1) >>> values <- sample(1:10,10) ?#values that we are looking for >>> mat <- matrix(c(x,values),ncol=2) >>> >>> closest<-function(x,values) ? ?#function is an example from The R book >> (Crawley) >> + { >> + x[which(abs(x-values)==min(abs(x-values)))] >> + } >>> >>> apply(mat[,2,drop=FALSE],1,function(y) closest(mat[,1],y)) >> ?[1] 10.183643 ?9.164371 ?9.164371 ?9.164371 ?9.164371 ?9.164371 ?9.164371 >> ?9.164371 >> ?[9] ?9.164371 ?9.164371 >> >> >> On Sun, Dec 4, 2011 at 7:00 PM, vamshi999 wrote: >> >>> Hello List, >>> >>> I am having trouble finding the command for my problem. >>> >>> I have two arrays x and y. now i would like to compare the values of x and >>> y >>> and then get the index of x which is exactly or approximately equal(+/- >>> some >>> value ) to the values in y. >>> ?x <- runif(100,min=0,max=5) >>> ?y <- runif(10,min=0,max=5) >>> >>> >>> the threshold value(+/-) value can vary. for this example lets take it to >>> be >>> .5 >>> >>> I know the regular method of doing this by writing different if and for >>> loops. But i have very big dataframe the computation time is very high for >>> this method. can anyone please tell me if there any functions to do this. >>> >>> thank you for your help. >>> >>> -- >>> View this message in context: >>> http://r.789695.n4.nabble.com/equating-approximate-values-tp4157551p4157551.html >>> Sent from the R help mailing list archive at Nabble.com. >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >> >> ? ? ? ?[[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. From rolf.turner at xtra.co.nz Mon Dec 5 00:57:29 2011 From: rolf.turner at xtra.co.nz (Rolf Turner) Date: Mon, 5 Dec 2011 12:57:29 +1300 Subject: [R] a weird question about gdata::: In-Reply-To: References: Message-ID: <4EDC08E9.1040703@xtra.co.nz> See end of message. On 05/12/11 10:19, Erin Hodgess wrote: > Dear R People: > > If I put in: > >> findPerl > Error: object 'findPerl' not found > > > But if I use: > >> gdata:::findPerl > function (perl, verbose = "FALSE") > { > errorMsg<- "perl executable not found. Use perl= argument to > specify the correct path." > if (missing(perl)) { > perl = "perl" > } > perl = Sys.which(perl) > if (perl == "" || perl == "perl") > stop(errorMsg) > if (.Platform$OS == "windows") { > if (length(grep("rtools", tolower(perl)))> 0) { > perl.ftype<- shell("ftype perl", intern = TRUE) > if (length(grep("^perl=", perl.ftype))> 0) { > perl<- sub("^perl=\"([^\"]*)\".*", "\\1", perl.ftype) > } > } > } > if (verbose) > cat("Using perl at", perl, "\n") > perl > } > > Why does one work but not the other, please? Because "findPerl" is ``not exported'' from the gdata namespace. Uhhh, what does that mean? I have a vague idea, but I'm not sufficiently confident/competent to elaborate. You'll just have to read up on namespaces. I'm *sure* namespaces are really a Good Thing, but they sure do add to the mysteries of R usage. Has Pat Burns written anything by way of explaining namespace to bunnies like me? cheers, Rolf From ggrothendieck at gmail.com Mon Dec 5 01:04:55 2011 From: ggrothendieck at gmail.com (Gabor Grothendieck) Date: Sun, 4 Dec 2011 19:04:55 -0500 Subject: [R] a weird question about gdata::: In-Reply-To: <4EDC08E9.1040703@xtra.co.nz> References: <4EDC08E9.1040703@xtra.co.nz> Message-ID: On Sun, Dec 4, 2011 at 6:57 PM, Rolf Turner wrote: > > See end of message. > > > On 05/12/11 10:19, Erin Hodgess wrote: >> >> Dear R People: >> >> If I put in: >> >>> findPerl >> >> Error: object 'findPerl' not found >> >> >> But if I use: >> >>> gdata:::findPerl >> >> function (perl, verbose = "FALSE") >> { >> ? ? errorMsg<- "perl executable not found. Use perl= argument to >> specify the correct path." >> ? ? if (missing(perl)) { >> ? ? ? ? perl = "perl" >> ? ? } >> ? ? perl = Sys.which(perl) >> ? ? if (perl == "" || perl == "perl") >> ? ? ? ? stop(errorMsg) >> ? ? if (.Platform$OS == "windows") { >> ? ? ? ? if (length(grep("rtools", tolower(perl)))> ?0) { >> ? ? ? ? ? ? perl.ftype<- shell("ftype perl", intern = TRUE) >> ? ? ? ? ? ? if (length(grep("^perl=", perl.ftype))> ?0) { >> ? ? ? ? ? ? ? ? perl<- sub("^perl=\"([^\"]*)\".*", "\\1", perl.ftype) >> ? ? ? ? ? ? } >> ? ? ? ? } >> ? ? } >> ? ? if (verbose) >> ? ? ? ? cat("Using perl at", perl, "\n") >> ? ? perl >> } >> >> Why does one work but not the other, please? > > > Because "findPerl" is ``not exported'' from the gdata namespace. > > Uhhh, what does that mean? ?I have a vague idea, but I'm not sufficiently > confident/competent to elaborate. ?You'll just have to read up on > namespaces. > I'm *sure* namespaces are really a Good Thing, but they sure do add to the > mysteries of R usage. > The idea is to divide objects into those that are there for the user to access (exported objects) and those that are internal objects that only the package itself uses (everything else). findPerl is there only so that read.xls and other routines that depend on perl scripts can use it internally to find perl. It was not intended that users access it so its better hidden from view. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com From jdnewmil at dcn.davis.ca.us Mon Dec 5 02:07:37 2011 From: jdnewmil at dcn.davis.ca.us (Jeff Newmiller) Date: Sun, 4 Dec 2011 20:07:37 -0500 Subject: [R] a weird question about gdata::: In-Reply-To: References: <4EDC08E9.1040703@xtra.co.nz> Message-ID: <8d015bdf-9f89-4752-ba32-14c8c3a14733@email.android.com> I prefer to think of namespaces as preventing clashes with similarly-named functions in the main workspace or in other packages that might serve a different need. Given that purpose, I don't think I would have confined that particular function behind the namespace, because any other use of that name is likely to duplicate the functionality of that particular function, and any improvements to it probably ought to be incorporated into that particular function just as much as any other implementation would deserve improvement. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN: Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. Gabor Grothendieck wrote: >On Sun, Dec 4, 2011 at 6:57 PM, Rolf Turner >wrote: >> >> See end of message. >> >> >> On 05/12/11 10:19, Erin Hodgess wrote: >>> >>> Dear R People: >>> >>> If I put in: >>> >>>> findPerl >>> >>> Error: object 'findPerl' not found >>> >>> >>> But if I use: >>> >>>> gdata:::findPerl >>> >>> function (perl, verbose = "FALSE") >>> { >>> ? ? errorMsg<- "perl executable not found. Use perl= argument to >>> specify the correct path." >>> ? ? if (missing(perl)) { >>> ? ? ? ? perl = "perl" >>> ? ? } >>> ? ? perl = Sys.which(perl) >>> ? ? if (perl == "" || perl == "perl") >>> ? ? ? ? stop(errorMsg) >>> ? ? if (.Platform$OS == "windows") { >>> ? ? ? ? if (length(grep("rtools", tolower(perl)))> ?0) { >>> ? ? ? ? ? ? perl.ftype<- shell("ftype perl", intern = TRUE) >>> ? ? ? ? ? ? if (length(grep("^perl=", perl.ftype))> ?0) { >>> ? ? ? ? ? ? ? ? perl<- sub("^perl=\"([^\"]*)\".*", "\\1", >perl.ftype) >>> ? ? ? ? ? ? } >>> ? ? ? ? } >>> ? ? } >>> ? ? if (verbose) >>> ? ? ? ? cat("Using perl at", perl, "\n") >>> ? ? perl >>> } >>> >>> Why does one work but not the other, please? >> >> >> Because "findPerl" is ``not exported'' from the gdata namespace. >> >> Uhhh, what does that mean? ?I have a vague idea, but I'm not >sufficiently >> confident/competent to elaborate. ?You'll just have to read up on >> namespaces. >> I'm *sure* namespaces are really a Good Thing, but they sure do add >to the >> mysteries of R usage. >> > >The idea is to divide objects into those that are there for the user >to access (exported objects) and those that are internal objects that >only the package itself uses (everything else). findPerl is there >only so that read.xls and other routines that depend on perl scripts >can use it internally to find perl. It was not intended that users >access it so its better hidden from view. > >-- >Statistics & Software Consulting >GKX Group, GKX Associates Inc. >tel: 1-877-GKX-GROUP >email: ggrothendieck at gmail.com > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. From chapkovski at gmail.com Mon Dec 5 02:12:54 2011 From: chapkovski at gmail.com (Philipp Chapkovski) Date: Mon, 5 Dec 2011 02:12:54 +0100 Subject: [R] convert table to a string in matrix Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From bbolker at gmail.com Mon Dec 5 02:43:10 2011 From: bbolker at gmail.com (Ben Bolker) Date: Mon, 5 Dec 2011 01:43:10 +0000 Subject: [R] upper bound in the integrate function depends on a parameter References: Message-ID: Jorge I Velez gmail.com> writes: > And remember: > > #install.packages('fortunes') > require(fortunes) > fortune('Yoda') > > Evelyn Hall: I would like to know how (if) I can extract some of the > information > from the summary of my nlme. > Simon Blomberg: This is R. There is no if. Only how. > -- Evelyn Hall and Simon 'Yoda' Blomberg > R-help (April 2005) Yes, although if you really wanted to compute (symbolic) indefinite integrals, it would be awfully hard. R is Turing-complete so of course you could do it ... but ... Ben Bolker From comtech.usa at gmail.com Mon Dec 5 03:31:11 2011 From: comtech.usa at gmail.com (Michael) Date: Sun, 4 Dec 2011 20:31:11 -0600 Subject: [R] Save debugging session info and resume from the middle? Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From vamshi999 at gmail.com Mon Dec 5 01:04:22 2011 From: vamshi999 at gmail.com (vamshi999) Date: Sun, 4 Dec 2011 16:04:22 -0800 (PST) Subject: [R] equating approximate values In-Reply-To: References: <1323021640135-4157551.post@n4.nabble.com> Message-ID: <1323043462928-4158691.post@n4.nabble.com> this is exactly what i wanted. How to i select only the minimum value from this?. thank you My apologies: you need an abs() call as well: which(abs(outer(x, y, "-")) < threshold, arr.ind = TRUE) Michael -- View this message in context: http://r.789695.n4.nabble.com/equating-approximate-values-tp4157551p4158691.html Sent from the R help mailing list archive at Nabble.com. From zack.abrahamson at gmail.com Mon Dec 5 02:04:16 2011 From: zack.abrahamson at gmail.com (z2.0) Date: Sun, 4 Dec 2011 17:04:16 -0800 (PST) Subject: [R] Prediction from censReg? In-Reply-To: <1322964489802-4155855.post@n4.nabble.com> References: <1322964489802-4155855.post@n4.nabble.com> Message-ID: <1323047056448-4158844.post@n4.nabble.com> Just posting again here... -- View this message in context: http://r.789695.n4.nabble.com/Prediction-from-censReg-tp4155855p4158844.html Sent from the R help mailing list archive at Nabble.com. From couch.world at gmail.com Mon Dec 5 02:14:31 2011 From: couch.world at gmail.com (=)) Date: Mon, 5 Dec 2011 03:14:31 +0200 Subject: [R] Rggobi pdf output In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From couch.world at gmail.com Mon Dec 5 02:21:19 2011 From: couch.world at gmail.com (=)) Date: Mon, 5 Dec 2011 03:21:19 +0200 Subject: [R] [rggobi] ggplot like pdf output Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From wchips at y7mail.com Mon Dec 5 02:57:19 2011 From: wchips at y7mail.com (wchips) Date: Sun, 4 Dec 2011 17:57:19 -0800 (PST) Subject: [R] Persp3d freezes when run from within Python Message-ID: <1323050239287-4158940.post@n4.nabble.com> G'day everyone, I've been trying to get an interactive OpenGL plot to work from within Python 2.6 using Rpy2 and the persp3d function. The problem is that the plot seems to freeze upon activation. All interactivity is lost even though it works fine when run from within the R console (version 2.11.1). Is this a known issue? Any ideas as to what might be causing this, or possibly how to fix it? cheers, wchips -- View this message in context: http://r.789695.n4.nabble.com/Persp3d-freezes-when-run-from-within-Python-tp4158940p4158940.html Sent from the R help mailing list archive at Nabble.com. From ggrothendieck at gmail.com Mon Dec 5 04:52:37 2011 From: ggrothendieck at gmail.com (Gabor Grothendieck) Date: Sun, 4 Dec 2011 22:52:37 -0500 Subject: [R] a weird question about gdata::: In-Reply-To: <8d015bdf-9f89-4752-ba32-14c8c3a14733@email.android.com> References: <4EDC08E9.1040703@xtra.co.nz> <8d015bdf-9f89-4752-ba32-14c8c3a14733@email.android.com> Message-ID: On Sun, Dec 4, 2011 at 8:07 PM, Jeff Newmiller wrote: > I prefer to think of namespaces as preventing clashes with similarly-named functions in the main workspace or in other packages that might serve a different need. > > Given that purpose, I don't think I would have confined that particular function behind the namespace, because any other use of that name is likely to duplicate the functionality of that particular function, and any improvements to it probably ought to be incorporated into that particular function just as much as any other implementation would deserve improvement. The idea of hiding the the internals is that they can then be changed with reasonable likelihood that it won't affect users. Only those who attempted to circumvent the barriers put in place would be affected. For example, suppose that read.xls and the related Excel routines were to be changed so that internally they use C instead of perl. In that case findPerl would not serve any purpose in the package and the current design would allow it to be dropped. On the other hand, if the purpose of the package were specifically to interface to perl then it would make sense to export it. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com From ngokangmin at gmail.com Mon Dec 5 04:02:44 2011 From: ngokangmin at gmail.com (Kang Min) Date: Sun, 4 Dec 2011 19:02:44 -0800 (PST) Subject: [R] Extract last 3 characters from numeric vector In-Reply-To: <4EDB94F8.1040100@statistik.tu-dortmund.de> References: <2b0fce6a-ec23-4034-b80f-91e4a8440389@z1g2000yqa.googlegroups.com> <4EDB94F8.1040100@statistik.tu-dortmund.de> Message-ID: Thanks Sarah, but I discovered that numbers like 3.0 only have 1 character, so I had a range of character lengths from 1 to 4 (e.g. 17.0 has 2 characters, 3.4 has 3 and 12.4 has 4). Uwe's method worked well. Thanks again. Kang Min On Dec 4, 11:42?pm, Uwe Ligges wrote: > On 04.12.2011 14:38, Kang Min wrote: > > > Hi all, > > > I have a numeric vector with 1 decimal place, and I'd like to extract > > the last 3 characters, including the decimal point. The vector ranges > > from 0 to 20. > > > x<- round(runif(100)*20, digits=1) > > formatC(round(x%%10, 1), format="f", digits=1) > > Uwe Ligges > > > Some of numbers have 3 characters, and some have 4. I've read up on > > the substr() function but that extracts characters based on exact > > positions. How can I extract just the last 3 characters no matter the > > length of the number? e.g. from 16.7 I want 6.7, from 3.5 I want 3.5 > > as it is. > > > Thanks, > > Kang Min > > > ______________________________________________ > > R-h... at r-project.org mailing list > >https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From un_tonio at yahoo.com Mon Dec 5 08:11:51 2011 From: un_tonio at yahoo.com (Tonio) Date: Sun, 4 Dec 2011 23:11:51 -0800 (PST) Subject: [R] Toggle cASE Message-ID: <1323069111.20601.YahooMailNeo@web130111.mail.mud.yahoo.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From tonja.krueger at web.de Mon Dec 5 08:46:34 2011 From: tonja.krueger at web.de (Tonja Krueger) Date: Mon, 5 Dec 2011 08:46:34 +0100 (CET) Subject: [R] local minima/ maxima Message-ID: <585155369.13769757.1323071194731.JavaMail.fmail@3capp-webde-bs38.dlan.cinetic.de> From astareh at hotmail.com Mon Dec 5 08:47:13 2011 From: astareh at hotmail.com (set) Date: Sun, 4 Dec 2011 23:47:13 -0800 (PST) Subject: [R] similarity matrix In-Reply-To: <1323027562692-4157840.post@n4.nabble.com> References: <1323022265536-4157576.post@n4.nabble.com> <1323027562692-4157840.post@n4.nabble.com> Message-ID: <1323071233237-4159547.post@n4.nabble.com> I'm sorry, I made a mistake in my example. you're right. I don't really know how a similarity alogrithm works....but I'm willing to try that...are there any good examples available? Thank you -- View this message in context: http://r.789695.n4.nabble.com/similarity-matrix-tp4157576p4159547.html Sent from the R help mailing list archive at Nabble.com. From narendarcse007 at gmail.com Mon Dec 5 07:46:23 2011 From: narendarcse007 at gmail.com (narendarreddy kalam) Date: Sun, 4 Dec 2011 22:46:23 -0800 (PST) Subject: [R] about error while using anova function Message-ID: <1323067583199-4159463.post@n4.nabble.com> fit1<-rq(formula=op~inp1+inp2+inp3+inp4+inp5+inp6+inp7+inp8+inp9,tau=0.15,data=wbc) fit2<-rq(formula=op~inp1+inp2+inp3+inp4+inp5+inp6+inp7+inp8+inp9,tau=0.5,data=wbc) fit3<-rq(formula=op~inp1+inp2+inp3+inp4+inp5+inp6+inp7+inp8+inp9,tau=0.15,data=wbc) fit4<-rq(formula=op~inp1+inp2+inp3+inp4+inp5+inp6+inp7+inp8+inp9,tau=0.15,data=wbc) fit5<-rq(formula=op~inp1+inp2+inp3+inp4+inp5+inp6+inp7+inp8+inp9,tau=0.15,data=wbc) *output of tau=0.15*fit1 Call: rq(formula = op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + inp8 + inp9, tau = 0.15, data = wbc) Coefficients: (Intercept) inp1 inp2 inp3 inp4 inp5 -0.191528450 0.005276347 0.021414032 0.016034803 0.007510343 0.005276347 inp6 inp7 inp8 inp9 0.058708544 0.005224906 0.006804871 -0.003931540 Degrees of freedom: 673 total; 663 residual *output of tau=0.3*fit2 Call: rq(formula = op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + inp8 + inp9, tau = 0.3, data = wbc) Coefficients: (Intercept) inp1 inp2 inp3 inp4 -1.111111e-01 5.776765e-19 4.635734e-18 1.874715e-18 2.099872e-18 inp5 inp6 inp7 inp8 inp9 -4.942052e-19 1.111111e-01 2.205289e-18 4.138435e-18 9.300642e-19 Degrees of freedom: 673 total; 663 residual *output of tau=0.5*fit3 Call: rq(formula = op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + inp8 + inp9, tau = 0.5, data = wbc) Coefficients: (Intercept) inp1 inp2 inp3 inp4 -1.400000e-01 5.810236e-17 4.000000e-02 1.087160e-16 4.297771e-18 inp5 inp6 inp7 inp8 inp9 8.045868e-17 8.000000e-02 6.841101e-17 2.000000e-02 7.560947e-17 Degrees of freedom: 673 total; 663 residual *output of tau=0.65* Call: rq(formula = op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + inp8 + inp9, tau = 0.65, data = wbc) Coefficients: (Intercept) inp1 inp2 inp3 inp4 inp5 -0.193593706 0.005012804 0.044208182 0.008994346 0.006214294 0.007622629 inp6 inp7 inp8 inp9 0.064595895 0.006214294 0.028904532 0.001775512 Degrees of freedom: 673 total; 663 residual *output of tau=0.9:* fit5 Call: rq(formula = op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + inp8 + inp9, tau = 0.9, data = wbc) Coefficients: (Intercept) inp1 inp2 inp3 inp4 inp5 -0.249006688 0.040430238 0.010854846 0.031021326 0.013558943 0.024867111 inp6 inp7 inp8 inp9 0.050441784 0.024867111 0.027018345 0.001079872 Degrees of freedom: 673 total; 663 residual < b> so fit1 fit2,fit3,fit4,fit5 are the 5 quantiles of the wbc dataset.but why i am encoutering the following error while using anova* *anova(fit1,fit2,fit3,fit4,fit5); Error in solve.default(D %*% W %*% t(D), D %*% coef) : system is computationally singular: reciprocal condition number = 5.58091e-19 In addition: Warning messages: 1: In summary.rq(x, se = "nid", covariance = TRUE) : 93 non-positive fis 2: In summary.rq(x, se = "nid", covariance = TRUE) : 138 non-positive fis 3: In summary.rq(x, se = "nid", covariance = TRUE) : 206 non-positive fis 4: In summary.rq(x, se = "nid", covariance = TRUE) : 53 non-positive fis 5: In summary.rq(x, se = "nid", covariance = TRUE) : 30 non-positive fis* -- View this message in context: http://r.789695.n4.nabble.com/about-error-while-using-anova-function-tp4159463p4159463.html Sent from the R help mailing list archive at Nabble.com. From narendarcse007 at gmail.com Mon Dec 5 08:18:03 2011 From: narendarcse007 at gmail.com (narendarreddy kalam) Date: Sun, 4 Dec 2011 23:18:03 -0800 (PST) Subject: [R] about interpretation of anova results... Message-ID: <1323069483773-4159510.post@n4.nabble.com> quantreg package is used. *fit1 results are* Call: rq(formula = op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + inp8 + inp9, tau = 0.15, data = wbc) Coefficients: (Intercept) inp1 inp2 inp3 inp4 inp5 -0.191528450 0.005276347 0.021414032 0.016034803 0.007510343 0.005276347 inp6 inp7 inp8 inp9 0.058708544 0.005224906 0.006804871 -0.003931540 Degrees of freedom: 673 total; 663 residual *fit2 results are* Call: rq(formula = op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + inp8 + inp9, tau = 0.3, data = wbc) Coefficients: (Intercept) inp1 inp2 inp3 inp4 -1.111111e-01 5.776765e-19 4.635734e-18 1.874715e-18 2.099872e-18 inp5 inp6 inp7 inp8 inp9 -4.942052e-19 1.111111e-01 2.205289e-18 4.138435e-18 9.300642e-19 Degrees of freedom: 673 total; 663 residual anova(fit1,fit2); Quantile Regression Analysis of Deviance Table Model: op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + inp8 + inp9 Joint Test of Equality of Slopes: tau in { 0.15 0.3 } Df Resid Df F value Pr(>F) 1 9 1337 0.5256 0.8568 Warning messages: 1: In summary.rq(x, se = "nid", covariance = TRUE) : 93 non-positive fis 2: In summary.rq(x, se = "nid", covariance = TRUE) : 138 non-positive fis how to interpret the above results?? what is the use of anova function?? will it give the best among fit1 && fit2.. -- View this message in context: http://r.789695.n4.nabble.com/about-interpretation-of-anova-results-tp4159510p4159510.html Sent from the R help mailing list archive at Nabble.com. From jim at bitwrit.com.au Mon Dec 5 09:23:13 2011 From: jim at bitwrit.com.au (Jim Lemon) Date: Mon, 05 Dec 2011 19:23:13 +1100 Subject: [R] frequency table? In-Reply-To: <1322990509062-4156422.post@n4.nabble.com> References: <1322990509062-4156422.post@n4.nabble.com> Message-ID: <4EDC7F71.5030507@bitwrit.com.au> On 12/04/2011 08:21 PM, set wrote: > Hello R-users, > > I've got a file with individuals as colums and the clusters where they occur > in as rows. And I wanted a table which tells me how many times each > individual occurs with another. I don't really know how such a table is > called...it is not a frequency table....My eventual goal is to make > Venn-diagrams from the occurence of my individuals. > > So I've this: > > cluster ind1 ind2 ind3 etc. > 1 0 1 2 > 2 3 0 1 > 3 1 1 1 > > And I want to go to this: > ind1 ind2 ind3 > ind1 0 4 2 > ind2 4 0 4 > ind3 2 4 1 > > is there a way to do this? Hi set, Your example is a bit hard to figure out. In particular, individual 1 seems to be in cluster 2 three times, and individual 3 in cluster 1 twice. I could understand it if the top table looked like this: cluster ind1 ind2 ind3 ... 1 0 1 1 ... 2 1 0 1 ... 3 1 1 1 ... That tells me that individual 1 is in cluster 2 and 3 but not in cluster 1, and so on. If you look at the first example in the intersectDiagram function in the plotrix package, you will see something similar, except that individuals are rows and common attributes (belonging to sets) are columns. You can get an intersection diagram from that showing how many individuals are in each combination of sets. This is similar to a Venn diagram, except that the population of each intersection is represented by the width of a rectangle and a text representation of that population. Thinking about it, maybe you are trying to represent both types of individuals (that is, there exists more than one of individual type 1 and so on) and attributes (belonging to clusters). In this case you are trying to get the intersections of two independent groups of sets. So, I created a dataset in which individuals can have personal characteristics (sex, age) and scholastic characteristics (which subjects they study). funnystuff<-data.frame(math=sample(c(0,1),100,TRUE), biology=sample(c(0,1),100,TRUE), english=sample(c(0,1),100,TRUE), sex=sample(c(0,1),100,TRUE), over18=sample(c(0,1),100,TRUE)) library(plotrix) intersectDiagram(funnystuff,main="Studies by sex and age",sep="\n") This gives me an interesting diagram from which I can get various intersections of these two groups of attributes. Is this what you are seeking? Jim From karajamu at hotmail.com Mon Dec 5 09:52:28 2011 From: karajamu at hotmail.com (karajamu) Date: Mon, 5 Dec 2011 09:52:28 +0100 Subject: [R] Spatstat - problem with which.marks and as.pp In-Reply-To: References: , Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From Rob.Calver at informa.com Mon Dec 5 10:19:01 2011 From: Rob.Calver at informa.com (Calver, Rob) Date: Mon, 5 Dec 2011 09:19:01 -0000 Subject: [R] ANNOUNCEMENT: Call for Proposals for The R Series from Chapman & Hall/CRC Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From S.Ellison at LGCGroup.com Mon Dec 5 10:18:44 2011 From: S.Ellison at LGCGroup.com (S Ellison) Date: Mon, 5 Dec 2011 09:18:44 +0000 Subject: [R] [rggobi] ggplot like pdf output In-Reply-To: References: Message-ID: ________________________________________ > neither the *DescribeDisplay* package, nor *ggplot* are available in 2.13.2. ggplot's package name is ggplot2. It certainly _was_ available for 2.13.2. S******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}} From bia.cdc at gmail.com Mon Dec 5 11:00:06 2011 From: bia.cdc at gmail.com (bcdc) Date: Mon, 5 Dec 2011 02:00:06 -0800 (PST) Subject: [R] iterative variable names Message-ID: <1323079206895-4159888.post@n4.nabble.com> Hi, I'm trying to assign iterative names to variable, but all my attempts have failed. I have a loop, and for every iteration, I need to create a variable, and I'd like to name them iteratively, such as: for(i in 1:10) { x_i <- c(values) } I need it to return ten variables: x_1, x_2, ..., x_10 How can I do it? Thank you very much! Beatriz -- View this message in context: http://r.789695.n4.nabble.com/iterative-variable-names-tp4159888p4159888.html Sent from the R help mailing list archive at Nabble.com. From ligges at statistik.tu-dortmund.de Mon Dec 5 11:18:39 2011 From: ligges at statistik.tu-dortmund.de (Uwe Ligges) Date: Mon, 05 Dec 2011 11:18:39 +0100 Subject: [R] iterative variable names In-Reply-To: <1323079206895-4159888.post@n4.nabble.com> References: <1323079206895-4159888.post@n4.nabble.com> Message-ID: <4EDC9A7F.8000208@statistik.tu-dortmund.de> On 05.12.2011 11:00, bcdc wrote: > Hi, > > I'm trying to assign iterative names to variable, but all my attempts have > failed. I have a loop, and for every iteration, I need to create a variable, > and I'd like to name them iteratively, such as: > > for(i in 1:10) > { > x_i<- c(values) > } You actually want to create a list of objects that you return in the end. Uwe Ligges > I need it to return ten variables: x_1, x_2, ..., x_10 > > How can I do it? > > Thank you very much! > Beatriz > > -- > View this message in context: http://r.789695.n4.nabble.com/iterative-variable-names-tp4159888p4159888.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From jholtman at gmail.com Mon Dec 5 11:23:25 2011 From: jholtman at gmail.com (Jim Holtman) Date: Mon, 5 Dec 2011 05:23:25 -0500 Subject: [R] iterative variable names In-Reply-To: <1323079206895-4159888.post@n4.nabble.com> References: <1323079206895-4159888.post@n4.nabble.com> Message-ID: <511429D6-561A-4EA6-95A1-44A936973BEE@gmail.com> ?assign for (i in 1:10) assign(paste('x_', i, sep = ''), i) but before you do this, consider using a 'list'; check the archives since this is asked a lot. Sent from my iPad On Dec 5, 2011, at 5:00, bcdc wrote: > Hi, > > I'm trying to assign iterative names to variable, but all my attempts have > failed. I have a loop, and for every iteration, I need to create a variable, > and I'd like to name them iteratively, such as: > > for(i in 1:10) > { > x_i <- c(values) > } > > I need it to return ten variables: x_1, x_2, ..., x_10 > > How can I do it? > > Thank you very much! > Beatriz > > -- > View this message in context: http://r.789695.n4.nabble.com/iterative-variable-names-tp4159888p4159888.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From Mintewab.Bezabih at economics.gu.se Mon Dec 5 11:28:26 2011 From: Mintewab.Bezabih at economics.gu.se (Mintewab Bezabih) Date: Mon, 5 Dec 2011 11:28:26 +0100 Subject: [R] problems using the thin plate spline method In-Reply-To: References: <4B46FB7EED800046A5952FCFA92D3BA0347DF578CD@HGUMAIL6.hgu.gu.se> <4B46FB7EED800046A5952FCFA92D3BA0347DF578D2@HGUMAIL6.hgu.gu.se>, Message-ID: <4B46FB7EED800046A5952FCFA92D3BA0347DF578D3@HGUMAIL6.hgu.gu.se> Dear Sarah and R users, Sorry again for not being explicit enough. Here is my full problem dat <- read.table("E:/thin plate/thin plate.csv", header=T, sep=",") dat names(dat) <- c("x1", "x2", "y") library(fields) plot (dat) #load the fields package (containing Tps) and fit a thin plate spline tpsfit <- Tps(cbind(x1, x2), y, scale.type="unscaled") What I meant when I said the graph works is when I do plot(dat) it does plot of all my three variables. If I do plot(x1,y), though, I get the 'object x1 not found' error message. Same when I do the next line tpsfit <- Tps(cbind(x1, x2), y, scale.type="unscaled"). I get the same error message. I tried your suggestion of checking str(x1) and I get the same error message (object x1 not found). I also typed ls() and I get "dat" after that command. I followed the r tutorial guide to read my data and I am following the r tutorial to guide me to apply the thin plate spline method. Regards, Mintewab ________________________________________ Fr?n: Sarah Goslee [sarah.goslee at gmail.com] Skickat: den 4 december 2011 15:21 Till: Mintewab Bezabih Kopia: r-help at r-project.org ?mne: Re: [R] problems using the thin plate spline method Hello, On Sun, Dec 4, 2011 at 8:08 AM, Mintewab Bezabih wrote: > Dear R users and Jeff, > > Sorry for not being quite explicit in my earlier message. And you are still not explicit. We have no idea what you've done. > My main problem is while my data seem to be read into R well (I manage to graph them and all), I cannot get the following line to work. > > tpsfit <- Tps(cbind(x1, x2), y, scale.type="unscaled") > > and I get the following error message > > Error in as.matrix(x) : > error in evaluating the argument 'x' in selecting a method for function 'as.matrix': Error: object 'x1' not found I'd have to guess that there's no object x1. What does ls() tell you? str(x1)? What do your data look like? You were already given instructions on how to include sample data to construct a reproducible example. You said that graphing your data worked; how did you do so? The posting guide and the advice you were already given were both offered for a reason. The querent needs to do the work of formulating an understandable and answerable question. Sarah > thanks for help > minti > ________________________________________ > Fr?n: Jeff Newmiller [jdnewmil at dcn.davis.ca.us] > Skickat: den 3 december 2011 17:45 > Till: Mintewab Bezabih; r-help at r-project.org > ?mne: Re: [R] problems using the thin plate spline method > > I can tell that you are puzzled and confused. Unfortunately, I am not psychic, so I cannot tell what you did, and therefore cannot tell where you went astray. > > The solution is for you to read the posting guide mentioned at the bottom of every R-help message. Spend a little time to create a small bit of data like yours if your actual data is large (subset and dput are useful for this). Remember to include the output of sessionInfo, and so on. Many times you are likely to find the answer yourself by going through these steps, but they are essential for communication. > > Good luck. > Sent from my phone. Please excuse my brevity. > > Mintewab Bezabih wrote: > >>Dear R users, >> >>I am a beginner in R trying to apply the thin plate spline method to my >>climate data. I used the example in R to do so, and the lines seem to >>run fine ( I am not getting errors) but I am not getting any output in >>the form of graph or anything. I got a warning message saying that >>'surface extends beyond box'. >> >>Any help is much appreciated. >>thanks >>minti -- Sarah Goslee http://www.functionaldiversity.org From petr.pikal at precheza.cz Mon Dec 5 11:44:27 2011 From: petr.pikal at precheza.cz (Petr PIKAL) Date: Mon, 5 Dec 2011 11:44:27 +0100 Subject: [R] Data alignment In-Reply-To: <1322915587713-4153112.post@n4.nabble.com> References: <1322912606118-4153024.post@n4.nabble.com> <1322915587713-4153112.post@n4.nabble.com> Message-ID: > > Re: [R] Data alignment > > Thanks for your suggestions. I will try them. > > The "-" in my original post was actually only there to serve as a separator > so that it is easier for you to see the data structure but apparently it > rather confused you... sorry :) That is why dput is to be used. Try this by yourself > dput(y) structure(c(2L, 1L, 1L, NA, 2L, 1L, NA, NA, 2L, NA, NA, NA, NA, 1L, NA, NA, NA, 2L, NA, 1L, NA, 2L, NA, 3L, NA), .Dim = c(5L, 5L), .Dimnames = list(NULL, c("", "BMW", "Mercedes", "VW", "Skoda" ))) x<-structure(c(2L, 1L, 1L, NA, 2L, 1L, NA, NA, 2L, NA, NA, NA, NA, 1L, NA, NA, NA, 2L, NA, 1L, NA, 2L, NA, 3L, NA), .Dim = c(5L, 5L), .Dimnames = list(NULL, c("", "BMW", "Mercedes", "VW", "Skoda" ))) > all.equal(x,y) [1] TRUE > Regards Petr > > -- > View this message in context: http://r.789695.n4.nabble.com/Data- > alignment-tp4153024p4153112.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From petr.pikal at precheza.cz Mon Dec 5 11:55:22 2011 From: petr.pikal at precheza.cz (Petr PIKAL) Date: Mon, 5 Dec 2011 11:55:22 +0100 Subject: [R] problem merging data with different shapes In-Reply-To: <20111204140218.183110@gmx.net> References: <20111204140218.183110@gmx.net> Message-ID: Hi > > > I have been trying to merge datasets, one of which has a long format > (Adata) and one has a (different) long format (Bdata): > > Adata Bdata > subject order bpm subject order trial agegroup gender > 1 1 70.2 1 1 3 2 1 > 1 1 69.5 1 2 1 2 1 > 1 1 68.8 1 3 2 2 1 > 1 2 69.1 2 1 2 1 2 > 1 2 70 2 2 3 1 2 > 1 2 70.5 2 3 1 1 2 > 1 3 70.2 ... > 1 3 > 1 3 > 2 1 > 2 1 > ... ... > > In the end I would like to have a dataset that contains A unchanged with > the additional information from B added. > > subject order bpm trial agegroup gender > 1 1 70.2 3 2 1 > 1 1 69.5 3 2 1 > 1 1 68.8 3 2 1 > ... > I have tried: > newdataframe <- merge(Adata,Bdata, by= c("subject", "order"), sort = FALSE) Hm it seems that it should work. Try newdataframe <- merge(Adata,Bdata, by= c("subject", "order"), all=TRUE) Regards Petr > > For some reason, the trial column is not matched to the subject and order > information, despite them being identified as key-variables for the merge. > (The same is true for other variables, the actual dataset has more > variables and trials, but this is essentially the problem.) > So it results in something like: > subject order bpm trial agegroup gender > 1 1 70.2 3 2 1 > 1 1 69.5 2 2 1 > 1 1 68.8 1 2 1 > > What could be my mistake? > > Thank you VERY much. > Miriam > > > -- > > > > > -- > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From chapkovski at gmail.com Mon Dec 5 11:57:38 2011 From: chapkovski at gmail.com (Philipp Chapkovski) Date: Mon, 5 Dec 2011 11:57:38 +0100 Subject: [R] Problem with parsing HTML table Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From jdnewmil at dcn.davis.ca.us Mon Dec 5 12:39:29 2011 From: jdnewmil at dcn.davis.ca.us (Jeff Newmiller) Date: Mon, 05 Dec 2011 06:39:29 -0500 Subject: [R] problems using the thin plate spline method In-Reply-To: <4B46FB7EED800046A5952FCFA92D3BA0347DF578D3@HGUMAIL6.hgu.gu.se> References: <4B46FB7EED800046A5952FCFA92D3BA0347DF578CD@HGUMAIL6.hgu.gu.se> <4B46FB7EED800046A5952FCFA92D3BA0347DF578D2@HGUMAIL6.hgu.gu.se>, <4B46FB7EED800046A5952FCFA92D3BA0347DF578D3@HGUMAIL6.hgu.gu.se> Message-ID: <67c9a4a2-ee18-49b6-a1a1-791a2d3bda2e@email.android.com> Try plot( dat$x1, dat$y ) or plot( x1, y, data=dat ) Note that your example is still not reproducible because you have not supplied the data or a shortened version of your data for us to work with. Also, your problem is not with thin plates but with plot, and reading the help for that function by typing ?plot at the R command line would have provided you with more examples and usage info on how to get around this problem. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN: Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. Mintewab Bezabih wrote: >Dear Sarah and R users, > >Sorry again for not being explicit enough. Here is my full problem > > >dat <- read.table("E:/thin plate/thin plate.csv", header=T, sep=",") >dat >names(dat) <- c("x1", "x2", "y") >library(fields) >plot (dat) > >#load the fields package (containing Tps) and fit a thin plate spline >tpsfit <- Tps(cbind(x1, x2), y, scale.type="unscaled") > >What I meant when I said the graph works is when I do plot(dat) it does >plot of all my three variables. If I do plot(x1,y), though, I get the >'object x1 not found' error message. > >Same when I do the next line tpsfit <- Tps(cbind(x1, x2), y, >scale.type="unscaled"). I get the same error message. > >I tried your suggestion of checking str(x1) and I get the same error >message (object x1 not found). >I also typed ls() and I get "dat" after that command. > >I followed the r tutorial guide to read my data and I am following the >r tutorial to guide me to apply the thin plate spline method. > >Regards, > >Mintewab >________________________________________ >Fr?n: Sarah Goslee [sarah.goslee at gmail.com] >Skickat: den 4 december 2011 15:21 >Till: Mintewab Bezabih >Kopia: r-help at r-project.org >?mne: Re: [R] problems using the thin plate spline method > >Hello, > >On Sun, Dec 4, 2011 at 8:08 AM, Mintewab Bezabih > wrote: >> Dear R users and Jeff, >> >> Sorry for not being quite explicit in my earlier message. > >And you are still not explicit. We have no idea what you've done. > >> My main problem is while my data seem to be read into R well (I >manage to graph them and all), I cannot get the following line to work. >> >> tpsfit <- Tps(cbind(x1, x2), y, scale.type="unscaled") >> >> and I get the following error message >> >> Error in as.matrix(x) : >> error in evaluating the argument 'x' in selecting a method for >function 'as.matrix': Error: object 'x1' not found > >I'd have to guess that there's no object x1. What does ls() tell you? >str(x1)? > >What do your data look like? You were already given instructions on how >to >include sample data to construct a reproducible example. You said that >graphing your data worked; how did you do so? > >The posting guide and the advice you were already given were both >offered for a reason. The querent needs to do the work of formulating >an understandable and answerable question. > >Sarah > >> thanks for help >> minti >> ________________________________________ >> Fr?n: Jeff Newmiller [jdnewmil at dcn.davis.ca.us] >> Skickat: den 3 december 2011 17:45 >> Till: Mintewab Bezabih; r-help at r-project.org >> ?mne: Re: [R] problems using the thin plate spline method >> >> I can tell that you are puzzled and confused. Unfortunately, I am not >psychic, so I cannot tell what you did, and therefore cannot tell where >you went astray. >> >> The solution is for you to read the posting guide mentioned at the >bottom of every R-help message. Spend a little time to create a small >bit of data like yours if your actual data is large (subset and dput >are useful for this). Remember to include the output of sessionInfo, >and so on. Many times you are likely to find the answer yourself by >going through these steps, but they are essential for communication. >> >> Good luck. >> Sent from my phone. Please excuse my brevity. >> >> Mintewab Bezabih wrote: >> >>>Dear R users, >>> >>>I am a beginner in R trying to apply the thin plate spline method to >my >>>climate data. I used the example in R to do so, and the lines seem to >>>run fine ( I am not getting errors) but I am not getting any output >in >>>the form of graph or anything. I got a warning message saying that >>>'surface extends beyond box'. >>> >>>Any help is much appreciated. >>>thanks >>>minti > > >-- >Sarah Goslee >http://www.functionaldiversity.org > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. From void1999 at gmail.com Mon Dec 5 12:42:12 2011 From: void1999 at gmail.com (zz dd) Date: Mon, 5 Dec 2011 12:42:12 +0100 Subject: [R] nipals in the chemometrics package in R In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From nvanzuydam at gmail.com Mon Dec 5 12:32:10 2011 From: nvanzuydam at gmail.com (natalie.vanzuydam) Date: Mon, 5 Dec 2011 03:32:10 -0800 (PST) Subject: [R] Subsetting a data frame Message-ID: <1323084730989-4160127.post@n4.nabble.com> Hi R users, I really need help with subsetting data frames: I have a large database of medical records and I want to be able to match patterns from a list of search terms . I've used this simplified data frame in a previous example: db <- structure(list(ind = c("ind1", "ind2", "ind3", "ind4"), test1 = c(1, 2, 1.3, 3), test2 = c(56L, 27L, 58L, 2L), test3 = c(1.1, 28, 9, 1.2)), .Names = c("ind", "test1", "test2", "test3"), class = "data.frame", row.names = c(NA, -4L)) terms_include <- c("1","2","3") terms_exclude <- c("1.1","1.2","1.3") So in this example I want to include all the terms from terms include as long as they don't occur with terms exclude in the same row of the data frame. Previously I was given this function which works very well if you want to match exactly: f <- function(x) !any(x %in% terms_exclude) && any(x %in% terms_include) db[apply(db[, -1], 1, f), ] ind test1 test2 test3 2 ind2 2 27 28.0 4 ind4 3 2 1.2 I would like to know if there is a way to write a similar function that looks for matches that start with the query string: as in grepl("^pattern",x) I started writing a function but am not sure how to get it to return the dataframe or matrix: for (i in 1:length(terms_include)){ db_new <- apply(db,2, grepl,pattern=i) } Applying this function gives me: db_new <- structure(c(FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE), .Dim = c(4L, 4L), .Dimnames = list(NULL, c("ind", "test1", "test2", "test3" ))) So the above is searching the pattern anywhere in the dataframe instead of just at the beginning of the string. How would I incorporate look for terms to include but don't return the row of the data frame if it also includes one of the terms to exclude while using partial matching? I hope that this makes sense. Many thanks, Natalie ----- Natalie Van Zuydam PhD Student University of Dundee nvanzuydam at dundee.ac.uk -- View this message in context: http://r.789695.n4.nabble.com/Subsetting-a-data-frame-tp4160127p4160127.html Sent from the R help mailing list archive at Nabble.com. From jdnewmil at dcn.davis.ca.us Mon Dec 5 12:48:35 2011 From: jdnewmil at dcn.davis.ca.us (Jeff Newmiller) Date: Mon, 05 Dec 2011 06:48:35 -0500 Subject: [R] nipals in the chemometrics package in R In-Reply-To: References: Message-ID: <1c18fb68-fdbd-4525-904d-496361f639b1@email.android.com> This is not a homework help list. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN: Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. zz dd wrote: >Hello >The solution maybe there but i need to compute it into R if someone can >help me : >(Previously store score vector t in score matrix T; store loading >vector p >in loading matrix P) that's done by nipals in chemometrics >After use of nipals function you have T and P matrix > >First : "Calculate the residual matrix of X. Stop if the elements of >Xres >are very small >because no further PCA components are reasonable" : >Xres= X-u.b(T) > >u : improved score vector >b: loading vector >X : a mean-centered matrix > >Second : Replace X with Xres and continue with step 2 (with nipals >chemometrics...) for calculation of the next PCA >component. > >If someone can help me ? >Thank's a lot > > >2011/12/1 zz dd > >> Hello >> i need some precision about nipals in the chemometrics package in R . >> >> When i use nipals in chemometrics i obtain T and P matrix. >> >> I really don't understand what to do with these two matrix to obtain >> the scores for every the component (like in spss fo example) >> >> Comp1 Comp2 Comp3 >> quest1 0,8434 0,54333 0,3466 >> quest2 0,665 0,7655 0,433 >> >> Thank you very much for your help >> (I know that X=TP+E)... But don't understand else.... >> > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. From Mintewab.Bezabih at economics.gu.se Mon Dec 5 12:54:25 2011 From: Mintewab.Bezabih at economics.gu.se (Mintewab Bezabih) Date: Mon, 5 Dec 2011 12:54:25 +0100 Subject: [R] problems using the thin plate spline method In-Reply-To: <67c9a4a2-ee18-49b6-a1a1-791a2d3bda2e@email.android.com> References: <4B46FB7EED800046A5952FCFA92D3BA0347DF578CD@HGUMAIL6.hgu.gu.se> <4B46FB7EED800046A5952FCFA92D3BA0347DF578D2@HGUMAIL6.hgu.gu.se>, <4B46FB7EED800046A5952FCFA92D3BA0347DF578D3@HGUMAIL6.hgu.gu.se>, <67c9a4a2-ee18-49b6-a1a1-791a2d3bda2e@email.android.com> Message-ID: <4B46FB7EED800046A5952FCFA92D3BA0347DF578D5@HGUMAIL6.hgu.gu.se> Dear Jeff and R users, Thanks Jeff. Your first plot suggestion worked. And when I stick dat$x1, dat$x2,dat$y, tpsfit seems to work as well. But it gives me a new error message tpsfit <- Tps(cbind(dat$x1, dat$x2), dat$y, scale.type="unscaled") Warning message: In gcv.Krig(out, nstep.cv = nstep.cv, verbose = verbose, cost = out$cost, : Value of pure error estimate is outside possible range Then I get error messages for the subsequent lines as well. I have now attached the data. And here is the full code I am trying to run. dat <- read.table("E:/thin plate/thin plate.csv", header=T, sep=",") names(dat) <- c("x1", "x2", "y") library(fields) plot (dat) #load the fields package (containing Tps) and fit a thin plate spline tpsfit <- Tps(cbind(dat$x1, dat$x2), dat$y, scale.type="unscaled") #predict the thin plate spline on the fine grid and plot the fitting ngrid <- length(xf); grid <- cbind(rep(xf, ngrid), rep(xf, rep(ngrid, ngrid))) out.p1 <- predict(tpsfit, grid) persp(xf, xf, matrix(out.p1, ngrid, ngrid, byrow=F), theta=130, phi=20, expand=0.45, xlab="x1", ylab="x2", zlab="y", xlim=c(0,1), ylim=c(0,1), zlim=range(zf), ticktype="detailed", scale=F, main="gcv fitting") Many thanks once again. regards mintewab Fr?n: Jeff Newmiller [jdnewmil at dcn.davis.ca.us] Skickat: den 5 december 2011 12:39 Till: Mintewab Bezabih; Sarah Goslee Kopia: r-help at r-project.org ?mne: Re: [R] problems using the thin plate spline method Try plot( dat$x1, dat$y ) or plot( x1, y, data=dat ) Note that your example is still not reproducible because you have not supplied the data or a shortened version of your data for us to work with. Also, your problem is not with thin plates but with plot, and reading the help for that function by typing ?plot at the R command line would have provided you with more examples and usage info on how to get around this problem. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN: Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. Mintewab Bezabih wrote: >Dear Sarah and R users, > >Sorry again for not being explicit enough. Here is my full problem > > >dat <- read.table("E:/thin plate/thin plate.csv", header=T, sep=",") >dat >names(dat) <- c("x1", "x2", "y") >library(fields) >plot (dat) > >#load the fields package (containing Tps) and fit a thin plate spline >tpsfit <- Tps(cbind(x1, x2), y, scale.type="unscaled") > >What I meant when I said the graph works is when I do plot(dat) it does >plot of all my three variables. If I do plot(x1,y), though, I get the >'object x1 not found' error message. > >Same when I do the next line tpsfit <- Tps(cbind(x1, x2), y, >scale.type="unscaled"). I get the same error message. > >I tried your suggestion of checking str(x1) and I get the same error >message (object x1 not found). >I also typed ls() and I get "dat" after that command. > >I followed the r tutorial guide to read my data and I am following the >r tutorial to guide me to apply the thin plate spline method. > >Regards, > >Mintewab >________________________________________ >Fr?n: Sarah Goslee [sarah.goslee at gmail.com] >Skickat: den 4 december 2011 15:21 >Till: Mintewab Bezabih >Kopia: r-help at r-project.org >?mne: Re: [R] problems using the thin plate spline method > >Hello, > >On Sun, Dec 4, 2011 at 8:08 AM, Mintewab Bezabih > wrote: >> Dear R users and Jeff, >> >> Sorry for not being quite explicit in my earlier message. > >And you are still not explicit. We have no idea what you've done. > >> My main problem is while my data seem to be read into R well (I >manage to graph them and all), I cannot get the following line to work. >> >> tpsfit <- Tps(cbind(x1, x2), y, scale.type="unscaled") >> >> and I get the following error message >> >> Error in as.matrix(x) : >> error in evaluating the argument 'x' in selecting a method for >function 'as.matrix': Error: object 'x1' not found > >I'd have to guess that there's no object x1. What does ls() tell you? >str(x1)? > >What do your data look like? You were already given instructions on how >to >include sample data to construct a reproducible example. You said that >graphing your data worked; how did you do so? > >The posting guide and the advice you were already given were both >offered for a reason. The querent needs to do the work of formulating >an understandable and answerable question. > >Sarah > >> thanks for help >> minti >> ________________________________________ >> Fr?n: Jeff Newmiller [jdnewmil at dcn.davis.ca.us] >> Skickat: den 3 december 2011 17:45 >> Till: Mintewab Bezabih; r-help at r-project.org >> ?mne: Re: [R] problems using the thin plate spline method >> >> I can tell that you are puzzled and confused. Unfortunately, I am not >psychic, so I cannot tell what you did, and therefore cannot tell where >you went astray. >> >> The solution is for you to read the posting guide mentioned at the >bottom of every R-help message. Spend a little time to create a small >bit of data like yours if your actual data is large (subset and dput >are useful for this). Remember to include the output of sessionInfo, >and so on. Many times you are likely to find the answer yourself by >going through these steps, but they are essential for communication. >> >> Good luck. >> Sent from my phone. Please excuse my brevity. >> >> Mintewab Bezabih wrote: >> >>>Dear R users, >>> >>>I am a beginner in R trying to apply the thin plate spline method to >my >>>climate data. I used the example in R to do so, and the lines seem to >>>run fine ( I am not getting errors) but I am not getting any output >in >>>the form of graph or anything. I got a warning message saying that >>>'surface extends beyond box'. >>> >>>Any help is much appreciated. >>>thanks >>>minti > > >-- >Sarah Goslee >http://www.functionaldiversity.org > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. From chapkovski at gmail.com Mon Dec 5 13:03:42 2011 From: chapkovski at gmail.com (Philipp Chapkovski) Date: Mon, 5 Dec 2011 13:03:42 +0100 Subject: [R] how to just download file on disk by the link Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From julia.lira at hotmail.co.uk Mon Dec 5 13:14:16 2011 From: julia.lira at hotmail.co.uk (Julia Lira) Date: Mon, 5 Dec 2011 12:14:16 +0000 Subject: [R] extract cov matrix in summary.rq and use as a matrix. Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From E.Vettorazzi at uke.de Mon Dec 5 13:21:42 2011 From: E.Vettorazzi at uke.de (Eik Vettorazzi) Date: Mon, 5 Dec 2011 13:21:42 +0100 Subject: [R] Toggle cASE In-Reply-To: <1323069111.20601.YahooMailNeo@web130111.mail.mud.yahoo.com> References: <1323069111.20601.YahooMailNeo@web130111.mail.mud.yahoo.com> Message-ID: <4EDCB756.2080509@uke.de> Hi Antonio, how about this: txt2 <- "useRs may fly into JFK or laGuardia" chartr("a-zA-Z", "A-Za-z", txt2) Cheers. Am 05.12.2011 08:11, schrieb Tonio: > Hello R-help list, > > I am looking for way to toggle the case of the characters like a flip-flop; that is from ''Hello'' to "hELLO" or vice versa. > > I know that there are a number of functions like casefold, tolower, toupper, etc. but these functions change the case in an uniform way. > > Thanks in advance, > > Antonio Rivero Ostoic > > > > > Antonio Rivero Ostoic > PhD Student, Department of Leadership and Strategy > From 1 Jul until 31 Dec 2011 > Tel. +61 3 8344 4300 > Fax +61 3 9347 6618 > Email jaro at sdu.dk > Addr. The University of Melbourne, Victoria 3010 Australia > ------------------------------------------------------------- > UNIVERSITY OF SOUTHERN DENMARK > Sdr. Stationsvej 28 ? DK-4200 Slagelse ? Denmark ? Tel. +45 6550 1000 ? > www.sdu.dk > > [[alternative HTML version deleted]] > > > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Eik Vettorazzi Department of Medical Biometry and Epidemiology University Medical Center Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 -- Pflichtangaben gem?? Gesetz ?ber elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG): Universit?tsklinikum Hamburg-Eppendorf; K?rperschaft des ?ffentlichen Rechts; Gerichtsstand: Hamburg Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. Alexander Kirstein, Joachim Pr?l?, Prof. Dr. Dr. Uwe Koch-Gromus From ggrothendieck at gmail.com Mon Dec 5 13:24:47 2011 From: ggrothendieck at gmail.com (Gabor Grothendieck) Date: Mon, 5 Dec 2011 07:24:47 -0500 Subject: [R] how to just download file on disk by the link In-Reply-To: References: Message-ID: On Mon, Dec 5, 2011 at 7:03 AM, Philipp Chapkovski wrote: > Sorry for stupid question but is there any way to just download file (excel > file) from the url to the disk with a certain name? > Now it seems that I should open it (via read.xls) and then write it by > write.xls. But I am pretty sure it should be something much easier? > read.xls in the gdata package can take the url of an Excel file and will read it into R. (It transparently downloads it into a temporary file and then reads it from there.) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com From void1999 at gmail.com Mon Dec 5 13:27:12 2011 From: void1999 at gmail.com (zz dd) Date: Mon, 5 Dec 2011 13:27:12 +0100 Subject: [R] nipals in the chemometrics package in R In-Reply-To: <1c18fb68-fdbd-4525-904d-496361f639b1@email.android.com> References: <1c18fb68-fdbd-4525-904d-496361f639b1@email.android.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From Marianne.ZEYRINGER at ec.europa.eu Mon Dec 5 13:44:14 2011 From: Marianne.ZEYRINGER at ec.europa.eu (Marianne.ZEYRINGER at ec.europa.eu) Date: Mon, 5 Dec 2011 13:44:14 +0100 Subject: [R] spatial analysis Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From michael.weylandt at gmail.com Mon Dec 5 13:55:45 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt ) Date: Mon, 5 Dec 2011 07:55:45 -0500 Subject: [R] extract cov matrix in summary.rq and use as a matrix. In-Reply-To: References: Message-ID: I'm not at my desk so this is untested, but I'm pretty sure double brackets will do the trick: qf2_1[[3]] M On Dec 5, 2011, at 7:14 AM, Julia Lira wrote: > > Dear all, > > I need to extract the covariance matrix of my quantile regression estimation to use in a test. My regression is: > > qf2_1 <- summary(rq(wb2 ~ apv2 + vol2, tau = phi2[1]), cov = TRUE) > > I can extract the covaraince matrix by using: qf2_1 [3]. However, if I try to use it in the test, it does not work. I only need to transform qf2_1[3] in a matrix 3x3. I have already tried: matrix(qf2_1[3], nrow=3, ncol=3) but it also does not work. By using the latter, I find: > [,1] [,2] [,3] > [1,] Numeric,9 Numeric,9 Numeric,9 > [2,] Numeric,9 Numeric,9 Numeric,9 > [3,] Numeric,9 Numeric,9 Numeric,9 > > Is there any other way to do it? > > Thanks a lot in advance! > > All the best, > > Julia > > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From michael.weylandt at gmail.com Mon Dec 5 14:02:15 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt ) Date: Mon, 5 Dec 2011 08:02:15 -0500 Subject: [R] equating approximate values In-Reply-To: <1323043462928-4158691.post@n4.nabble.com> References: <1323021640135-4157551.post@n4.nabble.com> <1323043462928-4158691.post@n4.nabble.com> Message-ID: <7DDE0973-E5AF-4299-87D6-EF46555EBB74@gmail.com> Change which to which.min, but then you won't easily be able to get the corresponding x,y indices. Look at the arrayInd() function to translate the result to a particular x,y. Michael On Dec 4, 2011, at 7:04 PM, vamshi999 wrote: > this is exactly what i wanted. > > How to i select only the minimum value from this?. > > thank you > > > > > My apologies: you need an abs() call as well: > > which(abs(outer(x, y, "-")) < threshold, arr.ind = TRUE) > > Michael > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/equating-approximate-values-tp4157551p4158691.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From michael.weylandt at gmail.com Mon Dec 5 14:04:36 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt ) Date: Mon, 5 Dec 2011 08:04:36 -0500 Subject: [R] problems using the thin plate spline method In-Reply-To: <4B46FB7EED800046A5952FCFA92D3BA0347DF578D5@HGUMAIL6.hgu.gu.se> References: <4B46FB7EED800046A5952FCFA92D3BA0347DF578CD@HGUMAIL6.hgu.gu.se> <4B46FB7EED800046A5952FCFA92D3BA0347DF578D2@HGUMAIL6.hgu.gu.se> <4B46FB7EED800046A5952FCFA92D3BA0347DF578D3@HGUMAIL6.hgu.gu.se> <67c9a4a2-ee18-49b6-a1a1-791a2d3bda2e@email.android.com> <4B46FB7EED800046A5952FCFA92D3BA0347DF578D5@HGUMAIL6.hgu.gu.se> Message-ID: <292964CB-7BD6-4F59-BC60-1256C3571180@gmail.com> Your data was scrubbed by the server. Use dput() to create a plain text representation of dat you can put in the body of the email. Michael On Dec 5, 2011, at 6:54 AM, Mintewab Bezabih wrote: > Dear Jeff and R users, > > Thanks Jeff. > > Your first plot suggestion worked. And when I stick dat$x1, dat$x2,dat$y, tpsfit seems to work as well. But it gives me a new error message > > tpsfit <- Tps(cbind(dat$x1, dat$x2), dat$y, scale.type="unscaled") > > Warning message: > In gcv.Krig(out, nstep.cv = nstep.cv, verbose = verbose, cost = out$cost, : > Value of pure error estimate is outside possible range > > Then I get error messages for the subsequent lines as well. > > I have now attached the data. And here is the full code I am trying to run. > > > dat <- read.table("E:/thin plate/thin plate.csv", header=T, sep=",") > names(dat) <- c("x1", "x2", "y") > library(fields) > plot (dat) > > #load the fields package (containing Tps) and fit a thin plate spline > tpsfit <- Tps(cbind(dat$x1, dat$x2), dat$y, scale.type="unscaled") > > #predict the thin plate spline on the fine grid and plot the fitting > ngrid <- length(xf); grid <- cbind(rep(xf, ngrid), rep(xf, rep(ngrid, ngrid))) > out.p1 <- predict(tpsfit, grid) > > > persp(xf, xf, matrix(out.p1, ngrid, ngrid, byrow=F), theta=130, phi=20, > expand=0.45, xlab="x1", ylab="x2", zlab="y", xlim=c(0,1), ylim=c(0,1), > zlim=range(zf), ticktype="detailed", scale=F, main="gcv fitting") > > Many thanks once again. > > regards > mintewab > > > > Fr?n: Jeff Newmiller [jdnewmil at dcn.davis.ca.us] > Skickat: den 5 december 2011 12:39 > Till: Mintewab Bezabih; Sarah Goslee > Kopia: r-help at r-project.org > ?mne: Re: [R] problems using the thin plate spline method > > Try > > plot( dat$x1, dat$y ) > > or > > plot( x1, y, data=dat ) > > Note that your example is still not reproducible because you have not supplied the data or a shortened version of your data for us to work with. Also, your problem is not with thin plates but with plot, and reading the help for that function by typing > > ?plot > > at the R command line would have provided you with more examples and usage info on how to get around this problem. > --------------------------------------------------------------------------- > Jeff Newmiller The ..... ..... Go Live... > DCN: Basics: ##.#. ##.#. Live Go... > Live: OO#.. Dead: OO#.. Playing > Research Engineer (Solar/Batteries O.O#. #.O#. with > /Software/Embedded Controllers) .OO#. .OO#. rocks...1k > --------------------------------------------------------------------------- > Sent from my phone. Please excuse my brevity. > > Mintewab Bezabih wrote: > >> Dear Sarah and R users, >> >> Sorry again for not being explicit enough. Here is my full problem >> >> >> dat <- read.table("E:/thin plate/thin plate.csv", header=T, sep=",") >> dat >> names(dat) <- c("x1", "x2", "y") >> library(fields) >> plot (dat) >> >> #load the fields package (containing Tps) and fit a thin plate spline >> tpsfit <- Tps(cbind(x1, x2), y, scale.type="unscaled") >> >> What I meant when I said the graph works is when I do plot(dat) it does >> plot of all my three variables. If I do plot(x1,y), though, I get the >> 'object x1 not found' error message. >> >> Same when I do the next line tpsfit <- Tps(cbind(x1, x2), y, >> scale.type="unscaled"). I get the same error message. >> >> I tried your suggestion of checking str(x1) and I get the same error >> message (object x1 not found). >> I also typed ls() and I get "dat" after that command. >> >> I followed the r tutorial guide to read my data and I am following the >> r tutorial to guide me to apply the thin plate spline method. >> >> Regards, >> >> Mintewab >> ________________________________________ >> Fr?n: Sarah Goslee [sarah.goslee at gmail.com] >> Skickat: den 4 december 2011 15:21 >> Till: Mintewab Bezabih >> Kopia: r-help at r-project.org >> ?mne: Re: [R] problems using the thin plate spline method >> >> Hello, >> >> On Sun, Dec 4, 2011 at 8:08 AM, Mintewab Bezabih >> wrote: >>> Dear R users and Jeff, >>> >>> Sorry for not being quite explicit in my earlier message. >> >> And you are still not explicit. We have no idea what you've done. >> >>> My main problem is while my data seem to be read into R well (I >> manage to graph them and all), I cannot get the following line to work. >>> >>> tpsfit <- Tps(cbind(x1, x2), y, scale.type="unscaled") >>> >>> and I get the following error message >>> >>> Error in as.matrix(x) : >>> error in evaluating the argument 'x' in selecting a method for >> function 'as.matrix': Error: object 'x1' not found >> >> I'd have to guess that there's no object x1. What does ls() tell you? >> str(x1)? >> >> What do your data look like? You were already given instructions on how >> to >> include sample data to construct a reproducible example. You said that >> graphing your data worked; how did you do so? >> >> The posting guide and the advice you were already given were both >> offered for a reason. The querent needs to do the work of formulating >> an understandable and answerable question. >> >> Sarah >> >>> thanks for help >>> minti >>> ________________________________________ >>> Fr?n: Jeff Newmiller [jdnewmil at dcn.davis.ca.us] >>> Skickat: den 3 december 2011 17:45 >>> Till: Mintewab Bezabih; r-help at r-project.org >>> ?mne: Re: [R] problems using the thin plate spline method >>> >>> I can tell that you are puzzled and confused. Unfortunately, I am not >> psychic, so I cannot tell what you did, and therefore cannot tell where >> you went astray. >>> >>> The solution is for you to read the posting guide mentioned at the >> bottom of every R-help message. Spend a little time to create a small >> bit of data like yours if your actual data is large (subset and dput >> are useful for this). Remember to include the output of sessionInfo, >> and so on. Many times you are likely to find the answer yourself by >> going through these steps, but they are essential for communication. >>> >>> Good luck. >>> Sent from my phone. Please excuse my brevity. >>> >>> Mintewab Bezabih wrote: >>> >>>> Dear R users, >>>> >>>> I am a beginner in R trying to apply the thin plate spline method to >> my >>>> climate data. I used the example in R to do so, and the lines seem to >>>> run fine ( I am not getting errors) but I am not getting any output >> in >>>> the form of graph or anything. I got a warning message saying that >>>> 'surface extends beyond box'. >>>> >>>> Any help is much appreciated. >>>> thanks >>>> minti >> >> >> -- >> Sarah Goslee >> http://www.functionaldiversity.org >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From bia.cdc at gmail.com Mon Dec 5 13:25:14 2011 From: bia.cdc at gmail.com (bcdc) Date: Mon, 5 Dec 2011 04:25:14 -0800 (PST) Subject: [R] iterative variable names In-Reply-To: <511429D6-561A-4EA6-95A1-44A936973BEE@gmail.com> References: <1323079206895-4159888.post@n4.nabble.com> <511429D6-561A-4EA6-95A1-44A936973BEE@gmail.com> Message-ID: <1323087914497-4160262.post@n4.nabble.com> Thank you very much, assign was exactly what I needed! For my case, it worked better than list! :) Beatriz -- View this message in context: http://r.789695.n4.nabble.com/iterative-variable-names-tp4159888p4160262.html Sent from the R help mailing list archive at Nabble.com. From amsaya2000 at gmail.com Mon Dec 5 13:53:38 2011 From: amsaya2000 at gmail.com (Amsalu Walelign) Date: Mon, 5 Dec 2011 15:53:38 +0300 Subject: [R] Dynamic Linear Models for Times Series - Implemented? Message-ID: Dear sir, As far as my understanding goes, the book ?dynamic linear models with R? does everything based up on the non innovations form. The problem is that I couldn?t find auxiliary residuals, which can be used to check for the presence of outliers and structural breaks. R packages ?dlm? and ?dlmodeler? use this form of model construction. Hence I am stuck in the middle of my work. Is there some R package which performs disturbance smoothing, or use the innovations form? Thanks beforehand! Amsaya From jholtman at gmail.com Mon Dec 5 14:10:35 2011 From: jholtman at gmail.com (jim holtman) Date: Mon, 5 Dec 2011 08:10:35 -0500 Subject: [R] Subsetting a data frame In-Reply-To: <1323084730989-4160127.post@n4.nabble.com> References: <1323084730989-4160127.post@n4.nabble.com> Message-ID: does this do what you want: > db <- structure(list(ind = c("ind1", "ind2", "ind3", "ind4"), test1 = c(1, + 2, 1.3, 3), test2 = c(56L, 27L, 58L, 2L), test3 = c(1.1, 28, + 9, 1.2)), .Names = c("ind", "test1", "test2", "test3"), class = + "data.frame", row.names = c(NA, + -4L)) > > terms_include <- c("1","2","3") > terms_exclude <- c("1.1","1.2","1.3") > > f.match <- function(obj, inc, exc){ + pat <- paste("^(", paste(inc, collapse = "|"), ")", sep = '') + patex <- paste(exc, collapse = "|") + isMatch <- apply(obj, 1, function(x) any(grepl(pat, x))) + notMatch <- !apply(obj, 1, function(x) any(grepl(patex, x))) + obj[isMatch & notMatch,] + } > > db ind test1 test2 test3 1 ind1 1.0 56 1.1 2 ind2 2.0 27 28.0 3 ind3 1.3 58 9.0 4 ind4 3.0 2 1.2 > f.match(db, terms_include, terms_exclude) ind test1 test2 test3 2 ind2 2 27 28 > On Mon, Dec 5, 2011 at 6:32 AM, natalie.vanzuydam wrote: > Hi R users, > > I really need help with subsetting ?data frames: > > I have a large database of medical records and I want to be able to match > patterns from a list of search terms . > > I've used this simplified data frame in a previous example: > > > db <- structure(list(ind = c("ind1", "ind2", "ind3", "ind4"), test1 = c(1, > 2, 1.3, 3), test2 = c(56L, 27L, 58L, 2L), test3 = c(1.1, 28, > 9, 1.2)), .Names = c("ind", "test1", "test2", "test3"), class = > "data.frame", row.names = c(NA, > -4L)) > > terms_include <- c("1","2","3") > terms_exclude <- c("1.1","1.2","1.3") > > > So in this example I want to include all the terms from terms include as > long as they don't occur with terms exclude in the same row of the data > frame. > > Previously I was given this function which works very well if you want to > match exactly: > > > f <- function(x) ?!any(x %in% terms_exclude) && any(x %in% terms_include) > db[apply(db[, -1], 1, f), ] > > ? ind test1 test2 test3 > 2 ind2 ? ? 2 ? ?27 ?28.0 > 4 ind4 ? ? 3 ? ? 2 ? 1.2 > > > I would like to know if there is a way to write a similar function that > looks for matches that start with the query string: ?as in > grepl("^pattern",x) > > I started writing a function but am not sure how to get it to return the > dataframe or matrix: > > > for (i in 1:length(terms_include)){ > db_new <- apply(db,2, grepl,pattern=i) > } > > Applying this function gives me: > > db_new <- structure(c(FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, > FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE), .Dim = c(4L, > 4L), .Dimnames = list(NULL, c("ind", "test1", "test2", "test3" > ))) > > So the above is searching the pattern anywhere in the dataframe instead of > just at the beginning of the string. > > How would I incorporate look for terms to include but don't return the row > of the data frame if it also includes one of the terms to exclude while > using partial matching? > > I hope that this makes sense. > > Many thanks, > Natalie > > ----- > Natalie Van Zuydam > > PhD Student > University of Dundee > nvanzuydam at dundee.ac.uk > -- > View this message in context: http://r.789695.n4.nabble.com/Subsetting-a-data-frame-tp4160127p4160127.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. From therneau at mayo.edu Mon Dec 5 14:24:03 2011 From: therneau at mayo.edu (Terry Therneau) Date: Mon, 05 Dec 2011 07:24:03 -0600 Subject: [R] Partitioning Around Mediods then rpart to follow In-Reply-To: References: Message-ID: <1323091443.1719.3.camel@nemo> Yes, that seems like a sensible idea to me. Terry Therneau On Sat, 2011-12-03 at 12:00 +0100, r-help-request at r-project.org wrote: > The problem: There are no a priori groupings to run a classification > on > > My solution: > > This is a non-R code question, so I appreciate any thoughts. I have > used pam in the cluster package proceeded by sillohouette to find the > optimum number of clusters on scaled and centered data. I have > followed > this by a classification tree analysis with rpart to discern which > variables drive the clustering on the original data. Is this a > sensible > approach? > many thanks, > > Stephen Sefick > From Mintewab.Bezabih at economics.gu.se Mon Dec 5 14:24:58 2011 From: Mintewab.Bezabih at economics.gu.se (Mintewab Bezabih) Date: Mon, 5 Dec 2011 14:24:58 +0100 Subject: [R] problems using the thin plate spline method In-Reply-To: <292964CB-7BD6-4F59-BC60-1256C3571180@gmail.com> References: <4B46FB7EED800046A5952FCFA92D3BA0347DF578CD@HGUMAIL6.hgu.gu.se> <4B46FB7EED800046A5952FCFA92D3BA0347DF578D2@HGUMAIL6.hgu.gu.se> <4B46FB7EED800046A5952FCFA92D3BA0347DF578D3@HGUMAIL6.hgu.gu.se> <67c9a4a2-ee18-49b6-a1a1-791a2d3bda2e@email.android.com> <4B46FB7EED800046A5952FCFA92D3BA0347DF578D5@HGUMAIL6.hgu.gu.se>, <292964CB-7BD6-4F59-BC60-1256C3571180@gmail.com> Message-ID: <4B46FB7EED800046A5952FCFA92D3BA0347DF578D6@HGUMAIL6.hgu.gu.se> Thanks Michael here is my data structure(list(x1 = c(409.5, 349, 385.5, 273, 543, 746, 198.75, 262.5, 320.5, 259, 399.5, 595.5, 374, 293, 330, 658, 299, 775, 559.75, 251, 402, 395.5, 345.5, 283.5, 452, 816.5, 266.5, 360.25, 386, 160.25, 360, 337, 326, 758, 342.5, 389, 347.5, 819.25, 355.25, 281, 494.5, 514.5, 263, 439, 263, 373.25, 546, 348, 380.5, 606, 460, 352.5, 737, 275, 520.5, 385.25, 354.5, 383.5, 322.5, 309, 502.5, 517, 276, 400.5, 272.5, NA, 253, 311, 389, 157.75, 520, 499.5, 481, 448.5, 335.5, 231.5, 492.5, 477.5, 650, 540.75, 620.5, 400.5, 331.5, 311, 229, 432.5, 422.75, 493.5, 414.25, 487, 369, 425, 233.5, 254.5, 417.5, NA, 583.25, 492.5, 490, 300.25, NA, 270, 307, 319, 374.5, 562.5, 569.5, 389.75, 341.25, 366, 262.75, 776.25, 379.5, 360, 203.75, 517, 539.5, 418.75, 353.5, 269, 475.5, 472, 342, 189, 492.5, 412, 467.5, 209.75, 340.75, 231.5, 185.5, 358.5, 354, 670.5, 686, 364, 138, 272, 183, 365.25, 188, 229.5, 553.5, 582.5, 469, 359.5, 284.25, 582.5, 287, NA, 455.25, 410.5, 477, 239, 313.5, 294.5, 523, 372.5, 231.5, NA, 365, 269.5, 394.5, 281.5, 418.5, 553.5, 245.75, 304, 423.75, 369.5, 330.5, 278, 257, 416.5, 413.25, 465.5, 877.25, 204, 475, 289, 425.75, 405, 494.25, 332, 552.5, 433.75, 821, 841.5, 226.5, 266.75, 552, 157.5, 528.5, 248.5, 245.5, 303, 444.25, 310, 768.25, 265.5, 98.25, 525, 407.75, 163.5, 374.25, 749, 318.5, 367, 250, 408, 341.5, 266.5, 348.5, 398.5, 429.5, 420, 263.5, 581.5, 509.5, 724.75, 476.5, 249.5, 297.5, 245, 139.5, 360.5, 983.5, 465.5, 263.75, NA, 510, 325, 122.5, 455.5, 531, 318, 373, 487, 401, 451.75, 561, 364.5, 439.5, 733.5, 455, 376.5, 554, 409.5, 1007.5, 462.5, 183, 342.5, 304, 258.25, 380.5, 373, 683, 577, 430, 324.25, 312, 389, 345, 358.5, 551.75, 317.5, 499, 335.5, 450.5, 363.5, 185, 177.5, 477.75, 644.5, 290.25, 457.5, 295.5, 266.5, 348.5, 357.75, 221.5, 739, 445.5, 416, 261.5, 909, 737.5, 194.5, 438.5, 358, 244, 388.5, 512.5, 315.25, 572, 473.75, 627.5, 507.75, 281, 511.5, 309.25, 308.25, 690, 180, 341.5, 273, 571, 694, 345, 497, 219, 311.5, 458.5, 283, 274, 282.5, 187.5, 332, 281.75, 397.75, 336.5, 392.5, 318, 609.5, 203.5, 144.5, 504.75, 647, 374, 149.5, 319, 306, 304.75, 304.5, 247, 329, 442, 308, 316, 219, 556.5, 643.5, 328.5, 301, 467, 452.5, 351.5, 373, 503.5, 287.5, 393.5, 444, 734, 458.5, 1182, 406, 286.5, 283.5, 642.5, 453.5, 206, 258, 412, 551, 784.75, 316.5, 326.5, 202.25, 336.75, 406, 225.5, 266, 916.5, 387, 496.25, 389, 668.5, 192, 396, 282.5, 414.5, 355, 294.5, 396.5, 348.75, 241.75, 347.5, 250, 473.5, 369, 672, 199.5, 318.25, 219.75, 124, 514.25, 600.5, 256, 574.75, 346.25, 397, 195, 494, 567.5, 431.5, 144.5, 440, 525.5, 375.5, 841.5, 386.25, 490.5, 296.5, 812.25, 385, 232.5, 239.25, 316.5, 312.25, 257.75, NA, 389, 301.5, 242.25, 400.25, 367.25, 321.5, 301, 223, 360, 662.5, 407.5, 736, 379.5, 852, 355, 397, 527.5, 531.25, 473, 559.75, 344, 379.75, 459, 322, 208.5, 424.25, 342.25, 414.5, 308, 574.5, 635, 449.5, 286, 986.25, 563.5, 596, 492, 265, 826.5, 557, 387.5, 531.5, 464, 582, 354.5, 382.75, 833, 347.25, 615.25, 389, 354.25, 564, 890.5, 168, 467.25, 554.5, 296, 744.5, 387.25, 393.25, 331, 391, 274, 707.75, 467.5, 160.5, 569.5, 340.5, 259, 321.75, 286.25, 416.5, 459.25, 276.5, 280.25, 258.5, 309.5, 424.5, 365, 809, 238.75, 524, 563.5, 419, 354.5, 303, 167.5, 236.25, 268, 330.5, 251.5, 249, 443.5, 411.5, 323.5, 485.25, 356.5, 221.5, 515.5, 462, 322.5, 602.5, 446.25, 489.75, 396.5, NA, 222.5, 365.5, 386, 286, 448, 379.75, 293.5, 410, 335.5, 444.5, 464.75, 364.25, 360, 589, 546.5, 470, 304.5, NA, 501.5, 459.5, 715, 349, 285, 268, 507.5, 441.5, 188.5, 186.5, 679, 249, 200, 419.5, 294.25, 596, 395.75, 314.75, 412.5, 363.75, 218.5, 208.5, 535.5, 309.75, 336, 217, 245.5, 608.75, 375, 555.5, 621, 488.5, 271.5, 331.5, 286, 555, 345, 529.5, 370, 584.25, 208.5, 473.5, 244, 296.25, 598, 456.25, 371, 505.5, 269.5, 284, 420.75, 358.25, 476.75, 363, 485.75, 570, 567.25, 355.5, 444, 629, 367.5, 174.5, 217, 239, 378.5, 179.5, 188, 355, 304.5, 354.5, 207.5, 615, 163.5, 374, 316.5, 79, 409, 218.25, 452, 398, 277.5, 289.25, 491, 515 ), x2 = c(673, 335, 1737, 457, 2325, 1255, 388, 104, 786, 516, 542, 916, 1257, 229, 490, 1016, 266, 1139, 1023, 153, 253, 319, 456, 400, 388, 941, 307, 683, 528, 368, 455, 488, 702, 1040, 405, 483, 524, 490, 517, 505, 844, 429, 349, 549, 450, 1212, 546, 485, 378, 598, 838, 519, 624, 185, 632, 696.5, 524, 618, 381, 380, 624, 612, 260, 831, 451, 284, 353, 720, 583, 344, 1175, 761, 694, 606, 239, 273, 394, 899, 721, 730, 1295, 1148, 524, 578, 262, 326, 217, 648, 485, 726, 747, 1663, 269, 488.5, 1137, 310, 434, 536, 486, 1225, 462, 237, 230, 242, 340, 521, 242, 389, 691, 387, 615, 1926, 597, 299, 213, 618, 684, 439, 459, 366, 1098, 384, 488, 181, 5342, 433, 1475, 480, 207, 153, 295, 524, 453, 978, 486, 676, 336, 254, 273, 255, 347, 420, 603, 739, 340, 572, 441, 833, 775, 129, 350, 1445, 328, 585, 412, 446, 679, 519, 372, 1712, 167, 492, 593, 210, 363, 630, 261, 869, 676, 253, 923, 791, 415, 349, 825, 486, 508, 191, 282, 267, 372, 639, 687, 1427, 847, 368, 616, 1723, 310, 449, 301, 378, 573, 273, 405, 653, 606, 943, 926, 399, 282, 1112, 484, 408, 434, 595, 223, 517, 323, 353, 628, 334, 502, 861, 361, 464, 285, 693, 129, 817, 516, 291, 211, 232, 269, 378, 2560.5, 662, 580, 531, 1334, 384, 217, 714, 766, 648, 288, 722, 917, 359, 576, 383, 546, 1379, 622, 201, 549, 575, 1416, 496, 111, 406, 519, 294, 343, 437, 972, 1403, 471, 368, 459, 617, 444, 312, 963, 315, 549, 1022, 423, 384, 195, 265, 827, 827, 309, 546, 385, 380, 422, 188, 378, 772, 233, 339, 952, 1336, 1740, 256, 772, 462, 254, 243, 332, 871, 562, 1761, 689, 623, 286, 233, 668, 1078, 682, 169, 437, 943, 724, 614, 439, 344, 297, 384, 569, 187, 498, 335, 339, 289, 431, 549, 334, 482, 363, 663, 192, 60, 468, 582, 365, 479, 983, 668, 605, 231, 457, 469, 664, 490, 274, 580, 476, 385, 302, 607, 1723, 441, 463, 229, 138, 279, 245, 1081, 1080, 1745, 1157, 338, 571, 211, 2256, 778, 224, 158, 393, 661.5, 4828, 478, 687, 497, 244, 455, 390, 271, 849, 316, 785, 464, 509, 338, 567, 726, 742, 515, 245, 501, 359, 220, 555, 424, 592, 1470, 441, 177, 1302, 245, 429, 597, 809, 835, 1548, 568, 310, 218, 904, 1276, 538, 315, 526, 604, 506, 1836, 365, 889, 508, 446, 999, 392, 189, 377, 335, 214, 469, 530, 197, 630, 814, 1305, 932, 753, 361, 1139, 639, 908, 1535, 483, 786, 476, 467, 703, 830, 565, 883, 1569, 1071, 261, 564, 645, 365, 587, 585, 395, 673, 940, 1002, 225, 1311, 471, 629, 433, 213, 1335, 662, 565, 1028, 442, 548, 418, 741, 798, 482, 595, 362, 580, 953, 1057, 171, 834, 466, 861, 1624, 648, 394, 1008, 626, 442, 530, 716, 211, 960.5, 511, 335, 452, 661, 303, 411, 336, 681, 450, 346, 417, 458, 1313, 795, 529, 203, 699, 500, 282, 339, 479, 361, 330, 366, 169, 882, 3209, 225, 1158, 701, 316, 646, 682, 414, 869, 761, 645, 641, 669, 260, 1155, 908, 878, 609, 519, 313, 527, 511, 538, 339, 803, 232, 773, 1739, 567, 248, 1375, 1340, 456, 1470, 459, 480, 396, 566, 668, 555, 198, 1479, 229, 227, 500, 560, 927, 412, 403, 397, 527, 385, 381, 582, 539, 426, 361, 1212, 624, 469, 294, 1194, 620, 234, 446, 177, 893, 489, 426, 699, 539, 486, 887, 321, 235, 501, 586, 509, 687, 520, 820, 758, 441, 876, 661, 638, 512, 518, 695, 397, 179, 450, 98, 94, 100, 216, 86, 149, 338, 324, 460, 124, 375, 255, 356, 263, 64, 374, 477, 664, 370, 416, 416, 741, 1136), y = c(1082.5, 684, 2122.5, 730, 2868, 2001, 586.75, 366.5, 1106.5, 775, 941.5, 1511.5, 1631, 522, 820, 1674, 565, 1914, 1582.75, 404, 655, 714.5, 801.5, 683.5, 840, 1757.5, 573.5, 1043.25, 914, 528.25, 815, 825, 1028, 1798, 747.5, 872, 871.5, 1309.25, 872.25, 786, 1338.5, 943.5, 612, 988, 713, 1585.25, 1092, 833, 758.5, 1204, 1298, 871.5, 1361, 460, 1152.5, 1081.75, 878.5, 1001.5, 703.5, 689, 1126.5, 1129, 513, 1231.5, 723.5, NA, 606, 1031, 972, 501.75, 1695, 1260.5, 1275, 1054.5, 574.5, 504.5, 886.5, 1376.5, 1371, 1270.75, 1915.5, 1548.5, 855.5, 889, 491, 758.5, 639.75, 1141.5, 899.25, 1213, 1116, 2088, 502.5, 743, 1554.5, NA, 1017.25, 1028.5, 976, 1525.25, NA, 507, 537, 561, 714.5, 1083.5, 811.5, 778.75, 1032.25, 753, 877.75, 2702.25, 976.5, 659, 416.75, 1135, 1223.5, 857.75, 812.5, 635, 1573.5, 856, 830, 370, 5834.5, 845, 1942.5, 689.75, 547.75, 384.5, 480.5, 882.5, 807, 1648.5, 1172, 1040, 474, 526, 456, 620.25, 535, 649.5, 1156.5, 1321.5, 809, 931.5, 725.25, 1415.5, 1062, NA, 805.25, 1855.5, 805, 824, 725.5, 740.5, 1202, 891.5, 603.5, NA, 532, 761.5, 987.5, 491.5, 781.5, 1183.5, 506.75, 1173, 1099.75, 622.5, 1253.5, 1069, 672, 765.5, 1238.25, 951.5, 1385.25, 395, 757, 556, 797.75, 1044, 1181.25, 1759, 1399.5, 801.75, 1437, 2564.5, 536.5, 715.75, 853, 535.5, 1101.5, 521.5, 650.5, 956, 1050.25, 1253, 1694.25, 664.5, 380.25, 1637, 891.75, 571.5, 808.25, 1344, 541.5, 884, 573, 761, 969.5, 600.5, 850.5, 1259.5, 790.5, 884, 548.5, 1274.5, 610.5, 1541.75, 992.5, 540.5, 508.5, 477, 408.5, 738.5, 3544, 1127.5, 843.75, NA, 1844, 709, 339.5, 1169.5, 1297, 966, 661, 1209, 1318, 810.75, 1137, 747.5, 985.5, 2112.5, 1077, 577.5, 1103, 984.5, 2423.5, 958.5, 294, 748.5, 823, 552.25, 723.5, 810, 1655, 1980, 901, 692.25, 771, 1006, 789, 670.5, 1514.75, 632.5, 1048, 1357.5, 873.5, 747.5, 380, 442.5, 1304.75, 1471.5, 599.25, 1003.5, 680.5, 646.5, 770.5, 545.75, 599.5, 1511, 678.5, 755, 1213.5, 2245, 2477.5, 450.5, 1210.5, 820, 498, 631.5, 844.5, 1186.25, 1134, 2234.75, 1316.5, 1130.75, 567, 744.5, 977.25, 1386.25, 1372, 349, 778.5, 1216, 1295, 1308, 784, 841, 516, 695.5, 1027.5, 470, 772, 617.5, 526.5, 621, 712.75, 946.75, 670.5, 874.5, 681, 1272.5, 395.5, 204.5, 972.75, 1229, 739, 658.5, 1302, 974, 909.75, 535.5, 704, 798, 1106, 798, 590, 799, 1032.5, 1028.5, 630.5, 908, 2190, 893.5, 814.5, 602, 641.5, 566.5, 638.5, 1525, 1814, 2203.5, 2339, 744, 857.5, 494.5, 2898.5, 1231.5, 430, 416, 805, 1212.5, 5612.75, 794.5, 1013.5, 699.25, 580.75, 861, 615.5, 537, 1765.5, 703, 1281.25, 853, 1177.5, 530, 963, 1008.5, 1156.5, 870, 539.5, 897.5, 707.75, 461.75, 902.5, 674, 1065.5, 1839, 1113, 376.5, 1620.25, 464.75, 553, 1111.25, 1409.5, 1091, 2122.75, 914.25, 707, 413, 1398, 1843.5, 969.5, 459.5, 966, 1129.5, 881.5, 2677.5, 751.25, 1379.5, 804.5, 1258.25, 1384, 624.5, 428.25, 693.5, 647.25, 471.75, NA, 919, 498.5, 872.25, 1214.25, 1672.25, 1253.5, 1054, 584, 1499, 1301.5, 1315.5, 2271, 862.5, 1638, 831, 864, 1230.5, 1361.25, 1038, 1442.75, 1913, 1450.75, 720, 886, 853.5, 789.25, 929.25, 999.5, 703, 1247.5, 1575, 1451.5, 511, 2297.25, 1034.5, 1225, 925, 478, 2161.5, 1219, 952.5, 1559.5, 906, 1130, 772.5, 1123.75, 1631, 829.25, 1210.25, 751, 934.25, 1517, 1947.5, 339, 1301.25, 1020.5, 1157, 2368.5, 1035.25, 787.25, 1339, 1017, 716, 1237.75, 1183.5, 371.5, 1530, 851.5, 594, 773.75, 947.25, 719.5, 870.25, 612.5, 961.25, 708.5, 655.5, 841.5, 823, 2122, 1033.75, 1053, 766.5, 1118, 854.5, 585, 506.5, 715.25, 629, 660.5, 617.5, 418, 1325.5, 3620.5, 548.5, 1643.25, 1057.5, 537.5, 1161.5, 1144, 736.5, 1471.5, 1207.25, 1134.75, 1037.5, NA, 482.5, 1520.5, 1294, 1164, 1057, 898.75, 606.5, 937, 846.5, 982.5, 803.75, 1167.25, 592, 1362, 2285.5, 1037, 552.5, NA, 1841.5, 915.5, 2185, 808, 765, 664, 1073.5, 1109.5, 743.5, 384.5, 2158, 478, 427, 919.5, 854.25, 1523, 807.75, 717.75, 809.5, 890.75, 603.5, 589.5, 1117.5, 848.75, 762, 578, 1457.5, 1232.75, 844, 849.5, 1815, 1108.5, 505.5, 777.5, 463, 1448, 834, 955.5, 1069, 1123.25, 694.5, 1360.5, 565, 531.25, 1099, 1042.25, 880, 1192.5, 789.5, 1104, 1178.75, 799.25, 1352.75, 1024, 1123.75, 1082, 1085.25, 1050.5, 841, 808, 817.5, 272.5, 311, 339, 594.5, 265.5, 337, 693, 628.5, 814.5, 331.5, 990, 418.5, 730, 579.5, 143, 783, 695.25, 1116, 768, 693.5, 705.25, 1232, 1651)), .Names = c("x1", "x2", "y"), class = "data.frame", row.names = c(NA, -629L)) mintewab ________________________________________ Fr?n: R. Michael Weylandt [michael.weylandt at gmail.com] Skickat: den 5 december 2011 14:04 Till: Mintewab Bezabih Kopia: Jeff Newmiller; Sarah Goslee; r-help at r-project.org ?mne: Re: [R] problems using the thin plate spline method Your data was scrubbed by the server. Use dput() to create a plain text representation of dat you can put in the body of the email. Michael On Dec 5, 2011, at 6:54 AM, Mintewab Bezabih wrote: > Dear Jeff and R users, > > Thanks Jeff. > > Your first plot suggestion worked. And when I stick dat$x1, dat$x2,dat$y, tpsfit seems to work as well. But it gives me a new error message > > tpsfit <- Tps(cbind(dat$x1, dat$x2), dat$y, scale.type="unscaled") > > Warning message: > In gcv.Krig(out, nstep.cv = nstep.cv, verbose = verbose, cost = out$cost, : > Value of pure error estimate is outside possible range > > Then I get error messages for the subsequent lines as well. > > I have now attached the data. And here is the full code I am trying to run. > > > dat <- read.table("E:/thin plate/thin plate.csv", header=T, sep=",") > names(dat) <- c("x1", "x2", "y") > library(fields) > plot (dat) > > #load the fields package (containing Tps) and fit a thin plate spline > tpsfit <- Tps(cbind(dat$x1, dat$x2), dat$y, scale.type="unscaled") > > #predict the thin plate spline on the fine grid and plot the fitting > ngrid <- length(xf); grid <- cbind(rep(xf, ngrid), rep(xf, rep(ngrid, ngrid))) > out.p1 <- predict(tpsfit, grid) > > > persp(xf, xf, matrix(out.p1, ngrid, ngrid, byrow=F), theta=130, phi=20, > expand=0.45, xlab="x1", ylab="x2", zlab="y", xlim=c(0,1), ylim=c(0,1), > zlim=range(zf), ticktype="detailed", scale=F, main="gcv fitting") > > Many thanks once again. > > regards > mintewab > > > > Fr?n: Jeff Newmiller [jdnewmil at dcn.davis.ca.us] > Skickat: den 5 december 2011 12:39 > Till: Mintewab Bezabih; Sarah Goslee > Kopia: r-help at r-project.org > ?mne: Re: [R] problems using the thin plate spline method > > Try > > plot( dat$x1, dat$y ) > > or > > plot( x1, y, data=dat ) > > Note that your example is still not reproducible because you have not supplied the data or a shortened version of your data for us to work with. Also, your problem is not with thin plates but with plot, and reading the help for that function by typing > > ?plot > > at the R command line would have provided you with more examples and usage info on how to get around this problem. > --------------------------------------------------------------------------- > Jeff Newmiller The ..... ..... Go Live... > DCN: Basics: ##.#. ##.#. Live Go... > Live: OO#.. Dead: OO#.. Playing > Research Engineer (Solar/Batteries O.O#. #.O#. with > /Software/Embedded Controllers) .OO#. .OO#. rocks...1k > --------------------------------------------------------------------------- > Sent from my phone. Please excuse my brevity. > > Mintewab Bezabih wrote: > >> Dear Sarah and R users, >> >> Sorry again for not being explicit enough. Here is my full problem >> >> >> dat <- read.table("E:/thin plate/thin plate.csv", header=T, sep=",") >> dat >> names(dat) <- c("x1", "x2", "y") >> library(fields) >> plot (dat) >> >> #load the fields package (containing Tps) and fit a thin plate spline >> tpsfit <- Tps(cbind(x1, x2), y, scale.type="unscaled") >> >> What I meant when I said the graph works is when I do plot(dat) it does >> plot of all my three variables. If I do plot(x1,y), though, I get the >> 'object x1 not found' error message. >> >> Same when I do the next line tpsfit <- Tps(cbind(x1, x2), y, >> scale.type="unscaled"). I get the same error message. >> >> I tried your suggestion of checking str(x1) and I get the same error >> message (object x1 not found). >> I also typed ls() and I get "dat" after that command. >> >> I followed the r tutorial guide to read my data and I am following the >> r tutorial to guide me to apply the thin plate spline method. >> >> Regards, >> >> Mintewab >> ________________________________________ >> Fr?n: Sarah Goslee [sarah.goslee at gmail.com] >> Skickat: den 4 december 2011 15:21 >> Till: Mintewab Bezabih >> Kopia: r-help at r-project.org >> ?mne: Re: [R] problems using the thin plate spline method >> >> Hello, >> >> On Sun, Dec 4, 2011 at 8:08 AM, Mintewab Bezabih >> wrote: >>> Dear R users and Jeff, >>> >>> Sorry for not being quite explicit in my earlier message. >> >> And you are still not explicit. We have no idea what you've done. >> >>> My main problem is while my data seem to be read into R well (I >> manage to graph them and all), I cannot get the following line to work. >>> >>> tpsfit <- Tps(cbind(x1, x2), y, scale.type="unscaled") >>> >>> and I get the following error message >>> >>> Error in as.matrix(x) : >>> error in evaluating the argument 'x' in selecting a method for >> function 'as.matrix': Error: object 'x1' not found >> >> I'd have to guess that there's no object x1. What does ls() tell you? >> str(x1)? >> >> What do your data look like? You were already given instructions on how >> to >> include sample data to construct a reproducible example. You said that >> graphing your data worked; how did you do so? >> >> The posting guide and the advice you were already given were both >> offered for a reason. The querent needs to do the work of formulating >> an understandable and answerable question. >> >> Sarah >> >>> thanks for help >>> minti >>> ________________________________________ >>> Fr?n: Jeff Newmiller [jdnewmil at dcn.davis.ca.us] >>> Skickat: den 3 december 2011 17:45 >>> Till: Mintewab Bezabih; r-help at r-project.org >>> ?mne: Re: [R] problems using the thin plate spline method >>> >>> I can tell that you are puzzled and confused. Unfortunately, I am not >> psychic, so I cannot tell what you did, and therefore cannot tell where >> you went astray. >>> >>> The solution is for you to read the posting guide mentioned at the >> bottom of every R-help message. Spend a little time to create a small >> bit of data like yours if your actual data is large (subset and dput >> are useful for this). Remember to include the output of sessionInfo, >> and so on. Many times you are likely to find the answer yourself by >> going through these steps, but they are essential for communication. >>> >>> Good luck. >>> Sent from my phone. Please excuse my brevity. >>> >>> Mintewab Bezabih wrote: >>> >>>> Dear R users, >>>> >>>> I am a beginner in R trying to apply the thin plate spline method to >> my >>>> climate data. I used the example in R to do so, and the lines seem to >>>> run fine ( I am not getting errors) but I am not getting any output >> in >>>> the form of graph or anything. I got a warning message saying that >>>> 'surface extends beyond box'. >>>> >>>> Any help is much appreciated. >>>> thanks >>>> minti >> >> >> -- >> Sarah Goslee >> http://www.functionaldiversity.org >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From hadley at rice.edu Mon Dec 5 14:30:53 2011 From: hadley at rice.edu (Hadley Wickham) Date: Mon, 5 Dec 2011 08:30:53 -0500 Subject: [R] Project local libraries (reproducible research) In-Reply-To: <4EDA0510.9080003@bitwrit.com.au> References: <4EDA0510.9080003@bitwrit.com.au> Message-ID: On Sat, Dec 3, 2011 at 11:16 AM, Jim Lemon wrote: > On 12/03/2011 06:04 AM, Hadley Wickham wrote: >> >> Hi all, >> >> I was wondering if any one had scripts that they could share for >> capturing the current version of R packages used for a project. I'm >> interested in creating a project local library so that you're safe if >> someone (e.g. the ggplot2 author) updates a package you're relying on >> and breaks your code. ? I could fairly easily hack together, but I was >> wondering if any one had any neat scripts they'd care to share. >> > Hi Hadley, > This makes quite a few assumptions, but I would build a list of packages > called in R scripts: > > # get all calls to library or require in a subdirectory of scripts > packagestrings<-c(system("grep library *.R",intern=TRUE), > ?system("grep require *.R",intern=TRUE)) > # get the unique package names > packagenames<-unique(sapply(strsplit(packagestrings,"[()]"),"[",2)) > # get the information on all installed packages in the system > installedpackages<-installed.packages() > # get the indices of the packages used in the subdirectory > whichpackages<-which(match(rownames(installedpackages),packagenames,0)>0) > # get the version information for each used package > installedpackages[whichpackages,"Built"] Thanks Jim. I was thinking something more like: rec <- dir(file.path(Sys.getenv("R_HOME"), "library")) pkgs <- search()[grepl("package:", search(), fixed = T)] pkgs <- gsub("package:", "", pkgs, fixed = TRUE) pkgs <- setdiff(pkgs, rec) i.e. work from the search path (once you've run your code). Then the next step would be find all dependencies of the packages, then copy them into the current working directory, and give a line to set .libPaths() correctly. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ From murdoch.duncan at gmail.com Mon Dec 5 14:32:26 2011 From: murdoch.duncan at gmail.com (Duncan Murdoch) Date: Mon, 05 Dec 2011 08:32:26 -0500 Subject: [R] Persp3d freezes when run from within Python In-Reply-To: <1323050239287-4158940.post@n4.nabble.com> References: <1323050239287-4158940.post@n4.nabble.com> Message-ID: <4EDCC7EA.1030008@gmail.com> On 11-12-04 8:57 PM, wchips wrote: > G'day everyone, > > I've been trying to get an interactive OpenGL plot to work from within > Python 2.6 using Rpy2 and the persp3d function. The problem is that the plot > seems to freeze upon activation. All interactivity is lost even though it > works fine when run from within the R console (version 2.11.1). Is this a > known issue? Any ideas as to what might be causing this, or possibly how to > fix it? Presumably your Python program or Rpy2 is not simulating the event handling that the real R console does. Solution: use the real R console, or fix the bug in your program or Rpy2. Duncan Murdoch > > cheers, > wchips > > -- > View this message in context: http://r.789695.n4.nabble.com/Persp3d-freezes-when-run-from-within-Python-tp4158940p4158940.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From michael.weylandt at gmail.com Mon Dec 5 14:50:34 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt ) Date: Mon, 5 Dec 2011 08:50:34 -0500 Subject: [R] extract cov matrix in summary.rq and use as a matrix. In-Reply-To: References: Message-ID: <397CB275-698B-43EE-8AFF-B28546135FB6@gmail.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From rkoenker at illinois.edu Mon Dec 5 14:53:21 2011 From: rkoenker at illinois.edu (Roger Koenker) Date: Mon, 5 Dec 2011 07:53:21 -0600 Subject: [R] about interpretation of anova results... In-Reply-To: <1323069483773-4159510.post@n4.nabble.com> References: <1323069483773-4159510.post@n4.nabble.com> Message-ID: If you were to rtfm you'd see that your anova suggests that the slope coefficients are the same for your tau = .15 and tau = .30 models. url: www.econ.uiuc.edu/~roger Roger Koenker email rkoenker at uiuc.edu Department of Economics vox: 217-333-4558 University of Illinois fax: 217-244-6678 Urbana, IL 61801 On Dec 5, 2011, at 1:18 AM, narendarreddy kalam wrote: > quantreg package is used. > *fit1 results are* > Call: > rq(formula = op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + > inp8 + inp9, tau = 0.15, data = wbc) > > Coefficients: > (Intercept) inp1 inp2 inp3 inp4 > inp5 > -0.191528450 0.005276347 0.021414032 0.016034803 0.007510343 > 0.005276347 > inp6 inp7 inp8 inp9 > 0.058708544 0.005224906 0.006804871 -0.003931540 > > Degrees of freedom: 673 total; 663 residual > *fit2 results are* > Call: > rq(formula = op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + > inp8 + inp9, tau = 0.3, data = wbc) > > Coefficients: > (Intercept) inp1 inp2 inp3 inp4 > -1.111111e-01 5.776765e-19 4.635734e-18 1.874715e-18 2.099872e-18 > inp5 inp6 inp7 inp8 inp9 > -4.942052e-19 1.111111e-01 2.205289e-18 4.138435e-18 9.300642e-19 > > Degrees of freedom: 673 total; 663 residual > > anova(fit1,fit2); > Quantile Regression Analysis of Deviance Table > > Model: op ~ inp1 + inp2 + inp3 + inp4 + inp5 + inp6 + inp7 + inp8 + inp9 > Joint Test of Equality of Slopes: tau in { 0.15 0.3 } > > Df Resid Df F value Pr(>F) > 1 9 1337 0.5256 0.8568 > Warning messages: > 1: In summary.rq(x, se = "nid", covariance = TRUE) : 93 non-positive fis > 2: In summary.rq(x, se = "nid", covariance = TRUE) : 138 non-positive fis > how to interpret the above results?? > > what is the use of anova function?? > will it give the best among fit1 && fit2.. > > > -- > View this message in context: http://r.789695.n4.nabble.com/about-interpretation-of-anova-results-tp4159510p4159510.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From friendly at yorku.ca Mon Dec 5 15:16:25 2011 From: friendly at yorku.ca (Michael Friendly) Date: Mon, 05 Dec 2011 09:16:25 -0500 Subject: [R] finding interpolated values along an empirical parametric curve Message-ID: <4EDCD239.6040501@yorku.ca> Given the following data, I am plotting log.det ~ norm.beta, where the points depend on a parameter, lambda (but there is no functional form). I want to find the (x,y) positions along this curve corresponding to two special values of lambda lambda.HKB <- 0.004275357 lambda.LW <- 0.03229531 and draw reference lines at ~ -45 degrees (or normal to the curve) thru these points. How can I do this? A complete example is below > pd lambda log.det norm.beta 0.000 0.000 -12.92710 3.806801 0.005 0.005 -14.41144 2.819460 0.010 0.010 -15.41069 2.423197 0.020 0.020 -16.82581 2.010924 0.040 0.040 -18.69819 1.611304 0.080 0.080 -21.05065 1.283928 > pd <- structure(list(lambda = c(0, 0.005, 0.01, 0.02, 0.04, 0.08), log.det = c(-12.9270978142337, -14.411442487768, -15.4106886674014, -16.8258120792945, -18.6981870228698, -21.050646106925), norm.beta = c(3.8068008759562, 2.81945995964196, 2.42319655878575, 2.01092421747594, 1.6113040561427, 1.28392804825009)), .Names = c("lambda", "log.det", "norm.beta"), class = "data.frame", row.names = c("0.000", "0.005", "0.010", "0.020", "0.040", "0.080")) clr <- c("black", rainbow(5, start=.6, end=.1)) lambdaf <- c(expression(~widehat(beta)^OLS), ".005", ".01", ".02", ".04", ".08") op <- par(mar=c(4, 4, 1, 1) + 0.2, xpd=TRUE) with(pd, {plot(norm.beta, log.det, type="b", cex.lab=1.25, pch=16, cex=1.5, col=clr, xlab='shrinkage: ||b||', ylab='variance: log |(Var(b)|)') text(norm.beta, log.det, lambdaf, cex=1.25, pos=2) text(min(norm.beta), max(log.det), "Variance vs. Shrinkage", cex=1.5, pos=4) }) # How to find the (x,y) positions for these values of lambda along the curve of log.det ~ norm.beta ? lambda.HKB <- 0.004275357 lambda.LW <- 0.03229531 -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Street Web: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA From S.Ellison at LGCGroup.com Mon Dec 5 15:45:01 2011 From: S.Ellison at LGCGroup.com (S Ellison) Date: Mon, 5 Dec 2011 14:45:01 +0000 Subject: [R] iterative variable names In-Reply-To: <1323087914497-4160262.post@n4.nabble.com> References: <1323079206895-4159888.post@n4.nabble.com> <511429D6-561A-4EA6-95A1-44A936973BEE@gmail.com> <1323087914497-4160262.post@n4.nabble.com> Message-ID: > -----Original Message----- > Thank you very much, assign was exactly what I needed! For my > case, it worked better than list! :) If assign(paste('x_', i)) works better for your case than using a list or array , you must surely have a very strange case.... S Ellison******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}} From jfox at mcmaster.ca Mon Dec 5 15:50:06 2011 From: jfox at mcmaster.ca (John Fox) Date: Mon, 5 Dec 2011 09:50:06 -0500 Subject: [R] finding interpolated values along an empirical parametric curve In-Reply-To: <4EDCD239.6040501@yorku.ca> References: <4EDCD239.6040501@yorku.ca> Message-ID: <002f01ccb35d$2e3a60d0$8aaf2270$@mcmaster.ca> Hi Michael, I can get what appears to be a good interpolation with a regression spline in a multivariate LM, playing around with the tuning parameter to leave 1 residual df. Try this: library(splines) mod <- lm(cbind(log.det, norm.beta) ~ bs(lambda, df=4), data=pd) summary(mod) x <- data.frame(lambda=seq(min(pd$lambda), max(pd$lambda), length=100)) fit <- predict(mod, newdata=x) points(fit[, "norm.beta"], fit[, "log.det"], pch=16, cex=0.5) x.2 <- data.frame(lambda=c(lambda.HKB, lambda.LW)) fit.2 <- predict(mod, x.2) points(fit.2[, "norm.beta"], fit.2[, "log.det"], pch=15, col="green") That doesn't solve the problem of calculating the normal, however. I hope this helps, John > -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Michael Friendly > Sent: December-05-11 9:16 AM > To: R-help > Subject: [R] finding interpolated values along an empirical parametric > curve > > Given the following data, I am plotting log.det ~ norm.beta, where the > points depend on a parameter, lambda (but there is no functional form). > I want to find the (x,y) positions along this curve corresponding to > two special values of lambda > > lambda.HKB <- 0.004275357 > lambda.LW <- 0.03229531 > > and draw reference lines at ~ -45 degrees (or normal to the curve) thru > these points. > How can I do this? A complete example is below > > > pd > lambda log.det norm.beta > 0.000 0.000 -12.92710 3.806801 > 0.005 0.005 -14.41144 2.819460 > 0.010 0.010 -15.41069 2.423197 > 0.020 0.020 -16.82581 2.010924 > 0.040 0.040 -18.69819 1.611304 > 0.080 0.080 -21.05065 1.283928 > > > > pd <- > structure(list(lambda = c(0, 0.005, 0.01, 0.02, 0.04, 0.08), > log.det = c(-12.9270978142337, -14.411442487768, - > 15.4106886674014, > -16.8258120792945, -18.6981870228698, -21.050646106925), > norm.beta = c(3.8068008759562, 2.81945995964196, 2.42319655878575, > 2.01092421747594, 1.6113040561427, 1.28392804825009)), .Names = > c("lambda", "log.det", "norm.beta"), class = "data.frame", row.names = > c("0.000", "0.005", "0.010", "0.020", "0.040", "0.080")) > > clr <- c("black", rainbow(5, start=.6, end=.1)) lambdaf <- > c(expression(~widehat(beta)^OLS), ".005", ".01", ".02", ".04", ".08") > op <- par(mar=c(4, 4, 1, 1) + 0.2, xpd=TRUE) with(pd, {plot(norm.beta, > log.det, type="b", > cex.lab=1.25, pch=16, cex=1.5, col=clr, > xlab='shrinkage: ||b||', > ylab='variance: log |(Var(b)|)') > text(norm.beta, log.det, lambdaf, cex=1.25, pos=2) > text(min(norm.beta), max(log.det), "Variance vs. Shrinkage", > cex=1.5, pos=4) > }) > > > # How to find the (x,y) positions for these values of lambda along the > curve of log.det ~ norm.beta ? > lambda.HKB <- 0.004275357 > lambda.LW <- 0.03229531 > > -- > Michael Friendly Email: friendly AT yorku DOT ca > Professor, Psychology Dept. > York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 > 4700 Keele Street Web: http://www.datavis.ca > Toronto, ONT M3J 1P3 CANADA > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. From erinm.hodgess at gmail.com Mon Dec 5 16:03:10 2011 From: erinm.hodgess at gmail.com (Erin Hodgess) Date: Mon, 5 Dec 2011 09:03:10 -0600 Subject: [R] R 2-14.0 locking up Message-ID: Dear R People: I'm working with R-2.14.0 created from source on a quad core Windows 7 machine. Starting yesterday, nearly everything I run just sits. When I hit escape or Ctrl C, nothing happens. Has anyone run into this, please? Any suggestions would be much appreciated. Thanks, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodgess at gmail.com From mardones.p at gmail.com Mon Dec 5 16:06:10 2011 From: mardones.p at gmail.com (Pedro Mardones) Date: Mon, 5 Dec 2011 12:06:10 -0300 Subject: [R] nipals in the chemometrics package in R In-Reply-To: References: <1c18fb68-fdbd-4525-904d-496361f639b1@email.android.com> Message-ID: Perhaps you can try the examples given in http://www.jstatsoft.org/v18/i02 for getting a better idea about how the NIPALS algorithm works. BTW, yes,it looks like a homework question specially when your user name is "zz dd " so you can't be recognized. On Mon, Dec 5, 2011 at 9:27 AM, zz dd wrote: > Thank you for your brevity you don't have to say more things to show who > you are. > Else if you don't understand what we are talking about, you shouldn't ?be > rude and insulting. > May be you are quite young please take time to read Nonaka and Takeuchi and > moreover Takanashi to uderstand the way to go from information to knowledge > to wisdom that's quite useful for IS / IT and should bring you a bit of > etiquette. > *I have a dream* *that one day this nation will rise up and live out the > true meaning of its creed : ?We hold these truths to be self-evident : that > all men are created equal.?* > > Have a nice day. > > 2011/12/5 Jeff Newmiller > >> This is not a homework help list. >> --------------------------------------------------------------------------- >> Jeff Newmiller ? ? ? ? ? ? ? ? ? ? ? ?The ? ? ..... ? ? ? ..... ?Go Live... >> DCN: ? ? ? ?Basics: ##.#. ? ? ? ##.#. ?Live >> Go... >> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Live: ? OO#.. Dead: OO#.. ?Playing >> Research Engineer (Solar/Batteries ? ? ? ? ? ?O.O#. ? ? ? #.O#. ?with >> /Software/Embedded Controllers) ? ? ? ? ? ? ? .OO#. ? ? ? .OO#. ?rocks...1k >> --------------------------------------------------------------------------- >> Sent from my phone. Please excuse my brevity. >> >> zz dd wrote: >> >> >Hello >> >The solution maybe there but i need to compute it into R if someone can >> >help me : >> >(Previously store score vector t in score matrix T; store loading >> >vector p >> >in loading matrix P) that's done by nipals in chemometrics >> >After use of nipals function you have T and P matrix >> > >> >First : "Calculate the residual matrix of X. Stop if the elements of >> >Xres >> >are very small >> >because no further PCA components are reasonable" : >> >Xres= X-u.b(T) >> > >> >u : improved score vector >> >b: loading vector >> >X : a mean-centered matrix >> > >> >Second : Replace X with Xres and continue with step 2 (with nipals >> >chemometrics...) for calculation of the next PCA >> >component. >> > >> >If someone can help me ? >> >Thank's a lot >> > >> > >> >2011/12/1 zz dd >> > >> >> Hello >> >> i need some precision about nipals in the chemometrics package in R . >> >> >> >> When i use nipals in chemometrics i obtain T and P matrix. >> >> >> >> I really don't understand what to do with these two matrix to obtain >> >> the scores for every the component (like in spss fo example) >> >> >> >> ? ? ? ? ? ? Comp1 ? ?Comp2 ? Comp3 >> >> quest1 0,8434 ? ? ?0,54333 ? 0,3466 >> >> quest2 0,665 ? ? ? 0,7655 ? ? ?0,433 >> >> >> >> Thank you very much for your help >> >> (I know that X=TP+E)... But don't understand else.... >> >> >> > >> > ? ? ? [[alternative HTML version deleted]] >> > >> >______________________________________________ >> >R-help at r-project.org mailing list >> >https://stat.ethz.ch/mailman/listinfo/r-help >> >PLEASE do read the posting guide >> >http://www.R-project.org/posting-guide.html >> >and provide commented, minimal, self-contained, reproducible code. >> >> > > ? ? ? ?[[alternative HTML version deleted]] > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > From mailinglist.honeypot at gmail.com Mon Dec 5 16:13:27 2011 From: mailinglist.honeypot at gmail.com (Steve Lianoglou) Date: Mon, 5 Dec 2011 10:13:27 -0500 Subject: [R] R 2-14.0 locking up In-Reply-To: References: Message-ID: Hi, On Mon, Dec 5, 2011 at 10:03 AM, Erin Hodgess wrote: > Dear R People: > > I'm working with R-2.14.0 created from source on a quad core Windows 7 machine. > > Starting yesterday, nearly everything I run just sits. ?When I hit > escape or Ctrl C, nothing happens. > > Has anyone run into this, please? > > Any suggestions would be much appreciated. Does this happen when you run R from the command line? Are you loading something wonky from a stored workspace (ie, your ~/.RData file)? Can you start R from terminal with the "vanilla" switch to see if its something else, ie: $ R --vanilla (where `$` is the command line prompt you typically see in a *nix environment, I'm not sure what the equivalent is in windows -- not that it matters) Does any of that work? And out of curiosity, why did you compile R from source instead of using the binaries? What were the configure args you used to compile? -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology ?| Memorial Sloan-Kettering Cancer Center ?| Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact From bps0002 at auburn.edu Mon Dec 5 16:23:32 2011 From: bps0002 at auburn.edu (B77S) Date: Mon, 5 Dec 2011 07:23:32 -0800 (PST) Subject: [R] similarity matrix In-Reply-To: <1323071233237-4159547.post@n4.nabble.com> References: <1323022265536-4157576.post@n4.nabble.com> <1323027562692-4157840.post@n4.nabble.com> <1323071233237-4159547.post@n4.nabble.com> Message-ID: <1323098612063-4160902.post@n4.nabble.com> That really all depends on what you need; and I can't tell you what you need. set wrote > > I'm sorry, I made a mistake in my example. you're right. I don't really > know how a similarity alogrithm works....but I'm willing to try that...are > there any good examples available? > Thank you > -- View this message in context: http://r.789695.n4.nabble.com/similarity-matrix-tp4157576p4160902.html Sent from the R help mailing list archive at Nabble.com. From dwinsemius at comcast.net Mon Dec 5 16:28:08 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Mon, 5 Dec 2011 10:28:08 -0500 Subject: [R] equating approximate values In-Reply-To: <7DDE0973-E5AF-4299-87D6-EF46555EBB74@gmail.com> References: <1323021640135-4157551.post@n4.nabble.com> <1323043462928-4158691.post@n4.nabble.com> <7DDE0973-E5AF-4299-87D6-EF46555EBB74@gmail.com> Message-ID: On Dec 5, 2011, at 8:02 AM, R. Michael Weylandt wrote: > Change which to which.min, but then you won't easily be able to get > the corresponding x,y indices. Look at the arrayInd() function to > translate the result to a particular x,y. The arrayInd help page is shared by the which help and which has an arr.ind=TRUE option that let's you encapsulate both steps: which( abs(outer(x, y, "-")) == min(abs(outer(x, y, "-"))), arr.ind=TRUE) > > Michael > > On Dec 4, 2011, at 7:04 PM, vamshi999 wrote: > >> this is exactly what i wanted. >> >> How to i select only the minimum value from this?. >> >> thank you >> >> >> >> >> My apologies: you need an abs() call as well: >> >> which(abs(outer(x, y, "-")) < threshold, arr.ind = TRUE) >> >> Michael >> >> >> >> >> -- >> View this message in context: http://r.789695.n4.nabble.com/equating-approximate-values-tp4157551p4158691.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT From matteo.richiardi at gmail.com Mon Dec 5 16:36:18 2011 From: matteo.richiardi at gmail.com (Matteo Richiardi) Date: Mon, 5 Dec 2011 16:36:18 +0100 Subject: [R] using StatEt IDE for Eclipse Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From f.calboli at imperial.ac.uk Mon Dec 5 16:44:21 2011 From: f.calboli at imperial.ac.uk (Federico Calboli) Date: Mon, 5 Dec 2011 15:44:21 +0000 Subject: [R] barplot ignoring col parameter Message-ID: Hi All, I'm having a problem with barplot: mydata [1,] 2 108 0 0 0 1 3 0 0 0 0 0 7 18 3 4 8 20 26 20 19 7 1 1 mycol = c(rep('yellow', 2), rep('white', 3), rep('orange',2), rep('white', 5), rep('orange',3), rep('red',9)) barplot(mydata, col = mycol) gives me an uniformly yellow barplot. How do I solve this? bw Federico -- Federico C. F. Calboli Neuroepidemiology and Ageing Research Imperial College, St. Mary's Campus Norfolk Place, London W2 1PG Tel +44 (0)20 75941602 Fax +44 (0)20 75943193 f.calboli [.a.t] imperial.ac.uk f.calboli [.a.t] gmail.com From void1999 at gmail.com Mon Dec 5 16:46:38 2011 From: void1999 at gmail.com (zz dd) Date: Mon, 5 Dec 2011 16:46:38 +0100 Subject: [R] nipals in the chemometrics package in R In-Reply-To: References: <1c18fb68-fdbd-4525-904d-496361f639b1@email.android.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From dwinsemius at comcast.net Mon Dec 5 16:51:55 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Mon, 5 Dec 2011 10:51:55 -0500 Subject: [R] barplot ignoring col parameter In-Reply-To: References: Message-ID: <8E367CCF-313A-4849-B5A1-2AD635AD3933@comcast.net> On Dec 5, 2011, at 10:44 AM, Federico Calboli wrote: > Hi All, > > I'm having a problem with barplot: > > mydata > [1,] 2 108 0 0 0 1 3 0 0 0 0 0 7 18 3 4 8 20 26 20 > 19 7 1 1 > > mycol = c(rep('yellow', 2), rep('white', 3), rep('orange',2), > rep('white', 5), rep('orange',3), rep('red',9)) > > barplot(mydata, col = mycol) > > gives me an uniformly yellow barplot. How do I solve this? Hard to say, since it involves graphics devices and I cannot reproduce it. > mydata <- scan() 1: 2 108 0 0 0 1 3 0 0 0 0 0 7 18 3 4 8 20 26 20 19 7 1 1 25: Read 24 items > barplot(mydata) > ?barplot > mycol = c(rep('yellow', 2), rep('white', 3), rep('orange',2), rep('white', 5), rep('orange',3), rep('red',9)) > > barplot(mydata, col = mycol) Gives a multicolored display on my machine: -------------- next part -------------- A non-text attachment was scrubbed... Name: Rplot.pdf Type: application/pdf Size: 39931 bytes Desc: not available URL: -------------- next part -------------- > > bw > > Federico > > > > -- > Federico C. F. Calboli > Neuroepidemiology and Ageing Research > Imperial College, St. Mary's Campus > Norfolk Place, London W2 1PG > > Tel +44 (0)20 75941602 Fax +44 (0)20 75943193 > > f.calboli [.a.t] imperial.ac.uk > f.calboli [.a.t] gmail.com > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT From michael.weylandt at gmail.com Mon Dec 5 16:58:36 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Mon, 5 Dec 2011 10:58:36 -0500 Subject: [R] barplot ignoring col parameter In-Reply-To: References: Message-ID: x <- c(2L, 108L, 0L, 0L, 0L, 1L, 3L, 0L, 0L, 0L, 0L, 0L, 7L, 18L, 3L, 4L, 8L, 20L, 26L, 20L, 19L, 7L, 1L, 1L) mycol = c(rep('yellow', 2), rep('white', 3), rep('orange',2), rep('white', 5), rep('orange',3), rep('red',9)) barplot(x, col = mycol) Produces a multi-colored barplot on my machine so I understand your confusion. Does the above work for you? It may be something hidden in your data. What is your sessionInfo() and str(mydata)? Same problem in a fresh R session (with --vanilla if necessary)? Michael On Mon, Dec 5, 2011 at 10:44 AM, Federico Calboli wrote: > Hi All, > > I'm having a problem with barplot: > > mydata > [1,] ?2 108 ?0 ?0 ?0 ?1 ?3 ?0 ?0 ?0 ?0 ?0 ?7 18 ?3 ?4 ?8 20 26 20 19 ?7 ?1 ?1 > > mycol = c(rep('yellow', 2), rep('white', 3), rep('orange',2), rep('white', 5), rep('orange',3), rep('red',9)) > > barplot(mydata, col = mycol) > > gives me an uniformly yellow barplot. How do I solve this? > > bw > > Federico > > > > -- > Federico C. F. Calboli > Neuroepidemiology and Ageing Research > Imperial College, St. Mary's Campus > Norfolk Place, London W2 1PG > > Tel +44 (0)20 75941602 ? Fax +44 (0)20 75943193 > > f.calboli [.a.t] imperial.ac.uk > f.calboli [.a.t] gmail.com > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From friendly at yorku.ca Mon Dec 5 17:02:07 2011 From: friendly at yorku.ca (Michael Friendly) Date: Mon, 05 Dec 2011 11:02:07 -0500 Subject: [R] finding interpolated values along an empirical parametric curve In-Reply-To: <002f01ccb35d$2e3a60d0$8aaf2270$@mcmaster.ca> References: <4EDCD239.6040501@yorku.ca> <002f01ccb35d$2e3a60d0$8aaf2270$@mcmaster.ca> Message-ID: <4EDCEAFF.50202@yorku.ca> Thanks, John That's very clever. I didn't realize that the splines package supports multivariate regression splines and that works well enough for my purposes; plus this solution is very transparent. best, -Michael On 12/5/2011 9:50 AM, John Fox wrote: > Hi Michael, > > I can get what appears to be a good interpolation with a regression spline > in a multivariate LM, playing around with the tuning parameter to leave 1 > residual df. Try this: > > library(splines) > mod<- lm(cbind(log.det, norm.beta) ~ bs(lambda, df=4), data=pd) > summary(mod) > > x<- data.frame(lambda=seq(min(pd$lambda), max(pd$lambda), length=100)) > fit<- predict(mod, newdata=x) > points(fit[, "norm.beta"], fit[, "log.det"], pch=16, cex=0.5) > > x.2<- data.frame(lambda=c(lambda.HKB, lambda.LW)) > fit.2<- predict(mod, x.2) > points(fit.2[, "norm.beta"], fit.2[, "log.det"], pch=15, col="green") > > That doesn't solve the problem of calculating the normal, however. > > I hope this helps, > John > >> -----Original Message----- >> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- >> project.org] On Behalf Of Michael Friendly >> Sent: December-05-11 9:16 AM >> To: R-help >> Subject: [R] finding interpolated values along an empirical parametric >> curve >> >> Given the following data, I am plotting log.det ~ norm.beta, where the >> points depend on a parameter, lambda (but there is no functional form). >> I want to find the (x,y) positions along this curve corresponding to >> two special values of lambda >> >> lambda.HKB<- 0.004275357 >> lambda.LW<- 0.03229531 >> >> and draw reference lines at ~ -45 degrees (or normal to the curve) thru >> these points. >> How can I do this? A complete example is below >> >> > pd >> lambda log.det norm.beta >> 0.000 0.000 -12.92710 3.806801 >> 0.005 0.005 -14.41144 2.819460 >> 0.010 0.010 -15.41069 2.423197 >> 0.020 0.020 -16.82581 2.010924 >> 0.040 0.040 -18.69819 1.611304 >> 0.080 0.080 -21.05065 1.283928 >> > >> >> pd<- >> structure(list(lambda = c(0, 0.005, 0.01, 0.02, 0.04, 0.08), >> log.det = c(-12.9270978142337, -14.411442487768, - >> 15.4106886674014, >> -16.8258120792945, -18.6981870228698, -21.050646106925), >> norm.beta = c(3.8068008759562, 2.81945995964196, 2.42319655878575, >> 2.01092421747594, 1.6113040561427, 1.28392804825009)), .Names = >> c("lambda", "log.det", "norm.beta"), class = "data.frame", row.names = >> c("0.000", "0.005", "0.010", "0.020", "0.040", "0.080")) >> >> clr<- c("black", rainbow(5, start=.6, end=.1)) lambdaf<- >> c(expression(~widehat(beta)^OLS), ".005", ".01", ".02", ".04", ".08") >> op<- par(mar=c(4, 4, 1, 1) + 0.2, xpd=TRUE) with(pd, {plot(norm.beta, >> log.det, type="b", >> cex.lab=1.25, pch=16, cex=1.5, col=clr, >> xlab='shrinkage: ||b||', >> ylab='variance: log |(Var(b)|)') >> text(norm.beta, log.det, lambdaf, cex=1.25, pos=2) >> text(min(norm.beta), max(log.det), "Variance vs. Shrinkage", >> cex=1.5, pos=4) >> }) >> >> >> # How to find the (x,y) positions for these values of lambda along the >> curve of log.det ~ norm.beta ? >> lambda.HKB<- 0.004275357 >> lambda.LW<- 0.03229531 >> >> -- >> Michael Friendly Email: friendly AT yorku DOT ca >> Professor, Psychology Dept. >> York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 >> 4700 Keele Street Web: http://www.datavis.ca >> Toronto, ONT M3J 1P3 CANADA >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting- >> guide.html >> and provide commented, minimal, self-contained, reproducible code. -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Street Web: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA From julia.lira at hotmail.co.uk Mon Dec 5 14:09:21 2011 From: julia.lira at hotmail.co.uk (Julia Lira) Date: Mon, 5 Dec 2011 13:09:21 +0000 Subject: [R] extract cov matrix in summary.rq and use as a matrix. In-Reply-To: References: , Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From juancarlosmarsan at gmail.com Mon Dec 5 16:19:07 2011 From: juancarlosmarsan at gmail.com (SilvaForever) Date: Mon, 5 Dec 2011 07:19:07 -0800 (PST) Subject: [R] Weighting and recodification Message-ID: <1323098347580-4160876.post@n4.nabble.com> I have a question that is more statistical than r-specific I have to recode a variable into quartiles, and I have weighted individuals. To calculate the quartiles that will serve me to recode the variable, should I use the weight or not? -- View this message in context: http://r.789695.n4.nabble.com/Weighting-and-recodification-tp4160876p4160876.html Sent from the R help mailing list archive at Nabble.com. From mark.pundurs at navteq.com Mon Dec 5 17:10:56 2011 From: mark.pundurs at navteq.com (Pundurs, Mark) Date: Mon, 5 Dec 2011 10:10:56 -0600 Subject: [R] Flexclust package: kcca object's methods and properties? Message-ID: <8A18D8FA4293104C9A710494FD6C273CB678DDDA@hq-ex-mb03.ad.navteq.com> What are all the methods and properties for the flexclust package's kcca object? Neither http://cran.r-project.org/web/packages/flexclust/flexclust.pdf nor http://www.stat.uni-muenchen.de/~leisch/papers/Leisch-2006.pdf appear to include a comprehensive centralized list. Mark Pundurs Data Analyst - Traffic Nokia Location & Commerce The information contained in this communication may be C...{{dropped:8}} From f.calboli at imperial.ac.uk Mon Dec 5 17:41:23 2011 From: f.calboli at imperial.ac.uk (Federico Calboli) Date: Mon, 5 Dec 2011 16:41:23 +0000 Subject: [R] barplot ignoring col parameter In-Reply-To: References: Message-ID: On 5 Dec 2011, at 15:58, R. Michael Weylandt wrote: > x <- c(2L, 108L, 0L, 0L, 0L, 1L, 3L, 0L, 0L, 0L, 0L, 0L, 7L, 18L, > 3L, 4L, 8L, 20L, 26L, 20L, 19L, 7L, 1L, 1L) > mycol = c(rep('yellow', 2), rep('white', 3), rep('orange',2), > rep('white', 5), rep('orange',3), rep('red',9)) > barplot(x, col = mycol) > > Produces a multi-colored barplot on my machine so I understand your > confusion. Does the above work for you? It may be something hidden in > your data. It does work. Might it be that my data is a matrix? I'm using it to give a name for each bar. > > What is your sessionInfo() and str(mydata)? Same problem in a fresh R > session (with --vanilla if necessary)? sessionInfo() R version 2.14.0 (2011-10-31) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8 attached base packages: [1] splines stats graphics grDevices utils datasets methods base other attached packages: [1] survival_2.36-10 loaded via a namespace (and not attached): [1] tools_2.14.0 str(mydata) num [1, 1:24] 2 108 0 0 0 1 3 0 0 0 ... - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : chr [1:24] "A" "B" "C" "D" ... Basically, using the 'x' object as you created the code works, and I can have a workaround. I fail to see why it would not work using mydata. Cheers F > > Michael > > On Mon, Dec 5, 2011 at 10:44 AM, Federico Calboli > wrote: >> Hi All, >> >> I'm having a problem with barplot: >> >> mydata >> [1,] 2 108 0 0 0 1 3 0 0 0 0 0 7 18 3 4 8 20 26 20 19 7 1 1 >> >> mycol = c(rep('yellow', 2), rep('white', 3), rep('orange',2), rep('white', 5), rep('orange',3), rep('red',9)) >> >> barplot(mydata, col = mycol) >> >> gives me an uniformly yellow barplot. How do I solve this? >> >> bw >> >> Federico >> >> >> >> -- >> Federico C. F. Calboli >> Neuroepidemiology and Ageing Research >> Imperial College, St. Mary's Campus >> Norfolk Place, London W2 1PG >> >> Tel +44 (0)20 75941602 Fax +44 (0)20 75943193 >> >> f.calboli [.a.t] imperial.ac.uk >> f.calboli [.a.t] gmail.com >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. -- Federico C. F. Calboli Neuroepidemiology and Ageing Research Imperial College, St. Mary's Campus Norfolk Place, London W2 1PG Tel +44 (0)20 75941602 Fax +44 (0)20 75943193 f.calboli [.a.t] imperial.ac.uk f.calboli [.a.t] gmail.com From dwinsemius at comcast.net Mon Dec 5 17:43:38 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Mon, 5 Dec 2011 11:43:38 -0500 Subject: [R] Weighting and recodification In-Reply-To: <1323098347580-4160876.post@n4.nabble.com> References: <1323098347580-4160876.post@n4.nabble.com> Message-ID: On Dec 5, 2011, at 10:19 AM, SilvaForever wrote: > I have a question that is more statistical than r-specific > > I have to recode a variable into quartiles, and I have weighted > individuals. > To calculate the quartiles that will serve me to recode the > variable, should > I use the weight or not? I would think that an affirmative answer should raise the follow-on question of "how", and an R-specific answer would be `wtd.quantile` in the Hmisc package. -- David Winsemius, MD West Hartford, CT From michael.weylandt at gmail.com Mon Dec 5 17:49:34 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Mon, 5 Dec 2011 11:49:34 -0500 Subject: [R] barplot ignoring col parameter In-Reply-To: References: Message-ID: barplot() defaults to stacked bars for matrices and uses the colors fresh for each bar: e.g., layout(1:2) barplot(matrix(1:6, 2), col = c("red", "blue","green")) barplot(matrix(1:6, 3), col = c("red", "blue","green")) To get what you are looking for, try something like this: x = matrix(1:6,1); colnames(x) = LETTERS[1:6] barplot(as.vector(x), names.arg = colnames(x)) More generally, just turn the matrix into a vector mat2vec <- function(x){ stopifnot(any(dim(x) == 1L)) if(nrow(x) != 1L) x <- t(x) cn <- colnames(x) x <- c(x) names(x) <- cn return(x) } and barplot that. Hope this helps, Michael On Mon, Dec 5, 2011 at 11:41 AM, Federico Calboli wrote: > > On 5 Dec 2011, at 15:58, R. Michael Weylandt wrote: > >> x <- c(2L, 108L, 0L, 0L, 0L, 1L, 3L, 0L, 0L, 0L, 0L, 0L, 7L, 18L, >> 3L, 4L, 8L, 20L, 26L, 20L, 19L, 7L, 1L, 1L) >> mycol = c(rep('yellow', 2), rep('white', 3), rep('orange',2), >> rep('white', 5), rep('orange',3), rep('red',9)) >> barplot(x, col = mycol) >> >> Produces a multi-colored barplot on my machine so I understand your >> confusion. Does the above work for you? It may be something hidden in >> your data. > > It does work. Might it be that my data is a matrix? I'm using it to give a name for each bar. > > >> >> What is your sessionInfo() and str(mydata)? Same problem in a fresh R >> session (with --vanilla if necessary)? > > > sessionInfo() > R version 2.14.0 (2011-10-31) > Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) > > locale: > [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8 > > attached base packages: > [1] splines ? stats ? ? graphics ?grDevices utils ? ? datasets ?methods ? base > > other attached packages: > [1] survival_2.36-10 > > loaded via a namespace (and not attached): > [1] tools_2.14.0 > > > str(mydata) > num [1, 1:24] 2 108 0 0 0 1 3 0 0 0 ... > - attr(*, "dimnames")=List of 2 > ?..$ : NULL > ?..$ : chr [1:24] "A" "B" "C" "D" ... > > > Basically, using the 'x' object as you created the code works, and I can have a workaround. I fail to see why it would not work using mydata. > > Cheers > > F > > > >> >> Michael >> >> On Mon, Dec 5, 2011 at 10:44 AM, Federico Calboli >> wrote: >>> Hi All, >>> >>> I'm having a problem with barplot: >>> >>> mydata >>> [1,] ?2 108 ?0 ?0 ?0 ?1 ?3 ?0 ?0 ?0 ?0 ?0 ?7 18 ?3 ?4 ?8 20 26 20 19 ?7 ?1 ?1 >>> >>> mycol = c(rep('yellow', 2), rep('white', 3), rep('orange',2), rep('white', 5), rep('orange',3), rep('red',9)) >>> >>> barplot(mydata, col = mycol) >>> >>> gives me an uniformly yellow barplot. How do I solve this? >>> >>> bw >>> >>> Federico >>> >>> >>> >>> -- >>> Federico C. F. Calboli >>> Neuroepidemiology and Ageing Research >>> Imperial College, St. Mary's Campus >>> Norfolk Place, London W2 1PG >>> >>> Tel +44 (0)20 75941602 ? Fax +44 (0)20 75943193 >>> >>> f.calboli [.a.t] imperial.ac.uk >>> f.calboli [.a.t] gmail.com >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. > > -- > Federico C. F. Calboli > Neuroepidemiology and Ageing Research > Imperial College, St. Mary's Campus > Norfolk Place, London W2 1PG > > Tel +44 (0)20 75941602 ? Fax +44 (0)20 75943193 > > f.calboli [.a.t] imperial.ac.uk > f.calboli [.a.t] gmail.com > From fincher at cs.fsu.edu Mon Dec 5 19:39:21 2011 From: fincher at cs.fsu.edu (Justin Fincher) Date: Mon, 5 Dec 2011 13:39:21 -0500 Subject: [R] adding hyperlinked text to pdf plot Message-ID: Howdy, I have read that if you put a URL in the text of a plot being saved into pdf, the result is a functional hyperlink. I am interested in having text in a plot that is linked to a URL, but I would like the text to be something other than the URL. Is this possible? Thank you. - Fincher From gianni.lavaredo at gmail.com Mon Dec 5 19:40:57 2011 From: gianni.lavaredo at gmail.com (gianni lavaredo) Date: Mon, 5 Dec 2011 19:40:57 +0100 Subject: [R] explanation why RandomForest don't require a transformations (e.g. logarithmic) of variables Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From ted.harding at wlandres.net Mon Dec 5 19:58:56 2011 From: ted.harding at wlandres.net ( (Ted Harding)) Date: Mon, 05 Dec 2011 18:58:56 -0000 (GMT) Subject: [R] adding hyperlinked text to pdf plot In-Reply-To: Message-ID: On 05-Dec-11 18:39:21, Justin Fincher wrote: > Howdy, > I have read that if you put a URL in the text of a plot > being saved into pdf, the result is a functional hyperlink. > I am interested in having text in a plot that is linked to > a URL, but I would like the text to be something other than > the URL. Is this possible? Thank you. > > - Fincher The "kosher" method of doing this kind of thing (and a host of other interactive elements in a PDF file) would be to incorporate a so-called PDFmark into the PDF code. See for instance: http://www.pdflib.com/developer/technical-documentation/ books/pdfmark-primer/ There are various ways of doing this in some document-preparation programs, but I don't know whether it would be easy to do this when creating a PDF in R. In mt experience, this involves first passing via PostScript. Any comments, anyone? Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) Fax-to-email: +44 (0)870 094 0861 Date: 05-Dec-11 Time: 18:58:53 ------------------------------ XFMail ------------------------------ From andy_liaw at merck.com Mon Dec 5 19:59:37 2011 From: andy_liaw at merck.com (Liaw, Andy) Date: Mon, 5 Dec 2011 13:59:37 -0500 Subject: [R] explanation why RandomForest don't require a transformations (e.g. logarithmic) of variables In-Reply-To: References: Message-ID: Tree based models (such as RF) are invriant to monotonic transformations in the predictor (x) variables, because they only use the ranks of the variables, not their actual values. More specifically, they look for splits that are at the mid-points of unique values. Thus the resulting trees are basically identical regardless of how you transform the x variables. Of course, the only, probably minor, differences is, e.g., mid-points can be different between the original and transformed data. While this doesn't impact the training data, it can impact the prediction on test data (although difference should be slight). Transformation of the response variable is quite another thing. RF needs it just as much as others if the situation calls for it. Cheers, Andy > -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of gianni lavaredo > Sent: Monday, December 05, 2011 1:41 PM > To: r-help at r-project.org > Subject: [R] explanation why RandomForest don't require a > transformations (e.g. logarithmic) of variables > > Dear Researches, > > sorry for the easy and common question. I am trying to > justify the idea of > RandomForest don't require a transformations (e.g. logarithmic) of > variables, comparing this non parametrics method with e.g. the linear > regressions. In leteruature to study my phenomena i need to apply a > logarithmic trasformation to describe my model, but i found RF don't > required this approach. Some people could suggest me text or > bibliography > to study? > > thanks in advance > > Gianni > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > Notice: This e-mail message, together with any attachme...{{dropped:11}} From dwinsemius at comcast.net Mon Dec 5 20:05:14 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Mon, 5 Dec 2011 14:05:14 -0500 Subject: [R] adding hyperlinked text to pdf plot In-Reply-To: References: Message-ID: <8363B812-47B0-4A43-8EF5-CEEC89F80942@comcast.net> On Dec 5, 2011, at 1:39 PM, Justin Fincher wrote: > Howdy, > I have read that if you put a URL in the text of a plot being saved > into pdf, the result is a functional hyperlink. Don't believe everything you read. pdf("test.pdf") plot(1,1,main="http://test.gov/some.htm") dev.off() "Non-functioning" text. > I am interested in > having text in a plot that is linked to a URL, but I would like the > text to be something other than the URL. Is this possible? Thank you. > > - Fincher > David Winsemius, MD West Hartford, CT From xie at yihui.name Mon Dec 5 20:09:56 2011 From: xie at yihui.name (Yihui Xie) Date: Mon, 5 Dec 2011 13:09:56 -0600 Subject: [R] adding hyperlinked text to pdf plot In-Reply-To: References: Message-ID: It seems I missed the context of this post -- who is "you", and what is "something other than the URL"? I feel the tikzDevice package should be an option for the task. Regards, Yihui -- Yihui Xie Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Mon, Dec 5, 2011 at 12:39 PM, Justin Fincher wrote: > Howdy, > ? I have read that if you put a URL in the text of a plot being saved > into pdf, the result is a functional hyperlink. I am interested in > having text in a plot that is linked to a URL, but I would like the > text to be something other than the URL. Is this possible? Thank you. > > - Fincher > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From gianni.lavaredo at gmail.com Mon Dec 5 20:19:18 2011 From: gianni.lavaredo at gmail.com (gianni lavaredo) Date: Mon, 5 Dec 2011 20:19:18 +0100 Subject: [R] explanation why RandomForest don't require a transformations (e.g. logarithmic) of variables In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From kehld at ktk.pte.hu Mon Dec 5 20:21:20 2011 From: kehld at ktk.pte.hu (=?ISO-8859-1?Q?Kehl_D=E1niel?=) Date: Mon, 05 Dec 2011 20:21:20 +0100 Subject: [R] lists everywhere In-Reply-To: References: Message-ID: <4EDD19B0.80202@ktk.pte.hu> Dear list members, I have a really simple problem. I connected to a DB and have the following query adat <- dbGetQuery(con, paste("select * from kmdata where SzeAZ='", szeazok[i], "' order by datum", sep="")) now I have the data in the adat variable which is a list. In fact the elements of the list are lists as well > is.list(adat) [1] TRUE > is.list(adat[10]) [1] TRUE > is.list(adat[[10]]) [1] FALSE > is.vector(adat[[10]]) [1] TRUE I simply want to use a function with sapply on the 13-76th columns of the original list. sapply(data[[13:76]], myfunc) does not work of course. I tried to define 13:76 in a vector, still no result. How is it possible? thanks a lot d From andy_liaw at merck.com Mon Dec 5 20:30:16 2011 From: andy_liaw at merck.com (Liaw, Andy) Date: Mon, 5 Dec 2011 14:30:16 -0500 Subject: [R] explanation why RandomForest don't require a transformations (e.g. logarithmic) of variables In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From kehld at ktk.pte.hu Mon Dec 5 20:36:09 2011 From: kehld at ktk.pte.hu (=?ISO-8859-1?Q?Kehl_D=E1niel?=) Date: Mon, 05 Dec 2011 20:36:09 +0100 Subject: [R] SOLVED, Re: lists everywhere In-Reply-To: <4EDD19B0.80202@ktk.pte.hu> References: <4EDD19B0.80202@ktk.pte.hu> Message-ID: <4EDD1D29.7000000@ktk.pte.hu> nevermind, typo (and some gray hair) sorry 12/5/2011 8:21 PM keltez?ssel, Kehl D?niel ?rta: > Dear list members, > > I have a really simple problem. > I connected to a DB and have the following query > > adat <- dbGetQuery(con, paste("select * from kmdata where SzeAZ='", > szeazok[i], "' order by datum", sep="")) > > now I have the data in the adat variable which is a list. In fact the > elements of the list are lists as well > > is.list(adat) > [1] TRUE > > is.list(adat[10]) > [1] TRUE > > is.list(adat[[10]]) > [1] FALSE > > is.vector(adat[[10]]) > [1] TRUE > > I simply want to use a function with sapply on the 13-76th columns of > the original list. > sapply(data[[13:76]], myfunc) does not work of course. I tried to > define 13:76 in a vector, still no result. > How is it possible? > > thanks a lot > d > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > From bt_jannis at yahoo.de Mon Dec 5 20:47:03 2011 From: bt_jannis at yahoo.de (Jannis) Date: Mon, 5 Dec 2011 19:47:03 +0000 (GMT) Subject: [R] installing several versions of R (2.14 and 2.12.2) on the same system on Ubuntu Message-ID: <1323114423.8857.YahooMailNeo@web28210.mail.ukl.yahoo.com> Dear R users, besides the current R 2.14 I would like to install a second version of R (2.12.2) on my Ubuntu system. The current version is easily installed as a precompiled package from Cran but I am heavily fighting with the older version. I tried to follow the instructions here: http://cran.r-project.org/doc/manuals/R-admin.html Unfortunately I got totally confused by all the different locations of the script, the library and the rest of the program. As I understand these all have to be different from the ones of the R 2.14 installation. In case anybody could point me to some nice instructions, fell welcome to do so. Otherwise we would need to check what went wrong during my try. I finally managed to install R.2.12.2 but, as it seems, without Java correctly set up and without tcltk support (both are needed). r-base-dev is installed. This I what I did: 1. downloaded R.2.12.2.tar.gz from Cran 2. tar -xzf R-2.12.2.tar.gz 3. sudo cp R-2.12.2 /usr/lib 4. cd /usr/lib/R.2.12.2 5. mkdir prog 5. sudo ./configure --prefix=/usr/bin 6. sudo make prefix=/usr/lib/R-2.12.2/prog rhome=/usr/lib/R-2.12.2/library 7. sudo mv /usr/bin/R /usr/bin/R-2.12.2 Most probably these two arguments for make are not correct as I did not fully understand the instructions here. Additionally I would need to facilitate tcl/tk and Java. Both works with R.2.14 so their dependecies should be installed but I probably need some more arguments during the build for that. Also this renaming of the R script seems arkward to me but I did this to easily run "R-2.12.2" or "R-2.14" from the command line. Does anybody have any advice on how to fix this stuff? Thanks for your help! Jannis From wdunlap at tibco.com Mon Dec 5 20:50:59 2011 From: wdunlap at tibco.com (William Dunlap) Date: Mon, 5 Dec 2011 19:50:59 +0000 Subject: [R] lists everywhere In-Reply-To: <4EDD19B0.80202@ktk.pte.hu> References: <4EDD19B0.80202@ktk.pte.hu> Message-ID: First, some general suggestions: To see the structure of an object I would recommend the str() function or, for a more concise output, the class() function. I don't think most ordinary users should be using is.list() and, especially, is.vector(). Now for the particulars. dbGetQuery probably returns an object of class "data.frame". data.frames are implemented as lists with certain attributes, so if 'dat' is a data.frame then is.list(dat) reports TRUE. class(dat) would report "data.frame", which is what you want to know. Similarly, dat[1] is a data.frame so is.list(dat[1]) reports TRUE. dat[[1]] is a column of a data.frame, not a data.frame, and class(dat[[1]]) will tell you its class. I haven't come across a case where is.vector is useful. is.vector(x) returns TRUE if x has no attributes other than "names" is x is not a language object, environment, or other esoteric type. E.g., is.vector of a factor object returns FALSE and is.vector of a numeric object or a list object returns TRUE (unless the object has some attributes). is.vector has nothing to do with the concept of a vector in linear algebra (or aviation or physics or almost anywhere else). Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Kehl D?niel > Sent: Monday, December 05, 2011 11:21 AM > To: r-help at r-project.org > Subject: [R] lists everywhere > > Dear list members, > > I have a really simple problem. > I connected to a DB and have the following query > > adat <- dbGetQuery(con, paste("select * from kmdata where SzeAZ='", > szeazok[i], "' order by datum", sep="")) > > now I have the data in the adat variable which is a list. In fact the > elements of the list are lists as well > > is.list(adat) > [1] TRUE > > is.list(adat[10]) > [1] TRUE > > is.list(adat[[10]]) > [1] FALSE > > is.vector(adat[[10]]) > [1] TRUE > > I simply want to use a function with sapply on the 13-76th columns of > the original list. > sapply(data[[13:76]], myfunc) does not work of course. I tried to define > 13:76 in a vector, still no result. > How is it possible? > > thanks a lot > d > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From fincher at cs.fsu.edu Mon Dec 5 21:10:57 2011 From: fincher at cs.fsu.edu (Justin Fincher) Date: Mon, 5 Dec 2011 15:10:57 -0500 Subject: [R] adding hyperlinked text to pdf plot In-Reply-To: References: Message-ID: For example, say I am plotting some data that is genomic and therefore maps to a specific locus on the human genome, like a gene. I was hoping to have the title of the plot display the gene name, but have it be a link so that clicking on it would take you to those coordinates on a public browser, like USCS's genome browser. So basically, I was hoping to have text in a plot generated by R function as a normal html-style link. - Fincher On Mon, Dec 5, 2011 at 14:09, Yihui Xie wrote: > It seems I missed the context of this post -- who is "you", and what > is "something other than the URL"? > > I feel the tikzDevice package should be an option for the task. > > Regards, > Yihui > -- > Yihui Xie > Phone: 515-294-2465 Web: http://yihui.name > Department of Statistics, Iowa State University > 2215 Snedecor Hall, Ames, IA > > > > On Mon, Dec 5, 2011 at 12:39 PM, Justin Fincher wrote: >> Howdy, >> ? I have read that if you put a URL in the text of a plot being saved >> into pdf, the result is a functional hyperlink. I am interested in >> having text in a plot that is linked to a URL, but I would like the >> text to be something other than the URL. Is this possible? Thank you. >> >> - Fincher >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean. > From xie at yihui.name Mon Dec 5 21:20:04 2011 From: xie at yihui.name (Yihui Xie) Date: Mon, 5 Dec 2011 14:20:04 -0600 Subject: [R] adding hyperlinked text to pdf plot In-Reply-To: References: Message-ID: Sorry I experimented with tikzDevice using \href{}{} but failed. You can probably try the old image hotspot technique in HTML. I remember someone did this before in R, but I cannot find the link to the work now. The key is your need to use the two functions grconvertX and grconvertY. Regards, Yihui -- Yihui Xie Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Mon, Dec 5, 2011 at 2:10 PM, Justin Fincher wrote: > For example, say I am plotting some data that is genomic and therefore > maps to a specific locus on the human genome, like a gene. ?I was > hoping to have the title of the plot display the gene name, but have > it be a link so that clicking on it would take you to those > coordinates on a public browser, like USCS's genome browser. ?So > basically, I was hoping to have text in a plot generated by R function > as a normal html-style link. > > - Fincher > > > On Mon, Dec 5, 2011 at 14:09, Yihui Xie wrote: >> It seems I missed the context of this post -- who is "you", and what >> is "something other than the URL"? >> >> I feel the tikzDevice package should be an option for the task. >> >> Regards, >> Yihui >> -- >> Yihui Xie >> Phone: 515-294-2465 Web: http://yihui.name >> Department of Statistics, Iowa State University >> 2215 Snedecor Hall, Ames, IA >> >> >> >> On Mon, Dec 5, 2011 at 12:39 PM, Justin Fincher wrote: >>> Howdy, >>> ? I have read that if you put a URL in the text of a plot being saved >>> into pdf, the result is a functional hyperlink. I am interested in >>> having text in a plot that is linked to a URL, but I would like the >>> text to be something other than the URL. Is this possible? Thank you. >>> >>> - Fincher >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> >> -- >> This message has been scanned for viruses and >> dangerous content by MailScanner, and is >> believed to be clean. >> From murdoch.duncan at gmail.com Mon Dec 5 21:20:37 2011 From: murdoch.duncan at gmail.com (Duncan Murdoch) Date: Mon, 05 Dec 2011 15:20:37 -0500 Subject: [R] adding hyperlinked text to pdf plot In-Reply-To: References: Message-ID: <4EDD2795.2070702@gmail.com> On 05/12/2011 3:10 PM, Justin Fincher wrote: > For example, say I am plotting some data that is genomic and therefore > maps to a specific locus on the human genome, like a gene. I was > hoping to have the title of the plot display the gene name, but have > it be a link so that clicking on it would take you to those > coordinates on a public browser, like USCS's genome browser. So > basically, I was hoping to have text in a plot generated by R function > as a normal html-style link. Just use Sweave, and put the URL in a LaTeX \href{URL}{text} tag, not in the R code. This can be generated in R code in \Sexp{}. It's not part of the PDF image, but it's part of the final document. Duncan Murdoch > - Fincher > > > On Mon, Dec 5, 2011 at 14:09, Yihui Xie wrote: > > It seems I missed the context of this post -- who is "you", and what > > is "something other than the URL"? > > > > I feel the tikzDevice package should be an option for the task. > > > > Regards, > > Yihui > > -- > > Yihui Xie > > Phone: 515-294-2465 Web: http://yihui.name > > Department of Statistics, Iowa State University > > 2215 Snedecor Hall, Ames, IA > > > > > > > > On Mon, Dec 5, 2011 at 12:39 PM, Justin Fincher wrote: > >> Howdy, > >> I have read that if you put a URL in the text of a plot being saved > >> into pdf, the result is a functional hyperlink. I am interested in > >> having text in a plot that is linked to a URL, but I would like the > >> text to be something other than the URL. Is this possible? Thank you. > >> > >> - Fincher > >> > >> ______________________________________________ > >> R-help at r-project.org mailing list > >> https://stat.ethz.ch/mailman/listinfo/r-help > >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > >> and provide commented, minimal, self-contained, reproducible code. > > > > -- > > This message has been scanned for viruses and > > dangerous content by MailScanner, and is > > believed to be clean. > > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From p.murrell at auckland.ac.nz Mon Dec 5 21:30:50 2011 From: p.murrell at auckland.ac.nz (Paul Murrell) Date: Tue, 06 Dec 2011 09:30:50 +1300 Subject: [R] adding hyperlinked text to pdf plot In-Reply-To: References: Message-ID: <4EDD29FA.8040004@auckland.ac.nz> Hi On 6/12/2011 9:10 a.m., Justin Fincher wrote: > For example, say I am plotting some data that is genomic and therefore > maps to a specific locus on the human genome, like a gene. I was > hoping to have the title of the plot display the gene name, but have > it be a link so that clicking on it would take you to those > coordinates on a public browser, like USCS's genome browser. So > basically, I was hoping to have text in a plot generated by R function > as a normal html-style link. The 'gridSVG' package will let you associate a hyperlink with text (or anything else) and produce SVG that can then be viewed in a web page (as long as your plot is a 'lattice' or 'ggplot2' one). Paul > - Fincher > > > On Mon, Dec 5, 2011 at 14:09, Yihui Xie wrote: >> It seems I missed the context of this post -- who is "you", and what >> is "something other than the URL"? >> >> I feel the tikzDevice package should be an option for the task. >> >> Regards, >> Yihui >> -- >> Yihui Xie >> Phone: 515-294-2465 Web: http://yihui.name >> Department of Statistics, Iowa State University >> 2215 Snedecor Hall, Ames, IA >> >> >> >> On Mon, Dec 5, 2011 at 12:39 PM, Justin Fincher wrote: >>> Howdy, >>> I have read that if you put a URL in the text of a plot being saved >>> into pdf, the result is a functional hyperlink. I am interested in >>> having text in a plot that is linked to a URL, but I would like the >>> text to be something other than the URL. Is this possible? Thank you. >>> >>> - Fincher >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> >> -- >> This message has been scanned for viruses and >> dangerous content by MailScanner, and is >> believed to be clean. >> > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/ From diviya.smith at gmail.com Mon Dec 5 21:37:31 2011 From: diviya.smith at gmail.com (Diviya Smith) Date: Mon, 5 Dec 2011 15:37:31 -0500 Subject: [R] Binning the data based on a value Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From michael.weylandt at gmail.com Mon Dec 5 21:41:36 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Mon, 5 Dec 2011 15:41:36 -0500 Subject: [R] Binning the data based on a value In-Reply-To: References: Message-ID: I'd so something like split(a, a$spending) and you can include a round(a$spending, -2) or something similar if you want to group by the 100's. Michael On Mon, Dec 5, 2011 at 3:37 PM, Diviya Smith wrote: > Hello there, > > I have a matrix with some data and I want to split this matrix based on the > values in one column. Is there a quick way of doing this? I have looked at > cut but I am not sure how to exactly use it? > for example: > > I would like to split the matrix "a" based on the spending such that the > data is binned groups [0..99],[100..199]...and so on. > > a <- data.frame(patient=1:7, charges=c(100,500,200,90,400,500,600), > ?age=c(0,3,5,7,10,16,19), ?spending=c(10, 60, 110, 200, 250, 400, 450)) > > Expected ?output - > bin[1] <- c(10, 60) > bin[2] <- c(110, 200, 250) > bin[3] <- c(400, 450) > > NOTE that the number of data points in each bin is not the same and the > empty bins are removed (since there are no points between [199..299], > bin[3] starts at 400. > > Any help would be most appreciated. Thank you in advance. > > Diviya > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From michael.weylandt at gmail.com Mon Dec 5 21:43:52 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Mon, 5 Dec 2011 15:43:52 -0500 Subject: [R] Binning the data based on a value In-Reply-To: References: Message-ID: Just a clarification: I can't get round to work as I first expected so if you want to do bins by 100's you'd probably want: split(a, cut(a$spending, breaks = (0:5)*100)) Michael On Mon, Dec 5, 2011 at 3:41 PM, R. Michael Weylandt wrote: > I'd so something like > > split(a, a$spending) > > and you can include a round(a$spending, -2) or something similar if > you want to group by the 100's. > > Michael > > On Mon, Dec 5, 2011 at 3:37 PM, Diviya Smith wrote: >> Hello there, >> >> I have a matrix with some data and I want to split this matrix based on the >> values in one column. Is there a quick way of doing this? I have looked at >> cut but I am not sure how to exactly use it? >> for example: >> >> I would like to split the matrix "a" based on the spending such that the >> data is binned groups [0..99],[100..199]...and so on. >> >> a <- data.frame(patient=1:7, charges=c(100,500,200,90,400,500,600), >> ?age=c(0,3,5,7,10,16,19), ?spending=c(10, 60, 110, 200, 250, 400, 450)) >> >> Expected ?output - >> bin[1] <- c(10, 60) >> bin[2] <- c(110, 200, 250) >> bin[3] <- c(400, 450) >> >> NOTE that the number of data points in each bin is not the same and the >> empty bins are removed (since there are no points between [199..299], >> bin[3] starts at 400. >> >> Any help would be most appreciated. Thank you in advance. >> >> Diviya >> >> ? ? ? ?[[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. From gyanendra.pokharel at gmail.com Mon Dec 5 21:46:18 2011 From: gyanendra.pokharel at gmail.com (Gyanendra Pokharel) Date: Mon, 5 Dec 2011 15:46:18 -0500 Subject: [R] Problem in while loop Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From gyanendra.pokharel at gmail.com Mon Dec 5 21:47:59 2011 From: gyanendra.pokharel at gmail.com (Gyanendra Pokharel) Date: Mon, 5 Dec 2011 15:47:59 -0500 Subject: [R] Problem in while loop In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From rcreeves at west.net Mon Dec 5 21:04:51 2011 From: rcreeves at west.net (Rick Reeves) Date: Mon, 05 Dec 2011 12:04:51 -0800 Subject: [R] args() function does not list function prototype for locally-produced/installed R package Message-ID: <4EDD23E3.2080802@west.net> Greetings: I have check the 'Building R Extensions' manual and can find no advice on this issue, so I am asking -- I have created an R package consisting entirely of R source code, and created an installer using the R CMD build / R CMD check commands. The package installs correctly, using R CMD install, and the .Rd files for each function (one function per .R / .Rd file) are visible using the '?function' command. However, the 'args(function)' command does not list the function prototype; instead generating the error: Error in args(function) : object "function" not found. Question: If it is possible, what changes do I make to my package and install process to get args() to display the function prototype(s) for the functions in my local package? Thanks, Rick Reeves From h_a_patience at hotmail.com Mon Dec 5 20:24:41 2011 From: h_a_patience at hotmail.com (Bazman76) Date: Mon, 5 Dec 2011 11:24:41 -0800 (PST) Subject: [R] a question on autocorrelation acf In-Reply-To: References: <4BDA115C.9040504@gmail.com> Message-ID: <1323113081359-4161818.post@n4.nabble.com> Hi there, I am wondering how R calculates the acf too? I have a data set of approx 1500 returns when I calculate the lag 1 autocorrelation in excel I get a value of -0.4 but in R its approximately -0.18? I have cross checked with PC give and PC give agrees with excel? I'm sure its just some kind of scaling but it would be nice to resolve this discrepency! Baz -- View this message in context: http://r.789695.n4.nabble.com/a-question-on-autocorrelation-acf-tp2076280p4161818.html Sent from the R help mailing list archive at Nabble.com. From ajdowd at hotmail.co.uk Mon Dec 5 21:57:34 2011 From: ajdowd at hotmail.co.uk (Gathurst) Date: Mon, 5 Dec 2011 12:57:34 -0800 (PST) Subject: [R] Summary coefficients give NA values because of singularities Message-ID: <1323118654603-4162113.post@n4.nabble.com> Hello, I have a data set which I am using to find a model with the most significant parameters included and most importantly, the p-values. The full model is of the form: sad[,1]~b_1 sad[,2]+b_2 sad[,3]+b_3 sad[,4]+b_4 sad[,5]+b_5 sad[,6]+b_6 sad[,7]+b_7 sad[,8]+b_8 sad[,9]+b_9 sad[,10], where the 9 variables on the right hand side are all indicator variables. The thing I don't understand is the line ' sad[, 10] NA NA NA NA ' as a result of 'Coefficients: (1 not defined because of singularities)'. I think the output is taking sad[,10] as the intercept, based on previous attempts at figuring my issue out, which I find a bit wierd considering sad[,10] is either 0 or 1. How do I produce the correct output showing all p-values? My code and output is as follows: sad<-matrix(1,ncol=11,nrow=486) sad[,c(1:10)]<-d[,2][-357] sad[,1]<-d[,29][-357] sad[,2][sad[,2]!=1]<-0 sad[,3][sad[,3]!=2]<-0 sad[,4][sad[,4]!=3]<-0 sad[,5][sad[,5]!=4]<-0 sad[,6][sad[,6]!=5]<-0 sad[,7][sad[,7]!=6]<-0 sad[,8][sad[,8]!=7]<-0 sad[,9][sad[,9]!=8]<-0 sad[,10][sad[,10]!=9]<-0 sad[,2][sad[,2]==1]<-1 sad[,3][sad[,3]==2]<-1 sad[,4][sad[,4]==3]<-1 sad[,5][sad[,5]==4]<-1 sad[,6][sad[,6]==5]<-1 sad[,7][sad[,7]==6]<-1 sad[,8][sad[,8]==7]<-1 sad[,9][sad[,9]==8]<-1 sad[,10][sad[,10]==9]<-1 sad summary(lm(sad[,1]~sad[,2]+sad[,3] +sad[,4]+sad[,5]+sad[,6] +sad[,7]+sad[,8]+sad[,9]+sad[,10])) Call: lm(formula = sad[, 1] ~ sad[, 2] + sad[, 3] + sad[, 4] + sad[, 5] + sad[, 6] + sad[, 7] + sad[, 8] + sad[, 9] + sad[, 10]) Residuals: Min 1Q Median 3Q Max -3.3191 -0.3893 0.0519 0.7436 1.0519 Coefficients: (1 not defined because of singularities) Estimate Std. Error t value Pr(>|t|) (Intercept) 4.34091 0.14495 29.947 <2e-16 *** sad[, 2] -0.16142 0.18128 -0.890 0.3737 sad[, 3] -0.23221 0.20275 -1.145 0.2527 sad[, 4] 0.17832 0.19695 0.905 0.3657 sad[, 5] 0.06450 0.21447 0.301 0.7638 sad[, 6] -0.15909 0.18713 -0.850 0.3957 sad[, 7] -0.39286 0.18171 -2.162 0.0311 * sad[, 8] -0.08450 0.21146 -0.400 0.6896 sad[, 9] -0.02176 0.20170 -0.108 0.9141 sad[, 10] NA NA NA NA --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 Residual standard error: 0.9615 on 477 degrees of freedom Multiple R-squared: 0.02984, Adjusted R-squared: 0.01357 F-statistic: 1.834 on 8 and 477 DF, p-value: 0.06869 Thanks in advance. -- View this message in context: http://r.789695.n4.nabble.com/Summary-coefficients-give-NA-values-because-of-singularities-tp4162113p4162113.html Sent from the R help mailing list archive at Nabble.com. From peter.langfelder at gmail.com Mon Dec 5 22:03:27 2011 From: peter.langfelder at gmail.com (Peter Langfelder) Date: Mon, 5 Dec 2011 13:03:27 -0800 Subject: [R] installing several versions of R (2.14 and 2.12.2) on the same system on Ubuntu In-Reply-To: <1323114423.8857.YahooMailNeo@web28210.mail.ukl.yahoo.com> References: <1323114423.8857.YahooMailNeo@web28210.mail.ukl.yahoo.com> Message-ID: On Mon, Dec 5, 2011 at 11:47 AM, Jannis wrote: > Dear R users, > > > besides the current R 2.14 I would like to install a second version of R (2.12.2) on my Ubuntu system. The current version is easily installed as a precompiled package from Cran but I am heavily fighting with the older version. I tried to follow the instructions here: > > http://cran.r-project.org/doc/manuals/R-admin.html > > Unfortunately I got totally confused by all the different locations of the script, the library and the rest of the program. As I understand these all have to be different from the ones of the R 2.14 installation. In case anybody could point me to some nice instructions, fell welcome to do so. > > > Otherwise we would need to check what went wrong during my try. I finally managed to install R.2.12.2 but, as it seems, without Java correctly set up and without tcltk support (both are needed). r-base-dev is installed. > > > This I what I did: > > 1. downloaded R.2.12.2.tar.gz from Cran > 2. tar -xzf R-2.12.2.tar.gz > 3. sudo cp R-2.12.2 /usr/lib > 4. cd /usr/lib/R.2.12.2 > 5. mkdir prog > 5. sudo ./configure --prefix=/usr/bin > 6. sudo make prefix=/usr/lib/R-2.12.2/prog rhome=/usr/lib/R-2.12.2/library > > 7. sudo mv /usr/bin/R /usr/bin/R-2.12.2 > > > Most probably these two arguments for make are not correct as I did not fully understand the instructions here. Additionally I would need to facilitate tcl/tk and Java. Both works with R.2.14 so their dependecies should be installed but I probably need some more arguments during the build for that. Also this renaming of the R script seems arkward to me but I did this to easily run "R-2.12.2" or "R-2.14" from the command line. > > > Does anybody have any advice on how to fix this stuff? I think you did basically the right thing. To be able to compile R with tcl/tk, you have to install the development files for tcl/tk - on Fedora the files are contained in package tcl-devel (this is a Fedora/Ubuntu package, not an R package). Then run the entire compilation process (./configure, make, make install) again. When you install a pre-compiled R, you don't need the development files, which is probably why you never needed them in the past. I'm not sure about Java - you may want to examine the output of configure (which is usually saved in configure.log) to see what is missing. HTH, Peter From diviya.smith at gmail.com Mon Dec 5 22:06:48 2011 From: diviya.smith at gmail.com (Diviya Smith) Date: Mon, 5 Dec 2011 16:06:48 -0500 Subject: [R] Binning the data based on a value In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From michael.weylandt at gmail.com Mon Dec 5 22:09:10 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Mon, 5 Dec 2011 16:09:10 -0500 Subject: [R] Binning the data based on a value In-Reply-To: References: Message-ID: Add the drop = TRUE command to split ?split split(a, cut(a$spending, breaks = (0:5)*100), drop = TRUE) Michael On Mon, Dec 5, 2011 at 4:06 PM, Diviya Smith wrote: > Thank you very much Michael. This is very helpful. However, if there is any > way to exclude zero length bins. Lets imagine that the matrix was as follows > - > > a <- data.frame(patient=1:7, charges=c(100,500,200,90,400,500,600), > ?age=c(0,3,5,7,10,16,19), ?spending=c(10, 60, 110, 200, 400, 450, 500)) > > bins <- split(a, cut(a$spending, breaks = (0:5)*100) > > then bins[3] = > $`(200,300]` > [1] patient ?charges ?age ? ? ?spending > <0 rows> (or 0-length row.names) > > Is there a way to exclude this? > > Priya > > On Mon, Dec 5, 2011 at 3:43 PM, R. Michael Weylandt > wrote: >> >> Just a clarification: I can't get round to work as I first expected so >> if you want to do bins by 100's you'd probably want: >> >> split(a, cut(a$spending, breaks = (0:5)*100)) >> >> Michael >> >> On Mon, Dec 5, 2011 at 3:41 PM, R. Michael Weylandt >> wrote: >> > I'd so something like >> > >> > split(a, a$spending) >> > >> > and you can include a round(a$spending, -2) or something similar if >> > you want to group by the 100's. >> > >> > Michael >> > >> > On Mon, Dec 5, 2011 at 3:37 PM, Diviya Smith >> > wrote: >> >> Hello there, >> >> >> >> I have a matrix with some data and I want to split this matrix based on >> >> the >> >> values in one column. Is there a quick way of doing this? I have looked >> >> at >> >> cut but I am not sure how to exactly use it? >> >> for example: >> >> >> >> I would like to split the matrix "a" based on the spending such that >> >> the >> >> data is binned groups [0..99],[100..199]...and so on. >> >> >> >> a <- data.frame(patient=1:7, charges=c(100,500,200,90,400,500,600), >> >> ?age=c(0,3,5,7,10,16,19), ?spending=c(10, 60, 110, 200, 250, 400, 450)) >> >> >> >> Expected ?output - >> >> bin[1] <- c(10, 60) >> >> bin[2] <- c(110, 200, 250) >> >> bin[3] <- c(400, 450) >> >> >> >> NOTE that the number of data points in each bin is not the same and the >> >> empty bins are removed (since there are no points between [199..299], >> >> bin[3] starts at 400. >> >> >> >> Any help would be most appreciated. Thank you in advance. >> >> >> >> Diviya >> >> >> >> ? ? ? ?[[alternative HTML version deleted]] >> >> >> >> ______________________________________________ >> >> R-help at r-project.org mailing list >> >> https://stat.ethz.ch/mailman/listinfo/r-help >> >> PLEASE do read the posting guide >> >> http://www.R-project.org/posting-guide.html >> >> and provide commented, minimal, self-contained, reproducible code. > > From michael.weylandt at gmail.com Mon Dec 5 22:23:49 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Mon, 5 Dec 2011 16:23:49 -0500 Subject: [R] a question on autocorrelation acf In-Reply-To: <1323113081359-4161818.post@n4.nabble.com> References: <4BDA115C.9040504@gmail.com> <1323113081359-4161818.post@n4.nabble.com> Message-ID: Did you check the MASS reference given above in the thread? If you want to see the source, it's here: http://svn.r-project.org/R/trunk/src/library/stats/src/filter.c (best I can tell) Michael On Mon, Dec 5, 2011 at 2:24 PM, Bazman76 wrote: > Hi there, > > I am wondering how R calculates the acf too? > > I have a data set of approx 1500 returns when I calculate the lag 1 > autocorrelation in excel I get a value of -0.4 but in R its approximately > -0.18? > > I have cross checked with PC give and PC give agrees with excel? > > I'm sure its just some kind of scaling but it would be nice to resolve this > discrepency! > > Baz > > -- > View this message in context: http://r.789695.n4.nabble.com/a-question-on-autocorrelation-acf-tp2076280p4161818.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From void1999 at gmail.com Mon Dec 5 22:35:45 2011 From: void1999 at gmail.com (zz dd) Date: Mon, 5 Dec 2011 22:35:45 +0100 Subject: [R] nipals in the chemometrics package in R In-Reply-To: References: <1c18fb68-fdbd-4525-904d-496361f639b1@email.android.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From un_tonio at yahoo.com Mon Dec 5 22:47:32 2011 From: un_tonio at yahoo.com (Tonio) Date: Mon, 5 Dec 2011 13:47:32 -0800 (PST) Subject: [R] Toggle cASE In-Reply-To: <4EDCB756.2080509@uke.de> References: <1323069111.20601.YahooMailNeo@web130111.mail.mud.yahoo.com> <4EDCB756.2080509@uke.de> Message-ID: <1323121652.3211.YahooMailNeo@web130113.mail.mud.yahoo.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From Mintewab.Bezabih at economics.gu.se Mon Dec 5 22:55:58 2011 From: Mintewab.Bezabih at economics.gu.se (Mintewab Bezabih) Date: Mon, 5 Dec 2011 22:55:58 +0100 Subject: [R] problems using the thin plate spline method In-Reply-To: <292964CB-7BD6-4F59-BC60-1256C3571180@gmail.com> References: <4B46FB7EED800046A5952FCFA92D3BA0347DF578CD@HGUMAIL6.hgu.gu.se> <4B46FB7EED800046A5952FCFA92D3BA0347DF578D2@HGUMAIL6.hgu.gu.se> <4B46FB7EED800046A5952FCFA92D3BA0347DF578D3@HGUMAIL6.hgu.gu.se> <67c9a4a2-ee18-49b6-a1a1-791a2d3bda2e@email.android.com> <4B46FB7EED800046A5952FCFA92D3BA0347DF578D5@HGUMAIL6.hgu.gu.se>, <292964CB-7BD6-4F59-BC60-1256C3571180@gmail.com> Message-ID: <4B46FB7EED800046A5952FCFA92D3BA0347DF578D7@HGUMAIL6.hgu.gu.se> Dear Michael and R users, I generated a more orderly looking data again and below are the data and the codes I am trying to run. many thanks mintewab dat <- read.table("E:/thin plate/thin plate.csv", header=T, sep=",") names(dat) <- c("x1", "x2", "y") library(fidelds) plot (dat) plot (dat$x1, dat$x2) #load the fields package (containing Tps) and fit a thin plate spline tpsfit <- Tps(cbind(dat$x1, dat$x2), dat$y, scale.type="unscaled") x1 x2 y 1 409.50 673.0 1082.50 2 349.00 335.0 684.00 3 385.50 1737.0 2122.50 4 273.00 457.0 730.00 5 543.00 2325.0 2868.00 6 746.00 1255.0 2001.00 7 198.75 388.0 586.75 8 262.50 104.0 366.50 9 320.50 786.0 1106.50 10 259.00 516.0 775.00 11 399.50 542.0 941.50 12 595.50 916.0 1511.50 13 374.00 1257.0 1631.00 14 293.00 229.0 522.00 15 330.00 490.0 820.00 16 658.00 1016.0 1674.00 17 299.00 266.0 565.00 18 775.00 1139.0 1914.00 19 559.75 1023.0 1582.75 20 251.00 153.0 404.00 21 402.00 253.0 655.00 22 395.50 319.0 714.50 23 345.50 456.0 801.50 24 283.50 400.0 683.50 25 452.00 388.0 840.00 26 816.50 941.0 1757.50 27 266.50 307.0 573.50 28 360.25 683.0 1043.25 29 386.00 528.0 914.00 30 160.25 368.0 528.25 31 360.00 455.0 815.00 32 337.00 488.0 825.00 33 326.00 702.0 1028.00 34 758.00 1040.0 1798.00 35 342.50 405.0 747.50 36 389.00 483.0 872.00 37 347.50 524.0 871.50 38 819.25 490.0 1309.25 39 355.25 517.0 872.25 40 281.00 505.0 786.00 41 494.50 844.0 1338.50 42 514.50 429.0 943.50 43 263.00 349.0 612.00 44 439.00 549.0 988.00 45 263.00 450.0 713.00 46 373.25 1212.0 1585.25 47 546.00 546.0 1092.00 48 348.00 485.0 833.00 49 380.50 378.0 758.50 50 606.00 598.0 1204.00 51 460.00 838.0 1298.00 52 352.50 519.0 871.50 53 737.00 624.0 1361.00 54 275.00 185.0 460.00 55 520.50 632.0 1152.50 56 385.25 696.5 1081.75 57 354.50 524.0 878.50 58 383.50 618.0 1001.50 59 322.50 381.0 703.50 60 309.00 380.0 689.00 61 502.50 624.0 1126.50 62 517.00 612.0 1129.00 63 276.00 260.0 513.00 64 400.50 831.0 1231.50 65 272.50 451.0 723.50 66 NA 284.0 NA 67 253.00 353.0 606.00 68 311.00 720.0 1031.00 69 389.00 583.0 972.00 70 157.75 344.0 501.75 71 520.00 1175.0 1695.00 72 499.50 761.0 1260.50 73 481.00 694.0 1275.00 74 448.50 606.0 1054.50 75 335.50 239.0 574.50 76 231.50 273.0 504.50 77 492.50 394.0 886.50 78 477.50 899.0 1376.50 79 650.00 721.0 1371.00 80 540.75 730.0 1270.75 81 620.50 1295.0 1915.50 82 400.50 1148.0 1548.50 83 331.50 524.0 855.50 84 311.00 578.0 889.00 85 229.00 262.0 491.00 86 432.50 326.0 758.50 87 422.75 217.0 639.75 88 493.50 648.0 1141.50 89 414.25 485.0 899.25 90 487.00 726.0 1213.00 91 369.00 747.0 1116.00 92 425.00 1663.0 2088.00 93 233.50 269.0 502.50 94 254.50 488.5 743.00 95 417.50 1137.0 1554.50 96 NA 310.0 NA 97 583.25 434.0 1017.25 98 492.50 536.0 1028.50 99 490.00 486.0 976.00 100 300.25 1225.0 1525.25 101 NA 462.0 NA 102 270.00 237.0 507.00 103 307.00 230.0 537.00 104 319.00 242.0 561.00 105 374.50 340.0 714.50 106 562.50 521.0 1083.50 107 569.50 242.0 811.50 108 389.75 389.0 778.75 109 341.25 691.0 1032.25 110 366.00 387.0 753.00 111 262.75 615.0 877.75 112 776.25 1926.0 2702.25 113 379.50 597.0 976.50 114 360.00 299.0 659.00 115 203.75 213.0 416.75 116 517.00 618.0 1135.00 117 539.50 684.0 1223.50 118 418.75 439.0 857.75 119 353.50 459.0 812.50 120 269.00 366.0 635.00 121 475.50 1098.0 1573.50 122 472.00 384.0 856.00 123 342.00 488.0 830.00 124 189.00 181.0 370.00 125 492.50 5342.0 5834.50 126 412.00 433.0 845.00 127 467.50 1475.0 1942.50 128 209.75 480.0 689.75 129 340.75 207.0 547.75 130 231.50 153.0 384.50 131 185.50 295.0 480.50 132 358.50 524.0 882.50 133 354.00 453.0 807.00 134 670.50 978.0 1648.50 135 686.00 486.0 1172.00 136 364.00 676.0 1040.00 137 138.00 336.0 474.00 138 272.00 254.0 526.00 139 183.00 273.0 456.00 140 365.25 255.0 620.25 141 188.00 347.0 535.00 142 229.50 420.0 649.50 143 553.50 603.0 1156.50 144 582.50 739.0 1321.50 145 469.00 340.0 809.00 146 359.50 572.0 931.50 147 284.25 441.0 725.25 148 582.50 833.0 1415.50 149 287.00 775.0 1062.00 150 NA 129.0 NA 151 455.25 350.0 805.25 152 410.50 1445.0 1855.50 153 477.00 328.0 805.00 154 239.00 585.0 824.00 155 313.50 412.0 725.50 156 294.50 446.0 740.50 157 523.00 679.0 1202.00 158 372.50 519.0 891.50 159 231.50 372.0 603.50 160 NA 1712.0 NA 161 365.00 167.0 532.00 162 269.50 492.0 761.50 163 394.50 593.0 987.50 164 281.50 210.0 491.50 165 418.50 363.0 781.50 166 553.50 630.0 1183.50 167 245.75 261.0 506.75 168 304.00 869.0 1173.00 169 423.75 676.0 1099.75 170 369.50 253.0 622.50 171 330.50 923.0 1253.50 172 278.00 791.0 1069.00 173 257.00 415.0 672.00 174 416.50 349.0 765.50 175 413.25 825.0 1238.25 176 465.50 486.0 951.50 177 877.25 508.0 1385.25 178 204.00 191.0 395.00 179 475.00 282.0 757.00 180 289.00 267.0 556.00 181 425.75 372.0 797.75 182 405.00 639.0 1044.00 183 494.25 687.0 1181.25 184 332.00 1427.0 1759.00 185 552.50 847.0 1399.50 186 433.75 368.0 801.75 187 821.00 616.0 1437.00 188 841.50 1723.0 2564.50 189 226.50 310.0 536.50 190 266.75 449.0 715.75 191 552.00 301.0 853.00 192 157.50 378.0 535.50 193 528.50 573.0 1101.50 194 248.50 273.0 521.50 195 245.50 405.0 650.50 196 303.00 653.0 956.00 197 444.25 606.0 1050.25 198 310.00 943.0 1253.00 199 768.25 926.0 1694.25 200 265.50 399.0 664.50 201 98.25 282.0 380.25 202 525.00 1112.0 1637.00 203 407.75 484.0 891.75 204 163.50 408.0 571.50 205 374.25 434.0 808.25 206 749.00 595.0 1344.00 207 318.50 223.0 541.50 208 367.00 517.0 884.00 209 250.00 323.0 573.00 210 408.00 353.0 761.00 211 341.50 628.0 969.50 212 266.50 334.0 600.50 213 348.50 502.0 850.50 214 398.50 861.0 1259.50 215 429.50 361.0 790.50 216 420.00 464.0 884.00 217 263.50 285.0 548.50 218 581.50 693.0 1274.50 219 509.50 129.0 610.50 220 724.75 817.0 1541.75 221 476.50 516.0 992.50 222 249.50 291.0 540.50 223 297.50 211.0 508.50 224 245.00 232.0 477.00 225 139.50 269.0 408.50 226 360.50 378.0 738.50 227 983.50 2560.5 3544.00 228 465.50 662.0 1127.50 229 263.75 580.0 843.75 230 NA 531.0 NA 231 510.00 1334.0 1844.00 232 325.00 384.0 709.00 233 122.50 217.0 339.50 234 455.50 714.0 1169.50 235 531.00 766.0 1297.00 236 318.00 648.0 966.00 237 373.00 288.0 661.00 238 487.00 722.0 1209.00 239 401.00 917.0 1318.00 240 451.75 359.0 810.75 241 561.00 576.0 1137.00 242 364.50 383.0 747.50 243 439.50 546.0 985.50 244 733.50 1379.0 2112.50 245 455.00 622.0 1077.00 246 376.50 201.0 577.50 247 554.00 549.0 1103.00 248 409.50 575.0 984.50 249 1007.50 1416.0 2423.50 250 462.50 496.0 958.50 251 183.00 111.0 294.00 252 342.50 406.0 748.50 253 304.00 519.0 823.00 254 258.25 294.0 552.25 255 380.50 343.0 723.50 256 373.00 437.0 810.00 257 683.00 972.0 1655.00 258 577.00 1403.0 1980.00 259 430.00 471.0 901.00 260 324.25 368.0 692.25 261 312.00 459.0 771.00 262 389.00 617.0 1006.00 263 345.00 444.0 789.00 264 358.50 312.0 670.50 265 551.75 963.0 1514.75 266 317.50 315.0 632.50 267 499.00 549.0 1048.00 268 335.50 1022.0 1357.50 269 450.50 423.0 873.50 270 363.50 384.0 747.50 271 185.00 195.0 380.00 272 177.50 265.0 442.50 273 477.75 827.0 1304.75 274 644.50 827.0 1471.50 275 290.25 309.0 599.25 276 457.50 546.0 1003.50 277 295.50 385.0 680.50 278 266.50 380.0 646.50 279 348.50 422.0 770.50 280 357.75 188.0 545.75 281 221.50 378.0 599.50 282 739.00 772.0 1511.00 283 445.50 233.0 678.50 284 416.00 339.0 755.00 285 261.50 952.0 1213.50 286 909.00 1336.0 2245.00 287 737.50 1740.0 2477.50 288 194.50 256.0 450.50 289 438.50 772.0 1210.50 290 358.00 462.0 820.00 291 244.00 254.0 498.00 292 388.50 243.0 631.50 293 512.50 332.0 844.50 294 315.25 871.0 1186.25 295 572.00 562.0 1134.00 296 473.75 1761.0 2234.75 297 627.50 689.0 1316.50 298 507.75 623.0 1130.75 299 281.00 286.0 567.00 300 511.50 233.0 744.50 301 309.25 668.0 977.25 302 308.25 1078.0 1386.25 303 690.00 682.0 1372.00 304 180.00 169.0 349.00 305 341.50 437.0 778.50 306 273.00 943.0 1216.00 307 571.00 724.0 1295.00 308 694.00 614.0 1308.00 309 345.00 439.0 784.00 310 497.00 344.0 841.00 311 219.00 297.0 516.00 312 311.50 384.0 695.50 313 458.50 569.0 1027.50 314 283.00 187.0 470.00 315 274.00 498.0 772.00 316 282.50 335.0 617.50 317 187.50 339.0 526.50 318 332.00 289.0 621.00 319 281.75 431.0 712.75 320 397.75 549.0 946.75 321 336.50 334.0 670.50 322 392.50 482.0 874.50 323 318.00 363.0 681.00 324 609.50 663.0 1272.50 325 203.50 192.0 395.50 326 144.50 60.0 204.50 327 504.75 468.0 972.75 328 647.00 582.0 1229.00 329 374.00 365.0 739.00 330 149.50 479.0 658.50 331 319.00 983.0 1302.00 332 306.00 668.0 974.00 333 304.75 605.0 909.75 334 304.50 231.0 535.50 335 247.00 457.0 704.00 336 329.00 469.0 798.00 337 442.00 664.0 1106.00 338 308.00 490.0 798.00 339 316.00 274.0 590.00 340 219.00 580.0 799.00 341 556.50 476.0 1032.50 342 643.50 385.0 1028.50 343 328.50 302.0 630.50 344 301.00 607.0 908.00 345 467.00 1723.0 2190.00 346 452.50 441.0 893.50 347 351.50 463.0 814.50 348 373.00 229.0 602.00 349 503.50 138.0 641.50 350 287.50 279.0 566.50 351 393.50 245.0 638.50 352 444.00 1081.0 1525.00 353 734.00 1080.0 1814.00 354 458.50 1745.0 2203.50 355 1182.00 1157.0 2339.00 356 406.00 338.0 744.00 357 286.50 571.0 857.50 358 283.50 211.0 494.50 359 642.50 2256.0 2898.50 360 453.50 778.0 1231.50 361 206.00 224.0 430.00 362 258.00 158.0 416.00 363 412.00 393.0 805.00 364 551.00 661.5 1212.50 365 784.75 4828.0 5612.75 366 316.50 478.0 794.50 367 326.50 687.0 1013.50 368 202.25 497.0 699.25 369 336.75 244.0 580.75 370 406.00 455.0 861.00 371 225.50 390.0 615.50 372 266.00 271.0 537.00 373 916.50 849.0 1765.50 374 387.00 316.0 703.00 375 496.25 785.0 1281.25 376 389.00 464.0 853.00 377 668.50 509.0 1177.50 378 192.00 338.0 530.00 379 396.00 567.0 963.00 380 282.50 726.0 1008.50 381 414.50 742.0 1156.50 382 355.00 515.0 870.00 383 294.50 245.0 539.50 384 396.50 501.0 897.50 385 348.75 359.0 707.75 386 241.75 220.0 461.75 387 347.50 555.0 902.50 388 250.00 424.0 674.00 389 473.50 592.0 1065.50 390 369.00 1470.0 1839.00 391 672.00 441.0 1113.00 392 199.50 177.0 376.50 393 318.25 1302.0 1620.25 394 219.75 245.0 464.75 395 124.00 429.0 553.00 396 514.25 597.0 1111.25 397 600.50 809.0 1409.50 398 256.00 835.0 1091.00 399 574.75 1548.0 2122.75 400 346.25 568.0 914.25 401 397.00 310.0 707.00 402 195.00 218.0 413.00 403 494.00 904.0 1398.00 404 567.50 1276.0 1843.50 405 431.50 538.0 969.50 406 144.50 315.0 459.50 407 440.00 526.0 966.00 408 525.50 604.0 1129.50 409 375.50 506.0 881.50 410 841.50 1836.0 2677.50 411 386.25 365.0 751.25 412 490.50 889.0 1379.50 413 296.50 508.0 804.50 414 812.25 446.0 1258.25 415 385.00 999.0 1384.00 416 232.50 392.0 624.50 417 239.25 189.0 428.25 418 316.50 377.0 693.50 419 312.25 335.0 647.25 420 257.75 214.0 471.75 421 NA 469.0 NA 422 389.00 530.0 919.00 423 301.50 197.0 498.50 424 242.25 630.0 872.25 425 400.25 814.0 1214.25 426 367.25 1305.0 1672.25 427 321.50 932.0 1253.50 428 301.00 753.0 1054.00 429 223.00 361.0 584.00 430 360.00 1139.0 1499.00 431 662.50 639.0 1301.50 432 407.50 908.0 1315.50 433 736.00 1535.0 2271.00 434 379.50 483.0 862.50 435 852.00 786.0 1638.00 436 355.00 476.0 831.00 437 397.00 467.0 864.00 438 527.50 703.0 1230.50 439 531.25 830.0 1361.25 440 473.00 565.0 1038.00 441 559.75 883.0 1442.75 442 344.00 1569.0 1913.00 443 379.75 1071.0 1450.75 444 459.00 261.0 720.00 445 322.00 564.0 886.00 446 208.50 645.0 853.50 447 424.25 365.0 789.25 448 342.25 587.0 929.25 449 414.50 585.0 999.50 450 308.00 395.0 703.00 451 574.50 673.0 1247.50 452 635.00 940.0 1575.00 453 449.50 1002.0 1451.50 454 286.00 225.0 511.00 455 986.25 1311.0 2297.25 456 563.50 471.0 1034.50 457 596.00 629.0 1225.00 458 492.00 433.0 925.00 459 265.00 213.0 478.00 460 826.50 1335.0 2161.50 461 557.00 662.0 1219.00 462 387.50 565.0 952.50 463 531.50 1028.0 1559.50 464 464.00 442.0 906.00 465 582.00 548.0 1130.00 466 354.50 418.0 772.50 467 382.75 741.0 1123.75 468 833.00 798.0 1631.00 469 347.25 482.0 829.25 470 615.25 595.0 1210.25 471 389.00 362.0 751.00 472 354.25 580.0 934.25 473 564.00 953.0 1517.00 474 890.50 1057.0 1947.50 475 168.00 171.0 339.00 476 467.25 834.0 1301.25 477 554.50 466.0 1020.50 478 296.00 861.0 1157.00 479 744.50 1624.0 2368.50 480 387.25 648.0 1035.25 481 393.25 394.0 787.25 482 331.00 1008.0 1339.00 483 391.00 626.0 1017.00 484 274.00 442.0 716.00 485 707.75 530.0 1237.75 486 467.50 716.0 1183.50 487 160.50 211.0 371.50 488 569.50 960.5 1530.00 489 340.50 511.0 851.50 490 259.00 335.0 594.00 491 321.75 452.0 773.75 492 286.25 661.0 947.25 493 416.50 303.0 719.50 494 459.25 411.0 870.25 495 276.50 336.0 612.50 496 280.25 681.0 961.25 497 258.50 450.0 708.50 498 309.50 346.0 655.50 499 424.50 417.0 841.50 500 365.00 458.0 823.00 501 809.00 1313.0 2122.00 502 238.75 795.0 1033.75 503 524.00 529.0 1053.00 504 563.50 203.0 766.50 505 419.00 699.0 1118.00 506 354.50 500.0 854.50 507 303.00 282.0 585.00 508 167.50 339.0 506.50 509 236.25 479.0 715.25 510 268.00 361.0 629.00 511 330.50 330.0 660.50 512 251.50 366.0 617.50 513 249.00 169.0 418.00 514 443.50 882.0 1325.50 515 411.50 3209.0 3620.50 516 323.50 225.0 548.50 517 485.25 1158.0 1643.25 518 356.50 701.0 1057.50 519 221.50 316.0 537.50 520 515.50 646.0 1161.50 521 462.00 682.0 1144.00 522 322.50 414.0 736.50 523 602.50 869.0 1471.50 524 446.25 761.0 1207.25 525 489.75 645.0 1134.75 526 396.50 641.0 1037.50 527 NA 669.0 NA 528 222.50 260.0 482.50 529 365.50 1155.0 1520.50 530 386.00 908.0 1294.00 531 286.00 878.0 1164.00 532 448.00 609.0 1057.00 533 379.75 519.0 898.75 534 293.50 313.0 606.50 535 410.00 527.0 937.00 536 335.50 511.0 846.50 537 444.50 538.0 982.50 538 464.75 339.0 803.75 539 364.25 803.0 1167.25 540 360.00 232.0 592.00 541 589.00 773.0 1362.00 542 546.50 1739.0 2285.50 543 470.00 567.0 1037.00 544 304.50 248.0 552.50 545 NA 1375.0 NA 546 501.50 1340.0 1841.50 547 459.50 456.0 915.50 548 715.00 1470.0 2185.00 549 349.00 459.0 808.00 550 285.00 480.0 765.00 551 268.00 396.0 664.00 552 507.50 566.0 1073.50 553 441.50 668.0 1109.50 554 188.50 555.0 743.50 555 186.50 198.0 384.50 556 679.00 1479.0 2158.00 557 249.00 229.0 478.00 558 200.00 227.0 427.00 559 419.50 500.0 919.50 560 294.25 560.0 854.25 561 596.00 927.0 1523.00 562 395.75 412.0 807.75 563 314.75 403.0 717.75 564 412.50 397.0 809.50 565 363.75 527.0 890.75 566 218.50 385.0 603.50 567 208.50 381.0 589.50 568 535.50 582.0 1117.50 569 309.75 539.0 848.75 570 336.00 426.0 762.00 571 217.00 361.0 578.00 572 245.50 1212.0 1457.50 573 608.75 624.0 1232.75 574 375.00 469.0 844.00 575 555.50 294.0 849.50 576 621.00 1194.0 1815.00 577 488.50 620.0 1108.50 578 271.50 234.0 505.50 579 331.50 446.0 777.50 580 286.00 177.0 463.00 581 555.00 893.0 1448.00 582 345.00 489.0 834.00 583 529.50 426.0 955.50 584 370.00 699.0 1069.00 585 584.25 539.0 1123.25 586 208.50 486.0 694.50 587 473.50 887.0 1360.50 588 244.00 321.0 565.00 589 296.25 235.0 531.25 590 598.00 501.0 1099.00 591 456.25 586.0 1042.25 592 371.00 509.0 880.00 593 505.50 687.0 1192.50 594 269.50 520.0 789.50 595 284.00 820.0 1104.00 596 420.75 758.0 1178.75 597 358.25 441.0 799.25 598 476.75 876.0 1352.75 599 363.00 661.0 1024.00 600 485.75 638.0 1123.75 601 570.00 512.0 1082.00 602 567.25 518.0 1085.25 603 355.50 695.0 1050.50 604 444.00 397.0 841.00 605 629.00 179.0 808.00 606 367.50 450.0 817.50 607 174.50 98.0 272.50 608 217.00 94.0 311.00 609 239.00 100.0 339.00 610 378.50 216.0 594.50 611 179.50 86.0 265.50 612 188.00 149.0 337.00 613 355.00 338.0 693.00 614 304.50 324.0 628.50 615 354.50 460.0 814.50 616 207.50 124.0 331.50 617 615.00 375.0 990.00 618 163.50 255.0 418.50 619 374.00 356.0 730.00 620 316.50 263.0 579.50 621 79.00 64.0 143.00 622 409.00 374.0 783.00 623 218.25 477.0 695.25 624 452.00 664.0 1116.00 625 398.00 370.0 768.00 626 277.50 416.0 693.50 627 289.25 416.0 705.25 628 491.00 741.0 1232.00 629 515.00 1136.0 1651.00 ________________________________________ Fr?n: R. Michael Weylandt [michael.weylandt at gmail.com] Skickat: den 5 december 2011 14:04 Till: Mintewab Bezabih Kopia: Jeff Newmiller; Sarah Goslee; r-help at r-project.org ?mne: Re: [R] problems using the thin plate spline method Your data was scrubbed by the server. Use dput() to create a plain text representation of dat you can put in the body of the email. Michael On Dec 5, 2011, at 6:54 AM, Mintewab Bezabih wrote: > Dear Jeff and R users, > > Thanks Jeff. > > Your first plot suggestion worked. And when I stick dat$x1, dat$x2,dat$y, tpsfit seems to work as well. But it gives me a new error message > > tpsfit <- Tps(cbind(dat$x1, dat$x2), dat$y, scale.type="unscaled") > > Warning message: > In gcv.Krig(out, nstep.cv = nstep.cv, verbose = verbose, cost = out$cost, : > Value of pure error estimate is outside possible range > > Then I get error messages for the subsequent lines as well. > > I have now attached the data. And here is the full code I am trying to run. > > > dat <- read.table("E:/thin plate/thin plate.csv", header=T, sep=",") > names(dat) <- c("x1", "x2", "y") > library(fields) > plot (dat) > > #load the fields package (containing Tps) and fit a thin plate spline > tpsfit <- Tps(cbind(dat$x1, dat$x2), dat$y, scale.type="unscaled") > > #predict the thin plate spline on the fine grid and plot the fitting > ngrid <- length(xf); grid <- cbind(rep(xf, ngrid), rep(xf, rep(ngrid, ngrid))) > out.p1 <- predict(tpsfit, grid) > > > persp(xf, xf, matrix(out.p1, ngrid, ngrid, byrow=F), theta=130, phi=20, > expand=0.45, xlab="x1", ylab="x2", zlab="y", xlim=c(0,1), ylim=c(0,1), > zlim=range(zf), ticktype="detailed", scale=F, main="gcv fitting") > > Many thanks once again. > > regards > mintewab > > > > Fr?n: Jeff Newmiller [jdnewmil at dcn.davis.ca.us] > Skickat: den 5 december 2011 12:39 > Till: Mintewab Bezabih; Sarah Goslee > Kopia: r-help at r-project.org > ?mne: Re: [R] problems using the thin plate spline method > > Try > > plot( dat$x1, dat$y ) > > or > > plot( x1, y, data=dat ) > > Note that your example is still not reproducible because you have not supplied the data or a shortened version of your data for us to work with. Also, your problem is not with thin plates but with plot, and reading the help for that function by typing > > ?plot > > at the R command line would have provided you with more examples and usage info on how to get around this problem. > --------------------------------------------------------------------------- > Jeff Newmiller The ..... ..... Go Live... > DCN: Basics: ##.#. ##.#. Live Go... > Live: OO#.. Dead: OO#.. Playing > Research Engineer (Solar/Batteries O.O#. #.O#. with > /Software/Embedded Controllers) .OO#. .OO#. rocks...1k > --------------------------------------------------------------------------- > Sent from my phone. Please excuse my brevity. > > Mintewab Bezabih wrote: > >> Dear Sarah and R users, >> >> Sorry again for not being explicit enough. Here is my full problem >> >> >> dat <- read.table("E:/thin plate/thin plate.csv", header=T, sep=",") >> dat >> names(dat) <- c("x1", "x2", "y") >> library(fields) >> plot (dat) >> >> #load the fields package (containing Tps) and fit a thin plate spline >> tpsfit <- Tps(cbind(x1, x2), y, scale.type="unscaled") >> >> What I meant when I said the graph works is when I do plot(dat) it does >> plot of all my three variables. If I do plot(x1,y), though, I get the >> 'object x1 not found' error message. >> >> Same when I do the next line tpsfit <- Tps(cbind(x1, x2), y, >> scale.type="unscaled"). I get the same error message. >> >> I tried your suggestion of checking str(x1) and I get the same error >> message (object x1 not found). >> I also typed ls() and I get "dat" after that command. >> >> I followed the r tutorial guide to read my data and I am following the >> r tutorial to guide me to apply the thin plate spline method. >> >> Regards, >> >> Mintewab >> ________________________________________ >> Fr?n: Sarah Goslee [sarah.goslee at gmail.com] >> Skickat: den 4 december 2011 15:21 >> Till: Mintewab Bezabih >> Kopia: r-help at r-project.org >> ?mne: Re: [R] problems using the thin plate spline method >> >> Hello, >> >> On Sun, Dec 4, 2011 at 8:08 AM, Mintewab Bezabih >> wrote: >>> Dear R users and Jeff, >>> >>> Sorry for not being quite explicit in my earlier message. >> >> And you are still not explicit. We have no idea what you've done. >> >>> My main problem is while my data seem to be read into R well (I >> manage to graph them and all), I cannot get the following line to work. >>> >>> tpsfit <- Tps(cbind(x1, x2), y, scale.type="unscaled") >>> >>> and I get the following error message >>> >>> Error in as.matrix(x) : >>> error in evaluating the argument 'x' in selecting a method for >> function 'as.matrix': Error: object 'x1' not found >> >> I'd have to guess that there's no object x1. What does ls() tell you? >> str(x1)? >> >> What do your data look like? You were already given instructions on how >> to >> include sample data to construct a reproducible example. You said that >> graphing your data worked; how did you do so? >> >> The posting guide and the advice you were already given were both >> offered for a reason. The querent needs to do the work of formulating >> an understandable and answerable question. >> >> Sarah >> >>> thanks for help >>> minti >>> ________________________________________ >>> Fr?n: Jeff Newmiller [jdnewmil at dcn.davis.ca.us] >>> Skickat: den 3 december 2011 17:45 >>> Till: Mintewab Bezabih; r-help at r-project.org >>> ?mne: Re: [R] problems using the thin plate spline method >>> >>> I can tell that you are puzzled and confused. Unfortunately, I am not >> psychic, so I cannot tell what you did, and therefore cannot tell where >> you went astray. >>> >>> The solution is for you to read the posting guide mentioned at the >> bottom of every R-help message. Spend a little time to create a small >> bit of data like yours if your actual data is large (subset and dput >> are useful for this). Remember to include the output of sessionInfo, >> and so on. Many times you are likely to find the answer yourself by >> going through these steps, but they are essential for communication. >>> >>> Good luck. >>> Sent from my phone. Please excuse my brevity. >>> >>> Mintewab Bezabih wrote: >>> >>>> Dear R users, >>>> >>>> I am a beginner in R trying to apply the thin plate spline method to >> my >>>> climate data. I used the example in R to do so, and the lines seem to >>>> run fine ( I am not getting errors) but I am not getting any output >> in >>>> the form of graph or anything. I got a warning message saying that >>>> 'surface extends beyond box'. >>>> >>>> Any help is much appreciated. >>>> thanks >>>> minti >> >> >> -- >> Sarah Goslee >> http://www.functionaldiversity.org >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From michael.weylandt at gmail.com Mon Dec 5 23:11:59 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Mon, 5 Dec 2011 17:11:59 -0500 Subject: [R] Shading the plot In-Reply-To: References: Message-ID: As David said, your "minimal working example" is neither minimal nor working...consider this (admittedly quite clunky) example though: time <- seq(10, 20, length.out = 100) S1 <- 10*exp( cumsum(rnorm(100))/20) S2 <- 10*exp( cumsum(rnorm(100))/20) plot(time, S1, ylim = range(c(S1,S2)), type = "n") lines(time, S1); lines(time, S2, col = 2) r <- c(1, which(diff(sign(S1-S2)) != 0L), length(time)) for(i in seq_along(r)){ if(i == length(r)){next} ind1 <- r[i] ind2 <- r[i+1] Xbnds <- time[ind1:ind2] Xbnds <- c(Xbnds, rev(Xbnds)) Ybnds <- c(S1[ind1:ind2],S2[ind2:ind1]) col = if(median((S1>S2)[ind1:ind2])) "blue" else "green" polygon(Xbnds, Ybnds, col = col, border = NA) } Best I can figure, this fills green if the red line is on top and blue otherwise. You may have to run it a few times to see that behavior. Michael On Sat, Dec 3, 2011 at 11:37 PM, avinash barnwal wrote: > Hi, > > I apologies? for my naive doubts > I have been trying it from a while. I need the area between the curve based > on conditions i wrote (whenever red line is above the blue line then area > between curves to be grey color and whenever blue line is above red line > then area between curves to be red color ) > > x and y are vectors > > Thank you for replying > > > > > On Sun, Dec 4, 2011 at 7:56 AM, David Winsemius > wrote: >> >> >> On Dec 3, 2011, at 5:28 PM, avinash barnwal wrote: >> >>> Hi Weylandt, >>> >>> >>> I tried it but i was not successful. >>> >>> Here is the full code >>> >>> Any help would be great. >>> ######################################################################## >>> >>> time<-c("02-Jan-05","09-Jan-05","16-Jan-05","23-Jan-05","30-Jan-05","06-Feb-05","13-Feb-05","20-Feb-05","27-Feb-05","06-Mar-05","13-Mar-05", >>> >>> "20-Mar-05","27-Mar-05","03-Apr-05","10-Apr-05","17-Apr-05","24-Apr-05","01-May-05","08-May-05","15-May-05") >>> time<-as.Date(time,"%d-%b-%y") >>> >>> a2<-c("81.96392786","81.96392786","82.16432866","82.56513026","82.76553106","79.96593186","78.16633267", >>> >>> "75.56713427","74.76753507","72.96793587","70.96793587","45.96793587","83.96793587","84.36873747", >>> >>> "84.56913828","84.56913828","84.56913828","84.56913828","84.36873747","84.36873747") >>> >>> a3<-c("81.96392786","81.96392786","81.96392786","70.96392786","68.16432866","66.16432866", >>> >>> "62.16432866","58.56513026","56.56513026","54.56513026","48.56513026","49.76553106","52.76553106", >>> >>> "54.76553106","57.96593186","59.36673347","83.36673347","83.36673347","83.36673347", >>> "83.56713427") >>> j<-0 >>> for(i in 1:length(a3)) >>> { >>> if(a2[i]>a3[i]) >>> { >>> j<-j+1 >>> x[j]<-a2[i] >>> y[j]<-a3[i] >>> temp_time[j]<-time[i] >>> } >>> } >>> plot(time,a2,type='l',col='red',ylab='',xlab=" ",axes=FALSE) >>> lines(time,a3,col='blue',ylab='',xlab=" ") >>> polygon(c(temp_time,rev(temp_time)),c(x,y),col="grey") >>> ######################################################################### >> >> >> What are the rules that govern requesting outside help in homework at your >> institution? >> >> Your current code does not recognize ?that there is line crossing. Nor do >> you describe what you mean by shading. If you wanted a rectangle within the >> lpot area it would drive one strategy and if you wanted only the area >> between the curves to be shaded it would drive a different strategy. >> >> AND you never define "x" or "y". >> >> -- >> David. >> >> >> >>> On Sun, Dec 4, 2011 at 2:46 AM, R. Michael Weylandt < >>> michael.weylandt at gmail.com> wrote: >>> >>>> ? polygon >>>> example(polygon) >>>> >>>> Michael >>>> >>>> On Sat, Dec 3, 2011 at 4:08 PM, avinash barnwal >>>> wrote: >>>>> >>>>> Hi all, >>>>> >>>>> I have been trying to shade the specific part of the plot >>>>> >>>>> Part to be shaded >>>>> >>>>> 1. Any color whenever a2>a3 >>>>> >>>>> 2. Any other color( Not same as 1) whenever a2>>>> >>>>> Suggest me some code for this task >>>>> >>>>> PLOT CODE for reference >>>>> >>>>> >>>> >>>> ###################################################################################################### >>>>> >>>>> >>>> >>>> a2<-c("81.96392786","81.96392786","82.16432866","82.56513026","82.76553106","79.96593186","78.16633267", >>>>> >>>>> >>>> >>>> "75.56713427","74.76753507","72.96793587","70.96793587","45.96793587","83.96793587","84.36873747", >>>>> >>>>> >>>> >>>> "84.56913828","84.56913828","84.56913828","84.56913828","84.36873747","84.36873747") >>>>> >>>>> >>>> >>>> a3<-c("81.96392786","81.96392786","81.96392786","70.96392786","68.16432866","66.16432866", >>>>> >>>>> >>>> >>>> "62.16432866","58.56513026","56.56513026","54.56513026","48.56513026","49.76553106","52.76553106", >>>>> >>>>> >>>> >>>> "54.76553106","57.96593186","59.36673347","83.36673347","83.36673347","83.36673347", >>>>> >>>>> "83.56713427") >>>>> plot(a2,type='l',col='red',ylab='',xlab=" ",axes=FALSE) >>>>> lines(a3,col='blue',ylab='',xlab=" ") >>>>> >>>> >>>> ###################################################################################################### >>>>> >>>>> >>>>> Thank you in the advance >>>>> -- >>>>> Avinash Barnwal >>>>> Final year undergraduate student >>>>> Statistics and informatics >>>>> Department of Mathematics >>>>> IIT Kharagpur >>>>> >>>>> ______________________________________________ >>>>> R-help at r-project.org mailing list >>>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>>> PLEASE do read the posting guide >>>> >>>> http://www.R-project.org/posting-guide.html >>>>> >>>>> and provide commented, minimal, self-contained, reproducible code. >>>>> >>>> >>> >>> >>> >>> -- >>> Avinash Barnwal >>> Final year undergraduate student >>> Statistics and informatics >>> Department of Mathematics >>> IIT Kharagpur >>> >>> ? ? ? ?[[alternative HTML version deleted]] >>> >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> >> >> David Winsemius, MD >> West Hartford, CT >> > > > > -- > Avinash Barnwal > Final year undergraduate student > Statistics and informatics > Department of Mathematics > IIT Kharagpur From michael.weylandt at gmail.com Mon Dec 5 23:18:46 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Mon, 5 Dec 2011 17:18:46 -0500 Subject: [R] Problem in while loop In-Reply-To: References: Message-ID: Your code is not reproducible nor minimal, but why don't you put a command print(acceptprob) in and see if you are getting reasonable values. If these values are extremely low it shouldn't surprise you that your loop takes a long time to run. More generally, read up on the use of print() and browser() as debugging tools. Michael On Mon, Dec 5, 2011 at 3:47 PM, Gyanendra Pokharel wrote: > I forgot to upload the R-code in last email, so heare is one > > epiann <- function(T0 = 1, N=1000, ainit=1, binit=1,rho = 0.99, amean = 3, > bmean=1.6, avar =.1, bvar=.1, f){ > > ? ? ? ?moving <- 1 > ? ? ? ?count <- 0 > ? ? ? ?Temp <- T0 > ? ? ? ?aout <- ainit > ? ? ? ?bout <- binit > ? ? ? ?while(moving > 0){ > ? ? ? ? ? ? ? ?moving <- 0 > ? ? ? ? ? ? ? ?for (i in 1:N) { > ? ? ? ? ? ? ? ?aprop <- rnorm (1,amean, avar) > ? ? ? ? ? ? ? ?bprop <- rnorm (1,bmean, bvar) > ? ? ? ? ? ? ? ?if (aprop > 0 & bprop > 0){ > ? ? ? ? ? ? ? ?acceptprob <- min(1,exp((f(aout, bout) - > f(aprop,bprop))/Temp)) > ? ? ? ? ? ? ? ?u <- runif(1) > ? ? ? ? ? ? ? ?if(u ? ? ? ? ? ? ? ? ? ?moving <- moving +1 > ? ? ? ? ? ? ? ? ? ?aout <- aprop > ? ? ? ? ? ? ? ? ? ?bout <- bprop > ? ? ? ? ? ? ? ? ? ?} > ? ? ? ? ? ? ? ? ? ?else{aprob <- aout > ? ? ? ? ? ? ? ? ? ? ? ?bprob <- bout} > ? ? ? ? ? ? ? ?} > ? ? ? ? ? ?} > ? ? ? ?Temp <- Temp*rho > ? ? ? ? ? ?count <- count +1 > > ? ?} > ? ?fmin <- f(aout,bout) > ? ?return(c(aout, bout,fmin, count) ) > > } > out<- epiann(f = loglikelihood) > > On Mon, Dec 5, 2011 at 3:46 PM, Gyanendra Pokharel < > gyanendra.pokharel at gmail.com> wrote: > >> Hi all, >> I have the following code, >> When I run the code, it never terminate this is because of the while loop >> i am using. In general, if you need a loop for which you don't know in >> advance how many iterations there will be, you can use the `while' >> statement so here too i don't know the number how many iterations are >> there. So Can some one suggest me whats going on? >> I am using the Metropolis simulated annealing algorithm >> Best >> > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From gyanendra.pokharel at gmail.com Mon Dec 5 23:29:24 2011 From: gyanendra.pokharel at gmail.com (Gyanendra Pokharel) Date: Mon, 5 Dec 2011 17:29:24 -0500 Subject: [R] Problem in while loop In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From jpntsang at yahoo.com Mon Dec 5 23:43:35 2011 From: jpntsang at yahoo.com (Juliet Ndukum) Date: Mon, 5 Dec 2011 14:43:35 -0800 (PST) Subject: [R] plot mixed variables Message-ID: <1323125015.70141.YahooMailClassic@web161203.mail.bf1.yahoo.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From murdoch.duncan at gmail.com Mon Dec 5 23:49:08 2011 From: murdoch.duncan at gmail.com (Duncan Murdoch) Date: Mon, 05 Dec 2011 17:49:08 -0500 Subject: [R] args() function does not list function prototype for locally-produced/installed R package In-Reply-To: <4EDD23E3.2080802@west.net> References: <4EDD23E3.2080802@west.net> Message-ID: <4EDD4A64.8040906@gmail.com> On 11-12-05 3:04 PM, Rick Reeves wrote: > Greetings: > > I have check the 'Building R Extensions' manual and can find no advice > on this issue, > so I am asking -- > > I have created an R package consisting entirely of R source code, and > created an installer > using the R CMD build / R CMD check commands. The package installs > correctly, using > R CMD install, and the .Rd files for each function (one function per .R > / .Rd file) are visible > using the '?function' command. However, the 'args(function)' command > does not list the > function prototype; instead generating the error: > > Error in args(function) : object "function" not found. > > Question: If it is possible, what changes do I make to my package and > install process to get > args() to display the function prototype(s) for the functions in my > local package? Is the function visible (e.g., if you type the name of the function, does it print)? I would guess not: I think you have a NAMESPACE file, and you haven't listed this function in it. If you don't have a NAMESPACE file, or you do have one and you list this function, then I think you need to be more forthcoming with accurate information. When I type args(function), I don't get the error you get, since "function" is a reserved word: > args(function) Error: unexpected ')' in "args(function)" Duncan Murdoch Duncan Murdoch From murdoch.duncan at gmail.com Mon Dec 5 23:54:48 2011 From: murdoch.duncan at gmail.com (Duncan Murdoch) Date: Mon, 05 Dec 2011 17:54:48 -0500 Subject: [R] installing several versions of R (2.14 and 2.12.2) on the same system on Ubuntu In-Reply-To: References: <1323114423.8857.YahooMailNeo@web28210.mail.ukl.yahoo.com> Message-ID: <4EDD4BB8.8060007@gmail.com> On 11-12-05 4:03 PM, Peter Langfelder wrote: > On Mon, Dec 5, 2011 at 11:47 AM, Jannis wrote: >> Dear R users, >> >> >> besides the current R 2.14 I would like to install a second version of R (2.12.2) on my Ubuntu system. The current version is easily installed as a precompiled package from Cran but I am heavily fighting with the older version. I tried to follow the instructions here: >> >> http://cran.r-project.org/doc/manuals/R-admin.html >> >> Unfortunately I got totally confused by all the different locations of the script, the library and the rest of the program. As I understand these all have to be different from the ones of the R 2.14 installation. In case anybody could point me to some nice instructions, fell welcome to do so. >> >> >> Otherwise we would need to check what went wrong during my try. I finally managed to install R.2.12.2 but, as it seems, without Java correctly set up and without tcltk support (both are needed). r-base-dev is installed. >> >> >> This I what I did: >> >> 1. downloaded R.2.12.2.tar.gz from Cran >> 2. tar -xzf R-2.12.2.tar.gz >> 3. sudo cp R-2.12.2 /usr/lib >> 4. cd /usr/lib/R.2.12.2 >> 5. mkdir prog >> 5. sudo ./configure --prefix=/usr/bin >> 6. sudo make prefix=/usr/lib/R-2.12.2/prog rhome=/usr/lib/R-2.12.2/library >> >> 7. sudo mv /usr/bin/R /usr/bin/R-2.12.2 >> >> >> Most probably these two arguments for make are not correct as I did not fully understand the instructions here. Additionally I would need to facilitate tcl/tk and Java. Both works with R.2.14 so their dependecies should be installed but I probably need some more arguments during the build for that. Also this renaming of the R script seems arkward to me but I did this to easily run "R-2.12.2" or "R-2.14" from the command line. >> >> >> Does anybody have any advice on how to fix this stuff? > > I think you did basically the right thing. To be able to compile R > with tcl/tk, you have to install the development files for tcl/tk - on > Fedora the files are contained in package tcl-devel (this is a > Fedora/Ubuntu package, not an R package). Then run the entire > compilation process (./configure, make, make install) again. When you > install a pre-compiled R, you don't need the development files, which > is probably why you never needed them in the past. > > I'm not sure about Java - you may want to examine the output of > configure (which is usually saved in configure.log) to see what is > missing. > Besides what Peter said, I would suggest that you follow the instructions for "simple compilation" in the document you cited. You are doing way too much as a superuser. You don't need that at all if you are the only user who needs this old version of R. If you need to install it for others to use, then follow the instructions for "installation" in that document, and let your users change their path to select the R version. Duncan Murdoch From sarah.goslee at gmail.com Mon Dec 5 23:58:46 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Mon, 5 Dec 2011 17:58:46 -0500 Subject: [R] plot mixed variables In-Reply-To: <1323125015.70141.YahooMailClassic@web161203.mail.bf1.yahoo.com> References: <1323125015.70141.YahooMailClassic@web161203.mail.bf1.yahoo.com> Message-ID: plot(xx1, yy, ylim = c(-13.5, 4), col="blue", xaxt="n") axis(1, at=c(1, 2), labels=c("C", "D")) Defining your own axes with axis() offers a great deal of flexibility. And thank you for providing a small reproducible example. Sarah On Mon, Dec 5, 2011 at 5:43 PM, Juliet Ndukum wrote: > > > > ?My data consists of a numeric (yy) > ?variable and a categorical (xx) variable, as shown below. > > > > > xx = > c(rep("C", 5), rep("D",5)) > > yy = rnorm(10, 0, 4) > > xx1 = > as.integer(as.factor(xx)) > > > > plot(xx1, yy, ylim = > c(-13.5, 4), col="blue") > > > > I > wish to generate a scatter plot of the data such that instead of 1 it prints C, > and instead of 2, it prints D on the x- axis. > > > > Could > someone help me with an R code on how to go about this. Thank you in advance > for your ?help, > > JN > ? ? ? ?[[alternative HTML version deleted]] > > -- Sarah Goslee http://www.functionaldiversity.org From michael.weylandt at gmail.com Tue Dec 6 00:07:19 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Mon, 5 Dec 2011 18:07:19 -0500 Subject: [R] Problem in while loop In-Reply-To: References: Message-ID: If you run out<- epiann(f = function(a,b) log(dnorm(a)*dnorm(b))), N = 10) It takes less than 0.5 seconds so there's no problem I can see: perhaps you want to look elsewhere to get better speed (like Rcpp or general vectorization), or maybe your loglikihood is not what's desired, but there's no problem with the loop. Michael On Mon, Dec 5, 2011 at 5:29 PM, Gyanendra Pokharel wrote: > Yes, I checked the acceptprob, it is very high but in my view, the while > loop is not stopping, so there is some thing wrong in the use of while loop. > When I removed the while loop, it returned some thing but not the result > what I want. When i run the while loop separately, it never stops. > > > > On Mon, Dec 5, 2011 at 5:18 PM, R. Michael Weylandt > wrote: >> >> Your code is not reproducible nor minimal, but why don't you put a >> command print(acceptprob) in and see if you are getting reasonable >> values. If these values are extremely low it shouldn't surprise you >> that your loop takes a long time to run. >> >> More generally, read up on the use of print() and browser() as debugging >> tools. >> >> Michael >> >> On Mon, Dec 5, 2011 at 3:47 PM, Gyanendra Pokharel >> wrote: >> > I forgot to upload the R-code in last email, so heare is one >> > >> > epiann <- function(T0 = 1, N=1000, ainit=1, binit=1,rho = 0.99, amean = >> > 3, >> > bmean=1.6, avar =.1, bvar=.1, f){ >> > >> > ? ? ? ?moving <- 1 >> > ? ? ? ?count <- 0 >> > ? ? ? ?Temp <- T0 >> > ? ? ? ?aout <- ainit >> > ? ? ? ?bout <- binit >> > ? ? ? ?while(moving > 0){ >> > ? ? ? ? ? ? ? ?moving <- 0 >> > ? ? ? ? ? ? ? ?for (i in 1:N) { >> > ? ? ? ? ? ? ? ?aprop <- rnorm (1,amean, avar) >> > ? ? ? ? ? ? ? ?bprop <- rnorm (1,bmean, bvar) >> > ? ? ? ? ? ? ? ?if (aprop > 0 & bprop > 0){ >> > ? ? ? ? ? ? ? ?acceptprob <- min(1,exp((f(aout, bout) - >> > f(aprop,bprop))/Temp)) >> > ? ? ? ? ? ? ? ?u <- runif(1) >> > ? ? ? ? ? ? ? ?if(u> > ? ? ? ? ? ? ? ? ? ?moving <- moving +1 >> > ? ? ? ? ? ? ? ? ? ?aout <- aprop >> > ? ? ? ? ? ? ? ? ? ?bout <- bprop >> > ? ? ? ? ? ? ? ? ? ?} >> > ? ? ? ? ? ? ? ? ? ?else{aprob <- aout >> > ? ? ? ? ? ? ? ? ? ? ? ?bprob <- bout} >> > ? ? ? ? ? ? ? ?} >> > ? ? ? ? ? ?} >> > ? ? ? ?Temp <- Temp*rho >> > ? ? ? ? ? ?count <- count +1 >> > >> > ? ?} >> > ? ?fmin <- f(aout,bout) >> > ? ?return(c(aout, bout,fmin, count) ) >> > >> > } >> > out<- epiann(f = loglikelihood) >> > >> > On Mon, Dec 5, 2011 at 3:46 PM, Gyanendra Pokharel < >> > gyanendra.pokharel at gmail.com> wrote: >> > >> >> Hi all, >> >> I have the following code, >> >> When I run the code, it never terminate this is because of the while >> >> loop >> >> i am using. In general, if you need a loop for which you don't know in >> >> advance how many iterations there will be, you can use the `while' >> >> statement so here too i don't know the number how many iterations are >> >> there. So Can some one suggest me whats going on? >> >> I am using the Metropolis simulated annealing algorithm >> >> Best >> >> >> > >> > ? ? ? ?[[alternative HTML version deleted]] >> > >> > ______________________________________________ >> > R-help at r-project.org mailing list >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guide >> > http://www.R-project.org/posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code. > > From jpntsang at yahoo.com Mon Dec 5 23:22:40 2011 From: jpntsang at yahoo.com (Juliet Ndukum) Date: Mon, 5 Dec 2011 14:22:40 -0800 (PST) Subject: [R] Plot numeric and categorical variable Message-ID: <1323123760.89219.YahooMailClassic@web161204.mail.bf1.yahoo.com> My data consists of numeric (yy) and categorical (xx) variables, as shown below.? > xx = c(rep("C", 5), rep("D",5))> xx?[1] "C" "C" "C" "C" "C" "D" "D" "D" "D" "D"> yy = rnorm(10, 0, 4)> yy?[1] ?2.7219346 -3.7142481 ?6.8716534 -0.9352463 ?0.4901249 ?3.8113247?[7] -2.6602041 ?1.7714471 ?4.7298233 ?0.8848188 > xx1 = as.integer(as.factor(xx))> plot(xx1, yy, ylim = c(-13.5, 4), col="blue") I have attached the plot above ?as plot1 I wish to generate a scatter plot of the data such that instead of 1 it prints C, and instead of 2, it prints D on the x- axis (see plot1 attached). How could I possibly go about this, let me know. Any help will be greatly appreciated. Thanks in advance for your help,JN From smoochie3002 at gmail.com Mon Dec 5 23:58:26 2011 From: smoochie3002 at gmail.com (crazedruff) Date: Mon, 5 Dec 2011 14:58:26 -0800 (PST) Subject: [R] Plotting Time Series Data by Month Message-ID: <1323125906801-4162534.post@n4.nabble.com> Hi, I have a dataset which includes monthly data for 17 years. I want to be able to see the monthly data behavior for the period of all 17 years. What my data looks like: http://r.789695.n4.nabble.com/file/n4162534/data.jpg I would like to represent the data in a graph such as the one below: http://r.789695.n4.nabble.com/file/n4162534/Untitled-2.jpg Any help would be appreciated. Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Plotting-Time-Series-Data-by-Month-tp4162534p4162534.html Sent from the R help mailing list archive at Nabble.com. From magee20v at uregina.ca Tue Dec 6 01:32:00 2011 From: magee20v at uregina.ca (Jasmine007) Date: Mon, 5 Dec 2011 16:32:00 -0800 (PST) Subject: [R] Why can't I figure this out? :S Message-ID: <1323131520211-4162826.post@n4.nabble.com> Hi, so I don't speak computer and I have no idea what this code is telling the program to do, but I apparently need to be able to find and isolate influencial observations. Problem, I have no idea what the error means and where it may be from in the code. error I get is below the code { ## OLS results NameC<- lm(gpanew~female+female:lastinit+agenew+canadian+mom_ed+yearstudy) ## default: choose psamp = quantile n <- length(residuals(NameC)) k <- length(coef(NameC)) if(is.null(quantile)) quantile <- c(floor((n + k + 1)/2), floor((n + k)/2)) quantile <- rep(quantile, length.out = 2) if(is.null(psamp)) psamp <- quantile[1] ## LTS results with robust residuals NameC_lts <- lqs(gpanew~female+female:lastinit+agenew+canadian+mom_ed+yearstudy, quantile = quantile[1], psamp = psamp, nsamp = nsamp) rr <- residuals(NameC_lts)/NameC_lts$scale[2] rr_nok <- abs(rr) > critval[1] ## robust leverage via MCD (or MVE) X <- model.matrix(NameC)[,-1] cv <- cov.rob(X, method = method, quantile = quantile[2], nsamp = dist_nsamp) rd <- sqrt(mahalanobis(X, cv$center, cv$cov)) rd_nok <- rd > critval[2] ## ROBUST results nok <- rr_nok & rd_nok NameC_rob <- lm(formula, data[!nok,]) rval <- list(ols = NameC, lts = NameC_lts, robust = NameC_rob, cov.rob = cv, robresid = rr, robdist = rd, high_residuals = rr[rr_nok], high_leverage = rd[rd_nok], bad_leverage = nok, psamp = psamp, method = method, nsamp = list(lts = nsamp, dist = dist_nsamp), quantile = list(lts = quantile[1], dist = quantile[2])) return(rval) } Error: object of type 'closure' is not subsettable Any ideas, In plain non-computer language.. I have a headache from trying to figure out if this question had been answered before. Thank you -- View this message in context: http://r.789695.n4.nabble.com/Why-can-t-I-figure-this-out-S-tp4162826p4162826.html Sent from the R help mailing list archive at Nabble.com. From wchips at y7mail.com Tue Dec 6 01:10:43 2011 From: wchips at y7mail.com (wchips) Date: Mon, 5 Dec 2011 16:10:43 -0800 (PST) Subject: [R] Persp3d freezes when run from within Python In-Reply-To: <4EDCC7EA.1030008@gmail.com> References: <1323050239287-4158940.post@n4.nabble.com> <4EDCC7EA.1030008@gmail.com> Message-ID: <1323130243190-4162766.post@n4.nabble.com> Thanks Duncan. The thing is, if you want to display a static R graph using Rpy2 you need to bring your Python program to a halt immediately after printing the graph to screen using something like: raw_input("Press any key to continue ...") , otherwise it flashes up on the screen for a fraction of a second and then disappears. I assume this is one and the same issue.. That being, that R is somehow opened and then _closed_ after each instruction when using Rpy2. So whilst "pausing" Python might give you a "snapshot" of the 3d graph, it doesn't give you dynamic interactivity. I just need to find a way to keep R running in the background when I execute that command. Again, if anyone has had the same problem throw me a line! Or other suggestions are also welcome. cheers, chips -- View this message in context: http://r.789695.n4.nabble.com/Persp3d-freezes-when-run-from-within-Python-tp4158940p4162766.html Sent from the R help mailing list archive at Nabble.com. From comtech.usa at gmail.com Tue Dec 6 02:01:00 2011 From: comtech.usa at gmail.com (Michael) Date: Mon, 5 Dec 2011 19:01:00 -0600 Subject: [R] how to view/edit large matrix/array in R? Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From comtech.usa at gmail.com Tue Dec 6 02:07:52 2011 From: comtech.usa at gmail.com (Michael) Date: Mon, 5 Dec 2011 19:07:52 -0600 Subject: [R] how to view/edit large matrix/array in R? In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From comtech.usa at gmail.com Tue Dec 6 02:09:32 2011 From: comtech.usa at gmail.com (Michael) Date: Mon, 5 Dec 2011 19:09:32 -0600 Subject: [R] how to view/edit large matrix/array in R? In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From carl at witthoft.com Tue Dec 6 02:12:25 2011 From: carl at witthoft.com (Carl Witthoft) Date: Mon, 05 Dec 2011 20:12:25 -0500 Subject: [R] Why can't I figure this out? :S Message-ID: <4EDD6BF9.1000208@witthoft.com> If you 'don't speak computer,' what are you doing trying to run R in the first place? Your email address suggests this is homework, but even if it isn't please go talk to your professor or teaching assistant. From: Jasmine007 Date: Mon, 05 Dec 2011 16:32:00 -0800 (PST) Hi, so I don't speak computer and I have no idea what this code is telling the program to do, but I apparently need to be able to find and isolate influencial observations. Problem, I have no idea what the error means and where it may be from in the code. error I get is below the code { ## OLS results NameC<- lm(gpanew~female+female:lastinit+agenew+canadian+mom_ed+yearstudy) ## default: choose psamp = quantile n <- length(residuals(NameC)) k <- length(coef(NameC)) if(is.null(quantile)) quantile <- c(floor((n + k + 1)/2), floor((n + k)/2)) quantile <- rep(quantile, length.out = 2) if(is.null(psamp)) psamp <- quantile[1] ## LTS results with robust residuals NameC_lts <- lqs(gpanew~female+female:lastinit+agenew+canadian+mom_ed+yearstudy, quantile = quantile[1], psamp = psamp, nsamp = nsamp) rr <- residuals(NameC_lts)/NameC_lts$scale[2] rr_nok <- abs(rr) > critval[1] ## robust leverage via MCD (or MVE) X <- model.matrix(NameC)[,-1] cv <- cov.rob(X, method = method, quantile = quantile[2], nsamp = dist_nsamp) rd <- sqrt(mahalanobis(X, cv$center, cv$cov)) rd_nok <- rd > critval[2] ## ROBUST results nok <- rr_nok & rd_nok NameC_rob <- lm(formula, data[!nok,]) rval <- list(ols = NameC, lts = NameC_lts, robust = NameC_rob, cov.rob = cv, robresid = rr, robdist = rd, high_residuals = rr[rr_nok], high_leverage = rd[rd_nok], bad_leverage = nok, psamp = psamp, method = method, nsamp = list(lts = nsamp, dist = dist_nsamp), quantile = list(lts = quantile[1], dist = quantile[2])) return(rval) } Error: object of type 'closure' is not subsettable Any ideas, In plain non-computer language.. I have a headache from trying to figure out if this question had been answered before. Thank you -- Sent from my Cray XK6 "Pendeo-navem mei anguillae plena est." From gunter.berton at gene.com Tue Dec 6 02:12:44 2011 From: gunter.berton at gene.com (Bert Gunter) Date: Mon, 5 Dec 2011 17:12:44 -0800 Subject: [R] how to view/edit large matrix/array in R? In-Reply-To: References: Message-ID: ... and do you really think perusing thousands of numbers by eye is any way to edit/check data?! Personal viewpoint: I would say that this is a large area of statistics and data analysis that the discipline fails to address in any systematic way ... perhaps because there is no way to address it systematically? Contrary views and corrections -- especially references! -- would be very welcome. My advice would be: graphics! -- but I can't provide anything more useful without the specifics of the problem. Some packages may provide the interactivity you seek -- check the CRAN GUI task view, R Commander, etc. -- Bert On Mon, Dec 5, 2011 at 5:01 PM, Michael wrote: > head, tail and fix commands don't really work well if I have large > matrix/array for which I would like to be able to scroll up and dow, left > and right ... > > Could anybody please help me? > > Thanks > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm From comtech.usa at gmail.com Tue Dec 6 02:35:14 2011 From: comtech.usa at gmail.com (Michael) Date: Mon, 5 Dec 2011 19:35:14 -0600 Subject: [R] how to view/edit large matrix/array in R? In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From jholtman at gmail.com Tue Dec 6 02:37:07 2011 From: jholtman at gmail.com (jim holtman) Date: Mon, 5 Dec 2011 20:37:07 -0500 Subject: [R] how to view/edit large matrix/array in R? In-Reply-To: References: Message-ID: Have you tried ?View ?edit On Mon, Dec 5, 2011 at 8:12 PM, Bert Gunter wrote: > ... and do you really think perusing thousands of numbers by eye is > any way to edit/check data?! > > Personal viewpoint: I would say that this is a large area of > statistics and data analysis that the discipline fails to address in > any systematic way ... perhaps because there is no way to address it > systematically? Contrary views and corrections -- especially > references! -- would be very welcome. > > ?My advice would be: graphics! -- but I can't provide anything more > useful without the specifics of the problem. > > Some packages may provide the interactivity you seek -- check the CRAN > GUI task view, R Commander, etc. > > -- Bert > > On Mon, Dec 5, 2011 at 5:01 PM, Michael wrote: >> head, tail and fix commands don't really work well if I have large >> matrix/array for which I would like to be able to scroll up and dow, left >> and right ... >> >> Could anybody please help me? >> >> Thanks >> >> ? ? ? ?[[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > > > -- > > Bert Gunter > Genentech Nonclinical Biostatistics > > Internal Contact Info: > Phone: 467-7374 > Website: > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. From rolf.turner at xtra.co.nz Tue Dec 6 02:45:05 2011 From: rolf.turner at xtra.co.nz (Rolf Turner) Date: Tue, 06 Dec 2011 14:45:05 +1300 Subject: [R] Spatstat - problem with which.marks and as.pp In-Reply-To: References: , Message-ID: <4EDD73A1.5080502@xtra.co.nz> Basically the problem is that you have a *VERY* old version of spatstat. Upgrade! Comments interpolated below. On 05/12/11 21:52, karajamu wrote: > I forgot to change the header, so I guess no one read my mail. That's why I'm trying it again... > > >> >> Hello everbody, >> >> I am new to this mailing list and hope to find some help. >> I'm trying to get into the spatstat package and encountered two problems. First a graphical one: >> There is an example dataset called "finpines" which has several marks (http://www.oga-lab.net/RGM2/func.php?rd_id=spatstat:finpines) >> When I pass the given code from the website to R >> >> >> >> data(finpines) If you were using the latest version of "spatstat" you wouldn't need to do this any more. The data are now lazy-loaded. See latest.news(). >> >> plot(unmark(finpines), main="Finnish pines: locations") >> plot(finpines, which.marks="height", main="heights") >> >> plot(finpines, which.marks="diameter", main="diameters") >> I get the warning >> >> Warnmeldung: >> In symbols(c(-1.993875, -1.019901, -4.914071, -4.469962, -4.303847, : >> "which.marks" ist kein Grafikparameter >> >> Something like "which.marks" is not a graphic parameter; and the plots for height and diameter show now differences. The version of spatstat that you are using must hail from a time prior to when the argument "which.marks" was added to plot.ppp(). >> Furthermore, I want to create a ppp with several marks, but I did not figure out how this works. >> Trying >> >> X<- as.ppp(mydata, owin(c(174, 178), c(29, 33))) >> >> just gives the error >> >> Error in as.ppp(mydata, owin(c(174, 178), c(29, 33))) : >> X must be a two-column or three-column data frame >> >> The data set looks something like >> >> Date X Y Mar1 Mar2 Mar3 >> >> 1.1. 4 3 50 6 A >> 2.1. 2 1 40 9 A >> 3.1. 5 8 35 12 B >> >> But how can I integrate two or more marks in a three-column data frame, when two columns are already needed for the X and Y coordinates? Presumably you want "X" and "Y" to be the x and y coordinates of the points of the pattern, respectively. In which case they must be the ***first two*** columns of the data frame. (Not the second and third!) As you have written "mydata", the first "Date" (the first column) will be of mode "character", which will cause as.ppp() to throw an error. I.e. it will try to take "Date" as the x coordinates (and "X" as the y coordinates) and since "Date" is not numeric, it will give up in disgust. When I do X <- as.ppp(mydata, owin(c(174, 178), c(29, 33))) (using the bit of "mydata" that your email showed) I get the error Error: is.numeric(x) is not TRUE (as expected). Of course I do not get the error that you got, which would have been thrown by as.ppp() waaaayyyy back, when marks had to be *vectors* and data frames of marks weren't allowed for. Bottom line: Update your version of spatstat. cheers, Rolf Turner From bps0002 at auburn.edu Tue Dec 6 03:28:45 2011 From: bps0002 at auburn.edu (B77S) Date: Mon, 5 Dec 2011 18:28:45 -0800 (PST) Subject: [R] Why can't I figure this out? :S In-Reply-To: <1323131520211-4162826.post@n4.nabble.com> References: <1323131520211-4162826.post@n4.nabble.com> Message-ID: <1323138525390-4163150.post@n4.nabble.com> Why can't you figure this out? I think you already know the answer: "I don't speak computer"..... Time to learn, or get another job I suppose. I hope you at least speak math-statistics if you are going to attempt to understand this. The only way you are going to be able to figure that code out is to break it up into pieces until you DO understand it. If that is too much work for you, then ???? Good luck. Jasmine007 wrote > > Hi, so I don't speak computer and I have no idea what this code is telling > the program to do, but I apparently need to be able to find and isolate > influencial observations. Problem, I have no idea what the error means and > where it may be from in the code. > > error I get is below the code > > { > ## OLS results > NameC<- lm(gpanew~female+female:lastinit+agenew+canadian+mom_ed+yearstudy) > > ## default: choose psamp = quantile > n <- length(residuals(NameC)) > k <- length(coef(NameC)) > if(is.null(quantile)) quantile <- c(floor((n + k + 1)/2), > floor((n + k)/2)) > quantile <- rep(quantile, length.out = 2) > if(is.null(psamp)) psamp <- quantile[1] > > ## LTS results with robust residuals > NameC_lts <- > lqs(gpanew~female+female:lastinit+agenew+canadian+mom_ed+yearstudy, > quantile = quantile[1], psamp = psamp, nsamp = nsamp) > rr <- residuals(NameC_lts)/NameC_lts$scale[2] > rr_nok <- abs(rr) > critval[1] > ## robust leverage via MCD (or MVE) > X <- model.matrix(NameC)[,-1] > cv <- cov.rob(X, method = method, > quantile = quantile[2], nsamp = dist_nsamp) > rd <- sqrt(mahalanobis(X, cv$center, cv$cov)) > rd_nok <- rd > critval[2] > ## ROBUST results > nok <- rr_nok & rd_nok > NameC_rob <- lm(formula, data[!nok,]) > rval <- list(ols = NameC, lts = NameC_lts, robust = NameC_rob, > cov.rob = cv, robresid = rr, robdist = rd, > high_residuals = rr[rr_nok], high_leverage = rd[rd_nok], > bad_leverage = nok, psamp = psamp, method = method, > nsamp = list(lts = nsamp, dist = dist_nsamp), > quantile = list(lts = quantile[1], dist = quantile[2])) > return(rval) > } > > Error: object of type 'closure' is not subsettable > > Any ideas, In plain non-computer language.. I have a headache from trying > to figure out if this question had been answered before. > > Thank you > -- View this message in context: http://r.789695.n4.nabble.com/Why-can-t-I-figure-this-out-S-tp4162826p4163150.html Sent from the R help mailing list archive at Nabble.com. From gyanendra.pokharel at gmail.com Tue Dec 6 03:30:29 2011 From: gyanendra.pokharel at gmail.com (Gyanendra Pokharel) Date: Mon, 5 Dec 2011 21:30:29 -0500 Subject: [R] Problem in while loop In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From bps0002 at auburn.edu Tue Dec 6 03:40:00 2011 From: bps0002 at auburn.edu (B77S) Date: Mon, 5 Dec 2011 18:40:00 -0800 (PST) Subject: [R] frequency table? In-Reply-To: <1322990509062-4156422.post@n4.nabble.com> References: <1322990509062-4156422.post@n4.nabble.com> Message-ID: <1323139200476-4163192.post@n4.nabble.com> Set, This is the same post as your "Similarity Matrix" post. I'm not trying to be a smart ass here, but ... ?Can you fit a square peg in a round hole?... yes, but it doesn't mean it belongs there. I suggest you get a piece of paper and a pencil and figure out 1) what you are trying to do and why, and 2) how you would do that by hand. After you do that, you should be able to figure this out on your own or formulate a question to post that someone will be able to answer. Reading might help as well. set wrote > > Hello R-users, > > I've got a file with individuals as colums and the clusters where they > occur in as rows. And I wanted a table which tells me how many times each > individual occurs with another. I don't really know how such a table is > called...it is not a frequency table....My eventual goal is to make > Venn-diagrams from the occurence of my individuals. > > So I've this: > > cluster ind1 ind2 ind3 etc. > 1 0 1 2 > 2 3 0 1 > 3 1 1 1 > > And I want to go to this: > ind1 ind2 ind3 > ind1 0 4 2 > ind2 4 0 4 > ind3 2 4 1 > > is there a way to do this? > Thank you for your help > -- View this message in context: http://r.789695.n4.nabble.com/frequency-table-tp4156422p4163192.html Sent from the R help mailing list archive at Nabble.com. From comtech.usa at gmail.com Tue Dec 6 03:52:22 2011 From: comtech.usa at gmail.com (Michael) Date: Mon, 5 Dec 2011 20:52:22 -0600 Subject: [R] how to view/edit large matrix/array in R? In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From dwinsemius at comcast.net Tue Dec 6 03:54:55 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Mon, 5 Dec 2011 21:54:55 -0500 Subject: [R] how to view/edit large matrix/array in R? In-Reply-To: References: Message-ID: On Dec 5, 2011, at 8:37 PM, jim holtman wrote: > Have you tried > > ?View > ?edit Or: ?pairs help(splom, package=lattice) (My preference is plot(density()) but the 2d density plots are slow so also use: help(hexbin, package=hexbin) -- david. > > On Mon, Dec 5, 2011 at 8:12 PM, Bert Gunter > wrote: >> ... and do you really think perusing thousands of numbers by eye is >> any way to edit/check data?! >> >> Personal viewpoint: I would say that this is a large area of >> statistics and data analysis that the discipline fails to address in >> any systematic way ... perhaps because there is no way to address it >> systematically? Contrary views and corrections -- especially >> references! -- would be very welcome. >> >> My advice would be: graphics! -- but I can't provide anything more >> useful without the specifics of the problem. >> >> Some packages may provide the interactivity you seek -- check the >> CRAN >> GUI task view, R Commander, etc. >> >> -- Bert >> >> On Mon, Dec 5, 2011 at 5:01 PM, Michael >> wrote: >>> head, tail and fix commands don't really work well if I have large >>> matrix/array for which I would like to be able to scroll up and >>> dow, left >>> and right ... >>> >>> Could anybody please help me? >>> >>> Thanks >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> >> >> >> -- >> >> Bert Gunter >> Genentech Nonclinical Biostatistics >> >> Internal Contact Info: >> Phone: 467-7374 >> Website: >> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > > > -- > Jim Holtman > Data Munger Guru > > What is the problem that you are trying to solve? > Tell me what you want to do, not how you want to do it. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT From jholtman at gmail.com Tue Dec 6 04:17:54 2011 From: jholtman at gmail.com (jim holtman) Date: Mon, 5 Dec 2011 22:17:54 -0500 Subject: [R] how to view/edit large matrix/array in R? In-Reply-To: References: Message-ID: 'edit' does allow you to change it. If all else fails, export to Excel, split the screen and then synchronize the two displays. On Mon, Dec 5, 2011 at 9:52 PM, Michael wrote: > View doesn't allow editing? And not multi-window so I cannot put variables > side-by-side for comparsion? Thanks! > > On Mon, Dec 5, 2011 at 7:37 PM, jim holtman wrote: >> >> Have you tried >> >> ?View >> ?edit >> >> On Mon, Dec 5, 2011 at 8:12 PM, Bert Gunter >> wrote: >> > ... and do you really think perusing thousands of numbers by eye is >> > any way to edit/check data?! >> > >> > Personal viewpoint: I would say that this is a large area of >> > statistics and data analysis that the discipline fails to address in >> > any systematic way ... perhaps because there is no way to address it >> > systematically? Contrary views and corrections -- especially >> > references! -- would be very welcome. >> > >> > ?My advice would be: graphics! -- but I can't provide anything more >> > useful without the specifics of the problem. >> > >> > Some packages may provide the interactivity you seek -- check the CRAN >> > GUI task view, R Commander, etc. >> > >> > -- Bert >> > >> > On Mon, Dec 5, 2011 at 5:01 PM, Michael wrote: >> >> head, tail and fix commands don't really work well if I have large >> >> matrix/array for which I would like to be able to scroll up and dow, >> >> left >> >> and right ... >> >> >> >> Could anybody please help me? >> >> >> >> Thanks >> >> >> >> ? ? ? ?[[alternative HTML version deleted]] >> >> >> >> ______________________________________________ >> >> R-help at r-project.org mailing list >> >> https://stat.ethz.ch/mailman/listinfo/r-help >> >> PLEASE do read the posting guide >> >> http://www.R-project.org/posting-guide.html >> >> and provide commented, minimal, self-contained, reproducible code. >> > >> > >> > >> > -- >> > >> > Bert Gunter >> > Genentech Nonclinical Biostatistics >> > >> > Internal Contact Info: >> > Phone: 467-7374 >> > Website: >> > >> > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm >> > >> > ______________________________________________ >> > R-help at r-project.org mailing list >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guide >> > http://www.R-project.org/posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code. >> >> >> >> -- >> Jim Holtman >> Data Munger Guru >> >> What is the problem that you are trying to solve? >> Tell me what you want to do, not how you want to do it. > > -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. From comtech.usa at gmail.com Tue Dec 6 04:26:22 2011 From: comtech.usa at gmail.com (Michael) Date: Mon, 5 Dec 2011 21:26:22 -0600 Subject: [R] how to view/edit large matrix/array in R? In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From comtech.usa at gmail.com Tue Dec 6 04:27:56 2011 From: comtech.usa at gmail.com (Michael) Date: Mon, 5 Dec 2011 21:27:56 -0600 Subject: [R] how to view/edit large matrix/array in R? In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From michael.weylandt at gmail.com Tue Dec 6 04:27:39 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt ) Date: Mon, 5 Dec 2011 22:27:39 -0500 Subject: [R] Problem in while loop In-Reply-To: References: Message-ID: <7DEC6BA8-EBF6-4F11-930E-4BBBA8340D47@gmail.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From comtech.usa at gmail.com Tue Dec 6 04:32:29 2011 From: comtech.usa at gmail.com (Michael) Date: Mon, 5 Dec 2011 21:32:29 -0600 Subject: [R] help! what's wrong with setBreakpoint Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From gyanendra.pokharel at gmail.com Tue Dec 6 04:37:45 2011 From: gyanendra.pokharel at gmail.com (Gyanendra Pokharel) Date: Mon, 5 Dec 2011 22:37:45 -0500 Subject: [R] Problem in while loop In-Reply-To: <7DEC6BA8-EBF6-4F11-930E-4BBBA8340D47@gmail.com> References: <7DEC6BA8-EBF6-4F11-930E-4BBBA8340D47@gmail.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From michael.weylandt at gmail.com Tue Dec 6 04:38:06 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt ) Date: Mon, 5 Dec 2011 22:38:06 -0500 Subject: [R] how to view/edit large matrix/array in R? In-Reply-To: References: Message-ID: <20CD0A34-701A-4EED-B098-A27314D48068@gmail.com> I think what most everyone is getting at is that the visual identification of numeric outliers is an exceedingly difficult task and one we humans are not well evolved for. Rather they are all suggesting you use visual techniques to spot and fix outliers individually. This practice has a long and reputable history in statistics and has been shown to be far more efficient than simply scanning pages of numbers for a single misplaced decimal. In conjunction, I'd also recommend use of the identify() function, which serves just this purpose. If you have so much data that the csv export is unbearably slow it seems unlikely you can check it all by hand. Another, more general, methodology if you are worried about data corruption is to use robust statistics when applicable. Michael On Dec 5, 2011, at 10:27 PM, Michael wrote: > In R-Studio, "edit" gives non-grid based format which is similar to "fix"... > > But exporting to Excel is time-consuming... > > On Mon, Dec 5, 2011 at 9:17 PM, jim holtman wrote: > >> 'edit' does allow you to change it. If all else fails, export to >> Excel, split the screen and then synchronize the two displays. >> >> On Mon, Dec 5, 2011 at 9:52 PM, Michael wrote: >>> View doesn't allow editing? And not multi-window so I cannot put >> variables >>> side-by-side for comparsion? Thanks! >>> >>> On Mon, Dec 5, 2011 at 7:37 PM, jim holtman wrote: >>>> >>>> Have you tried >>>> >>>> ?View >>>> ?edit >>>> >>>> On Mon, Dec 5, 2011 at 8:12 PM, Bert Gunter >>>> wrote: >>>>> ... and do you really think perusing thousands of numbers by eye is >>>>> any way to edit/check data?! >>>>> >>>>> Personal viewpoint: I would say that this is a large area of >>>>> statistics and data analysis that the discipline fails to address in >>>>> any systematic way ... perhaps because there is no way to address it >>>>> systematically? Contrary views and corrections -- especially >>>>> references! -- would be very welcome. >>>>> >>>>> My advice would be: graphics! -- but I can't provide anything more >>>>> useful without the specifics of the problem. >>>>> >>>>> Some packages may provide the interactivity you seek -- check the CRAN >>>>> GUI task view, R Commander, etc. >>>>> >>>>> -- Bert >>>>> >>>>> On Mon, Dec 5, 2011 at 5:01 PM, Michael >> wrote: >>>>>> head, tail and fix commands don't really work well if I have large >>>>>> matrix/array for which I would like to be able to scroll up and dow, >>>>>> left >>>>>> and right ... >>>>>> >>>>>> Could anybody please help me? >>>>>> >>>>>> Thanks >>>>>> >>>>>> [[alternative HTML version deleted]] >>>>>> >>>>>> ______________________________________________ >>>>>> R-help at r-project.org mailing list >>>>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>>>> PLEASE do read the posting guide >>>>>> http://www.R-project.org/posting-guide.html >>>>>> and provide commented, minimal, self-contained, reproducible code. >>>>> >>>>> >>>>> >>>>> -- >>>>> >>>>> Bert Gunter >>>>> Genentech Nonclinical Biostatistics >>>>> >>>>> Internal Contact Info: >>>>> Phone: 467-7374 >>>>> Website: >>>>> >>>>> >> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm >>>>> >>>>> ______________________________________________ >>>>> R-help at r-project.org mailing list >>>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>>> PLEASE do read the posting guide >>>>> http://www.R-project.org/posting-guide.html >>>>> and provide commented, minimal, self-contained, reproducible code. >>>> >>>> >>>> >>>> -- >>>> Jim Holtman >>>> Data Munger Guru >>>> >>>> What is the problem that you are trying to solve? >>>> Tell me what you want to do, not how you want to do it. >>> >>> >> >> >> >> -- >> Jim Holtman >> Data Munger Guru >> >> What is the problem that you are trying to solve? >> Tell me what you want to do, not how you want to do it. >> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From comtech.usa at gmail.com Tue Dec 6 04:40:22 2011 From: comtech.usa at gmail.com (Michael) Date: Mon, 5 Dec 2011 21:40:22 -0600 Subject: [R] how to view/edit large matrix/array in R? In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From comtech.usa at gmail.com Tue Dec 6 04:42:17 2011 From: comtech.usa at gmail.com (Michael) Date: Mon, 5 Dec 2011 21:42:17 -0600 Subject: [R] how to view/edit large matrix/array in R? In-Reply-To: <20CD0A34-701A-4EED-B098-A27314D48068@gmail.com> References: <20CD0A34-701A-4EED-B098-A27314D48068@gmail.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From gyanendra.pokharel at gmail.com Tue Dec 6 04:43:59 2011 From: gyanendra.pokharel at gmail.com (Gyanendra Pokharel) Date: Mon, 5 Dec 2011 22:43:59 -0500 Subject: [R] Problem in while loop In-Reply-To: References: <7DEC6BA8-EBF6-4F11-930E-4BBBA8340D47@gmail.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From ivan.popivanov at gmail.com Tue Dec 6 05:13:45 2011 From: ivan.popivanov at gmail.com (Ivan Popivanov) Date: Mon, 5 Dec 2011 23:13:45 -0500 Subject: [R] rugarch package: is this forecast correct? Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From michael.weylandt at gmail.com Tue Dec 6 05:40:39 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt ) Date: Mon, 5 Dec 2011 23:40:39 -0500 Subject: [R] help! what's wrong with setBreakpoint In-Reply-To: References: Message-ID: A function is a parsed object stored in memory; your edit applies to the source, but not to the memory object being executed. There is no way, to my knowledge, to use browser to alter the execution flow of an function once it's going (other than changing values of course). You need to edit the function definition to put the breakpoint where desired and then reread and rerun the function. Michael On Dec 5, 2011, at 10:32 PM, Michael wrote: > Hi all, > > I am in the middle of debugging which is stopped using "browser()"... in > myfile.R at around line #25. > > I was then stuck in a big loop which I want to escape and stop the program > at the line after the big loop. > > In the debugging mode, I used > > Browse[2]> setBreakpoint("myfile.R#38") > > I then typed "c" and "ENTER", thinking that it will continue to execute > until when it comes across line #38 and then stop there... > > But it didn't work - it continued the execution until the end of the > function, right at the line "return(results)"... > > What happened? How to solve this problem? > > Thanks a lot! > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From GormleyA at landcareresearch.co.nz Tue Dec 6 04:01:39 2011 From: GormleyA at landcareresearch.co.nz (Andrew Gormley) Date: Tue, 6 Dec 2011 16:01:39 +1300 Subject: [R] Memory getting eaten up with XML Message-ID: Hi all. I have an issue that I cannot resolve. I am trying to read in lots of data that are stored in xml files. But after I read them in and copy the relevant data, then remove the document etc, it doesn't free up the memory. When I monitor it in windows task manager the memory usage just climbs with each iteration until R crashes. I can replicate the problem with the small example: file.name<-"C:\\MyData.xml.gz" TEMPP<-xmlParse(file.name) xx <- xmlRoot(TEMPP) rm(xx) rm(TEMPP) gc() Even though I remove the root node xx and the document TEMPP, the memory usage remains the same as it was when I first read it in... Any ideas/solutions? I am using a 32bit version of R 2.14.0 on windows XP, and the latest version of XML (3.6.1). Many thanks Andrew (apologies for the large footer my work appends to all my emails...) Please consider the environment before printing this email Warning: This electronic message together with any attachments is confidential. If you receive it in error: (i) you must not read, use, disclose, copy or retain it; (ii) please contact the sender immediately by reply email and then delete the emails. The views expressed in this email may not be those of Landcare Research New Zealand Limited. http://www.landcareresearch.co.nz From h_a_patience at hotmail.com Tue Dec 6 02:32:37 2011 From: h_a_patience at hotmail.com (Bazman76) Date: Mon, 5 Dec 2011 17:32:37 -0800 (PST) Subject: [R] a question on autocorrelation acf In-Reply-To: References: <4BDA115C.9040504@gmail.com> <1323113081359-4161818.post@n4.nabble.com> Message-ID: <1323135157369-4163021.post@n4.nabble.com> Hi there, I have now cheked the results against pc give and the excel add-in poptools. Poptools and pc give get the same answer but R is quite different especially for the acf and pacf()? I looked at the book you recommended on p390 itshows the formulas and they look pretty standard. However looking at the code that you sent the acf function does not seem to be being calculated as shown in the book? At no point is the series mean calculated? unless the variable x is already demeaned in some way ie. there is some preprocessing that I need to see to fully understand? -- View this message in context: http://r.789695.n4.nabble.com/a-question-on-autocorrelation-acf-tp2076280p4163021.html Sent from the R help mailing list archive at Nabble.com. From rolf.turner at xtra.co.nz Tue Dec 6 03:06:39 2011 From: rolf.turner at xtra.co.nz (Rolf Turner) Date: Tue, 06 Dec 2011 15:06:39 +1300 Subject: [R] spatial analysis In-Reply-To: References: Message-ID: <4EDD78AF.9030106@xtra.co.nz> On 06/12/11 01:44, Marianne.ZEYRINGER at ec.europa.eu wrote: > Dear all, > > I am a PhD student in energy modelling. I am completely stuck with the > following problem and would be very grateful for any kind of help. > I have cells Don't we all? We're made of them. :-) What do you mean by ``I have''? I.e. be a bit more explicit about the nature of your data. > and each cell is assigned a number. I would like to form > clusters of cells where the sum of the cell numbers in each cluster must > not exceed 250. One restriction is that only neighbouring cells Define "neighbouring". > can be > formed into clusters. In the end I would like to have a list with all > possible cell combinations. Do you mean all possible ways in which your ``collection of cells'' can be subdivided into such clusters? My guess is that the number of such ways could be extremely large. (Depending of course on how many cells there are in the collection.) > Is it possible to do this with R If yes, I would very much appreciate > all possible hints how to solve it. Install the "fortunes" package. Then type fortune("Yoda") But if you want useful help you'll have to make your question much clearer. cheers, Rolf Turner From luc.villandre at mail.mcgill.ca Tue Dec 6 03:33:02 2011 From: luc.villandre at mail.mcgill.ca (Luc Villandre) Date: Mon, 5 Dec 2011 21:33:02 -0500 Subject: [R] Can't load package 'lars' Message-ID: <4EDD7EDE.6090809@mail.mcgill.ca> Hi, I installed package 'lars' earlier tonight and did not get any sort of error message. ### ** building package indices ... ** testing if installed package can be loaded Loaded lars 0.9-8 * DONE (lars) ### However, when I try to load it, I get ### > library(lars, lib.loc = "~/R/x86_64-redhat-linux-gnu-library/2.11") Error : .onLoad failed in loadNamespace() for 'lars', details: call: cat("Loaded lars", utils::installed.packages()["lars", "Version"], error: subscript out of bounds Error: package/namespace load failed for ?lars? ### Session info: ### > sessionInfo() R version 2.14.0 (2011-10-31) Platform: x86_64-redhat-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] rpart_3.1-50 tools_2.14.0 ### I get the same error message when I try to load it on another machine: ### > library("lars",lib.loc = "~/R/i686-pc-linux-gnu-library/2.12") Error : .onLoad failed in loadNamespace() for 'lars', details: call: cat("Loaded lars", utils::installed.packages()["lars", "Version"], error: subscript out of bounds Error: package/namespace load failed for 'lars' ### Session info: ### > sessionInfo() R version 2.13.1 (2011-07-08) Platform: i686-pc-linux-gnu (32-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.13.1 ### Is there at least a way to circumvent the problem? Thank you for your help, Luc Villandre From michael.weylandt at gmail.com Tue Dec 6 06:03:41 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt ) Date: Tue, 6 Dec 2011 00:03:41 -0500 Subject: [R] Problem in while loop In-Reply-To: References: <7DEC6BA8-EBF6-4F11-930E-4BBBA8340D47@gmail.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From elisacarli21 at gmail.com Tue Dec 6 06:58:14 2011 From: elisacarli21 at gmail.com (elisacarli21) Date: Mon, 5 Dec 2011 21:58:14 -0800 (PST) Subject: [R] Problem with clusplot Message-ID: <1323151094047-4163621.post@n4.nabble.com> Dear all I'm trying to run a cluster analysis with R Here are the commands: mydata <- na.omit(matrix) # listwise deletion of missing mydata <- scale(matrix) # standardize variables fit <- kmeans(mydata, 8) # 8 cluster solution # get cluster means aggregate(mydata,by=list(fit$cluster),FUN=mean) # append cluster assignment mydata <- data.frame(mydata, fit$cluster) library(cluster) clusplot(mydata, fit$cluster, color=TRUE, shade=TRUE, labels=2, lines=0) I get the following error Error in princomp.default(x, scores = TRUE, cor = ncol(x) != 2) : 'princomp' can only be used with more units than variables How can I fix it? Thanks -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-clusplot-tp4163621p4163621.html Sent from the R help mailing list archive at Nabble.com. From landronimirc at gmail.com Tue Dec 6 08:12:26 2011 From: landronimirc at gmail.com (Liviu Andronic) Date: Tue, 6 Dec 2011 08:12:26 +0100 Subject: [R] how to view/edit large matrix/array in R? In-Reply-To: References: <20CD0A34-701A-4EED-B098-A27314D48068@gmail.com> Message-ID: On Tue, Dec 6, 2011 at 4:42 AM, Michael wrote: > I didn't mean the speed of saving the file is slow... I meant the manual > procedures of exporting and then opening Excel, etc. is slow and > inconvenient and unproductive... > You may want to use RExcel then. Liviu > On Mon, Dec 5, 2011 at 9:38 PM, R. Michael Weylandt < > michael.weylandt at gmail.com> wrote: > >> I think what most everyone is getting at is that the visual identification >> of numeric outliers is an exceedingly difficult task and one we humans are >> not well evolved for. Rather they are all suggesting you use visual >> techniques to spot and fix outliers individually. This practice has a long >> and reputable history in statistics and has been shown to be far more >> efficient than simply scanning pages of numbers for a single misplaced >> decimal. In conjunction, I'd also recommend use of the identify() function, >> which serves just this purpose. >> >> If you have so much data that the csv export is unbearably slow it seems >> unlikely you can check it all by hand. >> >> Another, more general, methodology if you are worried about data >> corruption is to use robust statistics when applicable. >> >> Michael >> >> On Dec 5, 2011, at 10:27 PM, Michael wrote: >> >> > In R-Studio, "edit" gives non-grid based format which is similar to >> "fix"... >> > >> > But exporting to Excel is time-consuming... >> > >> > On Mon, Dec 5, 2011 at 9:17 PM, jim holtman wrote: >> > >> >> 'edit' does allow you to change it. ?If all else fails, export to >> >> Excel, split the screen and then synchronize the two displays. >> >> >> >> On Mon, Dec 5, 2011 at 9:52 PM, Michael wrote: >> >>> View doesn't allow editing? And not multi-window so I cannot put >> >> variables >> >>> side-by-side for comparsion? Thanks! >> >>> >> >>> On Mon, Dec 5, 2011 at 7:37 PM, jim holtman >> wrote: >> >>>> >> >>>> Have you tried >> >>>> >> >>>> ?View >> >>>> ?edit >> >>>> >> >>>> On Mon, Dec 5, 2011 at 8:12 PM, Bert Gunter >> >>>> wrote: >> >>>>> ... and do you really think perusing thousands of numbers by eye is >> >>>>> any way to edit/check data?! >> >>>>> >> >>>>> Personal viewpoint: I would say that this is a large area of >> >>>>> statistics and data analysis that the discipline fails to address in >> >>>>> any systematic way ... perhaps because there is no way to address it >> >>>>> systematically? Contrary views and corrections -- especially >> >>>>> references! -- would be very welcome. >> >>>>> >> >>>>> My advice would be: graphics! -- but I can't provide anything more >> >>>>> useful without the specifics of the problem. >> >>>>> >> >>>>> Some packages may provide the interactivity you seek -- check the >> CRAN >> >>>>> GUI task view, R Commander, etc. >> >>>>> >> >>>>> -- Bert >> >>>>> >> >>>>> On Mon, Dec 5, 2011 at 5:01 PM, Michael >> >> wrote: >> >>>>>> head, tail and fix commands don't really work well if I have large >> >>>>>> matrix/array for which I would like to be able to scroll up and dow, >> >>>>>> left >> >>>>>> and right ... >> >>>>>> >> >>>>>> Could anybody please help me? >> >>>>>> >> >>>>>> Thanks >> >>>>>> >> >>>>>> ? ? ? [[alternative HTML version deleted]] >> >>>>>> >> >>>>>> ______________________________________________ >> >>>>>> R-help at r-project.org mailing list >> >>>>>> https://stat.ethz.ch/mailman/listinfo/r-help >> >>>>>> PLEASE do read the posting guide >> >>>>>> http://www.R-project.org/posting-guide.html >> >> >>>>>> and provide commented, minimal, self-contained, reproducible code. >> >>>>> >> >>>>> >> >>>>> >> >>>>> -- >> >>>>> >> >>>>> Bert Gunter >> >>>>> Genentech Nonclinical Biostatistics >> >>>>> >> >>>>> Internal Contact Info: >> >>>>> Phone: 467-7374 >> >>>>> Website: >> >>>>> >> >>>>> >> >> >> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm >> >>>>> >> >>>>> ______________________________________________ >> >>>>> R-help at r-project.org mailing list >> >>>>> https://stat.ethz.ch/mailman/listinfo/r-help >> >>>>> PLEASE do read the posting guide >> >>>>> http://www.R-project.org/posting-guide.html >> >> >>>>> and provide commented, minimal, self-contained, reproducible code. >> >>>> >> >>>> >> >>>> >> >>>> -- >> >>>> Jim Holtman >> >>>> Data Munger Guru >> >>>> >> >>>> What is the problem that you are trying to solve? >> >>>> Tell me what you want to do, not how you want to do it. >> >>> >> >>> >> >> >> >> >> >> >> >> -- >> >> Jim Holtman >> >> Data Munger Guru >> >> >> >> What is the problem that you are trying to solve? >> >> Tell me what you want to do, not how you want to do it. >> >> >> > >> ?> ? ?[[alternative HTML version deleted]] >> > >> > ______________________________________________ >> > R-help at r-project.org mailing list >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code. >> > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail From r.m.krug at gmail.com Tue Dec 6 09:24:55 2011 From: r.m.krug at gmail.com (Rainer M Krug) Date: Tue, 06 Dec 2011 09:24:55 +0100 Subject: [R] spatial analysis In-Reply-To: <4EDD78AF.9030106@xtra.co.nz> References: <4EDD78AF.9030106@xtra.co.nz> Message-ID: <4EDDD157.9090508@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 06/12/11 03:06, Rolf Turner wrote: > On 06/12/11 01:44, Marianne.ZEYRINGER at ec.europa.eu wrote: >> Dear all, >> >> I am a PhD student in energy modelling. I am completely stuck >> with the following problem and would be very grateful for any >> kind of help. I have cells > Don't we all? We're made of them. :-) > > What do you mean by ``I have''? I.e. be a bit more explicit about > the nature of your data. >> and each cell is assigned a number. I would like to form clusters >> of cells where the sum of the cell numbers in each cluster must >> not exceed 250. One restriction is that only neighbouring cells > Define "neighbouring". >> can be formed into clusters. In the end I would like to have a >> list with all possible cell combinations. > Do you mean all possible ways in which your ``collection of > cells'' can be subdivided into such clusters? My guess is that the > number of such ways could be extremely large. (Depending of course > on how many cells there are in the collection.) >> Is it possible to do this with R If yes, I would very much >> appreciate all possible hints how to solve it. > Install the "fortunes" package. Then type > > fortune("Yoda") > > But if you want useful help you'll have to make your question much > clearer. Agreed - but as it is a spatial question, you should post it at r-sig-geo at r-project.org, the list of the special interest group spatial analysis. I would also look into e.g. GRASS and SAGA, which might be faster with these kind of spatial calculations. In general, if I understand you correctly, you can start with each cell and then "grow outwards" until you hit your stop criteria (sum <= 250), and then you should have your clusters: one solution per starting cell (assuming symmetric clusters - if the clusters can be a-symmetric, many many more). Cheers, Rainer > > cheers, > > Rolf Turner > > ______________________________________________ R-help at r-project.org > mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do > read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 59 98 Fax : +33 - (0)9 58 10 27 44 Fax (D): +49 - (0)3 21 21 25 22 44 email: Rainer at krugs.de Skype: RMkrug -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk7d0VYACgkQoYgNqgF2egqOsACfc6CKV1tY/0xbxR41AfwoBMtA bWsAnRivgAdiuF3MKErvl1l8I+twrOf+ =k9v+ -----END PGP SIGNATURE----- From pomchip at free.fr Tue Dec 6 09:29:03 2011 From: pomchip at free.fr (=?ISO-8859-1?Q?S=E9bastien_Bihorel?=) Date: Tue, 6 Dec 2011 03:29:03 -0500 Subject: [R] How to automate the detection of break points for use in cut Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From pomchip at free.fr Tue Dec 6 09:34:54 2011 From: pomchip at free.fr (=?ISO-8859-1?Q?S=E9bastien_Bihorel?=) Date: Tue, 6 Dec 2011 03:34:54 -0500 Subject: [R] How to automate the detection of break points for use in cut In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From agnieszka.e.konopka at gmail.com Tue Dec 6 10:53:29 2011 From: agnieszka.e.konopka at gmail.com (Agnieszka Konopka) Date: Tue, 6 Dec 2011 10:53:29 +0100 Subject: [R] factors with multiple levels Message-ID: Hi R-experts, I'm running into some trouble with a multi-level factor. My apologies if this is a basic question, but I have been told there are different ways to do this and would like to see what you think. In the dataset I'm looking at, subjects named pictures multiple times (e.g., they named each picture 8 times), so Repetition is a multi-level factor. How would you enter it into a model? As a factor? Or a numeric predictor? I understand the pros and cons of both approaches, but there seems to be some debate about this. I am not interested in the individual contrasts between different levels of the Repetition factor, but only need the equivalent of an F value in a standard ANOVA for that factor. And what about dependencies between levels? Many thanks in advance, Agnieszka From nalimilan at club.fr Tue Dec 6 11:03:27 2011 From: nalimilan at club.fr (Milan Bouchet-Valat) Date: Tue, 6 Dec 2011 11:03:27 +0100 Subject: [R] how to view/edit large matrix/array in R? In-Reply-To: References: Message-ID: <1323165808.17508.24.camel@milan> Le lundi 05 d?cembre 2011 ? 19:01 -0600, Michael a ?crit : > head, tail and fix commands don't really work well if I have large > matrix/array for which I would like to be able to scroll up and dow, left > and right ... > > Could anybody please help me? RKWard has a good data editor, and you can open several objects at the same time in tabs. But it will not probably work if your data set is really huge (here it works very well with a few thousand rows, though). If you need to see a selection of variables in parallel, ordering the variables so that they're next to each other is probably a good solution. Cheers From JRadinger at gmx.at Tue Dec 6 12:41:45 2011 From: JRadinger at gmx.at (Johannes Radinger) Date: Tue, 06 Dec 2011 12:41:45 +0100 Subject: [R] Argument validation within functions Message-ID: <20111206114145.143490@gmx.net> Hi, I just started with writing functions in R and so some questions popped up. I provide some values as argument to my function such as: function(a,b,c){} Now i want that the function first checks if the arguments are valid for the function. E.g argument "a" has to be a number in the range 0-1. How can that easily done? So far I have: a <- as.numeric(a) if(0 <= a && a <= 1) to first check if a is a number...if not the function stops and gives an error message. If it is a number it just continues... But how to check the range? Above there is the if-approach but then the rest of the function is exectued as part of if (or else). Is there a simpler way without having the if-brackets around the remaining code? Just a check if the value is between 0 and 1 and if yes continue with the next line if no abort the function with a error message? How can such an error message be created? thank you and best regards, /Johannes -- From michael.weylandt at gmail.com Tue Dec 6 12:52:49 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Tue, 6 Dec 2011 06:52:49 -0500 Subject: [R] Problem in while loop In-Reply-To: References: <7DEC6BA8-EBF6-4F11-930E-4BBBA8340D47@gmail.com> Message-ID: So I just ran your code verbatim with this one change and it finished in less than 10 seconds. However, even without the change it doesn't take more than 15 seconds: what exactly lead you to believe this was an infinite loop? Michael On Tue, Dec 6, 2011 at 12:03 AM, R. Michael Weylandt wrote: > Off the bat I'd suggest you vectorize loglikelihood as a simple one liner: > > sum(log(b^2 + (x-a)^2)) > > That alone will speed up your function many times over: I'll look at the big > function in more detail tomorrow. > > Michael > > On Dec 5, 2011, at 10:37 PM, Gyanendra Pokharel > wrote: > > Thanks Michael > Lets figure out the problem by using the following function. I found the > same problem in this code too. > > > loglikehood <- function(a, b = 0.1, x = c(-4.2, -2.85, -2.3, -1.02, 0.7, > 0.98, 2.72, 3.5)) > > { > > s <- 0 > > for(i in 1:length(x)){ > > s <- s + log(b^2 + (x[i] - a)^2) > > } > > s > > } > > loglikelihood(0.1) > > simann <- function(T0 = 1, N = 500, rho = 0.9, x0 = 0, eps = 0.1, f){ > > moving <- 1 > > count <- 0 > > Temp <- T0 > > x <- x0 > > while(moving > 0){ > > moving <- 0 > > for(i in 1:N){ > > y <- x + runif(1,-eps,eps) > > alpha <- min(1,exp((f(x) -f(y))/Temp)) > > if(runif(1) > moving <- moving +1 > > x <- y > > } > > } > > Temp <- Temp*rho > > count <- count + 1 > > } > > fmin <- f(x) > > return(c(x,fmin,count)) > > } > > simann(f = loglikelihood) > > I hope we can analyze every problems from this function > > On Mon, Dec 5, 2011 at 10:27 PM, R. Michael Weylandt > wrote: >> >> It's not necessarily equivalent to your "loglikelihood" function but since >> that function wasn't provided I couldn't test it. >> >> My broader point is this: you said the problem was that the loop ran >> endlessly: I showed it does not run endlessly for at least one input so at >> least part of the problem lies in loglikelihood, which, being unprovided, I >> have trouble replicating. >> >> My original guess still stands: it's either 1) a case of you getting stuck >> at probaccept = 1 or 2) so slow it just feels endless. ?Either way, my >> prescription is the same: print() >> >> Michael >> >> >> On Dec 5, 2011, at 9:30 PM, Gyanendra Pokharel >> wrote: >> >> Yes, your function out<- epiann(f = function(a,b) log(dnorm(a)*dnorm(b))), >> N = 10) works well. >> >> But?why you are changing the loglikelihood function to f = function(a,b) >> log(dnorm(a)*dnorm(b))? how it is equivalent to loglikelihood? is there any >> mathematical relation? ?I also want to see the plot of aout and bout versus >> loglikelihood, and see the cooling rate in different temperature. how is >> this possible? >> >> On Mon, Dec 5, 2011 at 6:07 PM, R. Michael Weylandt >> wrote: >>> >>> If you run >>> >>> out<- epiann(f = function(a,b) log(dnorm(a)*dnorm(b))), N = 10) >>> >>> It takes less than 0.5 seconds so there's no problem I can see: >>> perhaps you want to look elsewhere to get better speed (like Rcpp or >>> general vectorization), or maybe your loglikihood is not what's >>> desired, but there's no problem with the loop. >>> >>> Michael >>> >>> On Mon, Dec 5, 2011 at 5:29 PM, Gyanendra Pokharel >>> wrote: >>> > Yes, I checked the acceptprob, it is very high but in my view, the >>> > while >>> > loop is not stopping, so there is some thing wrong in the use of while >>> > loop. >>> > When I removed the while loop, it returned some thing but not the >>> > result >>> > what I want. When i run the while loop separately, it never stops. >>> > >>> > >>> > >>> > On Mon, Dec 5, 2011 at 5:18 PM, R. Michael Weylandt >>> > wrote: >>> >> >>> >> Your code is not reproducible nor minimal, but why don't you put a >>> >> command print(acceptprob) in and see if you are getting reasonable >>> >> values. If these values are extremely low it shouldn't surprise you >>> >> that your loop takes a long time to run. >>> >> >>> >> More generally, read up on the use of print() and browser() as >>> >> debugging >>> >> tools. >>> >> >>> >> Michael >>> >> >>> >> On Mon, Dec 5, 2011 at 3:47 PM, Gyanendra Pokharel >>> >> wrote: >>> >> > I forgot to upload the R-code in last email, so heare is one >>> >> > >>> >> > epiann <- function(T0 = 1, N=1000, ainit=1, binit=1,rho = 0.99, >>> >> > amean = >>> >> > 3, >>> >> > bmean=1.6, avar =.1, bvar=.1, f){ >>> >> > >>> >> > ? ? ? ?moving <- 1 >>> >> > ? ? ? ?count <- 0 >>> >> > ? ? ? ?Temp <- T0 >>> >> > ? ? ? ?aout <- ainit >>> >> > ? ? ? ?bout <- binit >>> >> > ? ? ? ?while(moving > 0){ >>> >> > ? ? ? ? ? ? ? ?moving <- 0 >>> >> > ? ? ? ? ? ? ? ?for (i in 1:N) { >>> >> > ? ? ? ? ? ? ? ?aprop <- rnorm (1,amean, avar) >>> >> > ? ? ? ? ? ? ? ?bprop <- rnorm (1,bmean, bvar) >>> >> > ? ? ? ? ? ? ? ?if (aprop > 0 & bprop > 0){ >>> >> > ? ? ? ? ? ? ? ?acceptprob <- min(1,exp((f(aout, bout) - >>> >> > f(aprop,bprop))/Temp)) >>> >> > ? ? ? ? ? ? ? ?u <- runif(1) >>> >> > ? ? ? ? ? ? ? ?if(u>> >> > ? ? ? ? ? ? ? ? ? ?moving <- moving +1 >>> >> > ? ? ? ? ? ? ? ? ? ?aout <- aprop >>> >> > ? ? ? ? ? ? ? ? ? ?bout <- bprop >>> >> > ? ? ? ? ? ? ? ? ? ?} >>> >> > ? ? ? ? ? ? ? ? ? ?else{aprob <- aout >>> >> > ? ? ? ? ? ? ? ? ? ? ? ?bprob <- bout} >>> >> > ? ? ? ? ? ? ? ?} >>> >> > ? ? ? ? ? ?} >>> >> > ? ? ? ?Temp <- Temp*rho >>> >> > ? ? ? ? ? ?count <- count +1 >>> >> > >>> >> > ? ?} >>> >> > ? ?fmin <- f(aout,bout) >>> >> > ? ?return(c(aout, bout,fmin, count) ) >>> >> > >>> >> > } >>> >> > out<- epiann(f = loglikelihood) >>> >> > >>> >> > On Mon, Dec 5, 2011 at 3:46 PM, Gyanendra Pokharel < >>> >> > gyanendra.pokharel at gmail.com> wrote: >>> >> > >>> >> >> Hi all, >>> >> >> I have the following code, >>> >> >> When I run the code, it never terminate this is because of the >>> >> >> while >>> >> >> loop >>> >> >> i am using. In general, if you need a loop for which you don't know >>> >> >> in >>> >> >> advance how many iterations there will be, you can use the `while' >>> >> >> statement so here too i don't know the number how many iterations >>> >> >> are >>> >> >> there. So Can some one suggest me whats going on? >>> >> >> I am using the Metropolis simulated annealing algorithm >>> >> >> Best >>> >> >> >>> >> > >>> >> > ? ? ? ?[[alternative HTML version deleted]] >>> >> > >>> >> > ______________________________________________ >>> >> > R-help at r-project.org mailing list >>> >> > https://stat.ethz.ch/mailman/listinfo/r-help >>> >> > PLEASE do read the posting guide >>> >> > http://www.R-project.org/posting-guide.html >>> >> > and provide commented, minimal, self-contained, reproducible code. >>> > >>> > >> >> > From michael.weylandt at gmail.com Tue Dec 6 13:04:59 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Tue, 6 Dec 2011 07:04:59 -0500 Subject: [R] Argument validation within functions In-Reply-To: <20111206114145.143490@gmx.net> References: <20111206114145.143490@gmx.net> Message-ID: The quick and dirty way to do so is to use: stopifnot() in conjunction (if necessary with all() and any()). You can replace that first condition with a simple is.numeric() as well. A more helpful way (if this is production code) is to use if statement with the stop() function directly which lets you provide specific error messages. Michael On Tue, Dec 6, 2011 at 6:41 AM, Johannes Radinger wrote: > Hi, > > I just started with writing functions in R and so some questions popped up. > I provide some values as argument to my function such as: > > function(a,b,c){} > > Now i want that the function first checks if the arguments are valid for the function. E.g argument "a" has to be a number in the range 0-1. How can that easily done? > > So far I have: > > ? ? ? ?a <- as.numeric(a) > ? ? ? ?if(0 <= a && a <= 1) > > to first check if a is a number...if not the function stops and gives an error message. If it is a number it just continues... > > But how to check the range? > Above there is the if-approach but then the rest of the function is exectued as part of if (or else). Is there a simpler way without having the if-brackets around the remaining code? > Just a check if the value is between 0 and 1 and if yes continue with the next line if no abort the function with a error message? How can such an error message be created? > > thank you and best regards, > > /Johannes > -- > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From michael.weylandt at gmail.com Tue Dec 6 13:12:04 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Tue, 6 Dec 2011 07:12:04 -0500 Subject: [R] a question on autocorrelation acf In-Reply-To: <1323135157369-4163021.post@n4.nabble.com> References: <4BDA115C.9040504@gmail.com> <1323113081359-4161818.post@n4.nabble.com> <1323135157369-4163021.post@n4.nabble.com> Message-ID: The code provided was the hard-to-find C part: there's also some R code involved that you can get in your console by typing acf without parentheses. I'm inclined to believe V&R over any Excel implementation (and I don't know what "pc" is) but perhaps you can provide a (small) data-set using the dput() function and say what you are expecting to get from acf() instead. Michael On Mon, Dec 5, 2011 at 8:32 PM, Bazman76 wrote: > Hi there, > > I have now cheked the results against pc give and the excel add-in poptools. > > Poptools and pc give get the same answer but R is quite different especially > for the acf and pacf()? > > I looked at the book you recommended on p390 itshows the formulas and they > look pretty standard. > > However looking at the code that you sent the acf function does not seem to > be being calculated as shown in the book? > > At no point is the series mean calculated? unless the variable x is already > demeaned in some way ie. there is some preprocessing that I need to see to > fully understand? > > > > -- > View this message in context: http://r.789695.n4.nabble.com/a-question-on-autocorrelation-acf-tp2076280p4163021.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From michael.weylandt at gmail.com Tue Dec 6 13:17:48 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Tue, 6 Dec 2011 07:17:48 -0500 Subject: [R] rugarch package: is this forecast correct? In-Reply-To: References: Message-ID: The calculation is numerically stable on my machine: I'd mark it up as computational/floating-point error and not worry about it. Michael On Mon, Dec 5, 2011 at 11:13 PM, Ivan Popivanov wrote: > Let me start with the code: > > library(quantmod) > library(rugarch) > getSymbols("SPY", from="1900-01-01") > rets=na.trim(diff(log(Cl(SPY)))) > tt = tail(rets["/2004-10-29"], 1000) > spec = ugarchspec(variance.model=list(garchOrder=c(1,1)), > mean.model=list(armaOrder=c(2,5)), distribution.model="sged") > for(ii in 1:10) > { > ? ttFit = ugarchfit( spec=spec, data=as.vector(tt), out.sample=0, > solver.control=list(trace=F) ) > ? ttFore = ugarchforecast( ttFit, n.ahead=1, n.roll=0 ) > ? print( as.array(ttFore)[,2,] ) > } > > Produces two different results: -0.001087313 and -0.001092084, each > repeated a few times. > > What is the explanation for that? Since they are based on previous data, I > was expecting single step forecasts to produce the same result. > > Thanks in advance! > Ivan > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From pomchip at free.fr Tue Dec 6 13:19:05 2011 From: pomchip at free.fr (=?ISO-8859-1?Q?S=E9bastien_Bihorel?=) Date: Tue, 6 Dec 2011 07:19:05 -0500 Subject: [R] Argument validation within functions Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From murdoch.duncan at gmail.com Tue Dec 6 13:22:06 2011 From: murdoch.duncan at gmail.com (Duncan Murdoch) Date: Tue, 6 Dec 2011 07:22:06 -0500 Subject: [R] help! what's wrong with setBreakpoint In-Reply-To: References: Message-ID: <4EDE08EE.6040407@gmail.com> On 11-12-05 10:32 PM, Michael wrote: > Hi all, > > I am in the middle of debugging which is stopped using "browser()"... in > myfile.R at around line #25. > > I was then stuck in a big loop which I want to escape and stop the program > at the line after the big loop. > > In the debugging mode, I used > > Browse[2]> setBreakpoint("myfile.R#38") What did it print? > > I then typed "c" and "ENTER", thinking that it will continue to execute > until when it comes across line #38 and then stop there... > > But it didn't work - it continued the execution until the end of the > function, right at the line "return(results)"... > > What happened? How to solve this problem? One of the complications in R is that you can have multiple copies of a function in memory. You may (or may not, what did it print??) have set a breakpoint in one copy, then run another. Or you may have edited that function after originally sourcing it, and lost the source reference. An alternative to using setBreakpoint is just to edit a call to browser() into the function. It's less convenient, but more robust. Duncan Murdoch > Thanks a lot! > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From murdoch.duncan at gmail.com Tue Dec 6 13:28:53 2011 From: murdoch.duncan at gmail.com (Duncan Murdoch) Date: Tue, 6 Dec 2011 07:28:53 -0500 Subject: [R] How to automate the detection of break points for use in cut In-Reply-To: References: Message-ID: <4EDE0A85.7070904@gmail.com> On 11-12-06 3:34 AM, S?bastien Bihorel wrote: > Obviously, cut would do the job if one knows the number of intervals in > advance, which I assume I won't. I guess what I'm looking for is a function > that figures out the number of intervals and their boundaries. That's not really a simple problem, but there are functions that do clustering and fit mixture models to data, which might be close enough. See the Cluster task view at http://cran.r-project.org/web/views/Cluster.html. Duncan Murdoch > > Sebastien > > On Tue, Dec 6, 2011 at 3:29 AM, S?bastien Bihorel wrote: > >> Dear R-users, >> >> I would like to know if there is a function (in base R or the extension >> packages) that would automatically detect the break points in a vector x >> for later use in the cut function. The idea is to determine the boundaries >> of the n intervals (n>=1) delimiting clusters of data points which could be >> considered "reasonably" close, given a numerical vector x with unknown >> content and unknown multimodal distribution. >> >> For instance, given for the vector x defined by set.seed(1234); x<- >> sort(c(rnorm(20,-1,0.1),rnorm( >> 10,5,0.1),rnorm(10,100,0.1))), this function would return a vector of 4 >> points: min(x), one value between 20 and 5, one value between 5 and 100, >> and max(x). >> >> Thank you in advance for your suggestions. >> >> Sebastien >> > > [[alternative HTML version deleted]] > > > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From JRadinger at gmx.at Tue Dec 6 13:46:14 2011 From: JRadinger at gmx.at (Johannes Radinger) Date: Tue, 06 Dec 2011 13:46:14 +0100 Subject: [R] Argument validation within functions In-Reply-To: References: <20111206114145.143490@gmx.net> Message-ID: <20111206124614.162280@gmx.net> Hi, thank you... I think I will go for the if-stop approach as the stop() stops the total function... So there is just one little other question: What is the opposite of is.numeric? Is ther isnot.numeric? How can that be implemented in following function: f <- function(a){ if(is.numeric(a)) stop("a is not numeric") if(0 > a && a > 1) stop("a must be a value between 0 and 1") a } /Johannes -------- Original-Nachricht -------- > Datum: Tue, 6 Dec 2011 07:04:59 -0500 > Von: "R. Michael Weylandt" > An: Johannes Radinger > CC: r-help at r-project.org > Betreff: Re: [R] Argument validation within functions > The quick and dirty way to do so is to use: stopifnot() in conjunction > (if necessary with all() and any()). You can replace that first > condition with a simple is.numeric() as well. A more helpful way (if > this is production code) is to use if statement with the stop() > function directly which lets you provide specific error messages. > > Michael > > On Tue, Dec 6, 2011 at 6:41 AM, Johannes Radinger > wrote: > > Hi, > > > > I just started with writing functions in R and so some questions popped > up. > > I provide some values as argument to my function such as: > > > > function(a,b,c){} > > > > Now i want that the function first checks if the arguments are valid for > the function. E.g argument "a" has to be a number in the range 0-1. How > can that easily done? > > > > So far I have: > > > > ? ? ? ?a <- as.numeric(a) > > ? ? ? ?if(0 <= a && a <= 1) > > > > to first check if a is a number...if not the function stops and gives an > error message. If it is a number it just continues... > > > > But how to check the range? > > Above there is the if-approach but then the rest of the function is > exectued as part of if (or else). Is there a simpler way without having the > if-brackets around the remaining code? > > Just a check if the value is between 0 and 1 and if yes continue with > the next line if no abort the function with a error message? How can such an > error message be created? > > > > thank you and best regards, > > > > /Johannes > > -- > > > > ______________________________________________ > > R-help at r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. -- From stan.gaj at maastrichtuniversity.nl Tue Dec 6 13:53:02 2011 From: stan.gaj at maastrichtuniversity.nl (Gaj Stan (BIGCAT)) Date: Tue, 6 Dec 2011 13:53:02 +0100 Subject: [R] Paste() - Get all possible combinations from multiple vectors Message-ID: <2D1C3C74C8DE6C48B602E679AB37211C0AA947527E@UM-MAIL4112.unimaas.nl> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From ligges at statistik.tu-dortmund.de Tue Dec 6 13:57:43 2011 From: ligges at statistik.tu-dortmund.de (Uwe Ligges) Date: Tue, 06 Dec 2011 13:57:43 +0100 Subject: [R] Argument validation within functions In-Reply-To: <20111206124614.162280@gmx.net> References: <20111206114145.143490@gmx.net> <20111206124614.162280@gmx.net> Message-ID: <4EDE1147.2060203@statistik.tu-dortmund.de> On 06.12.2011 13:46, Johannes Radinger wrote: > Hi, > > thank you... I think I will go for the if-stop approach > as the stop() stops the total function... So there is just > one little other question: What is the opposite of is.numeric? > Is ther isnot.numeric? Yes, see: ?"!" Uwe Ligges > How can that be implemented in following function: > > f<- function(a){ > if(is.numeric(a)) stop("a is not numeric") > if(0> a&& a> 1) stop("a must be a value between 0 and 1") > a > } > > /Johannes > > -------- Original-Nachricht -------- >> Datum: Tue, 6 Dec 2011 07:04:59 -0500 >> Von: "R. Michael Weylandt" >> An: Johannes Radinger >> CC: r-help at r-project.org >> Betreff: Re: [R] Argument validation within functions > >> The quick and dirty way to do so is to use: stopifnot() in conjunction >> (if necessary with all() and any()). You can replace that first >> condition with a simple is.numeric() as well. A more helpful way (if >> this is production code) is to use if statement with the stop() >> function directly which lets you provide specific error messages. >> >> Michael >> >> On Tue, Dec 6, 2011 at 6:41 AM, Johannes Radinger >> wrote: >>> Hi, >>> >>> I just started with writing functions in R and so some questions popped >> up. >>> I provide some values as argument to my function such as: >>> >>> function(a,b,c){} >>> >>> Now i want that the function first checks if the arguments are valid for >> the function. E.g argument "a" has to be a number in the range 0-1. How >> can that easily done? >>> >>> So far I have: >>> >>> a<- as.numeric(a) >>> if(0<= a&& a<= 1) >>> >>> to first check if a is a number...if not the function stops and gives an >> error message. If it is a number it just continues... >>> >>> But how to check the range? >>> Above there is the if-approach but then the rest of the function is >> exectued as part of if (or else). Is there a simpler way without having the >> if-brackets around the remaining code? >>> Just a check if the value is between 0 and 1 and if yes continue with >> the next line if no abort the function with a error message? How can such an >> error message be created? >>> >>> thank you and best regards, >>> >>> /Johannes >>> -- >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. > > -- > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From michael.weylandt at gmail.com Tue Dec 6 13:57:44 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Tue, 6 Dec 2011 07:57:44 -0500 Subject: [R] Argument validation within functions In-Reply-To: References: <20111206114145.143490@gmx.net> <20111206124614.162280@gmx.net> Message-ID: Use the ! (not) operator. Not sure what you mean by " as the stop() stops the total function": try the following f <- function(a){ ? ?stopifnot(a > 3) ? ?return(a^2) } f(2) f(4) Michael (PS -- It's usually asked to cc the list so that this all gets threaded properly in folks' mailboxes) On Tue, Dec 6, 2011 at 7:46 AM, Johannes Radinger wrote: > Hi, > > thank you... I think I will go for the if-stop approach > as the stop() stops the total function... So there is just > one little other question: What is the opposite of is.numeric? > Is ther isnot.numeric? How ?can that be implemented in following > function: > > f <- function(a){ > ? ? ? ?if(is.numeric(a)) stop("a is not numeric") > ? ? ? ?if(0 > a && a > 1) stop("a must be a value between 0 and 1") > ? ? ? ?a > } > > /Johannes > > -------- Original-Nachricht -------- >> Datum: Tue, 6 Dec 2011 07:04:59 -0500 >> Von: "R. Michael Weylandt" >> An: Johannes Radinger >> CC: r-help at r-project.org >> Betreff: Re: [R] Argument validation within functions > >> The quick and dirty way to do so is to use: stopifnot() in conjunction >> (if necessary with all() and any()). You can replace that first >> condition with a simple is.numeric() as well. A more helpful way (if >> this is production code) is to use if statement with the stop() >> function directly which lets you provide specific error messages. >> >> Michael >> >> On Tue, Dec 6, 2011 at 6:41 AM, Johannes Radinger >> wrote: >> > Hi, >> > >> > I just started with writing functions in R and so some questions popped >> up. >> > I provide some values as argument to my function such as: >> > >> > function(a,b,c){} >> > >> > Now i want that the function first checks if the arguments are valid for >> the function. E.g argument "a" has to be a number in the range 0-1. How >> can that easily done? >> > >> > So far I have: >> > >> > ? ? ? ?a <- as.numeric(a) >> > ? ? ? ?if(0 <= a && a <= 1) >> > >> > to first check if a is a number...if not the function stops and gives an >> error message. If it is a number it just continues... >> > >> > But how to check the range? >> > Above there is the if-approach but then the rest of the function is >> exectued as part of if (or else). Is there a simpler way without having the >> if-brackets around the remaining code? >> > Just a check if the value is between 0 and 1 and if yes continue with >> the next line if no abort the function with a error message? How can such an >> error message be created? >> > >> > thank you and best regards, >> > >> > /Johannes >> > -- >> > >> > ______________________________________________ >> > R-help at r-project.org mailing list >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code. > > -- > NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zur?ck-Garantie! > Jetzt informieren: http://www.gmx.net/de/go/freephone From michael.weylandt at gmail.com Tue Dec 6 13:58:27 2011 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Tue, 6 Dec 2011 07:58:27 -0500 Subject: [R] Paste() - Get all possible combinations from multiple vectors In-Reply-To: <2D1C3C74C8DE6C48B602E679AB37211C0AA947527E@UM-MAIL4112.unimaas.nl> References: <2D1C3C74C8DE6C48B602E679AB37211C0AA947527E@UM-MAIL4112.unimaas.nl> Message-ID: outer(outer(x, y, paste), z, paste) Michael On Tue, Dec 6, 2011 at 7:53 AM, Gaj Stan (BIGCAT) wrote: > Hello fellow R-users, > > Given are three vectors and the outcome would be all possible combinations in combination with the paste() function. > For example: > > x <- c(1:3) > y <- letters[1:3] > z <- LETTERS[1:3] > > My result would thus be 18 names based on all possible combinations between these vectors: > "1 a A" "1 a B", "1 a C", "1 b A", "1 b B", "1 b C", "1 c A", "1 c B", "1 c C", etc. > > To solve the issue above I would use: > > paste(rep(x, each=9), rep(y, each=6), z) > > This is a very straightforward example, but when I have vectors of different sizes, it will be much more difficult (for me) to create this. Is there an easier way to do this? > > Many thanks in advance, > > ?-- Stan > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From ligges at statistik.tu-dortmund.de Tue Dec 6 14:01:26 2011 From: ligges at statistik.tu-dortmund.de (Uwe Ligges) Date: Tue, 6 Dec 2011 14:01:26 +0100 Subject: [R] Can't load package 'lars' In-Reply-To: <4EDD7EDE.6090809@mail.mcgill.ca> References: <4EDD7EDE.6090809@mail.mcgill.ca> Message-ID: <4EDE1226.1010708@statistik.tu-dortmund.de> On 06.12.2011 03:33, Luc Villandre wrote: > Hi, > > I installed package 'lars' earlier tonight and did not get any sort of > error message. > > ### > ** building package indices ... > ** testing if installed package can be loaded > Loaded lars 0.9-8 > > * DONE (lars) > ### > > However, when I try to load it, I get > ### > > library(lars, lib.loc = "~/R/x86_64-redhat-linux-gnu-library/2.11") Are you sure it is installed at the location you specified? Uwe Ligges > Error : .onLoad failed in loadNamespace() for 'lars', details: > call: cat("Loaded lars", utils::installed.packages()["lars", "Version"], > error: subscript out of bounds > Error: package/namespace load failed for ?lars? > ### > > Session info: > > ### > > sessionInfo() > R version 2.14.0 (2011-10-31) > Platform: x86_64-redhat-linux-gnu (64-bit) > > locale: > [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C > [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 > [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 > [7] LC_PAPER=C LC_NAME=C > [9] LC_ADDRESS=C LC_TELEPHONE=C > [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > loaded via a namespace (and not attached): > [1] rpart_3.1-50 tools_2.14.0 > ### > > I get the same error message when I try to load it on another machine: > > ### > > > library("lars",lib.loc = "~/R/i686-pc-linux-gnu-library/2.12") > Error : .onLoad failed in loadNamespace() for 'lars', details: > call: cat("Loaded lars", utils::installed.packages()["lars", "Version"], > error: subscript out of bounds > Error: package/namespace load failed for 'lars' > ### > > Session info: > > ### > > sessionInfo() > R version 2.13.1 (2011-07-08) > Platform: i686-pc-linux-gnu (32-bit) > > locale: > [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C > [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 > [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 > [7] LC_PAPER=en_US.UTF-8 LC_NAME=C > [9] LC_ADDRESS=C LC_TELEPHONE=C > [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > loaded via a namespace (and not attached): > [1] tools_2.13.1 > ### > > Is there at least a way to circumvent the problem? > > Thank you for your help, > > Luc Villandre > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From djandrija at gmail.com Tue Dec 6 14:01:20 2011 From: djandrija at gmail.com (andrija djurovic) Date: Tue, 6 Dec 2011 14:01:20 +0100 Subject: [R] Paste() - Get all possible combinations from multiple vectors In-Reply-To: <2D1C3C74C8DE6C48B602E679AB37211C0AA947527E@UM-MAIL4112.unimaas.nl> References: <2D1C3C74C8DE6C48B602E679AB37211C0AA947527E@UM-MAIL4112.unimaas.nl> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From haenlein at escpeurope.eu Tue Dec 6 14:08:34 2011 From: haenlein at escpeurope.eu (Michael Haenlein) Date: Tue, 6 Dec 2011 14:08:34 +0100 Subject: [R] Regression model when dependent variable can only take positive values Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From ligges at statistik.tu-dortmund.de Tue Dec 6 14:15:08 2011 From: ligges at statistik.tu-dortmund.de (Uwe Ligges) Date: Tue, 06 Dec 2011 14:15:08 +0100 Subject: [R] Summary coefficients give NA values because of singularities In-Reply-To: <1323118654603-4162113.post@n4.nabble.com> References: <1323118654603-4162113.post@n4.nabble.com> Message-ID: <4EDE155C.7060100@statistik.tu-dortmund.de> On 05.12.2011 21:57, Gathurst wrote: > Hello, > > I have a data set which I am using to find a model with the most significant > parameters included and most importantly, the p-values. The full model is > of the form: > sad[,1]~b_1 sad[,2]+b_2 sad[,3]+b_3 sad[,4]+b_4 sad[,5]+b_5 sad[,6]+b_6 > sad[,7]+b_7 sad[,8]+b_8 sad[,9]+b_9 sad[,10], > where the 9 variables on the right hand side are all indicator variables. > The thing I don't understand is the line ' sad[, 10] NA NA > NA NA ' as a result of 'Coefficients: (1 not defined because of > singularities)'. > > I think the output is taking sad[,10] as the intercept, based on previous > attempts at figuring my issue out, which I find a bit wierd considering > sad[,10] is either 0 or 1. How do I produce the correct output showing all > p-values? You cannot: sad[,10] is either collinear to one or more of the other variables or is constant. Uwe Ligges > > My code and output is as follows: > > sad<-matrix(1,ncol=11,nrow=486) > sad[,c(1:10)]<-d[,2][-357] > sad[,1]<-d[,29][-357] > sad[,2][sad[,2]!=1]<-0 > sad[,3][sad[,3]!=2]<-0 > sad[,4][sad[,4]!=3]<-0 > sad[,5][sad[,5]!=4]<-0 > sad[,6][sad[,6]!=5]<-0 > sad[,7][sad[,7]!=6]<-0 > sad[,8][sad[,8]!=7]<-0 > sad[,9][sad[,9]!=8]<-0 > sad[,10][sad[,10]!=9]<-0 > sad[,2][sad[,2]==1]<-1 > sad[,3][sad[,3]==2]<-1 > sad[,4][sad[,4]==3]<-1 > sad[,5][sad[,5]==4]<-1 > sad[,6][sad[,6]==5]<-1 > sad[,7][sad[,7]==6]<-1 > sad[,8][sad[,8]==7]<-1 > sad[,9][sad[,9]==8]<-1 > sad[,10][sad[,10]==9]<-1 > sad > > summary(lm(sad[,1]~sad[,2]+sad[,3] > +sad[,4]+sad[,5]+sad[,6] > +sad[,7]+sad[,8]+sad[,9]+sad[,10])) > > Call: > lm(formula = sad[, 1] ~ sad[, 2] + sad[, 3] + sad[, 4] + sad[, > 5] + sad[, 6] + sad[, 7] + sad[, 8] + sad[, 9] + sad[, 10]) > > Residuals: > Min 1Q Median 3Q Max > -3.3191 -0.3893 0.0519 0.7436 1.0519 > > Coefficients: (1 not defined because of singularities) > Estimate Std. Error t value Pr(>|t|) > (Intercept) 4.34091 0.14495 29.947<2e-16 *** > sad[, 2] -0.16142 0.18128 -0.890 0.3737 > sad[, 3] -0.23221 0.20275 -1.145 0.2527 > sad[, 4] 0.17832 0.19695 0.905 0.3657 > sad[, 5] 0.06450 0.21447 0.301 0.7638 > sad[, 6] -0.15909 0.18713 -0.850 0.3957 > sad[, 7] -0.39286 0.18171 -2.162 0.0311 * > sad[, 8] -0.08450 0.21146 -0.400 0.6896 > sad[, 9] -0.02176 0.20170 -0.108 0.9141 > sad[, 10] NA NA NA NA > --- > Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > > Residual standard error: 0.9615 on 477 degrees of freedom > Multiple R-squared: 0.02984, Adjusted R-squared: 0.01357 > F-statistic: 1.834 on 8 and 477 DF, p-value: 0.06869 > > Thanks in advance. > > -- > View this message in context: http://r.789695.n4.nabble.com/Summary-coefficients-give-NA-values-because-of-singularities-tp4162113p4162113.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From ligges at statistik.tu-dortmund.de Tue Dec 6 14:19:12 2011 From: ligges at statistik.tu-dortmund.de (Uwe Ligges) Date: Tue, 06 Dec 2011 14:19:12 +0100 Subject: [R] Plot numeric and categorical variable In-Reply-To: <1323123760.89219.YahooMailClassic@web161204.mail.bf1.yahoo.com> References: <1323123760.89219.YahooMailClassic@web161204.mail.bf1.yahoo.com> Message-ID: <4EDE1650.8090601@statistik.tu-dortmund.de> On 05.12.2011 23:22, Juliet Ndukum wrote: > My data consists of numeric (yy) and categorical (xx) variables, as shown below. >> xx = c(rep("C", 5), rep("D",5))> xx [1] "C" "C" "C" "C" "C" "D" "D" "D" "D" "D"> yy = rnorm(10, 0, 4)> yy [1] 2.7219346 -3.7142481 6.8716534 -0.9352463 0.4901249 3.8113247 [7] -2.6602041 1.7714471 4.7298233 0.8848188 >> xx1 = as.integer(as.factor(xx))> plot(xx1, yy, ylim = c(-13.5, 4), col="blue") > I have attached the plot above as plot1 > I wish to generate a scatter plot of the data such that instead of 1 it prints C, and instead of 2, it prints D on the x- axis (see plot1 attached). > How could I possibly go about this, let me know. Any help will be greatly appreciated. > Thanks in advance for your help,JN Sounds like homework?! Anyway, see ?par and ?axis to answer your question directly or ?boxplot more implicitly... Best, Uwe Ligges > > > > > > > > > > > > > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From Thierry.ONKELINX at inbo.be Tue Dec 6 14:15:54 2011 From: Thierry.ONKELINX at inbo.be (ONKELINX, Thierry) Date: Tue, 6 Dec 2011 13:15:54 +0000 Subject: [R] Regression model when dependent variable can only take positive values In-Reply-To: References: Message-ID: Dear Michael, Did you measure newborns? If not center age to a value that makes sense in relation with the range of age in your dataset. Then the intercept will be the height at the reference age. And most likeli non-negative. Best regards, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium Thierry.Onkelinx at inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -----Oorspronkelijk bericht----- Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Namens Michael Haenlein Verzonden: dinsdag 6 december 2011 14:09 Aan: r-help at r-project.org Onderwerp: [R] Regression model when dependent variable can only take positive values Dear all, I would like to run a regression of the form lm(y ~ x1+x2) where the dependent variable y can only take positive values. Assume, for example, that y is the height of a person (measured in cm), x1 is the gender (measured as a binary indicator with 0=male and 1=female) and x2 is the age of the person (measured in years). When I run a simple lm(y ~ x1+x2), I obtain an intercept value that is negative. I interpret that in a way that a person who is male (x1=0) and just born (x2=0), has a negative height. This evidently does not make sense. I therefore assume that my estimates might be biased and that I need to use some other form of estimation that takes account of the fact that y>0 for all observations. Could anybody please tell me which type of regression would be most recommendable for this type of analysis? Thanks very much in advance, Michael [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. From sarah.goslee at gmail.com Tue Dec 6 14:27:26 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Tue, 6 Dec 2011 08:27:26 -0500 Subject: [R] frequency table? In-Reply-To: <1323139200476-4163192.post@n4.nabble.com> References: <1322990509062-4156422.post@n4.nabble.com> <1323139200476-4163192.post@n4.nabble.com> Message-ID: After that, you might consult the source code for distance() in ecodist. That function was specifically written to make it easy for people to add new dissimilarity/similarity metrics, and I think you'll find it helpful (even if you just extract the bit you need rather than expand the whole function). Sarah On Mon, Dec 5, 2011 at 9:40 PM, B77S wrote: > Set, > > This is the same post as your "Similarity Matrix" post. > > I'm not trying to be a smart ass here, but ... ?Can you fit a square peg in > a round hole?... yes, but it doesn't mean it belongs there. > > I suggest you get a piece of paper and a pencil and figure out 1) what you > are trying to do and why, and 2) how you would do that by hand. ?After you > do that, you should be able to figure this out on your own or formulate a > question to post that someone will be able to answer. ?Reading might help as > well. > > > > set wrote >> >> Hello R-users, >> >> I've got a file with individuals as colums and the clusters where they >> occur in as rows. And I wanted a table which tells me how many times each >> individual occurs with another. I don't really know how such a table is >> called...it is not a frequency table....My eventual goal is to make >> Venn-diagrams from the occurence of my individuals. >> >> So I've this: >> >> cluster ? ind1 ind2 ind3 etc. >> 1 ? ? ? ? ? ?0 ? ? ?1 ? ? 2 >> 2 ? ? ? ? ? ?3 ? ? ? 0 ? ?1 >> 3 ? ? ? ? ? ?1 ? ? ? 1 ? ? 1 >> >> And I want to go to this: >> ? ? ? ? ? ? ind1 ? ? ?ind2 ? ? ?ind3 >> ind1 ? ? ?0 ? ? ? ? ?4 ? ? ? ? ? ?2 >> ind2 ? ? ?4 ? ? ? ? ?0 ? ? ? ? ? ?4 >> ind3 ? ? ?2 ? ? ? ? ? 4 ? ? ? ? ? 1 >> >> is there a way to do this? >> Thank you for your help >> -- Sarah Goslee http://www.functionaldiversity.org From sarah.goslee at gmail.com Tue Dec 6 14:33:41 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Tue, 6 Dec 2011 08:33:41 -0500 Subject: [R] Problem with clusplot In-Reply-To: <1323151094047-4163621.post@n4.nabble.com> References: <1323151094047-4163621.post@n4.nabble.com> Message-ID: Well, if I had to guess (and I do, since we have no idea what your data look like, and calling your data matrix is a very bad idea): you have more variables than units, so clusplot() can't use princomp() to create a reduced- dimension plot. You could roll your own using a different ordination method, or you could remove some variables from your data, or you could think about whether the data you have are appropriate for what you're trying to do with them. Sarah On Tue, Dec 6, 2011 at 12:58 AM, elisacarli21 wrote: > Dear all > I'm trying to run a cluster analysis with R > Here are the commands: > > mydata <- na.omit(matrix) # listwise deletion of missing > mydata <- scale(matrix) # standardize variables > > ?fit <- kmeans(mydata, 8) # 8 cluster solution > ?# get cluster means > aggregate(mydata,by=list(fit$cluster),FUN=mean) > ?# append cluster assignment > ?mydata <- data.frame(mydata, fit$cluster) > > ?library(cluster) > clusplot(mydata, fit$cluster, color=TRUE, shade=TRUE, ?labels=2, lines=0) > > > I get the following error > Error in princomp.default(x, scores = TRUE, cor = ncol(x) != 2) : > ?'princomp' can only be used with more units than variables > > How can I fix it? > > Thanks > -- Sarah Goslee http://www.functionaldiversity.org From jverzani at gmail.com Tue Dec 6 14:34:42 2011 From: jverzani at gmail.com (j verzani) Date: Tue, 6 Dec 2011 13:34:42 +0000 Subject: [R] how to view/edit large matrix/array in R? References: Message-ID: Michael gmail.com> writes: > > head, tail and fix commands don't really work well if I have large > matrix/array for which I would like to be able to scroll up and dow, left > and right ... > > Could anybody please help me? > > Thanks > > [[alternative HTML version deleted]] > > You might look into the RGtk2Extras package and find the dfedit. You could also embed that in some custom GUI to show variables, as you want. The package requires RGtk2, and hence the Gtk libraries to be installed. The data frame editor there can gracefully handle large data sets. From sarah.goslee at gmail.com Tue Dec 6 14:35:20 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Tue, 6 Dec 2011 08:35:20 -0500 Subject: [R] Plot numeric and categorical variable In-Reply-To: <4EDE1650.8090601@statistik.tu-dortmund.de> References: <1323123760.89219.YahooMailClassic@web161204.mail.bf1.yahoo.com> <4EDE1650.8090601@statistik.tu-dortmund.de> Message-ID: Not to mention that I answered this exact question only yesterday. 2011/12/6 Uwe Ligges : > On 05.12.2011 23:22, Juliet Ndukum wrote: >> >> My data consists of numeric (yy) and categorical (xx) variables, as shown >> below. >>> >>> xx = c(rep("C", 5), rep("D",5))> ?xx [1] "C" "C" "C" "C" "C" "D" "D" "D" >>> "D" "D"> ?yy = rnorm(10, 0, 4)> ?yy [1] ?2.7219346 -3.7142481 ?6.8716534 >>> -0.9352463 ?0.4901249 ?3.8113247 [7] -2.6602041 ?1.7714471 ?4.7298233 >>> ?0.8848188 >>> xx1 = as.integer(as.factor(xx))> ?plot(xx1, yy, ylim = c(-13.5, 4), >>> col="blue") >> >> I have attached the plot above ?as plot1 >> I wish to generate a scatter plot of the data such that instead of 1 it >> prints C, and instead of 2, it prints D on the x- axis (see plot1 attached). >> How could I possibly go about this, let me know. Any help will be greatly >> appreciated. >> Thanks in advance for your help,JN > > > Sounds like homework?! > Anyway, see ?par and ?axis to answer your question directly or ?boxplot more > implicitly... > > Best, > Uwe Ligges > > > >> -- Sarah Goslee http://www.functionaldiversity.org From comtech.usa at gmail.com Tue Dec 6 15:47:31 2011 From: comtech.usa at gmail.com (Michael) Date: Tue, 6 Dec 2011 08:47:31 -0600 Subject: [R] help! what's wrong with setBreakpoint In-Reply-To: <4EDE08EE.6040407@gmail.com> References: <4EDE08EE.6040407@gmail.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From murdoch.duncan at gmail.com Tue Dec 6 15:57:21 2011 From: murdoch.duncan at gmail.com (Duncan Murdoch) Date: Tue, 6 Dec 2011 09:57:21 -0500 Subject: [R] help! what's wrong with setBreakpoint In-Reply-To: References: <4EDE08EE.6040407@gmail.com> Message-ID: <4EDE2D51.6040607@gmail.com> On 06/12/2011 9:47 AM, Michael wrote: > It printed: > > c:\R\myproject1\myfile.R#38: > myfunc1 step 6,4,9 in > > What do you think? So that set a breakpoint in the copy of the function in the global environment. Are you sure you were executing the same function after you hit c? If you were working on code in a package, you may have been executing the function in the namespace of the package, not the one in the global environment. If that's not the case, then are you sure you ever got to that line? You can see where the breakpoint was set using body(myfunc1)[[c(6,4,9)]] (Watch the parens and brackets!) Duncan Murdoch > Thank you! > > On Tue, Dec 6, 2011 at 6:22 AM, Duncan Murdochwrote: > > > On 11-12-05 10:32 PM, Michael wrote: > > > >> Hi all, > >> > >> I am in the middle of debugging which is stopped using "browser()"... in > >> myfile.R at around line #25. > >> > >> I was then stuck in a big loop which I want to escape and stop the program > >> at the line after the big loop. > >> > >> In the debugging mode, I used > >> > >> Browse[2]> setBreakpoint("myfile.R#38") > >> > > > > What did it print? > > > > > > > >> I then typed "c" and "ENTER", thinking that it will continue to execute > >> until when it comes across line #38 and then stop there... > >> > >> But it didn't work - it continued the execution until the end of the > >> function, right at the line "return(results)"... > >> > >> What happened? How to solve this problem? > >> > > > > One of the complications in R is that you can have multiple copies of a > > function in memory. You may (or may not, what did it print??) have set a > > breakpoint in one copy, then run another. Or you may have edited that > > function after originally sourcing it, and lost the source reference. > > > > An alternative to using setBreakpoint is just to edit a call to browser() > > into the function. It's less convenient, but more robust. > > > > Duncan Murdoch > > > > > > Thanks a lot! > >> > >> [[alternative HTML version deleted]] > >> > >> ______________________________**________________ > >> R-help at r-project.org mailing list > >> https://stat.ethz.ch/mailman/**listinfo/r-help > >> PLEASE do read the posting guide http://www.R-project.org/** > >> posting-guide.html > >> and provide commented, minimal, self-contained, reproducible code. > >> > > > > > From chesney.alt at gmail.com Tue Dec 6 10:18:05 2011 From: chesney.alt at gmail.com (Thomas) Date: Tue, 6 Dec 2011 09:18:05 +0000 Subject: [R] Writing out in loops Message-ID: <25F43847-81F3-4231-8D4F-DE54B85E6084@gmail.com> I would like to write some data to different files. I can create the filename Day1.txt like this: filen <- paste("Day", l, ".txt", sep="") and then I'm using a For loop to write out one row of a matrix, something like this: For (j in 1:10) { cat(mat[1,j], ",", file=filen, append=TRUE) } cat("\n", file=filen, append=TRUE) but is there a better way to do this? Thank you, Thomas From jefferis at mrc-lmb.cam.ac.uk Tue Dec 6 10:20:24 2011 From: jefferis at mrc-lmb.cam.ac.uk (Dr Gregory Jefferis) Date: Tue, 6 Dec 2011 09:20:24 +0000 Subject: [R] Read Windows BMP format images Message-ID: <7DB1296C-D2B5-4B8B-825F-C53C8C66212C@mrc-lmb.cam.ac.uk> Hello, Does anyone know of an R package that can read Windows BMP format images? Many thanks, Greg Jefferis. -- Gregory Jefferis, PhD Division of Neurobiology MRC Laboratory of Molecular Biology, Hills Road, Cambridge, CB2 0QH, UK. http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis http://www.neuroscience.cam.ac.uk/directory/profile.php?gsxej2 http://flybrain.stanford.edu From Bauermartin at gmx.at Tue Dec 6 10:37:47 2011 From: Bauermartin at gmx.at (Martin Bauer) Date: Tue, 06 Dec 2011 10:37:47 +0100 Subject: [R] MAC Problem with http in R while not problem on Win machine Message-ID: <20111206093747.201670@gmx.net> Hello, thanks to (http://timelyportfolio.blogspot.com/) and also (http://systematicinvestor.wordpress.com) the following code was published and it is running smoothly on my Windows enviroment but it is failing to perform on my MAC. #get MAImp code from GIST #thanks to http://systematicinvestor.wordpress.com #for showing me how to do this con=url("https://raw.github.com/gist/1405187/92e7c24ff2459a0830c45b828f1dba41143e9436/MAImp.r") source(con) the error code is the following Error in source(con) : cannot open the connection In addition: Warning message: In source(con) : unsupported URL scheme How can I amend the code that it will also work on my MAC ? many thanks martin -- From yumik091186 at gmail.com Tue Dec 6 11:02:12 2011 From: yumik091186 at gmail.com (stat999) Date: Tue, 6 Dec 2011 02:02:12 -0800 (PST) Subject: [R] the estimated random effects for each level of grouping Message-ID: <1323165732784-4164111.post@n4.nabble.com> Hi, I am a quite beginner of random effect modelling. Sorry for my ignorant question. My question is about the values of lme function. It returns coefficients which is a list with two components. The R-help file says that it returns the estimated random effects for each level of grouping. What is the estimator of this random effects in R? Since the random effects are random variables so this "estimate" should be something like mean or mode of the density of the random effect given data, f_i(b_i|y_i).... -- View this message in context: http://r.789695.n4.nabble.com/the-estimated-random-effects-for-each-level-of-grouping-tp4164111p4164111.html Sent from the R help mailing list archive at Nabble.com. From r.kozarski at gmail.com Tue Dec 6 11:38:43 2011 From: r.kozarski at gmail.com (threshold) Date: Tue, 6 Dec 2011 02:38:43 -0800 (PST) Subject: [R] split date nad time Message-ID: <1323167923173-4164191.post@n4.nabble.com> Dear R Users, given that: > AggDateTime[960:962] [1] "2011-08-25 23:59:00 BST" "2011-08-26 00:00:00 BST" [3] "2011-08-26 00:01:00 BST" > unlist(strsplit(as.character(AggDateTime[960])," ", fixed=TRUE)) [1] "2011-08-25" "23:59:00" > unlist(strsplit(as.character(AggDateTime[962])," ", fixed=TRUE)) [1] "2011-08-26" "00:01:00" Why no time here? > unlist(strsplit(as.character(AggDateTime[961])," ", fixed=TRUE)) [1] "2011-08-26" best, robert -- View this message in context: http://r.789695.n4.nabble.com/split-date-nad-time-tp4164191p4164191.html Sent from the R help mailing list archive at Nabble.com. From vioravis at gmail.com Tue Dec 6 12:52:56 2011 From: vioravis at gmail.com (vioravis) Date: Tue, 6 Dec 2011 03:52:56 -0800 (PST) Subject: [R] HTML Forms to R Message-ID: <1323172376189-4164360.post@n4.nabble.com> I have currently a R function that reads a csv file, does some computations, produces some plots and writes a csv file as output. I would like to use HTML forms to make a user interface for calling appropriate parts of the functions (reading csv file, doing computations, displaying plots and writing csv files). Are there are tutorials available that would help me get started?? Thank you. Ravi -- View this message in context: http://r.789695.n4.nabble.com/HTML-Forms-to-R-tp4164360p4164360.html Sent from the R help mailing list archive at Nabble.com. From surfprjab at hotmail.com Tue Dec 6 13:21:02 2011 From: surfprjab at hotmail.com (jose Bartolomei) Date: Tue, 6 Dec 2011 12:21:02 +0000 Subject: [R] LaTeX output for summary.lm object - while displaying the information outside the table In-Reply-To: References: Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From h_a_patience at hotmail.com Tue Dec 6 14:17:00 2011 From: h_a_patience at hotmail.com (Bazman76) Date: Tue, 6 Dec 2011 05:17:00 -0800 (PST) Subject: [R] a question on autocorrelation acf In-Reply-To: References: <4BDA115C.9040504@gmail.com> <1323113081359-4161818.post@n4.nabble.com> <1323135157369-4163021.post@n4.nabble.com> Message-ID: <1323177420061-4164630.post@n4.nabble.com> http://r.789695.n4.nabble.com/file/n4164630/R_example.xlsx R_example.xlsx Hi there, I attach an excel file which I use to produce the data. It simulates a simple AR(1) process y_t=0.5y_{t-1}+z_t. In column E I have cut and paste values so that we can compare like with like. When I run the acf() on these values, it shows 3 significant lags. When I run the pacf() it shows one very strong correlation of 0.3 at lag 1, and a smaller one at lag 2 of around 0.05. Now according to the theory the pacf() results should give the correct exponents for the lags. This is a pure AR(1) process so the results should be 0.5 on lag 1 and statistically insignificant else where? I have tried if for several realisations of the white noise term and the results are qualatively similar and is disagreement with the theory. Kind Regards Baz -- View this message in context: http://r.789695.n4.nabble.com/a-question-on-autocorrelation-acf-tp2076280p4164630.html Sent from the R help mailing list archive at Nabble.com. From pls at mevik.net Tue Dec 6 15:21:11 2011 From: pls at mevik.net (=?utf-8?Q?Bj=C3=B8rn-Helge_Mevik?=) Date: Tue, 6 Dec 2011 15:21:11 +0100 Subject: [R] [R-pkgs] pls 2.3.0 released Message-ID: Version 2.3.0 of the pls package has been released. The pls package implements Partial Least Squares Regression and Principal Component Regression. The major changes are: - New analysis method Canonical Powered PLS (CPPLS) implmemented. See ?cppls.fit. - coefplot() can now plot whiskers at +/-1 SE (since 2.2.0). See ?coefplot - The package now has a name space (since 2.2.0). -- Regards, Bj?rn-Helge Mevik _______________________________________________ R-packages mailing list R-packages at r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages From sarah.goslee at gmail.com Tue Dec 6 16:07:23 2011 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Tue, 6 Dec 2011 10:07:23 -0500 Subject: [R] Writing out in loops In-Reply-To: <25F43847-81F3-4231-8D4F-DE54B85E6084@gmail.com> References: <25F43847-81F3-4231-8D4F-DE54B85E6084@gmail.com> Message-ID: Is there some reason you can't create the entire file in R and then write it out in a single step? It looks like you're writing out mat[1, 1:10] so you could just use write.table(mat[1, 1:10], filen) Can you expand on what you're trying to do? Sarah On Tue, Dec 6, 2011 at 4:18 AM, Thomas wrote: > I would like to write some data to different files. I can create the > filename Day1.txt like this: > > filen <- paste("Day", l, ".txt", sep="") > > and then I'm using a For loop to write out one row of a matrix, something > like this: > > For (j in 1:10) > { > cat(mat[1,j], ",", file=filen, append=TRUE) > } > cat("\n", file=filen, append=TRUE) > > but is there a better way to do this? > > Thank you, > > Thomas > -- Sarah Goslee http://www.functionaldiversity.org From JRadinger at gmx.at Tue Dec 6 16:15:21 2011 From: JRadinger at gmx.at (Johannes Radinger) Date: Tue, 06 Dec 2011 16:15:21 +0100 Subject: [R] Argument validation within functions In-Reply-To: References: <20111206114145.143490@gmx.net> <20111206124614.162280@gmx.net> Message-ID: <20111206151521.286940@gmx.net> Thank you, i didn't know that the !operator is also working for is.numeric etc. Anyway I want to test if an argument is set in the function call and if not a code is executed... So far I tried: f <-function(a,b){ if(!exists("b")) print("exists: b is not set") if(is.null("b")) print("is.null : b is not set") } f(a=1,b=2) f(a=1) f(b=2) I don't really know how to do it...e.g: for f(a=1) b is not set so it also can't be NULL (thats why is.null is not working). I just want to "test" if it is set with the function call not outside the function or before etc. /Johannes -------- Original-Nachricht -------- > Datum: Tue, 6 Dec 2011 07:57:44 -0500 > Von: "R. Michael Weylandt" > An: r-help , Johannes Radinger > Betreff: Re: [R] Argument validation within functions > Use the ! (not) operator. > > Not sure what you mean by " as the stop() stops the total function": > try the following > > f <- function(a){ > ? ?stopifnot(a > 3) > ? ?return(a^2) > } > > f(2) > f(4) > > Michael > > (PS -- It's usually asked to cc the list so that this all gets > threaded properly in folks' mailboxes) > > On Tue, Dec 6, 2011 at 7:46 AM, Johannes Radinger > wrote: > > Hi, > > > > thank you... I think I will go for the if-stop approach > > as the stop() stops the total function... So there is just > > one little other question: What is the opposite of is.numeric? > > Is ther isnot.numeric? How ?can that be implemented in following > > function: > > > > f <- function(a){ > > ? ? ? ?if(is.numeric(a)) stop("a is not numeric") > > ? ? ? ?if(0 > a && a > 1) stop("a must be a value between 0 and 1") > > ? ? ? ?a > > } > > > > /Johannes > > > > -------- Original-Nachricht -------- > >> Datum: Tue, 6 Dec 2011 07:04:59 -0500 > >> Von: "R. Michael Weylandt" > >> An: Johannes Radinger > >> CC: r-help at r-project.org > >> Betreff: Re: [R] Argument validation within functions > > > >> The quick and dirty way to do so is to use: stopifnot() in conjunction > >> (if necessary with all() and any()). You can replace that first > >> condition with a simple is.numeric() as well. A more helpful way (if > >> this is production code) is to use if statement with the stop() > >> function directly which lets you provide specific error messages. > >> > >> Michael > >> > >> On Tue, Dec 6, 2011 at 6:41 AM, Johannes Radinger > >> wrote: > >> > Hi, > >> > > >> > I just started with writing functions in R and so some questions > popped > >> up. > >> > I provide some values as argument to my function such as: > >> > > >> > function(a,b,c){} > >> > > >> > Now i want that the function first checks if the arguments are valid > for > >> the function. E.g argument "a" has to be a number in the range 0-1. How > >> can that easily done? > >> > > >> > So far I have: > >> > > >> > ? ? ? ?a <- as.numeric(a) > >> > ? ? ? ?if(0 <= a && a <= 1) > >> > > >> > to first check if a is a number...if not the function stops and gives > an > >> error message. If it is a number it just continues... > >> > > >> > But how to check the range? > >> > Above there is the if-approach but then the rest of the function is > >> exectued as part of if (or else). Is there a simpler way without having > the > >> if-brackets around the remaining code? > >> > Just a check if the value is between 0 and 1 and if yes continue with > >> the next line if no abort the function with a error message? How can > such an > >> error message be created? > >> > > >> > thank you and best regards, > >> > > >> > /Johannes > >> > -- > >> > > >> > ______________________________________________ > >> > R-help at r-project.org mailing list > >> > https://stat.ethz.ch/mailman/listinfo/r-help > >> > PLEASE do read the posting guide > >> http://www.R-project.org/posting-guide.html > >> > and provide commented, minimal, self-contained, reproducible code. > > > > -- > > NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zur?ck-Garantie! > > Jetzt informieren: http://www.gmx.net/de/go/freephone -- From pomchip at free.fr Tue Dec 6 16:15:13 2011 From: pomchip at free.fr (=?ISO-8859-1?Q?S=E9bastien_Bihorel?=) Date: Tue, 6 Dec 2011 10:15:13 -0500 Subject: [R] How to automate the detection of break points for use in cut In-Reply-To: References: <4EDE0A85.7070904@gmail.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From Berwin.Turlach at gmail.com Tue Dec 6 16:36:46 2011 From: Berwin.Turlach at gmail.com (Berwin A Turlach) Date: Tue, 6 Dec 2011 23:36:46 +0800 Subject: [R] Argument validation within functions In-Reply-To: <20111206151521.286940@gmx.net> References: <20111206114145.143490@gmx.net> <20111206124614.162280@gmx.net> <20111206151521.286940@gmx.net> Message-ID: <20111206233646.1fdebd37@absentia> G'day Johannes, On Tue, 06 Dec 2011 16:15:21 +0100 "Johannes Radinger" wrote: > Thank you, i didn't know that the !operator is > also working for is.numeric etc. > > Anyway I want to test if an argument is set in the > function call and if not a code is executed... So > far I tried: > > f <-function(a,b){ > if(!exists("b")) print("exists: b is not set") > if(is.null("b")) print("is.null : b is not set") > } > > f(a=1,b=2) > f(a=1) > f(b=2) > > I don't really know how to do it...e.g: for f(a=1) b is not set > so it also can't be NULL (thats why is.null is not working). I > just want to "test" if it is set with the function call not outside > the function or before etc. ?missing Cheers, Berwin ========================== Full address ============================ A/Prof Berwin A Turlach Tel.: +61 (8) 6488 3338 (secr) School of Maths and Stats (M019) +61 (8) 6488 3383 (self) The University of Western Australia FAX : +61 (8) 6488 1028 35 Stirling Highway Crawley WA 6009 e-mail: Berwin.Turlach at gmail.com Australia http://www.maths.uwa.edu.au/~berwin From enricoschumann at yahoo.de Tue Dec 6 16:39:44 2011 From: enricoschumann at yahoo.de (Enrico Schumann) Date: Tue, 06 Dec 2011 16:39:44 +0100 Subject: [R] Argument validation within functions In-Reply-To: <20111206151521.286940@gmx.net> References: <20111206114145.143490@gmx.net> <20111206124614.162280@gmx.net> <20111206151521.286940@gmx.net> Message-ID: <4EDE3740.3090609@yahoo.de> you may be looking for ?missing f <- function(a,b) { if (missing(b)) print("b is missing") } f(a=1, b=2) f(a=1) f(b=2) Regards, Enrico Am 06.12.2011 16:15, schrieb Johannes Radinger: > Thank you, i didn't know that the !operator is > also working for is.numeric etc. > > Anyway I want to test if an argument is set in the > function call and if not a code is executed... So > far I tried: > > f<-function(a,b){ > if(!exists("b")) print("exists: b is not set") > if(is.null("b")) print("is.null : b is not set") > } > > f(a=1,b=2) > f(a=1) > f(b=2) > > I don't really know how to do it...e.g: for f(a=1) b is not set > so it also can't be NULL (thats why is.null is not working). I > just want to "test" if it is set with the function call not outside > the function or before etc. > > /Johannes > > -------- Original-Nachricht -------- >> Datum: Tue, 6 Dec 2011 07:57:44 -0500 >> Von: "R. Michael Weylandt" >> An: r-help, Johannes Radinger >> Betreff: Re: [R] Argument validation within functions > >> Use the ! (not) operator. >> >> Not sure what you mean by " as the stop() stops the total function": >> try the following >> >> f<- function(a){ >> stopifnot(a> 3) >> return(a^2) >> } >> >> f(2) >> f(4) >> >> Michael >> >> (PS -- It's usually asked to cc the list so that this all gets >> threaded properly in folks' mailboxes) >> >> On Tue, Dec 6, 2011 at 7:46 AM, Johannes Radinger >> wrote: >>> Hi, >>> >>> thank you... I think I will go for the if-stop approach >>> as the stop() stops the total function... So there is just >>> one little other question: What is the opposite of is.numeric? >>> Is ther isnot.numeric? How can that be implemented in following >>> function: >>> >>> f<- function(a){ >>> if(is.numeric(a)) stop("a is not numeric") >>> if(0> a&& a> 1) stop("a must be a value between 0 and 1") >>> a >>> } >>> >>> /Johannes >>> >>> -------- Original-Nachricht -------- >>>> Datum: Tue, 6 Dec 2011 07:04:59 -0500 >>>> Von: "R. Michael Weylandt" >>>> An: Johannes Radinger >>>> CC: r-help at r-project.org >>>> Betreff: Re: [R] Argument validation within functions >>> >>>> The quick and dirty way to do so is to use: stopifnot() in conjunction >>>> (if necessary with all() and any()). You can replace that first >>>> condition with a simple is.numeric() as well. A more helpful way (if >>>> this is production code) is to use if statement with the stop() >>>> function directly which lets you provide specific error messages. >>>> >>>> Michael >>>> >>>> On Tue, Dec 6, 2011 at 6:41 AM, Johannes Radinger >>>> wrote: >>>>> Hi, >>>>> >>>>> I just started with writing functions in R and so some questions >> popped >>>> up. >>>>> I provide some values as argument to my function such as: >>>>> >>>>> function(a,b,c){} >>>>> >>>>> Now i want that the function first checks if the arguments are valid >> for >>>> the function. E.g argument "a" has to be a number in the range 0-1. How >>>> can that easily done? >>>>> >>>>> So far I have: >>>>> >>>>> a<- as.numeric(a) >>>>> if(0<= a&& a<= 1) >>>>> >>>>> to first check if a is a number...if not the function stops and gives >> an >>>> error message. If it is a number it just continues... >>>>> >>>>> But how to check the range? >>>>> Above there is the if-approach but then the rest of the function is >>>> exectued as part of if (or else). Is there a simpler way without having >> the >>>> if-brackets around the remaining code? >>>>> Just a check if the value is between 0 and 1 and if yes continue with >>>> the next line if no abort the function with a error message? How can >> such an >>>> error message be created? >>>>> >>>>> thank you and best regards, >>>>> >>>>> /Johannes >>>>> -- >>>>> >>>>> ______________________________________________ >>>>> R-help at r-project.org mailing list >>>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>>> PLEASE do read the posting guide >>>> http://www.R-project.org/posting-guide.html >>>>> and provide commented, minimal, self-contained, reproducible code. >>> >>> -- >>> NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zur?ck-Garantie! >>> Jetzt informieren: http://www.gmx.net/de/go/freephone > > -- > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Enrico Schumann Lucerne, Switzerland http://nmof.net/ From gyanendra.pokharel at gmail.com Tue Dec 6 16:40:29 2011 From: gyanendra.pokharel at gmail.com (Gyanendra Pokharel) Date: Tue, 6 Dec 2011 10:40:29 -0500 Subject: [R] Problem in while loop In-Reply-To: References: <7DEC6BA8-EBF6-4F11-930E-4BBBA8340D47@gmail.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From gunter.berton at gene.com Tue Dec 6 17:05:37 2011 From: gunter.berton at gene.com (Bert Gunter) Date: Tue, 6 Dec 2011 08:05:37 -0800 Subject: [R] Argument validation within functions In-Reply-To: <20111206151521.286940@gmx.net> References: <20111206114145.143490@gmx.net> <20111206124614.162280@gmx.net> <20111206151521.286940@gmx.net> Message-ID: On Tue, Dec 6, 2011 at 7:15 AM, Johannes Radinger wrote: > Thank you, i didn't know that the !operator is > also working for is.numeric etc. Read (more carefully?) R docs, please. ! is a unary function that takes a logical argument(and will coerce to logical nonlogical arguments if it can); is.numeric() returns a logical, so of course it should "work". Ergo your failure to understand indicates a fundamental hole in your understanding of how R works. -- Bert > > Anyway I want to test if an argument is set in the > function call and if not a code is executed... So > far I tried: > > f <-function(a,b){ > ? ? ? ?if(!exists("b")) print("exists: b is not set") > ? ? ? ?if(is.null("b")) print("is.null : b is not set") > } > > f(a=1,b=2) > f(a=1) > f(b=2) > > I don't really know how to do it...e.g: for f(a=1) b is not set > so it also can't be NULL (thats why is.null is not working). I > just want to "test" if it is set with the function call not outside > the function or before etc. > > /Johannes > > -------- Original-Nachricht -------- >> Datum: Tue, 6 Dec 2011 07:57:44 -0500 >> Von: "R. Michael Weylandt" >> An: r-help , Johannes Radinger >> Betreff: Re: [R] Argument validation within functions > >> Use the ! (not) operator. >> >> Not sure what you mean by " as the stop() stops the total function": >> try the following >> >> f <- function(a){ >> ? ?stopifnot(a > 3) >> ? ?return(a^2) >> } >> >> f(2) >> f(4) >> >> Michael >> >> (PS -- It's usually asked to cc the list so that this all gets >> threaded properly in folks' mailboxes) >> >> On Tue, Dec 6, 2011 at 7:46 AM, Johannes Radinger >> wrote: >> > Hi, >> > >> > thank you... I think I will go for the if-stop approach >> > as the stop() stops the total function... So there is just >> > one little other question: What is the opposite of is.numeric? >> > Is ther isnot.numeric? How ?can that be implemented in following >> > function: >> > >> > f <- function(a){ >> > ? ? ? ?if(is.numeric(a)) stop("a is not numeric") >> > ? ? ? ?if(0 > a && a > 1) stop("a must be a value between 0 and 1") >> > ? ? ? ?a >> > } >> > >> > /Johannes >> > >> > -------- Original-Nachricht -------- >> >> Datum: Tue, 6 Dec 2011 07:04:59 -0500 >> >> Von: "R. Michael Weylandt" >> >> An: Johannes Radinger >> >> CC: r-help at r-project.org >> >> Betreff: Re: [R] Argument validation within functions >> > >> >> The quick and dirty way to do so is to use: stopifnot() in conjunction >> >> (if necessary with all() and any()). You can replace that first >> >> condition with a simple is.numeric() as well. A more helpful way (if >> >> this is production code) is to use if statement with the stop() >> >> function directly which lets you provide specific error messages. >> >> >> >> Michael >> >> >> >> On Tue, Dec 6, 2011 at 6:41 AM, Johannes Radinger >> >> wrote: >> >> > Hi, >> >> > >> >> > I just started with writing functions in R and so some questions >> popped >> >> up. >> >> > I provide some values as argument to my function such as: >> >> > >> >> > function(a,b,c){} >> >> > >> >> > Now i want that the function first checks if the arguments are valid >> for >> >> the function. E.g argument "a" has to be a number in the range 0-1. How >> >> can that easily done? >> >> > >> >> > So far I have: >> >> > >> >> > ? ? ? ?a <- as.numeric(a) >> >> > ? ? ? ?if(0 <= a && a <= 1) >> >> > >> >> > to first check if a is a number...if not the function stops and gives >> an >> >> error message. If it is a number it just continues... >> >> > >> >> > But how to check the range? >> >> > Above there is the if-approach but then the rest of the function is >> >> exectued as part of if (or else). Is there a simpler way without having >> the >> >> if-brackets around the remaining code? >> >> > Just a check if the value is between 0 and 1 and if yes continue with >> >> the next line if no abort the function with a error message? How can >> such an >> >> error message be created? >> >> > >> >> > thank you and best regards, >> >> > >> >> > /Johannes >> >> > -- >> >> > >> >> > ______________________________________________ >> >> > R-help at r-project.org mailing list >> >> > https://stat.ethz.ch/mailman/listinfo/r-help >> >> > PLEASE do read the posting guide >> >> http://www.R-project.org/posting-guide.html >> >> > and provide commented, minimal, self-contained, reproducible code. >> > >> > -- >> > NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zur?ck-Garantie! >> > Jetzt informieren: http://www.gmx.net/de/go/freephone > > -- > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm From ofwagner at gmail.com Tue Dec 6 16:28:52 2011 From: ofwagner at gmail.com (Otto F. Wagner) Date: Tue, 6 Dec 2011 16:28:52 +0100 Subject: [R] About summary in linear models Message-ID: An embedded and charset-unspecified text was scrubbed... Name: no disponible URL: From comtech.usa at gmail.com Tue Dec 6 17:11:21 2011 From: comtech.usa at gmail.com (Michael) Date: Tue, 6 Dec 2011 10:11:21 -0600 Subject: [R] help! what's wrong with setBreakpoint In-Reply-To: <4EDE2D51.6040607@gmail.com> References: <4EDE08EE.6040407@gmail.com> <4EDE2D51.6040607@gmail.com> Message-ID: An embedded and charset-unspecified text was scrubbed... Name: not available URL: From dwinsemius at comcast.net Tue Dec 6 17:12:32 2011 From: dwinsemius at comcast.net (David Winsemius) Date: Tue, 6 Dec 2011 11:12:32 -0500 Subject: [R] split date nad time In-Reply-To: <1323167923173-4164191.post@n4.nabble.com> References: <1323167923173-4164191.post@n4.nabble.com> Message-ID: <310852B4-4BD9-4F3D-B13B-D173A77A7AA9@comcast.net> On Dec 6, 2011, at 5:38 AM, threshold wrote: > Dear R Users, > > given that: > >> AggDateTime[960:962] > [1] "2011-08-25 23:59:00 BST" "2011-08-26 00:00:00 BST" > [3] "2011-08-26 00:01:00 BST" > > >> unlist(strsplit(as.character(AggDateTime[960])," ", fixed=TRUE)) > [1] "2011-08-25" "23:59:00" >> unlist(strsplit(as.character(AggDateTime[962])," ", fixed=TRUE)) > [1] "2011-08-26" "00:01:00" > > Why no time here? >> unlist(strsplit(as.character(AggDateTime[961])," ", fixed=TRUE)) > [1] "2011-08-26" The real question should be: why you didn't post the results of : dput(AggDateTime[960:962]) -- David Winsemius, MD West Hartford, CT From e.rapsomaniki at ucl.ac.uk Tue Dec 6 17:06:45 2011 From: e.rapsomaniki at ucl.ac.uk (Eleni Rapsomaniki) Date: Tue, 6 Dec 2011 16:06:45 -0000 Subject: [R] mfp package - can I exclude some powers? Message-ID: <78b6ff2618301e74c1715c3e9a599865.squirrel@www.squirrelmail.ucl.ac.uk> Hi, The mfp package suggests fractional polynomial transformations for non-linear predictors. For continuous variables that take negative values the suggested transformations tend to look ugly, e.g. if x1 is the original variable it is transformed to something like: (x1+5.67)^1 * log(x1+5.67), where 5.67 is the shift to make it positive. Can I somehow modify the mfp function to exclude some powers among those tried (e.g. those involving log and 0.5). I am willing to sacrifice some precision for a more interpretable transformation. Or is there another package to do something similar? Any suggestions very much appreciated! Eleni Medical Statistician Epidemiology & Public Health University College London, UK From alexandre.chausson at unil.ch Tue Dec 6 17:35:26 2011 From: alexandre.chausson at unil.ch (AlexC) Date: Tue, 6 Dec 2011 08:35:26 -0800 (PST) Subject: [R] axis thickness in plot() Message-ID: <1323189326756-4165430.post@n4.nabble.com> Hello, I am trying to increase the thickness of the axis in plot() without reverting to the use of paint programs i see posts on that topic for the xyplot function but want to see if i can do it with plot() because i've already setup my graph script using that i thought i could use axis() function and specify lwd="thickness" or lwd.axis= but that does not work like it does for lwd.ticks If anyone has an idea, sincerely heres the script windows(width=7,height=7) plot(data$Winter,data$NbFirstBroods,ylab="number of breeding pairs",xlab="winter harshness",cex=1.5,cex.lab=1.5,cex.axis=1.5,font.axis=2,axes=FALSE) points(data$Winter,data$NbFirstBroods,cex=1.5,col="black",pch=19) abline(lm(data$NbFirstBroods~data$Winter),col="red",lwd=4) i tried axis(1, lwd.axis = 3,lwd.ticks=3) for example also when adding the y axis axis(2...) x and y axes are disconnected Thank you for your kind help in advance, Alexandre -- View this message in context: http://r.789695.n4.nabble.com/axis-thickness-in-plot-tp4165430p4165430.html Sent from the R help mailing list archive at Nabble.com. From r.kozarski at gmail.com Tue Dec 6 17:23:34 2011 From: r.kozarski at gmail.com (threshold) Date: Tue, 6 Dec 2011 08:23:34 -0800 (PST) Subject: [R] split date nad time In-Reply-To: <310852B4-4BD9-4F3D-B13B-D173A77A7AA9@comcast.net> References: <1323167923173-4164191.post@n4.nabble.com> <310852B4-4BD9-4F3D-B13B-D173A77A7AA9@comcast.net> Message-ID: <1323188614142-4165378.post@n4.nabble.com> ok, > dput(AggDateTime[960:962]) structure(c(1314313140L, 1314313200L, 1314313260L), class = c("POSIXct", "POSIXt"), tzone = "") -- View this message in context: http://r.789695.n4.nabble.com/split-date-nad-time-tp4164191p4165378.html Sent from the R help mailing list archive at Nabble.com. From searl at vt.edu Tue Dec 6 17:43:52 2011 From: searl at vt.edu (Steve E.) Date: Tue, 6 Dec 2011 08:43:52 -0800 (PST) Subject: [R] help wrapping findInterval into a function Message-ID: <1323189832120-4165464.post@n4.nabble.com> Dear R Community, I hope you might be able to assist with a small problem creating a function. I am working with water-quality data sets that contain the concentration of many different elements in water samples. I need to assign quality-control flags to values that fall into various concentration ranges. Rather than a web of nested if statements, I am employing the findInterval function to identify values that need to be flagged and to assign the appropriate flag. The data consist of a sample identifier, the analysis, and corresponding value. The findInterval function works well; however, I would like to incorporate it into a function so that I can run multiple findInterval functions for many different water-quality analyses (and I have to do this for many dataset) but it seems to fall apart when incorporated into a function. Run straighforward, the findInterval function works as desired, e.g. below, creating the new CalciumFlag column with the appropriate flag for, in this case, levels of calcium in the water: WQdata$CalciumFlag <- with(WQdata, ifelse(analysis == "Calcium", (flags <- c("Y", 'Q', "", "A") [findInterval(WQdata$value, c(-Inf, 0.027, 0.1, 100, Inf))]),"")) However, it does not worked when wrapped in a function (no error messages are thrown, it simply does not seem to do anything): WQfunc <- function() { WQdata$CalciumFlag <- with(WQdata, ifelse(analysis == "Calcium", (flags <- c("Y", 'Q', "", "A") [findInterval(WQdata$value, c(-Inf, 0.027, 0.1, 100, Inf))]),"")) } Calling the function WQfunc() does not produce an error but also does not produce the expected CalciumFlag, it seems to not do anything. Ultimately, what I need to get to is something like below where multiple findInterval functions for different analyses are included in a single function, then I can concatenate the results into a single column containing all flags for all analyses, e.g.: WQfunc <- function() { WQdata$CalciumFlag <- with(WQdata, ifelse(analysis == "Calcium", (flags <- c("Y", 'Q', "", "A") [findInterval(WQdata$value, c(-Inf, 0.027, 0.1, 100, Inf))]),"")) WQdata$SodiumFlag <- with(WQdata, ifelse(analysis == "Sodium", (flags <- c("Y", 'Q', "", "A") [findInterval(WQdata$value, c(-Inf, 0.050, 0.125, 125, Inf))]),"")) WQdata$MagnesiumFlag <- with(WQdata, ifelse(analysis == "Magnesium", (flags <- c("Y", 'Q', "", "A") [findInterval(WQdata$value, c(-Inf, 0.065, 0.15, 75, Inf))]),"")) .....etc for additional water-quality analyses... } As an aside, I started working with the findInterval tool from an example that I found online but am not clear as to how the multi-component configuration incorporating brackets actually works, can anyone suggest a good resource that explains this? I thank you very much for any assistance you may be able to provide. Regards, Steve -- View this message in context: http://r.789695.n4.nabble.com/help-wrapping-findInterval-into-a-function-tp4165464p4165464.html Sent from the R help mailing list archive at Nabble.com. From frainj at gmail.com Tue Dec 6 17:55:04 2011 From: frainj at gmail.com (John C Frain) Date: Tue, 6 Dec 2011 16:55:04 +0000 Subject: [R] About summary in linear models In-Reply-To: References: Message-ID: Your email has become a bit distorted during transmission. If you have used the summary command you should be getting some more summary statistics. The lm function in R returns an object of class "lm" which is a list containing at least the components listed in the help files for lm. The objects in the list are used to produce the summary statistics. If you are doing more elaborate work this approach (like the use of internal functions in gretl) is very convenient. Best Regards John On 6 December 2011 15:28, Otto F. Wagner wrote: > Hello!!, for linear models fit I use Gretl, but now I'm starting to use R, > I would like to know if is there some function to obtain a extended summary > like in Gretl. > > I will write a example in Gretl > > > Modelo 1: MCO, usando las observaciones 1968-1982 (T = 15) > > Variable dependiente: Invest > > > Coeficient > > St error > > t-ratio > > p-value > > > > const > > 377,631 > > 35,0955 > > 10,7601 > > <0,00001 > > *** > > GNP > > 0,63612 > > 0,055015 > > 11,5627 > > <0,00001 > > *** > > CPI > > -9,70228 > > 0,913737 > > -10,6182 > > <0,00001 > > *** > > Interest > > -0,941363 > > 2,21077 > > -0,4258 > > 0,67927 > > > > time > > 8,49182 > > 3,18142 > > 2,6692 > > 0,02353 > > ** > > > > Average of Dep Var. > > ?276,0067 > > > St Error Dep. Var > > ?117,5827 > > Squared Sum of remainders > > ?818,6362 > > > > Regression standar error > > ?9,047852 > > R^2 > > ?0,995771 > > > > R^2 adj > > ?0,994079 > > F(4, 10) > > ?588,6040 > > > > p-value (de F) > > ?8,09e-12 > > Log-likelihood > > -51,28100 > > > > Akaike > > ?112,5620 > > Schwarz > > ?116,1023 > > > > Hannan-Quinn > > ?112,5243 > > rho > > -0,440663 > > > > Durbin-Watson > > ?2,757428 > > > Like you can see Gretl shows more statisticas. > > The same model in R: > > Call: > lm(formula = Invest ~ CPI + GNP + Interest + Year, data = Tabla6_3) > > Residuals: > ? ?Min ? ? ?1Q ?Median ? ? ?3Q ? ? Max > -16.397 ?-3.864 ? 1.391 ? 4.219 ?15.779 > > Coefficients: > ? ? ? ? ? ? ?Estimate Std. Error t value Pr(>|t|) > (Intercept) -1.633e+04 ?6.250e+03 ?-2.612 ? 0.0260 * > CPI ? ? ? ? -9.702e+00 ?9.137e-01 -10.618 9.15e-07 *** > GNP ? ? ? ? ?6.361e-01 ?5.502e-02 ?11.563 4.14e-07 *** > Interest ? ?-9.414e-01 ?2.211e+00 ?-0.426 ? 0.6793 > Year ? ? ? ? 8.492e+00 ?3.181e+00 ? 2.669 ? 0.0235 * > --- > Signif. codes: ?0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > Thanks so much, > > Otto > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- John C Frain Economics Department Trinity College Dublin Dublin 2 Ireland www.tcd.ie/Economics/staff/frainj/home.html mailto:frainj at tcd.ie mailto:frainj at gmail.com From comtech.usa at gmail.com Tue Dec 6 18:06:00 2011 From: comtech.usa at gmail.com (Michael) Date: Tue, 6 Dec 2011 11:06:00 -0600 Subject: [R] help! "browser()" does not get stopped... Message-ID: It's weird! I am sure that I have inserted "browser()" in a sub-routine where I wanted to stop and debug... But when I start running the main function from the separate main file, it doesn't stop within the target sub-routine at all. Please help me! Thanks! From ligges at statistik.tu-dortmund.de Tue Dec 6 18:12:31 2011 From: ligges at statistik.tu-dortmund.de (Uwe Ligges) Date: Tue, 6 Dec 2011 18:12:31 +0100 Subject: [R] help! "browser()" does not get stopped... In-Reply-To: References: Message-ID: <4EDE4CFF.3000601@statistik.tu-dortmund.de> On 06.12.2011 18:06, Michael wrote: > It's weird! > > I am sure that I have inserted "browser()" in a sub-routine where I > wanted to stop and debug... > > But when I start running the main function from the separate main file, > > it doesn't stop within the target sub-routine at all. Probably you are using some package and call the "subroutine" within the NAMESPACE of the package rather than the one in .GlobalEnv. Uwe Ligges > Please help me! > > Thanks! > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From ligges at statistik.tu-dortmund.de Tue Dec 6 18:31:56 2011 From: ligges at statistik.tu-dortmund.de (Uwe Ligges) Date: Tue, 6 Dec 2011 18:31:56 +0100 Subject: [R] Can't load package 'lars' In-Reply-To: References: <4EDD7EDE.6090809@mail.mcgill.ca>, <4EDE1226.1010708@statistik.tu-dortmund.de> Message-ID: <4EDE518C.1010808@statistik.tu-dortmund.de> On 06.12.2011 18:27, Luc Villandre wrote: > Hello, > > I do think so. > > ### > [villandre at stat04 lars]$ pwd > /home/villandre/R/x86_64-redhat-linux-gnu-library/2.11/lars > [villandre at stat04 lars]$ ls > data DESCRIPTION help html INDEX libs Meta NAMESPACE R > ### > > I re-installed it and I still get the same error message. > > #### > >> install.packages("lars", lib = "~/R/x86_64-redhat-linux-gnu-library/2.11") > > trying URL 'http://software.rc.fas.harvard.edu/mirrors/R/src/contrib/lars_0.9-8.tar.gz' > Content type 'application/x-gzip' length 172011 bytes (167 Kb) > opened URL > ================================================== > downloaded 167 Kb > > * installing *source* package ?lars? ... > ** libs > gfortran -m64 -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -c delcol.f -o delcol.o > gcc -m64 -std=gnu99 -shared -L/usr/local/lib64 -o lars.so delcol.o -lgfortran -lm -L/usr/lib64/R/lib -lR > installing to /mnt/prism/s20/villandre/R/x86_64-redhat-linux-gnu-library/2.11/lars/libs > ** R > ** data > ** preparing package for lazy loading > ** help > *** installing help indices > converting help for package ?lars? > finding HTML links ... done > cv.lars html > diabetes html > lars-internal html > lars html > plot.lars html > predict.lars html > summary.lars html > ** building package indices ... > ** testing if installed package can be loaded > Loaded lars 0.9-8 > > * DONE (lars) > > The downloaded packages are in > ?/tmp/RtmphxCj4j/downloaded_packages? >> library(lars, lib.loc = "~/R/x86_64-redhat-linux-gnu-library/2.11") > Error : .onLoad failed in loadNamespace() for 'lars', details: > call: cat("Loaded lars", utils::installed.packages()["lars", "Version"], > error: subscript out of bounds I haven't looked closely enough before: The culprit is in lars which has: cat("Loaded lars", utils::installed.packages()["lars", "Version"], and hence only looks at the default search path to report its version while you supplied a different one. Thus, it is a bug in the package you should report to its maintainer. I the meantime as a workaround (and maybe more convenient anyway): set the location of your library using .libPaths() before loading the package. Uwe Ligges > Error: package/namespace load failed for ?lars? > #### > > It is the first time I get such an error message when trying to load a package. It would seem that the problem is with > > ### > cat("Loaded lars", utils::installed.packages()["lars", "Version"] > ### > > Is there a way to circumvent this problem (e.g. attribute an arbitrary value to utils::installed.packages()["lars", "V