[R] RE
Hi any, Can some please detail me the createX command in bayesm package? To make things easy for you to help me, let me put forward my problem Suppose I have 3 covariates (say X matrix) and my Y has 3 categories say (1,2,3). Now from the CreateX I understand that the data matrix say 'Xa' must be of dimension n* (naxp), where 'na' is the number of variables and 'p' is the number of categories that Y has and 'n' is the number of observations. Now the Xa matrix will have 9 columns if I give na=3 and p=3, and 6 columns if I give na =2 and p=3. I understand this part. In order to create Xa with a dimension of n*9 or n*6 we have to create Xa as cbind(Xa,-Xa) and now when I get the design matrix say XD then I have 5 or 4 variables, which will be same as the beta matrix that I intend to get, I get this, but my question is when I get the XD matrix as explained below the covariate matrix (X) which initially had 3 columns now changed to a 9 rows and one column and two additional variables X4 and X5 as explained belwo which I guess for the beta, what is the role of these variables in the 'rmnlIndepMetrop'analysis. example x1<-runif(3,-1,1) x2<-runif(3,0,1) x3<-runif(3,10,50) X<-cbind(x1,x2,x3) X x1x2 x3 [1,] -0.9701396 0.4084203 41.31097 [2,] 0.3844539 0.4791997 36.85861 [3,] 0.2732056 0.5433642 13.14610 Xa<-cbind(X,-X) XD<-createX(p=3,na=2,nd=NULL,Xa=Xa,Xd=NULL) XD [,1] [,2] [,3][,4] [1,]10 -0.9701396 0.9701396 [2,]01 0.4084203 -0.4084203 [3,]00 41.3109655 -41.3109655 [4,]10 0.3844539 -0.3844539 [5,]01 0.4791997 -0.4791997 [6,]00 36.8586070 -36.8586070 [7,]10 0.2732056 -0.2732056 [8,]01 0.5433642 -0.5433642 [9,]00 13.1461040 -13.1461040 Xa<-cbind(X,-X,X^2) (is this a correct way) XD<-createX(p=3,na=3,nd=NULL,Xa=Xa,Xd=NULL) XD [,1] [,2] [,3][,4] [,5] [1,]10 -0.9701396 0.97013960.9411709 [2,]01 0.4084203 -0.40842030.1668071 [3,]00 41.3109655 -41.3109655 1706.5958746 [4,]10 0.3844539 -0.38445390.1478048 [5,]01 0.4791997 -0.47919970.2296324 [6,]00 36.8586070 -36.8586070 1358.5569127 [7,]10 0.2732056 -0.27320560.0746413 [8,]01 0.5433642 -0.54336420.2952447 [9,]00 13.1461040 -13.1461040 172.8200512 In the above example my X matrix as you can see has 3 columns with 3 observations, which now in XD are 9 observations in 3rd column, I don't know how col 4 and col 5 of XD play a role in computing the llmnl and rmnlIndepMetrop. Thanks for all your help and time. Regards, Murthy. __ 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] plot() with TukeyHSD
On Tue, 1 Aug 2006, Owen, Jason wrote: > Hello, > > When plotting the results of a TukeyHSD multiple comparisons > procedure with an ANOVA (lm) object, an extra line appears > in the confidence intervals that contain 0. For example (this > is straight from the TukeyHSD helpfile): > > > summary(fm1 <- aov(breaks ~ wool + tension, data = warpbreaks)) > > TukeyHSD(fm1, "tension", ordered = TRUE) > > plot(TukeyHSD(fm1, "tension")) > > An extra line segment appears in the interval to the right of the > dotted zero line. Coincidentally, if all of the calculated > intervals for a dataset don't contain zero, this isn't a problem > -- so I guess the line segment "belongs" to the zero line. I > checked R Search and didn't find this mentioned before... but > please let me know if I overlooked something. You overlooked the following in the posting guide If you are using an old version of R and think it does not work properly, upgrade to the latest version and try that, before posting. The NEWS for 2.2.1 says o The plot() method for TukeyHSD() needed updating after adding adjusted p-values. (PR#8229) which is probably what you are referring to. > > Jason > > R 2.2.0 on Windows Far too old. > -- BTW, the error didn't happen on my Mac OSX w/ R 1.9.1 > > -- > Assistant Professor of Statistics > Mathematics and Computer Science Department > University of Richmond, Virginia 23173 > (804) 289-8081 fax:(804) 287-6664 > http://www.mathcs.richmond.edu/~wowen > > "This is R. There is no if. Only how." > Simon (Yoda) Blomberg > > __ > 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. > -- 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 __ 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] open DLL in R
On Wed, 2 Aug 2006, [EMAIL PROTECTED] wrote: > > Hello Sir, > > I am just wondering that pedump is a command of 'R' because in could not It is not, as I stated. > find in the 'R' help using help.search("pedump"). I am requesting you to > narrate as i also have to look into .dll(s). Is there any way to know what > are the exported functions and constants and imported functions and > constants in a easy way. Yes, see the R-admin manual, using non-R tools. > thanks > -gaurav. > > > > Prof Brian Ripley <[EMAIL PROTECTED]> > Sent by: [EMAIL PROTECTED] > 01-08-06 11:18 PM > > To > qian li <[EMAIL PROTECTED]> > cc > r-help@stat.math.ethz.ch > Subject > Re: [R] open DLL in R > > > > > > > On Tue, 1 Aug 2006, qian li wrote: > > > I have downloaded a DLL file. I want to look at the contents in the DLL > file. How can I do it in R? > > You need a disassembler such as VC++'s DUMPBIN, but looking at compiled > code you did not write is not an easy task. (Or objdump from the MinGW > toolset.) > > If only you want to know what entry points it exports, use pedump -e for > the pedump.exe in tools.zip (see the R-admin manual). > > What has this to do with R? > > > > > Thanks, > > > > QL > > > > > > - > > > > > >[[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. > > > > -- 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 __ 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] open DLL in R
This refers to the windows command pedump.exe found in the Rtools collection at: http://www.murdoch-sutherland.com/Rtools/ On 8/2/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Hello Sir, > > I am just wondering that pedump is a command of 'R' because in could not > find in the 'R' help using help.search("pedump"). I am requesting you to > narrate as i also have to look into .dll(s). Is there any way to know what > are the exported functions and constants and imported functions and > constants in a easy way. > > thanks > -gaurav. > > > > Prof Brian Ripley <[EMAIL PROTECTED]> > Sent by: [EMAIL PROTECTED] > 01-08-06 11:18 PM > > To > qian li <[EMAIL PROTECTED]> > cc > r-help@stat.math.ethz.ch > Subject > Re: [R] open DLL in R > > > > > > > On Tue, 1 Aug 2006, qian li wrote: > > > I have downloaded a DLL file. I want to look at the contents in the DLL > file. How can I do it in R? > > You need a disassembler such as VC++'s DUMPBIN, but looking at compiled > code you did not write is not an easy task. (Or objdump from the MinGW > toolset.) > > If only you want to know what entry points it exports, use pedump -e for > the pedump.exe in tools.zip (see the R-admin manual). > > What has this to do with R? > > > > > Thanks, > > > > QL > > > > > > - > > > > > >[[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. > > > > -- > 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 > > __ > 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. > > > > > DISCLAIMER AND CONFIDENTIALITY CAUTION:\ \ This message and ...{{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. > __ 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] open DLL in R
Hello Sir, I am just wondering that pedump is a command of 'R' because in could not find in the 'R' help using help.search("pedump"). I am requesting you to narrate as i also have to look into .dll(s). Is there any way to know what are the exported functions and constants and imported functions and constants in a easy way. thanks -gaurav. Prof Brian Ripley <[EMAIL PROTECTED]> Sent by: [EMAIL PROTECTED] 01-08-06 11:18 PM To qian li <[EMAIL PROTECTED]> cc r-help@stat.math.ethz.ch Subject Re: [R] open DLL in R On Tue, 1 Aug 2006, qian li wrote: > I have downloaded a DLL file. I want to look at the contents in the DLL file. How can I do it in R? You need a disassembler such as VC++'s DUMPBIN, but looking at compiled code you did not write is not an easy task. (Or objdump from the MinGW toolset.) If only you want to know what entry points it exports, use pedump -e for the pedump.exe in tools.zip (see the R-admin manual). What has this to do with R? > > Thanks, > > QL > > > - > > >[[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. > -- 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 __ 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. DISCLAIMER AND CONFIDENTIALITY CAUTION:\ \ This message and ...{{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.
Re: [R] zero values in LHS and RHS
zubin bellsouth.net> writes: > > Hello! > > I have a data set where i need to predict hotel stays in a 3 month > period by customer. I have stays for each customer in the 3 month > period and the previous 3 month period + other variables. these stays > contain an integer that ranges from 0 to 10. classic poisson distribution. > > my question is around zeros. usually we could take logs on the stays > and run an OLS model i think an enhancement would be to fit a poisson > GLM model. i am confused about handling of zeros. i will have zero > values on the RHS and potentially on the LHS. It seems like the poisson > GLM model can handle zeros on the LHS and RHS. i guess my question is > fitting a poisson GLM, are zeros allowed? If so, how is this estimated > with a log link function? > I am not sure about the structure of LHS and RHS matrices, but yes, Poisson model can handle zeroes. If it turns out that there are to many zeroes as expected, you might try ZIP model. Log link is the default for Poisson and it links the expected value of Poisson distribution and not the values itself. Gregor __ 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] Fitting models in a loop
Here is another attempt. This one allows general prediction yet its actually shorter and does not use any advanced language constructs (although to understand why it works one must understand that formulas have environments and the environment of the formula corresponding to each component of mod is the environment within the anonymous function instance that created it): # test data - as before set.seed(1) x <- 1:10 y <- x^3 + rnorm(10) mod <- lapply(1:3, function(i) lm(y ~ poly(x,i))) print(mod) # test - each component of mod remembers its 'i' # This returns 1, 2 and 3 as required. for (j in 1:3) print(environment(formula(mod[[j]]))$i) # following two lines give same answer # showing prediction works predict(mod[[2]], list(x = 1:10)) fitted(lm(y ~ poly(x,2))) On 8/1/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > Actually in thinking about this some more that still gets you > into a mess if you want to do prediction at anything other > than the original points. > > On 8/1/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > > A simple way around this is to pass it as a data frame. > > In the code below the only change we made was to change > > the formula from y ~ poly(x, i) to y ~ . and pass poly(x,i) > > in a data frame as argument 2 of lm: > > > > # test data > > set.seed(1) > > x <- 1:10 > > y <- x^3 + rnorm(10) > > > > # run same code except change the lm call > > mod <- list() > > for (i in 1:3) { > >mod[[i]] <- lm(y ~., data.frame(poly(x, i))) > >print(summary(mod[[i]])) > > } > > > > After running the above we can test that it works: > > > > > for(i in 1:3) print(formula(mod[[i]])) > > y ~ X1 > > y ~ X1 + X2 > > y ~ X1 + X2 + X3 > > > > On 8/1/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > > > > Markus Gesmann writes: > > > > > > > Murray, > > > > > > > > How about creating an empty list and filling it during your loop: > > > > > > > > mod <- list() > > > > for (i in 1:6) { > > > > mod[[i]] <- lm(y ~ poly(x,i)) > > > > print(summary(mod[[i]])) > > > > } > > > > > > > > All your models are than stored in one object and you can use lapply > > > to > > > > do something on them, like: > > > > lapply(mod, summary) or lapply(mod, coef) > > > > > > I think it is important to see why this deceptively simple > > > solution does not achieve the result that Murray wanted. > > > > > > Take any fitted model object, say mod[[4]]. For this object the > > > formula component of the call will be, literally, y ~ poly(x, i), > > > and not y ~ poly(x, 4), as would be required to use the object, > > > e.g. for prediction. In fact all objects have the same formula. > > > > > > You could, of course, re-create i and some things would be OK, > > > but getting pretty messy. > > > > > > You would still have a problem if you wanted to plot the fit with > > > termplot(), for example, as it would try to do a two-dimensional > > > plot of the component if both arguments to poly were variables. > > > > > > > > > > > -Original Message- > > > > From: [EMAIL PROTECTED] > > > > [mailto:[EMAIL PROTECTED] On Behalf Of > > > > [EMAIL PROTECTED] > > > > Sent: 01 August 2006 06:16 > > > > To: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch > > > > Subject: Re: [R] Fitting models in a loop > > > > > > > > > > > > Murray, > > > > > > > > Here is a general paradigm I tend to use for such problems. It > > > extends > > > > to fairly general model sequences, including different responses, &c > > > > > > > > First a couple of tiny, tricky but useful functions: > > > > > > > > subst <- function(Command, ...) do.call("substitute", list(Command, > > > > list(...))) > > > > > > > > abut <- function(...) ## jam things tightly together > > > > do.call("paste", c(lapply(list(...), as.character), sep = "")) > > > > > > > > Name <- function(...) as.name(do.call("abut", list(...))) > > > > > > > > Now the gist. > > > > > > > > fitCommand <- quote({ > > > > MODELi <- lm(y ~ poly(x, degree = i), theData) > > > > print(summary(MODELi)) > > > > }) > > > > for(i in 1:6) { > > > > thisCommand <- subst(fitCommand, MODELi = Name("model_", i), i > > > = > > > > i) > > > > print(thisCommand) ## only as a check > > > > eval(thisCommand) > > > > } > > > > > > > > At this point you should have the results and > > > > > > > > objects(pat = "^model_") > > > > > > > > should list the fitted model objects, all of which can be updated, > > > > summarised, plotted, &c, because the information on their construction > > > > is all embedded in the call. > > > > > > > > Bill. > > > > > > > > -Original Message- > > > > From: [EMAIL PROTECTED] > > > > [mailto:[EMAIL PROTECTED] On Behalf Of Murray > > > Jorgensen > > > > Sent: Tuesday, 1 August 2006 2:09 PM > > > > To: r-help@stat.math.ethz.ch > > > > Subject: [R] Fitting models in a loop > > > > > > > > If I want to display a few polynomial regression fits I can do > > > something > > > > > > > > like > > > >
Re: [R] Fitting models in a loop
This (below) also runs into trouble if you try to predict with new data since you have no rule for re-constructing the formula. Also, you can't plot the term as a single contributor to the linear predictor with termplot(). I'm sure given enough ingenuity you can get round these two, but why avoid the language manipulation solution, when it does the lot? Bill. -Original Message- From: Gabor Grothendieck [mailto:[EMAIL PROTECTED] Sent: Wednesday, 2 August 2006 12:01 PM To: Venables, Bill (CMIS, Cleveland) Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]; r-help@stat.math.ethz.ch Subject: Re: [R] Fitting models in a loop A simple way around this is to pass it as a data frame. In the code below the only change we made was to change the formula from y ~ poly(x, i) to y ~ . and pass poly(x,i) in a data frame as argument 2 of lm: # test data set.seed(1) x <- 1:10 y <- x^3 + rnorm(10) # run same code except change the lm call mod <- list() for (i in 1:3) { mod[[i]] <- lm(y ~., data.frame(poly(x, i))) print(summary(mod[[i]])) } After running the above we can test that it works: > for(i in 1:3) print(formula(mod[[i]])) y ~ X1 y ~ X1 + X2 y ~ X1 + X2 + X3 On 8/1/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Markus Gesmann writes: > > > Murray, > > > > How about creating an empty list and filling it during your loop: > > > > mod <- list() > > for (i in 1:6) { > > mod[[i]] <- lm(y ~ poly(x,i)) > > print(summary(mod[[i]])) > > } > > > > All your models are than stored in one object and you can use lapply > to > > do something on them, like: > > lapply(mod, summary) or lapply(mod, coef) > > I think it is important to see why this deceptively simple > solution does not achieve the result that Murray wanted. > > Take any fitted model object, say mod[[4]]. For this object the > formula component of the call will be, literally, y ~ poly(x, i), > and not y ~ poly(x, 4), as would be required to use the object, > e.g. for prediction. In fact all objects have the same formula. > > You could, of course, re-create i and some things would be OK, > but getting pretty messy. > > You would still have a problem if you wanted to plot the fit with > termplot(), for example, as it would try to do a two-dimensional > plot of the component if both arguments to poly were variables. > > > > > -Original Message- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On Behalf Of > > [EMAIL PROTECTED] > > Sent: 01 August 2006 06:16 > > To: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch > > Subject: Re: [R] Fitting models in a loop > > > > > > Murray, > > > > Here is a general paradigm I tend to use for such problems. It > extends > > to fairly general model sequences, including different responses, &c > > > > First a couple of tiny, tricky but useful functions: > > > > subst <- function(Command, ...) do.call("substitute", list(Command, > > list(...))) > > > > abut <- function(...) ## jam things tightly together > > do.call("paste", c(lapply(list(...), as.character), sep = "")) > > > > Name <- function(...) as.name(do.call("abut", list(...))) > > > > Now the gist. > > > > fitCommand <- quote({ > > MODELi <- lm(y ~ poly(x, degree = i), theData) > > print(summary(MODELi)) > > }) > > for(i in 1:6) { > > thisCommand <- subst(fitCommand, MODELi = Name("model_", i), i > = > > i) > > print(thisCommand) ## only as a check > > eval(thisCommand) > > } > > > > At this point you should have the results and > > > > objects(pat = "^model_") > > > > should list the fitted model objects, all of which can be updated, > > summarised, plotted, &c, because the information on their construction > > is all embedded in the call. > > > > Bill. > > > > -Original Message- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On Behalf Of Murray > Jorgensen > > Sent: Tuesday, 1 August 2006 2:09 PM > > To: r-help@stat.math.ethz.ch > > Subject: [R] Fitting models in a loop > > > > If I want to display a few polynomial regression fits I can do > something > > > > like > > > > for (i in 1:6) { > > mod <- lm(y ~ poly(x,i)) > > print(summary(mod)) > > } > > > > Suppose that I don't want to over-write the fitted model objects, > > though. How do I create a list of blank fitted model objects for later > > > use in a loop? > > > > Murray Jorgensen > > -- > > __ > 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] Data transformation
Here is how to do it with vectors; you can extend to a data frame: > x <- "NA18501 + NA18502 + NA18504 + NA18505 + NA18507 + NA18508 + NA18516 + NA18517 + NA18522 + NA18523 + " > x <- scan(textConnection(x), what='') Read 10 items > x [1] "NA18501" "NA18502" "NA18504" "NA18505" "NA18507" "NA18508" "NA18516" "NA18517" "NA18522" "NA18523" > newDF <- x[rep(seq(length(x)), each=2)] > newDF [1] "NA18501" "NA18501" "NA18502" "NA18502" "NA18504" "NA18504" "NA18505" "NA18505" "NA18507" "NA18507" [11] "NA18508" "NA18508" "NA18516" "NA18516" "NA18517" "NA18517" "NA18522" "NA18522" "NA18523" "NA18523" > On 8/1/06, jenny tan <[EMAIL PROTECTED]> wrote: > > Hi there, > > Wonder if someone who is R-savvy can help me with the following task (see > below) that I occasionally do work and gets quite tedious if I do it > manually. Thanks in advance! > > jenny. > > - > > I have a column of data that looks like this: > NA18501 > NA18502 > NA18504 > NA18505 > NA18507 > NA18508 > NA18516 > NA18517 > NA18522 > NA18523 > > And I want to duplicate the values and sort of "interweave" them to look > like this: > > NA18501 > NA18501 > NA18502 > NA18502 > NA18504 > NA18504 > NA18505 > NA18505 > NA18507 > NA18507 > NA18508 > NA18508 > NA18516 > NA18516 > NA18517 > NA18517 > NA18522 > NA18522 > NA18523 > NA18523 > > __ > 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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? [[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] zero values in LHS and RHS
Hello! I have a data set where i need to predict hotel stays in a 3 month period by customer. I have stays for each customer in the 3 month period and the previous 3 month period + other variables. these stays contain an integer that ranges from 0 to 10. classic poisson distribution. my question is around zeros. usually we could take logs on the stays and run an OLS model i think an enhancement would be to fit a poisson GLM model. i am confused about handling of zeros. i will have zero values on the RHS and potentially on the LHS. It seems like the poisson GLM model can handle zeros on the LHS and RHS. i guess my question is fitting a poisson GLM, are zeros allowed? If so, how is this estimated with a log link function? -zubin __ 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] Data transformation
If x is your data, and is a vector, then rep(x, each=2) should do it for you. Cheers, Simon. jenny tan wrote: > Hi there, > > Wonder if someone who is R-savvy can help me with the following task (see > below) that I occasionally do work and gets quite tedious if I do it > manually. Thanks in advance! > > jenny. > > - > > I have a column of data that looks like this: > NA18501 > NA18502 > NA18504 > NA18505 > NA18507 > NA18508 > NA18516 > NA18517 > NA18522 > NA18523 > > And I want to duplicate the values and sort of "interweave" them to look > like this: > > NA18501 > NA18501 > NA18502 > NA18502 > NA18504 > NA18504 > NA18505 > NA18505 > NA18507 > NA18507 > NA18508 > NA18508 > NA18516 > NA18516 > NA18517 > NA18517 > NA18522 > NA18522 > NA18523 > NA18523 > > __ > 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. > > -- Simon Blomberg, B.Sc.(Hons.), Ph.D, M.App.Stat. Centre for Resource and Environmental Studies The Australian National University Canberra ACT 0200 Australia T: +61 2 6125 7800 email: Simon.Blomberg_at_anu.edu.au F: +61 2 6125 0757 CRICOS Provider # 00120C __ 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] Data transformation
Hi there, Wonder if someone who is R-savvy can help me with the following task (see below) that I occasionally do work and gets quite tedious if I do it manually. Thanks in advance! jenny. - I have a column of data that looks like this: NA18501 NA18502 NA18504 NA18505 NA18507 NA18508 NA18516 NA18517 NA18522 NA18523 And I want to duplicate the values and sort of "interweave" them to look like this: NA18501 NA18501 NA18502 NA18502 NA18504 NA18504 NA18505 NA18505 NA18507 NA18507 NA18508 NA18508 NA18516 NA18516 NA18517 NA18517 NA18522 NA18522 NA18523 NA18523 __ 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] Fitting models in a loop
Actually in thinking about this some more that still gets you into a mess if you want to do prediction at anything other than the original points. On 8/1/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > A simple way around this is to pass it as a data frame. > In the code below the only change we made was to change > the formula from y ~ poly(x, i) to y ~ . and pass poly(x,i) > in a data frame as argument 2 of lm: > > # test data > set.seed(1) > x <- 1:10 > y <- x^3 + rnorm(10) > > # run same code except change the lm call > mod <- list() > for (i in 1:3) { >mod[[i]] <- lm(y ~., data.frame(poly(x, i))) >print(summary(mod[[i]])) > } > > After running the above we can test that it works: > > > for(i in 1:3) print(formula(mod[[i]])) > y ~ X1 > y ~ X1 + X2 > y ~ X1 + X2 + X3 > > On 8/1/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > > Markus Gesmann writes: > > > > > Murray, > > > > > > How about creating an empty list and filling it during your loop: > > > > > > mod <- list() > > > for (i in 1:6) { > > > mod[[i]] <- lm(y ~ poly(x,i)) > > > print(summary(mod[[i]])) > > > } > > > > > > All your models are than stored in one object and you can use lapply > > to > > > do something on them, like: > > > lapply(mod, summary) or lapply(mod, coef) > > > > I think it is important to see why this deceptively simple > > solution does not achieve the result that Murray wanted. > > > > Take any fitted model object, say mod[[4]]. For this object the > > formula component of the call will be, literally, y ~ poly(x, i), > > and not y ~ poly(x, 4), as would be required to use the object, > > e.g. for prediction. In fact all objects have the same formula. > > > > You could, of course, re-create i and some things would be OK, > > but getting pretty messy. > > > > You would still have a problem if you wanted to plot the fit with > > termplot(), for example, as it would try to do a two-dimensional > > plot of the component if both arguments to poly were variables. > > > > > > > > -Original Message- > > > From: [EMAIL PROTECTED] > > > [mailto:[EMAIL PROTECTED] On Behalf Of > > > [EMAIL PROTECTED] > > > Sent: 01 August 2006 06:16 > > > To: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch > > > Subject: Re: [R] Fitting models in a loop > > > > > > > > > Murray, > > > > > > Here is a general paradigm I tend to use for such problems. It > > extends > > > to fairly general model sequences, including different responses, &c > > > > > > First a couple of tiny, tricky but useful functions: > > > > > > subst <- function(Command, ...) do.call("substitute", list(Command, > > > list(...))) > > > > > > abut <- function(...) ## jam things tightly together > > > do.call("paste", c(lapply(list(...), as.character), sep = "")) > > > > > > Name <- function(...) as.name(do.call("abut", list(...))) > > > > > > Now the gist. > > > > > > fitCommand <- quote({ > > > MODELi <- lm(y ~ poly(x, degree = i), theData) > > > print(summary(MODELi)) > > > }) > > > for(i in 1:6) { > > > thisCommand <- subst(fitCommand, MODELi = Name("model_", i), i > > = > > > i) > > > print(thisCommand) ## only as a check > > > eval(thisCommand) > > > } > > > > > > At this point you should have the results and > > > > > > objects(pat = "^model_") > > > > > > should list the fitted model objects, all of which can be updated, > > > summarised, plotted, &c, because the information on their construction > > > is all embedded in the call. > > > > > > Bill. > > > > > > -Original Message- > > > From: [EMAIL PROTECTED] > > > [mailto:[EMAIL PROTECTED] On Behalf Of Murray > > Jorgensen > > > Sent: Tuesday, 1 August 2006 2:09 PM > > > To: r-help@stat.math.ethz.ch > > > Subject: [R] Fitting models in a loop > > > > > > If I want to display a few polynomial regression fits I can do > > something > > > > > > like > > > > > > for (i in 1:6) { > > > mod <- lm(y ~ poly(x,i)) > > > print(summary(mod)) > > > } > > > > > > Suppose that I don't want to over-write the fitted model objects, > > > though. How do I create a list of blank fitted model objects for later > > > > > use in a loop? > > > > > > Murray Jorgensen > > > -- > > > > __ > > 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] placing rectangle behind plot
Hi Gabor Grothendieck wrote: > Thanks. That's helpful. > > I would be interested in the case where > > 1. one does not have a variable latticeplot, as per your example, > but just has the output of > >xyplot(x ~ x | gl(2,1), layout = 1:2) > > sitting on the screen, having been "printed" by a prior > function. We can assume that no other graphics have been > issued since then. Can one still create a grey rectangle behind > the lower panel? xyplot(x ~ x | gl(2,1), layout = 1:2) latticeplot <- grid.grab() # Continue as for grid.grabExpr() example ... > 2. In fact, ideally what I would like is to create a function, > put.in.bg, say, that works something like this: > >xyplot(x ~ x | gl(2,1), layout = 1:2) >trellis.focus("panel", 1, 1) >put.in.bg(grid.rect(w = 0.5)) >trellis.unfocus() > > or maybe > >xyplot(x ~ x | gl(2,1), layout = 1:2) >trellis.focus.bg("panel", 1, 1) >grid.rect(w = 0.5) >trellis.unfocus() > > That allows one to add objects to a lattice panel behind the objects > that are already there. This would also be helpful for adding grid > lines afterwards or other lines, rectangles, etc. I could imagine something like ... xyplot(x ~ x | gl(2,1), layout = 1:2) put.in.bg("panel", 1, 1, rectGrob(w = 0.5)) ... where you just wrap the approach I described (using grid.grab() to capture the existing plot, then modifying the resulting grob), but such a function would obviously not work well when called after something other than just a trellis plot. Paul > On 7/30/06, Paul Murrell <[EMAIL PROTECTED]> wrote: >> Hi >> >> >> Gabor Grothendieck wrote: >>> I am trying to create a lattice plot and would like to later, i.e. after >>> the plot is drawn, add a grey rectangle behind a portion of it. >>> The following works except that the rectrangle is on top of and >>> obscures a portion of the chart. I also tried adding col = "transparent" >>> to the gpar list but that did not help -- I am on windows and >>> perhaps the windows device does not support transparency? >> >> Correct. >> >> >>> At any rate, how can I place the rectangle behind the plotted >>> points without drawing the rectangle first? >>> >>> library(lattice) >>> library(grid) >>> trellis.unfocus() >>> x <- 1:10 >>> xyplot(x ~ x | gl(2,1), layout = 1:2) >>> trellis.focus("panel", 1, 1) >>> grid.rect(w = .5, gp = gpar(fill = "light grey")) >>> trellis.unfocus() >> >> The user-interface is a little rough, but this can be done by accessing >> the underlying grid objects. Here's an example, with explanatory bits >> interspersed ... >> >> # "grab" the lattice plot as a grid gTree >> # There are warnings, but they are ignorable >> latticeplot <- grid.grabExpr(print(xyplot(x ~ x | gl(2,1), >> layout = 1:2))) >> >> # Demonstrate that the gTree faithfully replicates the >> # original lattice plot (not necessary, just to to what's going on) >> grid.newpage() >> grid.draw(latticeplot) >> >> # Explore the gTree (just to to show what's going on) >> # Better user-interface would be nice here ... >> childNames(latticeplot) >> # Identify which children are which >> # (appropriate grob names would be nice here) >> lapply(latticeplot$children, class) >> # Identify where each child is drawn >> latticeplot$childrenvp >> lapply(latticeplot$children, "[[", "vp") >> >> # Add a rect (starts off on top of everything else) >> # NOTE that rect has to have correct vpPath >> plotwithrect <- addGrob(latticeplot, >>rectGrob(w = .5, gp = gpar(fill = "light grey"), >> vp=vpPath("plot1.toplevel.vp", >> "plot1.panel.1.1.vp"))) >> >> # Check this draws what we expect (just to show what's going on) >> grid.newpage() >> grid.draw(plotwithrect) >> >> # Reorder children to put rect at back >> # Appropriate user-interface would be nice here ... >> nc <- length(plotwithrect$childrenOrder) >> plotwithrect$childrenOrder <- >>plotwithrect$childrenOrder[c(nc, 1:(nc - 1))] >> >> # Final result >> grid.newpage() >> grid.draw(plotwithrect) >> >> Paul >> -- >> Dr Paul Murrell >> Department of Statistics >> The University of Auckland >> Private Bag 92019 >> Auckland >> New Zealand >> 64 9 3737599 x85392 >> [EMAIL PROTECTED] >> http://www.stat.auckland.ac.nz/~paul/ >> >> -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 [EMAIL PROTECTED] http://www.stat.auckland.ac.nz/~paul/ __ 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] rgb and col2rgb color conversion/modification/shading
Hi Earl F. Glynn wrote: > <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> I want to get a lighter shade of a color...I have a lot of colored objects >> and >> want each one printed as a foreground against a slightly lighter >> background. >> >> I thought I could try something like changing the alpha channel by first >> converting it to rgb. > > I'm not sure what you want to do with the alpha channel - it's sometimes > used for transparency, especially on Macs, but is not used much on PCs > (AFAIK). > > > > Let's say you want different shades of gold: > >> colors()[142] > > [1] "gold" > > > > Instead of RGB color space perhaps you should consider HSV > (Hue-Saturation-Value) color space. Or, use a perceptually-based colour space like HCL (Hue Chroma Luminance); see the hcl() function and the 'colorspace' package for one way to convert from RGB. Paul > Let's convert "gold" to rgb to hsv: > > > >> col2rgb( colors()[142] ) > > [,1] > > red255 > > green 215 > > blue 0 > > > >> rgb2hsv( col2rgb( colors()[142] ) ) > >[,1] > > h 0.1405229 > > s 1.000 > > v 1.000 > > > > The "hue" (h) is the color ranging from 0 to 1 around a color circle (with > red= 0 or 1). Find h = 0.140 ("gold") in this color circle: > > > > hue <- seq(0.0, 1.0, by=1/40) > > > > pie(rep(1,40), > > labels=formatC(hue, digits=3, format="f"), cex=0.75, > > col=hsv(hue, 1.0, 1.0), > > radius=1.0, > > main="HSV (S=1, V=1)" ) > > > > > Hues range from 0.0 to 1.0. > > > > > A color is saturated (s=1) when it is "far" from a shade of gray (ranging > from black to white). Grays are unsaturated (no color) colors with s = 0. > Saturation ranges from 0.0 to 1.0. > > > > The value (v) is the brightness of the color. Low values appear quite dark > but still have color. v=1 is as bright as possible. Values range from 0.0 > to 1.0. > > > > You can get different "shades" of the same color by varying changing the > saturation and value for a given hue. The hsv function returns the RGB > color in hex form. > > > > Consider: > >> hsv(0.1405, 1, 1) > > [1] "#FFD700" > > > > Hex FF = decimal 255 = red > > Hex D7 = decimal 215 = green > > Hex 00 = decimal 0 = blue > > > > Let's vary Saturation from 0.0 to 1.0 and Value from 0.0 to 1.0 in this > plot: > > > > > > MakeHSVRectangle <- function(saturation, value) > > { > > GoldHue <- 0.140 > > color <- hsv(GoldHue, saturation, value) > > rect(100*saturation, 100*value, 100*saturation+4, 100*value+4, col=color) > > } > > > > > > plot(0:110,0:110, type="n", > > xlab="Saturation[%]", ylab="Value[%]", > > main="Shades of Gold, H=0.140") > > outer(seq(0.0, 1.0, 0.05), seq(0.0, 1.0, 0.05), MakeHSVRectangle) > > > > > > With Value = 0, all colors are "black". With Saturation=0, the only > "colors" along the y axis are the shades of gray. The original "gold" > rectangle is at the upper right. > > > > So, given a starting color, you have a number of "shades" (various > saturations and values) with the same color hue. > > > > I hope this helps. > > > > efg > > Earl F. Glynn > > Scientific Programmer > > Stowers Institute for Medical Research > > __ > 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. -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 [EMAIL PROTECTED] http://www.stat.auckland.ac.nz/~paul/ __ 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] boxplot
Hi Ana Patricia Martins wrote: > Hello R-users and developers, > > > > Once again, I'm asking for your help. > > I've used "identify" to identify points in a scatter plot. However, I can't > apple in the boxplot. > > > > I need to identify the outlier's id in the boxplot. Can anyone help me? The box for the i'th group is at x-location 'i' so ... boxplot(count ~ spray, data = InsectSprays, col = "lightgray") with(InsectSprays, identify(unclass(spray), count)) Paul -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 [EMAIL PROTECTED] http://www.stat.auckland.ac.nz/~paul/ __ 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] Fitting models in a loop
A simple way around this is to pass it as a data frame. In the code below the only change we made was to change the formula from y ~ poly(x, i) to y ~ . and pass poly(x,i) in a data frame as argument 2 of lm: # test data set.seed(1) x <- 1:10 y <- x^3 + rnorm(10) # run same code except change the lm call mod <- list() for (i in 1:3) { mod[[i]] <- lm(y ~., data.frame(poly(x, i))) print(summary(mod[[i]])) } After running the above we can test that it works: > for(i in 1:3) print(formula(mod[[i]])) y ~ X1 y ~ X1 + X2 y ~ X1 + X2 + X3 On 8/1/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Markus Gesmann writes: > > > Murray, > > > > How about creating an empty list and filling it during your loop: > > > > mod <- list() > > for (i in 1:6) { > > mod[[i]] <- lm(y ~ poly(x,i)) > > print(summary(mod[[i]])) > > } > > > > All your models are than stored in one object and you can use lapply > to > > do something on them, like: > > lapply(mod, summary) or lapply(mod, coef) > > I think it is important to see why this deceptively simple > solution does not achieve the result that Murray wanted. > > Take any fitted model object, say mod[[4]]. For this object the > formula component of the call will be, literally, y ~ poly(x, i), > and not y ~ poly(x, 4), as would be required to use the object, > e.g. for prediction. In fact all objects have the same formula. > > You could, of course, re-create i and some things would be OK, > but getting pretty messy. > > You would still have a problem if you wanted to plot the fit with > termplot(), for example, as it would try to do a two-dimensional > plot of the component if both arguments to poly were variables. > > > > > -Original Message- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On Behalf Of > > [EMAIL PROTECTED] > > Sent: 01 August 2006 06:16 > > To: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch > > Subject: Re: [R] Fitting models in a loop > > > > > > Murray, > > > > Here is a general paradigm I tend to use for such problems. It > extends > > to fairly general model sequences, including different responses, &c > > > > First a couple of tiny, tricky but useful functions: > > > > subst <- function(Command, ...) do.call("substitute", list(Command, > > list(...))) > > > > abut <- function(...) ## jam things tightly together > > do.call("paste", c(lapply(list(...), as.character), sep = "")) > > > > Name <- function(...) as.name(do.call("abut", list(...))) > > > > Now the gist. > > > > fitCommand <- quote({ > > MODELi <- lm(y ~ poly(x, degree = i), theData) > > print(summary(MODELi)) > > }) > > for(i in 1:6) { > > thisCommand <- subst(fitCommand, MODELi = Name("model_", i), i > = > > i) > > print(thisCommand) ## only as a check > > eval(thisCommand) > > } > > > > At this point you should have the results and > > > > objects(pat = "^model_") > > > > should list the fitted model objects, all of which can be updated, > > summarised, plotted, &c, because the information on their construction > > is all embedded in the call. > > > > Bill. > > > > -Original Message- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On Behalf Of Murray > Jorgensen > > Sent: Tuesday, 1 August 2006 2:09 PM > > To: r-help@stat.math.ethz.ch > > Subject: [R] Fitting models in a loop > > > > If I want to display a few polynomial regression fits I can do > something > > > > like > > > > for (i in 1:6) { > > mod <- lm(y ~ poly(x,i)) > > print(summary(mod)) > > } > > > > Suppose that I don't want to over-write the fitted model objects, > > though. How do I create a list of blank fitted model objects for later > > > use in a loop? > > > > Murray Jorgensen > > -- > > __ > 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] R crashes using pdf() windows() or postscript()
Hi The problem is with the font information that R loads into memory. R tries to load each unique font only once per session, but there was a bug (or two) which meant that each time you create a new PDF (or PostScript) device, R loaded another copy of the font information into memory. So in your example below, we end up trying to load 1 font structures, where each one is not tiny. Hence eventual slow-down, crashes and/or low-memory messages. A fix has been made to the development version of R, so you could try that out. Otherwise, I'm afraid I can only suggest that you produce the plots in multiple R sessions (has anyone ever tried to use package 'snow' with Sweave?) Paul Jan Wijffels wrote: > Dear HelpeRs, > I have a script where I save several thousands of graphics. These are > then used in Latex through Sweave. Unfortunately R crashes while making > these plots and Windows pops up some message that I run low on virtual > memory. I tried to save the plots using pdf(), windows() and > postscript() and also tried to run it with R CMD BATCH myscript.R. But > after a while R slows down and crashes eventually or stops computing. > I'm using windows XP with R 2.3.1. I included a script that shows the > problem if you let it run for a while. >> R.version > _ > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 2 > minor 3.1 > year 2006 > month 06 > day01 > svn rev38247 > language R > version.string Version 2.3.1 (2006-06-01) > > > draw.rectangle <- function( > label, > figurename="figure", > figurepath=getwd(), > box.gpar=gpar(fill=rgb(red=51, green=51, blue=204, maxColorValue = > 255), >col=rgb(red=128, green=128, blue=128, maxColorValue = > 255), >lwd=2), > text.gpar=gpar(col="white", fontface="bold", fontsize=14, cex=1, > fontfamily="sans"), > type="pdf") { >setwd(figurepath) >if(type == "win"){ > windows(width=1.4, height=0.5) >} >else if(type == "pdf"){ > pdf(file = paste(figurename, ".pdf", sep=''), width = 1.4, height > = 0.5, onefile = TRUE, family = "Helvetica", paper = "special") >} >else if(type == "ps"){ > postscript(file = paste(figurename, ".ps", sep=''), width = 1.4, > height = 0.5, onefile = TRUE, family = "Helvetica", paper = "special", > fonts = "sans") >} >boxheight <- unit(1, "npc") >boxwidth <- unit(1, "npc") >pushViewport(viewport(x=0.5, y=0.5, width = boxwidth, height = > boxheight)) > grid.roundRect(height=boxheight, width=boxwidth, r=unit(3, "mm"), > gp = box.gpar) > grid.text(label, just = "centre", gp = text.gpar) >popViewport() >if(type == "win"){ > tmp <- savePlot(filename = figurename, type = "pdf", device = > dev.cur(), restoreConsole = TRUE) >} >tmp <- dev.off() > } > require(RGraphics) > setwd("C:\\") > for(i in 1:1){ >draw.rectangle("blablabla", type="win") > } > > Anyone has suggestions on how to solve this? > > > Jan > > > > Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm > > > [[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. -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 [EMAIL PROTECTED] http://www.stat.auckland.ac.nz/~paul/ __ 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] Fitting models in a loop
Markus Gesmann writes: > Murray, > > How about creating an empty list and filling it during your loop: > > mod <- list() > for (i in 1:6) { > mod[[i]] <- lm(y ~ poly(x,i)) > print(summary(mod[[i]])) > } > > All your models are than stored in one object and you can use lapply to > do something on them, like: > lapply(mod, summary) or lapply(mod, coef) I think it is important to see why this deceptively simple solution does not achieve the result that Murray wanted. Take any fitted model object, say mod[[4]]. For this object the formula component of the call will be, literally, y ~ poly(x, i), and not y ~ poly(x, 4), as would be required to use the object, e.g. for prediction. In fact all objects have the same formula. You could, of course, re-create i and some things would be OK, but getting pretty messy. You would still have a problem if you wanted to plot the fit with termplot(), for example, as it would try to do a two-dimensional plot of the component if both arguments to poly were variables. > > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of > [EMAIL PROTECTED] > Sent: 01 August 2006 06:16 > To: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch > Subject: Re: [R] Fitting models in a loop > > > Murray, > > Here is a general paradigm I tend to use for such problems. It extends > to fairly general model sequences, including different responses, &c > > First a couple of tiny, tricky but useful functions: > > subst <- function(Command, ...) do.call("substitute", list(Command, > list(...))) > > abut <- function(...) ## jam things tightly together > do.call("paste", c(lapply(list(...), as.character), sep = "")) > > Name <- function(...) as.name(do.call("abut", list(...))) > > Now the gist. > > fitCommand <- quote({ > MODELi <- lm(y ~ poly(x, degree = i), theData) > print(summary(MODELi)) > }) > for(i in 1:6) { > thisCommand <- subst(fitCommand, MODELi = Name("model_", i), i = > i) > print(thisCommand) ## only as a check > eval(thisCommand) > } > > At this point you should have the results and > > objects(pat = "^model_") > > should list the fitted model objects, all of which can be updated, > summarised, plotted, &c, because the information on their construction > is all embedded in the call. > > Bill. > > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Murray Jorgensen > Sent: Tuesday, 1 August 2006 2:09 PM > To: r-help@stat.math.ethz.ch > Subject: [R] Fitting models in a loop > > If I want to display a few polynomial regression fits I can do something > > like > > for (i in 1:6) { > mod <- lm(y ~ poly(x,i)) > print(summary(mod)) > } > > Suppose that I don't want to over-write the fitted model objects, > though. How do I create a list of blank fitted model objects for later > use in a loop? > > Murray Jorgensen > -- __ 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 Reference Card and other help (especially useful for Newbies)
Hi all: Newbies (and others!) may find useful the R Reference Card made available by Tom Short and Rpad at http://www.rpad.org/Rpad/Rpad-refcard.pdf or through the "Contributed" link on CRAN (where some other reference cards are also linked). It categorizes and organizes a bunch of R's basic, most used functions so that they can be easily found. For example, paste() is under the "Strings" heading and expand.grid() is under "Data Creation." For newbies struggling to find the right R function as well as veterans who can't quite remember the function name, it's very handy. Also don't forget R's other Help facilties: help.search("keyword or phrase") to search the **installed** man pages RSiteSearch("keyword or phrase") to search the CRAN website via Jonathan Baron's search engine. This can also be done directly from CRAN by following the "search" link there. And, occasionally, find()/apropos() to search the ** attached** packages for functions using regexp's. Though R certainly can be intimidating, please **do** try these measures first before posting questions to the list. And please **do** read the other basic R reference materials. Better and faster answers can often be found this way. -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box __ 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 and provide commented, minimal, self-contained, reproducible code.
[R] plot() with TukeyHSD
Hello, When plotting the results of a TukeyHSD multiple comparisons procedure with an ANOVA (lm) object, an extra line appears in the confidence intervals that contain 0. For example (this is straight from the TukeyHSD helpfile): > summary(fm1 <- aov(breaks ~ wool + tension, data = warpbreaks)) > TukeyHSD(fm1, "tension", ordered = TRUE) > plot(TukeyHSD(fm1, "tension")) An extra line segment appears in the interval to the right of the dotted zero line. Coincidentally, if all of the calculated intervals for a dataset don't contain zero, this isn't a problem -- so I guess the line segment "belongs" to the zero line. I checked R Search and didn't find this mentioned before... but please let me know if I overlooked something. Jason R 2.2.0 on Windows -- BTW, the error didn't happen on my Mac OSX w/ R 1.9.1 -- Assistant Professor of Statistics Mathematics and Computer Science Department University of Richmond, Virginia 23173 (804) 289-8081 fax:(804) 287-6664 http://www.mathcs.richmond.edu/~wowen "This is R. There is no if. Only how." Simon (Yoda) Blomberg __ 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] rsurv in ipred
Hi, I'm trying to find information about rsurv "Simulating Survival data" in the IPred package, without luck this far. In the description of this function we are asked to consult Hothorn et al. (2003) for the details. This paper is not in the reference list. Should it be same authors (2004)? In that case I will try my library, in any other case could someone please give me some directions to where I can find the paper. Regards Fredrik Jansson __ 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] Replacing NA in fSeries
Hi folks! What's a good way to replace NAs with a prior value in a time series created with the fSeries package? Thanks, John [[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.
Re: [R] Indexing issue
Hi, Try this: bIm <-array(rep(TRUE,5),c(5,1,1)) bIm[,,1] #[1] TRUE TRUE TRUE TRUE TRUE bIm[,,1,drop=FALSE] , , 1 [,1] [1,] TRUE [2,] TRUE [3,] TRUE [4,] TRUE [5,] TRUE See ?'[' for details on drop drop: For matrices and arrays. If 'TRUE' the result is coerced to the lowest possible dimension >From: "Swidan, Firas" <[EMAIL PROTECTED]> >To: "r-help@stat.math.ethz.ch" >Subject: [R] Indexing issue >Date: Tue, 01 Aug 2006 15:57:01 -0400 > >Hi, > >R is having the following weird behavior and I am not sure if that is a >feature or a bug: > >I am working on the following "3D" array: > > > bIm >, , 1 > > [,1] >[1,] TRUE >[2,] TRUE >[3,] TRUE >[4,] TRUE >[5,] TRUE > > > class(bIm) >[1] "array" > > dim(bIm) >[1] 5 1 1 > >When I try to get the first 2D subarray, the whole thing folds into a >vector: > > > bIm[,,1] >[1] TRUE TRUE TRUE TRUE TRUE > >This causes a lot of trouble in the R code as one would have expected to >get >a 2D array but ends up with this "logical" vector. > >Is this the way it was meant to be? Does not this behavior bother anyone >else besides me? > >Thanks for the help, >Firas. > >__ >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] R an AIX
Did you look in config.log for more information about the error? It looks like you cannot even run your compiler. (This is not really an R question, and off-topic for R-help: see the posting guide.) On Tue, 1 Aug 2006, kamil Marcinkowski wrote: > Hello All, > > I am having trouble with installing the latest R on AIX 5.3, I can't > even configure. > > > checking how to get verbose linking output from /usr/vac/bin/ > > xlf_r... configure: WARNING: compilation failed > > > > checking for Fortran libraries of /usr/vac/bin/xlf_r... > > checking how to get verbose linking output from /usr/vac/bin/ > > xlc_r... -v > > checking for C libraries of /usr/vac/bin/xlc_r... -L/usr/vac/lib - > > lxlopt -L/usr/lib/threads -lpthreads > > checking for dummy main to link with Fortran libraries... none > > checking for Fortran name-mangling scheme... configure: error: > > cannot compile a simple Fortran program > > > Has anyone installed R-2.3.1 on AIX 5.3 using the native complier > (xlc_r)? > If so would you send which flags and options did you use? > > Thanks, > > Kamil > > Kamil Marcinkowski Westgrid System Administrator > [EMAIL PROTECTED] University of Alberta site > Tel.780 492-0354 Research Computing Support > Fax.780 492-1729 Academic ICT > Edmonton, Alberta, CANADAUniversity of Alberta > > > "This communication is intended for the use of the recipient to which > it is > addressed, and may contain confidential, personal, and/or privileged > information. Please contact us immediately if you are not the intended > recipient of this communication. If you are not the intended > recipient of > this communication, do not copy, distribute, or take action on it. Any > communication received in error, or subsequent reply, should be > deleted or > destroyed." > > > > > > [[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. > -- 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 __ 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] libRmath
On Wed, 2 Aug 2006, TAN Chong Hui wrote: > Hi > > I'm trying to use the standalone library libRmath. > According to the documentation, I need to builld it in > src/nmath/standalone > > But this directory does not exist in the R I installed. > > What's the problem here, anyone? Did you install a *source* version of R: you are reading documentation about the sources of R? > > Thanks! > > Rgds > Chong Hui > > [[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. > -- 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 __ 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] Indexing issue
On Tue, 1 Aug 2006, Swidan, Firas wrote: > Hi, > > R is having the following weird behavior and I am not sure if that is a > feature or a bug: It's a feature. And a very old FAQ (#7.5) > I am working on the following "3D" array: > >> bIm > , , 1 > > [,1] > [1,] TRUE > [2,] TRUE > [3,] TRUE > [4,] TRUE > [5,] TRUE > >> class(bIm) > [1] "array" >> dim(bIm) > [1] 5 1 1 > > When I try to get the first 2D subarray, the whole thing folds into a > vector: > >> bIm[,,1] > [1] TRUE TRUE TRUE TRUE TRUE > > This causes a lot of trouble in the R code as one would have expected to get > a 2D array but ends up with this "logical" vector. > > Is this the way it was meant to be? Does not this behavior bother anyone > else besides me? Yes, it is the way it was meant to be. It has bothered other people, but the alternatives are probably worse. -thomas __ 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] What's a labelled data.frame? And how do I work with it?
John Kane wrote: > --- John Kane <[EMAIL PROTECTED]> wrote: > >> I imported an SPSS file with its data labels using >> spss.get (Library(Hmisc). >> Class = data.frame >> >> I then updated some of the spss labels and added a >> label to the object itself. >> >> label (staff.allocation) <- "raw data from the spss >> file" >> >> I then save it as an R object. When I load the >> object >> for further work it comes in as Class = "labelled" >> "data.frame" >> >> >> Then I try this >> >> > - >> # Get the raw data that we have imported from SPSS. >> load("H:/R.objects/staff.allocation.Rdata") >> >> # Recode all 99's in the data base as NA except >> dates >> and Subject since subject >> # 99 is a valid ID number. >> >> # Drop dates and ids >> st1 <- staff.allocation[, -1:-4] >> >> st1[st1==99] <- NA >> >> #replace date and id forget the entry date >> st2 <-data.frame(staff.allocation$site, >> staff.allocation$subject, >> staff.allocation$date, st1) >> >> > - >> If I have applied a label to the data.frame I get an >> error >> Error in data.frame(staff.allocation$site, >> staff.allocation$subject, staff.allocation$date, : >> >> arguments imply differing number of rows: 1865, >> 114 >> >> I orgininally was getting an error about >> " staff.allocation$site is a labelled >> class and cannot be coerced into a data.frame" >> >> but I lost that one while trying to see what was >> happeing >> >> If I do not apply the label to staff.allocation then >> I >> get a Class = "data.frame and I have no problem >> creating the second data.frame. >> >> Can anyone suggest what I am missing or what is >> happening >> >> Thanks > > To follow up to my own post it appears that if I make > any changes in the imported labels I also get an error > message when I attempt to create that data.frame > The message is > Error in as.data.frame.default(x[[i]], optional = > TRUE) : cannot coerce class "labelled" into a > data.frame No, you can do things like library(Hmisc) label(mydata$x) <- 'my label' or use the upData function in Hmisc A labelled data frame just sets up so that subsetting with [ will keep labels for all the variables in the data frame. Frank > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Indexing issue
Hi, R is having the following weird behavior and I am not sure if that is a feature or a bug: I am working on the following "3D" array: > bIm , , 1 [,1] [1,] TRUE [2,] TRUE [3,] TRUE [4,] TRUE [5,] TRUE > class(bIm) [1] "array" > dim(bIm) [1] 5 1 1 When I try to get the first 2D subarray, the whole thing folds into a vector: > bIm[,,1] [1] TRUE TRUE TRUE TRUE TRUE This causes a lot of trouble in the R code as one would have expected to get a 2D array but ends up with this "logical" vector. Is this the way it was meant to be? Does not this behavior bother anyone else besides me? Thanks for the help, Firas. __ 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] Use R in Java
On Wed, 2006-08-02 at 03:44 +0800, TAN Chong Hui wrote: > Hi > > I'm trying to use R from Java. > There doesn't seem to be much documentation on this. > I installed JGR that has JRI and Rjava coming with it. > > According to the short description at www.rosuda.org/JRI/, > there's supposed to be an "examples" directory in JRI. > I don't seem to be able to find that. > > I tried to install JRI on its own (not with JGR) from rosuda. > But there seems to be some error with the zip-file. > > Help, anybody? I don't know how it'd work on Windows (though I suppose it should be similar) but on Linux, you basically need to * Put JRI.jar in your CLASSPATH * Put libjrio.so in your LD_LIBRARY_PATH (libR.so should also be in this PATH) * Set R_HOME to point to wherever you installed R Also if you only want to use R from Java (and don't need Java from R) then you should not need Rjava at all. The JRI source's should be sufficient. The CDK uses JRI to use R as a backend and you can take a look at the code that we use to interact with R. On example can be seen at http://svn.sourceforge.net/viewvc/cdk/trunk/cdk/src/org/openscience/cdk/qsar/model/R2/RModel.java?view=markup --- Rajarshi Guha <[EMAIL PROTECTED]> GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE --- Q: What's purple and commutes? A: An abelian grape. __ 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 an AIX
Hello All, I am having trouble with installing the latest R on AIX 5.3, I can't even configure. > checking how to get verbose linking output from /usr/vac/bin/ > xlf_r... configure: WARNING: compilation failed > > checking for Fortran libraries of /usr/vac/bin/xlf_r... > checking how to get verbose linking output from /usr/vac/bin/ > xlc_r... -v > checking for C libraries of /usr/vac/bin/xlc_r... -L/usr/vac/lib - > lxlopt -L/usr/lib/threads -lpthreads > checking for dummy main to link with Fortran libraries... none > checking for Fortran name-mangling scheme... configure: error: > cannot compile a simple Fortran program Has anyone installed R-2.3.1 on AIX 5.3 using the native complier (xlc_r)? If so would you send which flags and options did you use? Thanks, Kamil Kamil Marcinkowski Westgrid System Administrator [EMAIL PROTECTED] University of Alberta site Tel.780 492-0354 Research Computing Support Fax.780 492-1729 Academic ICT Edmonton, Alberta, CANADAUniversity of Alberta "This communication is intended for the use of the recipient to which it is addressed, and may contain confidential, personal, and/or privileged information. Please contact us immediately if you are not the intended recipient of this communication. If you are not the intended recipient of this communication, do not copy, distribute, or take action on it. Any communication received in error, or subsequent reply, should be deleted or destroyed." [[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.
Re: [R] What's a labelled data.frame? And how do I work with it?
--- John Kane <[EMAIL PROTECTED]> wrote: > I imported an SPSS file with its data labels using > spss.get (Library(Hmisc). > Class = data.frame > > I then updated some of the spss labels and added a > label to the object itself. > > label (staff.allocation) <- "raw data from the spss > file" > > I then save it as an R object. When I load the > object > for further work it comes in as Class = "labelled" > "data.frame" > > > Then I try this > > - > # Get the raw data that we have imported from SPSS. > load("H:/R.objects/staff.allocation.Rdata") > > # Recode all 99's in the data base as NA except > dates > and Subject since subject > # 99 is a valid ID number. > > # Drop dates and ids > st1 <- staff.allocation[, -1:-4] > > st1[st1==99] <- NA > > #replace date and id forget the entry date > st2 <-data.frame(staff.allocation$site, > staff.allocation$subject, > staff.allocation$date, st1) > > - > If I have applied a label to the data.frame I get an > error > Error in data.frame(staff.allocation$site, > staff.allocation$subject, staff.allocation$date, : > > arguments imply differing number of rows: 1865, > 114 > > I orgininally was getting an error about > " staff.allocation$site is a labelled > class and cannot be coerced into a data.frame" > > but I lost that one while trying to see what was > happeing > > If I do not apply the label to staff.allocation then > I > get a Class = "data.frame and I have no problem > creating the second data.frame. > > Can anyone suggest what I am missing or what is > happening > > Thanks To follow up to my own post it appears that if I make any changes in the imported labels I also get an error message when I attempt to create that data.frame The message is Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot coerce class "labelled" into a data.frame __ 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] Use R in Java
Hi I'm trying to use R from Java. There doesn't seem to be much documentation on this. I installed JGR that has JRI and Rjava coming with it. According to the short description at www.rosuda.org/JRI/, there's supposed to be an "examples" directory in JRI. I don't seem to be able to find that. I tried to install JRI on its own (not with JGR) from rosuda. But there seems to be some error with the zip-file. Help, anybody? Thanks. Rgds Chong Hui [[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] libRmath
Hi I'm trying to use the standalone library libRmath. According to the documentation, I need to builld it in src/nmath/standalone But this directory does not exist in the R I installed. What's the problem here, anyone? Thanks! Rgds Chong Hui [[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.
Re: [R] rgb and col2rgb color conversion/modification/shading
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >I want to get a lighter shade of a color...I have a lot of colored objects >and > want each one printed as a foreground against a slightly lighter > background. > > I thought I could try something like changing the alpha channel by first > converting it to rgb. I'm not sure what you want to do with the alpha channel - it's sometimes used for transparency, especially on Macs, but is not used much on PCs (AFAIK). Let's say you want different shades of gold: > colors()[142] [1] "gold" Instead of RGB color space perhaps you should consider HSV (Hue-Saturation-Value) color space. Let's convert "gold" to rgb to hsv: > col2rgb( colors()[142] ) [,1] red255 green 215 blue 0 > rgb2hsv( col2rgb( colors()[142] ) ) [,1] h 0.1405229 s 1.000 v 1.000 The "hue" (h) is the color ranging from 0 to 1 around a color circle (with red= 0 or 1). Find h = 0.140 ("gold") in this color circle: hue <- seq(0.0, 1.0, by=1/40) pie(rep(1,40), labels=formatC(hue, digits=3, format="f"), cex=0.75, col=hsv(hue, 1.0, 1.0), radius=1.0, main="HSV (S=1, V=1)" ) Hues range from 0.0 to 1.0. A color is saturated (s=1) when it is "far" from a shade of gray (ranging from black to white). Grays are unsaturated (no color) colors with s = 0. Saturation ranges from 0.0 to 1.0. The value (v) is the brightness of the color. Low values appear quite dark but still have color. v=1 is as bright as possible. Values range from 0.0 to 1.0. You can get different "shades" of the same color by varying changing the saturation and value for a given hue. The hsv function returns the RGB color in hex form. Consider: > hsv(0.1405, 1, 1) [1] "#FFD700" Hex FF = decimal 255 = red Hex D7 = decimal 215 = green Hex 00 = decimal 0 = blue Let's vary Saturation from 0.0 to 1.0 and Value from 0.0 to 1.0 in this plot: MakeHSVRectangle <- function(saturation, value) { GoldHue <- 0.140 color <- hsv(GoldHue, saturation, value) rect(100*saturation, 100*value, 100*saturation+4, 100*value+4, col=color) } plot(0:110,0:110, type="n", xlab="Saturation[%]", ylab="Value[%]", main="Shades of Gold, H=0.140") outer(seq(0.0, 1.0, 0.05), seq(0.0, 1.0, 0.05), MakeHSVRectangle) With Value = 0, all colors are "black". With Saturation=0, the only "colors" along the y axis are the shades of gray. The original "gold" rectangle is at the upper right. So, given a starting color, you have a number of "shades" (various saturations and values) with the same color hue. I hope this helps. efg Earl F. Glynn Scientific Programmer Stowers Institute for Medical Research __ 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] open DLL in R
On Tue, 1 Aug 2006, qian li wrote: > I have downloaded a DLL file. I want to look at the contents in the DLL file. > How can I do it in R? You need a disassembler such as VC++'s DUMPBIN, but looking at compiled code you did not write is not an easy task. (Or objdump from the MinGW toolset.) If only you want to know what entry points it exports, use pedump -e for the pedump.exe in tools.zip (see the R-admin manual). What has this to do with R? > > Thanks, > > QL > > > - > > > [[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. > -- 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 __ 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] questions regarding spline functions
Posting reply to the list as well: On Tuesday 01 August 2006 07:02, Myers, Brent wrote: > Dylan, > > We are working on the same problem. I'm shocked that I hadn't seen the > paper you posted and I am most grateful for that. I try to pay attention > to McBratney's work too! > Hi Brent, glad to hear from a fellow soil scientist. I originally found the McBratney paper in the book: Upscaling and Downscaling Methods for Environmental Research. > The originator of the area-preserving spline is DeBoor, in A Practical > Guide to Splines, Chapter 8. The DeBoor algorithm is available in the > Matlab Spline Toolkit, which he wrote. Too pricey for me however. I have > been unsuccessful implementing it thus far in S-Plus, the reference is > not very clear in the construction of the coefficient matrix. I can send > you my notes on that. I've paused on that for now, more below. Notice > that these are quadratic splines (due to the number of constraints) and > that they are not so 'flexible' in representing soils data. Interesting. I will lookup the original author, and see if I can make any sense of it. This is not critical, merely a bit of initial exploration on horizon depth function characterizations for large data sets. > There are several other functions available from a CERN library > available also in their Physics Analyst Workstation software (GPL). I > haven't tried them. Realize also that some of the various density > estimation algorithms in S/R are spline fits of this nature. I will have to read up on those... > I also considered the possibility of boundary data to define slope at > some of the knots, but only about 1/3 of my data have good horizon > descriptions. Linear stairstep with sloped lines across boundaries are > trivial, but are a marked improvement over mid-horizon data. I too have seen similar results. However, I cannot quite get the bs() function to use the "knots" that I have in mind: note that this may be an operator error... Does it make sense to use the horizon boundaries as knots? > I am sure you are thinking about this...one big problem with area > preserving splines is that they will not represent the true distribution > of the soil property within the horizon if there are peaks. You > undoubtedly realize that since the vector of pedogenesis is anisotropic, > and that splines cannot represent this anisotropy. This is a real > problem for me in that it is critical to identify the location of minima > and maxima within the soil profile, more important than the property > value in my case. Their location is grossly distorted by a spline fit to > a mid-horizon data point. The mid-point data is better. I am taking a > separate approach to solve that problem, and then fit the area > preserving spline with knots defined at these locations. We need a > general algorithm to handle this data It would be very useful for > the soil science community! Indeed. If you wouldn't mind, I would be interested in hearing how this progresses. While we are not in a position to develop such a technique, outside of something rather simple, we sure would be able to put it to use. A quick summary in code and with an attached image of the various methods I have tried thus far, with one simple, and one complicated clay depth profile: require(splines) #example of two pedons on one plot: z.1 <- c(0,2,18,24,68,160,170,192,200) z.2 <- c(0,3,14,26,70,108,145,170,226,240) x.1 <- mid(z.1) x.2 <- mid(z.2) #clay pct y.1 <- c(0,1,2,2,4,7,6,1) y.2 <- c(0,5,3,3,3,2,27,3,5) fm.1 <- lm(y.1 ~ bs(x.1, df=5) ) fm.2 <- lm(y.2 ~ bs(x.2, df=5) ) isfm.1 <- interpSpline(y.1 ~ x.1) isfm.2 <- interpSpline(y.2 ~ x.2) new_x.1 <- seq(range(x.1)[1], range(x.1)[2], len = 200) new_x.2 <- seq(range(x.2)[1], range(x.2)[2], len = 200) new_y.1 <- predict(fm.1, data.frame(x.1=new_x.1) ) new_y.2 <- predict(fm.2, data.frame(x.2=new_x.2) ) #interpSpline() method #note different predict() syntax ispline_y.1 <- predict(isfm.1, new_x.1) ispline_y.2 <- predict(isfm.2, new_x.2) par(mfrow=c(2,1)) #simple pedon example plot(y.1 ~ x.1, xlab="Depth", ylab="Percent Clay", type="b", pch=16, lwd=2, main="Simple Pedon") #spline examples lines(spline(y.1 ~ x.1), col="blue", lty=2) lines(new_x.1, new_y.1, col='red', lty=2) lines(ispline_y.1, col='green', lty=2) legend(8,6, legend=c('soil data', 'splines()', 'interpSpline()', 'bs()'), col=c('black', 'blue', 'red', 'green'), lty=c(1,1,1,1), lwd=c(2,1,1,1), cex=0.7) #complex pedon: plot(y.2 ~ x.2, xlab="Depth", ylab="Percent Clay", type="b", pch=16, lwd=2, main="Complex Pedon") #spline examples lines(spline(y.2 ~ x.2), col="blue", lty=2) lines(new_x.2, new_y.2, col='red', lty=2) lines(ispline_y.2, col='green', lty=2) legend(8.4,24, legend=c('soil data', 'splines()', 'interpSpline()', 'bs()'), col=c('black', 'blue', 'red', 'green'), lty=c(1,1,1,1), lwd=c(2,1,1,1), cex=0.7) Cheers, Dylan > Brent > > D. Brenton Myers > Graduate Fellow > University of Missouri > Soil Environmen
[R] What's a labelled data.frame? And how do I work with it?
I imported an SPSS file with its data labels using spss.get (Library(Hmisc). Class = data.frame I then updated some of the spss labels and added a label to the object itself. label (staff.allocation) <- "raw data from the spss file" I then save it as an R object. When I load the object for further work it comes in as Class = "labelled" "data.frame" Then I try this - # Get the raw data that we have imported from SPSS. load("H:/R.objects/staff.allocation.Rdata") # Recode all 99's in the data base as NA except dates and Subject since subject # 99 is a valid ID number. # Drop dates and ids st1 <- staff.allocation[, -1:-4] st1[st1==99] <- NA #replace date and id forget the entry date st2 <-data.frame(staff.allocation$site, staff.allocation$subject, staff.allocation$date, st1) - If I have applied a label to the data.frame I get an error Error in data.frame(staff.allocation$site, staff.allocation$subject, staff.allocation$date, : arguments imply differing number of rows: 1865, 114 I orgininally was getting an error about " staff.allocation$site is a labelled class and cannot be coerced into a data.frame" but I lost that one while trying to see what was happeing If I do not apply the label to staff.allocation then I get a Class = "data.frame and I have no problem creating the second data.frame. Can anyone suggest what I am missing or what is happening Thanks __ 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] open DLL in R
On 8/1/2006 1:01 PM, qian li wrote: > I have downloaded a DLL file. I want to look at the contents in the DLL file. > How can I do it in R? As far as I know R has no tools to do that other than readBin, which will just show you a bunch of meaningless bytes. If you're on Windows, the MinGW compiler used to build R and packages includes objdump and dlltool which can display DLL contents in a human readable format. Duncan Murdoch __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] natural spline function
Hello, I am having difficulty with the ns function. I am trying to use natural spline of a list of dates in order to create a time series analysis where date does not need to have a linear relationship with the outcome. Here is my code and the error message - I have tried changing the class of variable but doesn't seem to help. > library(splines) > date <- dataset$date > mode(date) [1] "numeric" > class(date) [1] "factor" > try1 <- ns(date,6) ## with date as factor Error in (1 - h) * qs[i] : non-numeric argument to binary operator > > date <- strptime(admissions$date,"%d%b%y") > mode(date) [1] "list" > class(date) [1] "POSIXt" "POSIXlt" > foo <- ns(date,6) ## with date as POSIXt Error in as.POSIXct.default(X[[2]], ...) : do not know how to convert 'X[[2]]' to class "POSIXlt" > try <- as.character(date) > mode(try) [1] "character" > class(try) [1] "character" > foo <- ns(try,6) Error in qsort(x, FALSE) : argument is not a numeric vector __ 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] open DLL in R
I have downloaded a DLL file. I want to look at the contents in the DLL file. How can I do it in R? Thanks, QL - [[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] boxplot
Hello R-users and developers, Once again, I'm asking for your help. I've used "identify" to identify points in a scatter plot. However, I can't apple in the boxplot. I need to identify the outlier's id in the boxplot. Can anyone help me? Thanks in advance, Ana Patricia Martins [[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.
Re: [R] Tcltk package
Hi Peter, Peter Dalgaard <[EMAIL PROTECTED]> wrote: >Did you build R yourself, and can you do library(tcltk) on R's command >line? Yes, I built R myself. I couldn't find a debian package for R 2.3.1. The latest available is 2.2.1. > library(tcltk) Error in firstlib(which.lib.loc, package) : Tcl/Tk support is not available on this system Error in library(tcltk) : .First.lib failed for 'tcltk' > > You may well be missing the -devel packages for tcl and tk. I didn't get any warnings when I used configure. Do I need to explicitly configure for tcl and tk? >And, BTW, which Linux distribution is this? "i686-pc-linux-gnu" is not >sufficient. Ubuntu 6.06. Thanks, Jack. Peter Dalgaard <[EMAIL PROTECTED]> wrote: John McHenry writes: > Hi WizaRds, > > I ran into trouble trying to install the "debug" package, which requires > TCL/TK support. It seems like the tcltk package is not installed on my system. > From: http://tolstoy.newcastle.edu.au/R/help/05/07/7993.html it seems that > the tcltk is bundled with the base R distribution. > > I'm running R under linux: > > > version >_ > platform i686-pc-linux-gnu > arch i686 > os linux-gnu > system i686, linux-gnu > status > major 2 > minor 3.1 > year 2006 > month 06 > day01 > svn rev38247 > language R > version.string Version 2.3.1 (2006-06-01) > > > tcl8.4 and tk8.4 are both installed. > > The messages I get when I try to install the debug package are: > > > install.packages("debug") > trying URL 'http://cran.us.r-project.org/src/contrib/debug_1.1.0.tar.gz' > Content type 'application/x-tar' length 26492 bytes > opened URL > == > downloaded 25Kb > > * Installing *source* package 'debug' ... > ** R > ** inst > ** save image > Loading required package: mvbutils > MVBUTILS: no "tasks" vector found in ROOT > Loading required package: tcltk > Error in firstlib(which.lib.loc, package) : > Tcl/Tk support is not available on this system > Error: package 'tcltk' could not be loaded > Execution halted > ERROR: execution of package source for 'debug' failed > ** Removing '/usr/local/lib/R/library/debug' > > The downloaded packages are in > /tmp/RtmpEocXcC/downloaded_packages > Warning message: > installation of package 'debug' had non-zero exit status in: > install.packages("debug") > > Where am I going wrong? Did you build R yourself, and can you do library(tcltk) on R's command line? You may well be missing the -devel packages for tcl and tk. And, BTW, which Linux distribution is this? "i686-pc-linux-gnu" is not sufficient. -- 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 - [[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.
Re: [R] deleting a directory
?unlink says that unlink() can remove directories (and has a 'recursive' argument). 'unlink' is in the "SEE ALSO" section in ?file.remove. -- Tony Plate Sundar Dorai-Raj wrote: > Hi, all, > > I'm looking a utility for removing a directory from within R. Currently, > I'm using: > > foo <- function(...) { >mydir <- tempdir() >dir.create(mydir, showWarnings = FALSE, recursive = TRUE) >on.exit(system(sprintf("rm -rf %s", mydir))) >## do some stuff in "mydir" >invisible() > } > > However, this is assumes "rm" is available. I know of ?dir.create, but > there is no opposite. And ?file.remove appears to work only on files and > not directories. > > Any advice? Or is my current approach the only solution? > > > R.version > _ > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 2 > minor 3.1 > year 2006 > month 06 > day01 > svn rev38247 > language R > version.string Version 2.3.1 (2006-06-01) > > > Thanks, > > --sundar > > __ > 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] boxplot
Hello R-users and developers, Once again, I'm asking for your help. I've used "identify" to identify points in a scatter plot. However, I can't apple in the boxplot. I need to identify the outlier's id in the boxplot. Can anyone help me? Thanks in advance, Ana Patricia Martins [[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.
Re: [R] deleting a directory
Please ignore. I forgot ?unlink had a recursive argument. Thanks. --sundar Sundar Dorai-Raj wrote: > Hi, all, > > I'm looking a utility for removing a directory from within R. Currently, > I'm using: > > foo <- function(...) { > mydir <- tempdir() > dir.create(mydir, showWarnings = FALSE, recursive = TRUE) > on.exit(system(sprintf("rm -rf %s", mydir))) > ## do some stuff in "mydir" > invisible() > } > > However, this is assumes "rm" is available. I know of ?dir.create, but > there is no opposite. And ?file.remove appears to work only on files and > not directories. > > Any advice? Or is my current approach the only solution? > > > R.version >_ > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 2 > minor 3.1 > year 2006 > month 06 > day01 > svn rev38247 > language R > version.string Version 2.3.1 (2006-06-01) > > > Thanks, > > --sundar > > __ 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] deleting a directory
Hi, all, I'm looking a utility for removing a directory from within R. Currently, I'm using: foo <- function(...) { mydir <- tempdir() dir.create(mydir, showWarnings = FALSE, recursive = TRUE) on.exit(system(sprintf("rm -rf %s", mydir))) ## do some stuff in "mydir" invisible() } However, this is assumes "rm" is available. I know of ?dir.create, but there is no opposite. And ?file.remove appears to work only on files and not directories. Any advice? Or is my current approach the only solution? > R.version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 3.1 year 2006 month 06 day01 svn rev38247 language R version.string Version 2.3.1 (2006-06-01) Thanks, --sundar __ 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] Tcltk package
John McHenry <[EMAIL PROTECTED]> writes: > Hi WizaRds, > > I ran into trouble trying to install the "debug" package, which requires > TCL/TK support. It seems like the tcltk package is not installed on my system. > From: http://tolstoy.newcastle.edu.au/R/help/05/07/7993.html it seems that > the tcltk is bundled with the base R distribution. > > I'm running R under linux: > > > version >_ > platform i686-pc-linux-gnu > arch i686 > os linux-gnu > system i686, linux-gnu > status > major 2 > minor 3.1 > year 2006 > month 06 > day01 > svn rev38247 > language R > version.string Version 2.3.1 (2006-06-01) > > > tcl8.4 and tk8.4 are both installed. > > The messages I get when I try to install the debug package are: > > > install.packages("debug") > trying URL 'http://cran.us.r-project.org/src/contrib/debug_1.1.0.tar.gz' > Content type 'application/x-tar' length 26492 bytes > opened URL > == > downloaded 25Kb > > * Installing *source* package 'debug' ... > ** R > ** inst > ** save image > Loading required package: mvbutils > MVBUTILS: no "tasks" vector found in ROOT > Loading required package: tcltk > Error in firstlib(which.lib.loc, package) : > Tcl/Tk support is not available on this system > Error: package 'tcltk' could not be loaded > Execution halted > ERROR: execution of package source for 'debug' failed > ** Removing '/usr/local/lib/R/library/debug' > > The downloaded packages are in > /tmp/RtmpEocXcC/downloaded_packages > Warning message: > installation of package 'debug' had non-zero exit status in: > install.packages("debug") > > Where am I going wrong? Did you build R yourself, and can you do library(tcltk) on R's command line? You may well be missing the -devel packages for tcl and tk. And, BTW, which Linux distribution is this? "i686-pc-linux-gnu" is not sufficient. -- 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] Tcltk package
Hi WizaRds, I ran into trouble trying to install the "debug" package, which requires TCL/TK support. It seems like the tcltk package is not installed on my system. From: http://tolstoy.newcastle.edu.au/R/help/05/07/7993.html it seems that the tcltk is bundled with the base R distribution. I'm running R under linux: > version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 2 minor 3.1 year 2006 month 06 day01 svn rev38247 language R version.string Version 2.3.1 (2006-06-01) tcl8.4 and tk8.4 are both installed. The messages I get when I try to install the debug package are: > install.packages("debug") trying URL 'http://cran.us.r-project.org/src/contrib/debug_1.1.0.tar.gz' Content type 'application/x-tar' length 26492 bytes opened URL == downloaded 25Kb * Installing *source* package 'debug' ... ** R ** inst ** save image Loading required package: mvbutils MVBUTILS: no "tasks" vector found in ROOT Loading required package: tcltk Error in firstlib(which.lib.loc, package) : Tcl/Tk support is not available on this system Error: package 'tcltk' could not be loaded Execution halted ERROR: execution of package source for 'debug' failed ** Removing '/usr/local/lib/R/library/debug' The downloaded packages are in /tmp/RtmpEocXcC/downloaded_packages Warning message: installation of package 'debug' had non-zero exit status in: install.packages("debug") Where am I going wrong? Thanks, Jack. - [[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.
Re: [R] help on fitting negative binomial distribution with MLE
This is a special case of MASS::fitdistr MASS::glm.nb and the first will be easiest for you. On Tue, 1 Aug 2006, zhijie zhang wrote: > Dear friends, > Anybody knows how to fit the negative binomial distribution with MLE > using R or other software? I can't find the solution, any suggestions or > help would be greatly appreciated. > > -- 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 __ 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] How to convert two-dimensional function to matrix?
JeeBee <[EMAIL PROTECTED]> writes: > On Tue, 01 Aug 2006 16:23:46 +0200, Lothar Schmid wrote: > > > I'd like to convert a two-dimensional function f(x,y) to a matrix m, > > so that m[x,y] = f [x,y]. How can I achieve this? > > Maybe this helps. > I create an empty matrix first, then apply f to the indices. > > f <- function(x, y) { 1000*x + y } > > ( m <- matrix( data = NA, nrow = 5, ncol = 4 ) ) > ( m <- f(row(m), col(m)) ) outer(1:5, 1:4, f) -- 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.
Re: [R] How to convert two-dimensional function to matrix?
On Tue, 01 Aug 2006 16:23:46 +0200, Lothar Schmid wrote: > I'd like to convert a two-dimensional function f(x,y) to a matrix m, > so that m[x,y] = f [x,y]. How can I achieve this? Maybe this helps. I create an empty matrix first, then apply f to the indices. f <- function(x, y) { 1000*x + y } ( m <- matrix( data = NA, nrow = 5, ncol = 4 ) ) ( m <- f(row(m), col(m)) ) JeeBee. __ 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] Extracting a row number from a matrix
On Tue, 2006-08-01 at 07:03 -0700, Kartik Pappu wrote: > Hi all, > > I have a matrix with each column containing a large number of integers > (0 and above). in each column beyond a certain row (say row 120 in > column 1, row 134 in column 2, 142 in column 3...) there are only > 0's. I want to find, for each column the row number of the last row > which contains a positive integer beyond which there are 10 or more > 0's. > > so in the following example (single column, but my real data has > multiple columns) how do I get the row number of the last row of x > beyond which there are 10 or more 0's (which in this case is row#100). > > x <- as.matrix(c(rep(seq(1:20),5),rep(0,20))) > > I am still new to R so I was wondering if anyone had a quick fix. > > Thanks > Kartik Not fully tested, but something like the following: x <- as.matrix(c(rep(seq(1:20),5),rep(0,20))) get.zeros <- function(x) { runs <- rle(x == 0) pos <- max(which(runs$values & runs$lengths >= 10)) sum(runs$lengths[1:(pos - 1)]) } > apply(x, 2, get.zeros) [1] 100 See ?rle for getting information about sequences of values in a vector. HTH, Marc Schwartz __ 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 on fitting negative binomial distribution with MLE
Dear friends, Anybody knows how to fit the negative binomial distribution with MLE using R or other software? I can't find the solution, any suggestions or help would be greatly appreciated. -- Kind Regards, Zhi Jie,Zhang [[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] How to convert two-dimensional function to matrix?
I'd like to convert a two-dimensional function f(x,y) to a matrix m, so that m[x,y] = f [x,y]. How can I achieve this? Thanks, Lothar __ 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] Extracting a row number from a matrix
> so in the following example (single column, but my real data has > multiple columns) how do I get the row number of the last row of x > beyond which there are 10 or more 0's (which in this case is row#100). > > x <- as.matrix(c(rep(seq(1:20),5),rep(0,20))) > max( which(x > 0) ) JeeBee. __ 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] Extracting a row number from a matrix
Hi all, I have a matrix with each column containing a large number of integers (0 and above). in each column beyond a certain row (say row 120 in column 1, row 134 in column 2, 142 in column 3...) there are only 0's. I want to find, for each column the row number of the last row which contains a positive integer beyond which there are 10 or more 0's. so in the following example (single column, but my real data has multiple columns) how do I get the row number of the last row of x beyond which there are 10 or more 0's (which in this case is row#100). x <- as.matrix(c(rep(seq(1:20),5),rep(0,20))) I am still new to R so I was wondering if anyone had a quick fix. Thanks Kartik __ 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] A problem with R CMD SHLIB
On 8/1/2006 9:06 AM, TAN Chong Hui wrote: > Hi, > > I followed the example in "Writing R Extensions" to create a shared > object in Windows, using the command > > R CMD SHLIB X.cc X_main.cc > > This was encountered: > > ../src/gnuwin32/MkRules:155: warning: overriding commands for target > '.c.d' > ../src/gnuwin32/MkRules:143: warning: ignoring old commands for target > '.c.d' > ../src/gnuwin32/MkRules:171: warning: overriding commands for target > '.c.d' > ../src/gnuwin32/MkRules:159: warning: ignoring old commands for target > '.c.d' > make: *** No rule to make target 'X_main.cc''. Stop. > > What might be the problem? > Please advise, anyone? I think you need to tell us more. Have you got a Makefile or Makevars in the same directory? If so, they are probably conflicting with the default ones. If X.cc and X_main.cc are self-contained, then you won't need Makevars or Makefile. R will use its own. Duncan Murdoch > > Rgds > Chong Hui > > [[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] Overlay Boxplot with scatter plot
This is very easy to do with ggplot: # you need to get the development version from http://had.co.nz/ggplot: install.packages("ggplot", dep=TRUE, repos="http://www.ggobi.org/r/";) library(ggplot) qplot(a, factor(b), type=c("boxplot","point")) qplot(factor(b), a, type=c("boxplot","point")) Regards, Hadley On 8/1/06, Lanre Okusanya <[EMAIL PROTECTED]> wrote: > my apologies about the initial bad sample code. Now assume I have > > a<-rnorm(6) > b<-rep(c(10,20),each=3) > ab<-data.frame(a,b) > > and I wanted to overlay this points on the graph? > > On 8/1/06, Petr Pikal <[EMAIL PROTECTED]> wrote: > > Hi > > > > your example code is not reproducible. > > > > On 1 Aug 2006 at 8:09, Lanre Okusanya wrote: > > > > Date sent: Tue, 1 Aug 2006 08:09:38 -0400 > > From: "Lanre Okusanya" <[EMAIL PROTECTED]> > > To: R-help@stat.math.ethz.ch > > Subject:[R] Overlay Boxplot with scatter plot > > > > > I am trying to make a box plot and overlay it with a scatter plot from > > > another data.frame. I was able to successfully create the boxplot, but > > > when i tried using points(x~y...) the dots did not show up. > > > > > > example code > > > > > > aa<-(300,300,300,300,600,600,600,600,900,900,900,900) > > ^^^ missing c > > > bb<-(13,12,14,11,56,44,34,75,22.,34,22,98,59,55,56) > > > cc<-(13,12,14,11,56,44,34,75,22.,34,22,98,59,55,56) > > > nn<-data.frame(aa,bb) > > different length of aa and bb > > > > > mm<-data.frame(aa,cc) > > > boxplot(bb~aa, data=nn) > > > lines(cc~aa, data=cc) > > > > > > Any help with example code is appreciated. > > > > x<-rnorm(20) > > y<-rep(c(10,20),each=10) > > bbb<-boxplot(x~as.factor(y)) > > > > although it seems as boxes are drawn at 10, 20 they are not. > > Actually the x position of each box is located at > > > > - from help page - > > at numeric vector giving the locations where the boxplots > > should be > > drawn, particularly when add = TRUE; defaults to 1:n where n is the > > number of boxes. > > > > as you can clearly demonstrate by issuing > > > > points(1,0, cex=10) > > > > HTH > > Petr > > > > > > > > Thank you. > > > > > > Lanre > > > > > > __ > > > 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. > > > > Petr Pikal > > [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.
Re: [R] Global setting for na.rm=TRUE
There is a global option setting for na.action. See ?na.action . That does not completely address your question but might help with lm, glm, etc. You could define your own wrapper functions if you know ahead of time which functions with na.rm= args you need. e.g. my.max = function(..., na.rm = getOption("na.rm")) max(..., na.rm = na.rm) getOption("na.rm") # NULL my.max(1, 2, NA) # 2 options(na.rm = FALSE) my.max(1,2,NA) # NA On 8/1/06, Gorjanc Gregor <[EMAIL PROTECTED]> wrote: > Hello! > > Is it possible to set na.rm=TRUE in a global way? I'am constantly > forgeting on this when performing analyses. I agree that one should > be carefull with this when developing some code, but not necesarilly > so in data analysis. > > Lep pozdrav / With regards, >Gregor Gorjanc > > -- > University of Ljubljana PhD student > Biotechnical FacultyURI: http://www.bfro.uni-lj.si/MR/ggorjan > Zootechnical Department mail: gregor.gorjanc bfro.uni-lj.si > Groblje 3 tel: +386 (0)1 72 17 861 > SI-1230 Domzale fax: +386 (0)1 72 17 888 > Slovenia, Europe > -- > "One must learn by doing the thing; for though you think you know it, > you have no certainty until you try." Sophocles ~ 450 B.C. > > __ > 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] A problem with R CMD SHLIB
Hi, I followed the example in "Writing R Extensions" to create a shared object in Windows, using the command R CMD SHLIB X.cc X_main.cc This was encountered: ../src/gnuwin32/MkRules:155: warning: overriding commands for target '.c.d' ../src/gnuwin32/MkRules:143: warning: ignoring old commands for target '.c.d' ../src/gnuwin32/MkRules:171: warning: overriding commands for target '.c.d' ../src/gnuwin32/MkRules:159: warning: ignoring old commands for target '.c.d' make: *** No rule to make target 'X_main.cc''. Stop. What might be the problem? Please advise, anyone? Rgds Chong Hui [[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.
Re: [R] Overlay Boxplot with scatter plot
boxplot does not use the actual values of aa as x-value, but considers aa as a factor having three levels. Try bxp <- boxplot(bb~aa, data=nn) bxp to see what the boxplot actually is. For your lines you should also use three levels. aa2<-c(1,1,1,1,2,2,2,2,3,3,3,3,3,3,3) points(cc~aa2) (after you have been correcting your example code...) Joris Lanre Okusanya wrote: > I am trying to make a box plot and overlay it with a scatter plot from > another data.frame. I was able to successfully create the boxplot, but > when i tried using points(x~y...) the dots did not show up. > > example code > > aa<-(300,300,300,300,600,600,600,600,900,900,900,900) > bb<-(13,12,14,11,56,44,34,75,22.,34,22,98,59,55,56) > cc<-(13,12,14,11,56,44,34,75,22.,34,22,98,59,55,56) > nn<-data.frame(aa,bb) > mm<-data.frame(aa,cc) > boxplot(bb~aa, data=nn) > lines(cc~aa, data=cc) > > Any help with example code is appreciated. > > Thank you. > > Lanre > > __ > 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. confidentiality notice: The information contained in this e-mail is confidential and...{{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.
Re: [R] Overlay Boxplot with scatter plot
my apologies about the initial bad sample code. Now assume I have a<-rnorm(6) b<-rep(c(10,20),each=3) ab<-data.frame(a,b) and I wanted to overlay this points on the graph? On 8/1/06, Petr Pikal <[EMAIL PROTECTED]> wrote: > Hi > > your example code is not reproducible. > > On 1 Aug 2006 at 8:09, Lanre Okusanya wrote: > > Date sent: Tue, 1 Aug 2006 08:09:38 -0400 > From: "Lanre Okusanya" <[EMAIL PROTECTED]> > To: R-help@stat.math.ethz.ch > Subject:[R] Overlay Boxplot with scatter plot > > > I am trying to make a box plot and overlay it with a scatter plot from > > another data.frame. I was able to successfully create the boxplot, but > > when i tried using points(x~y...) the dots did not show up. > > > > example code > > > > aa<-(300,300,300,300,600,600,600,600,900,900,900,900) > ^^^ missing c > > bb<-(13,12,14,11,56,44,34,75,22.,34,22,98,59,55,56) > > cc<-(13,12,14,11,56,44,34,75,22.,34,22,98,59,55,56) > > nn<-data.frame(aa,bb) > different length of aa and bb > > > mm<-data.frame(aa,cc) > > boxplot(bb~aa, data=nn) > > lines(cc~aa, data=cc) > > > > Any help with example code is appreciated. > > x<-rnorm(20) > y<-rep(c(10,20),each=10) > bbb<-boxplot(x~as.factor(y)) > > although it seems as boxes are drawn at 10, 20 they are not. > Actually the x position of each box is located at > > - from help page - > at numeric vector giving the locations where the boxplots should > be > drawn, particularly when add = TRUE; defaults to 1:n where n is the > number of boxes. > > as you can clearly demonstrate by issuing > > points(1,0, cex=10) > > HTH > Petr > > > > > Thank you. > > > > Lanre > > > > __ > > 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. > > Petr Pikal > [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.
Re: [R] Overlay Boxplot with scatter plot
Hi your example code is not reproducible. On 1 Aug 2006 at 8:09, Lanre Okusanya wrote: Date sent: Tue, 1 Aug 2006 08:09:38 -0400 From: "Lanre Okusanya" <[EMAIL PROTECTED]> To: R-help@stat.math.ethz.ch Subject:[R] Overlay Boxplot with scatter plot > I am trying to make a box plot and overlay it with a scatter plot from > another data.frame. I was able to successfully create the boxplot, but > when i tried using points(x~y...) the dots did not show up. > > example code > > aa<-(300,300,300,300,600,600,600,600,900,900,900,900) ^^^ missing c > bb<-(13,12,14,11,56,44,34,75,22.,34,22,98,59,55,56) > cc<-(13,12,14,11,56,44,34,75,22.,34,22,98,59,55,56) > nn<-data.frame(aa,bb) different length of aa and bb > mm<-data.frame(aa,cc) > boxplot(bb~aa, data=nn) > lines(cc~aa, data=cc) > > Any help with example code is appreciated. x<-rnorm(20) y<-rep(c(10,20),each=10) bbb<-boxplot(x~as.factor(y)) although it seems as boxes are drawn at 10, 20 they are not. Actually the x position of each box is located at - from help page - at numeric vector giving the locations where the boxplots should be drawn, particularly when add = TRUE; defaults to 1:n where n is the number of boxes. as you can clearly demonstrate by issuing points(1,0, cex=10) HTH Petr > > Thank you. > > Lanre > > __ > 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. Petr Pikal [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] Overlay Boxplot with scatter plot
I am trying to make a box plot and overlay it with a scatter plot from another data.frame. I was able to successfully create the boxplot, but when i tried using points(x~y...) the dots did not show up. example code aa<-(300,300,300,300,600,600,600,600,900,900,900,900) bb<-(13,12,14,11,56,44,34,75,22.,34,22,98,59,55,56) cc<-(13,12,14,11,56,44,34,75,22.,34,22,98,59,55,56) nn<-data.frame(aa,bb) mm<-data.frame(aa,cc) boxplot(bb~aa, data=nn) lines(cc~aa, data=cc) Any help with example code is appreciated. Thank you. Lanre __ 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] Algebraic operation on the missing values
Hi try to post some reproducible example and maybe somebody can help you more. You need to handle missing values one way or another. Either you can supply a value for it or you can get rid of them. If you used it in computation, the result will be NA. At least I think so. HTH Petr On 31 Jul 2006 at 14:37, Joanna Procelewska wrote: Date sent: Mon, 31 Jul 2006 14:37:33 +0200 (CEST) From: Joanna Procelewska <[EMAIL PROTECTED]> To: r-help@stat.math.ethz.ch Subject:Re: [R] Algebraic operation on the missing values > Thanks for the answer. > > The problem is I have to perform a forward selection on the set and in > every step construct an orthonormal base for the subspace spanned on > the selected vectors. This means that I can use only the "full" > vectors for the constructing a base, or? > > Joanna > > --- Petr Pikal <[EMAIL PROTECTED]> schrieb: > > > Hi > > > > see > > ?complete.cases and/or ?is.na for evaluating non missing entries. > > > > However in any operation in which you use NA value, result shall be > > NA as you do not know what actually is NA. > > > > HTH > > Petr > > > > > Hi all, > > > > > > I have a large set of descriptors, which are stored as the > > > vectors, each one containing about 450 elements. Now I have to > > > perform some algebraical operations on this set to eliminate the > > > redundant ones. The problem is, that not all vales in the vectors > > > are known. Are there any norm defined how should I process such > > > vectors? Simple example: having two vectors: > > > > > > a b > > > 3 4 > > > 2 null > > > 3 6 > > > > > > I can imagine that a+b is [7 null 9]', but what about scalar > > > product? Is it null or have it a value? I don't want to replace > > > missing values with the concrete ones, but they significantly > > > complicate my computations. > > > > > > Does anyone know whether there are any ways to solve this problem? > > > Please share some experience. Really appreciate the help! > > > > > > Sincerely, > > > > > > Joanna > > > > > > __ > > > 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. > > > > Petr Pikal > > [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. Petr Pikal [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.
Re: [R] na.rm problem
Like the error message tells you, cor does not have an argument "na.rm". use="complete" already does what you want, namely casewise deletion of missing values. However, this will not work with vectors of unequal length (how is R to determine which observations in x correspond to those in y?). What you could do is create a copy of y that has the same length as x but is "padded" with NAs (missing values) using something like: y.NA<-c(rep(NA, length(x) - length(y)), y) Then you can compute the correlation: cor(x, y.NA, use="complete") [EMAIL PROTECTED] wrote: > hi, > > i am a new member. > > i am using R in finding correlation between two variables of unequal length. > > when i use > > cor(x,y,na.rm=T,use="complete") > > where x has observations from 1928 to 2006 & y has observations from 1950 to > 2006. I used na.rm=T to use the "complete observations". So missing values > should be handled by casewise deletion. But it gives me error > > Error in cov(close, close1, na.rm = T, use = "complete") : > unused argument(s) (na.rm ...) > > > Please help me with this as I am new to R. > > Thanks, > Sonal > > __ > 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] read.spss 'error reading system-file header'
Question 2: Try saving the data as an SPSS portable file. I never had trouble reading these in R. Finn Sandø wrote: > When I try to import an spss sav file with read.spss() I am getting the > following error > 'Error in read.spss("X:\\.sav") : error reading system-file header' > and the import process is aborted. > I have tried in v. 2.3.0 and 2.3.1 > The sav-file loads without problems in spss v14 I have tried saving in > older spss v7 but are getting the same result. > The read.spss() has other errors (the 'Unrecognized record type 7, > subtype 7 encountered in system file') but it does not seem to have any > impact. > This leads me to thinking that the spss.read() slowly is growing out of > date which would be sad. > So question 1: > Does anyone know if these problems are going to be solved? I know the > read.spss() function is build on the PSPP project so maybe it takes > someone with c-knowledge to do something about it. > If someone is going to work on the problem I will be happy to help by > testing and providing problematic test-files. > Question 2 > Is there some way to import spss-sav files in this case other than save > in a non-spss format? > Regards > FS > > __ > 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] if function and apply
John Kane yahoo.ca> writes: > I have a dataset just imported from SPSS. It has any > number of 99's as missing data and it looks like the > next dataset will have custom missing codes. I have > abouat 120 variables and an N of 2000. > ... > > # define function > fn <- function (x a) { you need comma between x and a i.e. (x, a) ^ > if (x==a)return (b) else x > } How can you return b, if b was not defined before Gregor __ 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] Fitting models in a loop
"Gesmann, Markus" <[EMAIL PROTECTED]> writes: > Murray, > > How about creating an empty list and filling it during your loop: > > mod <- list() > for (i in 1:6) { > mod[[i]] <- lm(y ~ poly(x,i)) > print(summary(mod[[i]])) > } > > All your models are than stored in one object and you can use lapply to > do something on them, like: > lapply(mod, summary) or lapply(mod, coef) Ouch. Make that mod <- vector("list",6) Otherwise you'll be extending the vector on every pass through the loop. -- 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.
Re: [R] Fitting models in a loop
Murray, How about creating an empty list and filling it during your loop: mod <- list() for (i in 1:6) { mod[[i]] <- lm(y ~ poly(x,i)) print(summary(mod[[i]])) } All your models are than stored in one object and you can use lapply to do something on them, like: lapply(mod, summary) or lapply(mod, coef) Kind Regards Markus Gesmann FPMA Lloyd's Market Analysis Lloyd's * One Lime Street * London * EC3M 7HA Telephone +44 (0)20 7327 6472 Facsimile +44 (0)20 7327 5718 http://www.lloyds.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: 01 August 2006 06:16 To: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch Subject: Re: [R] Fitting models in a loop Murray, Here is a general paradigm I tend to use for such problems. It extends to fairly general model sequences, including different responses, &c First a couple of tiny, tricky but useful functions: subst <- function(Command, ...) do.call("substitute", list(Command, list(...))) abut <- function(...) ## jam things tightly together do.call("paste", c(lapply(list(...), as.character), sep = "")) Name <- function(...) as.name(do.call("abut", list(...))) Now the gist. fitCommand <- quote({ MODELi <- lm(y ~ poly(x, degree = i), theData) print(summary(MODELi)) }) for(i in 1:6) { thisCommand <- subst(fitCommand, MODELi = Name("model_", i), i = i) print(thisCommand) ## only as a check eval(thisCommand) } At this point you should have the results and objects(pat = "^model_") should list the fitted model objects, all of which can be updated, summarised, plotted, &c, because the information on their construction is all embedded in the call. Bill. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Murray Jorgensen Sent: Tuesday, 1 August 2006 2:09 PM To: r-help@stat.math.ethz.ch Subject: [R] Fitting models in a loop If I want to display a few polynomial regression fits I can do something like for (i in 1:6) { mod <- lm(y ~ poly(x,i)) print(summary(mod)) } Suppose that I don't want to over-write the fitted model objects, though. How do I create a list of blank fitted model objects for later use in a loop? Murray Jorgensen -- Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html Department of Statistics, University of Waikato, Hamilton, New Zealand Email: [EMAIL PROTECTED]Fax 7 838 4155 Phone +64 7 838 4773 wkHome +64 7 825 0441Mobile 021 1395 862 __ 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. ** The information in this E-Mail and in any attachments is CON...{{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.
[R] Global setting for na.rm=TRUE
Hello! Is it possible to set na.rm=TRUE in a global way? I'am constantly forgeting on this when performing analyses. I agree that one should be carefull with this when developing some code, but not necesarilly so in data analysis. Lep pozdrav / With regards, Gregor Gorjanc -- University of Ljubljana PhD student Biotechnical FacultyURI: http://www.bfro.uni-lj.si/MR/ggorjan Zootechnical Department mail: gregor.gorjanc bfro.uni-lj.si Groblje 3 tel: +386 (0)1 72 17 861 SI-1230 Domzale fax: +386 (0)1 72 17 888 Slovenia, Europe -- "One must learn by doing the thing; for though you think you know it, you have no certainty until you try." Sophocles ~ 450 B.C. __ 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] memory problems when combining randomForests
Dear Eleni, > > But if every time you remove a variable you pass some test data (ie data > not used to train the model) and base the performance of the new, reduced > model on the error rate on the confusion matrix for the test data, then > this "overfitting" should not be an issue, right? (unless of course you > were referring to unsupervised learning). > Yes and no. The problem there could arise if you do this iteratively and use the minimum value you obtain with your procedure to return an estimate of the error rate. In such a case, you should, instead, do a double cross-validation or bootstrap (i.e., estimate, via cross-validation ---or the bootstrap--- the error rate of your complete procedure). Both Andy and collaborators on the one hand and myself on the other have done some further work on these issues. Svetnik V, Liaw A, Tong C, Wang T: Application of Breiman's random forest to modeling structure-activity relationships of pharmaceutical molecules. Multiple Classier Systems, Fifth International Workshop, MCS 2004, Proceedings, 9–11 June 2004, Cagliari, Italy. Lecture Notes in Computer Science, Springer 2004, 3077:334-343. Gene selection and classification of microarray data using random forest Ramón Díaz-Uriarte and Sara Alvarez de Andrés. BMC Bioinformatics 2006, 7:3. http://www.biomedcentral.com/1471-2105/7/3 Best, R. On Monday 31 July 2006 18:45, Eleni Rapsomaniki wrote: > Hi Andy, > > > > I get different order of importance for my variables depending on their > > order in the training data. > > Perhaps answering my own question, the change in importance rankings could > be attributed to the fact that before passing my data to randomForest I > impute the missing values randomly (using the combined distributions of > pos+neg), so the data seen by RF is slightly different. Then combining this > with the fact that RF chooses data randomly it makes sense to see different > rankings. > > In a previous thread regarding simplifying variables: > http://thread.gmane.org/gmane.comp.lang.r.general/6989/focus=6993 > > you say: > "The basic problem is that when you select important variables by RF and > then re-run RF with those variables, the OOB error rate become biased > downward. As you iterate more times, the "overfitting" becomes more and > more severe (in the sense that, the OOB error rate will keep decreasing > while error rate on an independent test set will be flat or increases)" > > But if every time you remove a variable you pass some test data (ie data > not used to train the model) and base the performance of the new, reduced > model on the error rate on the confusion matrix for the test data, then > this "overfitting" should not be an issue, right? (unless of course you > were referring to unsupervised learning). > > Best regards > Eleni Rapsomaniki > Birkbeck College, UK > > __ > 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. -- Ramón Díaz-Uriarte Bioinformatics Centro Nacional de Investigaciones Oncológicas (CNIO) (Spanish National Cancer Center) Melchor Fernández Almagro, 3 28029 Madrid (Spain) Fax: +-34-91-224-6972 Phone: +-34-91-224-6900 http://ligarto.org/rdiaz PGP KeyID: 0xE89B3462 (http://ligarto.org/rdiaz/0xE89B3462.asc) **NOTA DE CONFIDENCIALIDAD** Este correo electr�nico, y en s...{{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.
Re: [R] Fw: na.rm problem
[EMAIL PROTECTED] wrote: > hi, > > i am a new member. > > i am using R in finding correlation between two variables of unequal length. > > when i use > > cor(x,y,na.rm=T,use="complete") > > where x has observations from 1928 to 2006 & y has observations from 1950 to > 2006. I used na.rm=T to use the "complete observations". So missing values > should be handled by casewise deletion. But it gives me error > > Error in cor(close, close1, na.rm = T, use = "complete") : > unused argument(s) (na.rm ...) > > Please help me with this as I am new to R. See ?cor. It does not have an na.rm argument. Just use: cor(x, y, use = "complete") Uwe Ligges > Thanks, > Sonal > > __ > 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] resampling mean distances
Jose Andres wrote: > Hi all, > > I am trying to generate a distribution for the mean euclidean > distance between a group of n elements in a given surface (the > elements are randomly picked). Fo doing so I've written the > following code: > > sampling<- function(x,size) { > > x<- x[sample(1:nrow(x),size),] > > mat<- matrix(c(x$V6,x$V7,x$V8), ncol=3) > > mean.dist<- mean(dist(mat,"euclidean")) # insert some return value such as: return(mean.dist) > } Now replicate() the stuff, e.g.: replicate(1, sampling(x, 10)) Uwe Ligges > x is the file where the data are stored > size is the size of the group > mat generates a simple matrix. V6, V7, and V8 are the 3D (x,y,z) > coordinates of the group elements . > mean.dist calculates the mean pairwise distance between the objects > of the group. > > Everything works fine but I want to repeat this many times (e.g. > 1) and store the mean.dist values in a new variable so I can > generate the distribution of mean pairwise distances of a group of > size n in my surface. > > Is there any easy way to do this? I'd really appreciate all your > comments. > > Thanks in advance, > > /Jose > > > > > > > > > > > On Jul 31, 2006, at 15:35, Prof Brian Ripley wrote: > >> On Mon, 31 Jul 2006, Sundar Dorai-Raj wrote: >> >>> >>> LL wrote: Hi.. I am running R version 2.3.1 on a Windows XP machine with the latest Miktex 2.5 installed. I get no errors from R when running the Sweave example, testfile <- system.file("Sweave", "Sweave-test-1.Rnw", package = "utils") However, when I tex the resulting .tex file (after installing a4.sty) I get the error below. This is pdfeTeX, Version 3.141592-1.30.6-2.2 (MiKTeX 2.5 RC 1) entering extended mode (Sweave-test-1.tex LaTeX2e <2005/12/01> Babel and hyphenation patterns for english, dumylang, nohyphenation, ge rman, ngerman, french, loaded. ("C:\Program Files\MiKTeX 2.5\tex\latex\base\article.cls" Document Class: article 2005/09/16 v1.4f Standard LaTeX document class ("C:\Program Files\MiKTeX 2.5\tex\latex\base\size10.clo")) ("C:\Program Files\MiKTeX 2.5\tex\latex\ltxmisc\a4wide.sty" ("C:\Program Files\MiKTeX 2.5\tex\latex\ntgclass\a4.sty")) ! Missing \endcsname inserted. \protect l.11 \begin {document} ? [[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. >>> >>> This works for me. However, when I ran this, MiKTeX prompted me to >>> install the ntgclass package, which I did. Everything ran smoothly >>> after >>> that. I'm using R-2.3.1 with MiKTeX 2.4 in WinXP Pro. >> But he is using MiKTeX 2.5: looks like a problem with MiKTeX, as >> the latex >> error is in the initial processing. >> >> -- >> 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 >> >> __ >> 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] rgb and col2rgb color conversion/modification/shading
[EMAIL PROTECTED] wrote: > I want to get a lighter shade of a color...I have a lot of colored objects and > want each one printed as a foreground against a slightly lighter background. > > I thought I could try something like changing the alpha channel by first > converting it to rgb. > > But prior to trying that, I'm stuck with how to get the color after converting > using col2rgb() to be interpreted again as a color, rather than a simple > vector? > > Anyone have any help/ or alternative suggestion... > > Thanks, -c > -- > TRYING WITH A SINGLE COLOR: > > mycol<-"red" > >> col2rgb(mycol) > [,1] > red255 > green0 > blue 0 > >> rgb(col2rgb(mycol),maxColorValue=255) rgb() required separate arguments for red green and blue. Hence saying mycol2 <- col2rgb(mycol) rgb(mycol2[1,], mycol2[2,], mycol2[3,], maxColorValue=255) does not look like beautiful code, but is probably easier than the other "cool" tricks. Uwe Ligges > Error in rgb(col2rgb("red")) : argument "green" is missing, with no default > > __ > 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 crashes using pdf() windows() or postscript()
Dear HelpeRs, I have a script where I save several thousands of graphics. These are then used in Latex through Sweave. Unfortunately R crashes while making these plots and Windows pops up some message that I run low on virtual memory. I tried to save the plots using pdf(), windows() and postscript() and also tried to run it with R CMD BATCH myscript.R. But after a while R slows down and crashes eventually or stops computing. I'm using windows XP with R 2.3.1. I included a script that shows the problem if you let it run for a while. > R.version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 3.1 year 2006 month 06 day01 svn rev38247 language R version.string Version 2.3.1 (2006-06-01) draw.rectangle <- function( label, figurename="figure", figurepath=getwd(), box.gpar=gpar(fill=rgb(red=51, green=51, blue=204, maxColorValue = 255), col=rgb(red=128, green=128, blue=128, maxColorValue = 255), lwd=2), text.gpar=gpar(col="white", fontface="bold", fontsize=14, cex=1, fontfamily="sans"), type="pdf") { setwd(figurepath) if(type == "win"){ windows(width=1.4, height=0.5) } else if(type == "pdf"){ pdf(file = paste(figurename, ".pdf", sep=''), width = 1.4, height = 0.5, onefile = TRUE, family = "Helvetica", paper = "special") } else if(type == "ps"){ postscript(file = paste(figurename, ".ps", sep=''), width = 1.4, height = 0.5, onefile = TRUE, family = "Helvetica", paper = "special", fonts = "sans") } boxheight <- unit(1, "npc") boxwidth <- unit(1, "npc") pushViewport(viewport(x=0.5, y=0.5, width = boxwidth, height = boxheight)) grid.roundRect(height=boxheight, width=boxwidth, r=unit(3, "mm"), gp = box.gpar) grid.text(label, just = "centre", gp = text.gpar) popViewport() if(type == "win"){ tmp <- savePlot(filename = figurename, type = "pdf", device = dev.cur(), restoreConsole = TRUE) } tmp <- dev.off() } require(RGraphics) setwd("C:\\") for(i in 1:1){ draw.rectangle("blablabla", type="win") } Anyone has suggestions on how to solve this? Jan Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm [[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.
Re: [R] question about dataframe ("sensory") in PLS package
Hello, I do this in such way: DATAX <- matrix(seq(1,6,1),2,3) DATAY <- matrix (seq(1,4,1),2,2) rownames(DATAX) <- c("s1","s2") rownames(DATAY) <- c("s1","s2") colnames (DATAX) <- c("v1","v2","v3") colnames (DATAY) <- c("respone_1","response_2") KAL <- data.frame (N = rownames(DATAX)) KAL$Y <- DATAY KAL$X <- DATAX KAL$X KAL$Y DATAX is a matrix of testing data, but DATAY is a matrix of responses. Andris Jankevics On Pirmdiena, 31. Jūlijs 2006 05:45, [EMAIL PROTECTED] wrote: > Dear all, > > I am trying to my dataframe for the PLS analysis using the PLS package. > However I have some trouble generating the correct dataframe. The main > problem is how to use one name to represent several columns in the > dataframe. > > The example dataframe in PLS package is called "sensory". I cannot > directly read the data file since it's a binary file. If I use > "names(sensory)" command, I will get two names: "Quality" and "Panel". But > if I use "summary(sensory)" command, I will get information of five > columns for "Quality" and 6 columns for "Panel" (such as "Quality.Acidity" > "Quality.Peroxide"...). So when I use PLS regression, the function is > simply "Panel ~ Quality" (but it's actually multiple regression). > > Does anyone know how to build such dataframe? Please share some > experience. Really appreciate the help! > > Sincerely, > Jeny > > __ > 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.