Re: [R] position of the end of a text file
I think I have it and my apologies for spamming the list. I should not work this late on Sunday :-) I think that it should be as.integer(regexpr("$$", my.text.vector) 2011/10/16 Henri-Paul Indiogine : > > I tried the following > > as.integer(regexpr("??", my.text.vector) -- Henri-Paul Indiogine Curriculum & Instruction Texas A&M University TutorFind Learning Centre Email: hindiog...@gmail.com Skype: hindiogine Website: http://people.cehd.tamu.edu/~sindiogine __ 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] position of the end of a text file
Hi! I need to find the position of the last character (could be empty space) of a vector of text files (my.text.vector) that I have read into R. I tried Google, but all I have found needs a pattern. I tried the following as.integer(regexpr("??", my.text.vector) but it returns 1 or even the correct number, but not consistently. I understand that ?? is an operator, thus should not be used but itself. Any ideas? Thanks, Henri-Paul -- Henri-Paul Indiogine Curriculum & Instruction Texas A&M University TutorFind Learning Centre Email: hindiog...@gmail.com Skype: hindiogine Website: http://people.cehd.tamu.edu/~sindiogine __ 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] right justify right-axis tick values in lattice
Hi, You could also pad the text labels with phantom 0s, ghostrighter <- function(x, ...){ n <- sapply(x, nchar) nmax <- max(n) padaone <- function(ii){ si <- paste(rep("0", length= nmax - n[ii]), collapse="") as.expression(bquote(phantom(.(si)) * .(x[ii]) )) } sapply(seq_along(x), padaone) } ## ghostrighter(c(1, 23, 145)) panel.right<- function(x, y, ...) { panel.barchart(x, y, ...) print(x);print(y) panel.axis(side="right", at=pretty(y), lab=ghostrighter(pretty(y)), outside=TRUE) } mybar<- function(...) { args<- list(...) args$par.settings=list(clip=list(panel="off")) args$par.settings$layout.widths$axis.key.padding<- 4 do.call("barchart", args) } mybar(c(1,10,100,10,1) ~ "abcd", panel=panel.right, ylab.right="right") HTH, baptiste On 17 October 2011 13:12, Paul Murrell wrote: > Hi > > On 16/10/2011 6:17 p.m., Richard M. Heiberger wrote: >> >> How can I right justify the right-axis tick values? They appear in the >> example below as left-justified. >> >> I have tried several different ways and all fail in different ways. >> >> The example below creates the right axis tick value with no attempt at >> adjustment. >> >> alternates I have tried are >> 1. formatting the values. This doesn't work because they are in a >> proportional font and the blanks >> are too narrow. >> >> 2. gsub all leading " " characters into two " " characters. This >> overcompenates because a blank >> is slightly wider than half a digit width. >> >> I prefer to keep the default font. I am willing to go to a fixed width >> font >> (courier for example), but I haven't >> figured out the incantation to make that work in graphics. >> >> here is my example: >> >> panel.right<- function(x, y, ...) { >> panel.barchart(x, y, ...) >> print(x);print(y) >> panel.axis(side="right", at=pretty(y), outside=TRUE) >> } >> mybar<- function(...) { >> args<- list(...) >> args$par.settings=list(clip=list(panel="off")) >> args$par.settings$layout.widths$axis.key.padding<- 4 >> do.call("barchart", args) >> } >> mybar(c(1,10,100,10,1) ~ "abcd", panel=panel.right, ylab.right="right") > > You could do this ... > > library(grid) > oldx <- grid.get("plot_01.ticklabels.right.panel.1.1")$x > grid.edit("plot_01.ticklabels.right.panel.1.1", > just="right", > x=oldx + stringWidth("000")) > > Paul > >> >> >> thanks >> Rich >> >> [[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. > > -- > Dr Paul Murrell > Department of Statistics > The University of Auckland > Private Bag 92019 > Auckland > New Zealand > 64 9 3737599 x85392 > p...@stat.auckland.ac.nz > http://www.stat.auckland.ac.nz/~paul/ > > __ > 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] How to plot CI's (llim ulim) on ecodist mgram
It is good to provide the code but please make sure it is reproducible? e.g. XZ is not defined in mgram(XY,XZ)? Weidong Gu On Sun, Oct 16, 2011 at 7:10 PM, Nevil Amos wrote: > I would like to put confidence intervals on a mantel corellogram > they are already calculated in the pmgram object but I am unsure how I get > the x value in order to plot them? > > package(ecodist) > X<-1:100 > Y<-rnorm(1:100) > Z<-rnorm(1:100) > XY<-dist(data.frame(X,Y)) > YX<-dist(data.frame(Y,X)) > my.mgram<-mgram(XY,XZ) > plot(my.mgram) > print(my.mgram) >> print(my.mgram) > $mgram > lag ngroup mantelr pval llim ulim > [1,] 3.770055 672 0.500012737 0.001 0.49689923 0.504301550 > [2,] 11.310165 691 0.383960457 0.001 0.38000201 0.387324434 > [3,] 18.850274 584 0.232086251 0.001 0.22670074 0.237501735 > [4,] 26.390384 587 0.114097397 0.001 0.10243901 0.122973735 > [5,] 33.930494 463 -0.003113351 0.835 -0.01928101 0.008839295 > [6,] 41.470603 468 -0.106354446 0.001 -0.12682280 -0.089539628 > [7,] 49.010713 357 -0.181250278 0.001 -0.20154017 -0.164863572 > [8,] 56.550823 348 -0.266397615 0.001 -0.28498271 -0.251134864 > [9,] 64.090933 252 -0.298705798 0.001 -0.31421396 -0.284154643 > [10,] 71.631042 228 -0.353134525 0.001 -0.36468910 -0.341422330 > [11,] 79.171152 147 -0.337181781 0.001 -0.34854961 -0.322161075 > [12,] 86.711262 108 -0.334465576 0.001 -0.35500933 -0.309763543 > [13,] 94.251371 43 -0.238965642 0.001 -0.26437371 -0.196038662 > > $resids > [1] NA > > attr(,"class") > [1] "mgram" > > > Thanks > > Nevil Amos > > __ > 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] Opening Screen
On 17/10/11 12:12, Matt Curcio wrote: Greetings All, What is the procedure to make the open screen for R silent. I would to have my opening screen in Ubuntu 10.04 linux open to an empty terminal. Instead of the list of licenses and version of R that is being run. By the way, I am using RStudio as well. I have entered the following lines into my '/home/user/.Rprofile' but this is more of a 'cheat' ;) to me. .First<- function(){ cat(rep("\n",10)) } If you are starting from the command line, type R -q # q for quiet. On my (Ubuntu) system ``man R'' tells me this. 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.
[R] simultaneously maximizing two independent log likelihood functions using mle2
Hello, I have a log likelihood function that I was able to optimize using mle2. I have two years of the data used to fit the function and I would like to fit both years simultaneously to test if the model parameter estimates differ between years, using likelihood ratio tests and AIC. Can anyone give advice on how to do this? My likelihood functions are long so I'll use the tadpole predation example from Ben Bolker's book, Ecological Data and Models in R (p. 268-270). library(emdbook) data(ReedfrogFuncresp) attach(ReedfrogFuncresp) # Holling Type II Equation holling2.pred = function(N0, a, h, P, T) { a * N0 * P * T/(1 + a * h * N0) } # Negative log likelihood function NLL.holling2 = function(a, h, P = 1, T = 1) { -sum(dbinom(Killed, prob = a * T * P/(1 + a * h * Initial), size = Initial, log = TRUE)) } # MLE statement FFR.holling2 = mle2(NLL.holling2, start = list(a = 0.012, h = 0.84), data = list(T = 14, P = 3)) I have my negative log likelihood function setup similarly to the above example. Again, my goal is to simultaneously estimate parameters from the same function for two years, such that I can test if the parameters from the two years are different. Perhaps an important difference from the above example is that I am using a multinomial distribution (dmnom) because my data are trinomially distributed. Any help would be greatly appreciated. Adam Zeilinger -- Adam Zeilinger Ph. D Candidate Conservation Biology Program University of Minnesota Saint Paul, MN www.linkedin.com/in/adamzeilinger __ 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] mgp and axis title positions
Hi all, I consider myself a somewhat experienced user of R, but have struggled with this for a while now. to the point where I just end up pulling the entire graph together in powerpoint and fixing it up from there. How does one adjust the horizontal/vertical positions of axis titles? I've tried using mgp in the par function, but that never produces anything satisfactory as x and y-axes are modified simultaneously. It would appear that you can specify mgp in the axis function, but that doesn't seem to work at all. It is particularly frustrating when you need to adjust axis title positions separately for x and y axes - i.e. specify mgp twice - once for each axis within the axis function. But this doesn't seem to work - is this a bug? Cheers, Ben [[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] Suppressing the Intercept in lm() when using a dataframe for the model
Well don't I feel silly now. Thanks for the help! -- View this message in context: http://r.789695.n4.nabble.com/Suppressing-the-Intercept-in-lm-when-using-a-dataframe-for-the-model-tp3910327p3910443.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Beginner's question about ptrend. What package to use in R and a general explanation of the statistics.
Hello I'm wanting to understand more about ptrend (a statistical explanation via an internet website if possible) and also to know what package in R would produce a ptrend. Appreciate any help I can get on this as I'm trying to read and understand an epidemiological paper and data and reproduce similar results for my own understanding. Thanks Meredith [[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] Which function to use: grep, replace, substr etc.?
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of David Winsemius > Sent: Sunday, October 16, 2011 1:59 PM > To: Jeff Newmiller > Cc: r-help@r-project.org; syrvn > Subject: Re: [R] Which function to use: grep, replace, substr etc.? > > > On Oct 16, 2011, at 1:32 PM, Jeff Newmiller wrote: > > > Note that "male" comes before "female" in your data frame. > > --- > > Jeff Newmiller The . . Go Live... > > > > > syrvn wrote: > > > > Hi, > > > > thanks for the tip! I do it as follows now but I still have a > > problem I do > > not understand: > > > > > > abbrvs <- data.frame(c("peter", "name", "male", "female"), > > c("P", "N", "m", "f")) > > > > colnames(abbrvs) <- c("pattern", "replacement") > > > > str <- "My name is peter and I am male" > > > > for(m in 1:nrow(abbrvs)) { > > str <- sub(abbrvs$pattern[m], abbrvs$replacement[m], str, > > fixed=TRUE) > > print(str) > > } > > > > > > This works perfectly fine as I get: "My N is P and I am m" > > > > However, when I replace male by female then I get the following: "My > > N is P > > and I am fem" > > > > but I want to have "My N is P and I am f". > > > > Even with the parameter fixed=true I get the same result. Why is that? > > Because "male" is in "female? This reminds me of a comment on a > posting I made this morning on SO. > http://stackoverflow.com/questions/7782113/counting-keyword-occurrences-in-r > > The problem was slightly different, but the greppish principle was > that in order to match only complete words, you need to specific "^", > "$" or " " at each end of the word: > > dataset <- c("corn", "cornmeal", "corn on the cob", "meal") > grep("^corn$|^corn | corn$", dataset) > [1] 1 3 You can use the 2 character sequences "\\<" and "\\>" to match the beginning and end of a "word" (where the match takes up zero characters): > dataset <- c("corn", "cornmeal", "corn on the cob", "popcorn", "this corn is sweet") > grep("^corn$|^corn | corn$", dataset) [1] 1 3 > grep("\\", dataset) [1] 1 3 5 > gsub("\\", "CORN", dataset) [1] "CORN" [2] "cornmeal" [3] "CORN on the cob" [4] "popcorn" [5] "this CORN is sweet" If your definition of a "word" is more expansive it gets complicated. E.g., if words might include letters, numbers, and periods but not underscores or anything else, you could use: > gsub("(^|[^.[:alpha:][:digit:]])?corn($|[^.[:alpha:][:digit:]])?", "\\1CORN.BY.ITSELF\\2", c("corn.1", "corn_2", " corn", "4corn", "1.corn")) [1] "corn.1" [2] "CORN.BY.ITSELF_2" [3] " CORN.BY.ITSELF" [4] "4corn" [5] "1.corn" Moving to perl regular expressions would probably make this simpler. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > > In such cases you may want to look at the gsubfn package. It offers > higher level matching functions and I think strapply might be more > efficient and expressive here. I can imagine construction in a loop > such as yours, but you would probably want to build a pattern outside > the sub() call. > > After struggling to fix your loop (and your data.frame which > definitely should not be using factor variables), I am even more > convinced you should be learning "gubfn" facilities. (Tate out the > debugging print statements.) > > > abbrvs <- data.frame(c("peter", "name", "male", "female"), > + c(" P ", " N ", " m ", " f "), stringsAsFactors=FALSE) > > > > colnames(abbrvs) <- c("pattern", "replacement") > > > > for(m in 1:nrow(abbrvs)) { patt <- paste("^",abbrvs$pattern[m], "$| > ", > + abbrvs$pattern[m], " | ", > + abbrvs$pattern[m], "$", sep="") > + print(c( patt, abbrvs$replacement[m])) > + str <- sub(patt, abbrvs$replacement[m], str) > + print(str) > + } > [1] "^peter$| peter | peter$" " P " > [1] "My name is P and I am female" > [1] "^name$| name | name$" " N " > [1] "My N is P and I am female" > [1] "^male$| male | male$" " m " > [1] "My N is P and I am female" > [1] "^female$| female | female$" " f " > [1] "My N is P and I am f " > > -- > > David Winsemius, MD > Heritage Laboratories > West Hartford, CT > > __ > 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] ecdf
Thanks for the clarification. I stand corrected. Dennis On Sun, Oct 16, 2011 at 5:48 PM, gj wrote: > David is right. I am looking for the ecfd for fs$numstudents. The > other column is just an id. > > I guess I don't know how to read the R documentation when it comes to > functions. > > looking at the documentation, i now notice that it says "Compute an > empirical cummulative distribution function and not a vector. > > But still I would had assumed that in ecdf(x) ... the x is the argument. > > So ecdf(fs$numstudents)(unique(fs$numstudents)) > === == > function arguments > > Yes? But I can't read that from the documentation? I suspect it has > something to those dots in the arguments which I don't > understand. > > Why it says usage ecdf(x) when it's clearly not the case? > > I don't get it. > > Gawesh > > > On Sun, Oct 16, 2011 at 11:02 PM, David Winsemius > wrote: >> >> On Oct 16, 2011, at 3:53 PM, Dennis Murphy wrote: >> >>> Hi: >>> >>> I don't understand what you're attempting to do. Wouldn't courseid be >>> a categorical variable with a numeric label? If that is so, why are >>> you trying to compute an EDF? An EDF computes cumulative relative >>> frequency of a random variable, which by definition is numeric. If we >>> were talking about EDFs for a distribution of student course grades on >>> a numeric point system by course, that would make some sense, but I >>> don't see how the course IDs themselves qualify as being on an >>> interval scale of measurement. Could you clarify your intent? >> >> Huh? gawesh asked for ecdf on numstrudents (not courseid) ... pretty >> clearly a numeric value for which an ECDF should make sense. >> >> -- >> David. >> >> -- >>> >>> Dennis >>> >>> On Sun, Oct 16, 2011 at 8:31 AM, gj wrote: Hi, Newbie here. I read the R for Beginners but i still don't get this. I have the following data (this is just an example) in a CSV file: courseid numstudents 101 209 141 13 246 140 263 8 321 10 361 10 364 28 365 25 366 23 367 34 I load my data using: fs<-read.csv(file="C:\\num_students_inallmodules.csv",header=T, sep=',') I want to get the ecdf. So, I looked at the ?ecdf which says usage:ecdf(x) So I expected ecdf(fs$numstudents) to work Instead it just returned: Call: ecdf(fs$numstudents) x[1:210] = 1, 2, 3, ..., 3717, 4538 After Googling, got this to work: ecdf(fs$numstudents)(unique(fs$numstudents)) But I don't understand why if the ?ecdf says usage is ecdf(x) ... I need to use ecdf(fs$numstudents)(unique(fs$numstudents)) to get this to work? Can somebody explain this to me? Regards Gawesh __ 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. >> >> David Winsemius, MD >> Heritage Laboratories >> West Hartford, CT >> >> > __ 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] ecdf
Hi, On Sun, Oct 16, 2011 at 8:48 PM, gj wrote: > David is right. I am looking for the ecfd for fs$numstudents. The > other column is just an id. > > I guess I don't know how to read the R documentation when it comes to > functions. > > looking at the documentation, i now notice that it says "Compute an > empirical cumulative distribution function and not a vector. > > But still I would had assumed that in ecdf(x) ... the x is the argument. ecdf() is the function you're calling. x is your vector, for which you want the ECDF. num.ecdf <- ecdf(fs$numstudents) There. That's the ECDF. But the ECDF is a *function* - that's what the F stands for, after all. If you're looking for the percentiles for your data, you might try: num.ecdf(fs$numstudents) You might also try working the examples given in ?ecdf yourself, so that you can see exactly what's going on before you try it with your own data. > So ecdf(fs$numstudents)(unique(fs$numstudents)) > === == > function arguments > > Yes? But I can't read that from the documentation? I suspect it has > something to those dots in the arguments which I don't > understand. Yes. That's the condensed version of what I just proposed, done in one step, instead of two. The two-step version is definitely in the help. It doesn't have anything to do with the ..., which simply allow for other arguments to be passed. > Why it says usage ecdf(x) when it's clearly not the case? > > I don't get it. Clearly that is the case. ecdf(x) returns the empirical cumulative distribution *function* of the vector of data x. I'm not entirely sure what you think you should be getting. Perhaps if you explained your expectations, the list would be able to help you achieve them. Sarah > Gawesh > > > On Sun, Oct 16, 2011 at 11:02 PM, David Winsemius > wrote: >> >> On Oct 16, 2011, at 3:53 PM, Dennis Murphy wrote: >> >>> Hi: >>> >>> I don't understand what you're attempting to do. Wouldn't courseid be >>> a categorical variable with a numeric label? If that is so, why are >>> you trying to compute an EDF? An EDF computes cumulative relative >>> frequency of a random variable, which by definition is numeric. If we >>> were talking about EDFs for a distribution of student course grades on >>> a numeric point system by course, that would make some sense, but I >>> don't see how the course IDs themselves qualify as being on an >>> interval scale of measurement. Could you clarify your intent? >> >> Huh? gawesh asked for ecdf on numstrudents (not courseid) ... pretty >> clearly a numeric value for which an ECDF should make sense. >> >> -- >> David. >> >> -- >>> >>> Dennis >>> >>> On Sun, Oct 16, 2011 at 8:31 AM, gj wrote: Hi, Newbie here. I read the R for Beginners but i still don't get this. I have the following data (this is just an example) in a CSV file: courseid numstudents 101 209 141 13 246 140 263 8 321 10 361 10 364 28 365 25 366 23 367 34 I load my data using: fs<-read.csv(file="C:\\num_students_inallmodules.csv",header=T, sep=',') I want to get the ecdf. So, I looked at the ?ecdf which says usage:ecdf(x) So I expected ecdf(fs$numstudents) to work Instead it just returned: Call: ecdf(fs$numstudents) x[1:210] = 1, 2, 3, ..., 3717, 4538 After Googling, got this to work: ecdf(fs$numstudents)(unique(fs$numstudents)) But I don't understand why if the ?ecdf says usage is ecdf(x) ... I need to use ecdf(fs$numstudents)(unique(fs$numstudents)) to get this to work? Can somebody explain this to me? Regards Gawesh __ 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. >> >> David Winsemius, MD >> Heritage Laboratories >> West Hartford, CT >> >> > > __ > 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. > -- Sarah Goslee http://www.stringpage.com http://www.sarahgoslee.com http://www.fu
Re: [R] ecdf
David is right. I am looking for the ecfd for fs$numstudents. The other column is just an id. I guess I don't know how to read the R documentation when it comes to functions. looking at the documentation, i now notice that it says "Compute an empirical cummulative distribution function and not a vector. But still I would had assumed that in ecdf(x) ... the x is the argument. So ecdf(fs$numstudents)(unique(fs$numstudents)) === == function arguments Yes? But I can't read that from the documentation? I suspect it has something to those dots in the arguments which I don't understand. Why it says usage ecdf(x) when it's clearly not the case? I don't get it. Gawesh On Sun, Oct 16, 2011 at 11:02 PM, David Winsemius wrote: > > On Oct 16, 2011, at 3:53 PM, Dennis Murphy wrote: > >> Hi: >> >> I don't understand what you're attempting to do. Wouldn't courseid be >> a categorical variable with a numeric label? If that is so, why are >> you trying to compute an EDF? An EDF computes cumulative relative >> frequency of a random variable, which by definition is numeric. If we >> were talking about EDFs for a distribution of student course grades on >> a numeric point system by course, that would make some sense, but I >> don't see how the course IDs themselves qualify as being on an >> interval scale of measurement. Could you clarify your intent? > > Huh? gawesh asked for ecdf on numstrudents (not courseid) ... pretty > clearly a numeric value for which an ECDF should make sense. > > -- > David. > > -- >> >> Dennis >> >> On Sun, Oct 16, 2011 at 8:31 AM, gj wrote: >>> >>> Hi, >>> Newbie here. I read the R for Beginners but i still don't get this. >>> >>> I have the following data (this is just an example) in a CSV file: >>> >>> courseid numstudents >>> 101 209 >>> 141 13 >>> 246 140 >>> 263 8 >>> 321 10 >>> 361 10 >>> 364 28 >>> 365 25 >>> 366 23 >>> 367 34 >>> >>> I load my data using: >>> >>> fs<-read.csv(file="C:\\num_students_inallmodules.csv",header=T, sep=',') >>> >>> I want to get the ecdf. So, I looked at the ?ecdf which says >>> usage:ecdf(x) >>> >>> So I expected ecdf(fs$numstudents) to work >>> >>> Instead it just returned: >>> Call: ecdf(fs$numstudents) >>> x[1:210] = 1, 2, 3, ..., 3717, 4538 >>> >>> After Googling, got this to work: >>> ecdf(fs$numstudents)(unique(fs$numstudents)) >>> >>> But I don't understand why if the ?ecdf says usage is ecdf(x) ... I >>> need to use ecdf(fs$numstudents)(unique(fs$numstudents)) to get this >>> to work? >>> >>> Can somebody explain this to me? >>> >>> Regards >>> Gawesh >>> >>> __ >>> 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. > > David Winsemius, MD > Heritage Laboratories > West Hartford, CT > > __ 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] What does \Sexpr[results=rd]{} exactly mean in Rd?
Hi, I have spent a few hours on the R-exts manual and the documentation of parse_Rd() (as well as the PDF document in the references), but I still have not figured out what results=rd means. I thought I could use an R code fragment to create an Rd fragment dynamically. Here is an example, in which I was expected the output to be a describe list in HTML, but it turns out not to be true. (I was actually building a package with Rd's containing \Sexpr{} instead of really using Rd2HTML(); the content was not rendered after I run R CMD build.) des <- "\\describe{\\item{def}{ghi}}" con <- textConnection(c("\\title{abc}\\name{abc}", "\\details{\\Sexpr[results=rd,stage=build]{des}}")) z <- parse_Rd(con) Rd2HTML(z, stages = "build") close(con) R: abc abcR Documentation abc Details defghi > sessionInfo() R version 2.13.2 (2011-09-30) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] tools stats graphics grDevices utils datasets methods [8] base other attached packages: [1] devtools_0.4 loaded via a namespace (and not attached): [1] RCurl_1.6-10 Thanks! Regards, Yihui -- Yihui Xie Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA __ 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] glmmadmb help
[cc'ed back to r-help] I've started to take a look, and there's nothing immediately obvious about the problem with the fit (the warnings and errors are about a "non-positive-definite Hessian", which usually means an overfitted/poorly identified model) -- still working on whether there's a way to get more useful information. As it turns out, glmmADMB's default behavior in this case is to just stop with an error. I could re-write things to allow it to tell you something (but it wouldn't be able to compute standard errors on the parameters). It's conceivable that you might get slightly different results (different enough that it would work in one case and fail in another) on different operating systems, different machines, etc. ... because the failure is really a case of something that's numerically on the edge, where negative values in a vector are illegal but the minimum might be -1e-7 in one case and 1e-7 in another -- i.e., different but just by numeric "fuzz". My first response to this sort of problem would be to see if you can simplify the model slightly -- e.g. are both random effects really necessary, etc.. Several things do suggest themselves from looking at the data: * your response variable ranges from 0 to 1, which doesn't make much sense for a negative binomial response distribution. What does your response variable represent? If it is overdispersed *binomial* data, then (1) you need to use something like a beta-binomial distribution instead (unfortunately not yet implemented in glmmADMB, but if you were desperate I might give it a whack) (2) you need to specify the denominators -- just the proportions won't do it. If you have just proportions, then you might be looking for a beta distributed response (although that has its own trickiness in dealing with response values of exactly 0 or 1). * your "Site" variable has only two levels. That makes dealing with it as a random variable extremely questionable (from a *philosophical* or experimental-design point of view it may be sensible to treat it as a random variable, but not practical: see http://glmm.wikidot.com/faq for discussion of this point). When I made it a fixed effect instead, I got (apparently) sensible results. * The plot of the data (see attached, I hope the attachment gets through) makes it clear that you have some potential balance problems. In section/segment combinations (C-D) x (3-5) you have only a few (often only one) observation in the (beetle.ev=1) case. Mild lack of balance is no problem in mixed models, but such severe lack of balance can be. (Note this doesn't guarantee a problem, but it is one of the factors that makes estimation less stable.) On 11-10-16 05:41 PM, James McCarthy wrote: > Hello Ben, > > Many thanks for offering to help with this. I have attached the data set > “stain.csv”. I have also attached a script file with all of the code > that should (hopefully) work for you. > > What I would like to get working is the function: > > nbin1<-glmmadmb(stainp~beetle.ev+Caged*Section/Segment+(1|Site)+(1|Log.code),data=dat1,family="nbinom") > > The issue is with the “beetle.ev” column (binary, presence/absence of > insects). Below is some code that works, all that has changed is that > “beetle.ev” is substituted with “Test”. This one works, and has some > data in pretty much the same format as “beetle.ev” (as you can see in > the .csv file). > > nbin2<-glmmadmb(stainp~Test+Caged*Section/Segment+(1|Site)+(1|Log.code),data=dat1,family="nbinom") > > For the life of me, I can’t figure out what’s wrong with this column. > > Thanks again for talking a look at it. > > Cheers, > James > > > James McCarthy > MSc (Ecology) candidate, University of Canterbury > c/o Scion (New Zealand Forest Research Institute) > Forestry Rd, P.O. Box 29-237, Christchurch, New Zealand > Ph: (03) 364 2987 Ext. 7820 > Cell: 027 268 5506 > Fax: (03) 364 2812 > Email: james.mccar...@scionresearch.com or > james.mccar...@pg.canterbury.ac.nz > www.scionresearch.com > > This email may be confidential and subject to legal privilege, it may > not reflect the views of the University of Canterbury, and it is not > guaranteed to be virus free. If you are not an intended recipient, > please notify the sender immediately and erase all copies of the message > and any attachments. > > Please refer to http://www.canterbury.ac.nz/emaildisclaimer for more > information. > ## install.packages("glmmADMB",repos="http://glmmadmb.r-forge.r-project.org/repos",type="source";) library(glmmADMB) dat1<-read.csv("stain.csv") ## attach(dat1) ## dangerous names(dat1) dat1<-transform(dat1, Site=factor(Site), ## BMB: fixed typo Log.code=factor(Log.code), Caged=factor(Caged), beetle.ev=factor(beetle.ev), Test=factor(Test)) ## BMB: this could also be done via colClasses= argument to read.csv nbin1<-glmmadmb(stainp~beetle.ev+Caged*Section/Segment+(1|S
Re: [R] right justify right-axis tick values in lattice
Hi On 16/10/2011 6:17 p.m., Richard M. Heiberger wrote: How can I right justify the right-axis tick values? They appear in the example below as left-justified. I have tried several different ways and all fail in different ways. The example below creates the right axis tick value with no attempt at adjustment. alternates I have tried are 1. formatting the values. This doesn't work because they are in a proportional font and the blanks are too narrow. 2. gsub all leading " " characters into two " " characters. This overcompenates because a blank is slightly wider than half a digit width. I prefer to keep the default font. I am willing to go to a fixed width font (courier for example), but I haven't figured out the incantation to make that work in graphics. here is my example: panel.right<- function(x, y, ...) { panel.barchart(x, y, ...) print(x);print(y) panel.axis(side="right", at=pretty(y), outside=TRUE) } mybar<- function(...) { args<- list(...) args$par.settings=list(clip=list(panel="off")) args$par.settings$layout.widths$axis.key.padding<- 4 do.call("barchart", args) } mybar(c(1,10,100,10,1) ~ "abcd", panel=panel.right, ylab.right="right") You could do this ... library(grid) oldx <- grid.get("plot_01.ticklabels.right.panel.1.1")$x grid.edit("plot_01.ticklabels.right.panel.1.1", just="right", x=oldx + stringWidth("000")) Paul > thanks Rich [[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. -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 p...@stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to plot CI's (llim ulim) on ecodist mgram
Hi, The x value you want is lag from my.mgram$mgram You can use lines() to add them to the plot. Sarah On Sun, Oct 16, 2011 at 7:10 PM, Nevil Amos wrote: > I would like to put confidence intervals on a mantel corellogram > they are already calculated in the pmgram object but I am unsure how I get > the x value in order to plot them? > > package(ecodist) > X<-1:100 > Y<-rnorm(1:100) > Z<-rnorm(1:100) > XY<-dist(data.frame(X,Y)) > YX<-dist(data.frame(Y,X)) > my.mgram<-mgram(XY,XZ) > plot(my.mgram) > print(my.mgram) >> print(my.mgram) > $mgram > lag ngroup mantelr pval llim ulim > [1,] 3.770055 672 0.500012737 0.001 0.49689923 0.504301550 > [2,] 11.310165 691 0.383960457 0.001 0.38000201 0.387324434 > [3,] 18.850274 584 0.232086251 0.001 0.22670074 0.237501735 > [4,] 26.390384 587 0.114097397 0.001 0.10243901 0.122973735 > [5,] 33.930494 463 -0.003113351 0.835 -0.01928101 0.008839295 > [6,] 41.470603 468 -0.106354446 0.001 -0.12682280 -0.089539628 > [7,] 49.010713 357 -0.181250278 0.001 -0.20154017 -0.164863572 > [8,] 56.550823 348 -0.266397615 0.001 -0.28498271 -0.251134864 > [9,] 64.090933 252 -0.298705798 0.001 -0.31421396 -0.284154643 > [10,] 71.631042 228 -0.353134525 0.001 -0.36468910 -0.341422330 > [11,] 79.171152 147 -0.337181781 0.001 -0.34854961 -0.322161075 > [12,] 86.711262 108 -0.334465576 0.001 -0.35500933 -0.309763543 > [13,] 94.251371 43 -0.238965642 0.001 -0.26437371 -0.196038662 > > $resids > [1] NA > > attr(,"class") > [1] "mgram" > > > Thanks > > Nevil Amos -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to plot CI's (llim ulim) on ecodist mgram
I would like to put confidence intervals on a mantel corellogram they are already calculated in the pmgram object but I am unsure how I get the x value in order to plot them? package(ecodist) X<-1:100 Y<-rnorm(1:100) Z<-rnorm(1:100) XY<-dist(data.frame(X,Y)) YX<-dist(data.frame(Y,X)) my.mgram<-mgram(XY,XZ) plot(my.mgram) print(my.mgram) > print(my.mgram) $mgram lag ngroup mantelr pvalllim ulim [1,] 3.770055672 0.500012737 0.001 0.49689923 0.504301550 [2,] 11.310165691 0.383960457 0.001 0.38000201 0.387324434 [3,] 18.850274584 0.232086251 0.001 0.22670074 0.237501735 [4,] 26.390384587 0.114097397 0.001 0.10243901 0.122973735 [5,] 33.930494463 -0.003113351 0.835 -0.01928101 0.008839295 [6,] 41.470603468 -0.106354446 0.001 -0.12682280 -0.089539628 [7,] 49.010713357 -0.181250278 0.001 -0.20154017 -0.164863572 [8,] 56.550823348 -0.266397615 0.001 -0.28498271 -0.251134864 [9,] 64.090933252 -0.298705798 0.001 -0.31421396 -0.284154643 [10,] 71.631042228 -0.353134525 0.001 -0.36468910 -0.341422330 [11,] 79.171152147 -0.337181781 0.001 -0.34854961 -0.322161075 [12,] 86.711262108 -0.334465576 0.001 -0.35500933 -0.309763543 [13,] 94.251371 43 -0.238965642 0.001 -0.26437371 -0.196038662 $resids [1] NA attr(,"class") [1] "mgram" Thanks Nevil Amos __ 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] Suppressing the Intercept in lm() when using a dataframe for the model
On Oct 16, 2011, at 3:55 PM, Cliff Clive wrote: It's easy to run a linear regression on a simple model without an intercept just by doing this: lm(y ~ x1 + x2 -1) Is there a similar trick to suppress the intercept when your model is in a large dataframe and you don't want to write out the names of individual columns? Something along the lines of: lm(y ~ . -1, data=dfrm) But you do need to offer specific examples to get specific answers. (Hence the usual advice to read the Posting Guide.) -- David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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] position of first and last axis tick
On Oct 16, 2011, at 3:08 PM, Jonas Stein wrote: Hi, how can i set the position of the first and last tick to the borderline of a plot? The plot should look like this one made in Gnuplot [1]. Gnu-R adds some space between the ticks and the end of plot. do you mean like this? plot(rnorm(25),rnorm(25), xaxs ="i", yaxs="i", xlim=c(-2,2), ylim=c(-2,2)) [1] http://commons.wikimedia.org/wiki/File:Atmospheric_radiocarbon_1954-1993.svg kind regards, -- Jonas Stein __ 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. David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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] ecdf
On Oct 16, 2011, at 3:53 PM, Dennis Murphy wrote: Hi: I don't understand what you're attempting to do. Wouldn't courseid be a categorical variable with a numeric label? If that is so, why are you trying to compute an EDF? An EDF computes cumulative relative frequency of a random variable, which by definition is numeric. If we were talking about EDFs for a distribution of student course grades on a numeric point system by course, that would make some sense, but I don't see how the course IDs themselves qualify as being on an interval scale of measurement. Could you clarify your intent? Huh? gawesh asked for ecdf on numstrudents (not courseid) ... pretty clearly a numeric value for which an ECDF should make sense. -- David. -- Dennis On Sun, Oct 16, 2011 at 8:31 AM, gj wrote: Hi, Newbie here. I read the R for Beginners but i still don't get this. I have the following data (this is just an example) in a CSV file: courseid numstudents 101 209 141 13 246 140 263 8 321 10 361 10 364 28 365 25 366 23 367 34 I load my data using: fs<-read.csv(file="C:\\num_students_inallmodules.csv",header=T, sep=',') I want to get the ecdf. So, I looked at the ?ecdf which says usage:ecdf(x) So I expected ecdf(fs$numstudents) to work Instead it just returned: Call: ecdf(fs$numstudents) x[1:210] = 1, 2, 3, ..., 3717, 4538 After Googling, got this to work: ecdf(fs$numstudents)(unique(fs$numstudents)) But I don't understand why if the ?ecdf says usage is ecdf(x) ... I need to use ecdf(fs$numstudents)(unique(fs$numstudents)) to get this to work? Can somebody explain this to me? Regards Gawesh __ 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. David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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] Which function to use: grep, replace, substr etc.?
On Oct 16, 2011, at 1:32 PM, Jeff Newmiller wrote: Note that "male" comes before "female" in your data frame. --- Jeff Newmiller The . . Go Live... syrvn wrote: Hi, thanks for the tip! I do it as follows now but I still have a problem I do not understand: abbrvs <- data.frame(c("peter", "name", "male", "female"), c("P", "N", "m", "f")) colnames(abbrvs) <- c("pattern", "replacement") str <- "My name is peter and I am male" for(m in 1:nrow(abbrvs)) { str <- sub(abbrvs$pattern[m], abbrvs$replacement[m], str, fixed=TRUE) print(str) } This works perfectly fine as I get: "My N is P and I am m" However, when I replace male by female then I get the following: "My N is P and I am fem" but I want to have "My N is P and I am f". Even with the parameter fixed=true I get the same result. Why is that? Because "male" is in "female? This reminds me of a comment on a posting I made this morning on SO. http://stackoverflow.com/questions/7782113/counting-keyword-occurrences-in-r The problem was slightly different, but the greppish principle was that in order to match only complete words, you need to specific "^", "$" or " " at each end of the word: dataset <- c("corn", "cornmeal", "corn on the cob", "meal") grep("^corn$|^corn | corn$", dataset) [1] 1 3 In such cases you may want to look at the gsubfn package. It offers higher level matching functions and I think strapply might be more efficient and expressive here. I can imagine construction in a loop such as yours, but you would probably want to build a pattern outside the sub() call. After struggling to fix your loop (and your data.frame which definitely should not be using factor variables), I am even more convinced you should be learning "gubfn" facilities. (Tate out the debugging print statements.) > abbrvs <- data.frame(c("peter", "name", "male", "female"), +c(" P ", " N ", " m ", " f "), stringsAsFactors=FALSE) > > colnames(abbrvs) <- c("pattern", "replacement") > for(m in 1:nrow(abbrvs)) { patt <- paste("^",abbrvs$pattern[m], "$| ", + abbrvs$pattern[m], " | ", + abbrvs$pattern[m], "$", sep="") + print(c( patt, abbrvs$replacement[m])) + str <- sub(patt, abbrvs$replacement[m], str) + print(str) + } [1] "^peter$| peter | peter$" " P " [1] "My name is P and I am female" [1] "^name$| name | name$" " N " [1] "My N is P and I am female" [1] "^male$| male | male$" " m " [1] "My N is P and I am female" [1] "^female$| female | female$" " f " [1] "My N is P and I am f " -- David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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] Suppressing the Intercept in lm() when using a dataframe for the model
On Sun, Oct 16, 2011 at 12:55 PM, Cliff Clive wrote: > It's easy to run a linear regression on a simple model without an intercept > just by doing this: > > lm(y ~ x1 + x2 -1) > > > Is there a similar trick to suppress the intercept when your model is in a > large dataframe and you don't want to write out the names of individual > columns? Yep...same trick. > > -- > View this message in context: > http://r.789695.n4.nabble.com/Suppressing-the-Intercept-in-lm-when-using-a-dataframe-for-the-model-tp3910327p3910327.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. > -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] position of first and last axis tick
Hi, how can i set the position of the first and last tick to the borderline of a plot? The plot should look like this one made in Gnuplot [1]. Gnu-R adds some space between the ticks and the end of plot. [1] http://commons.wikimedia.org/wiki/File:Atmospheric_radiocarbon_1954-1993.svg kind regards, -- Jonas Stein __ 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] Suppressing the Intercept in lm() when using a dataframe for the model
It's easy to run a linear regression on a simple model without an intercept just by doing this: lm(y ~ x1 + x2 -1) Is there a similar trick to suppress the intercept when your model is in a large dataframe and you don't want to write out the names of individual columns? -- View this message in context: http://r.789695.n4.nabble.com/Suppressing-the-Intercept-in-lm-when-using-a-dataframe-for-the-model-tp3910327p3910327.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] Help in kmeans
Hi, no, don't use kmeans with factors. The kmeans algorithm does, besides other things, calculate the mean of the k clusters. But you don't get a useful mean from factors, because the internally used integers are arbitrary. In this case its 1,2 and 3. But it could be 42, 7 and 10 as well, which would change any calculation of a mean. Thats why the kmeans() function wants numeric matrices. Maybe you should think about how kmeans works: http://en.wikipedia.org/wiki/K-means_clustering Christoph 2011/10/16 raji sankaran > Hi, > > Thank you .. The information was very helpful. > > Yes.It was meant to be centers=3.Even with that , kmeans gives error if we > give the index of Species columns. > > So, *is it ok to use kmeans for String data by using cbind*.But, kmeans*works > even if we give a column which contains distinct String values > *. > For example,a column which contains names like country names.How does this > work in such cases? Is it expected behavior? > > Country > --- > England > Germany > China > > Thanks, > Raji > > > On Mon, Oct 17, 2011 at 1:02 AM, Christoph Molnar < > christoph.mol...@googlemail.com> wrote: > >> Hi, >> >> I suspect your column Species is of class "factor" (as it is in R's built >> in iris dataset). >> This means that in your case Species is an integer vector with the >> additional information of the levels names. kmeans is internally calling >> as.matrix(), which creates a character matrix of your dataframe, because one >> column is factor and you get an error. >> >> After binding the columns with cbind, the result is an integer matrix with >> the Species columns as the internal levels (1,2 and 3 instead of "setosa" >> "versicolor" "virginica" ) and kmeans is not throwing a error any more. >> >> Furthermore kmeans wouldn't work in the first case, because there is no >> "size=" - argument in kmeans. You probably meant centers=3. >> For additional information try ?kmeans >> >> Christoph >> >> >> 2011/10/16 Raji >> >>> Hi All, >>> >>> For executing kmeans for Iris, we found that there were 2 different >>> ways. >>> >>> dataFrame <- read.csv("c:/Iris.csv",header=T) >>> >>> 1. kmeans_model<-kmeans(dataFrame[1:5],size=3) >>> *This gave an error as it had Species which is a String column as one >>> of >>> the inputs* >>> >>> 2.attach(dataFrame) >>> >>> >>> kmeans_model<-kmeans(cbind(SepalLength,SepalWidth,PetalLength,PetalWidth,Species),3) >>> >>> * But this command worked and gave output.* >>> >>> Does this mean that kmeans can accept String inputs also? >>> >>> Can you please let me know how the second command works? >>> >>> Thanks in advance. >>> >>> Regards, >>> Raji >>> >>> -- >>> View this message in context: >>> http://r.789695.n4.nabble.com/Help-in-kmeans-tp3430433p3909552.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. >>> >> >> > [[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] Editor for RD file?
On Sun, Oct 16, 2011 at 7:20 AM, Duncan Murdoch wrote: > On 11-10-16 8:57 AM, Bogaso Christofer wrote: >> >> Dear all, can somebody please update me on what could be the best editor >> to >> write and edit the RD files? I need to something with syntax highlighter, >> auto-completion etc (like Notepad++ for R etc.). Currently I am using >> plain >> Notepad however expect something which could be more professional. > > I believe ESS does syntax highlighting for Rd files if you use Emacs. Yes, it does. It is also nice because it runs R, so if I am writing examples in the Rd files, I can run them directly. Here is the little blurb regarding the major mode for Rd files: (Rd-mode) Major mode for editing R documentation source files. This mode makes it easier to write R documentation by helping with indentation, doing some of the typing for you (with Abbrev mode) and by showing keywords, strings, etc. in different faces (with Font Lock mode on terminals that support it). Cheers, Josh > > You could probably modify a LaTeX syntax highlighter for any other editor to > work with Rd files: the syntax is quite similar. > > 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. > -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.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] ecdf
Hi: I don't understand what you're attempting to do. Wouldn't courseid be a categorical variable with a numeric label? If that is so, why are you trying to compute an EDF? An EDF computes cumulative relative frequency of a random variable, which by definition is numeric. If we were talking about EDFs for a distribution of student course grades on a numeric point system by course, that would make some sense, but I don't see how the course IDs themselves qualify as being on an interval scale of measurement. Could you clarify your intent? Dennis On Sun, Oct 16, 2011 at 8:31 AM, gj wrote: > Hi, > Newbie here. I read the R for Beginners but i still don't get this. > > I have the following data (this is just an example) in a CSV file: > > courseid numstudents > 101 209 > 141 13 > 246 140 > 263 8 > 321 10 > 361 10 > 364 28 > 365 25 > 366 23 > 367 34 > > I load my data using: > > fs<-read.csv(file="C:\\num_students_inallmodules.csv",header=T, sep=',') > > I want to get the ecdf. So, I looked at the ?ecdf which says usage:ecdf(x) > > So I expected ecdf(fs$numstudents) to work > > Instead it just returned: > Call: ecdf(fs$numstudents) > x[1:210] = 1, 2, 3, ..., 3717, 4538 > > After Googling, got this to work: > ecdf(fs$numstudents)(unique(fs$numstudents)) > > But I don't understand why if the ?ecdf says usage is ecdf(x) ... I > need to use ecdf(fs$numstudents)(unique(fs$numstudents)) to get this > to work? > > Can somebody explain this to me? > > Regards > Gawesh > > __ > 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] question: ragged array
Hi: Try this: ratok <- data.frame(Id = rep(1:3, 3:1), value = c(2, 3, 4, 2, 1, 5)) aggregate(value ~ Id, data = ratok, FUN = mean) Id value 1 1 3.0 2 2 1.5 3 3 5.0 aggregate() returns a data frame with the Id variable and mean(value). HTH, Dennis On Sun, Oct 16, 2011 at 6:53 AM, Helene Schreyer wrote: > Hello, > > > I have a big problem which I’m just not able to solve. > > > > I created the following mean value from the following dataset structure: > > > Id |value > > 1 | 2 > > 1 | 3 > > 1 | 4 > > 2 | 2 > > 2 | 1 > > 3 | 5 > > 4 | 3 > > etc.|etc. > > > > with the command: > > mean_rating <- tapply(ratok$value, ratok$project_id , mean,simplify = FALSE) > > > > this gives me a ragged array: > >> mean_rating [1] > > $`14` ###==project_id > > [1] 3.93 ###==mean value > > > > > >> dim (mean_rating) > > [1] 2214 > > > > I want to separate now the project_id from the mean value. So that I have > two separate columns (2 dimension). > > > > How can I separate a ragged array into two variables? > > > > > > > > *Additional information:* > > I need this information to put the mean value into another dataset > (“projok”) at the correct project_id. > > > > I would do that as follow: > > k=projok[,1] > > > > for(i in 1:2442) { > > projLineNb = which(mean_rating$project_id==k[i]) > > projok$mean[i] = mean_rating$value[projLineNb] > > } > > > > But with a ragged array I can not refer to project_id. Or is there a > possibility that I can refer to the project_id in a ragged array? > > > >> mean_rating [[1]] > > [1] 3.93 ==I can refer to the value only > > > > Thank you very much > > Best, > > Helene > > [[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] Help in kmeans
Hi, Thank you .. The information was very helpful. Yes.It was meant to be centers=3.Even with that , kmeans gives error if we give the index of Species columns. So, *is it ok to use kmeans for String data by using cbind*.But, kmeans*works even if we give a column which contains distinct String values *. For example,a column which contains names like country names.How does this work in such cases? Is it expected behavior? Country --- England Germany China Thanks, Raji On Mon, Oct 17, 2011 at 1:02 AM, Christoph Molnar < christoph.mol...@googlemail.com> wrote: > Hi, > > I suspect your column Species is of class "factor" (as it is in R's built > in iris dataset). > This means that in your case Species is an integer vector with the > additional information of the levels names. kmeans is internally calling > as.matrix(), which creates a character matrix of your dataframe, because one > column is factor and you get an error. > > After binding the columns with cbind, the result is an integer matrix with > the Species columns as the internal levels (1,2 and 3 instead of "setosa" > "versicolor" "virginica" ) and kmeans is not throwing a error any more. > > Furthermore kmeans wouldn't work in the first case, because there is no > "size=" - argument in kmeans. You probably meant centers=3. > For additional information try ?kmeans > > Christoph > > > 2011/10/16 Raji > >> Hi All, >> >> For executing kmeans for Iris, we found that there were 2 different ways. >> >> dataFrame <- read.csv("c:/Iris.csv",header=T) >> >> 1. kmeans_model<-kmeans(dataFrame[1:5],size=3) >> *This gave an error as it had Species which is a String column as one of >> the inputs* >> >> 2.attach(dataFrame) >> >> >> kmeans_model<-kmeans(cbind(SepalLength,SepalWidth,PetalLength,PetalWidth,Species),3) >> >> * But this command worked and gave output.* >> >> Does this mean that kmeans can accept String inputs also? >> >> Can you please let me know how the second command works? >> >> Thanks in advance. >> >> Regards, >> Raji >> >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/Help-in-kmeans-tp3430433p3909552.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. >> > > [[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 in kmeans
Hi, I suspect your column Species is of class "factor" (as it is in R's built in iris dataset). This means that in your case Species is an integer vector with the additional information of the levels names. kmeans is internally calling as.matrix(), which creates a character matrix of your dataframe, because one column is factor and you get an error. After binding the columns with cbind, the result is an integer matrix with the Species columns as the internal levels (1,2 and 3 instead of "setosa" "versicolor" "virginica" ) and kmeans is not throwing a error any more. Furthermore kmeans wouldn't work in the first case, because there is no "size=" - argument in kmeans. You probably meant centers=3. For additional information try ?kmeans Christoph 2011/10/16 Raji > Hi All, > > For executing kmeans for Iris, we found that there were 2 different ways. > > dataFrame <- read.csv("c:/Iris.csv",header=T) > > 1. kmeans_model<-kmeans(dataFrame[1:5],size=3) > *This gave an error as it had Species which is a String column as one of > the inputs* > > 2.attach(dataFrame) > > > kmeans_model<-kmeans(cbind(SepalLength,SepalWidth,PetalLength,PetalWidth,Species),3) > > * But this command worked and gave output.* > > Does this mean that kmeans can accept String inputs also? > > Can you please let me know how the second command works? > > Thanks in advance. > > Regards, > Raji > > -- > View this message in context: > http://r.789695.n4.nabble.com/Help-in-kmeans-tp3430433p3909552.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. > [[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] need help in pausing a script
On Sun, 16-Oct-2011 at 09:08AM -0700, M3Mph15 wrote: |> Hey, I'm new to R. I wrote a script for doing several statistic tests and |> plot. is there any way to add a kind of pause function which halts script |> execution until a key is pressed. Please help fast if you can ?browser |> |> -- |> View this message in context: http://r.789695.n4.nabble.com/need-help-in-pausing-a-script-tp3909815p3909815.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. -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___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] need help in pausing a script
In addition to Michael's suggestion, if what you want to pause is the creation of graphs, set: par(ask = TRUE) see ?par for details. It makes it so that user input is required between each graph plotting. Cheers, Josh On Sun, Oct 16, 2011 at 9:08 AM, M3Mph15 wrote: > Hey, I'm new to R. I wrote a script for doing several statistic tests and > plot. is there any way to add a kind of pause function which halts script > execution until a key is pressed. Please help fast if you can Generally speaking, telling volunteers to respond "fast" is rather rude (also may hurt your chances of a response because it makes academics suspicious that it is for an assignment or homework due soon). At least some justification (e.g., I work at an animal rescue and we just saved 3000 baby whales, but we do not have facilities for all 3000 of them, have little funds and need to find the most cost effective way to get them to special whale vets all around the worldalso 35 need medical attention quickly, so I need to get this script working in the next 6 hours so they have time to make it to a treatment facility and receive life-saving care.) might make some of us feel better about prioritizing a response to you. > > -- > View this message in context: > http://r.789695.n4.nabble.com/need-help-in-pausing-a-script-tp3909815p3909815.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. > -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.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] need help in pausing a script
Perhaps something like this (stolen from the demo() code): readline("\nType \t to start : ") # If you don't want the auto-print "" and are running it interactively, a call to invisible() might help. Michael Weylandt On Sun, Oct 16, 2011 at 12:08 PM, M3Mph15 wrote: > Hey, I'm new to R. I wrote a script for doing several statistic tests and > plot. is there any way to add a kind of pause function which halts script > execution until a key is pressed. Please help fast if you can > > -- > View this message in context: > http://r.789695.n4.nabble.com/need-help-in-pausing-a-script-tp3909815p3909815.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] right justify right-axis tick values in lattice
Perfect. Thank you David. Since I almost always want right-axis numeric ticks to be right justified, I will include this function as part of the next version of the HH package (any day now), listing you as author. Would you consider sending this as a proposed patch to lattice? As a patch it might be necessary to make the justification direction an argument, rather than a hard-wired change. Rich On Sun, Oct 16, 2011 at 9:50 AM, David Winsemius wrote: > > On Oct 16, 2011, at 1:17 AM, Richard M. Heiberger wrote: > [[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] Which function to use: grep, replace, substr etc.?
Note that "male" comes before "female" in your data frame. --- Jeff Newmiller The . . Go Live... DCN: Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. syrvn wrote: Hi, thanks for the tip! I do it as follows now but I still have a problem I do not understand: abbrvs <- data.frame(c("peter", "name", "male", "female"), c("P", "N", "m", "f")) colnames(abbrvs) <- c("pattern", "replacement") str <- "My name is peter and I am male" for(m in 1:nrow(abbrvs)) { str <- sub(abbrvs$pattern[m], abbrvs$replacement[m], str, fixed=TRUE) print(str) } This works perfectly fine as I get: "My N is P and I am m" However, when I replace male by female then I get the following: "My N is P and I am fem" but I want to have "My N is P and I am f". Even with the parameter fixed=true I get the same result. Why is that? -- View this message in context: http://r.789695.n4.nabble.com/Which-function-to-use-grep-replace-substr-etc-tp3909871p3909922.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. [[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] Which function to use: grep, replace, substr etc.?
Hi, thanks for the tip! I do it as follows now but I still have a problem I do not understand: abbrvs <- data.frame(c("peter", "name", "male", "female"), c("P", "N", "m", "f")) colnames(abbrvs) <- c("pattern", "replacement") str <- "My name is peter and I am male" for(m in 1:nrow(abbrvs)) { str <- sub(abbrvs$pattern[m], abbrvs$replacement[m], str, fixed=TRUE) print(str) } This works perfectly fine as I get: "My N is P and I am m" However, when I replace male by female then I get the following: "My N is P and I am fem" but I want to have "My N is P and I am f". Even with the parameter fixed=true I get the same result. Why is that? -- View this message in context: http://r.789695.n4.nabble.com/Which-function-to-use-grep-replace-substr-etc-tp3909871p3909922.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] need help in pausing a script
Hey, I'm new to R. I wrote a script for doing several statistic tests and plot. is there any way to add a kind of pause function which halts script execution until a key is pressed. Please help fast if you can -- View this message in context: http://r.789695.n4.nabble.com/need-help-in-pausing-a-script-tp3909815p3909815.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] Which function to use: grep, replace, substr etc.?
On Oct 16, 2011, at 12:35 PM, syrvn wrote: Hello, I have a simple question but I don't know which method is best to use for my problem. I have the following strings: str1 <- "My_name_is_peter" str2 <- "what_is_your_surname_peter" I would like to apply predefined abbreviations for peter=p and name=n to both strings so that the new strings look like the followings: str1: "My_n_is_p" str2: "what_is_your_surn_p" Which method is the best to use for that particular problem? ?sub # on same page as grep > sub("(p)eter", "\\1", vec) [1] "My_name_is_p" "what_is_your_surname_p" -- David Winsemius, MD West Hartford, CT __ 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] Which function to use: grep, replace, substr etc.?
Hello, I have a simple question but I don't know which method is best to use for my problem. I have the following strings: str1 <- "My_name_is_peter" str2 <- "what_is_your_surname_peter" I would like to apply predefined abbreviations for peter=p and name=n to both strings so that the new strings look like the followings: str1: "My_n_is_p" str2: "what_is_your_surn_p" Which method is the best to use for that particular problem? syrvn -- View this message in context: http://r.789695.n4.nabble.com/Which-function-to-use-grep-replace-substr-etc-tp3909871p3909871.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] nlrq {quantreg}
The model _is_ linear in parameters, after the log transformation of the response, so you don't need nlrq. If you really want something like: y = exp(a + b x) + u then you need to make a token effort to look at the documentation. Here is another example: x <- exp(rnorm(50)) y <- exp(1 + .5*x) + rnorm(50) nlrq(y ~ exp(a + b * x), start = list(a = 2, b = 1)) Nonlinear quantile regression model: y ~ exp(a + b * x) data: parent.frame tau: 0.5 deviance: 15.39633 a b 1.0348673 0.4962638 Roger Koenker rkoen...@illinois.edu On Oct 16, 2011, at 3:59 AM, Julia Lira wrote: Dear all, I sent an email on Friday asking about nlrq {quantreg}, but I haven't received any answer. I need to estimate the quantile regression estimators of a model as: y = exp(b0+x'b1+u). The model is nonlinear in parameters, although I can linearise it by using log.When I write: fitnl <- nlrq(y ~ exp(x), tau=0.5) I have the following error: Error in match.call(func, call = cll) : invalid 'definition' argument Is there any way to estimate this model, or should I accept the following change: fitnl <- rq(log(y) ~ x, tau=0.5) ? Thanks in advance! Best, Julia [[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] ecdf
On Oct 16, 2011, at 11:31 AM, gj wrote: Hi, Newbie here. I read the R for Beginners but i still don't get this. I have the following data (this is just an example) in a CSV file: courseid numstudents 101 209 141 13 246 140 263 8 321 10 361 10 364 28 365 25 366 23 367 34 I load my data using: fs<-read.csv(file="C:\\num_students_inallmodules.csv",header=T, sep=',') I want to get the ecdf. So, I looked at the ?ecdf which says usage:ecdf(x) So I expected ecdf(fs$numstudents) to work Instead it just returned: Call: ecdf(fs$numstudents) x[1:210] = 1, 2, 3, ..., 3717, 4538 After Googling, got this to work: ecdf(fs$numstudents)(unique(fs$numstudents)) But I don't understand why if the ?ecdf says usage is ecdf(x) ... I need to use ecdf(fs$numstudents)(unique(fs$numstudents)) to get this to work? Can somebody explain this to me? ecdf() returns a function rather than a vector. You need to supply arguments to that function to get something that you recognize. Had you passed that function off to plot you would have seen that the information needed to calculate the plot is obviously "in there". If you go to the stepfun page you find that the knots function can recover some of htat information for display. > plot( ecdf(fs$numstudents) ) > knots( ecdf(fs$numstudents) ) [1] 8 10 13 23 25 28 34 140 209 If you count the knots you can deduce the quantile values (the "y- values") at which those "x-values" will start the step "dot-line" -- David Winsemius, MD West Hartford, CT __ 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] ecdf
Hi, Newbie here. I read the R for Beginners but i still don't get this. I have the following data (this is just an example) in a CSV file: courseid numstudents 101 209 141 13 246 140 263 8 321 10 361 10 364 28 365 25 366 23 367 34 I load my data using: fs<-read.csv(file="C:\\num_students_inallmodules.csv",header=T, sep=',') I want to get the ecdf. So, I looked at the ?ecdf which says usage:ecdf(x) So I expected ecdf(fs$numstudents) to work Instead it just returned: Call: ecdf(fs$numstudents) x[1:210] = 1, 2, 3, ..., 3717, 4538 After Googling, got this to work: ecdf(fs$numstudents)(unique(fs$numstudents)) But I don't understand why if the ?ecdf says usage is ecdf(x) ... I need to use ecdf(fs$numstudents)(unique(fs$numstudents)) to get this to work? Can somebody explain this to me? Regards Gawesh __ 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] glmmadmb help
chchjames windowslive.com> writes: > > Thanks for the reply Ben. I tried it with verbose=TRUE, and got about 7 pages > of a word doc as an output, that ended with the error "Error in > glmmadmb(stainp ~ beetle.ev + Caged * Section/SegmentT + (1 | : > The function maximizer failed". > > I am not sure how I would best go about posting this, as you put it, > "voluminous output", but I am happy to post/send that and a similar data-set > somewhere. > > How would I best go about this? Don't bother with the output, please send me the data and any accompanying R code (you can find my e-mail easily). 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] Help in kmeans
Hi All, For executing kmeans for Iris, we found that there were 2 different ways. dataFrame <- read.csv("c:/Iris.csv",header=T) 1. kmeans_model<-kmeans(dataFrame[1:5],size=3) *This gave an error as it had Species which is a String column as one of the inputs* 2.attach(dataFrame) kmeans_model<-kmeans(cbind(SepalLength,SepalWidth,PetalLength,PetalWidth,Species),3) * But this command worked and gave output.* Does this mean that kmeans can accept String inputs also? Can you please let me know how the second command works? Thanks in advance. Regards, Raji -- View this message in context: http://r.789695.n4.nabble.com/Help-in-kmeans-tp3430433p3909552.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] background normalization in rma() in the affy package
Hi, i was looking into the documentation for the rma() function in affy() package, and was trying to figure out how exactly the background normalization is done. I read all three papers cited in the rma() documentation, but the most detailed explanation i could find was in Irizary et al., 2003, where they state that they compute B(PM_{ijn}) = E[s_{ijn} | PM_{ijn}] where s_{ijn} is assumed to be exponential, and bg_{ijn} is normal. I still don't understand what value is being computed here, neither am i clear on what the correction looks like. i.e. if s_{ijn} is an exponentially-distributed random variable, how is bg_{ijn} fit into this? 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] question: ragged array
if you set parameter simplify=TRUE, it returns a vector of the ragged mean. In your case, mean_rating <- tapply(ratok$value, ratok$project_id , mean,simplify = TRUE) df<-data.frame(ID=dimnames(mean_rating)[[1]], mean=mean_rating) Weidong Gu On Sun, Oct 16, 2011 at 9:53 AM, Helene Schreyer wrote: > Hello, > > > I have a big problem which I’m just not able to solve. > > > > I created the following mean value from the following dataset structure: > > > Id |value > > 1 | 2 > > 1 | 3 > > 1 | 4 > > 2 | 2 > > 2 | 1 > > 3 | 5 > > 4 | 3 > > etc.|etc. > > > > with the command: > > mean_rating <- tapply(ratok$value, ratok$project_id , mean,simplify = FALSE) > > > > this gives me a ragged array: > >> mean_rating [1] > > $`14` ###==project_id > > [1] 3.93 ###==mean value > > > > > >> dim (mean_rating) > > [1] 2214 > > > > I want to separate now the project_id from the mean value. So that I have > two separate columns (2 dimension). > > > > How can I separate a ragged array into two variables? > > > > > > > > *Additional information:* > > I need this information to put the mean value into another dataset > (“projok”) at the correct project_id. > > > > I would do that as follow: > > k=projok[,1] > > > > for(i in 1:2442) { > > projLineNb = which(mean_rating$project_id==k[i]) > > projok$mean[i] = mean_rating$value[projLineNb] > > } > > > > But with a ragged array I can not refer to project_id. Or is there a > possibility that I can refer to the project_id in a ragged array? > > > >> mean_rating [[1]] > > [1] 3.93 ==I can refer to the value only > > > > Thank you very much > > Best, > > Helene > > [[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] Editor for RD file?
On 11-10-16 8:57 AM, Bogaso Christofer wrote: Dear all, can somebody please update me on what could be the best editor to write and edit the RD files? I need to something with syntax highlighter, auto-completion etc (like Notepad++ for R etc.). Currently I am using plain Notepad however expect something which could be more professional. I believe ESS does syntax highlighting for Rd files if you use Emacs. You could probably modify a LaTeX syntax highlighter for any other editor to work with Rd files: the syntax is quite similar. 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] grouped lattice plot with overall regression line
As usual, try reading the Help files! ?panel.lmline -- Bert On Sun, Oct 16, 2011 at 6:50 AM, Weidong Gu wrote: > If you want to draw the global regression line in each panel, you can try > > xyplot(T~A|speaker,data=spk0,layout=c(4,5),type='p',groups=fns), > panel=function(x,y,...){ > panel.xyplot(x,y,...) > panel.abline(lm(y~x,data=spk0))}) > > Weidong Gu > > 2011/10/16 ì¡°íì : > > I'd like to draw a lattice plot with groups. The groups (the grouping > condition, fns) are successfully marked with separate symbols, using the > following code: > > > xyplot(T~A|speaker,groups=fns,pch=1:3,key=list(space="right",points=list(pch=1:3)),type=c("g","p","r")) > > Here's a hard part. This draws regression lines for each group in each > panel (there are three groups, so three regression lines show up in each > panel). But I want to have only one global regression line for all groups > together, still maintaining separate symbols for each group. > > I don't want to have individual regression lines for each group. > > I tried many things, with various panel functions, but I've never > succeeded. Could any expert help with this? I'd appreciate it greatly. The > closest I could find was something like the following, which didn't work for > me - anyways, it is supposed to draw by-group regression lines as well as > the global one. So this is not exactly I need. > > xyplot(T~A|speaker,data=spk0,layout=c(4,5),type='p',groups=fns), > > panel=function(x,y){ > > panel.superpose(x,y) > > panel.abline(lm(y~x))}), > > panel.groups=function(x,y,lty){ > > panel.xyplot(x,y,lty=lty) > > panel.abline(lm(y~x),lty=3)}) > > Thanks so 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. > > > > __ > 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 [[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] question: ragged array
Hello, I have a big problem which Im just not able to solve. I created the following mean value from the following dataset structure: Id |value 1 | 2 1 | 3 1 | 4 2 | 2 2 | 1 3 | 5 4 | 3 etc.|etc. with the command: mean_rating <- tapply(ratok$value, ratok$project_id , mean,simplify = FALSE) this gives me a ragged array: > mean_rating [1] $`14` ###==project_id [1] 3.93 ###==mean value > dim (mean_rating) [1] 2214 I want to separate now the project_id from the mean value. So that I have two separate columns (2 dimension). How can I separate a ragged array into two variables? *Additional information:* I need this information to put the mean value into another dataset (projok) at the correct project_id. I would do that as follow: k=projok[,1] for(i in 1:2442) { projLineNb = which(mean_rating$project_id==k[i]) projok$mean[i] = mean_rating$value[projLineNb] } But with a ragged array I can not refer to project_id. Or is there a possibility that I can refer to the project_id in a ragged array? > mean_rating [[1]] [1] 3.93 ==I can refer to the value only Thank you very much Best, Helene [[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] grouped lattice plot with overall regression line
If you want to draw the global regression line in each panel, you can try xyplot(T~A|speaker,data=spk0,layout=c(4,5),type='p',groups=fns), panel=function(x,y,...){ panel.xyplot(x,y,...) panel.abline(lm(y~x,data=spk0))}) Weidong Gu 2011/10/16 조혜선 : > I'd like to draw a lattice plot with groups. The groups (the grouping > condition, fns) are successfully marked with separate symbols, using the > following code: > xyplot(T~A|speaker,groups=fns,pch=1:3,key=list(space="right",points=list(pch=1:3)),type=c("g","p","r")) > Here's a hard part. This draws regression lines for each group in each panel > (there are three groups, so three regression lines show up in each panel). > But I want to have only one global regression line for all groups together, > still maintaining separate symbols for each group. > I don't want to have individual regression lines for each group. > I tried many things, with various panel functions, but I've never succeeded. > Could any expert help with this? I'd appreciate it greatly. The closest I > could find was something like the following, which didn't work for me - > anyways, it is supposed to draw by-group regression lines as well as the > global one. So this is not exactly I need. > xyplot(T~A|speaker,data=spk0,layout=c(4,5),type='p',groups=fns), > panel=function(x,y){ > panel.superpose(x,y) > panel.abline(lm(y~x))}), > panel.groups=function(x,y,lty){ > panel.xyplot(x,y,lty=lty) > panel.abline(lm(y~x),lty=3)}) > Thanks so 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. > __ 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] Use of ICA for sound
On Oct 16, 2011, at 1:44 AM, Noah Silverman wrote: > Hi, > > I'm looking at the "cocktail party" classic problem. > > I can see how to use ICA to separate the components. But, How do I then > create new wav files of the separated sounds so that they can be played? > FWIW you can play sounds directly without creating any files using play() from the audio package. Cheers, Simon > Thanks > > -- > Noah Silverman > UCLA Department of Statistics > 8208 Math Sciences Building > Los Angeles, CA 90095 > > > [[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.
[R] Editor for RD file?
Dear all, can somebody please update me on what could be the best editor to write and edit the RD files? I need to something with syntax highlighter, auto-completion etc (like Notepad++ for R etc.). Currently I am using plain Notepad however expect something which could be more professional. Thanks for your help. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] multicore combn
Just thought I'd let you know the following: In the gRbase package there is a function called combnPrim which does the same as combn but it is implemented in C - and is quite a bit faster than combn(). Regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] På vegne af jebyrnes [byr...@msi.ucsb.edu] Sendt: 16. oktober 2011 03:25 Til: r-help@r-project.org Emne: [R] multicore combn This is a 'rather than re-invent the wheel' post. Has anyone out there re-written combn so that it can be parallelized - with multicore, snow, or otherwise? I have a job that requires large numbers of combinations, and rather than get all of the index values, then crank it through mclapply, I was wondering if there was a way to just do this natively within a function. Just curious. Thanks! -Jarrett -- View this message in context: http://r.789695.n4.nabble.com/multicore-combn-tp3908633p3908633.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Use of ICA for sound
On 16.10.2011 07:44, Noah Silverman wrote: Hi, I'm looking at the "cocktail party" classic problem. I can see how to use ICA to separate the components. But, How do I then create new wav files of the separated sounds so that they can be played? Others suggested tuneR already for a former question. You can make a Wave object from the signal returned by ICA processing using tuneR and also write a wav filke with tuneR: See ?Wave and ?writeWave Best, Uwe Ligges Thanks -- Noah Silverman UCLA Department of Statistics 8208 Math Sciences Building Los Angeles, CA 90095 [[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] Custom Sort Character and Numeric
Here is another solution that gets the order you posted: > myArray <- c('AFP9','AFR9','TLQP7','AFS9','AFR8','AFP8','AFS7','TLQS8') > # create a sort key > key <- sub("^(.*)(.)(.)$", "\\3\\2\\1", myArray) > key [1] "9PAF" "9RAF" "7PTLQ" "9SAF" "8RAF" "8PAF" "7SAF" "8STLQ" > # sort, but don't get your output > myArray[order(key)] [1] "TLQP7" "AFS7" "AFP8" "AFR8" "TLQS8" "AFP9" "AFR9" "AFS9" > # to get your output, new key > newKey <- sub("^(.*)(.)(.)$", "\\1\\3\\2", myArray) > newKey [1] "AF9P" "AF9R" "TLQ7P" "AF9S" "AF8R" "AF8P" "AF7S" "TLQ8S" > myArray[order(newKey)] [1] "AFS7" "AFP8" "AFR8" "AFP9" "AFR9" "AFS9" "TLQP7" "TLQS8" > On Sun, Oct 16, 2011 at 4:47 AM, swonder03 wrote: > I"m trying to do a custom sort in this order: > > 1) Numeric digit furthest right; > 2) Alphabetical second furthest to the right; > 3) Alphabetical the rest of the string beginning with the first character; > > The example code I'm using is an array that follows: > > /myArray <- c('AFP9','AFR9','TLQP7','AFS9','AFR8','AFP8','AFS7','TLQS8')/ > > The output I desire is: > > />myArray > [1] "AFS7" "AFP8" "AFR8" "AFP9" "AFR9" "AFS9" "TLQP7" TLQS8" / > > What I'm thinking is writing a function that will order it by analyzing it > from right to left. Ideally there would be a way to look at the individual > strings like the formula in Excel "=RIGHT(cell, 1)" and drop the furthest > right then do the same thing to the next character. I've been looking into > custom sort for R and haven't found much. Any idea what this function would > look like? Possibly a while loop? Each string would have a length of at > least 3, possibly longer. Thank you in advance. > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Custom-Sort-Character-and-Numeric-tp3909058p3909058.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. > -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ 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] Custom Sort Character and Numeric
Try this, but I get a different order especially based on the last digit > myArray <- c('AFP9','AFR9','TLQP7','AFS9','AFR8','AFP8','AFS7','TLQS8') > # create a sort key > key <- sub("^(.*)(.)(.)$", "\\3\\2\\1", myArray) > key [1] "9PAF" "9RAF" "7PTLQ" "9SAF" "8RAF" "8PAF" "7SAF" "8STLQ" > # sort, but don't get your output > myArray[order(key)] [1] "TLQP7" "AFS7" "AFP8" "AFR8" "TLQS8" "AFP9" "AFR9" "AFS9" > On Sun, Oct 16, 2011 at 4:47 AM, swonder03 wrote: > I"m trying to do a custom sort in this order: > > 1) Numeric digit furthest right; > 2) Alphabetical second furthest to the right; > 3) Alphabetical the rest of the string beginning with the first character; > > The example code I'm using is an array that follows: > > /myArray <- c('AFP9','AFR9','TLQP7','AFS9','AFR8','AFP8','AFS7','TLQS8')/ > > The output I desire is: > > />myArray > [1] "AFS7" "AFP8" "AFR8" "AFP9" "AFR9" "AFS9" "TLQP7" TLQS8" / > > What I'm thinking is writing a function that will order it by analyzing it > from right to left. Ideally there would be a way to look at the individual > strings like the formula in Excel "=RIGHT(cell, 1)" and drop the furthest > right then do the same thing to the next character. I've been looking into > custom sort for R and haven't found much. Any idea what this function would > look like? Possibly a while loop? Each string would have a length of at > least 3, possibly longer. Thank you in advance. > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Custom-Sort-Character-and-Numeric-tp3909058p3909058.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. > -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ 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] two-sided p-value?
On 16.10.2011 13:08, Laura wrote: Dear all, I am a little bit confused because of the returned p-value by summary.lm and also summary.rq I thought if the pvalue is<= 0.05 the difference is significant. But the R help says it is a two-sided pvalue. So does that mean the pvalue has to be <= 0.025 and>= 0.975? And at the same time. ;-) Actually, the hypothesis is a two sided one, the p-value should still be smaller than your predefined alpha that may or may not be 0.05. If that is not yet clear, you should really ask for local statistical advice or start reading yourself some statistics textbooks. Best, Uwe Ligges Best, Laura -- View this message in context: http://r.789695.n4.nabble.com/two-sided-p-value-tp3909277p3909277.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Drop ALL Levels of a Data Frame Object
No worries for the brevity. That worked exactly like I wanted. Thank you. -- View this message in context: http://r.789695.n4.nabble.com/Drop-ALL-Levels-of-a-Data-Frame-Object-tp3903788p3909062.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] two-sided p-value?
Dear all, I am a little bit confused because of the returned p-value by summary.lm and also summary.rq I thought if the pvalue is <= 0.05 the difference is significant. But the R help says it is a two-sided pvalue. So does that mean the pvalue has to be <= 0.025 and >= 0.975? Best, Laura -- View this message in context: http://r.789695.n4.nabble.com/two-sided-p-value-tp3909277p3909277.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Custom Sort Character and Numeric
I"m trying to do a custom sort in this order: 1) Numeric digit furthest right; 2) Alphabetical second furthest to the right; 3) Alphabetical the rest of the string beginning with the first character; The example code I'm using is an array that follows: /myArray <- c('AFP9','AFR9','TLQP7','AFS9','AFR8','AFP8','AFS7','TLQS8')/ The output I desire is: />myArray [1] "AFS7" "AFP8" "AFR8" "AFP9" "AFR9" "AFS9" "TLQP7" TLQS8" / What I'm thinking is writing a function that will order it by analyzing it from right to left. Ideally there would be a way to look at the individual strings like the formula in Excel "=RIGHT(cell, 1)" and drop the furthest right then do the same thing to the next character. I've been looking into custom sort for R and haven't found much. Any idea what this function would look like? Possibly a while loop? Each string would have a length of at least 3, possibly longer. Thank you in advance. -- View this message in context: http://r.789695.n4.nabble.com/Custom-Sort-Character-and-Numeric-tp3909058p3909058.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] function for handling time
You are too good! Thanks a lot ! Have a nice weekend B.R Alexs From: Jim Lemon Cc: "R-help@r-project.org" Sent: Sunday, October 16, 2011 9:10 AM Subject: Re: [R] function for handling time On 10/16/2011 04:13 AM, Alaios wrote: > Dear all > I have the following time stamps (in the following format) > > MeasurementSet$TimeStamps > [,1] [,2] [,3] [,4] [,5] [,6] > [1,] 2011 7 2 13 43 48.718 > [2,] 2011 7 2 13 43 54.281 > [3,] 2011 7 2 13 43 59.843 > [4,] 2011 7 2 13 44 5.390 > [5,] 2011 7 2 13 44 10.859 > [6,] 2011 7 2 13 44 16.375 > [7,] 2011 7 2 13 44 21.890 > [8,] 2011 7 2 13 44 27.390 > [9,] 2011 7 2 13 44 33.015 > [10,] 2011 7 2 13 44 38.531 > [11,] 2011 7 2 13 44 44.078 > [12,] 2011 7 2 13 44 49.546 > [13,] 2011 7 2 13 44 55.078 > [14,] 2011 7 2 13 45 0.718 > [15,] 2011 7 2 13 45 6.281 > [16,] 2011 7 2 13 45 11.953 > [17,] 2011 7 2 13 45 17.453 > [18,] 2011 7 2 13 45 22.984 > > > I would like to write a function that will have inputs like that: > function(data, TimeStamps, timeBegin, timeEnd) {(not fixed though) > > > and will return the index of start and the end. > > I need your help specify how the input arguments should look like (something > simple and compatible with the format I have already should be good). > Then based on that two arguments, how I can search for start and end of > timestamps inside the MeasurementSet$Timestamps and return the indexes of > start and end of the time block? > Hi Alex, I think what you are trying to do is this: TimeStamps<-matrix( c(2011,7,2,13,43,48.718, 2011,7,2,13,43,54.281, 2011,7,2,13,43,59.843, 2011,7,2,13,44,5.390, 2011,7,2,13,44,10.859, 2011,7,2,13,44,16.375, 2011,7,2,13,44,21.890, 2011,7,2,13,44,27.390, 2011,7,2,13,44,33.015, 2011,7,2,13,44,38.531, 2011,7,2,13,44,44.078, 2011,7,2,13,44,49.546, 2011,7,2,13,44,55.078, 2011,7,2,13,45,0.718, 2011,7,2,13,45,6.281, 2011,7,2,13,45,11.953, 2011,7,2,13,45,17.453, 2011,7,2,13,45,22.984), ncol=6,byrow=TRUE) findBeginEnd<-function(x,timeBegin,timeEnd) { bits2date<-function(x) { the_date<-strptime(paste(x,c("-","-"," ",":",":",""), sep="",collapse=""),format="%Y-%m-%d %H:%M:%S") return(the_date) } dimx<-dim(x) timeBegin<-strptime(timeBegin,format="%Y-%m-%d %H:%M:%S") timeEnd<-strptime(timeEnd,format="%Y-%m-%d %H:%M:%S") start_index<-1 nextdate<-bits2date(x[1,]) while(nextdate < timeBegin && start_index < dimx[1]) { start_index<-start_index + 1 nextdate<-bits2date(x[start_index,]) } end_index<-start_index while(timeEnd > nextdate && end_index < dimx[1]) { end_index<-end_index + 1 nextdate<-bits2date(x[end_index,]) } return(list(start=start_index,end=end_index)) } findBeginEnd(TimeStamps,"2011-7-2 13:44:20.0","2011-7-2 13:45:12.0") Jim [[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] write.csv naming file after function argument
Thank you for your help. It works now. 2011/10/13 Jean V Adams > > Kristian Lind wrote on 10/13/2011 04:52:16 AM: > > > > > Dear R-users, > > > > I'm writing a program that constructs a dataset. I wish to save the > dataset > > to a file. > > > > Here's a very simple example of what I'm trying to do > > > > function(x=peter){ > > y <- x/2 > > write.csv(y, file = "...\x") > > } > > > > The problem is that I want to name the dataset as whatever the name of > the > > input is. In this case peter. > > How do I do this? > > > > Thank you in advance. > > > > Kristian > > > I think you're looking for something like this > > foo <- function(x){ > y <- x/2 > file.name <- paste("...\\", deparse(substitute(x)), ".csv", > sep="") > # I include the print() functions just so you can see what happened > print(y) > print(file.name) > write.csv(y, file=file.name) > } > > peter <- 12 > foo(peter) > > > Jean [[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] nlrq {quantreg}
Dear all, I sent an email on Friday asking about nlrq {quantreg}, but I haven't received any answer. I need to estimate the quantile regression estimators of a model as: y = exp(b0+x'b1+u). The model is nonlinear in parameters, although I can linearise it by using log.When I write: fitnl <- nlrq(y ~ exp(x), tau=0.5) I have the following error: Error in match.call(func, call = cll) : invalid 'definition' argument Is there any way to estimate this model, or should I accept the following change: fitnl <- rq(log(y) ~ x, tau=0.5) ? Thanks in advance! Best, Julia [[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] grouped lattice plot with overall regression line
I'd like to draw a lattice plot with groups. The groups (the grouping condition, fns) are successfully marked with separate symbols, using the following code: xyplot(T~A|speaker,groups=fns,pch=1:3,key=list(space="right",points=list(pch=1:3)),type=c("g","p","r")) Here's a hard part. This draws regression lines for each group in each panel (there are three groups, so three regression lines show up in each panel). But I want to have only one global regression line for all groups together, still maintaining separate symbols for each group. I don't want to have individual regression lines for each group. I tried many things, with various panel functions, but I've never succeeded. Could any expert help with this? I'd appreciate it greatly. The closest I could find was something like the following, which didn't work for me - anyways, it is supposed to draw by-group regression lines as well as the global one. So this is not exactly I need. xyplot(T~A|speaker,data=spk0,layout=c(4,5),type='p',groups=fns), panel=function(x,y){ panel.superpose(x,y) panel.abline(lm(y~x))}), panel.groups=function(x,y,lty){ panel.xyplot(x,y,lty=lty) panel.abline(lm(y~x),lty=3)}) Thanks so 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.
[R] multicore combn
This is a 'rather than re-invent the wheel' post. Has anyone out there re-written combn so that it can be parallelized - with multicore, snow, or otherwise? I have a job that requires large numbers of combinations, and rather than get all of the index values, then crank it through mclapply, I was wondering if there was a way to just do this natively within a function. Just curious. Thanks! -Jarrett -- View this message in context: http://r.789695.n4.nabble.com/multicore-combn-tp3908633p3908633.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.