Re: [R] nlme predict with se?
Berton, What you say makes sense and helps. I could do a parametric bootstrapping. However, I cannot make predict.nlme work at all, even without the se's. It would save me a lot of time to be able to use the predict as the statistic in boot. Does "predict.nlme" work at all? It is a listed method in MEMSS. Is there an example? thanks eal On Fri 17-Mar-06, at 3:08 PM, Berton Gunter wrote: > This won't be much help, I'm afraid but ... > > The problem is, of course, that the prediction is a **nonlinear** __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Binning question (binning rows of a data.frame according to a variable)
Do you by any chance want to sample from each group equally to get an equal representation matrix ? Here is an example of the input : mydf <- data.frame( value=1:100, value2=rnorm(100), grp=rep( LETTERS[1:4], c(35, 15, 30, 20) ) ) which has 35 observations from A, 15 from B, 30 from C and 20 from D. And here is a function that I wrote: sample.by.group <- function(df, grp, k, replace=FALSE){ if(length(k)==1){ k <- rep(k, length(unique(grp))) } if(!replace && any(k > table(grp))) stop( paste("Cannot take a sample larger than the population when 'replace = FALSE'.\n", "Please specify a value greater than", min(table(grp)), "or use 'replace = TRUE'.\n") ) ind <- model.matrix( ~ -1 + grp ) w.mat <- list(NULL) for(i in 1:ncol(ind)){ w.mat[[i]] <- sample( which( ind[,i]==1 ), k[i], replace=replace ) } out <- df[ unlist(w.mat), ] return(out) } And here are some examples of how to use it : mydf <- mydf[ sample(1:nrow(mydf)), ] # scramble it for fun out1 <- sample.by.group(mydf, mydf$grp, k=10 ) table( out1$grp ) out2 <- sample.by.group(mydf, mydf$grp, k=50, replace=T) # ie bootstrap table( out2$grp ) and you can even do bootstrapping or sampling with weights via: out3 <- sample.by.group(mydf, mydf$grp, k=c(20, 20, 30, 30), replace=T) table( out3$grp ) Regards, Adai On Fri, 2006-03-17 at 16:01 +, Dan Bolser wrote: > Hi, > > I have tuples of data in rows of a data.frame, each column is a variable > for the 'items' (one per row). > > One of the variables is the 'size' of the item (row). > > I would like to cut my data.frame into groups such that each group has > the same *total size*. So, assuming that we order by size, some groups > should have several small items while other groups have a few large > items. All the groups should have approximately the same total size. > > I have tried various combinations of cut, quantile, and ecdf, and I just > can't work out how to do this! > > Any help is greatly appreciated! > > All the best, > Dan. > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] removing NA from a data frame
You might find the 2nd part of the following response useful https://stat.ethz.ch/pipermail/r-help/2006-March/090611.html And if you want to RTFM, I guess sections 2.5, 2.7, 5.1, 5.2 of http://cran.r-project.org/doc/manuals/R-intro.html might be useful. PS: 1) R-help is designed for and by unpaid volunteers. Therefore sometimes RTFM without page reference is quite acceptable. 2) Similar question often gets repeated over and over the list. It might be useful to search http://finzi.psych.upenn.edu/nmz.html first. On Fri, 2006-03-17 at 16:17 -0500, Sam Steingold wrote: > > * Francisco J. Zagmutt <[EMAIL PROTECTED]> [2006-03-17 21:09:48 +]: > > > > Go to the help menu-> manuals in pdf and select "An Introduction to > > R". After you read that document you will be able to answer your > > questions :-) > > I did. I still need help. > > The matter is not so much with "getting things done" (I can probably > write the code - although I would rather not) as with not reinventing > the wheel. > > PS. next time you decide to answer my question with "RTFM", please also > include the number of the page that answers my specific question. > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to divide too long labels?
Thank you for answering, both Roger and Henrik There are only 5 cases which need divisions, so I inserted \n to them and now everything works. Atte > On 3/18/06, Atte Tenkanen <[EMAIL PROTECTED]> wrote: >> Is there any possibility to divide too long text in a plot to two or >> more >> lines, when using labels-parameter in the text()-command? >> >> Here is an example picture: >> >> http://users.utu.fi/attenka/253.jpeg >> >> My example script is something like this: >> >> text(1,0.7,labels=Chordnames[fnid(pcs%%12)]) # according to Larry >> Solomon's table http://solomonsmusic.net/pcsets.htm >> >> Chordnames is a long vector with long character strings. > > plot(1, xlab="First row\nSecond row") > text(1,1, labels="First row\nSecond row") > > To insert a '\n' at sensible positions such as between two words, look > at regexpr() and substring() and paste(). If you labels have a known > pattern you might be able to use gsub(). > > /Henrik > >> Atte Tenkanen >> University of Turku >> Finland >> >> __ >> R-help@stat.math.ethz.ch mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide! >> http://www.R-project.org/posting-guide.html >> >> > > > -- > Henrik Bengtsson > Mobile: +46 708 909208 (+1h UTC) > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to divide too long labels?
On 3/18/06, Atte Tenkanen <[EMAIL PROTECTED]> wrote: > Is there any possibility to divide too long text in a plot to two or more > lines, when using labels-parameter in the text()-command? > > Here is an example picture: > > http://users.utu.fi/attenka/253.jpeg > > My example script is something like this: > > text(1,0.7,labels=Chordnames[fnid(pcs%%12)]) # according to Larry > Solomon's table http://solomonsmusic.net/pcsets.htm > > Chordnames is a long vector with long character strings. plot(1, xlab="First row\nSecond row") text(1,1, labels="First row\nSecond row") To insert a '\n' at sensible positions such as between two words, look at regexpr() and substring() and paste(). If you labels have a known pattern you might be able to use gsub(). /Henrik > Atte Tenkanen > University of Turku > Finland > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > -- Henrik Bengtsson Mobile: +46 708 909208 (+1h UTC) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to divide too long labels?
On Sat, 18 Mar 2006, Atte Tenkanen wrote: > Is there any possibility to divide too long text in a plot to two or more > lines, when using labels-parameter in the text()-command? > > Here is an example picture: > > http://users.utu.fi/attenka/253.jpeg > > My example script is something like this: > > text(1,0.7,labels=Chordnames[fnid(pcs%%12)]) # according to Larry > Solomon's table http://solomonsmusic.net/pcsets.htm > > Chordnames is a long vector with long character strings. I think you could pre-process the labels column to insert suitable line breaks: str <- "Pantuvarali Raga (1321131), Chromatic Mixolydian (1131132), Chromatic Dorian/Mela Kanakangi (1132113)" out <- paste(strwrap(str, width=40), collapse="\n") but I think you'd have to do it for each value separately. > > Atte Tenkanen > University of Turku > Finland > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] legend in bubble plots made with symbols()
On Sat, 18 Mar 2006, Denis Chabot wrote: > Hi, > > I have read about the use of symbols() to draw circles of different > sizes, but I have not been able to find out how to add a legend to > such a graph, legend that would display some specific sizes and their > meaning. > > Before finding the symbols function in Paul Murrell's book, I had > rolled by own function where the variable I want to use to control > circle size was actually used to control cex. I was able to draw a > legend afterward. Symbols seems a bit simpler and I wanted to see if > it would be better than my own function. But without legend it is > less useful. However I'm sure there is a way which I'm not aware of > to draw a legend for a plot drawn with symbols()... > There is a recent paper in JSS by Susumu Tanimura, Chusi Kuroiwa, and Tsutomu Mizota, including some legend code: http://www.jstatsoft.org/ Volume 15, 2006, Issue 5 > Thanks in advance, > > Denis Chabot > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] legend in bubble plots made with symbols()
Denis Chabot wrote: > Hi, > > I have read about the use of symbols() to draw circles of different > sizes, but I have not been able to find out how to add a legend to > such a graph, legend that would display some specific sizes and their > meaning. > > Before finding the symbols function in Paul Murrell's book, I had > rolled by own function where the variable I want to use to control > circle size was actually used to control cex. I was able to draw a > legend afterward. Symbols seems a bit simpler and I wanted to see if > it would be better than my own function. But without legend it is > less useful. However I'm sure there is a way which I'm not aware of > to draw a legend for a plot drawn with symbols()... > > Thanks in advance, > > Denis Chabot library(Hmisc) ?xYplot See the size argument and the use of the skey function that is generated by xYplot. Frank > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] listing nodes in paths
Hi All, I have the following adjacency matrix for a directed graph: [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,]00000000 [2,]00000000 [3,]10000000 [4,]00100000 [5,]00100000 [6,]11000000 [7,]00011000 [8,]00000110 My interest is the numberof path between (8) and (1). Using a standard matrix moltiplication I can see I have one pathe of length 2 and two paths of length 4. (paths of length 2) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,]00000000 [2,]00000000 [3,]00000000 [4,]10000000 [5,]10000000 [6,]00000000 [7,]00200000 [8,]11011000 (paths of length 4) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,]00000000 [2,]00000000 [3,]00000000 [4,]00000000 [5,]00000000 [6,]00000000 [7,]00000000 [8,]20000000 All in all I have 3 paths (not all of the same length) between (8) and (1). Is there already a function in R (whatever the library) that will list the nodes touched in all those three paths (i.e. 8 -> 6 -> 1; 8 - > 7 -> 4 -> 3 -> 1; 8 -> 7 -> 5 -> 3 -> 1)? Regards, Federico Calboli -- Federico C. F. Calboli Department of Epidemiology and Public Health Imperial College, St. Mary's Campus Norfolk Place, London W2 1PG Tel +44 (0)20 75941602 Fax +44 (0)20 75943193 f.calboli [.a.t] imperial.ac.uk f.calboli [.a.t] gmail.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] legend in bubble plots made with symbols()
Hi, I have read about the use of symbols() to draw circles of different sizes, but I have not been able to find out how to add a legend to such a graph, legend that would display some specific sizes and their meaning. Before finding the symbols function in Paul Murrell's book, I had rolled by own function where the variable I want to use to control circle size was actually used to control cex. I was able to draw a legend afterward. Symbols seems a bit simpler and I wanted to see if it would be better than my own function. But without legend it is less useful. However I'm sure there is a way which I'm not aware of to draw a legend for a plot drawn with symbols()... Thanks in advance, Denis Chabot __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] storing via for (k in 1:100) {}
See ?sprintf and/or ?paste. /Henrik On 3/18/06, Stefan Semmeling <[EMAIL PROTECTED]> wrote: > daer list, > > i want to save a result as mentioned above. > > for (i in 1:100) { > a[i] <- write.table(a[i], "C:/.../result"i"") > } > > how is the correct way to save the results? > > thank you > > stefan > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > -- Henrik Bengtsson Mobile: +46 708 909208 (+1h UTC) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] How to divide too long labels?
Is there any possibility to divide too long text in a plot to two or more lines, when using labels-parameter in the text()-command? Here is an example picture: http://users.utu.fi/attenka/253.jpeg My example script is something like this: text(1,0.7,labels=Chordnames[fnid(pcs%%12)]) # according to Larry Solomon's table http://solomonsmusic.net/pcsets.htm Chordnames is a long vector with long character strings. Atte Tenkanen University of Turku Finland __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] cat(), Rgui, and support for carriage return \r...
On 3/17/2006 9:44 AM, Jeffrey Racine wrote: > Hi, and thanks in advance for your time. > > Background - I am working on a package and wish to have a routine's > progress reported. The routine can take some time, and I would like to > inform the user about the routine's progress. I have scoured the > archives but to no avail, so would like to solicit input from this list. > > I am successfully using > > cat("\rBootstrap replication ", i, " of ", boot.num,) > flush.console() # To flush stdout on windows systems > > which works as expected on *NIX systems and using Rterm under windows. > However, under Rgui the carriage return \r is ignored, and I certainly > don't want to use the newline escape sequence \n. Under Rgui it appears > as > > Bootstrap replication 1 of 399Bootstrap replication 2 of 399Bootstrap... > > but I want it to function properly if at all possible. > > My question is simply whether there is a portable way to implement this > so that it works regardless of the R platform the user may be working > on? > > Many thanks for any/all suggestions. I've just been looking at the source code for this. I think it will be relatively easy to make \r in Rgui do a destructive CR (i.e. it will return to the start of the line, but clear any existing characters). I'll play around a bit and then do that for R-devel. In the meantime, \b does a destructive backspace, so you can get the effect you want with something like this: msg <- "" for (i in 1:1000) { cat(rep("\b", nchar(msg)), sep="") msg <- paste("Message ", i) cat(msg) flush.console() } This seems to work in Rgui, Rterm, (and R on Unix, if you get rid of the flush.console call). Duncan Murdoch __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] storing via for (k in 1:100) {}
daer list, i want to save a result as mentioned above. for (i in 1:100) { a[i] <- write.table(a[i], "C:/.../result"i"") } how is the correct way to save the results? thank you stefan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] extraction - subsets
matrixX[vectorY %in% subsample,] ?"%in%" Roberto Furlan wrote: > Hi everybody, > let us assume i have the following matrixX and vectorY > > matrixX <- runif(100) > dim(matrixX) <- c(10,10) > vectorY <- as.matrix(as.character(seq(1,10))) > > if I define: > subsample<-c("2") > > i can extract the rows from matriX based on the elements in vectorY which > are listed in subsample > matrixX[vectorY==subsample] > > if I define subsample with more than 1 element, such as: > subsample=c("2", "3") > > how can i extract the rows from matriX based on the elements in vectorY > which are listed in subsample? > > many thanks > > Roberto Furlan > University of Turin > > -- > > La mia Cartella di Posta in Arrivo è protetta da SPAMfighter > 259 messaggi contenenti spam sono stati bloccati con successo. > Scarica gratuitamente SPAMfighter! > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 452-1424 (M, W, F) fax: (917) 438-0894 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] The R "fork"
On 3/18/06, Uwe Ligges <[EMAIL PROTECTED]> wrote: > pau carre wrote: > > Hello, I would like to call a function that can take infinite time to > > be executed in some circumstances (which can not be easily detected). > > So, I would like that once the function is being executed for more > > than two seconds it is stopped. I have found documentation for timers > > but i did not found how to "kill" a function. Moreover, I would like > > not to change the function code (it should work in all R versions and > > I want to use the default function because of the updates in its > > package). > > > On the one hand I do not think this is possible on all supported > platforms, on the other hand I think non-terminating algotithms can be > improved by checking number of iterations or recursion depth for some > forces termination. > You might want to ask the package maintainer to include such an > improvement (of not bugfix) in his code. The package maintainer > certainly will be happy to see your contribution. In addition, you could ask to have hooks added, see ?seeHook. Then you could write a hook function that generates an error, e.g. stop(), which you then can catch with tryCatch(). If you define your own error class, say, TimeoutError, your calling code will look like tryCatch(neverEndingFunction(), TimeoutError=function(ex) print(ex)) Alternatively, you could send a SIGINT (corresponds to Ctrl-C) signal to R from "outside" R. On Unix you can do something like: pkill -INT -U $user R from a shell. I do not know how to send a SIGINT on Windows (the Windows application 'termkill' will just kill R if you try that). In R you catch this interrupt signal via tryCatch(neverEndingFunction(), interrupt=function(intr) print(intr)) Then interrupt will exit neverEndingFunction() and continue with the next line of code. If you can schedule or write a shell script that sends the SIGINT signal every two minutes this would work for you. It is possible that you may be able to do all of this from within R; write Tcl(Tk) code, which R supports, that calls 'pkill' at certain times. I think this is possible even though R is single threaded, but I'm not a Tcl hacker so you have to ask someone else about this. Interrestingly, the last few days I've tried to find a way for a function to send an interrupt itself. See r-help thead "New simpleExit condition" (Mar 14-Mar 16) for details. Solving that would be one step closer to solve your problem. (No, system("pkill -INT ...") does not seem to work). Cheers Henrik > Uwe Ligges > > > > Pau > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] extraction - subsets
Hi everybody, let us assume i have the following matrixX and vectorY matrixX <- runif(100) dim(matrixX) <- c(10,10) vectorY <- as.matrix(as.character(seq(1,10))) if I define: subsample<-c("2") i can extract the rows from matriX based on the elements in vectorY which are listed in subsample matrixX[vectorY==subsample] if I define subsample with more than 1 element, such as: subsample=c("2", "3") how can i extract the rows from matriX based on the elements in vectorY which are listed in subsample? many thanks Roberto Furlan University of Turin -- La mia Cartella di Posta in Arrivo è protetta da SPAMfighter 259 messaggi contenenti spam sono stati bloccati con successo. Scarica gratuitamente SPAMfighter! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Maximum likelihood
Have you considered the Bioconductor project (www.bioconductor.org)? If you are not already familiar with their capabilities, I suggest you review their capabilities and consider posting a question to their listserve if you don't find the answer without that. hope this helps. spencer graves Erez Shabo wrote: > Hello all, > > I'm trying to calculate the Maximum likelihood of individuals to get the > ancestry. > I mixd 3 populations 15 generations in proportion of 20% 20% 60% when each > population > sorce have diferent genome (0 1 and 2) with frequencies for each one. > So now i have individuals looks like 0 0 2 1 1 2 0 . and i don't now how > to calculate the > mle although i try to figure out from the package state4. > can somebody help me please? > > Thanks > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] VAR
Where did you find the function "forecast"? It is NOT a standard R function. I just tried 'methods(class="ar")', which produced the following: [1] predict.ar* print.ar* Non-visible functions are asterisked The documentation for 'predict.ar' includes the following example: > sunspot.ar <- ar(sunspot.year) > (pred.sunspot <- predict(sunspot.ar, n.ahead=25)) $pred Time Series: Start = 1989 End = 2013 Frequency = 1 [1] 135.25933 148.09051 133.98476 106.61344 71.21921 40.84057 18.70100 [8] 11.52416 27.24208 56.99888 87.86705 107.62926 111.05437 98.05484 [15] 74.84085 48.80128 27.65441 18.15075 23.15355 40.04723 61.95906 [22] 80.79092 90.11420 87.44131 74.42284 $se Time Series: Start = 1989 End = 2013 Frequency = 1 [1] 16.35519 24.68467 28.95653 29.97401 30.07714 30.15629 30.35971 30.58793 [9] 30.71100 30.74276 31.42565 32.96467 34.48910 35.33601 35.51890 35.52034 [17] 35.62544 35.63564 35.63623 35.65107 35.70321 35.74992 35.78223 35.78905 [25] 35.78905 Does this answer your question? spencer graves Julija Kackina wrote: > Hello! > > > > I'm trying to forecast the UK exchange rate. To estimate my model I use > ar() function. However, I can't get a forecast of the exchange rate > using the function forecast(). > > > > Regards, > > Julija Kackina > > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] The R "fork"
pau carre wrote: > Hello, I would like to call a function that can take infinite time to > be executed in some circumstances (which can not be easily detected). > So, I would like that once the function is being executed for more > than two seconds it is stopped. I have found documentation for timers > but i did not found how to "kill" a function. Moreover, I would like > not to change the function code (it should work in all R versions and > I want to use the default function because of the updates in its > package). On the one hand I do not think this is possible on all supported platforms, on the other hand I think non-terminating algotithms can be improved by checking number of iterations or recursion depth for some forces termination. You might want to ask the package maintainer to include such an improvement (of not bugfix) in his code. The package maintainer certainly will be happy to see your contribution. Uwe Ligges > Pau > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Information Window - Warning Message
Mathias Ehrich wrote: > Hi all, > > this might be a very stupid question, but I tried for several hours now > and I'm helpless. I'm running windows and R 2-2-1. Recently, every time > when I have an error in my code a message box pops up telling me the > error message. The code won't continue before I click ok in the box. > Before I changed to 2-2-1 the code was just running through and I could > check within the command window for errors. I tried to find an option to > disable the message box but couldn't. > > I know it is probably not the best way to have code with errors anyway, > but I'm not that good. > > If someone knows an answer, PLEASE let me know. > > Thanks a lot for your time. Probably you have loaded a package that handles eror messages and warnings in a different way. I remember at least one package that caused such an annyoing behaviour ... Which do you have loaded (incl. version number)? Uwe Ligges > best > > Mathias > > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Search for the minimum of a fitted curve
Hi, I have a function of the second grade, with 2 parameters: y~A^2 + A + B^2 + B The response y is a measurement for the precision of the analytical method, where A en B are method parameters. As its neccesary to keep the precision of the analytical methad as good as possible, its usefull to optimize A en B to keep y as low as possible. But how can I do this with R? I have searched the archives, did some search work in the help function ( optimize, nlm, nls, ...) but could find anything that looks like what I need. I have written a script which does the work, but I doubt this is the easiest way. Here are some data and the script: A<- rep(c(1,4,8),3) B<- rep(c(1,3,6),each=3) C <- c(3,2,3,2,1,2,3,2,3) fit <- lm(C~I(A^2)+A+I(B^2)+B) Now to optimize: new <- data.frame(A=rep( seq(0, 8, 0.5),each=17),B=rep(seq(0, 8, 0.5),17)) new$C <- predict(fit, new) new[which.min(new$C),] This give me the values for A en B, where C is minimized. Is there another way? Kind regards Bart [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Derivative of a splinefun function.
> "BeT" == Berwin A Turlach <[EMAIL PROTECTED]> > on Sat, 18 Mar 2006 17:08:47 +0800 writes: BeT> G'day Rolf, > "RT" == Rolf Turner <[EMAIL PROTECTED]> writes: RT> Is there a way of calculating the derivative of a function RT> returned by splinefun()? BeT> Yes, of course. :) BeT> As somebody else once said: "this is R, anything can be done, the BeT> question is just how easy it is to do so". BeT> It may depend on what kind of spline you are fitting with BeT> splinefun()... RT> Such a function is a cubic spline, whence it has a calculable RT> derivative, but is there a (simple) way of getting at it? BeT> Depends on your definition of simple. ;-)) RT> One workaround that I have thought of is to take a fine grid RT> of points, evaluate the function returned by splinefun() at RT> these points, put an interpolating spline through these points RT> using smooth.spline() with spar=0, and then calculate the RT> derivative with predict(...,deriv=1). BeT> Why easy if one can also make it complicated? There is the function BeT> interpSpline() in the package splines for which, according to its help BeT> page, the predict method also works. So using smooth.spline with BeT> spar=0 does indeed look a bit kludgy. :) RT> Is there a better way? BeT> splinefun() essentially returns a function that contains one object in BeT> its environment, namely z, which contains all the necessary BeT> information for calculating the spline and whose body is just a call BeT> to an internal C function. BeT> The components y, b, c and d of the object z contain the piecewise BeT> polynomial representation between knots of the spline if you choose BeT> the methods "fmm" or "natural". If you use the method "periodic" then BeT> the component e of the object z is used too, but I don't know whether BeT> it is just used to hold intermediate results while calculating the BeT> spline or whether it is actually necessary for calculating the BeT> spline. (An analysis of the C code that is called to calculate the BeT> spline and to evaluate the spline should answer that question but BeT> until now I never bothered of doing this since I didn't have use for BeT> periodic splines yet.) BeT> Thus, since the spline is stored in a piecewise polynomial fashion, it BeT> shouldn't be hard to define a function that calculates the derivative BeT> of the function returned by splinefun(). If my calculus is correct, BeT> the following code should construct such a function: >> par(mfrow=c(1,2)) >> n <- 9 >> x <- 1:n >> y <- rnorm(n) >> f <- splinefun(x, y) >> ls(envir = environment(f)) > [1] "z" >> splinecoef <- eval(expression(z), envir = environment(f)) >> curve(f(x), 1, 10, col = "green", lwd = 1.5) >> points(splinecoef, col = "purple", cex = 2) > ## > ## construct a function that calculates the derivative of f() > ## >> g <- f >> environment(g) <- new.env(parent=baseenv()) >> z <- get("z", envir=environment(f)) >> z$y <- z$b >> z$b <- 2*z$c >> z$c <- 3*z$d >> z$d <- rep(0, z$n) >> assign("z", z, envir=environment(g)) >> curve(g(x), 1, 10, col = "green", lwd = 1.5) BeT> As indicated above, I would only vouch for this method if splinefun() BeT> is called with method="fmm" or method="natural". And the second BeT> caveat is, of course, that you are assuming that I get my calculus BeT> correct on a Saturday morning which might be a bit much to ask. ;-)) It does work with "periodic" as well. The "e" component could have been zapped (in splinefun before returning). Berwin, do you feel like making this into patch for splinefun(), which in the future would return a function(x, deriv = 0) and would also work for deriv \in {1,2,3} (for 'deriv = 3' it could return an object of class "stepfun" !) ? BeT> Hope that helps. I'm pretty sure it did. Well done for early Saturday morning! (I've checked numerically with my sfsmisc::D1ss() function that your result is correct) Regards, Martin __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Binning question (binning rows of a data.frame according to a variable)
On 3/18/06, Dan Bolser <[EMAIL PROTECTED]> wrote: > Gabor Grothendieck wrote: > > If you are just looking for something simple that may be good enough > > then assign the largest one to group 1, the second largest to group 2, > > ..., the 8th largest to group 8 and then start over again with group 1 > > and so on. > > > > # test data > > set.seed(1) > > x <- sample(100, 100, rep = TRUE) > > > > xs <- sort(x) > > g <- gl(8, 1, length(xs)) # 8 groups > > > > # so that g contains the groups that correspond to xs. > > > > tapply(xs, g, sum) # 659 671 687 701 612 622 629 646 > > > > > That is a fairly neat way of getting groups with a good 'approximate > same size', however, in general I would like to be able to order my data > in any way, and still cut it into equal 'size' groups (like quantiles > for rows, but for row variable totals instead). Do you mean you want g to be in the original order of x? order(x) is the permutation which sorts x and order(order(x)) is its inverse permutation so apply that to the gl expression: x <- c(10, 4, 15, 2, 20, 13) g <- gl(2, 1, length(x))[order(order(x))] # check it identical(tapply(sort(x), gl(2, 1, length(x)), sum), tapply(x, g, sum)) > > Seems it should be possible without an explicit loop (and some more > 'refinement' of the final group sizes), but I can't work it out. > > > > > > > > On 3/17/06, Dan Bolser <[EMAIL PROTECTED]> wrote: > > > >>Dan Bolser wrote: > >> > >>>Hi, > >>> > >>>I have tuples of data in rows of a data.frame, each column is a variable > >>>for the 'items' (one per row). > >>> > >>>One of the variables is the 'size' of the item (row). > >>> > >>>I would like to cut my data.frame into groups such that each group has > >>>the same *total size*. So, assuming that we order by size, some groups > >>>should have several small items while other groups have a few large > >>>items. All the groups should have approximately the same total size. > >>> > >>>I have tried various combinations of cut, quantile, and ecdf, and I just > >>>can't work out how to do this! > >>> > >>>Any help is greatly appreciated! > >>> > >>>All the best, > >>>Dan. > >>> > >> > >>Perhaps there is a cleaver way, but I just wrote this in despiration... > >> > >> > >>my.groups <- 8 > >> > >>my.total <- > >> sum(my.res.1$TOT) ## The 'size' variable in my data.frame > >> > >>my.approx.size <- > >> my.total/ > >> my.groups > >> > >>my.j <- 1 > >>my.roll <- 0 > >>my.factor <- numeric() > >> > >>for(i in sort(my.res.1$TOT)){ > >> > >> my.roll <- > >>my.roll + i > >> > >> if (my.roll > my.approx.size * my.j) > >>my.j <- my.j + 1 > >> > >> my.factor <- > >>append(my.factor,my.j) > >>} > >> > >>my.factor <- > >> as.factor(my.factor) > >> > >> > >> > >>Then... > >> > >> > tapply(my.factor,my.factor,length) > >> 1 2 3 4 5 6 7 8 > >>152 62 45 34 25 21 14 8 > >> > >> > >>And... > >> > >> > tapply(sort(my.res.1$TOT),my.factor,sum) > >> 12345678 > >>2880 2848 2912 2893 2832 2906 2776 3029 > >> > > >> > >> > >> > >>Which isn't bad. > >> __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Binning question (binning rows of a data.frame according to a variable)
Gabor Grothendieck wrote: > If you are just looking for something simple that may be good enough > then assign the largest one to group 1, the second largest to group 2, > ..., the 8th largest to group 8 and then start over again with group 1 > and so on. > > # test data > set.seed(1) > x <- sample(100, 100, rep = TRUE) > > xs <- sort(x) > g <- gl(8, 1, length(xs)) # 8 groups > > # so that g contains the groups that correspond to xs. > > tapply(xs, g, sum) # 659 671 687 701 612 622 629 646 > That is a fairly neat way of getting groups with a good 'approximate same size', however, in general I would like to be able to order my data in any way, and still cut it into equal 'size' groups (like quantiles for rows, but for row variable totals instead). Seems it should be possible without an explicit loop (and some more 'refinement' of the final group sizes), but I can't work it out. > > On 3/17/06, Dan Bolser <[EMAIL PROTECTED]> wrote: > >>Dan Bolser wrote: >> >>>Hi, >>> >>>I have tuples of data in rows of a data.frame, each column is a variable >>>for the 'items' (one per row). >>> >>>One of the variables is the 'size' of the item (row). >>> >>>I would like to cut my data.frame into groups such that each group has >>>the same *total size*. So, assuming that we order by size, some groups >>>should have several small items while other groups have a few large >>>items. All the groups should have approximately the same total size. >>> >>>I have tried various combinations of cut, quantile, and ecdf, and I just >>>can't work out how to do this! >>> >>>Any help is greatly appreciated! >>> >>>All the best, >>>Dan. >>> >> >>Perhaps there is a cleaver way, but I just wrote this in despiration... >> >> >>my.groups <- 8 >> >>my.total <- >> sum(my.res.1$TOT) ## The 'size' variable in my data.frame >> >>my.approx.size <- >> my.total/ >> my.groups >> >>my.j <- 1 >>my.roll <- 0 >>my.factor <- numeric() >> >>for(i in sort(my.res.1$TOT)){ >> >> my.roll <- >>my.roll + i >> >> if (my.roll > my.approx.size * my.j) >>my.j <- my.j + 1 >> >> my.factor <- >>append(my.factor,my.j) >>} >> >>my.factor <- >> as.factor(my.factor) >> >> >> >>Then... >> >> > tapply(my.factor,my.factor,length) >> 1 2 3 4 5 6 7 8 >>152 62 45 34 25 21 14 8 >> >> >>And... >> >> > tapply(sort(my.res.1$TOT),my.factor,sum) >> 12345678 >>2880 2848 2912 2893 2832 2906 2776 3029 >> > >> >> >> >>Which isn't bad. >> >> >> >> >> >> >> >> >> >> >> >> >> >>>__ >>>R-help@stat.math.ethz.ch mailing list >>>https://stat.ethz.ch/mailman/listinfo/r-help >>>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >> >>__ >>R-help@stat.math.ethz.ch mailing list >>https://stat.ethz.ch/mailman/listinfo/r-help >>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >> __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] How to bootstrap one-sample ks.test?
Hello! I am testing if my data are distributed under Laplace's distribution, which I managed to do with: > library(rmutil) > ks.test(jitter(x), "plaplace", mean(x), sd(x)) Nevertheless, I am trying to bootstrap ks.test without any success. Something is wrong in my commands: > data = read.table("data.dat",T) > library(rmutil) > library(boot) > ks.laplace = function(d, w) > ks.test(jitter(d), "plaplace", mean(d), sd(d)) > boot(data$x, ks.laplace, R = 5000) I am getting error-message: > Error: incorrect number of subscripts on matrix Can anyone help me, since I have almost no experience with bootstrapping techniques. I saw ks.boot() in Matching package, but it is for two-samples, not for testing the shape of the distribution. Sincerely, P. Milin __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] The R "fork"
Hello, I would like to call a function that can take infinite time to be executed in some circumstances (which can not be easily detected). So, I would like that once the function is being executed for more than two seconds it is stopped. I have found documentation for timers but i did not found how to "kill" a function. Moreover, I would like not to change the function code (it should work in all R versions and I want to use the default function because of the updates in its package). Pau __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Derivative of a splinefun function.
G'day Rolf, > "RT" == Rolf Turner <[EMAIL PROTECTED]> writes: RT> Is there a way of calculating the derivative of a function RT> returned by splinefun()? Yes, of course. :) As somebody else once said: "this is R, anything can be done, the question is just how easy it is to do so". It may depend on what kind of spline you are fitting with splinefun()... RT> Such a function is a cubic spline, whence it has a calculable RT> derivative, but is there a (simple) way of getting at it? Depends on your definition of simple. ;-)) RT> One workaround that I have thought of is to take a fine grid RT> of points, evaluate the function returned by splinefun() at RT> these points, put an interpolating spline through these points RT> using smooth.spline() with spar=0, and then calculate the RT> derivative with predict(...,deriv=1). Why easy if one can also make it complicated? There is the function interpSpline() in the package splines for which, according to its help page, the predict method also works. So using smooth.spline with spar=0 does indeed look a bit kludgy. :) RT> Is there a better way? splinefun() essentially returns a function that contains one object in its environment, namely z, which contains all the necessary information for calculating the spline and whose body is just a call to an internal C function. The components y, b, c and d of the object z contain the piecewise polynomial representation between knots of the spline if you choose the methods "fmm" or "natural". If you use the method "periodic" then the component e of the object z is used too, but I don't know whether it is just used to hold intermediate results while calculating the spline or whether it is actually necessary for calculating the spline. (An analysis of the C code that is called to calculate the spline and to evaluate the spline should answer that question but until now I never bothered of doing this since I didn't have use for periodic splines yet.) Thus, since the spline is stored in a piecewise polynomial fashion, it shouldn't be hard to define a function that calculates the derivative of the function returned by splinefun(). If my calculus is correct, the following code should construct such a function: > par(mfrow=c(1,2)) > n <- 9 > x <- 1:n > y <- rnorm(n) > f <- splinefun(x, y) > ls(envir = environment(f)) [1] "z" > splinecoef <- eval(expression(z), envir = environment(f)) > curve(f(x), 1, 10, col = "green", lwd = 1.5) > points(splinecoef, col = "purple", cex = 2) ## ## construct a function that calculates the derivative of f() ## > g <- f > environment(g) <- new.env(parent=baseenv()) > z <- get("z", envir=environment(f)) > z$y <- z$b > z$b <- 2*z$c > z$c <- 3*z$d > z$d <- rep(0, z$n) > assign("z", z, envir=environment(g)) > curve(g(x), 1, 10, col = "green", lwd = 1.5) As indicated above, I would only vouch for this method if splinefun() is called with method="fmm" or method="natural". And the second caveat is, of course, that you are assuming that I get my calculus correct on a Saturday morning which might be a bit much to ask. ;-)) Hope that helps. Cheers, Berwin __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] cat(), Rgui, and support for carriage return \r...
\r with cat performs a carriage return and line feed in R-GUI. > for (i in 1:10) { cat("\rFoo",i) } Foo 1 Foo 2 Foo 3 Foo 4 Foo 5 Foo 6 Foo 7 Foo 8 Foo 9 Foo 10 > _ Performs a carriage return only on the console. > for (i in 1:10) { cat("\rFoo",i) } Foo 10> _ Cheers, Martin On 18/03/2006, at 6:09 AM, Duncan Murdoch wrote: > On 3/17/2006 9:44 AM, Jeffrey Racine wrote: >> Hi, and thanks in advance for your time. >> >> Background - I am working on a package and wish to have a routine's >> progress reported. The routine can take some time, and I would like to >> inform the user about the routine's progress. I have scoured the >> archives but to no avail, so would like to solicit input from this >> list. >> >> I am successfully using >> >> cat("\rBootstrap replication ", i, " of ", boot.num,) >> flush.console() # To flush stdout on windows systems >> >> which works as expected on *NIX systems and using Rterm under windows. >> However, under Rgui the carriage return \r is ignored, and I certainly >> don't want to use the newline escape sequence \n. Under Rgui it >> appears >> as >> >> Bootstrap replication 1 of 399Bootstrap replication 2 of >> 399Bootstrap... >> >> but I want it to function properly if at all possible. >> >> My question is simply whether there is a portable way to implement >> this >> so that it works regardless of the R platform the user may be working >> on? >> >> Many thanks for any/all suggestions. > > This looks like it would be a useful addition to Rgui to support this. > The problem is that on Unix or Rterm, it isn't actually R that does > anything, it's the display that handles the CR with no LF. Rgui uses a > different mechanism for putting text on the screen, so this would have > to be implemented specially. > > Just out of interest: does the Mac OS X gui handle this like the ascii > terminals or like Windows Rgui? > > Duncan Murdoch > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html