Re: [R] efficient way to compute a probability distribution?
prob <- function(x,ranks,dereg) mean(dereg %in% ranks[seq_len(x)]) 2007/8/25, Naxerova, Kamila <[EMAIL PROTECTED]>: > Hello! > > I have a piece of slow code and I am wondering if I am missing some obvious > way > to make it faster -- or if there is some predefined function I should be using > instead. > > I have a list (ranks), for which I would like to compute the probability of a > bunch of values (dereg) being contained in ranks[1:i] > > prob=function(x,ranks,dereg){ > > revranks=ranks[1:x] > p=length(which(dereg %in% revranks))/length(dereg) > return(p) > } > > probdist=lapply(c(2:5166),prob,ranks=r,dereg=list) > > Takes a long time... too long to do a meaningful number of permutations. > > Thanks!!! > --Kamila > > > The information transmitted in this electronic communication...{{dropped}} > > __ > 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 > and provide commented, minimal, self-contained, reproducible code. > -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] compare 2 vectors
setdiff(b, a) 2007/6/28, João Fadista <[EMAIL PROTECTED]>: > Dear all, > > I would like to take out the values from one vector that are equal to the > values in another vector. > > Example: > a <- c(1,2,3,4,5,6,7,8,9) > b <- c(3,10,20,5,6) > b_noRepeats = c(10,20) > > So I would like to have the vector b without the same values as vector a. > > > Kind regards, > João Fadista > > > > > > [[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 > and provide commented, minimal, self-contained, reproducible code. > > -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] suppressing outliers in ggboxplot
2007/5/14, hadley wickham <[EMAIL PROTECTED]>: > > Hi Antonio, > > You can't in the current version. However, you can in the next > version, which I hope to release very soon: > > p <- ggplot(mtcars, aes(y=mpg, x=factor(cyl))) > p + geom_boxplot() # has outliers > p + geom_boxplot(shape=NA) # no outliers Great!! Antonio. Hadley > > On 5/13/07, Antonio, Fabio Di Narzo <[EMAIL PROTECTED]> wrote: > > Hi. > > How can I suppress those red dots from ggboxplot output in package > ggplot? > > This is especially a nuisance when adding a jitter (as it is done in the > end > > of the package vignette). > > > > Bests, > > Antonio. > > -- > > Antonio, Fabio Di Narzo > > Ph.D. student at > > Department of Statistical Sciences > > University of Bologna, Italy > > > > [[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 > > and provide commented, minimal, self-contained, reproducible code. > > > -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy [[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 and provide commented, minimal, self-contained, reproducible code.
[R] suppressing outliers in ggboxplot
Hi. How can I suppress those red dots from ggboxplot output in package ggplot? This is especially a nuisance when adding a jitter (as it is done in the end of the package vignette). Bests, Antonio. -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy [[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 and provide commented, minimal, self-contained, reproducible code.
[R] adding custom details to ggplot subplots
Hi all. Consider the following example from ggplot vignette: ggpoint( ggplot(tips, .~sex, ae=list(y=tip, x=total_bill)) ) You have one scatterplot per sex. With 'ggabline' I can add one or more lines to each subplot at the same time. How can I add different lines in each subplot? Note that I have 0https://stat.ethz.ch/mailman/listinfo/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] [R-pkgs] RTisean 3.0-7 released
Dear R users, I've just uploaded to CRAN a new version of RTisean, the TISEAN-to-R interface. This is now compatible with the recent, new 3.0.1 release of TISEAN [1]. This new TISEAN version is explicitely GPL-ed, and has some more routines handling multivariate time series. Bests, Antonio, Fabio Di Narzo. [1] http://idmc.blogspot.com/2007/03/tisean-300-is-out.html ___ R-packages mailing list R-packages@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-packages __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Neural Net forecasting
The tsDyn package has the 'nnetTs' model, for fitting univariate NNET time series model. The model is presented as a NonLinearAutoRegressive model. Boundled with tsDyn there is a vignette with some working examples. Hope this helps. Bests, Antonio. 2007/2/23, sj <[EMAIL PROTECTED]>: > Are there any packages in R that are suitable for doing time series > forecasting using neural networks? I have looked in the nnet package and > neural package and they both seem geared towards classification. > > thanks, > > Spencer > > [[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 > and provide commented, minimal, self-contained, reproducible code. > -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] curious about dimension of 'apply' output when MARGIN=1
2007/1/17, Patrick Burns <[EMAIL PROTECTED]>: > A logical reason for the phenomenon is that > matrices are stored down their columns. For > example: > > > matrix(1:15,5) > [,1] [,2] [,3] > [1,]16 11 > [2,]27 12 > [3,]38 13 > [4,]49 14 > [5,]5 10 15 > > When an 'apply' across rows is done, it will be > the values corresponding to each of the rows that > are together. > > For matrices, merely transposing the result fixes > the "problem", but it is considerably more complex > in higher dimensional arrays. I routinely use 'aperm' > > There could be a spectrum of opinion from: > > the original programmer was lazy and didn't adequately > serve users > > to: > > the simpler the program the fewer bugs there will be. > > Patrick Burns > [EMAIL PROTECTED] > +44 (0)20 8525 0696 > http://www.burns-stat.com > (home of S Poetry and "A Guide for the Unwilling S User") > > > Gabor Grothendieck wrote: > > >The reshape package has an idempotent apply, iapply: > > > > > > > >>library(reshape) > >>iapply(M,1,function(row) row+c(1,2)) > >> > >> > > [,1] [,2] > >[1,]26 > >[2,]37 > >[3,]48 > > > >On 1/16/07, Benjamin Tyner <[EMAIL PROTECTED]> wrote: > > > > > >>Reading the documentation for 'apply', I understand the following is > >>working exactly as documented: > >> > >> > M<-matrix(1:6,ncol=2) > >> > M > >>[,1] [,2] > >>[1,]14 > >>[2,]25 > >>[3,]36 > >> > apply(M,2,function(column) column+c(1,2,3)) > >>[,1] [,2] > >>[1,]25 > >>[2,]47 > >>[3,]69 > >> > apply(M,1,function(row) row+c(1,2)) > >>[,1] [,2] [,3] > >>[1,]234 > >>[2,]678 > >> > >>I'm not proposing any changes or extra arguments to 'apply'. Rather, I'm > >>wondering what is the benefit for (or rationale behind) this somewhat > >>unintuitive behavior in the case that MARGIN=1. > >> > >>Thanks, > >>Ben > >> > >>__ > >>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 > >>and provide commented, minimal, self-contained, reproducible code. > >> > >> > >> > > > >__ > >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 > >and provide commented, minimal, self-contained, reproducible code. > > > > > > > > > > __ > 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 > and provide commented, minimal, self-contained, reproducible code. > -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Skipping Results with Errors in a Loop
?try 2006/12/13, Rick Bilonick <[EMAIL PROTECTED]>: > I'm estimating models using lme in a for loop. Sometimes the model > doesn't converge or there are other problems. This causes the evaluation > to stop prematurely. I can't remember the function name that I need to > use to allow the loop to continue until the end. Could someone remind me > the name of the function? I've tried searching but haven't hit upon the > function. > > Rick B. > > __ > 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 > and provide commented, minimal, self-contained, reproducible code. > -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] Trouble passing arrays to C code
2006/12/2, Wee-Jin Goh <[EMAIL PROTECTED]>: > Hello, > > I'm having more trouble with interfacing with C code. I have a > function in C that will return the result of its computation as 3 > arrays. The signature of the function is as follows: > > void lorenz_run(double x0, double y0, double z0, double h, int steps, > double *res_x, double *res_y, double > *res_z) > > The function works, as I've tested it from within C itself and the > results it gives are accurate. In order to integrate it with R, I've > written the following C wrapper function: > > void lorenz_run_R_wrapper(double *x0, double *y0, double *z0, double > *h, double *steps, here 'steps' is double, was integer in 'lorenz_run'. > double *res_x, double *res_y, double *res_z) { > lorenz_run(*x0, *y0, *z0, *h, *steps, res_x, res_y, res_z); > } > > The corresponding R wrapper function is: > > lorenz_run <- function(x0,y0,z0,h,steps) { > returned_data = .C("lorenz_run_R_wrapper", > x0=as.double(x0), > y0=as.double(y0), > z0=as.double(z0), > h=as.double(h), > steps=as.integer(steps), > res_x=double(steps), > res_y=double(steps), > res_z=double(steps)) > # Return the value of the result parameter > return( rbind(returned_data$res_x, returned_data$res_y, > returned_data$res_z)) > > } > > My problem is, that the first elements of res_x, res_y, and res_z are > correctly set. But the rest of the cells in those 3 arrays remain 0. > This leads me to think that I am passing these arrays to the C code > wrongly. Can anyone help me out? > > Thanks in advance, > Wee-Jin > > __ > 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 > and provide commented, minimal, self-contained, reproducible code. > -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] dumping/loading objects with 'tsp' attribute
2006/11/23, Gabor Grothendieck <[EMAIL PROTECTED]>: > On 11/23/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > > On 11/23/06, Antonio, Fabio Di Narzo <[EMAIL PROTECTED]> wrote: > > > 2006/11/23, Prof Brian Ripley <[EMAIL PROTECTED]>: > > > > On Thu, 23 Nov 2006, Antonio, Fabio Di Narzo wrote: > > > > > > > > > Dear all, > > > > > I'm indirectly faced with the fact that setting the 'tsp' attribute of > > > > > an object modifies its class definition: > > > > >> class( structure(1:2, tsp=c(1,2,1), class=c("myts","ts")) ) > > > > > [1] "ts" "myts" > > > > > > > > > > In general, this is of really little (ok, I admit: totally no) > > > > > interest for me because 'myts' class is added just after assigning the > > > > > 'tsp' attribute (by calling ts). > > > > > However, this behaviour gives me troubles when re-loading a previously > > > > > deparsed object, so that: > > > > >> x <- ts(1:2) > > > > >> class(x) <- c("myts", class(x)) > > > > >> dput( x , "temp.dat") > > > > >> class(dget("temp.dat")) > > > > > [1] "ts" "myts" > > > > >> unlink("temp.dat") > > > > > > > > > > In other words, my real problem should be restated as: how to safely > > > > > dump (and then load) an object which has a (perhaps valid) "tsp" > > > > > attribute? > > > > > More generally: can someone suggest me a safer way to dump/restoring > > > > > R objects? > > > > > > > > save/load. > > > > > > Ok. That seems to be the final statement: to be sure about the result, > > > I have to use binary files for storing R objects (even pure data > > > objects with attached attributes) instead of dumped R code. > > > > If its mainly ascii you are after but the source file part is not important > > then note that save can save to ascii files: > > > > y <- x > > save("x", file = "temp.rda", ascii = TRUE) > > rm(x) > > load("temp.rda") > > identical(x, y) > > readLines("temp.rda") > > unlink("temp.rda") > > and here is a workaround if you are willing to do a bit of work when > outputting the objects: > > > # test data > x <- ts(1:2) > class(x) <- c("myts", "ts") > y <- x > > # need 3 output statements > dump("x", "temp.R") > write("attributes(x) <-", "temp.R", append = TRUE) > write(deparse(attributes(x)), "temp.R", append = TRUE) > > # source it back in and check > rm(x) > source("temp.R") > identical(x,y) > readLines("temp.R") > > # clean up > unlink("temp.R") > Many thanks! This works as I want, and can be eventually encapsulated in a sort of "safedump" function for convenience. More generally, interesting to learn that using "attributes<-" has no side effects (i.e., attributes aren't set by using accessor functions, isn't it?), as opposed to using 'structure' named arguments, so can be more convenient in building R objects with arbitrary attributes (at useR risk...). -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] dumping/loading objects with 'tsp' attribute
2006/11/23, Prof Brian Ripley <[EMAIL PROTECTED]>: > On Thu, 23 Nov 2006, Antonio, Fabio Di Narzo wrote: > > > Dear all, > > I'm indirectly faced with the fact that setting the 'tsp' attribute of > > an object modifies its class definition: > >> class( structure(1:2, tsp=c(1,2,1), class=c("myts","ts")) ) > > [1] "ts" "myts" > > > > In general, this is of really little (ok, I admit: totally no) > > interest for me because 'myts' class is added just after assigning the > > 'tsp' attribute (by calling ts). > > However, this behaviour gives me troubles when re-loading a previously > > deparsed object, so that: > >> x <- ts(1:2) > >> class(x) <- c("myts", class(x)) > >> dput( x , "temp.dat") > >> class(dget("temp.dat")) > > [1] "ts" "myts" > >> unlink("temp.dat") > > > > In other words, my real problem should be restated as: how to safely > > dump (and then load) an object which has a (perhaps valid) "tsp" > > attribute? > > More generally: can someone suggest me a safer way to dump/restoring R > > objects? > > save/load. Ok. That seems to be the final statement: to be sure about the result, I have to use binary files for storing R objects (even pure data objects with attached attributes) instead of dumped R code. I will accept that (infact, as I can read in 'save' help page, those binaries should be portable across R platforms) and avoid boring you anymore :-) > > ?dput comes with copious warnings about the problems of doing what you are > attempting, so I wonder why you are surprised. I've seen. That's because I've asked for suggestions, and not called this a 'bug' or a 'nonsense' behaviour. > > -- > Brian D. Ripley, [EMAIL PROTECTED] > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, Tel: +44 1865 272861 (self) > 1 South Parks Road, +44 1865 272866 (PA) > Oxford OX1 3TG, UKFax: +44 1865 272595 > -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] dumping/loading objects with 'tsp' attribute
Dear all, I'm indirectly faced with the fact that setting the 'tsp' attribute of an object modifies its class definition: > class( structure(1:2, tsp=c(1,2,1), class=c("myts","ts")) ) [1] "ts" "myts" In general, this is of really little (ok, I admit: totally no) interest for me because 'myts' class is added just after assigning the 'tsp' attribute (by calling ts). However, this behaviour gives me troubles when re-loading a previously deparsed object, so that: > x <- ts(1:2) > class(x) <- c("myts", class(x)) > dput( x , "temp.dat") > class(dget("temp.dat")) [1] "ts" "myts" > unlink("temp.dat") In other words, my real problem should be restated as: how to safely dump (and then load) an object which has a (perhaps valid) "tsp" attribute? More generally: can someone suggest me a safer way to dump/restoring R objects? Tnx all, Antonio. -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] t.test()
23 Nov 2006 14:48:31 +0100, Peter Dalgaard <[EMAIL PROTECTED]>: > "ONKELINX, Thierry" <[EMAIL PROTECTED]> writes: > > > There is no such thing as an unpaired t-test. A t-test can be a paired, > > one sample or two sample t-test. Since you want to compare the sample > > against a given mean, you need a one sample t-test. You tried to do a > > two sample test. That didn't work because you need at least two > > observations in each group. > > NO! This is just plain wrong. I agree. Hoping I'm not missing anything, something like: > t.test(x[1],x[-1], var.equal=TRUE) should work, since pooled variance can be computed if length(x)>2. But, surprising, this still gives "not enough 'x' observations". I've seen that's because length of the first argument in t.test is checked before checking 'var.equal' value in 't.test.default'. I'm wrong, or 2 sided test should be computed as: t.test.value <- abs(x[1]-mean(x[-1]))/var(x) t.test.pvalue <- 2*pt(-t.test.value, length(x)-2) ? > > > > x <- c(23,25,29,27,30,30) > > t.test(x[-1], mu = x[1]) > > > > One Sample t-test > > > > data: x[-1] > > t = 5.3634, df = 4, p-value = 0.005833 > > alternative hypothesis: true mean is not equal to 23 > > 95 percent confidence interval: > > 25.50814 30.89186 > > sample estimates: > > mean of x > > 28.2 > > > > > > Cheers, > > > > Thierry > > > > > > > > > > ir. Thierry Onkelinx > > > > Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature > > and Forest > > > > Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, > > methodology and quality assurance > > > > Gaverstraat 4 > > > > 9500 Geraardsbergen > > > > Belgium > > > > tel. + 32 54/436 185 > > > > [EMAIL PROTECTED] > > > > www.inbo.be > > > > > > > > Do not put your faith in what statistics say until you have carefully > > considered what they do not say. ~William W. Watt > > > > A statistical analysis, properly conducted, is a delicate dissection of > > uncertainties, a surgery of suppositions. ~M.J.Moroney > > > > -Oorspronkelijk bericht- > > Van: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] Namens Robin Hankin > > Verzonden: donderdag 23 november 2006 14:12 > > Aan: [EMAIL PROTECTED] > > Onderwerp: [R] t.test() > > > > Hi > > > > I have a vector x of length n. I am interested in x[1] > > being different from the other observations (ie x[-1]). > > > > My null hypothesis is that x[1] > > is drawn from a Gaussian distribution of the same > > mean as observations x[-1], which are assumed > > to be iid Gaussian. The (unknown) variance > > of x[1] is assumed to be the same as the > > variance of x[-1]. > > > > > > This should be an unpaired t-test. > > > > But > > > > > > > x <- c(23,25,29,27,30,30) > > > t.test(x=x[1] , y=x[-1]) > > Error in t.test.default(x = x[1], y = x[-1]) : > > not enough 'x' observations > > > > > > > > > > > What arguments do I need to send to t.test() to test my null? > > > > > > > > > > > > > > > > -- > > Robin Hankin > > Uncertainty Analyst > > National Oceanography Centre, Southampton > > European Way, Southampton SO14 3ZH, UK > > tel 023-8059-7743 > > > > __ > > 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 > > and provide commented, minimal, self-contained, reproducible code. > > > > __ > > 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 > > and provide commented, minimal, self-contained, reproducible code. > > > > -- >O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B > c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K > (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 > ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 > > __ > 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 > and provide commented, minimal, self-contained, reproducible code. > __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] [Rd] How to link to vignette from .Rd file
2006/11/8, Agner Fog <[EMAIL PROTECTED]>: > Thanks for the tip. I had thought of using the demo facility for this > but I didn't know how to check for the operating system. See help about '.Platform'. I.e., > .Platform$OS.type can be useful. > This is a clumsy solution, but better than nothing. I agree with Duncan > that there is a problem with the help system. It should either have a > way to embed formulas and graphics in .chm files, or a way to use .pdf > files for help under all operating systems. The latter solution is > probably easier to implement. > > Unfortunately, I personally don't have the time to contribute to > improving the help system of R. Maybe tasks like this could be offered > as projects to university students. Many students are doing useless > projects so why not use this resource for something useful. > > I have proposed to use R instead of Matlab for teaching math and signal > analysis at my university college, but I am not teaching math myself so > it's not my decision. If more universities were using R instead of > Matlab, Mathcad, SAS, etc. then they would also be motivated to > contribute to the development. > > > Dominick Samperi wrote: > > > Duncan Murdoch wrote: > > > >> On 11/7/2006 8:51 AM, Agner Fog wrote: > >> > >> > >>> I am building a package for various noncentral hypergeometric > >>> distributions. > >>> > >>> I want to include some heavy mathematical formulas. It appears that > >>> the build and INSTALL commands produce only .chm files and not .pdf > >>> files from my .Rd files under Windows. This means that it cannot > >>> show complicated mathematical formulas. > >>> > >>> The solution might be to include a .pdf file as a vignette. I tried > >>> that, but I can't find any way to link to the .pdf file or access it > >>> from any of the help facilities. The .pdf file is useless if the > >>> user can't find it. > >>> > >> > >> > >> Yes, that's a major problem in the current R help system. You can > >> give the user code that would work to show the vignette, but there's > >> no way to create a live link to it. > >> > > > > The demo system can be used to compensate for limitations of the help > > system. > > You can display PDF files from any package subdirectory using a demo file > > like this (named demo/ReadPkgDoc.R, and documented in demo/00Index): > > > > # ReadPkgDoc.R -- Displays a PDF file as a demo > > # > > isWindows <- (Sys.info()['sysname'] == 'Windows') > > file <- system.file("doc", "PkgManual.pdf", package="PkgName") > > if(isWindows) { # Windows automatically finds executable based on file > > type. > > system(paste("CMD /C ", file, "\n")) > > } else { # Change this to use path to Adobe reader if desired. > > system(paste("xpdf ", file, "\n")) > > } > > > > To create the PDF file from the Rd file use R CMD Rd2dvi, and dvipdf. > > > > ds > > > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] (no subject)
put the constrained predictor in the model offset ('offset' argument in 'lm'). i.e.: > set.seed(10) > X <- matrix(rnorm(20), 10, 2) > y <- X %*% c(1,2) + rnorm(10) > coef(lm(y ~ X[,2], offset=X[,1])) (Intercept) X[, 2] -0.8009112 1.6968198 > coef(lm(I(y-X[,1]) ~ X[,2])) (Intercept) X[, 2] -0.8009112 1.6968198 Antonio. 2006/11/1, John Gauss <[EMAIL PROTECTED]>: > Dear R users, > > Please excuse my inexperience. I am trying to contrain the coefficients of > my linear regression to equal one when using the <-lm(...) command. I've > searched "help(glm)" "help(model.offset)" etc. but I am unable to figure out > where to put this constraint. Your help would be greatly apprciated. > > 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 > and provide commented, minimal, self-contained, reproducible code. > __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Recurrence plot in package "tseriesChaos"
Hi Joy. 2006/10/23, Joydeep <[EMAIL PROTECTED]>: > > Hi, > I'm a new user of the R package, and I need to generate recurrence plots for > a set of 56 time series data. The package tseriesChaos has the function > "recurr" that gives a plot. But what I really need are the recurrence plot > parameters that are calculated from each plot (like %recur, %det, trend, > etc...) and that can be stored dynamically in a output file for all the 56 > datasets. > It seems that the function recurr does not calculate these parameters. I'm sorry, but I don't ever know what these parameters are. The 'recurr' function only computes a matrix of distances in the state space embedding-reconstructed from the given time series, and plots it as an image plot. I can only guess the parameters you're claiming can be computed from the distance matrix. Antonio. > Is there another function in the package that does so? If not, is there > another package that deals with recurrence quantification analysis? I would > be very glad to have this problem solved in R itself. > > Thanking in advance, > Joy > > __ > 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 > and provide commented, minimal, self-contained, reproducible code. > __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Recipe: Print a Color Sampler
Really fine. Should this go on the wiki? Antonio. 2006/10/22, Gabor Grothendieck <[EMAIL PROTECTED]>: > Here it is again corrected: > > getColorName <- function(colorNumber) colors()[colorNumber] > printColorSampler <- function(n = 0) { >i <- seq(colors()) >k <- ceiling(sqrt(length(i))) >xy <- cbind(floor(i/k)*2, i %% k) >plot(xy, type = "n", axes = FALSE, xlab = "", ylab = "") >text(xy[,1]+.5, xy[,2]+.2, i, col = colors(), cex = 0.7) >if (n > 0) > colors()[identify(xy, n = n, labels = colors(), plot = FALSE)] > } > # test > printColorSampler(0) > printColorSampler(1) > > > On 10/22/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > > I have removed the dots, vectorized it and changed the > > argument to the number points to be identified (default 0): > > > > getColorName <- function(colorNumber) colors()[colorNumber] > > printColorSampler <- function(n = 0) { > > i <- seq(colors()) > > k <- ceiling(sqrt(length(i))) > > xy <- cbind(floor(i/k)*2, i %% k) > > plot(xy, type = "n", axes = FALSE, xlab = "", ylab = "") > > text(x+.5, y+.2, i, col = colors(), cex = 0.7) > > if (n > 0) > > colors()[identify(xy, n = n, labels = colors(), plot = FALSE)] > > } > > # test > > printColorSampler(0) > > printColorSampler(1) > > > > > > > > On 10/22/06, Stefano Calza <[EMAIL PROTECTED]> wrote: > > > Thanks, might be very useful. > > > > > > I attached a slightly modified version that uses identify (whith an > > > argument to choose if use it), to return the name of the colors on the > > > panel. Left-click on the choosen colors, and right click to end. > > > > > > Stefano > > > > > > > > > On Sun, Oct 22, 2006 at 12:51:19PM +0100, Ana Nelson wrote: > > > I wrote this to help me choose a suitable plot color. You can set the > > > value of pch to whichever type of point you are using in your plot, > > > and then you can see what the various colors will look like. When > > > this plot it stretched to A4/Letter landscape it prints quite nicely, > > > even though it will look very bunched up initially. I have only used > > > this on my own machine which runs Apple OSX 10.4. > > > > > > I included a getColorName() convenience function to retrieve the name > > > of the color from its position in the colors() array which is printed > > > next to the dot in the plot. > > > > > > printColorSampler <- function() { > > > i <- 1 > > > pch <- 20 > > > l <- length(colors()) > > > k <- ceiling(sqrt(l)) > > > > > > plot(floor(i/k), i %% k, pch=pch, col=colors()[i], xlim=c(0, > > > k*2), ylim=c(0, k), axes=FALSE, xlab="", ylab="") > > > > > > for (i in 2:length(colors())) { > > >x <- floor(i/k)*2 > > >y <- i %% k > > >col=colors()[i] > > >points(x, y, pch=pch, col=col) > > >text(x+0.5, y+0.2, i, col=col, cex=0.7) > > > } > > > } > > > > > > getColorName <- function(colorNumber) { > > > colors()[colorNumber] > > > } > > > > > > __ > > > 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 > > > and provide commented, minimal, self-contained, reproducible code. > > > > > > > > > __ > > > 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 > > > and provide commented, minimal, self-contained, reproducible code. > > > > > > > > > > > > > > > > __ > 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 > and provide commented, minimal, self-contained, reproducible code. > __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Automatical download of needed packages from CRAN
install.packages("foo", dep="Depends") See online help. I think that the GUI version of install.packages automatically does that. Antonio. 2006/9/29, Søren Højsgaard <[EMAIL PROTECTED]>: > I write a package foo which requires a package bar (from CRAN) to work. So in > the DESCRIPTION file I write Depends: bar. I would like it to be so that when > one installs foo, then it is automatically checked whether bar is installed, > and if not then bar is also installed at the same time. I remember having > seen packages which do so, but I can not figure out the mechanism > 'Depends: bar' in the DESCRIPTION file does not solve the problem. Can anyone > help? > > A related question: How to check programmatically that a specific package is > loaded? > > Best regards > Søren > > [[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 > and provide commented, minimal, self-contained, reproducible code. > > > __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] [Rd] Sweave processes \Sexpr in commented LaTeX source (2.3.1patched and 2.4.0)
Hi. 2006/9/20, Marc Schwartz <[EMAIL PROTECTED]>: > Hi all, > > On FC5, using: > > Version 2.3.1 Patched (2006-08-06 r38829) > > and today's > > R version 2.4.0 alpha (2006-09-19 r39397) > > with the following .Rnw file: > > > \documentclass[10pt]{article} > \begin{document} > >This line should print '2': \Sexpr{1 + 1} > %% This line should NOT print '2': \Sexpr{1 + 1} If it's just a comment, why don't use something like: % \ Sexpr (del the space) or %\sexpr (change 'sexpr' with 'Sexpr') or %...the 'Sexpr' command (add a backslash in latex code) ? Antonio. > > \end{document} > > > The \Sexpr in the second line is processed even though the line is > commented. This results in the following .tex file content (in the case > of R 2.4.0): > > > \documentclass[10pt]{article} > \usepackage{/home/marcs/R.Files/SourceCode/R-alpha/share/texmf/Sweave} > \begin{document} > >This line should print '2': 2 > %% This line should NOT print '2': 2 > > \end{document} > > > > Shouldn't Sweave just generally ignore commented LaTeX code? In > reviewing Sweave.R I did not see a check for this, so perhaps there are > circumstances where one wants a \Sexpr in commented LaTeX code > processed. An example escapes me at the moment however. > > HTH, > > Marc Schwartz > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Connecting to a SQLBASE database with R
The ODBC protocol is a widely used standard for accessing databases sources, especially under m$ windows. I think you can use RODBC for accessing your SQLBASE data, at least after some machine configuration... Antonio. 2006/9/8, SPIESSER Vincent <[EMAIL PROTECTED]>: > > Hi, > > I am trying to extract data from a database with R in order to produce > monthly statistics. > > I found in the R Website, the package RODBC, RSQLite and others ones which > permit this kind of extraction. > > The database I want to be connected with is a SQLBASE 7.0 database. > So, I would like to know if, using one of these package or another one, I > could be able to connect with this type of database. > > > I hope I would be understood. I am not a database specialist and, being > french, my english is a little bit poor. > > Thanks for your response. > > Vincent Spiesser > > > - > Ce message a ete scanne par l'anti-virus du Conseil General du Finistere. > - > [[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 > and provide commented, minimal, self-contained, reproducible code. > __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] problem with putting objects in list
Use 'sapply' instead of 'lapply'. Type >?lapply for details Antonio, Fabio Di Narzo. University of Bologna, Italy 2006/9/6, Rainer M Krug <[EMAIL PROTECTED]>: > Hi > > I use the following code and it stores the results of density() in the > list dr: > > dens <- function(run) { density( positions$X[positions$run==run], bw=3, > cut=-2 ) } > dr <- lapply(1:5, dens) > > but the results are stored in dr[[i]] and not dr[i], i.e. plot(dr[[1]]) > works, but plot([1]) doesn't. > > Is there any way that I can store them in dr[i]? > > Thanks a lot, > > Rainer > > > > -- > Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation > Biology (UCT) > > Department of Conservation Ecology and Entomology > University of Stellenbosch > Matieland 7602 > South Africa > > Tel:+27 - (0)72 808 2975 (w) > Fax:+27 - (0)21 808 3304 > Cell: +27 - (0)83 9479 042 > > email: [EMAIL PROTECTED] > [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 > and provide commented, minimal, self-contained, reproducible code. > __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] tsDyn and RTisean packages on CRAN
Dear R users, I've just uploaded 2 packages on CRAN, RTisean and tsDyn, both for time series analysis (joint research projects with members of the Statistics Department, University of Udine). Brief descriptions follow. RTisean is an R interface to TISEAN executables (http://www.mpipks-dresden.mpg.de/~tisean/). TISEAN is a suite of C and Fortran routines for nonlinear time series analysis, coded and documented by Rainer Hegger, Holger Kantz and Thomas Schreiber. In RTisean, almost all TISEAN routines are wrapped in a conventional R function (which silently calls TISEAN executables), with online help and examples (thanks to Gianluca Gazzola). tsDyn is a package for nonlinear time series modelling. At this point the package focuses on Nonlinear Autoregressive Models, often indicated as NLAR (as a major reference, see Tong (1990)). Currently available are threshold (SETAR and LSTAR), neural networks (NNET), and additive autoregressive (AAR) models. An experimental cross-platform tcltk GUI is included for model selection. Explorative and diagnostic tools are also available. A vignette is included for a clearer presentation of the package contents. Comments and suggestions appreciated Antonio, Fabio Di Narzo Dipartimento di Statistica Università degli studi di Bologna. ___ R-packages mailing list [EMAIL PROTECTED] https://stat.ethz.ch/mailman/listinfo/r-packages __ 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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] Building packages in R - 'private' functions
1. If you have time to change internal functions naming, you can rename internal functions by putting a leading '.'. Even without namespace, I have noticed there is no check for corresponding docs for such functions. 2. If you don't want to rename all internal functions, the best way is writing an 'internals.Rd' file with an alias for each internal function (documented in 'writing R extensions'). 3.Finally, you can add a NAMESPACE (see writing R extensions). However, if you use S3/S4 classes, this can be much more tedious to do. I think the no. 2 to be the fastest/safer way. Antonio. 2006/6/7, Dan Rabosky <[EMAIL PROTECTED]>: > > > Hello. > > I am creating an R package that I'd like to submit to CRAN (OS Windows > XP). How do I distinguish among 'public' functions, e.g., those that are > intended to be called by users of the package and for which I am providing > documentation & examples, and 'private' functions, which are used > internally by the 'public' functions, but for which I do not wish to > provide documentation? The private functions are all coded in R (nothing > in C or Fortran) and are essential to the operation of several public > functions. > > I have been unable to find any documentation on this in the 'writing r > extensions' manual', on previous posts to R-help, or through any other > source. One possibility is to include the source code for the 'private' > functions within the public functions. However, since multiple public > functions utilize the same core set of 'private' functions, this seems > unwieldy and redundant at best. > > If I simply include the source for the 'private' functions in the "R" > directory (without corresponding *.Rd and *.html documentation in /man), > then check the package with "R CMD check', it does appear to process the > private functions (and successfully builds with R CMD build). However, I > do receive a warning for including undocumented code objects. Is this the > recommended approach and/or is there a better way to do this? One > potential problem with this approach is that - should an error occur > within > a private function, it may be very difficult for the user to decipher the > nature of the problem. > > Any suggestions will be greatly appreciated. > ~Dan Rabosky > > > > Dan Rabosky > Department of Ecology and Evolutionary Biology > 237 Corson Hall > Cornell University > Ithaca, NY14853-2701 USA > [EMAIL PROTECTED] > web: http://www.birds.cornell.edu/evb/Graduates_Dan.htm > > __ > 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 > [[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] strange (to me) ncolumns default value in 'write'
Hi all. In 'write' documentation, one can read: write(x, file = "data", ncolumns = if(is.character(x)) 1 else 5, append = FALSE, sep = " ") Now my question is: why the default value of 1column for character vectors and the special value '5' for non character vectors? Nice sunday to all, Antonio, Fabio Di Narzo. Note: this is just curiosity. Don't read as: "WHY? WHY!?!?", but just as "why?" [[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] Is there a way to draw 3d plot?
2006/5/26, Michael <[EMAIL PROTECTED]>: > > On 5/26/06, Uwe Ligges <[EMAIL PROTECTED]> wrote: > > > > Michael wrote: > > > > > Hi all, > > > > > > I have a 2D matrix, which has 100 rows, and 100 columns, > > > > > > I have a 2D matrix, with 100 rows and 100 columns, > > > > > > I want to display it using 3D plot, much like plot3d and mesh/surf > > functions > > > in matlab. > > > > > > Specifically, in matlab, I just need to do the following: > > > > > > > > > [X, Y]=meshgrid([0:0.01:0.99, 0:0.01:0.99]); > > > % Z is my 2D matrix, > > > surf(X, Y, Z); > > > > > > > > > Note that X and Y are created so that I can associate physical meaning > > onto > > > the x and y axis of the 3D plot. > > > > > > For example, my 100 rows represent 0, 0.01, 0.02, ... 0.99 here. > > > > > > In Matlab I can also drag in the graphic window and see from different > > > visual angle and perspective of the 3D plot... > > > > > > Are there similar functions in R that (1) show 3D plot; (2) let me > > > manipulate view angles easily? > > > > (1) See ?persp > > > > (1) *and* (2): See package "rgl". > > > > Uwe Ligges > > > > > > > > Thanks a lot, > > But a glance at "rgl" seems requireing "shape", etc... and very > complicated... > > Any easier approaches? > > "persp" does not allow me to use mouse to rotate > > [[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 > Have you seen the example in 'rgl' man page? It seems sufficient something like: rgl.surface(x,y,z) In that example, is also showed how to colorize the surface. Antonio. [[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] missed ylim from plot.default
2006/5/26, Peter Ehlers <[EMAIL PROTECTED]>: > > > Antonio, Fabio Di Narzo wrote: > > > Hi all. > > On my R-2.3.0, calling: > > > > > >>plot(1:5, rep(1,5), xlim=c(-0.5,7), ylim=c(-0.5,2.8), asp=1) > > > > > > gives to me a plot (tried pdf and X11) whose y axis goes from about -2 > to > > about 4.5. What I've missed? How can I show some pre-specified x and y > > ranges from a plot (keeping fixed the aspect ratio)? > > > > Tnx all, > > Antonio, Fabio Di Narzo. > > > > [[alternative HTML version deleted]] > > Do you want a wide, but not very tall plot? If so, you > could specify the width/height in your X11() call. > > Peter Ehlers > > Tnx for your indication, now I see: x and y plotting ranges are influenced by the actual window size (at least when fixing aspect ratio). I think this is obvious... What I missed/forgot above, was that default plot width and height are fixed indipendently from the 'x-ylim' and 'asp' arguments. However now I have a problem: I can write a wrapper to set device width and height depending on the (xlim,ylim,asp) triple. But there's often extra-space in the device due to plot title, axis labels, etc. So, I fear I can't simply set width=height*asp. Some suggestion? (Anyway, by now I only have to produce few plots, so today I can go try by try :-) ). Bests, Antonio. [[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] missed ylim from plot.default
Hi all. On my R-2.3.0, calling: > plot(1:5, rep(1,5), xlim=c(-0.5,7), ylim=c(-0.5,2.8), asp=1) gives to me a plot (tried pdf and X11) whose y axis goes from about -2 to about 4.5. What I've missed? How can I show some pre-specified x and y ranges from a plot (keeping fixed the aspect ratio)? Tnx all, Antonio, Fabio Di Narzo. [[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] extracting values from data.frame given arbitrary keys
Hi all. I have a pure R programming question. Having a data.frame with a 'data' variable and some (>1) ID variables (either numeric or factors), I would extract a sequence of data values given a sequence of ID values. Here's an example. Build a dataset: n1 <- 5 n2 <- 2 v1 <- rep(factor(1:n1),2) v2 <- rep(1:n2,5) x <- rnorm(10) dat <- data.frame(x=x, v1=v1, v2=v2) Now, for example, I should extract x values responding to some arbitrary IDs: (v1="2", v2=1), (v1="3", v2=2), (v1="4", v2=1). For example, I should store those id sequences in a separate list (maybe an indexing data.frame), but this really isn't the point. The point is that I have somewhere a ready sequence of IDs from which obtaining corresponding data. Note that I don't know if some ID combination exists in the database. Some suggestions on a good way to do this? Tnx all, Antonio, Fabio Di Narzo. [[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] SQL like manipulations on data frames
Do you know the RSQLite package? It uses the DBI package which gives a common interface to various DB engines. With it, you can explicitely treat data.frames as tables, and execute SQL querys on them. Antonio, Fabio Di Narzo. 2006/5/5, Robert Citek <[EMAIL PROTECTED]>: > > > Is there a cheat-sheet anywhere that describes how to do SQL-like > manipulations on a data frame? > > My knowledge of R is rather limited. But from my experience it seems > as though one can think of data frames as being similar to tables in > a database: there are rows, columns, and values. Also, one can > perform similar manipulations on a data frame as one can on a table. > For example: > > select * from foo where bar < 10 ; > > is similar to > > foo[foo["bar"] < 10,] > > I'm just wondering how many other SQL-like manipulations can be done > on a data frame? As an extreme example, is it reasonable to assume > there is an R equivalent to: > > select bar, bat, baz, baz*100 as 'pctbaz' from foo where bar like %xyz > % order by bat, baz desc ; > > Regards, > - Robert > http://www.cwelug.org/downloads > Help others get OpenSource software. Distribute FLOSS > for Windows, Linux, *BSD, and MacOS X with BitTorrent > > __ > 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 > [[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] question on residuals df in weighted linear regression
Hi all. I have a doubt with weighted linear regression. I've noted that supplying integer weights gives different residuals df than giving 'double' weights. Here an example: x <- 1:5 y <- -1 + 2*x + rnorm(length(x))*0.1 y <- c(y, x + rnorm(length(x))*0.1) dat <- data.frame(x=rep(x,2), y = y) #integer weights: dat$w1 <- rep(0:1, each=length(x)) #double weights: dat$w2 <- dat$w1 dat$w2[dat$w2==0] <- .Machine$double.neg.eps dat$w2[dat$w2==1] <- 1- .Machine$double.neg.eps lm(x~y, data=dat, weights=w1)$df.residual #[1] 3 lm(x~y, data=dat, weights=w2)$df.residual #[1] 8 Estimated coefficients are, as expected, the same in the two cases, but residuals df changes a lot. This also has strong effect on residual standard error estimation, an thus in many other model summaries, which in the above case to me seems more sensible in the first case. Why a so different evaluation of residuals df? Antonio, Fabio Di Narzo. [[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] as.factor: changed behaviour for Date class
Dear all, I have noticed a little change in the behaviour of as.factor from R-2.2.1 to R-2.3.0, and can't find it in the NEWS. In R-2.3.0: > times <- 1:5 > class(times) <- "Date" > as.factor(times) [1] 1 2 3 4 5 Levels: 1 2 3 4 5 In R-2.2.1: > as.factor(times) [1] 1970-01-02 1970-01-03 1970-01-04 1970-01-05 1970-01-06 Levels: 1970-01-02 1970-01-03 1970-01-04 1970-01-05 1970-01-06 Is this the intended behaviour? Note that the change is reflected on other functions which seems to use as.factor internally, for example 'tapply'. Consider the following code: times <- 1:5 class(times) <- "Date" id <- rep(times, each=2) vals <- rep(1:2,5) tapply(vals, id, mean) Under R-2.2.1 this gives: 1970-01-02 1970-01-03 1970-01-04 1970-01-05 1970-01-06 1.51.51.51.51.5 But under R-2.3.0 the output is: 1 2 3 4 5 1.5 1.5 1.5 1.5 1.5 Antonio, Fabio Di Narzo. [[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] [Rd] R 2.3.0: Use of NULL as an environment is deprecated
2006/4/26, Uwe Ligges <[EMAIL PROTECTED]>: > > Pfaff, Bernhard Dr. wrote: > >>>>>>"BernPf" == Pfaff, Bernhard Dr <[EMAIL PROTECTED]> > >>>>>>on Wed, 26 Apr 2006 08:28:34 +0100 writes: > > > > > > BernPf> Dear Andy, Uwe and remaining list subscribers, > > BernPf> now, coming closer to the evil's root. Yesterday, I source > > compiled on a > > BernPf> Linux box at home and the result is the same behaviour as > > pointed out > > BernPf> below. This is regardless of the package version of 'urca'. > > Aside of > > BernPf> 'urca', other packages that have Imports/Depends entries in > > the > > BernPf> DESCRIPTION to packages that are shipped within the standard > > library of > > BernPf> R show the warning too, e.g. fMultivar, VLMC, to name but a > > few. > > BernPf> I do have set on both OS, i.e. Windows and Linux, a second > > library tree > > BernPf> in Renviron.site with R-LIBS. If I comment this out and do a > > reinstall > > BernPf> of the packages, i.e. the packages are now installed in the > > standard > > BernPf> library, the warning does not show up any longer. Has > > something changed > > BernPf> with regard to additional libraries that slipped my notice > > by upgrading > > BernPf> to version 2.3.0? > > > > I don't think so. > > I ***NEVER*** install a package into the standard library. > > We have all CRAN packages in a different library, > > (and Bioconductor too) and I typically use about 6 library (paths), > > and I don't have your problem. > > > > I only get your warning if I get a version of a package that was > > installed previous to 2.3.0 (or it's alpha / beta / rc ) versions. > > > > BernPf> Is it possible that during startup the environment is > > handeld/passed > > BernPf> differently for standard and additional libraries? Would > > this odd > > BernPf> behaviour qualify as a bug? > > > > If it was general, yes, but I think it's not. > > > > > > Hello Martin and all others involved in this thread, > > > > thank you very much for your time and patience. After having updated the > > packages in the standard library, too, the warning message does indeed > > not show up any longer by issuing the command library(urca) and similar > > with other packages. Just out of curiosity, I wonder what has changed in > > these packages (i.e. nlme, foreign, cluster and VR got updated) from > > downloading the '.exe' or the tarball in the official 2.3.0 release up > > to now? > > > For sure you got (or still had in front of your R_LIBS path) packages > that were compiled for R < 2.3.0! That's it. Very simple. > > Uwe Ligges > > > > Best, > > Bernhard > > * > > Confidentiality Note: The information contained in this message, > > and any attachments, may contain confidential and/or privileged > > material. It is intended solely for the person(s) or entity to > > which it is addressed. Any review, retransmission, dissemination, > > or taking of any action in reliance upon this information by > > persons or entities other than the intended recipient(s) is > > prohibited. If you received this in error, please contact the > > sender and delete the material from any computer. > > * > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > I'm happy the problem was solved. I had the same problem with a package of mines (not on CRAN). The problem was an imported package that was compiled for R-2.2.0. Tnx all for solving my problem just before posting it on the list:D Antonio, Fabio Di Narzo. [[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] garch warning
What package are you using? If you're using tseries, NA's are not allowed in the time series, so you have to trim out your first missing with a command like: x1 <- na.remove(x) made available by tseries itself. But I'm note sure is the first NA your problem... You should provide reproducible example, if you can. Antonio, Fabio Di Narzo. 2006/4/24, stat stat <[EMAIL PROTECTED]>: > > Dear r users, > > Few days ago I posted the same topic but unable to receive any > suggestion. So I am asking this same question. > > I was trying to fit a garch(1,1) model to my dataset. But while > executing I got a warning message "NaNs produced in: sqrt(pred$e)". And got > the estimated sd's along with five "NA", but as per my best knowledge I > should get only one "NA" i.e. corresponding to the first observation only. > If anyone tell me why I got this message it will be a great advantage for > me. > > With regards, > > > > thanks in advance > > - > > > [[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 > [[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] latex-like array in Rd documents
Hi all. Is it possible to use something like latex array environments in Rd files? This is just for typesetting a formula of the type: something=a if TRUE, b if FALSE in two lines instead of one line. Any suggestion is wellcome. Antonio, Fabio Di Narzo. [[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] cross product
2006/4/8, He, Yulei <[EMAIL PROTECTED]>: > > Hi, there. > > > > How do I calculate the cross-product in the form of > \sum_{i=1}^{n}X_{i}^{t} \Sigma X_{i} using R code without using do loop? > X_{i} is the covariate matrix for subject I, \Sigma is the covariance > matrix. If I don't miss something in the matrix algebra, maybe you want the following: > crossprod(crossprod(t(X),sigma),X) where X is the 'n by d' matrix of covariates, and sigma the 'd by d' matrix of assigned covariances. Antonio, Fabio Di Narzo. Thanks for your help. > > > > Yulei > > > > > [[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 > [[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] GARCH Forecast?
2006/3/30, Peter Arnold <[EMAIL PROTECTED]>: > I am trying to forecast volatility 2 periods forward using a ARCH(1) > model: > > predict(garch(fit2,order=c(0,1),n.ahead=2)) Misplaced ')'. Maybe: predict(garch(...),n.ahead=2) Anyway, typing: ?predict.garch (I'm referring to the tseries package) I can't see any 'n.ahead' argument support documented. Antonio, Fabio Di Narzo. * ESTIMATION WITH ANALYTICAL GRADIENT * > > > Error in qr(com.hess$hess, ...) : unused argument(s) (n.ahead ...) > > > What did I do wrong? > > Thank you. > > > Best regards, > > > > Peter Arnold, CFA > President > PRA Investment Counsel, Inc. > 704-341-8193 > www.prainvestment.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 > [[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] create a gui with a button to change graphic?
See demos in the tcltk package. I remember there was some example of interactive graphics, with buttons to change graphical parameters. You can start from there... Antonio, Fabio Di Narzo. 2006/3/20, Gael de Lannoy <[EMAIL PROTECTED]>: > > Hello everybody, > > I am wondering if it is possible to create a gui to plot a time series > that is very big, it's an EEG signal of 20mins. What I would like to do > is plot the first 5mins, then have a button on the gui that plots the > next 5mins when pushed. > > Is it possible? > > Thanks in advance ! > > Gael. > > __ > 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 > > [[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] fitting problems detection in nnet
Dear all, could someone suggest some strategies for detecting fitting problems in neural network estimation? I'm using the nnet package for fitting standardized simulated data (some thousands estimations are required). The estimation is generally ok, but sometimes (about 1-3 every 1000) I found too big final weights in the neural network (and so, output saturation...). In my specific application this is not a real problem, and I can simply check if fitted values are costant ('cause this is what I've seen in those bad fits), but I'm asking if there are better strategies for marking a fitted model as "possibly wrong". For example, is there a way for checking if convergence was reached during error criterion optimization? Tnx all, Antonio, Fabio Di Narzo. [[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] variance from correlated observations
Hi all. A statistical question. I have to estimate the variance of the sum: X(1) + X(2) + ...+ X(n) from an observed sample, where X(i) are *correlated* and not necessarly identically distributed. Someone can suggest a simple strategy (I hope by exploiting some already present R package) for obtaining such estimate from an observed vector X[1:n]? Tnx all, Antonio, Fabio Di Narzo. [[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] lag.plot messy labels default
Hi all. Using R 2.2.1 I have encountered the following trivial problem with lag.plot. lag.plot(1:3) produces a labelled, directed lines "lag plot". But labels are taken to be as.character(1:3) so x-y coordinates for the last label have to be recycled, and one actually sees on the screen labels "1" and "3" overlapping. Typing: lag.plot(1:3, labels=as.character(1:2)) solves the problem. Of course, the problem is there for univariate time series of any length (just tried some values:D ). Have a nice week end, Antonio, Fabio Di Narzo. __ 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 get the row name?
2006/1/30, Ionut Florescu <[EMAIL PROTECTED]>: > > I don't know about rownames but > x >= 0 gives you a vector of logical values True and false. > If then you do > c(1:length(x)) [x>=0] > this gives the positions where the true happened, meaning your vector of > values. But also returns NA's, if present in 'X'. If you're really interested in indices of matched condition, consider using 'which': which(mydata$X>=0) Anyway, if you're really interested in rownames instead of numerical indices, you have various options. For example: rownames(mydata)[which(mydata$X>=0)] or, more compactly, as Chuck Cleland has suggested: rownames(subset(mydata, X >=0)) Antonio, Fabio Di Narzo. > Chuck Cleland wrote: > > rownames(subset(mydata, X >=0)) > > > > ?rownames > > > > Leaf Sun wrote: > > > >> Hi R-listers, > >> > >> I have a simple question about a data frame. > >> > >> I sorted a data set by one of the variable in some condition (eg. > X>=0), the followed is part of the achieved. I was wondering how can I get > the row name, i. e. (1202, 2077 , 2328, 3341,... ) and save them as a > vector. Thanks! > >> > >>Tag Species X Y Dbh3 Recr4 mort slope > elevation aspectSA SR dist1 dist2 dist3 > >> 120219103 316 856.0 430.3 21 41 9.87151.42 > 60.08 25.38 1.02 0.2236068 0.7211103 1.3601471 > >> 207729893 316 935.4 482.7 28 41 5.66137.28 > 13.86 25.14 1.01 0.6403124 0.8944272 1.0630146 > >> 232832989 316 910.7 301.5 12 41 8.07137.69 > 86.16 25.26 1.01 0.300 1.2806248 1.3038405 > >> 334145198 316 975.2 2.4 144 41 2.95121.10 > 173.60 0.00 0.00 0.5656854 1.2727922 1.3416408 > >> ... > >> > >> Regards, > >> > >> Leaf > >> > >> > >> > >> > > >> > >> __ > >> 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 > > [[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] Fit non-lineair 3D Data
2005/12/18, Bart Joosen <[EMAIL PROTECTED]>: > Hi, > > I have a problem with fitting a model: > I made a dataframe with this data: > a <- 1:3 > b <- 1:3 > c <- c(3, 2, 3, 2, 1, 2, 3, 2, 3) > df <- expand.grid(a,b) > df$result <- c > names(df) <- c("A","B", "result") > > Although I can make a graph of the data: > require(lattice) > wireframe(result~A*B, data=df) > > I can't get a model to fit this 3D data. > > > I have tried the lm function, but its easy to see that this a non lineair > data set. The use of poly also isn't a solution. > I tried to use nls, but there seems to be an error? > mod <- nls(result~A:B, df, start = list (A=0, B=0)) > Error in qr.qty(QR, resid) : 'qr' and 'y' must have the same number of > rows That's not the proper way to use 'nls'. You have to already know which model to fit to data. 'nls' doesn't magically find it for you. Watch at: "An Introduction to R"->"Statistical Models in R"-> "Nonlinear least squares and maximum likelihood models" for an overview. There are various functions in R packages to do nonparametric even nonlinear fitting. Anyway, you should keep in mind that you really have'nt a lot of observations, so parametric models should be more appropriate. Antonio, Fabio Di Narzo. > > Is there a way to fit this data? > > > Thanks for your time by reading this, hopefully I will get an answer. > > Bart Joosen > > [[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] typo error in sink help page
In 'sink' help page (R version 2.2.0), you can read, in details: " If 'file' is a connection if will be opened if necessary. " Maybe: " If 'file' is a connection it will be opened if necessary. " Antonio, Fabio Di Narzo. [[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] bug in geoR (?)
I've enconuntered this problem with the last cran version of geoR: > library(geoR) > day <- rep(1:2, each=5) > coords <- matrix(rep(runif(10),2), 10, 2) > data <- rnorm(10) > data[1] <- NA > as.geodata(cbind(coords, data, day), realisations=4) as.geodata: 1 points removed due to NA in the data Errore in as.geodata(cbind(coords, data, day), realisations = 4) : realisations and coords have incompatible dimensions The problem disappear if I remove the NA manually from the dataset before passing to as.geodata. I.e.: > as.geodata(cbind(coords, data, day)[2:10,], realisations=4) works. Antonio, Fabio Di Narzo. [[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] getting variable length numerical gradient
2005/9/26, Dimitris Rizopoulos <[EMAIL PROTECTED]>: > AFAIK the deriv() is for symbolic derivatives, so I don't know if it > will work in your case. numericDeriv surely computes numerical gradient. The problem here is its interface, which requires the vector of symbols involved in the expression to differenziate. > > Best, > Dimitris > > > ----- Original Message ----- > From: "Antonio, Fabio Di Narzo" <[EMAIL PROTECTED]> > To: "Dimitris Rizopoulos" <[EMAIL PROTECTED]> > Cc: > Sent: Monday, September 26, 2005 10:58 AM > Subject: Re: getting variable length numerical gradient > > > Tnx very much Dimitris, > your code does what I need. I've just adapted it to my needs (e.g., I > don't deal with scalar functions), and so solved my problem. > > Given this, is there a way to use the deriv function in the base > package, within this context (variable length vector of indipendent > variables)? > > Best, > Antonio, Fabio Di Narzo. > > On 9/25/05, Dimitris Rizopoulos <[EMAIL PROTECTED]> > wrote: > > maybe you can find the following function useful (any comments are > > greatly appreciated): > > > > fd <- function(x, f, scalar = TRUE, ..., eps = > > sqrt(.Machine$double.neg.eps)){ > > f <- match.fun(f) > > out <- if(scalar){ > > if(length(f0 <- f(x, ...)) != length(x)) > > stop("'f' must be vectorized") > > x. <- x + eps * pmax(abs(x), 1) > > c(f(x., ...) - f0) / (x. - x) > > } else{ > > n <- length(x) > > res <- array(0, c(n, n)) > > f0 <- f(x, ...) > > ex <- pmax(abs(x), 1) > > for(i in 1:n){ > > x. <- x > > x.[i] <- x[i] + eps * ex[i] > > res[, i] <- c(f(x., ...) - f0) / (x.[i] - x[i]) > > } > > res > > } > > out > > } > > > > > > ## Examples > > > > x <- seq(-3.3, 3.3, 0.1) > > all.equal(fd(x, pnorm, mean = 0.5), dnorm(x, mean = 0.5)) > > > > > > # Approximate the Hessian matrix for a logistic regression > > > > # the score vector function > > gn <- function(b, y, X){ > > p <- as.vector(plogis(X %*% b)) > > -colSums(X * (y - p)) > > } > > > > # We simulate some data and fit the logistic regression > > n <- 800 > > x1 <- runif(n,-3, 3); x2 <- runif(n, -3, 3) > > pr <- plogis(0.8 + 0.4 * x1 - 0.3 * x2) > > y <- rbinom(n, 1, pr) > > fm <- glm(y ~ x1 + x2, binomial) > > > > ## The Hessian using forward difference approximation > > fd(fm$coef, gn, scalar = FALSE, y = y, X = cbind(1, x1, x2)) > > > > ## The true Hessian > > solve(summary(fm)$cov.unscaled) > > > > > > I hope it helps. > > > > Best, > > Dimitris > > > > > > Dimitris Rizopoulos > > Ph.D. Student > > Biostatistical Centre > > School of Public Health > > Catholic University of Leuven > > > > Address: Kapucijnenvoer 35, Leuven, Belgium > > Tel: +32/(0)16/336899 > > Fax: +32/(0)16/337015 > > Web: http://www.med.kuleuven.be/biostat/ > > http://www.student.kuleuven.be/~m0390867/dimitris.htm > > > > > > - Original Message - > > From: "Antonio, Fabio Di Narzo" <[EMAIL PROTECTED]> > > To: > > Sent: Sunday, September 25, 2005 11:37 AM > > Subject: [R] getting variable length numerical gradient > > > > > > > Hi all. > > > I have a numerical function f(x), with x being a vector of generic > > > size (say k=4), and I wanna take the numerically computed > > > gradient, > > > using deriv or numericDeriv (or something else). > > > > > > My difficulties here are that in deriv and numericDeric the > > > function > > > is passed as an expression, and one have to pass the list of > > > variables > > > involved as a char vector... So, it's a pure R programming > > > question. > > > > > > > > > Have a nice sunday, > > > Antonio, Fabio Di Narzo. > > > > > > __ > > > 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 > > > > > > > > > Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm > > > > > > > Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm > > __ 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] getting variable length numerical gradient
Tnx very much Dimitris, your code does what I need. I've just adapted it to my needs (e.g., I don't deal with scalar functions), and so solved my problem. Given this, is there a way to use the deriv function in the base package, within this context (variable length vector of indipendent variables)? Best, Antonio, Fabio Di Narzo. On 9/25/05, Dimitris Rizopoulos <[EMAIL PROTECTED]> wrote: > maybe you can find the following function useful (any comments are > greatly appreciated): > > fd <- function(x, f, scalar = TRUE, ..., eps = > sqrt(.Machine$double.neg.eps)){ > f <- match.fun(f) > out <- if(scalar){ > if(length(f0 <- f(x, ...)) != length(x)) > stop("'f' must be vectorized") > x. <- x + eps * pmax(abs(x), 1) > c(f(x., ...) - f0) / (x. - x) > } else{ > n <- length(x) > res <- array(0, c(n, n)) > f0 <- f(x, ...) > ex <- pmax(abs(x), 1) > for(i in 1:n){ > x. <- x > x.[i] <- x[i] + eps * ex[i] > res[, i] <- c(f(x., ...) - f0) / (x.[i] - x[i]) > } > res > } > out > } > > > ## Examples > > x <- seq(-3.3, 3.3, 0.1) > all.equal(fd(x, pnorm, mean = 0.5), dnorm(x, mean = 0.5)) > > > # Approximate the Hessian matrix for a logistic regression > > # the score vector function > gn <- function(b, y, X){ > p <- as.vector(plogis(X %*% b)) > -colSums(X * (y - p)) > } > > # We simulate some data and fit the logistic regression > n <- 800 > x1 <- runif(n,-3, 3); x2 <- runif(n, -3, 3) > pr <- plogis(0.8 + 0.4 * x1 - 0.3 * x2) > y <- rbinom(n, 1, pr) > fm <- glm(y ~ x1 + x2, binomial) > > ## The Hessian using forward difference approximation > fd(fm$coef, gn, scalar = FALSE, y = y, X = cbind(1, x1, x2)) > > ## The true Hessian > solve(summary(fm)$cov.unscaled) > > > I hope it helps. > > Best, > Dimitris > > > Dimitris Rizopoulos > Ph.D. Student > Biostatistical Centre > School of Public Health > Catholic University of Leuven > > Address: Kapucijnenvoer 35, Leuven, Belgium > Tel: +32/(0)16/336899 > Fax: +32/(0)16/337015 > Web: http://www.med.kuleuven.be/biostat/ > http://www.student.kuleuven.be/~m0390867/dimitris.htm > > > - Original Message - > From: "Antonio, Fabio Di Narzo" <[EMAIL PROTECTED]> > To: > Sent: Sunday, September 25, 2005 11:37 AM > Subject: [R] getting variable length numerical gradient > > > > Hi all. > > I have a numerical function f(x), with x being a vector of generic > > size (say k=4), and I wanna take the numerically computed gradient, > > using deriv or numericDeriv (or something else). > > > > My difficulties here are that in deriv and numericDeric the function > > is passed as an expression, and one have to pass the list of > > variables > > involved as a char vector... So, it's a pure R programming question. > > > > > > Have a nice sunday, > > Antonio, Fabio Di Narzo. > > > > __ > > 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 > > > > > Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm > > __ 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] getting variable length numerical gradient
Hi all. I have a numerical function f(x), with x being a vector of generic size (say k=4), and I wanna take the numerically computed gradient, using deriv or numericDeriv (or something else). My difficulties here are that in deriv and numericDeric the function is passed as an expression, and one have to pass the list of variables involved as a char vector... So, it's a pure R programming question. Have a nice sunday, Antonio, Fabio Di Narzo. __ 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] Fwd: ts.intersect bug?
2005/9/21, Gabor Grothendieck <[EMAIL PROTECTED]>: > On 9/21/05, Antonio, Fabio Di Narzo <[EMAIL PROTECTED]> wrote: > > -- Forwarded message ------ > > From: Antonio, Fabio Di Narzo <[EMAIL PROTECTED]> > > Date: 21-set-2005 15.34 > > Subject: Re: [R] ts.intersect bug? > > To: Martin Maechler <[EMAIL PROTECTED]> > > > > > > 2005/9/21, Martin Maechler <[EMAIL PROTECTED]>: > > > >>>>> "AntonioFDN" == Antonio, Fabio Di Narzo <[EMAIL PROTECTED]> > > > >>>>> on Wed, 21 Sep 2005 13:59:26 +0200 writes: > > > > > > AntonioFDN> This code gives an error: > > > > > > AntonioFDN> a <- ts(1:10, start=0, freq=10) > > > AntonioFDN> b <- ts(1:10, start=1, freq=10) > > > AntonioFDN> ts.intersect(a,b) > > > > > > No, it gives a *warning* and returns NULL. > > > > Ooops, bad example. > > Try this instead: > > a <- ts(runif(6500), start=0, freq=10) > > b <- lag(a, 1) > > c <- ts.intersect(a, b) > > > > Gives an error from .cbind.ts > > A workaround would be to convert both a and b to zoo class, > intersect them using zoo's merge and convert back to ts: > > library(zoo) > z <- as.ts(merge(as.zoo(a), as.zoo(b), all = FALSE)) > > Regarding your other question, > > Sys.putenv(LANGUAGE="en") > > will result in error messages in English. > Many tnx, and again sorry for the starting bad example. Will the ts.intersect bug addressed in next R release? Antonio, Fabio Di Narzo. P.S. A little OT: shouldn't the "Sys.putenv(LANGUAGE="en")" tip be put in the posting guide? __ 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] Fwd: ts.intersect bug?
-- Forwarded message -- From: Antonio, Fabio Di Narzo <[EMAIL PROTECTED]> Date: 21-set-2005 15.34 Subject: Re: [R] ts.intersect bug? To: Martin Maechler <[EMAIL PROTECTED]> 2005/9/21, Martin Maechler <[EMAIL PROTECTED]>: > >>>>> "AntonioFDN" == Antonio, Fabio Di Narzo <[EMAIL PROTECTED]> > >>>>> on Wed, 21 Sep 2005 13:59:26 +0200 writes: > > AntonioFDN> This code gives an error: > > AntonioFDN> a <- ts(1:10, start=0, freq=10) > AntonioFDN> b <- ts(1:10, start=1, freq=10) > AntonioFDN> ts.intersect(a,b) > > No, it gives a *warning* and returns NULL. Ooops, bad example. Try this instead: a <- ts(runif(6500), start=0, freq=10) b <- lag(a, 1) c <- ts.intersect(a, b) Gives an error from .cbind.ts __ 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] ts.intersect bug?
This code gives an error: a <- ts(1:10, start=0, freq=10) b <- ts(1:10, start=1, freq=10) ts.intersect(a,b) This one works normally (and correctly): a <- ts(1:10, start=0) b <- ts(1:10, start=1) ts.intersect(a,b) Antonio, Fabio Di Narzo. P.S. How to switch off italian error messages to post on r-help? > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor1.0 year 2005 month04 day 18 language R __ 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] TeX distribution on Windows
With my windows installation, MikTeX works fine, without any problem in compiling packages documentation. Antonio, Fabio Di Narzo. 2005/9/5, Göran Broström <[EMAIL PROTECTED]>: > I'm looking for a Windows distribution of TeX that works with R, after a > few years' absence from Windows. On Duncan Murdoch's Rtools page fptex is > still recommended, but it turns out that fptex is "defunct" as of May 2005, > see > > http://www.metz.supelec.fr/~popineau/xemtex-7.html > > So, what is suggested? TUG (tug.org) recommends something called proTeXt, > which is said to be "based on MiKTeX", for Windows users. Since MikTeX > could be used with R, that sounds like a good alternative. > > Any comments to that? > > -- > Göran Broströmtel: +46 90 786 5223 > Department of Statistics fax: +46 90 786 6614 > Umeå University http://www.stat.umu.se/~goran.brostrom/ > SE-90187 Umeå, Sweden 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 > __ 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] source package linking problem under linux
02 Sep 2005 18:15:22 +0200, Peter Dalgaard <[EMAIL PROTECTED]>: > "Antonio, Fabio Di Narzo" <[EMAIL PROTECTED]> writes: > > > I'm having some problems in installing some source packages under linux. > > As an example, MCMCpack. An error is raised when linking: > > > > > install.packages("MCMCpack") > > [...] > > * Installing *source* package 'MCMCpack' ... > > checking for C++ compiler default output file name... a.out > > checking whether the C++ compiler works... yes > > checking whether we are cross compiling... no > > checking for suffix of executables... > > checking for suffix of object files... o > > checking whether we are using the GNU C++ compiler... yes > > checking whether g++ accepts -g... yes > > checking for gcc... gcc > > checking whether we are using the GNU C compiler... yes > > checking whether gcc accepts -g... yes > > checking for gcc option to accept ANSI C... none needed > > checking how to run the C preprocessor... gcc -E > > checking for egrep... grep -E > > checking for ANSI C header files... yes > > checking for sys/types.h... yes > > checking for sys/stat.h... yes > > checking for stdlib.h... yes > > checking for string.h... yes > > checking for memory.h... yes > > checking for strings.h... yes > > checking for inttypes.h... yes > > checking for stdint.h... yes > > checking for unistd.h... yes > > checking ieeefp.h usability... no > > checking ieeefp.h presence... no > > checking for ieeefp.h... no > > checking for trunc... no > > configure: creating ./config.status > > config.status: creating src/Makevars > > ** libs > > g++ -I/usr/lib/R/include-DSCYTHE_COMPILE_DIRECT -DSCYTHE_NO_RANGE > > -c distributions.cc -o distributions.o > > [...etc. etc. All compilations are ok] > > > > g++ -o MCMCpack.so distributions.o ide.o la.o lecuyer.o MCMCdistn.o > > MCMCdynamicEI.o MCMCfactanal.o MCMCfcds.o MCMChierEI.o MCMCirt1d.o > > MCMClogit.o MCMCmetrop1R.o MCMCmixfactanal.o MCMCmnlMH.o > > MCMCmnlslice.o MCMCoprobit.o MCMCordfactanal.o MCMCpanel.o > > MCMCpoisson.o MCMCprobit.o MCMCprobitres.o MCMCregress.o MCMCrng.o > > MCMCtobit.o mersenne.o optimize.o rng.o smath.o stat.o > > -L/usr/lib/R/lib -lR > > /usr/lib/gcc-lib/i486-linux/3.3.5/../../../crt1.o(.text+0x18): In > > function `_start': > > ../sysdeps/i386/elf/start.S:98: undefined reference to `main' > > collect2: ld returned 1 exit status > > make: *** [MCMCpack.so] Error 1 > > ERROR: compilation failed for package 'MCMCpack' > > > > I don't know why it searches a reference to 'main'... > > > > Presumably because it thinks that MCMCpack.so is supposed to be a > standalone binary. (Compilers don't read filname suffixes...) > > There would seem to be something missing in that command line, > "-shared" if my memory serves me. Yes, it is... > Now *why* that happens is a bit hard > to figure out. Your version info below is not quite sufficient; which > linux distribution is it? Did you compile R itself from sources? I'm using ubuntu 5.04 (debian based), and installed precompiled binary version of R from an italian cran mirror ('woody' subdirectory). Another package with the *same* problem: bayesm. Maybe the problem is that ther's c++ code? What should I do? > > > Antonio, Fabio Di Narzo. > > > > > > > version > > _ > > platform i386-pc-linux-gnu > > arch i386 > > os linux-gnu > > system i386, linux-gnu > > status > > major2 > > minor1.1 > > year 2005 > > month06 > > day 20 > > language R > > > > __ > > 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 > > > > -- >O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B > c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K > (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 > ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 > __ 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] source package linking problem under linux
I'm having some problems in installing some source packages under linux. As an example, MCMCpack. An error is raised when linking: > install.packages("MCMCpack") [...] * Installing *source* package 'MCMCpack' ... checking for C++ compiler default output file name... a.out checking whether the C++ compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C++ compiler... yes checking whether g++ accepts -g... yes checking for gcc... gcc checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ANSI C... none needed checking how to run the C preprocessor... gcc -E checking for egrep... grep -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking ieeefp.h usability... no checking ieeefp.h presence... no checking for ieeefp.h... no checking for trunc... no configure: creating ./config.status config.status: creating src/Makevars ** libs g++ -I/usr/lib/R/include-DSCYTHE_COMPILE_DIRECT -DSCYTHE_NO_RANGE -c distributions.cc -o distributions.o [...etc. etc. All compilations are ok] g++ -o MCMCpack.so distributions.o ide.o la.o lecuyer.o MCMCdistn.o MCMCdynamicEI.o MCMCfactanal.o MCMCfcds.o MCMChierEI.o MCMCirt1d.o MCMClogit.o MCMCmetrop1R.o MCMCmixfactanal.o MCMCmnlMH.o MCMCmnlslice.o MCMCoprobit.o MCMCordfactanal.o MCMCpanel.o MCMCpoisson.o MCMCprobit.o MCMCprobitres.o MCMCregress.o MCMCrng.o MCMCtobit.o mersenne.o optimize.o rng.o smath.o stat.o -L/usr/lib/R/lib -lR /usr/lib/gcc-lib/i486-linux/3.3.5/../../../crt1.o(.text+0x18): In function `_start': ../sysdeps/i386/elf/start.S:98: undefined reference to `main' collect2: ld returned 1 exit status make: *** [MCMCpack.so] Error 1 ERROR: compilation failed for package 'MCMCpack' I don't know why it searches a reference to 'main'... Antonio, Fabio Di Narzo. > version _ platform i386-pc-linux-gnu arch i386 os linux-gnu system i386, linux-gnu status major2 minor1.1 year 2005 month06 day 20 language R __ 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] Anybody have a binary version of SJava for rw2001 (Windows)?
On the omegahat site, you can read: "There is currently no binary available for Windows. I hope to release one wihtin a few weeks (i.e. near the end of September, 2004)." You can ask to developers an "unofficial" binary version for you. Maybe they have, or maybe they're esperiencing problems in building it, in which case I fear you have to stand by a little more... Antonio, Fabio Di Narzo. Il giorno mar, 26/07/2005 alle 23.39 +0100, Quin Wills ha scritto: > I am not a techie and have been struggling 2 days solid to try and install > SJava (the source from http://www.omegahat.org/RSJava/). Does anybody have a > binary file for me (I am Windows XP and rw2001)? I have tried installing > Perl, mingwin and the cygwin tools but still no luck. When I try R CMD > INSTALL c:\SJava_0.78-0.tar.gz I get the following (and havent a clue what > it could mean): > > > > -Making package SJava-- > Building JNI header files... > Extracting the classes from Environment.jar > /jdk1.3/bin/jar: not found > RForeignReference > /jdk1.3/bin/javah: not found > ROmegahat Interpreter > /jdkl.3/bin/javah: not found > REvaluator > /jdkl.3/bin/Javah: not found > RManualFunctionActionListener > /jdk1.3/bin/javah: not found > /jdkl.3/bin/javah: not found > adding build stamp to DESCRIPTION > running src/Makefile.win > (cd .. ; ./configure.win c:/PROGRW1/R/rw200l) > /configure.win: not found > make[3]: *** [conf ig] Error 127 > make[2]: *** [srcDynLib] Error 2 > make[1]: *** [all] Error 2 > make: *** [pkgSJava] Error 2 > *** Installation of SJava failed *** > > > > > --- > > > > > > [[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] [R-pkgs] tseriesChaos ver. 0.1
Dear all, I have uploaded to CRAN a new package: tseriesChaos. This is an early version (0.1) with basic tools for the explorative analysis of nonlinear time series motivated by chaos theory. Until now, the package is largely inspired by the TISEAN project (by Rainer Hegger, Holger Kantz and Thomas Schreiber: http://www.mpipks-dresden.mpg.de/~tisean/ ). This version includes: - Method of false nearest neighbours for the choice of the embedding dimension. - Tools for the estimation of the correlation dimension. - Kantz algorithm for the estimation of the largest Lyapunov exponent. - (naif) mutual information index estimation. - Space-time separation plot. - Recurrence plot. - Simulation of noise-free continuous dynamic systems. At the present time, algorithms are not too much optimized for speed, we are working on optimizing the codes. Future versions will (hopefully) include also code inspired from the book of Chan and Tong (2001) (Chaos: A Statistical perspective) by Springer as well as other contributions. Checking was mainly done by comparing results with those available in literature. Any kind of feedback/help would be greatly appreciated. Antonio, Fabio Di Narzo. ___ R-packages mailing list [EMAIL PROTECTED] https://stat.ethz.ch/mailman/listinfo/r-packages __ 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