Re: [R] lattice xyplot point labelling
hi duncan, thanks a lot for your help! yes, your solution is working fine with a little tweaking of the vector poscec : but on the other hand it's just affecting the relative position of labels around respective points; to get more flexibility would be probably better to supply (even if I do not know exactly how) a set of coordinates for respective labels via the parameters x and y or maybe just changing the position of some specific labels remaing the rest unaltered can you think to a viable solution for this approach? I've been trying that but for reasons I do not fully understand I can't make it work thanks again for your valuable help Massimo Bressan ARPAV Environmental Protection Agency of Veneto Region - Italy Department of Treviso 31100 Treviso, Italy Il 27/02/2013 23:38, Duncan Mackay-2 [via R] ha scritto: hi the bottom panel seems ok so for the top you supply a vector of positions that are your required positions (name eg posvec) to the panel function. may need to do the same for other functions to access the correct panel there is the ifelse statement posvec = c(...) panel = function(x, y , subscripts,...) { pnl = panel.number() panel.xyplot(x, y, cex=0.8,...) panel.abline(a = 0, b = 1, lty = 2, col =gray) if (pnl == 2){ panel.text(x, y, labels=tv.ms$inq[subscripts], cex = 0.7, pos=3, offset=1, srt=0, adj=c(1,1)) } else { panel.text(x, y, labels=tv.ms$inq[subscripts], cex = 0.7, pos=posvec, offset=1, srt=0, adj=c(1,1)) } #alternative to the use of panel.text #ltext(x=x, y=y, labels=tv.ms$inq[subscripts], pos=1, cex=0.8) }, HTh Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: [hidden email] /user/SendEmail.jtp?type=nodenode=4659841i=0 At 22:30 27/02/2013, you wrote: This is my reproducible example tv.ms-structure(list(inq = structure(4:17, .Label = c(D4, D5, D6a, D6b, D6c, D7, D8, F4, F5a, F5b, F6a, F6b, F6c, F6d, F7a, F7b, F8), class = factor), tv.km.median.iteq = c(0.324, 0.238, 0.242, 0.0801, 0.985, 0.309, 4.470003, 0.625, 0.625, 0.18, 0.796, 0.32, 0.0205, 0.01), ms.km.median.iteq = c(0.422, 0.381, 0.33, 0.0901, 1.069994, 0.5599974, 5.200027, 1.5, 1.19, 0.469, 0.312, 0.459, 0.0403, 0.04 ), type = c(PCDD, PCDD, PCDD, PCDD, PCDF, PCDF, PCDF, PCDF, PCDF, PCDF, PCDF, PCDF, PCDF, PCDF)), .Names = c(inq, tv.km.median.iteq, ms.km.median.iteq, type), row.names = 4:17, class = data.frame) I worked out the chart mainly with the hints of this great forum (thanks again for that): what IâÂÂve done so far accomplishes my needs except for that now I need a little final tweaking in order to avoid the overlapping of some specific labels (i.e. by looking at the plot the labels: F6b and F6a, F7a and F5a) xyplot(tv.km.median.iteq~ms.km.median.iteq|type, data=tv.ms, layout=c(1,2), aspect=xy, xlab = expression(paste('ms [ fg/', m^3, ' ]', sep = '')), ylab = expression(paste('tv [ fg/', m^3, ' ]', sep = '')), scales= list(relation=free, log=10, cex=0.8),prepanel = function(x, y, subscripts) { rr- range(cbind(x,y)) list(xlim = rr, ylim= rr) }, panel = function(x, y , subscripts,...) { panel.xyplot(x, y, cex=0.8,...) panel.abline(a = 0, b = 1, lty = 2, col =gray) panel.text(x, y, labels=tv.ms$inq[subscripts], cex = 0.7, pos=3, offset=1, srt=0, adj=c(1,1)) #alternative to the use of panel.text #ltext(x=x, y=y, labels=tv.ms$inq[subscripts], pos=1, cex=0.8) }, #subscripts=TRUE, xscale.components = function(...) { ans - xscale.components.logpower(...) range - ans$num.limit newtck - round(seq(range[1],range[2],l=7),1) ans$bottom$ticks$at - newtck ans$bottom$labels$at - newtck ans$bottom$labels$labels -parse(text=paste('10^',newtck,sep='')) ans } , yscale.components = function(...) { ans - yscale.components.logpower(...) range - ans$num.limit newtck - round(seq(range[1],range[2],l=7),1) ans$left$ticks$at - newtck ans$left$labels$at - newtck ans$left$labels$labels -parse(text=paste('10^',newtck,sep='')) ans } ) IâÂÂm thinking to sort out the problem by: 1 - plotting all labels except for those overlapping (i.e the above mentioned points); 2 - plotting the remaining labels (i.e. the overlapping ones) by introducing a âÂÂmanual
[R] Debugging (was Re: HELP!!!)
On Fri, 22-Feb-2013 at 02:23PM -0500, jim holtman wrote: | Run with: | | options(error=utils::recover) | | Then at the point of the error you will be able to examine sigma2$id | which is probably not a numeric. Any time you get an error like this, | if you have been using the above statement in your script (which I | always have turned on), you will be able to discover for yourself most | of your bugs. Debugging is an important talent to learn if you are | going to be writing programs/scripts. Does that have advantages of using a browser() line or two? I find them indispensable. | | On Fri, Feb 22, 2013 at 2:02 PM, lara sowale lara.d...@gmail.com wrote: | I am sorry to bug you, I am having this error whenever I want to run | random effects regression in software R: Error in if (sigma2$id 0) | stop(paste(the estimated variance of the, : | missing value where TRUE/FALSE needed. | | Please help me look into it. | | [[alternative HTML version deleted]] | | __ | R-help@r-project.org mailing list | https://stat.ethz.ch/mailman/listinfo/r-help | PLEASE do read the posting guide http://www.R-project.org/posting-guide.html | and provide commented, minimal, self-contained, reproducible code. | | | | -- | Jim Holtman | 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@r-project.org mailing list | https://stat.ethz.ch/mailman/listinfo/r-help | PLEASE do read the posting guide http://www.R-project.org/posting-guide.html | and provide commented, minimal, self-contained, reproducible code. -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sys.frame() and variables from parent frame
On 02/27/2013 07:30 PM, David Winsemius wrote: On Feb 27, 2013, at 10:16 AM, Bert Gunter wrote: Some additional comments inline below to add to David's clarifications, proffered largely in response to the poster's remark about coming to R from another language. On Wed, Feb 27, 2013 at 9:44 AM, David Winsemius dwinsem...@comcast.net wrote: On Feb 27, 2013, at 1:11 AM, Zé Miguel wrote: Dear David, thanks for your reply. Sorry for the ambiguous example. I guess the get() will do it, but I still have a question regarding the parent frame. If I declare both function g and f in the global environment: g - function() { get(N,envir = ???) write(N) } f-function() { N-99 g() } While David shows you below how you **can** do this, I would suggest that you **don't.** The reason is that R largely follows a functional programming paradigm (e.g like Scheme or Lisp, for those in the know). Among other things, this means that essentially a function environment should be its own little world, and that anything needed for it to do its job in that world should be explicitly passed to it as a function argument. The practical danger of circumventing this paradigm and reaching back into a parent or global environment is that you don't know what will be there. Functions can be called by other functions and, if created to serve a purpose as an independent entity, might be called under circumstances entirely unforeseen by the function author. There are certainly situations where one may wish to violate this dictum, and I am sure R experts could provide compelling examples of them. But for the great mass of us unwashed, I think hewing to the R functional paradigm is a safer and more sensible course. Oh, yes. I quite agree. I was taking that as an opportunity to illustrate why the N of 99 in inside his f() was NOT in the global environment (as it appeared that JMD expected). I was not suggesting that he try to shoehorn R into behaving like SAS or SPSS or BASIC. or Minitab or where everything is global. I get your point. I will avoid it in the future, but will definitely need it for this particular problem. The issue was solved with get(). Thanks for guiding me through the beautiful world of R. An additional comment from Mark Leeds was also quite helpful: hadley wickham has a whole set of documentation ( he's writing a book ) titled devtools on github. john fox has something on scope from back in 2003 but it's still good. ( on his website ) www.obeautifulcode.com http://www.obeautifulcode.com has an archive called how R researches and finds stuff that is exactly talking directly about scope but in an indirect way it is. Thanks a lot to him too -- Zé Miguel ___ JM Delgado Reichenberger Str. 52 10999 Berlim Alemanha t(d):+49 30 841 18 127 m(d):+49 176 9633 92 56 m(p):+351 91 671 07 08 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] PCA with spearman and kendall correlations
Hello, I would like to do a PCA with dudi.pca or PCA, but also with the use of Spearman or Kendall correlations Is it possible ? Otherwise, how can I do, according to you ? Thanking you in advance Eric Bourgade RTE France [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] help for an R automated procedures
Dear, I would like to post the following question to the r-help on Nabble (thanks in advance for the attention, Gustavo Vieira): Hi there. I have a data set on hands with 5,220 cases and I'd like to automate some procedures (but I have almost no programming knowledge). The data has some continuous variables that are grouped by 2 others: the name of species and the locality where they were collected. So, the samples are defined as 'each species on each locality'. For every sample I'd like to do multiple imputation (when applicable), test for the presence of outliers, standardize the variables, correct some species abundances, save individual samples to tab delimited text file, and assemble each individual sample (now, without NAs and outliers, corrected abundances, and with the new standardized variables) into a single data set. That task is pretty complex to me, since my programming knowledge is poor (and my free time to learn R programming is sparse). Could someone help me with that (I could provide you the data set and the script I have written to do that, sample by sample [ouch!])? Thanks in advance for your attention and all the best (g...@hotmail.com). [Bellow is an example is the codes I've used to accomplish my goals, sample by sample, which can exemplify the complexity of the procedures: #Subsetting the data (v1-v11 are continuous predictors): species 1 at locality 1 (all data [5520 cases] are on a vector called 'morfo') sp1.loc1-morfo[which(spps==sp1 taxoc==loc1),] #getting only the observations of sp1 (species 1) at loc1 (locality 1) str(sp1.loc1) #abundance - 19 cases and the abundance variable ('abund') says 18 sp1.loc1$abund-rep(19,19) summary(sp1.loc1) #missing values present; abundance for sp1 at loc1 corrected attach(sp1.loc1) #Dealing with NAs: install.packages(mice, dependencies = T) #ok (R at: home work) library(mice) imp - mice(sp1.loc1) sp1.loc1 - complete(imp) summary(sp1.loc1) #jaust checking... No more Nas! attach(sp1.loc1) #Detecting univariate outliers z.crit - qnorm(0.) subset(sp1.loc1, select = id, subset = abs(scale(v1)) z.crit) subset(sp1.loc1, select = id, subset = abs(scale(v2)) z.crit) morfo[47,6] sort(v2[taxoc==loc1]) #the nearest observation close to 32.00 is 25.10 sp1.loc1[,6][sp1.loc1[,6]==32.00]-25.10 subset(sp1.loc1, select = id, subset = abs(scale(v2)) z.crit) #Rechecking for outliers (now, it's ok) subset(sp1.loc1, select = id, subset = abs(scale(v3)) z.crit) subset(sp1.loc1, select = id, subset = abs(scale(v4)) z.crit) subset(sp1.loc1, select = id, subset = abs(scale(v5)) z.crit) subset(sp1.loc1, select = id, subset = abs(scale(v6)) z.crit) subset(sp1.loc1, select = id, subset = abs(scale(v7)) z.crit) subset(sp1.loc1, select = id, subset = abs(scale(v8)) z.crit) subset(sp1.loc1, select = id, subset = abs(scale(v9)) z.crit) subset(sp1.loc1, select = id, subset = abs(scale(v10)) z.crit) subset(sp1.loc1, select = id, subset = abs(scale(v11)) z.crit) #Standardizing variables v1.std-with(sp1.loc1,(scale(v1))) v1.pad-v1.std[,1] v2.std-with(sp1.loc1,(scale(v2))) v2.pad-v2.std[,1] v3.std-with(sp1.loc1,(scale(v3))) v3.pad-v3.std[,1] v4.std-with(sp1.loc1,(scale(v4))) v4.pad-v4.std[,1] v5.std-with(sp1.loc1,(scale(v5))) v5.pad-v5.std[,1] v6.std-with(sp1.loc1,(scale(v6))) v6.pad-v6.std[,1] v7.std-with(sp1.loc1,(scale(v7))) v7.pad-v7.std[,1] v8.std-with(sp1.loc1,(scale(v8))) v8.pad-v8.std[,1] v9.std-with(sp1.loc1,(scale(v9))) v9.pad-v9.std[,1] v10.std-with(sp1.loc1,(scale(v10))) v10.pad-v10.std[,1] v11.std-with(sp1.loc1,(scale(v11))) v11.pad-v1.std[,1] #Joining the new standardized variables to the sp1.loc1 data set sp1.loc1-data.frame(sp1.loc1,v1.pad,v2.pad,v3.pad,v4.pad,v5.pad,v6.pad,v7.pad,v8.pad,v9.pad,v10.pad,v11.pad) attach(sp1.loc1) write.table(sp1.loc1,sp1.at.loc1.txt,quote=F,row.names=F, col.names=T,sep=\t) detach(sp1.loc1) #Subsetting the data (v1-v11 are continuous predictors): species 2 at locality 1...]-- Time will tell -- [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] ARMA and AR in R
Hello, I would like to compute ARMA and AR using arima-function in R. My question is: If I have Null=zero values in my data, what should I do? Remove ? or doesn't matter for ARIMA-models and I can estimate my coefficients including zero values in data in arima-function in R ? What is the better way? How to manage the data for ARIMA estimation? Thank you. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help for an R automated procedures
Hi exactly what is fortune(surgery) about. Anyway, you can save yourself a lot headache, if you start using lists for your objects. Lists can be used easily in cycles. for (i in 1:n) { some.list[i] - some.function(some.other.list[i]) } and also lapply/sapply functions can be useful sapply(sp1.loc1,scale) will give you scaled data frame Regards Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Gustavo Vieira Sent: Thursday, February 28, 2013 10:53 AM To: r-help@r-project.org Subject: [R] help for an R automated procedures Dear, I would like to post the following question to the r-help on Nabble (thanks in advance for the attention, Gustavo Vieira): Hi there. I have a data set on hands with 5,220 cases and I'd like to automate some procedures (but I have almost no programming knowledge). The data has some continuous variables that are grouped by 2 others: the name of species and the locality where they were collected. So, the samples are defined as 'each species on each locality'. For every sample I'd like to do multiple imputation (when applicable), test for the presence of outliers, standardize the variables, correct some species abundances, save individual samples to tab delimited text file, and assemble each individual sample (now, without NAs and outliers, corrected abundances, and with the new standardized variables) into a single data set. That task is pretty complex to me, since my programming knowledge is poor (and my free time to learn R programming is sparse). Could someone help me with that (I could provide you the data set and the script I have written to do that, sample by sample [ouch!])? Thanks in advance for your attention and all the best (g...@hotmail.com). [Bellow is an example is the codes I've used to accomplish my goals, sample by sample, which can exemplify the complexity of the procedures: #Subsetting the data (v1-v11 are continuous predictors): species 1 at locality 1 (all data [5520 cases] are on a vector called 'morfo') sp1.loc1-morfo[which(spps==sp1 taxoc==loc1),] #getting only the observations of sp1 (species 1) at loc1 (locality 1) str(sp1.loc1) #abundance - 19 cases and the abundance variable ('abund') says 18... sp1.loc1$abund-rep(19,19) summary(sp1.loc1) #missing values present; abundance for sp1 at loc1 corrected attach(sp1.loc1) #Dealing with NAs: install.packages(mice, dependencies = T) #ok (R at: home work) library(mice) imp - mice(sp1.loc1) sp1.loc1 - complete(imp) summary(sp1.loc1) #jaust checking... No more Nas! attach(sp1.loc1) #Detecting univariate outliers z.crit - qnorm(0.) subset(sp1.loc1, select = id, subset = abs(scale(v1)) z.crit) subset(sp1.loc1, select = id, subset = abs(scale(v2)) z.crit) morfo[47,6] sort(v2[taxoc==loc1]) #the nearest observation close to 32.00 is 25.10 sp1.loc1[,6][sp1.loc1[,6]==32.00]-25.10 subset(sp1.loc1, select = id, subset = abs(scale(v2)) z.crit) #Rechecking for outliers (now, it's ok) subset(sp1.loc1, select = id, subset = abs(scale(v3)) z.crit) subset(sp1.loc1, select = id, subset = abs(scale(v4)) z.crit) subset(sp1.loc1, select = id, subset = abs(scale(v5)) z.crit) subset(sp1.loc1, select = id, subset = abs(scale(v6)) z.crit) subset(sp1.loc1, select = id, subset = abs(scale(v7)) z.crit) subset(sp1.loc1, select = id, subset = abs(scale(v8)) z.crit) subset(sp1.loc1, select = id, subset = abs(scale(v9)) z.crit) subset(sp1.loc1, select = id, subset = abs(scale(v10)) z.crit) subset(sp1.loc1, select = id, subset = abs(scale(v11)) z.crit) #Standardizing variables v1.std-with(sp1.loc1,(scale(v1))) v1.pad-v1.std[,1] v2.std-with(sp1.loc1,(scale(v2))) v2.pad-v2.std[,1] v3.std-with(sp1.loc1,(scale(v3))) v3.pad-v3.std[,1] v4.std-with(sp1.loc1,(scale(v4))) v4.pad-v4.std[,1] v5.std-with(sp1.loc1,(scale(v5))) v5.pad-v5.std[,1] v6.std-with(sp1.loc1,(scale(v6))) v6.pad-v6.std[,1] v7.std-with(sp1.loc1,(scale(v7))) v7.pad-v7.std[,1] v8.std-with(sp1.loc1,(scale(v8))) v8.pad-v8.std[,1] v9.std-with(sp1.loc1,(scale(v9))) v9.pad-v9.std[,1] v10.std-with(sp1.loc1,(scale(v10))) v10.pad-v10.std[,1] v11.std-with(sp1.loc1,(scale(v11))) v11.pad-v1.std[,1] #Joining the new standardized variables to the sp1.loc1 data set sp1.loc1- data.frame(sp1.loc1,v1.pad,v2.pad,v3.pad,v4.pad,v5.pad,v6.pad,v7.pad,v8 .pad,v9.pad,v10.pad,v11.pad) attach(sp1.loc1) write.table(sp1.loc1,sp1.at.loc1.txt,quote=F,row.names=F, col.names=T,sep=\t) detach(sp1.loc1) #Subsetting the data (v1-v11 are continuous predictors): species 2 at locality 1...]-- Time will tell -- [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and
Re: [R] Debugging (was Re: HELP!!!)
On 13-02-28 4:20 AM, Patrick Connolly wrote: On Fri, 22-Feb-2013 at 02:23PM -0500, jim holtman wrote: | Run with: | | options(error=utils::recover) | | Then at the point of the error you will be able to examine sigma2$id | which is probably not a numeric. Any time you get an error like this, | if you have been using the above statement in your script (which I | always have turned on), you will be able to discover for yourself most | of your bugs. Debugging is an important talent to learn if you are | going to be writing programs/scripts. Does that have advantages of using a browser() line or two? I find them indispensable. The error=utils::recover option will invoke a browser at the time of an error, so it's very helpful when you don't know where to put the browser() calls. You should also consider using trace(), which inserts temporary browser() calls (or other code). The setBreakpoint() function constructs a call to trace() using source file information and is often an easier front end. Duncan Murdoch | | On Fri, Feb 22, 2013 at 2:02 PM, lara sowale lara.d...@gmail.com wrote: | I am sorry to bug you, I am having this error whenever I want to run | random effects regression in software R: Error in if (sigma2$id 0) | stop(paste(the estimated variance of the, : | missing value where TRUE/FALSE needed. | | Please help me look into it. | | [[alternative HTML version deleted]] | | __ | R-help@r-project.org mailing list | https://stat.ethz.ch/mailman/listinfo/r-help | PLEASE do read the posting guide http://www.R-project.org/posting-guide.html | and provide commented, minimal, self-contained, reproducible code. | | | | -- | Jim Holtman | 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@r-project.org mailing list | https://stat.ethz.ch/mailman/listinfo/r-help | PLEASE do read the posting guide http://www.R-project.org/posting-guide.html | and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] put strip below the panel (dotplot)
Hello I am using lattice dotplot and I would like to put the strip under the panel. I found the code strip is for the strip above the panel, and strip.left for the strip left to the panel. Please kindly advise how to write the code for the strip under the panel Thank you Elaine [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] positioning of R windows
On Wed, Feb 27, 2013 at 5:33 PM, Glenn Stauffer ges...@psu.edu wrote: I have 2 (related, I think) questions about positioning of windows within R. 1. I often work with a second monitor and sometimes like to arrange 1 or more plot windows on the second monitor, while keeping the console on the primary monitor (so I can see things better). I used to be able to do this (when using Windows XP), but it seems that now (using Windows 7) I can't even move the plot window outside of the parent R window. Is this a Windows 7 issue, or something I can fix with R preferences? 2. When I use the file menu to change directories I noticed 2 differences from Win XP to Win 7. In Win 7, 1) the bottom of the pop-up window is off the bottom of my computer, and 2) the directory tree defaults to something close to the root, regardless of the current working directory. In Win XP, the directory tree defaulted to the current working directory, which made it easy to jump up one folder, etc. Is there any way to make this the default behavior? I am using R 2.15.1 Regarding (2) you might try adjusting the screen resolution. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Negative Binomial Regression - glm.nb
Martin Spindler Martin.Spindler at gmx.de writes: Dear all, I would like to ask, if there is a way to make the variance / dispersion parameter $\theta$ (referring to MASS, 4th edition, p. 206) in the function glm.nb dependent on the data, e.g. $1/ \theta = exp(x \beta)$ and to estimate the parameter vector $\beta$ additionally. If this is not possible with glm.nb, is there another function / package which might do that? As Brian Ripley says, that's outside the scope of glm.nb(), and a later chapter in MASS tells you how to do it. The mle2 function in the bbmle package offers a possibly convenient shortcut. Something like mle2(response~dnbinom(mu=exp(logmu),size=exp(logtheta)), parameters=list(logmu~[formula for linear predictor of log(mu)], logtheta~[formula for linear predictor of log(beta)]), start=list(logmu=[starting value for logmu intercept], logbeta=[starting value for logbeta intercept]), data=...) should work ... Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] best ordination method for binary variables
It is always useful to look at the data in multiple ways. The unique() function will remove the duplicates in your data so that isoMDS will work: set.seed(42) x - matrix(sample(0:1, 20, replace=TRUE), 10, 2) x [,1] [,2] [1,]10 [2,]11 [3,]01 [4,]10 [5,]10 [6,]11 [7,]11 [8,]00 [9,]10 [10,]11 unique(x) [,1] [,2] [1,]10 [2,]11 [3,]01 [4,]00 -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of marco milella Sent: Wednesday, February 27, 2013 6:09 AM To: r-help@r-project.org Subject: [R] best ordination method for binary variables Dear all, I'm analyzing a dataset (A) of 400 cases with 11 binary variables. Unfortunately, several (actually a lot) of cases are identical. NA are also present. I want to to plot distances between cases. For this, I obtained a distance matrix by dist(A, method=binary). I then analyzed the obtained distance via Principal coordinate analysis with cmdscale(). Results are fine. However, do you think this is a wrong approach? After reading the literature and previous posts, I noticed that non metrical MDS (via isoMDS or metaMDS) could be a more correct choice. The problem is that, when trying this methods, I immediately get problems due to the identity between several of mycases or the presence of NA. Typical error messages are *Error in isoMDS(DistB, k = 3) : zero or negative distance between objects 1 and 2* or *Error in if (any(autotransform, noshare 0, wascores) any(comm 0)) { : missing value where TRUE/FALSE needed* *In addition: Warning message:* *In Ops.factor(left, right) : not meaningful for factor* Do you think Principal coordinate analysis on a binary distance matrix is a decent strategy? Thanks for any suggestion marco [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] PCA with spearman and kendall correlations
Spearman would be easier since you just convert the data to ranks and use the Pearson correlation: set.seed(42) x - data.frame(matrix(sample(1:9, 20, replace=TRUE), 10, 2)) x X1 X2 1 9 5 2 9 7 3 3 9 4 8 3 5 6 5 6 5 9 7 7 9 8 2 2 9 6 5 10 7 6 cor(x) X1 X2 X1 1. 0.01897427 X2 0.01897427 1. cor(x, method=spearman) X1 X2 X1 1. -0.03135181 X2 -0.03135181 1. cor(sapply(x, rank)) X1 X2 X1 1. -0.03135181 X2 -0.03135181 1. -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of BOURGADE Eric Sent: Thursday, February 28, 2013 3:50 AM To: r-help@r-project.org Subject: [R] PCA with spearman and kendall correlations Hello, I would like to do a PCA with dudi.pca or PCA, but also with the use of Spearman or Kendall correlations Is it possible ? Otherwise, how can I do, according to you ? Thanking you in advance Eric Bourgade RTE France [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ARMA and AR in R
Hello, This is a statistics question, not an R one. If you want to fit an ARMA model, your time series can have any values, zero, negative or positive. Please revise your knowledge of time series. Hope this helps, Rui Barradas Em 28-02-2013 10:40, Nnina escreveu: Hello, I would like to compute ARMA and AR using arima-function in R. My question is: If I have Null=zero values in my data, what should I do? Remove ? or doesn't matter for ARIMA-models and I can estimate my coefficients including zero values in data in arima-function in R ? What is the better way? How to manage the data for ARIMA estimation? Thank you. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] positioning of R windows
On 28/02/2013 11:00 AM, Glenn Stauffer wrote: Ahh, I should have known about the MDI and SDI options - choosing SDI lets me do what I want. Thanks. On #2, I realized that when the change directory dialog window pops up, if I resize it, R remembers the resizing so that now the entire window is visible. I should have tried that before I posted. No luck though on getting the change directory dialog box to begin at the current working directory the same manner as 'save' or 'open' dialog boxes. I'll update to the new R version In the 2.15.3 release candidate, I see this: The first time I open that control, it starts in the current working directory. After that, it starts in the last directory chosen in that control. If I've used setwd() in the console to change, it doesn't see the change. This might be fixable, but not for tomorrow. Duncan Murdoch Thanks, Glenn Stauffer -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Prof Brian Ripley Sent: Thursday, February 28, 2013 1:52 AM To: r-help@r-project.org Subject: Re: [R] positioning of R windows On 27/02/2013 22:33, Glenn Stauffer wrote: I have 2 (related, I think) questions about positioning of windows within R. 1. I often work with a second monitor and sometimes like to arrange 1 or more plot windows on the second monitor, while keeping the console on the primary monitor (so I can see things better). I used to be able to do this (when using Windows XP), but it seems that now (using Windows 7) I can't even move the plot window outside of the parent R window. Is this a Windows 7 issue, or something I can fix with R preferences? Run RGui with --sdi I don't believe it was ever intentionally possible to move MDI windows outside the frame. 2. When I use the file menu to change directories I noticed 2 differences from Win XP to Win 7. In Win 7, 1) the bottom of the pop-up window is off the bottom of my computer, and 2) the directory tree defaults to something close to the root, regardless of the current working directory. In Win XP, the directory tree defaulted to the current working directory, which made it easy to jump up one folder, etc. Is there any way to make this the default behavior? Ask Microsoft not to change the behaviour of their common controls API. I am using R 2.15.1 Which is not current: R 2.15.3 will be released tomorrow. And you are comparing an old OS (Win7) with a very old one (XP): R for Windows was adapted for Win7 and before that, Vista, several years ago. Thanks, Glenn Stauffer [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Separation issue in binary response models - glm, brglm, logistf
Xochitl CORMON Xochitl.Cormon at ifremer.fr writes: Dear all, I am encountering some issues with my data and need some help. I am trying to run glm analysis with a presence/absence variable as response variable and several explanatory variable (time, location, presence/absence data, abundance data). First I tried to use the glm() function, however I was having 2 warnings concerning glm.fit () : # 1: glm.fit: algorithm did not converge # 2: glm.fit: fitted probabilities numerically 0 or 1 occurred After some investigation I found out that the problem was most probably quasi complete separation and therefor decide to use brglm and/or logistf. * logistf : analysis does not run When running logistf() I get a error message saying : # error in chol.default(x) : # leading minor 39 is not positive definite I looked into logistf package manual, on Internet, in the theoretical and technical paper of Heinze and Ploner and cannot find where this function is used and if the error can be fixed by some settings. chol.default is a function for Cholesky decomposition, which is going to be embedded fairly deeply in the code ... * brglm : analysis run However I get a warning message saying : # In fit.proc(x = X, y = Y, weights = weights, start = start, etastart # = etastart, : # Iteration limit reached Like before i cannot find where and why this function is used while running the package and if it can be fixed by adjusting some settings. In a more general way, I was wondering what are the fundamental differences of these packages. You might also take a crack with bayesglm() in the arm package, which should (?) be able to overcome the separation problem by specifying a not-completely-uninformative prior. I hope this make sense enough and I am sorry if this is kind of statistical evidence that I'm not aware of. --- Here an extract of my table and the different formula I run : head (CPUE_table) Year Quarter Subarea Latitude Longitude Presence.S CPUE.S Presence.H CPUE.H Presence.NP CPUE.NP Presence.BW CPUE.BW Presence.C CPUE.C Presence.P CPUE.P Presence.W CPUE.W 1 2000 131F151.25 1.5 0 0 0 0 0 0 0 0 1 76.002 0 0 1 3358.667 [snip] logistf_binomPres - logistf (Presence.S ~ (Presence.BW + Presence.W + Presence.C + Presence.NP +Presence.P + Presence.H +CPUE.BW + CPUE.H + CPUE.P + CPUE.NP + CPUE.W + CPUE.C + Year + Quarter + Latitude + Longitude)^2, data = CPUE_table) Brglm_binomPres - brglm (Presence.S ~ (Presence.BW + Presence.W + Presence.C + Presence.NP +Presence.P + Presence.H +CPUE.BW + CPUE.H + CPUE.P + CPUE.NP + CPUE.W + CPUE.C + Year + Quarter + Latitude + Longitude)^2, family = binomial, data = CPUE_table) It's not much to go on, but: * are you overfitting your data? That is, do you have at least 20 times as many 1's or 0's (whichever is rarer) as the number of parameters you are trying to estimated? * have you examined your data graphically and looked for any strong outliers that might be throwing off the fit? * do you have some strongly correlated/multicollinear predictors? * for what it's worth it looks like a variety of your variables might be dummy variables, which you can often express more compactly by using a factor variable and letting R construct the design matrix (i.e. generating the dummy variables on the fly), although that shouldn't change your results __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Separation issue in binary response models - glm, brglm, logistf
Le 28/02/2013 17:22, Ben Bolker a écrit : Thank you for your help ! Xochitl CORMONXochitl.Cormonat ifremer.fr writes: Dear all, I am encountering some issues with my data and need some help. I am trying to run glm analysis with a presence/absence variable as response variable and several explanatory variable (time, location, presence/absence data, abundance data). First I tried to use the glm() function, however I was having 2 warnings concerning glm.fit () : # 1: glm.fit: algorithm did not converge # 2: glm.fit: fitted probabilities numerically 0 or 1 occurred After some investigation I found out that the problem was most probably quasi complete separation and therefor decide to use brglm and/or logistf. * logistf : analysis does not run When running logistf() I get a error message saying : # error in chol.default(x) : # leading minor 39 is not positive definite I looked into logistf package manual, on Internet, in the theoretical and technical paper of Heinze and Ploner and cannot find where this function is used and if the error can be fixed by some settings. chol.default is a function for Cholesky decomposition, which is going to be embedded fairly deeply in the code ... If I understand good I should just not use this package as this error is not easily fixable ? * brglm : analysis run However I get a warning message saying : # In fit.proc(x = X, y = Y, weights = weights, start = start, etastart # = etastart, : # Iteration limit reached Like before i cannot find where and why this function is used while running the package and if it can be fixed by adjusting some settings. In a more general way, I was wondering what are the fundamental differences of these packages. You might also take a crack with bayesglm() in the arm package, which should (?) be able to overcome the separation problem by specifying a not-completely-uninformative prior. Thank you for the tip I will have a look into this package and its doc tomorrow. Do you have any idea of what is this fit.proc function ? I hope this make sense enough and I am sorry if this is kind of statistical evidence that I'm not aware of. --- Here an extract of my table and the different formula I run : head (CPUE_table) Year Quarter Subarea Latitude Longitude Presence.S CPUE.S Presence.H CPUE.H Presence.NP CPUE.NP Presence.BW CPUE.BW Presence.C CPUE.C Presence.P CPUE.P Presence.W CPUE.W 1 2000 1 31F1 51.25 1.5 0 0 0 0 0 0 0 0 1 76.002 0 0 1 3358.667 [snip] logistf_binomPres- logistf (Presence.S ~ (Presence.BW + Presence.W + Presence.C + Presence.NP +Presence.P + Presence.H +CPUE.BW + CPUE.H + CPUE.P + CPUE.NP + CPUE.W + CPUE.C + Year + Quarter + Latitude + Longitude)^2, data = CPUE_table) Brglm_binomPres- brglm (Presence.S ~ (Presence.BW + Presence.W + Presence.C + Presence.NP +Presence.P + Presence.H +CPUE.BW + CPUE.H + CPUE.P + CPUE.NP + CPUE.W + CPUE.C + Year + Quarter + Latitude + Longitude)^2, family = binomial, data = CPUE_table) It's not much to go on, but: Yeah sorry my table header appeared really bad on the email :s * are you overfitting your data? That is, do you have at least 20 times as many 1's or 0's (whichever is rarer) as the number of parameters you are trying to estimated? I have 16 explanatory variable and with interactions we go to 136 parameters. length (which((CPUE_table)[,]== 0)) [1] 33466 length (which((CPUE_table)[,]== 1)) [1] 17552 I assume the over fitting is good, isn't it? * have you examined your data graphically and looked for any strong outliers that might be throwing off the fit? I did check my data graphically in a lot and different ways. However if you have any particular suggestions, please let me know. Concerning strong outliers, I do not really understand what you mean. I have outliers here and there but how can I know that they are strong enough to throw off the fit? Most of the time they are really high abundance coming from the fact that I'm using survey data and probably related to the fact that the boat fished over a fish school. * do you have some strongly correlated/multicollinear predictors? It's survey data so they indeed are correlated in time and space. However I checked the scatterplot matrix and I didn't notice any linear relation between variable. * for what it's worth it looks like a variety of your variables might be dummy variables, which you can often express more compactly by using a factor variable and letting R construct the design matrix (i.e. generating the dummy variables on the fly), although that shouldn't change your results I will check about dummy variable concept as to be honest I don't really understand what it means... Thank you again for your time and help __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
Re: [R] How to plot 2 continous variables on double y-axis with 2 factors: ggplot2, gplot, lattice, sciplot?
It is not at all clear to me exactly what you want but ggplot2 does not allow double-y graphs. However does this suggest anything useful? http://grokbase.com/t/r/r-help/104yxg1q38/r-plotting-multiple-cis John Kane Kingston ON Canada -Original Message- From: a...@ecology.su.se Sent: Mon, 25 Feb 2013 07:07:22 +0100 To: r-help@r-project.org Subject: [R] How to plot 2 continous variables on double y-axis with 2 factors: ggplot2, gplot, lattice, sciplot? Hi, I have a data set with two continous variables that I want to plot MEANS (I am not intrerested in median values) on a double-y graph. I also have 2 factors. I want the factor combinations plotted in different panes. Dummy dataset: mydata - data.frame(factor1 = factor(rep(LETTERS[1:3], each = 40)), factor2 = factor(rep(c(1:4), each = 10)), y1 = rnorm(120, mean = rep(c(0, 3, 5), each = 40), sd = rep(c(1, 2, 3), each = 20)), y2 = rnorm(120, mean = rep(c(6, 7, 8), each = 40), sd = rep(c(1, 2, 3), each = 20))) I have tried plotrix(), but I everything is overlaid. Also, I am pretty sure that the means are wrong as I have assumed that the below calculates the mean of each factor level separately and not the mean per level factor 1 AND factor 2. Is there a way of doing this in ggplot2? I have also tried plotmeans() in the sciplot package, but was unsuccessful. Sincerely Anna Zakrisson library(plotrix) ?brkdn.plot par(family=serif,font=1) brkdn.plot(y1, factor1,factor2, data=mydata, mct=mean,md=sd, main=, cex=0.8, stagger=NA, xlab=factor1, ylab = y1, dispbar=TRUE, type=b,pch=c(0),lty=1,col=par(fg)) par(new=TRUE) brkdn.plot(y2,factor1, factor2,data=mydata, mct=mean,md=sd, main=, cex=0.8, stagger=NA, xlab=, ylab = , dispbar=TRUE, type=b,pch=1,lty=2,col=par(fg)) axis(4) mtext(y2,side=4,line=3) legend(topleft,col=c(black,black),bty=n, lty=c(1:2),legend=c(y1,y2)) Anna Zakrisson Braeunlich PhD Student Department of Ecology Environment and Plant Sciences Stockholm University Svante Arrheniusv. 21A SE-106 91 Stockholm Lives in Berlin. For paper mail: Katzbachstr. 21 D-10965, Berlin - Kreuzberg Germany/Deutschland E-mail: anna.zakris...@su.se Tel work: +49-(0)3091541281 Mobile: +49-(0)15777374888 LinkedIn: http://se.linkedin.com/pub/anna-zakrisson-braeunlich/33/5a2/51b B:`b?. . b? `b?. .b? `b?. . B:`b?. . b? `b?. .b? `b?. .B: [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Separation issue in binary response models - glm, brglm, logistf
Xochitl CORMON Xochitl.Cormon at ifremer.fr writes: Le 28/02/2013 17:22, Ben Bolker a écrit : Xochitl CORMONXochitl.Cormonat ifremer.fr writes: I am encountering some issues with my data and need some help. I am trying to run glm analysis with a presence/absence variable as response variable and several explanatory variable (time, location, presence/absence data, abundance data). [snip] * logistf : analysis does not run When running logistf() I get a error message saying : # error in chol.default(x) : # leading minor 39 is not positive definite I looked into logistf package manual, on Internet, in the theoretical and technical paper of Heinze and Ploner and cannot find where this function is used and if the error can be fixed by some settings. chol.default is a function for Cholesky decomposition, which is going to be embedded fairly deeply in the code ... If I understand good I should just not use this package as this error is not easily fixable ? Yes. * brglm : analysis run However I get a warning message saying : # In fit.proc(x = X, y = Y, weights = weights, start = start, etastart # = etastart, : # Iteration limit reached Like before i cannot find where and why this function is used while running the package and if it can be fixed by adjusting some settings. In a more general way, I was wondering what are the fundamental differences of these packages. You might also take a crack with bayesglm() in the arm package, which should (?) be able to overcome the separation problem by specifying a not-completely-uninformative prior. Thank you for the tip I will have a look into this package and its doc tomorrow. Do you have any idea of what is this fit.proc function ? It is again deep inside brglm. You can use debug() to try to follow the process, but it will probably not help much. **However** you should definitely see ?brglm and especially ?brglm.control ... adding control.brglm=brglm.control(br.maxit=1000) to your function call might help (the default is 100) Here an extract of my table and the different formula I run : head (CPUE_table) Year Quarter Subarea Latitude Longitude Presence.S CPUE.S Presence.H CPUE.H Presence.NP CPUE.NP Presence.BW CPUE.BW Presence.C CPUE.C Presence.P CPUE.P Presence.W CPUE.W 1 2000 1 31F1 51.25 1.5 0 0 0 0 0 0 0 0 1 76.002 0 0 1 3358.667 [snip] logistf_binomPres- logistf (Presence.S ~ (Presence.BW + Presence.W + Presence.C + Presence.NP +Presence.P + Presence.H +CPUE.BW + CPUE.H + CPUE.P + CPUE.NP + CPUE.W + CPUE.C + Year + Quarter + Latitude + Longitude)^2, data = CPUE_table) Brglm_binomPres- brglm (Presence.S ~ (Presence.BW + Presence.W + Presence.C + Presence.NP +Presence.P + Presence.H +CPUE.BW + CPUE.H + CPUE.P + CPUE.NP + CPUE.W + CPUE.C + Year + Quarter + Latitude + Longitude)^2, family = binomial, data = CPUE_table) It's not much to go on, but: * are you overfitting your data? That is, do you have at least 20 times as many 1's or 0's (whichever is rarer) as the number of parameters you are trying to estimated? I have 16 explanatory variable and with interactions we go to 136 parameters. length (which((CPUE_table)[,]== 0)) [1] 33466 length (which((CPUE_table)[,]== 1)) [1] 17552 I assume the over fitting is good, isn't it? No, overfitting is *bad*. But you do have a large data set, so you might get away with fitting a model that's this complex. I would certainly start by seeing if you can successfully fit your model with main effects only (i.e. temporarily get rid of the ^2) I don't think that your statements above really count the zeros and ones in the _response_ variable -- I think you need table(CPUE_table$Presence.S) * have you examined your data graphically and looked for any strong outliers that might be throwing off the fit? I did check my data graphically in a lot and different ways. However if you have any particular suggestions, please let me know. Concerning strong outliers, I do not really understand what you mean. I have outliers here and there but how can I know that they are strong enough to throw off the fit? Most of the time they are really high abundance coming from the fact that I'm using survey data and probably related to the fact that the boat fished over a fish school. * do you have some strongly correlated/multicollinear predictors? It's survey data so they indeed are correlated in time and space. However I checked the scatterplot matrix and I didn't notice any linear relation between variable. * for what it's worth it looks like a variety of your variables might be dummy variables, which you can often express more compactly by using a factor variable and letting R construct the design matrix (i.e. generating the dummy variables on the fly), although that shouldn't change your results I will check about dummy variable concept as to be honest I
Re: [R] new question
Hi, directory- /home/arunksa111/data.new #first function filelist-function(directory,number,list1){ setwd(directory) filelist1-dir(directory) direct-dir(directory,pattern = paste(MSMS_,number,PepInfo.txt,sep=), full.names = FALSE, recursive = TRUE) list1-lapply(direct, function(x) read.table(x,header=TRUE, sep = \t,stringsAsFactors=FALSE)) names(list1)-filelist1 list2- list(filelist1,list1) return(list2) } foldernames1-filelist(directory,23,list1)[[1]] foldernames1 #[1] a1 c1 c2 c3 t1 t2 lista-filelist(directory,23,list1)[[2]] #lista output FacGroup- c(c1,c3,t2) #Second function f-function(listRes,Toselect){ res2-split(listRes,gsub([0-9],,names(listRes))) res3-lapply(seq_along(res2),function(i) lapply(res2[[i]],function(x) x[x[[FDR]]0.01,c(Seq,Mod,z,spec)])) res4-lapply(res3,function(x) x[names(x)[names(x)%in%Toselect]]) res4New- lapply(res4,function(x) lapply(names(x), function(i) do.call(rbind,lapply(x[i],function(x) cbind(folder_name=i,x))) )) library(plyr) library(data.table) res5-lapply(res4New,function(x) lapply(x,function(x1){ x1- data.table(x1);x1[,spec:=paste(spec,collapse=,),by=c(Seq,Mod,z)]})) res6- lapply(res5,function(x) lapply(x,function(x1) {x1$counts-sapply(x1$spec, function(x2) length(gsub(\\s, , unlist(strsplit(x2, ,);x3-as.data.frame(x1);names(x3)[6]- as.character(unique(x3$folder_name));x3[,-c(1,5)]})) res7-lapply(res6,function(x) Reduce(function(...) merge(...,by=c(Seq,Mod,z),all=TRUE),x)) res8-res7[lapply(res7,length)!=0] res9- Reduce(function(...) merge(...,by=c(Seq,Mod,z),all=TRUE),res8) res9[is.na(res9)] - 0 return(res9) } f(lista,FacGroup) head(f(lista,FacGroup)) # Seq Mod z c1 c3 t2 #1 aAATATAGPR 1-n_acPro/ 2 0 0 1 #2 aAAASSPVGVGQR 1-n_acPro/ 2 0 0 1 #3 aAGAAGGR 1-n_acPro/ 2 0 0 1 #4 aAAAGAAGGRGSGPGRR 1-n_acPro/ 2 1 0 0 #5 AAALQAK 2 0 1 1 #6 aAGAGPEMVR 1-n_acPro/ 2 0 0 2 resCounts- f(lista,FacGroup) t.test.p.value - function(...) { obj-try(t.test(...), silent=TRUE) if (is(obj, try-error)) return(NA) else return(obj$p.value) } #3rd function for p-value fpv- function(Countdata){ resNew-do.call(cbind,lapply(split(names(Countdata)[4:ncol(Countdata)],gsub([0-9],,names(Countdata)[4:ncol(Countdata)])), function(i) {x-if(ncol(Countdata[i])1) rowSums(Countdata[i]) else Countdata[i]; colnames(x)-NULL;x})) indx-combn(names(resNew),2) resPval-do.call(cbind,lapply(seq_len(ncol(indx)),function(i) {x-as.data.frame(apply(resNew[,indx[,i]],1,t.test.p.value)); colnames(x)-paste(Pvalue,paste(indx[,i],collapse=),sep=_);x})) resF-cbind(resCounts,resPval) resF } fpv(resCounts) A.K. From: Vera Costa veracosta...@gmail.com To: arun smartpink...@yahoo.com Sent: Thursday, February 28, 2013 11:30 AM Subject: new question Sorry about my question, but I need a new small thing...I need to split my function to read data and to do the treatment of the data. At first I need to know the names of the files and read data, and after a new function with my analysis. So, I did this directory-C:/Users/Vera Costa/Desktop/data.new filelist-function(directory,number){ setwd(directory) filelist-dir(directory) return(filelist) direct-dir(directory,pattern = paste(MSMS_,number,PepInfo.txt,sep=), full.names = FALSE, recursive = TRUE) lista-lapply(direct, function(x) read.table(x,header=TRUE, sep = \t)) names(lista)-filelist return(lista) } filelist(directory,23) ###a1 a2 c1 c2 c3 t1 t2 and after f-function(filelist,FacGroup){ res2-split(lista,names(lista)) res3- lapply(res2,function(x) {names(x)-paste(gsub(.*_,,names(x)),1:length(x),sep=);x}) res3 #Freq FDR0.01 res4-lapply(seq_along(res3),function(i) lapply(res3[[i]],function(x) x[x[[FDR]]0.01,c(Seq,Mod,z,spec)])) names(res4)- names(res2) res4 res4New-lapply(res4,function(x) lapply(names(x),function(i) do.call(rbind,lapply(x[i],function(x) cbind(folder_name=i,x))) )) res5- lapply(res4New,function(x) if(length(x)1) tail(x,-1) else NULL) library(plyr) library(data.table) res6- lapply(res5,function(x) lapply(x,function(x1) {x1-data.table(x1); x1[,spec:=past How can I ask lista in second function? Could you help me? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Iteration through a list in R
Hello :) I'm just starting out with R and would appreciate your help with a couple of problems I am running into. I have used Sys.glob to get a list of all filenames having a particular file extension (in my case, *.txt) I would now like to use this list in the following manner: I would like to use each filename from the list and open that file into a tab separated matrix and proceed. How can I go about iterating through each filename in the list and then opening each of the files? I believe as.matrix can be used to open the txt file as a table, is that correct? I know these are beginner queries but I would love your help. Thank you in advance :) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Hidden information in an object
Hello, The dataset cats contain information about the heart weight (Hwt), body weight (Bwt) and gender (Sex) of a group of 144 cats. I write the following piece of code: library(MASS)attach(cats)ratio - Hwt/Bwtmale - ratio[Sex == M]female - ratio[Sex == F] My question is, when I look at the object ratio, it is just a list of 144 numbers with no information about the gender of the cat that the ratio comes from, and yet the command ratio[Sex == M] is able to pick out those numbers of ratio for which the corresponding cat is male. Why is this? If I write the code like library(MASS)cats$ratio - cats$Hwt/cats$Bwtmale - cats$ratio[cats$Sex == M]... it also works, which I suppose is because there is a correspondence between the Sex variable and the ratio variable in the cats dataset. Regards,Rasmus Hedegaard. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How do I calculate prediction intervals for GLM, BRT and MARS models in R?
I'm working across the statistical literature to find methods for calculating prediction intervals for GLM, BRT (boosted regression tree) models and MARS (multivariate adaptive regression spline) models, but unfortunately my statistical background is too weak to understand most of the stuff I read. I would by satisfied by knowing how to code this in R (and accept the methods as black boxes...). Can anyone provide me with information on (1) which R packages can be used for these purposes, and (2) where I can find example code? -- Christian Kampichler Roghorst 91 6708 KD Wageningen, Niederlande Tel +31 (0)317 417527 Mob +31 (0)6 26 32 39 72 www.christian-kampichler.net __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Results from clogit out of range?
I still don't think the exp(lp)/(1+exp(lp)) gonna work. Since this is conditional logit model, while this formula is only used in unconditional ones. By using this, one neglects the information based on stratum. Though I don't know how to solve it to. I am also working on a project on this and I do hope there's someone explaining this problem. Will that be a possibility that the phat can never be estimated as we never know the individual intercept? Disclaimer: This email (including any attachments) is for the use of the intended recipient only and may contain confidential information and/or copyright material. If you are not the intended recipient, please notify the sender immediately and delete this email and all copies from your system. Any unauthorized use, disclosure, reproduction, copying, distribution, or other form of unauthorized dissemination of the contents is expressly prohibited. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] query labels in iplot() (or other interactive scatterplot)
By Ctr-moving the cursor over a point in an iplot() scatterplot (package iplots) it is possible to check the exact x,y coordinates of a given point. Is it possible to check a text label for that point as well? (i.e., the same info that would get printed on the graphic using text(x,y, labels=v) or with identify(x,y,labels), but I do not want to get the labels permanently plotted on the graphic) Thanks -- -- Dr. Agustin Lobo Institut de Ciencies de la Terra Jaume Almera (CSIC) Lluis Sole Sabaris s/n 08028 Barcelona Spain Tel. 34 934095410 Fax. 34 934110012 e-mail agustin.l...@ictja.csic.es https://sites.google.com/site/aloboaleu/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Dealing with parentheses within variable names
Dear all I'm having some problems with a data set that has parenthesis within the variable names. A example of this kind of variable names is the following: fBodyGyroskewness()Z The case is that R is having a lot of troubles to identify the variable (probably it does understand it like a function). I've tried (among other things) to remove the parenthesis from the name using the following command: names(dataFrame) - sub((),, names(dataFrame)) but It didn't work. Sorry if it's a silly issue but I would really appreciate if anybody could help me. Thank you very much. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] positioning of R windows
Ahh, I should have known about the MDI and SDI options - choosing SDI lets me do what I want. Thanks. On #2, I realized that when the change directory dialog window pops up, if I resize it, R remembers the resizing so that now the entire window is visible. I should have tried that before I posted. No luck though on getting the change directory dialog box to begin at the current working directory the same manner as 'save' or 'open' dialog boxes. I'll update to the new R version Thanks, Glenn Stauffer -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Prof Brian Ripley Sent: Thursday, February 28, 2013 1:52 AM To: r-help@r-project.org Subject: Re: [R] positioning of R windows On 27/02/2013 22:33, Glenn Stauffer wrote: I have 2 (related, I think) questions about positioning of windows within R. 1. I often work with a second monitor and sometimes like to arrange 1 or more plot windows on the second monitor, while keeping the console on the primary monitor (so I can see things better). I used to be able to do this (when using Windows XP), but it seems that now (using Windows 7) I can't even move the plot window outside of the parent R window. Is this a Windows 7 issue, or something I can fix with R preferences? Run RGui with --sdi I don't believe it was ever intentionally possible to move MDI windows outside the frame. 2. When I use the file menu to change directories I noticed 2 differences from Win XP to Win 7. In Win 7, 1) the bottom of the pop-up window is off the bottom of my computer, and 2) the directory tree defaults to something close to the root, regardless of the current working directory. In Win XP, the directory tree defaulted to the current working directory, which made it easy to jump up one folder, etc. Is there any way to make this the default behavior? Ask Microsoft not to change the behaviour of their common controls API. I am using R 2.15.1 Which is not current: R 2.15.3 will be released tomorrow. And you are comparing an old OS (Win7) with a very old one (XP): R for Windows was adapted for Win7 and before that, Vista, several years ago. Thanks, Glenn Stauffer [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Negative Binomial Regression - glm.nb
On 02/28/2013 08:27 PM, Martin Spindler wrote: Dear all, I would like to ask, if there is a way to make the variance / dispersion parameter $\theta$ (referring to MASS, 4th edition, p. 206) in the function glm.nb dependent on the data, e.g. $1/ \theta = exp(x \beta)$ and to estimate the parameter vector $\beta$ additionally. If this is not possible with glm.nb, is there another function / package which might do that? I believe that the VGAM package is designed precisely to do this sort of thing. cheers, Rolf Turner __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Hidden information in an object
Hi Rasmus, Things will be much less confusing if you don't use attach. I know that sounds flippent, but I'm quite serious. Best, Ista On Thu, Feb 28, 2013 at 7:50 AM, Rasmus Hedegaard hedegaard...@hotmail.com wrote: Hello, The dataset cats contain information about the heart weight (Hwt), body weight (Bwt) and gender (Sex) of a group of 144 cats. I write the following piece of code: library(MASS)attach(cats)ratio - Hwt/Bwtmale - ratio[Sex == M]female - ratio[Sex == F] My question is, when I look at the object ratio, it is just a list of 144 numbers with no information about the gender of the cat that the ratio comes from, and yet the command ratio[Sex == M] is able to pick out those numbers of ratio for which the corresponding cat is male. Why is this? If I write the code like library(MASS)cats$ratio - cats$Hwt/cats$Bwtmale - cats$ratio[cats$Sex == M]... it also works, which I suppose is because there is a correspondence between the Sex variable and the ratio variable in the cats dataset. Regards,Rasmus Hedegaard. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dealing with parentheses within variable names
Please read ?regex, where it says: Any metacharacter with special meaning may be quoted by preceding it with a backslash. The metacharacters in EREs are . \ | ( ) [ { ^ $ * + ?, but note that whether these have a special meaning depends on the context. So use: sub(\(\),, names(dataFrame)) instead. -- Bert On Thu, Feb 28, 2013 at 8:08 AM, Jesus Munoz Serrano jesusmunozserr...@gmail.com wrote: Dear all I'm having some problems with a data set that has parenthesis within the variable names. A example of this kind of variable names is the following: fBodyGyroskewness()Z The case is that R is having a lot of troubles to identify the variable (probably it does understand it like a function). I've tried (among other things) to remove the parenthesis from the name using the following command: names(dataFrame) - sub((),, names(dataFrame)) but It didn't work. Sorry if it's a silly issue but I would really appreciate if anybody could help me. Thank you very much. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dealing with parentheses within variable names
Oops -- forgot that you have to double the backslashes: So use: sub(\\(\\),, names(dataFrame)) -- Bert On Thu, Feb 28, 2013 at 1:20 PM, Bert Gunter bgun...@gene.com wrote: Please read ?regex, where it says: Any metacharacter with special meaning may be quoted by preceding it with a backslash. The metacharacters in EREs are . \ | ( ) [ { ^ $ * + ?, but note that whether these have a special meaning depends on the context. So use: sub(\(\),, names(dataFrame)) instead. -- Bert On Thu, Feb 28, 2013 at 8:08 AM, Jesus Munoz Serrano jesusmunozserr...@gmail.com wrote: Dear all I'm having some problems with a data set that has parenthesis within the variable names. A example of this kind of variable names is the following: fBodyGyroskewness()Z The case is that R is having a lot of troubles to identify the variable (probably it does understand it like a function). I've tried (among other things) to remove the parenthesis from the name using the following command: names(dataFrame) - sub((),, names(dataFrame)) but It didn't work. Sorry if it's a silly issue but I would really appreciate if anybody could help me. Thank you very much. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Hidden information in an object
Below is what happens when you let hotmail format your message using html. Always use plain text emails. The command attach(cats) told R to put the data.frame in the search path so that the variables in cats would be visible without specifying the name of the data frame: detach(cats) data(cats) ratio - Hwt/Bwt Error: object 'Hwt' not found attach(cats) ratio - Hwt/Bwt R can find the variables in cats, but it does not automatically put new variables in cats so your command creates ratio as a separate variable. You can still use sex to subset ratio even though they are not in the same data.frame. str(cats) 'data.frame': 144 obs. of 3 variables: $ Sex: Factor w/ 2 levels F,M: 1 1 1 1 1 1 1 1 1 1 ... $ Bwt: num 2 2 2 2.1 2.1 2.1 2.1 2.1 2.1 2.1 ... $ Hwt: num 7 7.4 9.5 7.2 7.3 7.6 8.1 8.2 8.3 8.5 ... str(ratio) num [1:144] 3.5 3.7 4.75 3.43 3.48 ... If you want to add ratio to the cats data frame, you need to tell R to put it there: cats$ratio - Hwt/Bwt str(cats) 'data.frame': 144 obs. of 4 variables: $ Sex : Factor w/ 2 levels F,M: 1 1 1 1 1 1 1 1 1 1 ... $ Bwt : num 2 2 2 2.1 2.1 2.1 2.1 2.1 2.1 2.1 ... $ Hwt : num 7 7.4 9.5 7.2 7.3 7.6 8.1 8.2 8.3 8.5 ... $ ratio: num 3.5 3.7 4.75 3.43 3.48 ... -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Rasmus Hedegaard Sent: Thursday, February 28, 2013 6:51 AM To: r-help@r-project.org Subject: [R] Hidden information in an object Hello, The dataset cats contain information about the heart weight (Hwt), body weight (Bwt) and gender (Sex) of a group of 144 cats. I write the following piece of code: library(MASS)attach(cats)ratio - Hwt/Bwtmale - ratio[Sex == M]female - ratio[Sex == F] My question is, when I look at the object ratio, it is just a list of 144 numbers with no information about the gender of the cat that the ratio comes from, and yet the command ratio[Sex == M] is able to pick out those numbers of ratio for which the corresponding cat is male. Why is this? If I write the code like library(MASS)cats$ratio - cats$Hwt/cats$Bwtmale - cats$ratio[cats$Sex == M]... it also works, which I suppose is because there is a correspondence between the Sex variable and the ratio variable in the cats dataset. Regards,Rasmus Hedegaard. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dealing with parentheses within variable names
Hi, You could also try: gsub([()],,names(dataFrame)) set.seed(15) datF- data.frame(sample(1:10,15,replace=TRUE)) names(datF)- fBodyGyroskewness()Z gsub([()],,names(datF)) #[1] fBodyGyroskewnessZ sub(\\(\\),,names(datF)) #[1] fBodyGyroskewnessZ A.K. - Original Message - From: Bert Gunter gunter.ber...@gene.com To: Jesus Munoz Serrano jesusmunozserr...@gmail.com Cc: r-help@r-project.org Sent: Thursday, February 28, 2013 4:25 PM Subject: Re: [R] Dealing with parentheses within variable names Oops -- forgot that you have to double the backslashes: So use: sub(\\(\\),, names(dataFrame)) -- Bert On Thu, Feb 28, 2013 at 1:20 PM, Bert Gunter bgun...@gene.com wrote: Please read ?regex, where it says: Any metacharacter with special meaning may be quoted by preceding it with a backslash. The metacharacters in EREs are . \ | ( ) [ { ^ $ * + ?, but note that whether these have a special meaning depends on the context. So use: sub(\(\),, names(dataFrame)) instead. -- Bert On Thu, Feb 28, 2013 at 8:08 AM, Jesus Munoz Serrano jesusmunozserr...@gmail.com wrote: Dear all I'm having some problems with a data set that has parenthesis within the variable names. A example of this kind of variable names is the following: fBodyGyroskewness()Z The case is that R is having a lot of troubles to identify the variable (probably it does understand it like a function). I've tried (among other things) to remove the parenthesis from the name using the following command: names(dataFrame) - sub((),, names(dataFrame)) but It didn't work. Sorry if it's a silly issue but I would really appreciate if anybody could help me. Thank you very much. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Iteration through a list in R
Have you read An Introduction to R (ships with R) or other of the many web tutorials. If not, please do so before posting. -- Bert On Thu, Feb 28, 2013 at 4:30 AM, Sahana Srinivasan sahanasrinivasan...@gmail.com wrote: Hello :) I'm just starting out with R and would appreciate your help with a couple of problems I am running into. I have used Sys.glob to get a list of all filenames having a particular file extension (in my case, *.txt) I would now like to use this list in the following manner: I would like to use each filename from the list and open that file into a tab separated matrix and proceed. How can I go about iterating through each filename in the list and then opening each of the files? I believe as.matrix can be used to open the txt file as a table, is that correct? I know these are beginner queries but I would love your help. Thank you in advance :) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dealing with parentheses within variable names
On 28/02/2013 11:08 AM, Jesus Munoz Serrano wrote: Dear all I'm having some problems with a data set that has parenthesis within the variable names. A example of this kind of variable names is the following: fBodyGyroskewness()Z The case is that R is having a lot of troubles to identify the variable (probably it does understand it like a function). I've tried (among other things) to remove the parenthesis from the name using the following command: names(dataFrame) - sub((),, names(dataFrame)) but It didn't work. Sorry if it's a silly issue but I would really appreciate if anybody could help me. Thank you very much. R shouldn't have trouble with names like that, but a lot of packages will (e.g. the ones that construct strings and call parse() on them). If you find functions in base R that object to those names, I think we'd like to fix them. If the functions are in contributed packages, your mileage may vary. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Iteration through a list in R
1. I have forwarded this to the list in order to increase your chance of getting a response. I hope that is OK. 2. I would have thought that by putting in the effort to understand the tutorial is how a complete beginner advances beyond that stage. Cheers, Bert On Thu, Feb 28, 2013 at 1:43 PM, Sahana Srinivasan sahanasrinivasan...@gmail.com wrote: Um. Yes. I wouldn't have posted without having looked stuff up. Most documentation is written in a way that is a little tough for a complete beginner to understand. On Thu, Feb 28, 2013 at 9:41 PM, Bert Gunter gunter.ber...@gene.com wrote: Have you read An Introduction to R (ships with R) or other of the many web tutorials. If not, please do so before posting. -- Bert On Thu, Feb 28, 2013 at 4:30 AM, Sahana Srinivasan sahanasrinivasan...@gmail.com wrote: Hello :) I'm just starting out with R and would appreciate your help with a couple of problems I am running into. I have used Sys.glob to get a list of all filenames having a particular file extension (in my case, *.txt) I would now like to use this list in the following manner: I would like to use each filename from the list and open that file into a tab separated matrix and proceed. How can I go about iterating through each filename in the list and then opening each of the files? I believe as.matrix can be used to open the txt file as a table, is that correct? I know these are beginner queries but I would love your help. Thank you in advance :) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Iteration through a list in R
On Feb 28, 2013, at 4:30 AM, Sahana Srinivasan wrote: Hello :) I'm just starting out with R and would appreciate your help with a couple of problems I am running into. You do need to work through the examples in Introduction to R I have used Sys.glob to get a list of all filenames having a particular file extension (in my case, *.txt) When posting to rhelp you should offer code as well as a description. I would now like to use this list in the following manner: I would like to use each filename from the list and open that file into a tab separated matrix and proceed. ?read.delim Matrix is sometimes used as a generic English word describing a regular arrangement of data. When discussing the R language, you should use it only when talking about a specific sort of data-object which will return TRUE for: is.matrix(object). And then depending on whether you actually want a matrix or will be satisfied by the data-frame object that read.delim would have returned, you may or may not need: ?data.matrix How can I go about iterating through each filename in the list and then opening each of the files? lapply( fil_list, read.delim) I believe as.matrix can be used to open the txt file as a table, is that correct? No. Please read the help page for `as.matrix` more carefully. It does not take a file or connection argument. I know these are beginner queries but I would love your help. Thank you in advance :) -- David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Question concerning directory/path names
This seems like a very basic question so I have searched the FAQ site, several manuals, and the R-Seek site as well as Googling for an answer but can't seem to come up with one. I am trying to import an Excel file that resides on a University network. The path name of the file is to a network drive and includes blank spaces (e.g. K:/science/next directory science2/mydata/). The setwd() works and I am able to actually see the files in the directory on the network but for some reason the RODBC, GDATA and XlsReadWrite functions do not seem to be able to find the files. Does anyone know if these functions able to read path names with blank spaces? The available documentation doesn't seem to indicate one way or another. Note that I can't change the path name because they are setup by University network administrators. Obviously it may be some sort of syntax error with my coding of the functions (I'm in the process of learning R) but I am not going to ask for help with that a! nd I would like to eliminate the possibility that it is simply the path names. I have not tried conversion to .csv and then importing which I would prefer not to do. Thanks in advance for any help. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] data grouping and fitting mixed model with lme function
Dear all,  I have data from the following experimental design and trying to fit a mixed model with lme function according to following steps but struggling. Any help is deeply appreciated.  1) Experimental design: I have 40 plants each of which has 4 clones. Each clone planted to one of 4 blocks. Phenotypes were collected from each clone for 3 consecutive years. I have genotypes of plants. I need to relate phenotype to genotype.  2) I am reading data from a file with âread.tableâ function. Then grouping data as: my.Data-groupedData( phenotype ~ Block | PlantID, data = as.data.frame( Data ) )  3) I want to fit Genotype + Year + Genotype:Year as fixed effect. Block + PlantID + Block.PlantID as random effect.  I feel my data grouping is incorrect as model fitting do not work properly.  Any help regarding data grouping and model fitting is deeply appreciated.  Kind Regards  Seyit Ali  Dr. Seyit Ali KAYIS Selcuk University, Faculty of Agriculture Kampus/Konya, Turkey Tel: +90 332 223 2830 Mobile: +90 535 587 1139 Greetings from Konya, Turkey http://www.ziraat.selcuk.edu.tr/skayis/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] using a personal template for new R scripts
Does anyone know if there's an easy facility to create and specify a template file to be used for new R scripts? I found myself creating this function which works well (in RStudio on Windows). newR = function(filename=tempfile(tmpdir='.',fileext='.R'), open=TRUE) { template = paste(Sys.getenv('R_USER'), 'R_template.R', sep='/') lines = readLines(template) lines = sub('Sys.time', format(Sys.time(), '%A, %d %B %Y'), lines) lines = sub('getwd', getwd(), lines) lines = sub('R.version.string', R.version.string, lines) writeLines(lines, filename) if (open) shell.exec(filename) filename } Rather than the default of an empty file, it would be good practice to start with a structured template script. Such a template might contain opening comments (author, date, project folder, aims, inputs, outputs etc.) and section comment headings for the various components of what a script does (load packages, get data, process data, produce outputs). cheers, Steve __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] put strip below the panel (dotplot)
On 2013-02-28 04:20, Elaine Kuo wrote: Hello I am using lattice dotplot and I would like to put the strip under the panel. I found the code “strip” is for the strip above the panel, and “strip.left” for the strip left to the panel. Please kindly advise how to write the code for the strip under the panel Thank you Elaine I don't think that this is trivial. I would just use panel.text() and panel.rect() to create my own strips. [I do wonder why you would want to have the strips at the bottom - seems unnatural to me.] Here's a start, using the iris data: dotplot(Sepal.Length ~ Petal.Length | Species, data=iris, layout = c(3, 1), ylim = c(-2, 37),## adjust y-range to leave a bit ## of space at bottom strip = FALSE, ## omit top strips panel = function(...){ cp - current.panel.limits() stripheight - (cp$ylim[2] - cp$ylim[1]) / 25 ## may have to adjust the '25' xleft - cp$xlim[1] xright - cp$xlim[2] ybottom - cp$ylim[1] ytop - cp$ylim[1] + stripheight lab - levels(iris$Species)[panel.number()] panel.dotplot(...) panel.rect(xleft, ybottom, xright, ytop, fill = bisque) panel.text(x = (xleft + xright) / 2, y = (ybottom + ytop) / 2, labels = lab) }) Peter Ehlers __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] resizing panels but some strip letters disappeared (dotplot)
Hello, I am using library(latticeExtra) resizePanels to have better visual display in dotplot (lattice). However, some panels became smaller and the strip letters of those panels were partially missing. Please kindly advise how to keep all strip letters remaining when resizing panels. Thank you. Elaine [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Results from clogit out of range?
On Feb 28, 2013, at 5:26 AM, Miss SHENG Lisha wrote: I still don't think the exp(lp)/(1+exp(lp)) gonna work. Since this is conditional logit model, while this formula is only used in unconditional ones. By using this, one neglects the information based on stratum. Though I don't know how to solve it to. I am also working on a project on this and I do hope there's someone explaining this problem. Will that be a possibility that the phat can never be estimated as we never know the individual intercept? [[alternative HTML version deleted]] (You are requested to post in palin text.) This appears to be addressed to a thread that appeared almost three years ago. I suspect you have not read all the way to the end of the thread: https://stat.ethz.ch/pipermail/r-help/2010-April/235956.html -- David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] query labels in iplot() (or other interactive scatterplot)
The HWidentify and HTKidentify functions in the TeachingDemos package let you specify a label for each point, then that label is displayed when you hover over that point with the mouse (and it goes away when you move the mouse away from that point). On Thu, Feb 28, 2013 at 8:36 AM, Agustin Lobo agustin.l...@ictja.csic.eswrote: By Ctr-moving the cursor over a point in an iplot() scatterplot (package iplots) it is possible to check the exact x,y coordinates of a given point. Is it possible to check a text label for that point as well? (i.e., the same info that would get printed on the graphic using text(x,y, labels=v) or with identify(x,y,labels), but I do not want to get the labels permanently plotted on the graphic) Thanks -- -- Dr. Agustin Lobo Institut de Ciencies de la Terra Jaume Almera (CSIC) Lluis Sole Sabaris s/n 08028 Barcelona Spain Tel. 34 934095410 Fax. 34 934110012 e-mail agustin.l...@ictja.csic.es https://sites.google.com/site/aloboaleu/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using a personal template for new R scripts
On 02/28/2013 05:40 PM, Steve Taylor wrote: Does anyone know if there's an easy facility to create and specify a template file to be used for new R scripts? I found myself creating this function which works well (in RStudio on Windows). newR = function(filename=tempfile(tmpdir='.',fileext='.R'), open=TRUE) { template = paste(Sys.getenv('R_USER'), 'R_template.R', sep='/') lines = readLines(template) lines = sub('Sys.time', format(Sys.time(), '%A, %d %B %Y'), lines) lines = sub('getwd', getwd(), lines) lines = sub('R.version.string', R.version.string, lines) writeLines(lines, filename) if (open) shell.exec(filename) filename } Rather than the default of an empty file, it would be good practice to start with a structured template script. Such a template might contain opening comments (author, date, project folder, aims, inputs, outputs etc.) and section comment headings for the various components of what a script does (load packages, get data, process data, produce outputs). The ProjectTemplate CRAN module might be helpful. I don't know if it works well with RStudio, but it does offer an entire project template: http://cran.r-project.org/web/packages/ProjectTemplate/index.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Issue attaching a dataset
thanks a lot. works!!! On Tue, Feb 26, 2013 at 7:58 AM, Prof Brian Ripley rip...@stats.ox.ac.ukwrote: On 26/02/2013 09:55, Milan Bouchet-Valat wrote: Le lundi 25 février 2013 à 20:26 -0300, Pablo Menese a écrit : I use to work whit stata dataframe, so, when I use R I type read.dta Until today I do that without any problem, after type: mydata-read.dta(C:/dropbox/**dataframe.dta) attach(mydata) Everything works great... but today, when I typed: mydata-read.dta(C:/dropbox/**dataframe.dta) attach(mydata) Appeared: Error in substr(these, 1L, 6L) : invalid multibyte string at 'f1' I searched in google and nothing. Can anyone help me? To be clear: the error appears when running read.dta(), not when calling attach(), right? And the C:/dropbox/dataframe.dta that fails today is different from the one that worked yesterday? Are you able to read it in Stata? Also, please provide the output of sessionInfo(). Note that Stata say 4. Strings use ASCII encoding. (in the URL linked from ?read.dta). We have seen exceptions in the past, but as the format has no way to record the encoding (it is ASCII, right?), read.dta can only read files in the native encoding. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~**ripley/http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] issue creating a subset
I'm performing item response theory with eRm packages I am excluding the persons that doesn't fit in the infit/outfit persons. for that I created a condition. then I have to create a new subset or matrix but with the condition. So: ORIGINAL matrix-cbind(item1, item2, item3, item4) IF I PERFORM A head(matrix) item1 item2 item3 item4 3 2 3 1 3 1 2 4 THEN I CREATE THE LOGIC CONDITION z-thing==T THEN I TRY TO CREATE THE NEW MATRIX BUT WITH THE CONDITION matrix2-cbind(item1[z==T], item2[z==T], item3[z==T], item4[z==T]) THE ISSUE IS THAT IF I PERFORM A head(matrix2) I1I2 I3 I4 3 2 3 1 3 1 2 4 The names of the columns change at all. CAN ANYONE HELP ME TO KEEP THE SAME NAMES? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] issue creating a subset
On 03/01/2013 12:53 PM, Pablo Menese wrote: I'm performing item response theory with eRm packages I am excluding the persons that doesn't fit in the infit/outfit persons. for that I created a condition. then I have to create a new subset or matrix but with the condition. So: ORIGINAL matrix-cbind(item1, item2, item3, item4) IF I PERFORM A head(matrix) item1 item2 item3 item4 3 2 3 1 3 1 2 4 THEN I CREATE THE LOGIC CONDITION z-thing==T THEN I TRY TO CREATE THE NEW MATRIX BUT WITH THE CONDITION matrix2-cbind(item1[z==T], item2[z==T], item3[z==T], item4[z==T]) THE ISSUE IS THAT IF I PERFORM A head(matrix2) I1I2 I3 I4 3 2 3 1 3 1 2 4 The names of the columns change at all. CAN ANYONE HELP ME TO KEEP THE SAME NAMES? Hi Pablo, If I understand what you are doing, you are taking the scenic route. Say you have a matrix of scores: scoremat-matrix(sample(1:4,40,TRUE),ncol=4) and a vector specifying whether each person is in or out: z-sample(c(TRUE,FALSE),10,TRUE) all you have to do is: scoremat2-scoremat2[z,] Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Ploting different values with different colors
Hello I am trying to plot a 20 x 20 grid of points with the colors of each point refering to percent cover of that specific point So basically the point are all the same size and their position on the graph is base on their coordinates (x,y). I want the color (a grey scale from white=0 to black =100) to represent the values of each of these point (cover) Here is what my data looks like x y cover A1 0 95 3.0 A2 5 95 0.5 A3 10 9510.0 ...etc Up to now I have tried plot(Q.xy[,1],Q.xy[,2],pch=16, cex=2.6, col=heat.colors(8)[x[,3]]) I put 8 after heat colors because their are 8 different values in my cover column My problem is that I only get one color out this line of code. Regardless of which number I put after heat.colors I always have the same quadrats colored with only one color. Any idea of how to get 8 colors in my graph? and how to make sure they are associated with the good cover values? Thanks Benoit Gendreau-Berthiaume PhD Candidate Department of Renewable Resources University of Alberta [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Results from clogit out of range?
I do appreciate this answer. I heard that in SAS, conditional logistic model do predictions in the same way. However, this formula can only deal with in-sample predictions. How about the out-of-sample one? Is it like one of the former responses by Thomas, say, it's impossible to do the out-of-sample prediction?? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Extracting coefficients of covariates in a LME-model
Hi all, I have created a linear mixed-effects model using lmer. My dependent variable is comp.score and my main independent variable is delay.type, a repeated-measures within-subject variable (2 levels: Synch and Asynch, order counter-balanced across participants). I had a series of covariates that were included in the initial model and used a step-wise process to produce the most parsimonious model (two covariates age and PLE). The final model was: disem-lmer(comp.score~delay.type+age+PLE+(1|id), data=Disembodiment) The first 5 rows of the data frame appeared as follows: head(Disembodiment) id comp comp.score delay.type sex age yrs.edu PLE fds bds 4 C01 Disembodiment 1.3846685 Synch f 56 14 0 8 6 5 C01 Disembodiment 0.3782303 Asynch f 56 14 0 8 6 12 C02 Disembodiment 1.4691870 Asynch f 48 15 0 12 11 16 C02 Disembodiment 1.5863690 Synch f 48 15 0 12 11 22 C03 Disembodiment -1.3751083 Asynch m 26 15 0 13 12 23 C03 Disembodiment -0.4114244 Synch m 26 15 0 13 12 I am at the point where I am creating the plots for the data and I want to display the effects of each covariate on my dependent variable (a separate plot for each covariate), which would be achieved by finding the linear equation for each covariate and plotting it. e.g. with(Disembodiment, plot(age, comp.score, ylab=Component Score, xlab=Age (years))) abline(coef(disem)) ## this doesnt work but as an example My question is how do I obtain this information from my model? When I use summary(disem), I can see the slopes easily enough and I understand that the intercept is the overall mean for the data, and not the intercept for the covariates age and PLE. Do I need to alter my model in order to calculate separate intercepts for each of the covariates and, if so, how? Thanks for your help! -- Kyran Graham (PhD Candidate) School of Medicine Pharmacology, University of Western Australia (M510) 35 Stirling Highway Crawley, WA 6009 Centre for Clinical Research in Neuropsychiatry, Graylands Hospital Private Bag No 1 Claremont, WA 6910 Phone: 9347 6430 Email: graha...@student.uwa.edu.au [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Select first element of each factor and convert to NA
Hi all, I have a dataframe of the following type: DayPlace dendrometermax 1 1 1 4684 2 1 1 4831 .. 1 1 2 2486 2 1 2 2596 . 1 2 1 6987 2 2 1 6824 I need the first element of each dendrometer as NA, so every time R calculates max for a new dendrometer (independently of the place), starts with NA, like this: DayPlace dendrometermax 1 1 1 NA 2 1 1 4831 .. 1 1 2 NA 2 1 2 2596 . 1 2 1 NA 2 2 1 6824 Could you also let me know I could calculate MEAN of the max column for each dendrometer within each ring (sapply, aggregate?) instead of calculating mean for the entire max column? Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Returning index of vector element matching specific value
Thanks for the reply AK. From R FAQ 7.31: The only numbers that can be represented exactly in R's numeric type are integers and fractions whose denominator is a power of 2 I'm not sure though that this is the problem here, does this statement apply to only floating point numbers? Is 0.15 a floating point number? Also the dummy code I provided above works for 0.1, which is 1/10, but not 0.15, which is 3/20, yet neither of these fractions has a denominator that is a power of 2, of if FAQ 7.31 is to be read literally, neither of these fractions can be accurately represented yet one still works in the test. I will cast the vector to character and go on from there - but it would be great if I could understand this a bit more. Cheers, Dave -- View this message in context: http://r.789695.n4.nabble.com/Returning-index-of-vector-element-matching-specific-value-tp4659952p4659955.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Returning index of vector element matching specific value
Thanks very much AK so indeed they are floats! I'll be more careful next time when performing equality comparisons. Cheers, Dave -- View this message in context: http://r.789695.n4.nabble.com/Returning-index-of-vector-element-matching-specific-value-tp4659952p4659959.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Ploting different values with different colors
Hi -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Benoit Gendreau-Berthiaume Sent: Friday, March 01, 2013 12:54 AM To: r-help@r-project.org Subject: [R] Ploting different values with different colors Hello I am trying to plot a 20 x 20 grid of points with the colors of each point refering to percent cover of that specific point So basically the point are all the same size and their position on the graph is base on their coordinates (x,y). I want the color (a grey scale from white=0 to black =100) to represent the values of each of these point (cover) Here is what my data looks like x y cover A1 0 95 3.0 A2 5 95 0.5 A3 10 9510.0 ...etc Up to now I have tried plot(Q.xy[,1],Q.xy[,2],pch=16, cex=2.6, col=heat.colors(8)[x[,3]]) I Well, you did not provide much info to let us help you. What is e.g. x[,3]? I can only guess, that it is the same as cover variable. If yes, you need to change it to ordered factor, if you want to use it for selection. something like sel.col-ordered(x[,3]) plot(Q.xy[,1],Q.xy[,2],pch=16, cex=2.6, col=heat.colors(8)[as.numeric(sel.col)]) can do what you want if there is really only 8 unique values. You could also consider some graphic devices which can use alpha transparency ??alpha Regards Petr put 8 after heat colors because their are 8 different values in my cover column My problem is that I only get one color out this line of code. Regardless of which number I put after heat.colors I always have the same quadrats colored with only one color. Any idea of how to get 8 colors in my graph? and how to make sure they are associated with the good cover values? Thanks Benoit Gendreau-Berthiaume PhD Candidate Department of Renewable Resources University of Alberta [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Select first element of each factor and convert to NA
Hi -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Cesar Terrer Sent: Friday, March 01, 2013 4:21 AM To: r-help@r-project.org Subject: [R] Select first element of each factor and convert to NA Hi all, I have a dataframe of the following type: DayPlace dendrometermax 1 1 1 4684 2 1 1 4831 .. 1 1 2 2486 2 1 2 2596 . 1 2 1 6987 2 2 1 6824 I need the first element of each dendrometer as NA, so every time R calculates max for a new dendrometer (independently of the place), starts with NA, like this: DayPlace dendrometermax 1 1 1 NA 2 1 1 4831 .. 1 1 2 NA 2 1 2 2596 . 1 2 1 NA 2 2 1 6824 Just as a curiosity, do you want to change max value for a Day 1 to NA? If yes, DF$max[DF$Day==1] - NA shall work. Could you also let me know I could calculate MEAN of the max column for each dendrometer within each ring (sapply, aggregate?) instead of calculating mean for the entire max column? ?aggregate or maybe ?ave Regards Petr Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.