Re: [R] comparing two regression models with different dependent variable
We need to define what it means for these models to be the same or different. With the usual lm assumptions suppose for i=1, 2 (the two models) that: y1 = a1 + X b1 + error1 y2 = a2 + X b2 + error2 which implies the following which also satisfies the usual lm assumptions: y1-y2 = (a1-a2) + X(b1-b2) + error Here X is a matrix, a1 and a2 are scalars and all other elements are vectors. We say the models are the "same" if b1=b2 (but allow the intercepts to differ even if the models are the "same"). If y1 and y2 are as in the built in anscombe data frame and x3 and x4 are the x variables, i.e. columns of X, then: > fm1 <- lm(y1 - y2 ~ x3 + x4, anscombe) > # this model reduces to the following if b1 = b2 > fm0 <- lm(y1 - y2 ~ 1, anscombe) > anova(fm0, fm1) Analysis of Variance Table Model 1: y1 - y2 ~ 1 Model 2: y1 - y2 ~ x3 + x4 Res.DfRSS Df Sum of Sq F Pr(>F) 1 10 20.637 2 8 18.662 21.9751 0.4233 0.6687 so we cannot reject the hypothesis that the models are the "same". On Wed, Jun 9, 2010 at 11:19 AM, Or Duek wrote: > Hi, > I would like to compare to regression models - each model has a different > dependent variable. > The first model uses a number that represents the learning curve for reward. > The second model uses a number that represents the learning curve from > punishment stimuli. > The first model is significant and the second isn't. > I want to compare those two models and show that they are significantly > different. > How can I do that? > Thank you. > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] importing multidimensional matrix from MATLAB
Hi, Suppose I have a matrix of size 256x14x32 in MATLAB. I want to import that into R. I used readMat and then do.call. But the variable is stored as an array as its done in R. However, I want to define a variable W=array(0,c(256,14,32)) in R and read the multidimensional matlab variable into W. I am not able to do this in R. Please, could you help ? Thanks Gopi [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R: Collaborative Filtering
Is Collaborative Filtering available in R? It seems I could not find any R package implementing Collaborative Filtering? Thanks! -- View this message in context: http://r.789695.n4.nabble.com/R-Collaborative-Filtering-tp2249934p2249934.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] To give column names of a data-frame
Sir, I want to export the results of R in a data frame. So I want to give rownames,columnnames & title to the data-frame.I have applied the following: data.frame(matrix(c(...),nrow=,ncol=),row.names=c("a","b"),col.names=c("c","d"),title="aaa") But, it does not work. Can you help me? Regards, Suman Dhara [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Retrieving the 2 row of "dist" computations
Hey, The code definitely works, but I may need a more elegant way to do it. Rather than 5 rows, the full data contains 829 rows, so instead of d of length 10, d will be of length 343206. Jorge Ivan Velez wrote: > > Hi there, > > I am sure there is a better way to do it, but here is a suggestion: > > res <- matrix(NA, ncol = 2, nrow = 5) > for(i in 1:5) res[i, ] <- which(as.matrix(d) == sort(d)[i], arr.ind = > TRUE)[1,] > res > > HTH, > Jorge > > > On Wed, Jun 9, 2010 at 11:30 PM, Jeff08 <> wrote: > >> >> Dear R Gurus, >> >> As you probably know, dist calculates the distance between every two rows >> of >> data. What I am interested in is the actual two rows that have the least >> distance between them, rather than the numerical value of the distance >> itself. >> >> For example, If the minimum distance in the following sample run is >> d[14], >> which is .3826119, and the rows are 4 & 6. I need to find a generic way >> to >> retrieve these rows, for a generic matrix of NRows (in this example >> NRows=7) >> >> NCols=5 >> NRows=7 >> myMat<-matrix(runif(NCols*NRows), ncol=NCols) >> >> d<-dist(myMat) >> >> 1 2 3 4 5 6 >> 2 0.7202138 >> 3 0.7866527 0.9052319 >> 4 0.6105235 1.0754259 0.8897555 >> 5 0.5032729 1.0789359 0.9756421 0.4167131 >> 6 0.6007685 0.6949224 0.3826119 0.7590029 0.7994574 >> 7 0.9751200 1.2218754 1.0547197 0.5681905 0.7795579 0.8291303 >> >> e<-sort.list(d) >> e<-e[1:5] ##Retrieve minimum 5 distances >> >> [1] 14 16 4 18 5 >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/Retrieving-the-2-row-of-dist-computations-tp2249844p2249844.html >> Sent from the R help mailing list archive at Nabble.com. >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > -- View this message in context: http://r.789695.n4.nabble.com/Retrieving-the-2-row-of-dist-computations-tp2249844p2249900.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] error message in fitting tcopula
Hi r-users, I really need help in fitting the t-copula. I try to reproduce the example given by Jun Yan in "Enjoy the joy of copula" but I'm not sure how to correct the error based on the error message. I tried so many ways but still could not get it working. loglik.marg <- function(b, x) sum(dgamma(x, shape = b[1], scale = b[2], log = TRUE)) ctrl <- list(fnscale = -1) #dat <- stn_pos[,1:2] ## observed data myCop.t <- ellipCopula(family = "t", param = 0.5,dim = 2, dispstr = "un", df = 8) myCop.t myMvd <- mvdc(copula = myCop.t, margins = c("gamma", "gamma"), paramMargins = list(list(shape = 1.5, scale = 38), list(shape = 1.7, scale = 50))) myMvd n <- 200 dat <- rmvdc(myMvd, n) mm <- apply(dat, 2, mean) vv <- apply(dat, 2, var) rho <- rcorr(dat,type="spearman")[[1]]; round(rho,2) rbind(mm,vv) b1.0 <- c(mm[1]^2/vv[1], vv[1]/mm[1]) b2.0 <- c(mm[2]^2/vv[2], vv[2]/mm[2]) a.0 <- sin(cor(dat[, 1], dat[, 2], method = "kendall") * pi/2) start <- c(b1.0, b2.0, a.0) b1hat <- optim(c(1,5), fn = loglik.marg, x = dat[, 1], control = ctrl)$par b2hat <- optim(c(1,5), fn = loglik.marg, x = dat[, 2], control = ctrl)$par udat <- cbind(pgamma(dat[, 1], shape = b1hat[1], scale = b1hat[2]),pgamma(dat[, 2], shape = b2hat[1], scale = b2hat[2])) > fit.ifl <- fitCopula(myCop.t, udat, method="mpl", c(1,5,1,5,8),estimate.variance=TRUE) Error in fitCopula.ml(data, copula, start, lower, upper, optim.control, : The length of start and copula parameters do not match. > fit.ifl <- fitCopula(udat, my...@copula, c(1,5,1,5,8)) Error in fitCopula(udat, my...@copula, c(1, 5, 1, 5, 8)) : Implemented methods are: ml, mpl, itau, and irho. In addition: Warning messages: 1: In if (method == "ml") fit <- fitCopula.ml(data, copula, start, : the condition has length > 1 and only the first element will be used 2: In if (method == "mpl") fit <- fitCopula.mpl(copula, data, start, : the condition has length > 1 and only the first element will be used 3: In if (method == "itau") fit <- fitCopula.itau(copula, data, estimate.variance) else if (method == : the condition has length > 1 and only the first element will be used 4: In if (method == "irho") fit <- fitCopula.irho(copula, data, estimate.variance) else stop("Implemented methods are: ml, mpl, itau, and irho.") : the condition has length > 1 and only the first element will be used > fit.ifl <- fitCopula(udat, my...@copula, a.0) ## this given the paper Error in fitCopula(udat, my...@copula, a.0) : Implemented methods are: ml, mpl, itau, and irho. Thank you so much for your help. Regards, Roslinazairimah Zakaria PhD Student School of Maths & Stats University of South Australia Mawson Lakes, SA 5095. Ph: 83025296 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Rmath.dll importing in VB6 problem
Hi, I am facing a problem which i think i need to explain it to you with some background. I need to use the Project R pnorm function in Visual Basic 6.0. I have already installed R and this is how i perform and get back the result: > pnorm(2, 15) [1] 6.117164e-39 which is what i need. I have already installed R, i generated the Rmath.DLL file out so i can import it into my VB6 and use it. Anyway, i reviewed pnorm.c file which was in the directory tree of project R i downloaded, and it has two functions in it: pnorm5 and pnorm_both i have successfully imported the Rmath.dll file into my VB6 program, the matter is that now i am able to use two functions inside pnorm.c which are pnorm5 and pnorm_both; but not the pnorm() (which gives me the result i am looking for) and i get back this error: "Run-time error '453': Can't find DLL entry point pnorm in C:\Rmath.dll" I know that when i want to generate a dll from Visual C++ 6.0, i do need to create a .def file which determines which functions should be exported, but as long as the Rmath.dll is automatically generated after 'make' in standalone folder, i don't have a clear idea that how (and where)should i add the .def file and which file shall i compile to get the Rmath.dll file again, but with mentioning the exporting functions. Or is it a totally different story from the .def files and there is another solution for it? Any help is in advanced appreciated. -- Thank you, Best regards. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with Tinn-R
Hi It sounds like you haven't got the right line in your Rprofile.site file. If in Tinn-R you do R, Configure, Permanent this will open and edit this file, adding in the relevant lines including one defining .trPaths. HTH David Jessop -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Van Wyk, Jaap Sent: 10 June 2010 07:21 To: r-help@r-project.org Subject: [R] Help with Tinn-R Importance: High I have just installed the latest versions of R and Tinn-R (running Windows XP prof.) R 2.11.0 Tinn-R version 2.3.5.2 Everything seems fine, except for the following: I usually do this: Open Tinn-R and click on the R icon to open R - this splits the screen into two parts horiozontally, with Tinn-R on top and R in the bottom window. My problem is simply this: By highlighting one line, and click the "send line to R" icon, all works well. But if I highlight more than 1 line and click the "send selection to R" icon, it does not work.\I get the following response and error message displayed in R: R> source(.trPaths[5], echo=TRUE, max.deparse.length=150) Error in source(.trPaths[5], echo = TRUE, max.deparse.length = 150) : object '.trPaths' not found Can somebody please help me solve this. Thank you so much for your time. Regards Jacob Jacob L van Wyk, Dept. of Statistics, University of Johannesburg (APK), Box 524, Auckland Park, 2006, South Africa Office: +27 11 559 3080, Fax: +27 11 559 2499 This email and all contents are subject to the following disclaimer: http://disclaimer.uj.ac.za [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Issued by UBS AG or affiliates to professional investors...{{dropped:30}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] geom_ribbon removes missing values
Hi William, On 6/10/10 2:07 AM, William Dunlap wrote: > I'm not sure exactly what you want in poly_ids, but > if x is a vector of numbers that might contain NA's > and you want a vector of integers that identify each > run of non-NA's and are NA for each then you can get > it with > poly_id <- cumsum(is.na(x)) + 1 # bump count for each NA seen > poly_id[is.na(x)] <- NA > E.g., > > x<-c(1.5, 2.5, NA, 4.5, 5.5, 6.5, NA, 8.5, 9.5, NA, NA, 12.5) > > poly_ids <- cumsum(is.na(x)) + 1 > > poly_ids[is.na(x)] <- NA > > rbind(x, poly_ids) # to line up input and output >[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] > [,12] > x 1.5 2.5 NA 4.5 5.5 6.5 NA 8.5 9.5NANA > 12.5 > poly_ids 1.0 1.0 NA 2.0 2.0 2.0 NA 3.0 3.0NANA > 5.0 Great! That's exactly what I want in poly_ids. Thanks! Please find the new patch below. I also put a new branch on GitHub that is based on ggplot2 master and that has this patch. Note that I still don't know how to run ggplot2 from sources, so you'll have to trust in my copy-and-paste fu: http://github.com/kloesing/ggplot2/commit/177e69ae654da074 --- ggplot2-orig2010-06-06 14:02:25.0 +0200 +++ ggplot2 2010-06-10 08:31:02.0 +0200 @@ -5044,9 +5044,16 @@ draw <- function(., data, scales, coordinates, na.rm = FALSE, ...) { -data <- remove_missing(data, na.rm, - c("x","ymin","ymax"), name = "geom_ribbon") data <- data[order(data$group, data$x), ] + + # Instead of removing NA values from the data and plotting a single + # polygon, we want to "stop" plotting the polygon whenever we're missing + # values and "start" a new polygon as soon as we have new values. We do + # this by creating an id vector for polygonGrob that has distinct + # polygon numbers for sequences of non-NA values and NA for NA values in + # the original data. Example: c(NA, 2, 2, 2, NA, NA, 4, 4, 4, NA) + poly_ids <- cumsum(is.na(data$ymin) | is.na(data$ymax)) +1 + poly_ids[is.na(data$ymin) | is.na(data$ymax)] <- NA tb <- with(data, coordinates$munch(data.frame(x=c(x, rev(x)), y=c(ymax, rev(ymin))), scales) @@ -5054,12 +5061,12 @@ with(data, ggname(.$my_name(), gTree(children=gList( ggname("fill", polygonGrob( -tb$x, tb$y, +tb$x, tb$y, id=c(poly_ids, rev(poly_ids)), default.units="native", gp=gpar(fill=alpha(fill, alpha), col=NA) )), ggname("outline", polygonGrob( -tb$x, tb$y, +tb$x, tb$y, id=c(poly_ids, rev(poly_ids)), default.units="native", gp=gpar(fill=NA, col=colour, lwd=size * .pt, lty=linetype) )) Best, --Karsten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Row binding
hello i use the following code,but it is talking too much time to execute. It there any alternate code for the same. ## >names(bimas_epitopes) >dim(bimas_epitopes) >z6<-NULL;for ( i in 1:1496837) { if (bimas_epitopes[i,7]>39.99 ) z6<-c(z6,i)} >length(z6) 112301 >temp6<-NULL >temp6<-z6[1] >result6<-bimas_epitopes[temp6,] >for ( i in 2:112301) { temp6<-z6[i];result6<-rbind(result6,bimas_epitopes[temp6,])}this code is talking too much time for row binding # need the alternate if u can help. -- Regards Ab Rauf Shah [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Patch for legend.position={left,top,bottom} in ggplot2
Hi everyone, here's the same patch as a new branch on GitHub. http://github.com/kloesing/ggplot2/commit/a25e4fbfa4017ed1 Best, --Karsten On 6/7/10 3:39 PM, Karsten Loesing wrote: > Hi Hadley and everyone, > > here's a patch for ggplot2 that fixes the behavior of > opts(legend.position={left,top,bottom}). If you try the following code > in an unmodified ggplot2 > > options(warn = -1) > suppressPackageStartupMessages(library("ggplot2")) > data <- data.frame( > x = c(1, 2, 3, 4, 5, 6), > y = c(2, 3, 4, 3, 4, 5), > colour = c(TRUE, TRUE, TRUE, FALSE, FALSE, FALSE)) > ggplot(data, aes(x = x, y = y, colour = colour)) + > geom_line() + opts(title = "title", legend.position = "right") > ggplot(data, aes(x = x, y = y, colour = colour)) + > geom_line() + opts(title = "title", legend.position = "left") > ggplot(data, aes(x = x, y = y, colour = colour)) + > geom_line() + opts(title = "title", legend.position = "top") > ggplot(data, aes(x = x, y = y, colour = colour)) + > geom_line() + opts(title = "title", legend.position = "bottom") > > you'll see that plots 2 to 4 are broken. > > I think I located the bug in surround_viewports() where the graphical > elements are placed into the grid. If we increment all rows and columns > of the graphical elements for positions "left", "top", and "bottom" by > 1, those graphs look sane again. I assume that a new first row and > column were added at some point in the development, but only the > parameters for the default position "right" were adjusted. Here's the patch: > > > --- ggplot2-orig2 2010-06-07 13:14:35.0 +0200 > +++ ggplot2 2010-06-07 15:22:33.0 +0200 > @@ -7003,27 +7003,27 @@ > ) >} else if (position == "left") { > viewports <- vpList( > - vp("panels", 2, 3), > - vp("legend_box", 2, 1), > - vp("ylabel", 2, 2), > - vp("xlabel", 3, 3), > - vp("title", 1, 3) > + vp("panels", 3, 4), > + vp("legend_box", 3, 2), > + vp("ylabel", 3, 3), > + vp("xlabel", 4, 4), > + vp("title", 2, 4) > ) >} else if (position == "top") { > viewports <- vpList( > - vp("panels", 3, 2), > - vp("legend_box", 2, 2), > - vp("ylabel", 3, 1), > - vp("xlabel", 4, 2), > - vp("title", 1, 2) > + vp("panels", 4, 3), > + vp("legend_box", 3, 3), > + vp("ylabel", 4, 2), > + vp("xlabel", 5, 3), > + vp("title", 2, 3) > ) >} else if (position == "bottom") { > viewports <- vpList( > - vp("panels", 2, 2), > - vp("legend_box", 4, 2), > - vp("ylabel", 2, 1), > - vp("xlabel", 3, 2), > - vp("title", 1, 2) > + vp("panels", 3, 3), > + vp("legend_box", 5, 3), > + vp("ylabel", 3, 2), > + vp("xlabel", 4, 3), > + vp("title", 2, 3) > ) >} else { > viewports <- vpList( > > > Best, > --Karsten > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Rmath.dll importing in VB6 problem
On Thu, 10 Jun 2010, Ali Makhmali wrote: Hi, I am facing a problem which i think i need to explain it to you with some background. I need to use the Project R pnorm function in Visual Basic 6.0. I have already installed R and this is how i perform and get back the result: pnorm(2, 15) [1] 6.117164e-39 which is what i need. I have already installed R, i generated the Rmath.DLL file out so i can import it into my VB6 and use it. Anyway, i reviewed pnorm.c file which was in the directory tree of project R i downloaded, and it has two functions in it: pnorm5 and pnorm_both i have successfully imported the Rmath.dll file into my VB6 program, the matter is that now i am able to use two functions inside pnorm.c which are pnorm5 and pnorm_both; but not the pnorm() (which gives me the result i am looking for) and i get back this error: "Run-time error '453': Can't find DLL entry point pnorm in C:\Rmath.dll" I know that when i want to generate a dll from Visual C++ 6.0, i do need to create a .def file which determines which functions should be exported, but as long as the Rmath.dll is automatically generated after 'make' in standalone folder, i don't have a clear idea that how (and where)should i add the .def file and which file shall i compile to get the Rmath.dll file again, but with mentioning the exporting functions. Instead of speculating, you should instead look at the exported entry points: assuming you made Rmath.dll correctly, the entry points are exported. Or is it a totally different story from the .def files and there is another solution for it? There is, but this is not an R-help question -- please do study the posting guide and follow its request not to post C programming questions _here_ (and not to send HTML). Any help is in advanced appreciated. -- Thank you, Best regards. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] error in misclass results
please help me again I have a problem. I want to do cross-validation for multinomial log. reg. I have a response variabe with 7 levels (Z((a,b,c,d,e,f,g)) and 4 predictor(1 classifier and 3 continuous). I did: #data with 100 observations > library('bootstrap') >x<-matrix(c(data$H, data$K, data$P, data$W),100,4) >y<-data$Z >theta.fit <- function(x,y){lsfit(x,y)} >theta.predict <- function(fit,x){cbind(1,x)%*%fit$coef} >sq.err <- function(y,yhat) { (y-yhat)^2} >results <- bootpred(x,y,50,theta.fit,theta.predict, sq.err) >miss.clas <- function(y,yhat){ 1*(yhat!=y)} >results <- bootpred(x,y,50,theta.fit,theta.predict, miss.clas) do this form correct for my data? if yes; but why after both results, R give me error? Error in lsfit(x, y) : NA/NaN/Inf in foreign function call (arg 1) In addition: Warning messages: 1: In storage.mode(x) <- "double" : NAs introduced by coercion 2: In storage.mode(y) <- "double" : NAs introduced by coercion Thanks alot Azam [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to add a new plot in the same graph using add=T at the command plot?
Hi Peter Ehlers napsal dne 09.06.2010 19:05:24: > Soapbox: > Well, if you're just starting out with R it would be > a VERY good idea to learn right away that T is not TRUE > and F is not FALSE, at least not always. Sooner or > later you WILL have problems. So do yourself a favour > and get into the habit of using TRUE/FALSE instead of T/F. > > (I know that Petr knows better.) Yes good point. However when I work interactively with command prompt I often (well almost exclusively :-) use T/F instead of TRUE/FALSE as I am lazy to type. It is necessary to keep habit not to use T/F/c/matrix/vector/... as names for objects. So T can be used as abbreviation for TRUE like mean(x, na.rm=T) as long as you do not define T <- "Title" mean(x, na.rm=T) Error in if (na.rm) x <- x[!is.na(x)] : argument is not interpretable as logical at least until T/F is removed from such use by R developers You can even try ?"T" and you can read help page for that. Regards Petr > > -Peter Ehlers > > On 2010-06-09 9:08, Larissa Lucena wrote: > > Thanks so much!!! I'm using R for the first time, and so, I have many stupid > > doubts! Sorry and thanks again! > > > > Regards! > > > > 2010/6/9 Petr PIKAL > > > >> Hi > >> > >> where did you find parameter add=T. > >> > >> You can use > >> > >> par(new=T) > >> before using new plot command > >> > >> or use > >> > >> points, lines > >> > >> Regards > >> Petr > >> __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] cbind with vectors of different lengths?
I wrote a function that cbinds vectors of different lengths. Basically, the function adds NAs to shorter vectors and cbinds in the end. I'm attaching the code for guidance. # This function takes in a list() of vectors and cbinds them into a data.frame. timerMelt <- function(x, write.down = FALSE, filename = "output") { stopifnot(is.list(x)) filename <- paste(filename, ".txt", sep = "") len1 <- length(x[[1]]) len2 <- length(x[[2]]) len3 <- length(x[[3]]) max.len <- max(c(len1, len2, len3)) x.cat1 <- data.frame(rep(NA, max.len)) x.cat2 <- data.frame(rep(NA, max.len)) x.cat3 <- data.frame(rep(NA, max.len)) if (len1 < max.len) { x.cat1[1:len1,] <- data.frame(x[[1]]) } else { x.cat1 <- data.frame(x[[1]]) } if (len2 < max.len) { x.cat2[1:len2,] <- data.frame(x[[2]]) } else { x.cat2 <- data.frame(x[[2]]) } if (len3 < max.len) { x.cat3[1:len3,] <- data.frame(x[[3]]) } else { x.cat3 <- data.frame(x[[3]]) } result <- cbind(x.cat1, x.cat2, x.cat3) names(result) <- c("s", "p", "r") if (write.down == TRUE) { write.table(result, filename, row.names = FALSE) } return(result) } Cheers, Roman -- View this message in context: http://r.789695.n4.nabble.com/cbind-with-vectors-of-different-lengths-tp2249680p2250025.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multidimensional matrix from MATLAB
Gopi - Not much to go by, but maybe this will be helpful: In matlab: themat = rand(10,5,3) save themat In R: library(R.matlab) themat = readMat('themat.mat') dim(themat$themat) [1] 10 5 3 (Since .mat file can store more than one object, readMat returns a list with each object as a named element.) - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Thu, 10 Jun 2010, Gopikrishna Deshpande wrote: Hi, Suppose I have a matrix of size 256x14x32 in MATLAB. I want to import that into R. I used readMat and then do.call. But the variable is stored as an array as its done in R. However, I want to define a variable W=array(0,c(256,14,32)) in R and read the multidimensional matlab variable into W. I am not able to do this in R. Please, could you help ? Thanks Gopi [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to add a new plot in the same graph using add=T at the command plot?
On 10.06.2010 10:19, Petr PIKAL wrote: Hi Peter Ehlers napsal dne 09.06.2010 19:05:24: Soapbox: Well, if you're just starting out with R it would be a VERY good idea to learn right away that T is not TRUE and F is not FALSE, at least not always. Sooner or later you WILL have problems. So do yourself a favour and get into the habit of using TRUE/FALSE instead of T/F. (I know that Petr knows better.) Yes good point. However when I work interactively with command prompt I often (well almost exclusively :-) use T/F instead of TRUE/FALSE as I am lazy to type. It is necessary to keep habit not to use T/F/c/matrix/vector/... as names for objects. So T can be used as abbreviation for TRUE like mean(x, na.rm=T) as long as you do not define T<- "Title" mean(x, na.rm=T) Error in if (na.rm) x<- x[!is.na(x)] : argument is not interpretable as logical But note that T <- 0 mean(x, na.rm=T) will yield a more surprising result and that's the reason why you really should not even start to use F and T (neither for a logical value nor for a number). Uwe Ligges at least until T/F is removed from such use by R developers You can even try ?"T" and you can read help page for that. Regards Petr -Peter Ehlers On 2010-06-09 9:08, Larissa Lucena wrote: Thanks so much!!! I'm using R for the first time, and so, I have many stupid doubts! Sorry and thanks again! Regards! 2010/6/9 Petr PIKAL Hi where did you find parameter add=T. You can use par(new=T) before using new plot command or use points, lines Regards Petr __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Odp: question about "mean"
Hi split/sapply can be used besides other options sapply(split(iris[,1:4], iris$Species), mean) Regards Petr r-help-boun...@r-project.org napsal dne 10.06.2010 00:43:29: > Hi there: > I have a question about generating mean value of a data.frame. Take > iris data for example, if I have a data.frame looking like the following: > - > Sepal.Length Sepal.Width Petal.Length Petal.WidthSpecies > 15.1 3.5 1.4 > 0.2 setosa > 24.9 3.0 1.4 > 0.2 setosa > 34.7 3.2 1.3 >0.2 setosa > . . . . > . . > . . . . > . . > . . . . > . . > --- > There are three different species in this table. I want to make a table and > calculate mean value for each specie as the following table: > > - > Sepal.Length Sepal.Width Petal.Length > Petal.Width > mean.setosa5.0063.428 1.462 > 0.246 > mean.versicolor 5.936 2.770 4.260 > 1.326 > mean.virginica 6.5882.974 5.552 > 2.026 > - > Is there any short syntax can do it?? I mean shorter than the code I wrote > as following: > > attach(iris) > mean.setosa<-mean(iris[Species=="setosa", 1:4]) > mean.versicolor<-mean(iris[Species=="versicolor", 1:4]) > mean.virginica<-mean(iris[Species=="virginica", 1:4]) > data.mean<-rbind(mean.setosa, mean.versicolor, mean.virginica) > detach(iris) > -- > > Thanks a million!!! > > > -- > = > Shih-Hsiung, Chou > System Administrator / PH.D Student at > Department of Industrial Manufacturing > and Systems Engineering > Kansas State University > >[[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Re :help to aggregate data
On 10.06.2010 04:48, Mohan L wrote: Dear All, I have the data some thing like this, I am showing here three days data only: dummy.data<- read.table(file='dummy.txt',sep='', header=TRUE) dummy.data StDate Domaindesc Logins 1 05/01/10xxx 10 2 05/01/10xxx 45 3 05/01/10xxx 2 4 05/01/10yyy 45 5 05/01/10yyy 20 6 05/01/10yyy 22 7 05/01/10zzz 34 8 05/01/10zzz 54 9 05/01/10zzz 1 10 05/01/10zzz 0 11 05/02/10yyy 32 12 05/02/10xxx 40 13 05/02/10zzz 23 14 05/02/10yyy 5 15 05/02/10zzz 12 16 05/02/10xxx 19 17 05/02/10xxx 23 18 05/02/10xxx 11 19 05/02/10yyy 9 20 05/02/10zzz 0 21 05/03/10xxx 2 22 05/03/10xxx 21 23 05/03/10xxx 6 24 05/03/10yyy 45 25 05/03/10yyy 43 26 05/03/10yyy 34 27 05/03/10yyy 41 28 05/03/10zzz 31 29 05/03/10zzz 19 30 05/03/10zzz 27 I trying to aggregate(sum) the Logins based on Domaindesc,StDate. I need like this : Domaindesc05/01/10 05/02/10 05/03/10 xxx 5793 29 yyy 8746 122 zzz Any help will be greatly appreciated. See ?tapply, e.g.: tapply(dummy.data[,3], dummy.data[,1:2], sum) Uwe Ligges Thanks for your time. Mohan L [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Odp: cbind with vectors of different lengths?
Hi you shall use na.action = "na.exclude" option in your lm call? Regards Petr r-help-boun...@r-project.org napsal dne 10.06.2010 01:12:55: > > Hello R help > I have a dataframe, with 71 samples (rows) and 30 variables. I got linear > models for some of the variables, and I want to join fitted and residuals of > these models to the data frame. Sometimes, these vectors have the same length > of the dependant variable, but in a few cases, NA values can be found on my > data, and therefore, both fitted and residuals have a few rows less than the > original data frame. As I try cbind, R answers with error, because both > vectors have different lenghts. I have tried with merge but... suddenly I had > a lot of rows of repeated values. I think (with my small idea of R and the > manuals and helps I did read) that first, I have to force residuals and fitted > of my model to be a data frame. > >as.data.frame(fitted(lm)) > this gives, for example > [1] 1.1 > > > [3] 3.8 > > > [4] 1.3 > > [5] 0.9 > > instead of the original fitted(lm) > 13 4 5 > 1.1 3.8 1.3 0.9 > > > that I want to join to my data frame > [1] 17.0 > [2] 15.2 > > > [3] 17.3 > > > [4] 15.0 > > [5] 17.4 > as you can see, row 2 does not exist in fitted... how can I tell R to leave > this row as NA, as below? > > [1] 17.01.1 > > [2] 15.2NA > > > > [3] 17.33.8 > > > > [4] 15.01.3 > > > [5] 17.40.9 > thanks and greets. > Arantzazu Blanco Bernardeau > Dpto de Química Agrícola, Geología y Edafología > Universidad de Murcia-Campus de Espinardo > > _ > ¿Un navegador seguro buscando estás? ¡Protegete ya en www.ayudartepodria.com! > www.ayudartepodria.com > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Position of Axis Labels (Base Graphics)
Hi, I wonder if there is a way to selectively manipulate the position of the axis labels (i.e., the numbers). As far as I get it from ?par the only way to manipulate it is via mgp = c(x,y,z), where z is the relevant number. However, this manipulates the position of the axis labels for both the x- and y-axis. The reason I want to do this is that I have the impression that when using the standard values, the x-axis labels are somewhat further from the axis ticks than the y-axis labels. To make both more similar I would like to position the x-axis labels a little bit nearer to the axis. I know I can work around this problem by suppressing one axis (yaxt="n") and then adding it afterwards via axis(side=2,...). But I wonder if one cannot do this in a better way (hey, it is R). Here is a plot where you should see the problem with the different distance of the labels from the axis ticks: plot(50,50,xlab="", ylab="", xlim=c(30,100), ylim=c(30,100), cex.axis=0.8) Thanks, Henrik Singmann -- View this message in context: http://r.789695.n4.nabble.com/Position-of-Axis-Labels-Base-Graphics-tp2250129p2250129.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] makign help files by hand
On 09.06.2010 19:39, Philip A. Viton wrote: Can someone tell me how to make up (eg) a library's html help files by hand? I think I ought to be able to use RCMD Rdconv for this but (R-2.10.0, MS-win) when I type (in a dos session) "rdcmd rdconv --help" I get a message to the effect that a perl script rdconv can't be opened. Can I do this from within R itself? And if so, how (in particular, what is the target file to be converted)? 1. Please upgrade R. R-2.10.0 was the first version with a new help system, hence there are some corrections made in the meantime. 2. Please read the manual Writing R Extensions. 3. R is case sensitive which is important for the name of the script, hence please use "R CMD Rdconv". I do not have 2.10.0 installed anywhere, but at least since R-2.10.1, Rdconv.sh is a shell script rather than a perl script. Best, Uwe Ligges Thanks! Philip A. Viton City Planning, Ohio State University 275 West Woodruff Avenue, Columbus OH 43210 vito...@osu.edu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Position of Axis Labels (Base Graphics)
On 10.06.2010 11:02, Singmann wrote: Hi, I wonder if there is a way to selectively manipulate the position of the axis labels (i.e., the numbers). As far as I get it from ?par the only way to manipulate it is via mgp = c(x,y,z), where z is the relevant number. However, this manipulates the position of the axis labels for both the x- and y-axis. The reason I want to do this is that I have the impression that when using the standard values, the x-axis labels are somewhat further from the axis ticks than the y-axis labels. To make both more similar I would like to position the x-axis labels a little bit nearer to the axis. I know I can work around this problem by suppressing one axis (yaxt="n") and then adding it afterwards via axis(side=2,...). But I wonder if one cannot do this in a better way (hey, it is R). Right, and axis() is the way to go. Uwe Ligges Here is a plot where you should see the problem with the different distance of the labels from the axis ticks: plot(50,50,xlab="", ylab="", xlim=c(30,100), ylim=c(30,100), cex.axis=0.8) Thanks, Henrik Singmann __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to add a new plot in the same graph using add=T at the command plot?
Hi Uwe Ligges napsal dne 10.06.2010 10:37:05: > > > On 10.06.2010 10:19, Petr PIKAL wrote: > > Hi > > > > Peter Ehlers napsal dne 09.06.2010 19:05:24: > > > >> Soapbox: > >> Well, if you're just starting out with R it would be > >> a VERY good idea to learn right away that T is not TRUE > >> and F is not FALSE, at least not always. Sooner or > >> later you WILL have problems. So do yourself a favour > >> and get into the habit of using TRUE/FALSE instead of T/F. > >> > >> (I know that Petr knows better.) > > > > Yes good point. However when I work interactively with command prompt I > > often (well almost exclusively :-) use T/F instead of TRUE/FALSE as I am > > lazy to type. It is necessary to keep habit not to use > > T/F/c/matrix/vector/... as names for objects. So T can be used as > > abbreviation for TRUE like > > > > mean(x, na.rm=T) > > > > as long as you do not define > > > > T<- "Title" > > mean(x, na.rm=T) > > Error in if (na.rm) x<- x[!is.na(x)] : > >argument is not interpretable as logical > > > But note that > > T <- 0 > mean(x, na.rm=T) > > will yield a more surprising result and that's the reason why you really > should not even start to use F and T (neither for a logical value nor > for a number). > > Uwe Ligges I believe that if you consider T/F as reserved word and do not assign number or text to it you can be on safe side. I agree that in programs it is far better to use TRUE/FALSE instead T/F as you never know if user does not define his own T/F (but he can define its own mean function with unexpected result too). There was some thread about T/F and TRUE/FALSE about half a year ago with no definite output, so I consider it probably still quite controversial item. Regards Petr > > > > > > > at least until T/F is removed from such use by R developers > > > > You can even try > > > > ?"T" > > > > and you can read help page for that. > > > > Regards > > Petr > > > > > >> > >>-Peter Ehlers > >> > >> On 2010-06-09 9:08, Larissa Lucena wrote: > >>> Thanks so much!!! I'm using R for the first time, and so, I have many > > stupid > >>> doubts! Sorry and thanks again! > >>> > >>>Regards! > >>> > >>> 2010/6/9 Petr PIKAL > >>> > Hi > > where did you find parameter add=T. > > You can use > > par(new=T) > before using new plot command > > or use > > points, lines > > Regards > Petr > > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Issues with Bar Graph
> I am having a few problems with this. 1) My y > label seems to be getting > cut off by the edge of my graphing area. I have tried > adjusting the "mar" > and "omi" but it doesn't seem to make any difference. Sure mar changes the plot. Add for example par(mar=c(4,8,4,4)) and you can see the whole y-label. No idea abou the texwrapping though HTH Jannis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] comparing two regression models with different dependent variable
This is only valid in case your X matrix is exactly the same, thus when you have an experiment with multiple response variables (i.e. paired response data). When the data for both models come from a different experiment, it ends here. You also assume that y1 and y2 are measured in the same scale, and can be substracted. If you take two models, one with response Y in meters and one with response Y in centimeters, all others equal, your method will find the models "significantly different" whereas they are exactly the same except for a scaling parameter. If we're talking two different responses, the substraction of both responses doesn't even make sense. The hypothesis you test is whether there is a significant relation between your predictors and the difference of the "reward" response and the "punishment" response. If that is the hypothesis of interest, the difference can be interpreted in a sensible way, AND both the reward learning curve and the punishment learning curve are measured simultaneously for every participant in the study, you can intrinsically compare both models by modelling the difference of the response variable. As this is not the case (learning curves from punishment and reward can never be made up simultaneously), your approach is invalid. Cheers Joris On Thu, Jun 10, 2010 at 9:00 AM, Gabor Grothendieck wrote: > We need to define what it means for these models to be the same or > different. With the usual lm assumptions suppose for i=1, 2 (the two > models) that: > > y1 = a1 + X b1 + error1 > y2 = a2 + X b2 + error2 > > which implies the following which also satisfies the usual lm assumptions: > > y1-y2 = (a1-a2) + X(b1-b2) + error > > Here X is a matrix, a1 and a2 are scalars and all other elements are > vectors. We say the models are the "same" if b1=b2 (but allow the > intercepts to differ even if the models are the "same"). > > If y1 and y2 are as in the built in anscombe data frame and x3 and x4 > are the x variables, i.e. columns of X, then: > >> fm1 <- lm(y1 - y2 ~ x3 + x4, anscombe) >> # this model reduces to the following if b1 = b2 >> fm0 <- lm(y1 - y2 ~ 1, anscombe) >> anova(fm0, fm1) > Analysis of Variance Table > > Model 1: y1 - y2 ~ 1 > Model 2: y1 - y2 ~ x3 + x4 > Res.Df RSS Df Sum of Sq F Pr(>F) > 1 10 20.637 > 2 8 18.662 2 1.9751 0.4233 0.6687 > > so we cannot reject the hypothesis that the models are the "same". > > > On Wed, Jun 9, 2010 at 11:19 AM, Or Duek wrote: >> Hi, >> I would like to compare to regression models - each model has a different >> dependent variable. >> The first model uses a number that represents the learning curve for reward. >> The second model uses a number that represents the learning curve from >> punishment stimuli. >> The first model is significant and the second isn't. >> I want to compare those two models and show that they are significantly >> different. >> How can I do that? >> Thank you. >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Row binding
See 'The R Inferno' Circle 2 for why this takes so long, and what to do about it. On 10/06/2010 08:35, makhdoomi wrote: hello i use the following code,but it is talking too much time to execute. It there any alternate code for the same. ## names(bimas_epitopes) dim(bimas_epitopes) z6<-NULL;for ( i in 1:1496837) { if (bimas_epitopes[i,7]>39.99 ) z6<-c(z6,i)} length(z6) 112301 temp6<-NULL temp6<-z6[1] result6<-bimas_epitopes[temp6,] for ( i in 2:112301) { temp6<-z6[i];result6<-rbind(result6,bimas_epitopes[temp6,])}this code is talking too much time for row binding # need the alternate if u can help. -- Patrick Burns pbu...@pburns.seanet.com http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] comparing two regression models with different dependent variable
I'll try to add some more information regarding my experiment - maybe that would help clear things out. Instead of actually measuring the learning curve (i.e. number of correct responses per block) I created a variable that substract the number of correct answers from the last block with that of the first block. I did the same thing for reward and punishment. I also use the same predictors in both regression models. Until now I just created a new variable - learning vector of reward minus learning vector of punishment. By that I think I measure the difference. I just wanted to know if there's another option to compare a model with same predictors but different dependent variable. On Thu, Jun 10, 2010 at 12:33 PM, Joris Meys wrote: > This is only valid in case your X matrix is exactly the same, thus > when you have an experiment with multiple response variables (i.e. > paired response data). When the data for both models come from a > different experiment, it ends here. > > You also assume that y1 and y2 are measured in the same scale, and can > be substracted. If you take two models, one with response Y in meters > and one with response Y in centimeters, all others equal, your method > will find the models "significantly different" whereas they are > exactly the same except for a scaling parameter. If we're talking two > different responses, the substraction of both responses doesn't even > make sense. > > The hypothesis you test is whether there is a significant relation > between your predictors and the difference of the "reward" response > and the "punishment" response. If that is the hypothesis of interest, > the difference can be interpreted in a sensible way, AND both the > reward learning curve and the punishment learning curve are measured > simultaneously for every participant in the study, you can > intrinsically compare both models by modelling the difference of the > response variable. > > As this is not the case (learning curves from punishment and reward > can never be made up simultaneously), your approach is invalid. > > Cheers > Joris > > On Thu, Jun 10, 2010 at 9:00 AM, Gabor Grothendieck > wrote: > > We need to define what it means for these models to be the same or > > different. With the usual lm assumptions suppose for i=1, 2 (the two > > models) that: > > > > y1 = a1 + X b1 + error1 > > y2 = a2 + X b2 + error2 > > > > which implies the following which also satisfies the usual lm > assumptions: > > > > y1-y2 = (a1-a2) + X(b1-b2) + error > > > > Here X is a matrix, a1 and a2 are scalars and all other elements are > > vectors. We say the models are the "same" if b1=b2 (but allow the > > intercepts to differ even if the models are the "same"). > > > > If y1 and y2 are as in the built in anscombe data frame and x3 and x4 > > are the x variables, i.e. columns of X, then: > > > >> fm1 <- lm(y1 - y2 ~ x3 + x4, anscombe) > >> # this model reduces to the following if b1 = b2 > >> fm0 <- lm(y1 - y2 ~ 1, anscombe) > >> anova(fm0, fm1) > > Analysis of Variance Table > > > > Model 1: y1 - y2 ~ 1 > > Model 2: y1 - y2 ~ x3 + x4 > > Res.DfRSS Df Sum of Sq F Pr(>F) > > 1 10 20.637 > > 2 8 18.662 21.9751 0.4233 0.6687 > > > > so we cannot reject the hypothesis that the models are the "same". > > > > > > On Wed, Jun 9, 2010 at 11:19 AM, Or Duek wrote: > >> Hi, > >> I would like to compare to regression models - each model has a > different > >> dependent variable. > >> The first model uses a number that represents the learning curve for > reward. > >> The second model uses a number that represents the learning curve from > >> punishment stimuli. > >> The first model is significant and the second isn't. > >> I want to compare those two models and show that they are significantly > >> different. > >> How can I do that? > >> Thank you. > >> > >>[[alternative HTML version deleted]] > >> > >> __ > >> R-help@r-project.org mailing list > >> https://stat.ethz.ch/mailman/listinfo/r-help > >> PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > >> and provide commented, minimal, self-contained, reproducible code. > >> > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > > > -- > Joris Meys > Statistical consultant > > Ghent University > Faculty of Bioscience Engineering > Department of Applied mathematics, biometrics and process control > > tel : +32 9 264 59 87 > joris.m...@ugent.be > --- > Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE
Re: [R] Re :help to aggregate data
Hello, Or ?aggregate stdate<-c(rep(1,5),rep(2,5)) domaindesc<-c(1,1,1,2,2,2,3,3,3,3) logins<-sample(1:10, 10) dummy.data<-as.data.frame(cbind(stdate,domaindesc,logins)) aggregate(dummy.data[,3], by=list(dummy.data[,1],dummy.data[,2]), FUN=sum) # same result as tapply, but with only levels that have observation # tapply(dummy.data[,3], dummy.data[,1:2], sum) Eugen Pircalabelu (0032)471 842 140 (0040)727 839 293 - Original Message From: Uwe Ligges To: Mohan L Cc: r-help@r-project.org Sent: Thu, June 10, 2010 10:47:20 AM Subject: Re: [R] Re :help to aggregate data On 10.06.2010 04:48, Mohan L wrote: > Dear All, > > I have the data some thing like this, I am showing here three days data > only: > >> dummy.data<- read.table(file='dummy.txt',sep='', header=TRUE) >> dummy.data > StDate Domaindesc Logins > 1 05/01/10xxx 10 > 2 05/01/10xxx 45 > 3 05/01/10xxx 2 > 4 05/01/10yyy 45 > 5 05/01/10yyy 20 > 6 05/01/10yyy 22 > 7 05/01/10zzz 34 > 8 05/01/10zzz 54 > 9 05/01/10zzz 1 > 10 05/01/10zzz 0 > 11 05/02/10yyy 32 > 12 05/02/10xxx 40 > 13 05/02/10zzz 23 > 14 05/02/10yyy 5 > 15 05/02/10zzz 12 > 16 05/02/10xxx 19 > 17 05/02/10xxx 23 > 18 05/02/10xxx 11 > 19 05/02/10yyy 9 > 20 05/02/10zzz 0 > 21 05/03/10xxx 2 > 22 05/03/10xxx 21 > 23 05/03/10xxx 6 > 24 05/03/10yyy 45 > 25 05/03/10yyy 43 > 26 05/03/10yyy 34 > 27 05/03/10yyy 41 > 28 05/03/10zzz 31 > 29 05/03/10zzz 19 > 30 05/03/10zzz 27 > > I trying to aggregate(sum) the Logins based on Domaindesc,StDate. I need > like this : > > Domaindesc05/01/10 05/02/10 05/03/10 > xxx 5793 29 > yyy 8746 122 > zzz > > Any help will be greatly appreciated. See ?tapply, e.g.: tapply(dummy.data[,3], dummy.data[,1:2], sum) Uwe Ligges > Thanks for your time. > Mohan L > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Package not on CRAN mirrow - what now?
Package arulesSequences isn't on CRAN for automatic package install. I downloaded a *.tar.qz version because no *.zip for Windows offered. Why is this? I expanded *.tar.qz in ~R/R-2.11.0/library/arulesSequences I then assumed that R would list it in the packages list but it doesn't. What am I doing wrong ? Regards __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to add a new plot in the same graph using add=T at the command plot?
On 10.06.2010 11:15, Petr PIKAL wrote: Hi Uwe Ligges napsal dne 10.06.2010 10:37:05: On 10.06.2010 10:19, Petr PIKAL wrote: Hi Peter Ehlers napsal dne 09.06.2010 19:05:24: Soapbox: Well, if you're just starting out with R it would be a VERY good idea to learn right away that T is not TRUE and F is not FALSE, at least not always. Sooner or later you WILL have problems. So do yourself a favour and get into the habit of using TRUE/FALSE instead of T/F. (I know that Petr knows better.) Yes good point. However when I work interactively with command prompt I often (well almost exclusively :-) use T/F instead of TRUE/FALSE as I am lazy to type. It is necessary to keep habit not to use T/F/c/matrix/vector/... as names for objects. So T can be used as abbreviation for TRUE like mean(x, na.rm=T) as long as you do not define T<- "Title" mean(x, na.rm=T) Error in if (na.rm) x<- x[!is.na(x)] : argument is not interpretable as logical But note that T<- 0 mean(x, na.rm=T) will yield a more surprising result and that's the reason why you really should not even start to use F and T (neither for a logical value nor for a number). Uwe Ligges I believe that if you consider T/F as reserved word and do not assign number or text to it you can be on safe side. I agree that in programs it is far better to use TRUE/FALSE instead T/F as you never know if user does not define his own T/F (but he can define its own mean function with unexpected result too). There was some thread about T/F and TRUE/FALSE about half a year ago with no definite output, so I consider it probably still quite controversial item. At least not controversial for me. ;-) Uwe Regards Petr at least until T/F is removed from such use by R developers You can even try ?"T" and you can read help page for that. Regards Petr -Peter Ehlers On 2010-06-09 9:08, Larissa Lucena wrote: Thanks so much!!! I'm using R for the first time, and so, I have many stupid doubts! Sorry and thanks again! Regards! 2010/6/9 Petr PIKAL Hi where did you find parameter add=T. You can use par(new=T) before using new plot command or use points, lines Regards Petr __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Capturing buffered output from Rterm
In MS Windows I a) invoke Rterm from a batch file (test.bat) b) to execute commands from a script (m:\test.rsc) c) capturing output in a log file (m:\test.log) BUT if the script results in an error the error message is NOT written to the log file, leaving me problems when the error is from a complicated function. Simplified example:. test.bat REM ensure 'R' is in path path \\Server02\stats\R\R-Current\bin\;%PATH% Rterm --no-init-file --no-restore-data --no-save --silent < m:\test.rsc > m:\test.log - m:\test.rsc - print("this is a test") #generate an error nls() -- The error message: "Error in .Internal(inherits(x, what, which)) : 'x' is missing" is is NOT written to the log file, which just ends m:\test.log -- > print("this is a test") [1] "this is a test" > #generate an error > nls() - I surmise this is due to output buffering (?). In an S-Plus version I turned off buffering with guiSetOption(option.name="BufferOutputWindows", value.string="F") but I don't think this is available in R (?). Has anyone any suggestions? Thanks in advance, Keith Jewell --please do not edit the information below-- R Version: platform = i386-pc-mingw32 arch = i386 os = mingw32 system = i386, mingw32 status = major = 2 minor = 11.0 year = 2010 month = 04 day = 22 svn rev = 51801 language = R version.string = R version 2.11.0 (2010-04-22) Windows Server 2003 x64 (build 3790) Service Pack 2 Locale: LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United Kingdom.1252;LC_MONETARY=English_United Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252 Search Path: .GlobalEnv, package:datasets, CBRIForecast, package:RODBC, package:tree, package:locfit, package:lattice, package:akima, package:nlme, package:MASS, package:grDevices, package:geometry, KJRutils, package:xlsReadWrite, package:svSocket, package:TinnR, package:R2HTML, package:Hmisc, package:survival, package:splines, package:graphics, package:stats, CBRIutils, package:utils, package:tcltk, package:tools, package:methods, TempEnv, Autoloads, package:base __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Cforest and Random Forest memory use
Hi all, I'm having great trouble working with the Cforest (from the party package) and Random forest functions. Large data set seem to create very large model objects which means I cannot work with the number of observations I need to, despite running on a large 8GB 64-bit box. I would like the object to only hold the trees themselves as I intend to export them out of R. Is there anyway, either through options or editing out code and recompiling them, I can reduce their footprint? I've had a look at the cforest code and the culprit is the 'emsemble' area of the object. I suspect this part of the object contains something related to the number of observations (I have savesplitstats set to FALSE so this shouldn't be the issue). Thanks, Matt [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Package not on CRAN mirrow - what now?
On 10.06.2010 12:28, markw...@afrihost.co.za wrote: Package arulesSequences isn't on CRAN for automatic package install. I downloaded a *.tar.qz version because no *.zip for Windows offered. Why is this? Because the DESCRIPTION file and hence the web page of the package at http://cran.r-project.org/web/packages/arulesSequences/index.html tell us OS_type: unix that means the author declared this package does only work on unix like systems. Best, Uwe Ligges I expanded *.tar.qz in ~R/R-2.11.0/library/arulesSequences I then assumed that R would list it in the packages list but it doesn't. What am I doing wrong ? Regards __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Package not on CRAN mirrow - what now?
markw...@afrihost.co.za wrote: Package arulesSequences isn't on CRAN for automatic package install. I downloaded a *.tar.qz version because no *.zip for Windows offered. Why is this? I expanded *.tar.qz in ~R/R-2.11.0/library/arulesSequences I then assumed that R would list it in the packages list but it doesn't. What am I doing wrong ? You need to install it, it's not generally enough to just unpack it. But that will not work, because the package is marked as "Unix-only". You could try to figure out what needs fixing to get it working on Windows, but it's probably not easy. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Capturing buffered output from Rterm
Keith Jewell wrote: In MS Windows I a) invoke Rterm from a batch file (test.bat) b) to execute commands from a script (m:\test.rsc) c) capturing output in a log file (m:\test.log) BUT if the script results in an error the error message is NOT written to the log file, leaving me problems when the error is from a complicated function. Simplified example:. test.bat REM ensure 'R' is in path path \\Server02\stats\R\R-Current\bin\;%PATH% Rterm --no-init-file --no-restore-data --no-save --silent < m:\test.rsc > m:\test.log - m:\test.rsc - print("this is a test") #generate an error nls() -- The error message: "Error in .Internal(inherits(x, what, which)) : 'x' is missing" is is NOT written to the log file, which just ends m:\test.log -- print("this is a test") [1] "this is a test" #generate an error nls() - I surmise this is due to output buffering (?). In an S-Plus version I turned off buffering with guiSetOption(option.name="BufferOutputWindows", value.string="F") but I don't think this is available in R (?). Has anyone any suggestions? It's not output buffering, it's because error messages go to a different file handle than regular ones. You need to redirect both stdout and stderr. I'm not sure of the syntax to do that in Windows CMD, but R CMD BATCH test.rsc instead of Rterm would do it. (The output should go to test.Rout.) Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] creating a new variable, conditional on the value of an existing variable, selected conditionally
Hi: I had Harold's idea (matrix indexing), but I was curious to see which of these ran fastest. I simulated 1000 rows and three columns of binary data, along with a fourth column that sampled the values 1:3 1000 times. Here are the timings: > f <- as.data.frame(matrix(rbinom(3000, 1, 0.4), nrow = 1000)) > names(f) <- LETTERS[1:3] > f$D <- sample(1:3, 1000, replace = TRUE) > system.time(E1 <- f[cbind(1:nrow(f), f$D)]) user system elapsed 0 0 0 > system.time(E2 <- apply(f, 1, function(x) x[eval(x)["D"]])) user system elapsed 0.030.000.03 > system.time(E3 <- diag(as.matrix(f[f$D]))) user system elapsed 0.260.030.30 > identical(E1, E2) [1] TRUE > identical(E2, E3) [1] TRUE HTH, Dennis On Wed, Jun 9, 2010 at 7:03 AM, Malcolm Fairbrother < m.fairbrot...@bristol.ac.uk> wrote: > Dear all, > > I have a data frame f, with four variables: > > f <- data.frame(A=c(0,0,1,1), B=c(0,1,0,1), C=c(1,1,0,1), D=c(3,1,2,3)) > f > A B C D > 1 0 0 1 3 > 2 0 1 1 1 > 3 1 0 0 2 > 4 1 1 1 3 > > I want to create a new variable (f$E), such that each of its elements is > drawn from either f$A, f$B, or f$C, according to the value (for each row) of > f$D (values of which range from 1 to 3). > > In the first row, D is 3, so I want the value from the third variable (C), > which for the first row is 1. In the second row, D is 1, so I want the value > from the first variable (A), which for the second row is 0. And so forth, > such that in the end my new data frame looks like: > > A B C D E > 1 0 0 1 3 1 > 2 0 1 1 1 0 > 3 1 0 0 2 0 > 4 1 1 1 3 1 > > My question is: How do I do this for a much larger dataset, where my "index > variable" (f$D in this example) actually indexes a much larger number of > variables (not just three)? > > I know that in principle I could do this with a long series of nested > ifelse statements (as below), but I assume there is some less cumbersome > option, and I'd like to know what it is. Any help would be much appreciated. > Apologies if I'm missing something obvious. > > f$E <- ifelse(f$D==3, f$C, ifelse(f$D==2, f$B, f$A)) > > Thanks, > Malcolm > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] comparing two regression models with different dependent variable
As I explained, you cannot just test two models with different dependent variables. You can model the difference you calculated, if you think you can give a sensible interpretation to it. But be aware of the fact that your model will tell you something about the relation between your predictors and the calculated difference between the predictor variables, not about the difference between both models. So the hypothesis you test is whether or not the difference between the learning vector of reward and the learning vector of punishment can be explained by any of your predictor variables. If I understand it right, the setup is as follows : two groups of participants are given a certain task, and have to do that repeatedly. One group gets a punishment for a mistake, the other one a reward for a good answer. the response variable is the difference between the correct answers before and after the learning process. If this is the case, the measurements for punishment and reward are comparable. Then just combine both datasets, add a factor indicating whether the score comes from reward or from punishment, take into account the design (repeated measures, blocks, cross-over, ...), and then you can test a multitude of hypotheses, eg : 1) if there is a main effect of your predictor variables 2) if there is a significant difference between the scores obtained by reward and those obtained by punishment (which is the main effect of the factor you constructed) 3) if the influence of your predictor variables is different for scores obtained by reward or by punishment (which is tested by interaction terms) If you can't get it done with this information, please do consult a statistician in your proximity. Statistics is not a detail, it's a huge set of complex tools that require a thorough understanding of the underlying processes. Don't expect to get some magical one-size-fits-all answer. Cheers Joris On Thu, Jun 10, 2010 at 11:39 AM, Or Duek wrote: > I'll try to add some more information regarding my experiment - maybe that > would help clear things out. > Instead of actually measuring the learning curve (i.e. number of correct > responses per block) I created a variable that substract the number of > correct answers from the last block with that of the first block. > I did the same thing for reward and punishment. > I also use the same predictors in both regression models. > Until now I just created a new variable - learning vector of reward minus > learning vector of punishment. > By that I think I measure the difference. > I just wanted to know if there's another option to compare a model with same > predictors but different dependent variable. > > > On Thu, Jun 10, 2010 at 12:33 PM, Joris Meys wrote: >> >> This is only valid in case your X matrix is exactly the same, thus >> when you have an experiment with multiple response variables (i.e. >> paired response data). When the data for both models come from a >> different experiment, it ends here. >> >> You also assume that y1 and y2 are measured in the same scale, and can >> be substracted. If you take two models, one with response Y in meters >> and one with response Y in centimeters, all others equal, your method >> will find the models "significantly different" whereas they are >> exactly the same except for a scaling parameter. If we're talking two >> different responses, the substraction of both responses doesn't even >> make sense. >> >> The hypothesis you test is whether there is a significant relation >> between your predictors and the difference of the "reward" response >> and the "punishment" response. If that is the hypothesis of interest, >> the difference can be interpreted in a sensible way, AND both the >> reward learning curve and the punishment learning curve are measured >> simultaneously for every participant in the study, you can >> intrinsically compare both models by modelling the difference of the >> response variable. >> >> As this is not the case (learning curves from punishment and reward >> can never be made up simultaneously), your approach is invalid. >> >> Cheers >> Joris >> >> On Thu, Jun 10, 2010 at 9:00 AM, Gabor Grothendieck >> wrote: >> > We need to define what it means for these models to be the same or >> > different. With the usual lm assumptions suppose for i=1, 2 (the two >> > models) that: >> > >> > y1 = a1 + X b1 + error1 >> > y2 = a2 + X b2 + error2 >> > >> > which implies the following which also satisfies the usual lm >> > assumptions: >> > >> > y1-y2 = (a1-a2) + X(b1-b2) + error >> > >> > Here X is a matrix, a1 and a2 are scalars and all other elements are >> > vectors. We say the models are the "same" if b1=b2 (but allow the >> > intercepts to differ even if the models are the "same"). >> > >> > If y1 and y2 are as in the built in anscombe data frame and x3 and x4 >> > are the x variables, i.e. columns of X, then: >> > >> >> fm1 <- lm(y1 - y2 ~ x3 + x4, anscombe) >> >> # this model reduces to the following if b1
Re: [R] back transforming arcsine transformations in metafor
Dear Chris, Just define the following function: transf.iasin <- function(x) { z <- sin(x)^2 return(z) } to give the inverse of the arcsine transformation. Then specify this function under the atransf argument. I will add the transf.iasin() function to the package. Best, -- Wolfgang Viechtbauerhttp://www.wvbauer.com/ Department of Methodology and StatisticsTel: +31 (43) 388-2277 School for Public Health and Primary Care Office Location: Maastricht University, P.O. Box 616 Room B2.01 (second floor) 6200 MD Maastricht, The Netherlands Debyeplein 1 (Randwyck) Original Message From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Chris Miller Sent: Thursday, June 10, 2010 00:28 To: r-help@r-project.org Subject: [R] back transforming arcsine transformations in metafor > Hi everyone, > > I'm using the metafor package to meta-analyze a set of proportions. > This is working really well for the raw proportions, but is there a > way to back-transform the arcsine transformed proportions in the rma > or forest functions with the atransf option? The estimates and CIs > for the transformed proportions need to be back-transformed to be the > sin of the estimate squared. Back-transforming the output isn't a big > deal - it's the forest plots that I would need the back transform > for. Any help or advice would be greatly appreciated. > > Thanks in advance, > Chris > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] To give column names of a data-frame
First of all, read the help file ?data.frame. What you do is adding a variable row.names, column.names and title to your dataframe. What you want to do is set the rownames and colnames. > results <- data.frame(matrix(c(1,2,3,4),nrow=2,ncol=2)) > rownames(results) <- c("a","b") > colnames(results) <- c("c","d") > attr(results,"title") <- "aaa" > results c d a 1 3 b 2 4 > str(results) 'data.frame': 2 obs. of 2 variables: $ c: num 1 2 $ d: num 3 4 - attr(*, "title")= chr "aaa" > attr(results,"title") [1] "aaa" If you have the matrix already, take a look at ?as.data.frame. Cheers Joris On Thu, Jun 10, 2010 at 7:22 AM, suman dhara wrote: > Sir, > I want to export the results of R in a data frame. So I want to give > rownames,columnnames & title to the data-frame.I have applied the following: > > > data.frame(matrix(c(...),nrow=,ncol=),row.names=c("a","b"),col.names=c("c","d"),title="aaa") > > But, it does not work. > Can you help me? > > > Regards, > Suman Dhara > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] comparing two regression models with different dependent variable
Thank you very much for your answers. The setup is not as you described - all participants have 4 stimuli - 2 for punishment and 2 for reward. all participants see them in mixed blocks. I try to measure the correlation between some personality traits (measured with personality questionnaires) and the learning of reward and punishment. again, Thank you very much for your help. On Thu, Jun 10, 2010 at 2:12 PM, Joris Meys wrote: > As I explained, you cannot just test two models with different > dependent variables. You can model the difference you calculated, if > you think you can give a sensible interpretation to it. But be aware > of the fact that your model will tell you something about the relation > between your predictors and the calculated difference between the > predictor variables, not about the difference between both models. So > the hypothesis you test is whether or not the difference between the > learning vector of reward and the learning vector of punishment can be > explained by any of your predictor variables. > > If I understand it right, the setup is as follows : > two groups of participants are given a certain task, and have to do > that repeatedly. One group gets a punishment for a mistake, the other > one a reward for a good answer. the response variable is the > difference between the correct answers before and after the learning > process. > > If this is the case, the measurements for punishment and reward are > comparable. Then just combine both datasets, add a factor indicating > whether the score comes from reward or from punishment, take into > account the design (repeated measures, blocks, cross-over, ...), and > then you can test a multitude of hypotheses, eg : > 1) if there is a main effect of your predictor variables > 2) if there is a significant difference between the scores obtained by > reward and those obtained by punishment (which is the main effect of > the factor you constructed) > 3) if the influence of your predictor variables is different for > scores obtained by reward or by punishment (which is tested by > interaction terms) > > If you can't get it done with this information, please do consult a > statistician in your proximity. Statistics is not a detail, it's a > huge set of complex tools that require a thorough understanding of the > underlying processes. Don't expect to get some magical > one-size-fits-all answer. > > Cheers > Joris > > On Thu, Jun 10, 2010 at 11:39 AM, Or Duek wrote: > > I'll try to add some more information regarding my experiment - maybe > that > > would help clear things out. > > Instead of actually measuring the learning curve (i.e. number of correct > > responses per block) I created a variable that substract the number of > > correct answers from the last block with that of the first block. > > I did the same thing for reward and punishment. > > I also use the same predictors in both regression models. > > Until now I just created a new variable - learning vector of reward minus > > learning vector of punishment. > > By that I think I measure the difference. > > I just wanted to know if there's another option to compare a model with > same > > predictors but different dependent variable. > > > > > > On Thu, Jun 10, 2010 at 12:33 PM, Joris Meys > wrote: > >> > >> This is only valid in case your X matrix is exactly the same, thus > >> when you have an experiment with multiple response variables (i.e. > >> paired response data). When the data for both models come from a > >> different experiment, it ends here. > >> > >> You also assume that y1 and y2 are measured in the same scale, and can > >> be substracted. If you take two models, one with response Y in meters > >> and one with response Y in centimeters, all others equal, your method > >> will find the models "significantly different" whereas they are > >> exactly the same except for a scaling parameter. If we're talking two > >> different responses, the substraction of both responses doesn't even > >> make sense. > >> > >> The hypothesis you test is whether there is a significant relation > >> between your predictors and the difference of the "reward" response > >> and the "punishment" response. If that is the hypothesis of interest, > >> the difference can be interpreted in a sensible way, AND both the > >> reward learning curve and the punishment learning curve are measured > >> simultaneously for every participant in the study, you can > >> intrinsically compare both models by modelling the difference of the > >> response variable. > >> > >> As this is not the case (learning curves from punishment and reward > >> can never be made up simultaneously), your approach is invalid. > >> > >> Cheers > >> Joris > >> > >> On Thu, Jun 10, 2010 at 9:00 AM, Gabor Grothendieck > >> wrote: > >> > We need to define what it means for these models to be the same or > >> > different. With the usual lm assumptions suppose for i=1, 2 (the two > >> > models) that: > >> > > >> > y1 = a1 + X b1 +
Re: [R] mgcv
On Mon, 2010-06-07 at 10:25 -0700, Dipa Hari wrote: > > Hello Sir, > I am using mgcv package for my data. > My model isy~x1+f(x2),I want to find out the function f(x2). > Following is the code. > > sm1=gam(y~x1+s(x2),family=binomial, f) > summary(sm1) > plot(sm1,residuals=TRUE, xlab="AGE",pch=20) > > In this plot I am getting S(x2,1.93) on y axixs > How should I get the function for x2 from this plot.or Is there > anyother procedureinR to get this function or value for that > particular function.for example f(x2)= log(x2) so from that plot how > can I get this kind of formula for x2 variable? ## evaluate smooth at 200 equally spaced points across range of x2 n <- 200 ndat <- with(f, data.frame("x2" = seq(min(x2), max(x2), length = n)) pred <- predict(sm1, newdata = ndat, type = "terms", terms = "s(x2)") ## or for the observed data pred <- predict(sm1, type = "terms", terms = "s(x2)") > How can I find variance covariance matrix for that model That can be done with the standard vcov() extractor method for "gam" objects: vcov(sm1) > and confidence interval for that model ? Model or smooth s(x2)? If the latter, add se.fit = TRUE to the predict calls above. If the former; pred <- predict(sm1, se.fit = TRUE) or for predictions on scale of your response: pred <- predict(sm1, type = "response", se.fit = TRUE) And you can add newdata = ndat to either call if you want predictions for the newdata points we generated earlier. > I tried delta method but I am not getting result. > Hope you understand my question? > Thanks HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Taylor Diagram
On 06/09/2010 10:14 PM, Mustafa Tufan Turp wrote: Dear R users, I need to learn plotting Taylor diagram. I dowloaded the "plotrix" that includes "taylor.diagram" but I dont know how to study with real datasets. Anyone help me? Hi Tufan, Try this: www-pcmdi.llnl.gov/about/staff/Taylor/CV/Taylor_diagram_primer.pdf Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] comparing two regression models with different dependent variable
On Thu, Jun 10, 2010 at 5:33 AM, Joris Meys wrote: > This is only valid in case your X matrix is exactly the same, thus The poster did not give a full explanation so the best that can be done without getting into an extended question and answer is to make some assumptions, show the result and hope that the assumptions are sufficiently close that the poster can tweak it. That the X matrices are assumed to be the same was clearly stated already and seems not to be some new revelation. Ditto for the other comments below. > when you have an experiment with multiple response variables (i.e. > paired response data). When the data for both models come from a > different experiment, it ends here. > > You also assume that y1 and y2 are measured in the same scale, and can > be substracted. If you take two models, one with response Y in meters > and one with response Y in centimeters, all others equal, your method > will find the models "significantly different" whereas they are > exactly the same except for a scaling parameter. If we're talking two > different responses, the substraction of both responses doesn't even > make sense. > > The hypothesis you test is whether there is a significant relation > between your predictors and the difference of the "reward" response > and the "punishment" response. If that is the hypothesis of interest, > the difference can be interpreted in a sensible way, AND both the > reward learning curve and the punishment learning curve are measured > simultaneously for every participant in the study, you can > intrinsically compare both models by modelling the difference of the > response variable. > > As this is not the case (learning curves from punishment and reward > can never be made up simultaneously), your approach is invalid. > > Cheers > Joris > > On Thu, Jun 10, 2010 at 9:00 AM, Gabor Grothendieck > wrote: >> We need to define what it means for these models to be the same or >> different. With the usual lm assumptions suppose for i=1, 2 (the two >> models) that: >> >> y1 = a1 + X b1 + error1 >> y2 = a2 + X b2 + error2 >> >> which implies the following which also satisfies the usual lm assumptions: >> >> y1-y2 = (a1-a2) + X(b1-b2) + error >> >> Here X is a matrix, a1 and a2 are scalars and all other elements are >> vectors. We say the models are the "same" if b1=b2 (but allow the >> intercepts to differ even if the models are the "same"). >> >> If y1 and y2 are as in the built in anscombe data frame and x3 and x4 >> are the x variables, i.e. columns of X, then: >> >>> fm1 <- lm(y1 - y2 ~ x3 + x4, anscombe) >>> # this model reduces to the following if b1 = b2 >>> fm0 <- lm(y1 - y2 ~ 1, anscombe) >>> anova(fm0, fm1) >> Analysis of Variance Table >> >> Model 1: y1 - y2 ~ 1 >> Model 2: y1 - y2 ~ x3 + x4 >> Res.Df RSS Df Sum of Sq F Pr(>F) >> 1 10 20.637 >> 2 8 18.662 2 1.9751 0.4233 0.6687 >> >> so we cannot reject the hypothesis that the models are the "same". >> >> >> On Wed, Jun 9, 2010 at 11:19 AM, Or Duek wrote: >>> Hi, >>> I would like to compare to regression models - each model has a different >>> dependent variable. >>> The first model uses a number that represents the learning curve for reward. >>> The second model uses a number that represents the learning curve from >>> punishment stimuli. >>> The first model is significant and the second isn't. >>> I want to compare those two models and show that they are significantly >>> different. >>> How can I do that? >>> Thank you. >>> >>> [[alternative HTML version deleted]] >>> >>> __ >>> R-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > > > -- > Joris Meys > Statistical consultant > > Ghent University > Faculty of Bioscience Engineering > Department of Applied mathematics, biometrics and process control > > tel : +32 9 264 59 87 > joris.m...@ugent.be > --- > Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 45 degree tick marks
On 06/10/2010 01:44 PM, beloitstudent wrote: Hello experts. Sorry this is such a novice question, but I have been trying, fruitlessly to get my x axis to angle at 45 degrees. I have tried the text() call with srt and adj and just cannot get my labels to tilt. Does anyone have any other suggestions? The following is my command for the graph. Thanks in advance for any help you might be able to provide! Try the staxlab function in plotrix. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Power calculation
Hello, Is there any R function which does power calculation for unbalanced groups (n1 neq n2)? Since power.t.test has n Number of observations (per group). Many thanks, Samuel [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] comparing two regression models with different dependent variable
On Thu, Jun 10, 2010 at 2:04 PM, Gabor Grothendieck wrote: > On Thu, Jun 10, 2010 at 5:33 AM, Joris Meys wrote: >> This is only valid in case your X matrix is exactly the same, thus > > The poster did not give a full explanation so the best that can be > done without getting into an extended question and answer is to make > some assumptions, show the result and hope that the assumptions are > sufficiently close that the poster can tweak it. Don't get me wrong, I do appreciate your willingness to help people on the list. Your solution is also mathematically sound. Yet, it is my experience that proposing a method without a full understanding of the setup and the data of the experiment, often leads to erroneous results. Most often, the tested hypotheses turn out to be not the ones of interest to the researcher, and they're unlikely to grasp the full importance of all assumptions made and all subtle differences between the tested hypotheses. It was clear from the OP that the TS has only limited knowledge about statistics. Hence my further explanation. > > That the X matrices are assumed to be the same was clearly stated > already and seems not to be some new revelation. Ditto for the other > comments below. It is not because the same variables are used, that they contain the same data. I could not conclude that from the little information we have been given. It could have been the same persons tested twice, but it could easily have been two seperate groups as well. Same predictor variables, but other observations, and the X matrices are not the same any more. Cheers Joris __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Power calculation
On 6/10/2010 8:26 AM, Samuel Okoye wrote: > Hello, > > Is there any R function which does power calculation for unbalanced groups > (n1 neq n2)? Since power.t.test has n > > Number of observations (per group). > > Many thanks, > Samuel See pwr.t2n.test() in the pwr package. http://finzi.psych.upenn.edu/R/library/pwr/html/pwr.t2n.test.html You might have found it by doing the following in R: RSiteSearch("power analysis", restrict='function') > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Capturing buffered output from Rterm
On Thu, 10 Jun 2010, Keith Jewell wrote: In MS Windows I a) invoke Rterm from a batch file (test.bat) b) to execute commands from a script (m:\test.rsc) c) capturing output in a log file (m:\test.log) BUT if the script results in an error the error message is NOT written to the log file, leaving me problems when the error is from a complicated function. Sure, warning and errors are written to stderr, which you did not redirect. This is covered in rw-FAQ Q2.12. Using R CMD BATCH would have done this for you This is not to do with 'buffered output': in any case R uses minimal buffering so stdout and stderr can be mixed nicely on a single log file. Simplified example:. test.bat REM ensure 'R' is in path path \\Server02\stats\R\R-Current\bin\;%PATH% Rterm --no-init-file --no-restore-data --no-save --silent < m:\test.rsc > m:\test.log - m:\test.rsc - print("this is a test") #generate an error nls() -- The error message: "Error in .Internal(inherits(x, what, which)) : 'x' is missing" is is NOT written to the log file, which just ends m:\test.log -- print("this is a test") [1] "this is a test" #generate an error nls() - I surmise this is due to output buffering (?). In an S-Plus version I turned off buffering with guiSetOption(option.name="BufferOutputWindows", value.string="F") but I don't think this is available in R (?). Has anyone any suggestions? Thanks in advance, Keith Jewell --please do not edit the information below-- R Version: platform = i386-pc-mingw32 arch = i386 os = mingw32 system = i386, mingw32 status = major = 2 minor = 11.0 year = 2010 month = 04 day = 22 svn rev = 51801 language = R version.string = R version 2.11.0 (2010-04-22) Windows Server 2003 x64 (build 3790) Service Pack 2 Locale: LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United Kingdom.1252;LC_MONETARY=English_United Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252 Search Path: .GlobalEnv, package:datasets, CBRIForecast, package:RODBC, package:tree, package:locfit, package:lattice, package:akima, package:nlme, package:MASS, package:grDevices, package:geometry, KJRutils, package:xlsReadWrite, package:svSocket, package:TinnR, package:R2HTML, package:Hmisc, package:survival, package:splines, package:graphics, package:stats, CBRIutils, package:utils, package:tcltk, package:tools, package:methods, TempEnv, Autoloads, package:base __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ANOVA of a sort
This is a typical problem we give as a homework to students. If you can't solve this yourself, you really need to brush up your statistical knowledge or look for a statistician close by to cooperate with. Take a look at these : http://www.ats.ucla.edu/stat/r/seminars/repeated_measures/repeated_measures.htm http://gribblelab.org/2009/03/09/repeated-measures-anova-using-r/ http://www.r-statistics.com/2010/04/repeated-measures-anova-with-r-tutorials/ If you read through the documentation, you should get a fair idea of whether or not your data is suited to use a repeated measures anova, and if so, how you'd have to specify your model in R. Good luck with it. Cheers Joris On Thu, Jun 10, 2010 at 1:17 AM, Claus O'Rourke wrote: > Dear R Help, > > I have a general question - I know this is the R list, but I hope > someone can help me out a little as I've always found the help here to > be absolutely fantastic. > > I have run a psychological study where participants are given multiple > stimuli and their responses to those stimuli are measured on the same > numerical scale, i.e., the data is something like > > Participant Stimulus Measurement > p1 s`1 5 > p1 s`2 6.1 > p1 s`3 7 > p2 s`1 4.8 > p2 s`2 6 > p2 s`3 6.5 > p3 s`1 4 > p3 s`2 7 > p3 s`3 6 > > I would like to be able to measure the between participant variability > for my data - i.e., determine whether measurements are relatively > homogeneous across participants and whether there are very strange > outliers (i.e., participants who maybe gave random or purposefully > incorrect answers). > > Can anyone point me towards the correct type of tests for quantifying > this? I have read that a repeated measure ANOVA might be a starting > point. > > Many many thanks for any help you can give me! > > Claus > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Can RMySQL be used for a paramterized query?
I think you can do this: ids <- dbGetQuery(conn, "SELECT id FROM my_table") other_table <- dbGetQuery(conn, sprintf("SELECT * FROM my_other_table WHERE t1_id in (%s)", paste(ids, collapse = ","))) On Wed, Jun 9, 2010 at 11:24 PM, Ted Byers wrote: > I have not found anything about this except the following from the DBI > documentation : > > Bind variables: the interface is heavily biased towards queries, as opposed > > to general > > purpose database development. In particular we made no attempt to define > > bind > > variables; this is a mechanism by which the contents of R/S objects are > > implicitly > > moved to the database during SQL execution. For instance, the following > > embedded SQL statement > > /* SQL */ > > SELECT * from emp_table where emp_id = :sampleEmployee > > would take the vector sampleEmployee and iterate over each of its > elements > > to get the result. Perhaps the DBI could at some point in the future > > implement > > this feature. > > > > I can connect, and execute a SQL query such as "SELECT id FROM my_table", > and display a frame with all the IDs from my_table. But I need also to do > something like "SELECT * FROM my_other_table WHERE t1_id = x" where 'x' is > one of the IDs returned by the first select statement. Actually, I have to > do this in two contexts, one where the data are not ordered by time and one > where it is (and thus where I'd have to use TSMySQL to execute something > like "SELECT record_datetime,value FROM my_ts_table WHERE t2_id = x"). > > I'd like to embed this in a loop where I iterate over the IDs returned by > the first select, get the appropriate data from the second for each ID, > analyze that data and store results in another table in the DB, and then > proceed to the next ID in the list. I suppose an alternative would be to > get all the data at once, but the resulting resultset would be huge, and I > don't (yet) know how to take a subset of the data in a frame based on a > given value in one ot the fields and analyze that. Can you point me to an > example of how this is done, or do I have to use a mix of perl (to get the > data) and R (to do the analysis)? > > Any insights on how to proceed would be appreciated. Thanks. > > Ted > >[[alternative HTML version deleted]] > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 45 degree tick marks
On Jun 10, 2010, at 7:18 AM, Jim Lemon wrote: > On 06/10/2010 01:44 PM, beloitstudent wrote: >> >> Hello experts. >> >> Sorry this is such a novice question, but I have been trying, fruitlessly to >> get my x axis to angle at 45 degrees. I have tried the text() call with srt >> and adj and just cannot get my labels to tilt. Does anyone have any other >> suggestions? The following is my command for the graph. Thanks in advance >> for any help you might be able to provide! >> > Try the staxlab function in plotrix. > > Jim Also see: http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f HTH, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Patch for legend.position={left,top,bottom} in ggplot2
Cool! Thanks Karsten. If you send me a github pull request I'll incorporate it. Hadley On Thursday, June 10, 2010, Karsten Loesing wrote: > Hi everyone, > > here's the same patch as a new branch on GitHub. > > http://github.com/kloesing/ggplot2/commit/a25e4fbfa4017ed1 > > Best, > --Karsten > > > On 6/7/10 3:39 PM, Karsten Loesing wrote: >> Hi Hadley and everyone, >> >> here's a patch for ggplot2 that fixes the behavior of >> opts(legend.position={left,top,bottom}). If you try the following code >> in an unmodified ggplot2 >> >> options(warn = -1) >> suppressPackageStartupMessages(library("ggplot2")) >> data <- data.frame( >> x = c(1, 2, 3, 4, 5, 6), >> y = c(2, 3, 4, 3, 4, 5), >> colour = c(TRUE, TRUE, TRUE, FALSE, FALSE, FALSE)) >> ggplot(data, aes(x = x, y = y, colour = colour)) + >> geom_line() + opts(title = "title", legend.position = "right") >> ggplot(data, aes(x = x, y = y, colour = colour)) + >> geom_line() + opts(title = "title", legend.position = "left") >> ggplot(data, aes(x = x, y = y, colour = colour)) + >> geom_line() + opts(title = "title", legend.position = "top") >> ggplot(data, aes(x = x, y = y, colour = colour)) + >> geom_line() + opts(title = "title", legend.position = "bottom") >> >> you'll see that plots 2 to 4 are broken. >> >> I think I located the bug in surround_viewports() where the graphical >> elements are placed into the grid. If we increment all rows and columns >> of the graphical elements for positions "left", "top", and "bottom" by >> 1, those graphs look sane again. I assume that a new first row and >> column were added at some point in the development, but only the >> parameters for the default position "right" were adjusted. Here's the patch: >> >> >> --- ggplot2-orig2 2010-06-07 13:14:35.0 +0200 >> +++ ggplot2 2010-06-07 15:22:33.0 +0200 >> @@ -7003,27 +7003,27 @@ >> ) >> } else if (position == "left") { >> viewports <- vpList( >> - vp("panels", 2, 3), >> - vp("legend_box", 2, 1), >> - vp("ylabel", 2, 2), >> - vp("xlabel", 3, 3), >> - vp("title", 1, 3) >> + vp("panels", 3, 4), >> + vp("legend_box", 3, 2), >> + vp("ylabel", 3, 3), >> + vp("xlabel", 4, 4), >> + vp("title", 2, 4) >> ) >> } else if (position == "top") { >> viewports <- vpList( >> - vp("panels", 3, 2), >> - vp("legend_box", 2, 2), >> - vp("ylabel", 3, 1), >> - vp("xlabel", 4, 2), >> - vp("title", 1, 2) >> + vp("panels", 4, 3), >> + vp("legend_box", 3, 3), >> + vp("ylabel", 4, 2), >> + vp("xlabel", 5, 3), >> + vp("title", 2, 3) >> ) >> } else if (position == "bottom") { >> viewports <- vpList( >> - vp("panels", 2, 2), >> - vp("legend_box", 4, 2), >> - vp("ylabel", 2, 1), >> - vp("xlabel", 3, 2), >> - vp("title", 1, 2) >> + vp("panels", 3, 3), >> + vp("legend_box", 5, 3), >> + vp("ylabel", 3, 2), >> + vp("xlabel", 4, 3), >> + vp("title", 2, 3) >> ) >> } else { >> viewports <- vpList( >> >> >> Best, >> --Karsten >> > > -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] counting Na/not NA by groups by column
Try this also: rowsum(`mode<-`(!is.na(m[,-(1:2)]), 'numeric'), m[,2]) On Wed, Jun 9, 2010 at 10:03 PM, steven mosher wrote: > # create a matrix with some random NAs in it > > m<-matrix(NA,nrow=15,ncol=14) > > m[,3:14]<-52 > > m[13,9]<-NA > > m[4:7,8]<-NA > > m[1:2,5]<-NA > > m[,2]<-rep(1800:1804, by=3) > > y<-order(m[,2]) > > m<-m[y,] > > m[,1]<-rep(1:3,by=5) > > m > [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] > [,14] > [1,]1 1800 52 52 NA 52 52 52 5252525252 > 52 > [2,]2 1800 52 52 52 52 52 NA 5252525252 > 52 > [3,]3 1800 52 52 52 52 52 52 5252525252 > 52 > [4,]1 1801 52 52 NA 52 52 52 5252525252 > 52 > [5,]2 1801 52 52 52 52 52 NA 5252525252 > 52 > [6,]3 1801 52 52 52 52 52 52 5252525252 > 52 > [7,]1 1802 52 52 52 52 52 52 5252525252 > 52 > [8,]2 1802 52 52 52 52 52 52 5252525252 > 52 > [9,]3 1802 52 52 52 52 52 52 NA52525252 > 52 > [10,]1 1803 52 52 52 52 52 NA 5252525252 > 52 > [11,]2 1803 52 52 52 52 52 52 5252525252 > 52 > [12,]3 1803 52 52 52 52 52 52 5252525252 > 52 > [13,]1 1804 52 52 52 52 52 NA 5252525252 > 52 > [14,]2 1804 52 52 52 52 52 52 5252525252 > 52 > [15,]3 1804 52 52 52 52 52 52 5252525252 > 52 > > # the goal is to count all NON NA by changes in column 2 > # we can get the count for all rows easily. > > col.sum<-(apply(!is.na(m[,3:14]),2,sum)) > > col.sum > [1] 15 15 13 15 15 11 14 15 15 15 15 15 > > # what we want is a result that looks like this > 1800 3 3 2 3 3 2 3 3 3 3 3 3 > 1801 3 3 2 3 3 2 3 3 3 3 3 3 > 1802 3 3 3 3 3 3 2 3 3 3 3 3 > 1803 3 3 3 3 3 2 3 3 3 3 3 3 > 1804 3 3 3 3 3 2 3 3 3 3 3 3 > > I've toyed a bit with By > > > mask<-!is.na(m[,3:14]) > > test<-cbind(m[,1:2],mask) > > test > [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] > [,14] > [1,]1 18001101111 1 1 1 1 > 1 > [2,]2 18001111101 1 1 1 1 > 1 > [3,]3 18001111111 1 1 1 1 > 1 > [4,]1 18011101111 1 1 1 1 > 1 > [5,]2 18011111101 1 1 1 1 > 1 > [6,]3 18011111111 1 1 1 1 > 1 > [7,]1 18021111111 1 1 1 1 > 1 > [8,]2 18021111111 1 1 1 1 > 1 > [9,]3 18021111110 1 1 1 1 > 1 > [10,]1 18031111101 1 1 1 1 > 1 > [11,]2 18031111111 1 1 1 1 > 1 > [12,]3 18031111111 1 1 1 1 > 1 > [13,]1 18041111101 1 1 1 1 > 1 > [14,]2 18041111111 1 1 1 1 > 1 > [15,]3 18041111111 1 1 1 1 > 1 > > > result<-by(test[,3:14],test[,2], sum) > > result > INDICES: 1800 > [1] 34 > > - > INDICES: 1801 > [1] 34 > > - > INDICES: 1802 > [1] 35 > > - > INDICES: 1803 > [1] 35 > > - > INDICES: 1804 > [1] 35 > > > as this sums all the values and not by column. it's wrong > so is there an elegant way to get the number of > NON Nas.. by column governed by changes in the values of a variable. > >[[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://s
[R] Sweave cutting new lines
Hi, I have trouble with Sweave (I think) cutting of my newlines. As stated in the help of Sweave, I generate tex code straight from R for dynamically computed reports. If I do this in R: for (i in 0:4) {cat("\n",i,"\n")};cat("\n 3") 0 1 2 3 4 3 The output looks correct. However, Sweave for some reason seems to trim everything outside forloops. Hence, this <>= sec<-0 lambda<-0 chartvalue<-"b" relsec<-0 for (chartvalue in c("b","beta")) { for (relsec in 0:(e("count pd")-2)) { file<-paste("working/frontfile",sec,"x",lambda,"x",chartvalue,"x",relsec,".pdf",sep="") pdf(file=file,paper="special",width=14,height=6) correl.plotsinglechart(sec,lambda,chartvalue,relsec) tmp<-dev.off() cat("\\includegraphics{",file,"}\n\n",sep="") } } chartvalue<-"rsq" relsec<-0 file<-paste("working/frontfile",sec,"x",lambda,"x",chartvalue,"x",relsec,".pdf",sep="") pdf(file=file,paper="special",width=14,height=6) correl.plotsinglechart(sec,lambda,chartvalue,relsec) tmp<-dev.off() cat("\n\\newline\\includegraphics{",file,"}\n\n",sep="") @ gets converted to this \includegraphics{working/frontfile0x0xbx0.pdf} \includegraphics{working/frontfile0x0xbx1.pdf} \includegraphics{working/frontfile0x0xbx2.pdf} \includegraphics{working/frontfile0x0xbetax0.pdf} \includegraphics{working/frontfile0x0xbetax1.pdf} \includegraphics{working/frontfile0x0xbetax2.pdf}\newline\includegraphics{working/frontfile0x0xrsqx0.pdf} This actually works now because the \newline takes care of the line break, but it is not very pretty. Does anyone know why Sweave behaves this way? Is there a way to fix it (besides working in another R chunk)? Maybe I am just being silly... Thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] glm poisson function
Hi, I'm totally new to R so I apologise for the basic request. I am looking at the incidence of a disease over two time periods 1990-1995 and 2003-2008. I have counts for each year, subdivided into three disease categories and by males/females. I understand that I need to analyse the data using poisson regression and have managed to use the pois.daly function to get age-sex adjusted rates and corresponding confidence intervals. However, I now want to know how get a p value (I'm writing up a paper for a journal) to say that x number of cases in the first cohort (1990-1995) is significantly lower than y number in the later cohort (2003-2008). I also want to make sure that I've corrected for overdispersion etc. I'm totally stuck and can't think where to start with writing a script. So basically my question is: e.g. I have 271 cases of the disease between 1990-1995 (total population at risk over six years = 6,164,113) and 433 cases between 2003-2008 (total population at risk over sic year = 5,572,041) - is this significant and what is the P value. Any help much appreciated! Cheers P -- View this message in context: http://r.789695.n4.nabble.com/glm-poisson-function-tp2250210p2250210.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Intra-Class correlation psych package missing data
Hi Bill, No worries, always a million things to do! Thanks very much for the reply, that has cleared that up and I'll look out for the update next week. Many thanks, Ross -- View this message in context: http://r.789695.n4.nabble.com/Intra-Class-correlation-psych-package-missing-data-tp1773942p2250304.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] drawing curve
Sir, I have a problem regarding drawing curve.I pose the problem as follows: suppose I have two vectors: x<-c(1:6) y<-c(.01,.09,.08,.03,.001,.02) plot(x,y) It gives me the plotted points.But I want to draw a smooth curve passing througt these points. How can I do this? Thanks & Regards, Suman Dhara [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] partial matches across rows not columns
Hi Jim and Hi Jannis, Thanks very much to both of you for your help! Both methods work perfectly! Always good to know that there is more than one way to skin a cat when it comes to R! I will just need to get a grip on the regular expressions, it would seem. Many thanks again for you r help, much appreciated, Ross -- View this message in context: http://r.789695.n4.nabble.com/partial-matches-across-rows-not-columns-tp2247757p2250306.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] drawing curve
Have a look at the ggplot2 package x <- 1:6 y <- c(.01,.09,.08,.03,.001,.02) dataset <- data.frame(x, y) library(ggplot2) ggplot(data = dataset, aes(x = x , y = y)) + geom_smooth() ggplot(data = dataset, aes(x = x , y = y)) + geom_smooth() + geom_point() ggplot(data = dataset, aes(x = x , y = y)) + geom_smooth(span = 1) + geom_point() Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg Gaverstraat 4 9500 Geraardsbergen Belgium Research Institute for Nature and Forest team Biometrics & Quality Assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey > -Oorspronkelijk bericht- > Van: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] Namens suman dhara > Verzonden: donderdag 10 juni 2010 12:12 > Aan: r-h...@stat.math.ethz.ch > Onderwerp: [R] drawing curve > > Sir, > I have a problem regarding drawing curve.I pose the problem > as follows: > > suppose I have two vectors: > x<-c(1:6) > y<-c(.01,.09,.08,.03,.001,.02) > plot(x,y) > > It gives me the plotted points.But I want to draw a smooth > curve passing througt these points. > How can I do this? > > > Thanks & Regards, > Suman Dhara > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > Druk dit bericht a.u.b. niet onnodig af. Please do not print this message unnecessarily. Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sweave cutting new lines
Hi Florian, Have you tried to replace each '\n' with '\r\n'. That did the trick for me. HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie & Kwaliteitszorg Gaverstraat 4 9500 Geraardsbergen Belgium Research Institute for Nature and Forest team Biometrics & Quality Assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey > -Oorspronkelijk bericht- > Van: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] Namens Florian Burkart > Verzonden: donderdag 10 juni 2010 14:44 > Aan: r-help@r-project.org > Onderwerp: [R] Sweave cutting new lines > > Hi, > > I have trouble with Sweave (I think) cutting of my newlines. > > As stated in the help of Sweave, I generate tex code straight > from R for dynamically computed reports. > > If I do this in R: > > for (i in 0:4) {cat("\n",i,"\n")};cat("\n 3") > > 0 > > 1 > > 2 > > 3 > > 4 > > 3 > > The output looks correct. > > However, Sweave for some reason seems to trim everything > outside forloops. Hence, this > > <>= > sec<-0 > lambda<-0 > chartvalue<-"b" > relsec<-0 > for (chartvalue in c("b","beta")) { > for (relsec in 0:(e("count pd")-2)) { > > file<-paste("working/frontfile",sec,"x",lambda,"x",chartvalue, > "x",relsec,".pdf",sep="") > pdf(file=file,paper="special",width=14,height=6) > correl.plotsinglechart(sec,lambda,chartvalue,relsec) > tmp<-dev.off() > cat("\\includegraphics{",file,"}\n\n",sep="") > } > } > chartvalue<-"rsq" > relsec<-0 > file<-paste("working/frontfile",sec,"x",lambda,"x",chartvalue, > "x",relsec,".pdf",sep="") > pdf(file=file,paper="special",width=14,height=6) > correl.plotsinglechart(sec,lambda,chartvalue,relsec) > tmp<-dev.off() > cat("\n\\newline\\includegraphics{",file,"}\n\n",sep="") > @ > > gets converted to this > > \includegraphics{working/frontfile0x0xbx0.pdf} > > \includegraphics{working/frontfile0x0xbx1.pdf} > > \includegraphics{working/frontfile0x0xbx2.pdf} > > \includegraphics{working/frontfile0x0xbetax0.pdf} > > \includegraphics{working/frontfile0x0xbetax1.pdf} > > \includegraphics{working/frontfile0x0xbetax2.pdf}\newline\incl > udegraphics{working/frontfile0x0xrsqx0.pdf} > > > > This actually works now because the \newline takes care of > the line break, but it is not very pretty. > > > Does anyone know why Sweave behaves this way? Is there a way > to fix it > (besides working in another R chunk)? Maybe I am just being silly... > > Thanks > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > Druk dit bericht a.u.b. niet onnodig af. Please do not print this message unnecessarily. Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R[ dates on zoo objects
Dear R People: I have a zoo object with its date index as a factor. > xAle1.zoo$index Error in xAle1.zoo$index : $ operator is invalid for atomic vectors > str(xAle1.zoo) Class 'zoo' atomic [1:32] 1253 1316 1038 1157 1710 1489 1159 1142 945 1245 ... ..- attr(*, "index")= Factor w/ 32 levels "04/16/09","04/17/09",..: 1 2 3 4 5 6 7 8 9 10 ... > How do I change that over to dates, please? Thanks, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Capturing errors [not buffered output] from Rterm
Thanks to both Prof. Ripley and Duncan Murdoch for correctly diagnosing my problem as failure to redirect stderr (nothing to do with buffering). Both pointed me to R CMD BATCH which would have done the job, if I hadn't wanted to run interactively - in my real task (not the example below) I had Rterm --ess. I guess I could use R CMD BATCH --ess but instead I'm using the suggestion in rw-FAQ Q2.12 of simply adding 2>&1 to redirect stderr to stdout. Rterm < m:\test.rsc > m:\test.log 2>&1 Problem solved. The answer was in rw-FAQ , mea culpa for not spotting it myself, thanks for treating me kindly! "Prof Brian Ripley" wrote in message news:alpine.lfd.2.00.1006101333520.25...@gannet.stats.ox.ac.uk... > On Thu, 10 Jun 2010, Keith Jewell wrote: > >> In MS Windows I >> a) invoke Rterm from a batch file (test.bat) >> b) to execute commands from a script (m:\test.rsc) >> c) capturing output in a log file (m:\test.log) >> >> BUT if the script results in an error the error message is NOT written to >> the log file, leaving me problems when the error is from a complicated >> function. > > Sure, warning and errors are written to stderr, which you did not > redirect. This is covered in rw-FAQ Q2.12. Using R CMD BATCH would have > done this for you > > This is not to do with 'buffered output': in any case R uses minimal > buffering so stdout and stderr can be mixed nicely on a single log file. > >> Simplified example:. >> >> test.bat >> REM ensure 'R' is in path >> path \\Server02\stats\R\R-Current\bin\;%PATH% >> Rterm --no-init-file --no-restore-data --no-save --silent < m:\test.rsc >> > >> m:\test.log >> - >> >> m:\test.rsc - >> print("this is a test") >> #generate an error >> nls() >> -- >> >> The error message: >> "Error in .Internal(inherits(x, what, which)) : 'x' is missing" >> is is NOT written to the log file, which just ends >> >> m:\test.log -- >> >>> print("this is a test") >> [1] "this is a test" >>> #generate an error >>> nls() >> - >> >> I surmise this is due to output buffering (?). In an S-Plus version I >> turned >> off buffering with >> guiSetOption(option.name="BufferOutputWindows", value.string="F") >> but I don't think this is available in R (?). >> >> Has anyone any suggestions? >> >> Thanks in advance, >> >> Keith Jewell >> --please do not edit the information below-- >> >> R Version: >> platform = i386-pc-mingw32 >> arch = i386 >> os = mingw32 >> system = i386, mingw32 >> status = >> major = 2 >> minor = 11.0 >> year = 2010 >> month = 04 >> day = 22 >> svn rev = 51801 >> language = R >> version.string = R version 2.11.0 (2010-04-22) >> >> Windows Server 2003 x64 (build 3790) Service Pack 2 >> >> Locale: >> LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United >> Kingdom.1252;LC_MONETARY=English_United >> Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252 >> >> Search Path: >> .GlobalEnv, package:datasets, CBRIForecast, package:RODBC, package:tree, >> package:locfit, package:lattice, package:akima, package:nlme, >> package:MASS, >> package:grDevices, package:geometry, KJRutils, package:xlsReadWrite, >> package:svSocket, package:TinnR, package:R2HTML, package:Hmisc, >> package:survival, package:splines, package:graphics, package:stats, >> CBRIutils, package:utils, package:tcltk, package:tools, package:methods, >> TempEnv, Autoloads, package:base >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > -- > Brian D. Ripley, rip...@stats.ox.ac.uk > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, Tel: +44 1865 272861 (self) > 1 South Parks Road, +44 1865 272866 (PA) > Oxford OX1 3TG, UKFax: +44 1865 272595 > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] points marking
Hi, How to mark points on x axis of a graph keeping x axis as constant and changing y from y1 to y2 respectively. I want to highlight the area from y1 to y2. Any suggestions Thank you Jeet [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Wrong symbol rendering in plots (Ubuntu)
Hello, please excuse me if this is a repost, I think I got confused about how to reply. Anyway, I posted the message below about a day and a half ago through Nabble but have not been cleared until today. Here it goes again. Please bear with me I will get better with time. Start of message sent about two days ago--- Hello all, thank you very much for the replies and I am very sorry for being so late to come back to the discussion, I was on a field trip without internet access. @ Ben I have the problem any time I try to use the mu symbol or the degree symbol using expression() (the only way I know how to do it). Yvonnick's code is a good example, I have just added the mu and the degree symbol: pdf("Test.pdf") plot(1:10,xlab=expression(mu), ylab=expression(C*degree~pi)) dev.off() Even if I don't make the pdf (i.e. just plot on the X11 device), like in Yvonnick's example, the degree symbol is still showing as that gamma-like symbol, pi is shown like an inequality symbol but mu is shown right (on the X11). @ Erik and Yvonnick I think Yvonnick's problem is the same I have (i.e. it is not restricted to pdf files, it also happens in the X11 device, jpg and png). Further, if I create a pdf in Ooo Writer that contains mu, pi or degree symbols and I export them as pdf, they are rendered just fine (similar to what Peter reported, not sure whether he has problems in the X11 device too), the problem is restricted to R-generated graphs. I am going to try Erik's suggestion tonight (sorry I could not try it before posting, I am still catching up with work accumulated from my trip). However, would this fix the problem in rendering in the X11 device? I also feel this might not be just a pdf-viewer issue, but I am an absolute novice. End of message sent about two days ago--- Since then, i tried Erik's suggestion, but I could not find either '~/.fonts.conf' or '/etc/fonts/local.conf' in my system (at least with those exact names). I also got a reply from Prof. Ripley (quote below), I am working on it now, but maybe more experienced users will be more efficient in using it than me. "Your first para confirms it. The problem is font selection by fontconfig, which R's X11 device and Evince etc use and Xpdf or Acroread do not. See ?X11 for ways to debug this." Thanks! Eduardo > sessionInfo() R version 2.11.1 (2010-05-31) i486-pc-linux-gnu locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] adding column of ordered numbers to matrix
Hello everyone, I have a matrix of over 4 line and about 30 columns. For my analysis I would like to add another column with ascending numbers (column header should be "order", and than 1,2,3,4 the end of the matrix). During my analysis I reorder them ( due to merge commands by a different column). How do I add such a column in an ascending order (or descending for what it matters)? THX Assa [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] nls model fitting errors
What am I failing to understand here? The script below works fine if the dataset being used is DNase1 <- DNase[ DNase$Run == 1, ] per the example given in help(nlrob). Obviously, I am trying to understand how to use nls and nlrob to fit curves to data using R. #package=DAAG attach(codling) plot(pobs~dose) #next command returns 'step factor reduced below min factor error' m.nls <- nls( pobs ~ a/(1 + exp(( b - log(dose) )/c ) ), data = codling, start = list( a = 3, b = 0, c = 1 ), trace = TRUE ) s<-seq(min(pobs), max(pobs), .01) p.nls<-predict(m.nls,list(pobs=s)) lines(s,p.nls,col='blue') #generates 'x and y lengths differ' error Gregory A. Graves, Lead Scientist Everglades REstoration COoordination and VERification (RECOVER) Restoration Sciences Department South Florida Water Management District Phones: DESK: 561 / 682 - 2429 CELL: 561 / 719 - 8157 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Patch for legend.position={left,top,bottom} in ggplot2
Hi: I downloaded the patch, how do I incorporate it to my current version of ggplot2? Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish & Wildlife Service California, USA - Original Message > From: Hadley Wickham > To: Karsten Loesing > Cc: "r-help@r-project.org" ; Hadley Wickham > > Sent: Thu, June 10, 2010 5:52:43 AM > Subject: Re: [R] Patch for legend.position={left,top,bottom} in ggplot2 > > Cool! Thanks Karsten. If you send me a github pull request I'll incorporate > it. Hadley On Thursday, June 10, 2010, Karsten Loesing <> ymailto="mailto:karsten.loes...@gmx.net"; > href="mailto:karsten.loes...@gmx.net";>karsten.loes...@gmx.net> > wrote: > Hi everyone, > > here's the same patch as a new > branch on GitHub. > > > http://github.com/kloesing/ggplot2/commit/a25e4fbfa4017ed1 > > > Best, > --Karsten > > > On 6/7/10 3:39 PM, Karsten > Loesing wrote: >> Hi Hadley and everyone, >> >> > here's a patch for ggplot2 that fixes the behavior of >> > opts(legend.position={left,top,bottom}). If you try the following > code >> in an unmodified ggplot2 >> >> options(warn = > -1) >> suppressPackageStartupMessages(library("ggplot2")) >> > data <- data.frame( >> x = c(1, 2, 3, 4, 5, 6), >> > y = c(2, 3, 4, 3, 4, 5), >> colour = c(TRUE, TRUE, TRUE, FALSE, > FALSE, FALSE)) >> ggplot(data, aes(x = x, y = y, colour = colour)) > + >> geom_line() + opts(title = "title", legend.position = > "right") >> ggplot(data, aes(x = x, y = y, colour = colour)) > + >> geom_line() + opts(title = "title", legend.position = > "left") >> ggplot(data, aes(x = x, y = y, colour = colour)) > + >> geom_line() + opts(title = "title", legend.position = > "top") >> ggplot(data, aes(x = x, y = y, colour = colour)) > + >> geom_line() + opts(title = "title", legend.position = > "bottom") >> >> you'll see that plots 2 to 4 are > broken. >> >> I think I located the bug in > surround_viewports() where the graphical >> elements are placed into > the grid. If we increment all rows and columns >> of the graphical > elements for positions "left", "top", and "bottom" by >> 1, those > graphs look sane again. I assume that a new first row and >> column > were added at some point in the development, but only the >> parameters > for the default position "right" were adjusted. Here's the > patch: >> >> >> --- ggplot2-orig2 2010-06-07 > 13:14:35.0 +0200 >> +++ ggplot2 2010-06-07 15:22:33.0 > +0200 >> @@ -7003,27 +7003,27 @@ >> ) >> } > else if (position == "left") { >> viewports <- > vpList( >> - vp("panels", 2, 3), >> - > vp("legend_box", 2, 1), >> - vp("ylabel", 2, 2), >> - > vp("xlabel", 3, 3), >> - vp("title", 1, 3) >> + > vp("panels", 3, 4), >> + vp("legend_box", 3, 2), >> + > vp("ylabel", 3, 3), >> + vp("xlabel", 4, 4), >> + > vp("title", 2, 4) >> ) >> } else if (position == > "top") { >> viewports <- vpList( >> - > vp("panels", 3, 2), >> - vp("legend_box", 2, 2), >> - > vp("ylabel", 3, 1), >> - vp("xlabel", 4, 2), >> - > vp("title", 1, 2) >> + vp("panels", 4, 3), >> + > vp("legend_box", 3, 3), >> + vp("ylabel", 4, 2), >> + > vp("xlabel", 5, 3), >> + vp("title", 2, 3) >> > ) >> } else if (position == "bottom") { >> viewports > <- vpList( >> - vp("panels", 2, 2), >> - > vp("legend_box", 4, 2), >> - vp("ylabel", 2, 1), >> - > vp("xlabel", 3, 2), >> - vp("title", 1, 2) >> + > vp("panels", 3, 3), >> + vp("legend_box", 5, 3), >> + > vp("ylabel", 3, 2), >> + vp("xlabel", 4, 3), >> + > vp("title", 2, 3) >> ) >> } else { >> > viewports <- vpList( >> >> >> Best, >> > --Karsten >> > > -- Assistant Professor / > Dobelman Family Junior Chair Department of Statistics / Rice > University http://had.co.nz/ __ > ymailto="mailto:R-help@r-project.org"; > href="mailto:R-help@r-project.org";>R-help@r-project.org mailing list > href="https://stat.ethz.ch/mailman/listinfo/r-help"; target=_blank > >https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting > guide http://www.R-project.org/posting-guide.html and provide commented, > minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [R[ dates on zoo objects
or > or # 3 > aggregate(z, as.Date(time(z), "%m/%d/%y")) 2009-04-16 2009-04-17 1 2 On Thu, Jun 10, 2010 at 9:58 AM, Gabor Grothendieck wrote: > Its best to use dput when displaying your data in r-help as in dput(z) > or dput(head(z)) if large. > > Try this: > >> library(zoo) >> # test data >> z <- zoo(1:2, factor(c("04/16/09","04/17/09"))) >> >> # 1 >> aggregate(z, function(x) as.Date(x, "%m/%d/%y")) > 2009-04-16 2009-04-17 > 1 2 >> >> # or #2 >> time(z) <- as.Date(time(z), "%m/%d/%y") >> z > 2009-04-16 2009-04-17 > 1 2 > > On Thu, Jun 10, 2010 at 9:42 AM, Erin Hodgess wrote: >> Dear R People: >> >> I have a zoo object with its date index as a factor. >> >>> xAle1.zoo$index >> Error in xAle1.zoo$index : $ operator is invalid for atomic vectors >>> str(xAle1.zoo) >> Class 'zoo' atomic [1:32] 1253 1316 1038 1157 1710 1489 1159 1142 945 1245 >> ... >> ..- attr(*, "index")= Factor w/ 32 levels "04/16/09","04/17/09",..: >> 1 2 3 4 5 6 7 8 9 10 ... >>> >> >> >> >> How do I change that over to dates, please? >> >> Thanks, >> Erin >> >> >> -- >> Erin Hodgess >> Associate Professor >> Department of Computer and Mathematical Sciences >> University of Houston - Downtown >> mailto: erinm.hodg...@gmail.com >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] drawing curve
x<-c(1:6) y<-c(.01,.09,.08,.03,.001,.02) plot(x,y, type='l') Please try ?plot before asking to the list. Ciao! mario On 10-Jun-10 12:11, suman dhara wrote: Sir, I have a problem regarding drawing curve.I pose the problem as follows: suppose I have two vectors: x<-c(1:6) y<-c(.01,.09,.08,.03,.001,.02) plot(x,y) It gives me the plotted points.But I want to draw a smooth curve passing througt these points. How can I do this? Thanks& Regards, Suman Dhara [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ing. Mario Valle Data Analysis and Visualization Group| http://www.cscs.ch/~mvalle Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91) 610.82.60 v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] drawing curve
The OP asked for a smooth curve, foo = splinefun(x,y) curve(foo, min(x), max(x)) # points(x,y) I'm sure a R wizard could make it a one-liner. HTH, baptiste On 10 June 2010 16:48, Mario Valle wrote: > x<-c(1:6) > y<-c(.01,.09,.08,.03,.001,.02) > plot(x,y, type='l') > > Please try ?plot before asking to the list. > Ciao! > mario > > On 10-Jun-10 12:11, suman dhara wrote: >> >> Sir, >> I have a problem regarding drawing curve.I pose the problem as follows: >> >> suppose I have two vectors: >> x<-c(1:6) >> y<-c(.01,.09,.08,.03,.001,.02) >> plot(x,y) >> >> It gives me the plotted points.But I want to draw a smooth curve passing >> througt these points. >> How can I do this? >> >> >> Thanks& Regards, >> Suman Dhara >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > -- > Ing. Mario Valle > Data Analysis and Visualization Group | > http://www.cscs.ch/~mvalle > Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91) 610.82.60 > v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82 > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Baptiste Auguié Departamento de Química Física, Universidade de Vigo, Campus Universitario, 36310, Vigo, Spain tel: +34 9868 18617 http://webs.uvigo.es/coloides __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] glm poisson function
> prop.test(c(271,433),c(6164113,5572041)) 2-sample test for equality of proportions with continuity correction data: c(271, 433) out of c(6164113, 5572041) X-squared = 54.999, df = 1, p-value = 1.206e-13 alternative hypothesis: two.sided 95 percent confidence interval: -4.291428e-05 -2.457623e-05 sample estimates: prop 1 prop 2 4.396415e-05 7.770941e-05 At 06:36 AM 6/10/2010, Phender79 wrote: Hi, I'm totally new to R so I apologise for the basic request. I am looking at the incidence of a disease over two time periods 1990-1995 and 2003-2008. I have counts for each year, subdivided into three disease categories and by males/females. I understand that I need to analyse the data using poisson regression and have managed to use the pois.daly function to get age-sex adjusted rates and corresponding confidence intervals. However, I now want to know how get a p value (I'm writing up a paper for a journal) to say that x number of cases in the first cohort (1990-1995) is significantly lower than y number in the later cohort (2003-2008). I also want to make sure that I've corrected for overdispersion etc. I'm totally stuck and can't think where to start with writing a script. So basically my question is: e.g. I have 271 cases of the disease between 1990-1995 (total population at risk over six years = 6,164,113) and 433 cases between 2003-2008 (total population at risk over sic year = 5,572,041) - is this significant and what is the P value. Any help much appreciated! Cheers P -- View this message in context: http://r.789695.n4.nabble.com/glm-poisson-function-tp2250210p2250210.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Robert A. LaBudde, PhD, PAS, Dpl. ACAFS e-mail: r...@lcfltd.com Least Cost Formulations, Ltd.URL: http://lcfltd.com/ 824 Timberlake Drive Tel: 757-467-0954 Virginia Beach, VA 23464-3239Fax: 757-467-2947 "Vere scire est per causas scire" __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Latex: Date Format conversion
Hi: Can't find a way to convert from shortDate to LongDate format. I got: 3/10/10 that I want to convert to March 10, 2010. I am using: \documentclass[11pt]{article} \usepackage{longtable,verbatim} \usepackage{ctable} \usepackage{datetime} \title{my title} \begin{document} % Convert date \dddate\3/10/10 end{document} My report is changing every two weeks so I will eventually use \Sexpr{report[1,1]} to grab the date from column 1, row 1 of a table named "report" but right now my report has the date formated as described above (3/10/10). Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish & Wildlife Service California, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] selecting and excluding files through a pattern
I have the following files list: > list.files() [1] "Prostate-Cancer_cvs_Dir" [2] "Prostate_Cancer-miRNAs&Genes.Pathway.xml" [3] "Prostate_Cancer_Pathways-miRNAs-GeneTargets-Dir" [4] "Prostate_Cancer_Pathways-miRNAs-GeneTargets-Dir.zip" [5] "Prostate-miRNAs.OrganTargets.txt" [6] "Prostate_Organ-miRNAs-GenesTargets-Dir" [7] "Prostate_Organ-miRNAs-GenesTargets-Dir.zip" [8] "Prostate_Organ-miRNAs-Targets.xml" [9] "Prostatic_Neoplasm-miRNAs.DiseaseTargets.csv-KO" [10] "Prostatic_Neoplasm-miRNAs.DiseaseTargets.txt" [11] "Prostatic_Neoplasms-miRNAs-GeneTargets-Dir" [12] "Prostatic_Neoplasms-miRNAs-GeneTargets-Dir.zip" [13] "Prostatic_Neoplasms-miRNAs.xml" I'd like to find the pattern expression which selects only the directories excluding the one whose pathname contains "csv". I tried: > list.files(pattern="Prostate*Dir") But I do not know how to exclude the names containing the string "csv" at the same time. Thank you for any help, Maura ; tutti i telefonini TIM! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Date conversion
Hi: Can't find a way to convert from shortDate to LongDate format. I got: 3/10/10 that I want to convert to March 10, 2010. I am using: \documentclass[11pt]{article} \usepackage{longtable,verbatim} \usepackage{ctable} \usepackage{datetime} \title{my title} \begin{document} % Convert date \dddate\3/10/10 end{document} My report is changing every two weeks so I will eventually use \Sexpr{report[1,1]} to grab the date from column 1, row 1 of a table named "report" but right now my report has the date formated as described above (3/10/10). Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish & Wildlife Service California, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] lattice: how to remove ticks from splom()?
Is the quote below from Deepayan a possible Fortune? It put a sardonic smile on my lips. Bert Gunter Genentech Nonclinical Biostatistics ... You should really get into the habit of reading documentation; it can often turn out to be very useful. -Deepayan Sarkar __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] selecting and excluding files through a pattern
Hi Maura, Try list.files(pattern = 'csv') HTH, Jorge On Thu, Jun 10, 2010 at 11:24 AM, <> wrote: > I have the following files list: > > > list.files() > [1] "Prostate-Cancer_cvs_Dir" > [2] "Prostate_Cancer-miRNAs&Genes.Pathway.xml" > [3] "Prostate_Cancer_Pathways-miRNAs-GeneTargets-Dir" > [4] "Prostate_Cancer_Pathways-miRNAs-GeneTargets-Dir.zip" > [5] "Prostate-miRNAs.OrganTargets.txt" > [6] "Prostate_Organ-miRNAs-GenesTargets-Dir" > [7] "Prostate_Organ-miRNAs-GenesTargets-Dir.zip" > [8] "Prostate_Organ-miRNAs-Targets.xml" > [9] "Prostatic_Neoplasm-miRNAs.DiseaseTargets.csv-KO" > [10] "Prostatic_Neoplasm-miRNAs.DiseaseTargets.txt" > [11] "Prostatic_Neoplasms-miRNAs-GeneTargets-Dir" > [12] "Prostatic_Neoplasms-miRNAs-GeneTargets-Dir.zip" > [13] "Prostatic_Neoplasms-miRNAs.xml" > > I'd like to find the pattern expression which selects only the directories > excluding the one whose > pathname contains "csv". > I tried: > > list.files(pattern="Prostate*Dir") > But I do not know how to exclude the names containing the string "csv" at > the same time. > > Thank you for any help, > Maura > > > > > ; > > > tutti i telefonini TIM! > > >[[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Latex: Date Format conversion
On Jun 10, 2010, at 10:21 AM, Felipe Carrillo wrote: > Hi: > Can't find a way to convert from shortDate to LongDate format. I got: > 3/10/10 that I want to convert to March 10, 2010. I am using: > > \documentclass[11pt]{article} > \usepackage{longtable,verbatim} > \usepackage{ctable} > \usepackage{datetime} > \title{my title} > \begin{document} > % Convert date > \dddate\3/10/10 > end{document} > > My report is changing every two weeks so I will eventually > use \Sexpr{report[1,1]} to grab the date from column 1, row 1 > of a table named "report" but right now my report has the date > formated as described above (3/10/10). Felipe, Do you want the report to be dated for the day that it is processed by latex? If so, just use: \today to generate the current date at run time in the long format that you have above. HTH, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Problems with BRugs
Hello, I am trying to run some examples from the book of P.Congdon. If I run the following script # Program 7.2 Bayesian Statistical Modelling - Peter Congdon # library(R2WinBUGS) setwd("c:/temp/R") mo <- function() { rho ~ dbeta(1,1) th ~ dgamma(0.001,0.001) Y[1] ~ dpois(th) for (t in 2:14) {Y[t] ~ dpois(mu[t]) for (k in 1:Y[t-1]+1) {B[k,t] ~ dbern(rho)} B.s[t] <- sum(B[1:Y[t-1]+1,t])-B[1,t] mu[t] <- B.s[t] +th*(1-rho)} } write.model(mo,con="test.bug") Data <- list(Y=c(0,1,2,3,1,4,9,18,23,31,20,25,37,45)) Inits <- function() { list(rho=0.8,th=5) } Parameters <- c("rho","mu") # p1.sim <- bugs(model.file="test.bug", Data, Inits, n.chains=1, Parameters, n.burnin = 1000, n.iter = 1, n.thin=2, program="WinBUGS", bugs.directory=Sys.getenv("DirWinBUGS") ) # and this works OK given answers similar to the book But changing library to BRugs, write.model to witeModel and the call to > # > p1.sim <- BRugsFit("test.bug", +Data, +Inits, +numChains=1, +Parameters, +nBurnin = 1000, +nIter = 1, +nThin=2 + ) I get : model is syntactically correct data loaded model compiled [1] "C:\\Users\\User\\AppData\\Local\\Temp\\RtmphLlekC/inits1.txt" Initializing chain 1: initial values loaded but this or another chain contain uninitialized variables model must be initialized before updating can not calculate deviance for this model Error in samplesSet(parametersToSave) : model must be initialized before monitors used > # I tried several forms of the Inits and it does not work Can somebody tell me where is the mistake I am making? Thanks for any help Heberto Ghezzo Montreal __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] levelplot and contour lines
Hello list, Is there a way to add contour lines to a levelplot at different breakpoints than are used for the colors? For example: library(lattice) # colors good but too many contours levelplot(volcano, at=94:195, contour=TRUE) # I thought something like this might work levelplot(volcano, panel=function(...) { panel.levelplot(..., at=94:195) panel.contourplot(..., at=c(100, 125, 150)) }) Thanks, Richard -- UMass Amherst Natural Resources Conservation __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Odp: adding column of ordered numbers to matrix
Hi r-help-boun...@r-project.org napsal dne 10.06.2010 15:56:06: > Hello everyone, > > I have a matrix of over 4 line and about 30 columns. Matrix or data.frame? > > For my analysis I would like to add another column with ascending numbers > (column header should be "order", and than 1,2,3,4 the end of the > matrix). If data frame DF DF$order <- 1:nrow(DF) in case of matrix mat mat <- cbind(mat, "order"=1:nrow(mat)) Regards Petr PS. order is built in function so it is not especially wise to use it as a name for some object/column > During my analysis I reorder them ( due to merge commands by a different > column). > > How do I add such a column in an ascending order (or descending for what it > matters)? > > THX > > Assa > >[[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] lattice: how to remove ticks from splom()?
It gets my vote. -Peter Ehlers On 2010-06-10 9:30, Bert Gunter wrote: Is the quote below from Deepayan a possible Fortune? It put a sardonic smile on my lips. Bert Gunter Genentech Nonclinical Biostatistics ... You should really get into the habit of reading documentation; it can often turn out to be very useful. -Deepayan Sarkar __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [R[ dates on zoo objects
Its best to use dput when displaying your data in r-help as in dput(z) or dput(head(z)) if large. Try this: > library(zoo) > # test data > z <- zoo(1:2, factor(c("04/16/09","04/17/09"))) > > # 1 > aggregate(z, function(x) as.Date(x, "%m/%d/%y")) 2009-04-16 2009-04-17 1 2 > > # or #2 > time(z) <- as.Date(time(z), "%m/%d/%y") > z 2009-04-16 2009-04-17 1 2 On Thu, Jun 10, 2010 at 9:42 AM, Erin Hodgess wrote: > Dear R People: > > I have a zoo object with its date index as a factor. > >> xAle1.zoo$index > Error in xAle1.zoo$index : $ operator is invalid for atomic vectors >> str(xAle1.zoo) > Class 'zoo' atomic [1:32] 1253 1316 1038 1157 1710 1489 1159 1142 945 1245 > ... > ..- attr(*, "index")= Factor w/ 32 levels "04/16/09","04/17/09",..: > 1 2 3 4 5 6 7 8 9 10 ... >> > > > > How do I change that over to dates, please? > > Thanks, > Erin > > > -- > Erin Hodgess > Associate Professor > Department of Computer and Mathematical Sciences > University of Houston - Downtown > mailto: erinm.hodg...@gmail.com > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] do faster ANOVAS
Dear all R users, I want to realize 800 000 ANOVAS and to store Sum of Squares of the effects. Here is an extract of my table data Product attribute subject rep t1 t2 t3 ⦠t101 P1 A1 S1 R1 1 0 0 ⦠1 I want to realize 1 ANOVA per timepoint and per attribute, there are 101 timepoints and 8 attributes so I want to realize 808 ANOVAS. This will be an ANOVA with two factors : Here is one example: Aov(t1~Subject*Product,data[data$attribute==âA1â,]) I want to store for each ANOVA SSprod,SSsujet,SSerreur,SSinter and SStotal. In fact I want the result in several matrices: Ssprod matrice: T1 t2 t3 t4 ⦠t101 A1 ssprod(A1,T1) A2 A3 ⦠A8 So I would like a matrice like that for ssprod, ssujet,sserreur,ssinter and sstotal. And this is for one permutation, and I want to do 1000 permutations Here is my code: SSmatrixglobal<-function(k){ daten.temp<-data daten.temp$product=permutations[[k]] listmat<-apply(daten.temp[,5:105],2,function(x,y){ tab2<-as.data.frame(cbind(x,y)) tab.class<-by(tab2[,1:3],tab2[,4],function(x){ f <- formula(paste(names(x)[1],"~",names(x)[2],"*",names(x)[3],sep="")) anovas <- aov(f, data=x) anovas$call$formula <-f s1 <- summary(anovas) qa <- s1[[1]][,2] return(qa) }) return(tab.class) },y=daten.temp[,1:3] ) ar <- array(unlist(listmat),dim=c(length(listmat[[1]][[1]]),length(listmat[[1]]),length(listmat))) l=lapply(1:4,function(i) ar[i,,]) sssujet=l[[1]] ssprod=l[[2]] ssinter=l[[3]] sserreur=l[[4]] ss=rbind(sssujet,ssprod,ssinter,sserreur,sstotal) ss=as.data.frame(ss) sqlSave(channel,ss,"SS1000",append=T) rm(ss,numperm,daten.temp) } system.time(por <- lapply(c(1:1000), SSmatrixglobal)) But it takes time about 90seconds for a permutation so *1000, how can I do in order to do faster ANOVAS? Many thanks Best regards Mélissa PS: I think that I can gain a lot of time in the aov function but I don't know how to do [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] HOW to install RSQLite database
Please let me know where i have to type below thing to RSQLite database get installed.Please let me know the solution.Thanks in advance RSQLite -- Embedding the SQLite engine in R (The RSQLite package includes a recent copy of the SQLite distribution from http://www.sqlite.org.) Installation There are 3 alternatives for installation: 1. Simple installation: R CMD INSTALL RSQLite-.tar.gz the installation automatically detects whether SQLite is available in any of your system directories; if it's not available, it installs the SQLite engine and the R-SQLite interface under the package directory $R_PACKAGE_DIR/sqlite. 2. If you have SQLite installed in a non-system directory (e.g, in $HOME/sqlite), a) You can use export PKG_LIBS="-L$HOME/sqlite/lib -lsqlite" export PKG_CPPFLAGS="-I$HOME/sqlite/include" R CMD INSTALL RSQLite-.tar.gz b) or you can use the --with-sqlite-dir configuration argument R CMD INSTALL --configure-args=--with-sqlite-dir=$HOME/sqlite \ RSQLite-.tar.gz 3. If you don't have SQLite but you rather install the version we provide into a directory different than the RSQLite package, for instance, $HOME/app/sqlite, use R CMD INSTALL --configure-args=--enable-sqlite=$HOME/app/sqlite \ RSQLite-.tar.gz Usage - Note that if you use an *existing* SQLite library that resides in a non-system directory (e.g., other than /lib, /usr/lib, /usr/local/lib) you may need to include it in our LD_LIBRARY_PATH, prior to invoking R. For instance export LD_LIBRARY_PATH=$HOME/sqlite/lib:$LD_LIBRARY_PATH R > library(help=RSQLite) > library(RSQLite) (if you use the --enable-sqlite=DIR configuration argument, the SQLite library is statically linked to the RSQLite R package, and you need not worry about setting LD_LIBRARY_PATH.) -- View this message in context: http://r.789695.n4.nabble.com/HOW-to-install-RSQLite-database-tp2250604p2250604.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Finding distance matrix for categorical data
All, How can we find a distance matrix for categorical data ie. given a csv below var1 var2var3var4 element1-1 yesx a k element1-2 no y b l element1-3 maybe y c m how can i compute the distance matrix between all the elements Actually i need it to create clusters on top of it Thanks & Regards Kapil [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] calibration and validation for svycoxph
You don't say what you mean by validation and calibration of the model (these terms have multiple meanings) but if you mean looking at how good the prediction is, all the raw materials are available through svykm() and the predict() method for svycoxph(). There aren't any predefined functions like the ones Frank Harrell provides, though. Incidentally, sending two messages in quick succession like this is not a good strategy for getting help. -thomas On Wed, 9 Jun 2010, R user wrote: Hello, This post is for Dr. Thomas Lumley or anybody familiar with the survey package. I am estimating a proportional hazards model with weights using svycoxph. Are there functions already built in the survey package that allow me to do validation and calibration of the model? Thanks -- View this message in context: http://r.789695.n4.nabble.com/calibration-and-validation-for-svycoxph-tp2249118p2249118.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] coxph and completely missing strata/subsetting
Hi everyone, I'm doing some coxph() analyses with a large and complex dataset. The data was collected in different centers, so I am using strata(centers) to stratify the analysis. My main issue is, not all centers collected all the variables, so for a model such as: coxph(Surv(days, cancer) ~ varA + sex + strata(centers), data) I might have 1 or more centers that have NA for varA (in practice, all the individuals monitored at those centers come without varA). coxph() obviously warns me that a number of individuals have been excluded -- would that be equivalent to doing the analysis on a subset of the data or not? I ask because I have many centers and many variables, and if the automatic exclusion of individuals missing the variable in analysis *is not* equivalent to subsetting I might have some serious work to do. Best, Federico -- Federico C. F. Calboli Department of Epidemiology and Biostatistics Imperial College, St. Mary's Campus Norfolk Place, London W2 1PG Tel +44 (0)20 75941602 Fax +44 (0)20 75943193 f.calboli [.a.t] imperial.ac.uk f.calboli [.a.t] gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] coxph and completely missing strata/subsetting
I'm doing some coxph() analyses with a large and complex dataset. The data was collected in different centers, so I am using strata(centers) to stratify the analysis. My main issue is, not all centers collected all the variables, so for a model such as: coxph(Surv(days, cancer) ~ varA + sex + strata(centers), data) I might have 1 or more centers that have NA for varA (in practice, all the individuals monitored at those centers come without varA). coxph() obviously warns me that a number of individuals have been excluded -- would that be equivalent to doing the analysis on a subset of the data or not? It seems so by definition to me. I am confused as to what else would be happening. You can always create a smaller, easier to understand dataset and try things out for yourself. Perhaps I do not understand your question though. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Latex: Date Format conversion
Marc: My report is done every two weeks and is created automatically. I click a command button on an Excel form and it runs a .rnw script in R creating a latex dynamic report. Excel sends 15 days of data to R, eg: 6/1/10 to 6/15/10. Right above my report I usually write the range of the report manually, something like "Report from 6/1/10 - 6/15/10" so I want to see if latex can select that range of dates dynamically because my report dates are constantly changing. I would like latex to look at the beginning and last date of my report and fill out the dates on the fly. I can do this easily with the following: Report from \Sexpr{report[1,1]} & - & \Sexpr{report[1,15]} and it prints the correct values: Report from 6/1/10 - 6/15/10 But I want those values formatted like this: Report from June 01, 2010 - June 15, 2010 I am looking for a latex command to convert the dates, something like this pseudo-code: Report from \longdate\Sexpr{report[1,1]} & - & \longdate\Sexpr{report[1,15]} Where long date will be the format that converts 6/1/10 to June 01, 2010 Thanks for helping. - Original Message > From: Marc Schwartz > To: Felipe Carrillo > Cc: r-h...@stat.math.ethz.ch > Sent: Thu, June 10, 2010 8:40:16 AM > Subject: Re: [R] Latex: Date Format conversion > > On Jun 10, 2010, at 10:21 AM, Felipe Carrillo wrote: > Hi: > > Can't find a way to convert from shortDate to LongDate format. I got: > > 3/10/10 that I want to convert to March 10, 2010. I am using: > > > \documentclass[11pt]{article} > \usepackage{longtable,verbatim} > > \usepackage{ctable} > \usepackage{datetime} > \title{my > title} > \begin{document} > % Convert date > > \dddate\3/10/10 > end{document} > > My report is > changing every two weeks so I will eventually > use \Sexpr{report[1,1]} > to grab the date from column 1, row 1 > of a table named "report" but > right now my report has the date > formated as described above > (3/10/10). Felipe, Do you want the report to be dated for the day > that it is processed by latex? If so, just use: > \today to generate the current date at run time in the long format that > you have above. HTH, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] do faster ANOVAS
The lm and aov functions can take a matrix response allowing you to fit all of the responses for a single attribute simultaneously. On Thu, Jun 10, 2010 at 8:47 AM, melissa wrote: > Dear all R users, > I want to realize 800 000 ANOVAS and to store Sum of Squares of the effects. > Here is an extract of my table data > Product attribute subject rep t1 t2 t3 … t101 > P1 A1 S1 R1 1 0 0 … 1 > I want to realize 1 ANOVA per timepoint and per attribute, there are 101 > timepoints and 8 attributes so I want to realize 808 ANOVAS. This will be an > ANOVA with two factors : > Here is one example: > Aov(t1~Subject*Product,data[data$attribute==”A1”,]) > I want to store for each ANOVA SSprod,SSsujet,SSerreur,SSinter and SStotal. > In fact I want the result in several matrices: > Ssprod matrice: > T1 t2 t3 t4 … t101 > A1 ssprod(A1,T1) > A2 > A3 > … > A8 > So I would like a matrice like that for ssprod, ssujet,sserreur,ssinter and > sstotal. > And this is for one permutation, and I want to do 1000 permutations > Here is my code: > SSmatrixglobal<-function(k){ > > daten.temp<-data > daten.temp$product=permutations[[k]] > listmat<-apply(daten.temp[,5:105],2,function(x,y){ > tab2<-as.data.frame(cbind(x,y)) > tab.class<-by(tab2[,1:3],tab2[,4],function(x){ > f <- formula(paste(names(x)[1],"~",names(x)[2],"*",names(x)[3],sep="")) > anovas <- aov(f, data=x) > anovas$call$formula <-f > s1 <- summary(anovas) > qa <- s1[[1]][,2] > return(qa) > }) > return(tab.class) > },y=daten.temp[,1:3] > ) > ar <- > array(unlist(listmat),dim=c(length(listmat[[1]][[1]]),length(listmat[[1]]),length(listmat))) > l=lapply(1:4,function(i) ar[i,,]) > sssujet=l[[1]] > ssprod=l[[2]] > ssinter=l[[3]] > sserreur=l[[4]] > ss=rbind(sssujet,ssprod,ssinter,sserreur,sstotal) > ss=as.data.frame(ss) > sqlSave(channel,ss,"SS1000",append=T) > rm(ss,numperm,daten.temp) > } > > system.time(por <- lapply(c(1:1000), SSmatrixglobal)) > > But it takes time about 90seconds for a permutation so *1000, how can I do in > order to do faster ANOVAS? > > Many thanks > Best regards > Mélissa > > PS: I think that I can gain a lot of time in the aov function but I don't > know how to do > [[alternative HTML version deleted]] > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Finding distance matrix for categorical data
see ?daisy in the library cluster Cheers Joris On Thu, Jun 10, 2010 at 6:12 PM, kapil mahant wrote: > All, > > How can we find a distance matrix for categorical data > > ie. given a csv below > > var1 var2 var3 var4 > element1-1 yes x a k > element1-2 no y b l > element1-3 maybe y c m > > how can i compute the distance matrix between all the elements > > Actually i need it to create clusters on top of it > > Thanks & Regards > Kapil > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Finding distance matrix for categorical data
correction. See ?daisy in the PACKAGE cluster. *slaps head* cheers Joris On Thu, Jun 10, 2010 at 7:02 PM, Joris Meys wrote: > see ?daisy in the library cluster > > Cheers > Joris > > On Thu, Jun 10, 2010 at 6:12 PM, kapil mahant wrote: >> All, >> >> How can we find a distance matrix for categorical data >> >> ie. given a csv below >> >> var1 var2 var3 var4 >> element1-1 yes x a k >> element1-2 no y b l >> element1-3 maybe y c m >> >> how can i compute the distance matrix between all the elements >> >> Actually i need it to create clusters on top of it >> >> Thanks & Regards >> Kapil >> >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > > > -- > Joris Meys > Statistical consultant > > Ghent University > Faculty of Bioscience Engineering > Department of Applied mathematics, biometrics and process control > > tel : +32 9 264 59 87 > joris.m...@ugent.be > --- > Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php > -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 joris.m...@ugent.be --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Latex: Date Format conversion
Felipe, I would not do the processing in TeX, but do it in R and then pass the results to the \Sexpr{}'s. If I am correctly understanding the process flow, put the following R code chunk before the point where you need to output the formatted dates: <> START <- format(as.Date(report[1, 1], "%m/%d/%y"), "%B %d, %Y") END <- format(as.Date(report[1, 15], "%m/%d/%y"), "%B %d, %Y") @ Then have the following in the document body: Report from \Sexpr{START} & - & \Sexpr{END]} To take an example of your two dates below: > format(as.Date("6/1/10", "%m/%d/%y"), "%B %d, %Y") [1] "June 01, 2010" > format(as.Date("6/15/10", "%m/%d/%y"), "%B %d, %Y") [1] "June 15, 2010" See ?as.Date for more information. Note, that one possible complication is that if the dates in Excel are stored as dates and not as text, that is they are exported as numbers to R, pay close attention to the last example in ?as.Date. If this is the case, then you will need to modify the R code chunk above as per the examples on the help page, to correctly convert the numbers to R's date type and then format the result as you desire. HTH, Marc On Jun 10, 2010, at 11:37 AM, Felipe Carrillo wrote: > > Marc: > My report is done every two weeks and is created automatically. > I click a command button on an Excel form and it runs a .rnw script > in R creating a latex dynamic report. Excel sends 15 days of data > to R, eg: 6/1/10 to 6/15/10. Right above my report I usually write the range > of the report manually, something like "Report from 6/1/10 - 6/15/10" so > I want to see if latex can select that range of dates dynamically because my > report dates are constantly changing. I would like latex to look at the > beginning > and last date of my report and fill out the dates on the fly. I can do this > easily with > the following: > Report from \Sexpr{report[1,1]} & - & \Sexpr{report[1,15]} > and it prints the correct values: > Report from 6/1/10 - 6/15/10 > But I want those values formatted like this: > Report from June 01, 2010 - June 15, 2010 > I am looking for a latex command to convert the dates, something like this > pseudo-code: > Report from \longdate\Sexpr{report[1,1]} & - & \longdate\Sexpr{report[1,15]} > Where long date will be the format that converts 6/1/10 to June 01, 2010 > Thanks for helping. > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Latex: Date Format conversion
Marc: Thanks for reinforcing that, I was just trying to go that route. It seems to be simpler to import the dataset and just grab the first and last date from it and then format it. Thanks again. Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish & Wildlife Service California, USA - Original Message > From: Marc Schwartz > To: Felipe Carrillo > Cc: r-h...@stat.math.ethz.ch > Sent: Thu, June 10, 2010 10:19:40 AM > Subject: Re: [R] Latex: Date Format conversion > > Felipe, I would not do the processing in TeX, but do it in R and then > pass the results to the \Sexpr{}'s. If I am correctly understanding the > process flow, put the following R code chunk before the point where you need > to > output the formatted dates: <> > START <- format(as.Date(report[1, 1], "%m/%d/%y"), "%B %d, %Y") END > <- format(as.Date(report[1, 15], "%m/%d/%y"), "%B %d, > %Y") @ Then have the following in the document body: > Report from \Sexpr{START} & - & \Sexpr{END]} To take an > example of your two dates below: > format(as.Date("6/1/10", > "%m/%d/%y"), "%B %d, %Y") [1] "June 01, 2010" > > format(as.Date("6/15/10", "%m/%d/%y"), "%B %d, %Y") [1] "June 15, > 2010" See ?as.Date for more information. Note, that one > possible complication is that if the dates in Excel are stored as dates and > not > as text, that is they are exported as numbers to R, pay close attention to > the > last example in ?as.Date. If this is the case, then you will need to modify > the > R code chunk above as per the examples on the help page, to correctly convert > the numbers to R's date type and then format the result as you > desire. HTH, Marc On Jun 10, 2010, at 11:37 AM, Felipe > Carrillo wrote: > > Marc: > My report is done every > two weeks and is created automatically. > I click a command button on an > Excel form and it runs a .rnw script > in R creating a latex dynamic > report. Excel sends 15 days of data > to R, eg: 6/1/10 to 6/15/10. Right > above my report I usually write the range > of the report manually, > something like "Report from 6/1/10 - 6/15/10" so > I want to see if latex > can select that range of dates dynamically because my > report dates are > constantly changing. I would like latex to look at the beginning > and > last date of my report and fill out the dates on the fly. I can do this > easily > with > the following: > Report from \Sexpr{report[1,1]} & - > & \Sexpr{report[1,15]} > and it prints the correct values: > > Report from 6/1/10 - 6/15/10 > But I want those values formatted like > this: > Report from June 01, 2010 - June 15, 2010 > I am looking for > a latex command to convert the dates, something like this pseudo-code: > > Report from \longdate\Sexpr{report[1,1]} & - & > \longdate\Sexpr{report[1,15]} > Where long date will be the format that > converts 6/1/10 to June 01, 2010 > Thanks for helping. > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Latex: Date Format conversion
On Jun 10, 2010, at 12:19 PM, Marc Schwartz wrote: > Felipe, > > I would not do the processing in TeX, but do it in R and then pass the > results to the \Sexpr{}'s. > > If I am correctly understanding the process flow, put the following R code > chunk before the point where you need to output the formatted dates: > > <> > > START <- format(as.Date(report[1, 1], "%m/%d/%y"), "%B %d, %Y") > END <- format(as.Date(report[1, 15], "%m/%d/%y"), "%B %d, %Y") > > @ > > > Then have the following in the document body: > > Report from \Sexpr{START} & - & \Sexpr{END]} Quick correction, just noted a typo with the ']' in the second \Sexpr{}. That should be: Report from \Sexpr{START} & - & \Sexpr{END} Marc __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] adding column of ordered numbers to matrix
> newmat <- cbind( oldmat, order=seq(nrow(oldmat)) ) See ?seq and/or ?rev for descending. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Assa Yeroslaviz > Sent: Thursday, June 10, 2010 7:56 AM > To: r-h...@stat.math.ethz.ch > Subject: [R] adding column of ordered numbers to matrix > > Hello everyone, > > I have a matrix of over 4 line and about 30 columns. > > For my analysis I would like to add another column with ascending > numbers > (column header should be "order", and than 1,2,3,4 the end of the > matrix). > During my analysis I reorder them ( due to merge commands by a > different > column). > > How do I add such a column in an ascending order (or descending for > what it > matters)? > > THX > > Assa > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] points marking
Your question is not really clear, do either of these examples do what you want? with(anscombe, plot(x1, y2, ylim=range(y2,y3)) ) with(anscombe, points(x1, y3, col='blue', pch=2) ) with(anscombe, segments(x1, y2, x1, y3, col=ifelse( y2>y3, 'green','red') ) ) with(anscombe, plot(x1, y2, ylim=range(y2,y3), type='n') ) with(anscombe[order(anscombe$x1),], polygon( c( x1,rev(x1) ), c(y2, rev(y3)), col='grey' ) ) -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of khush > Sent: Thursday, June 10, 2010 7:48 AM > To: r-help@r-project.org > Subject: [R] points marking > > Hi, > > How to mark points on x axis of a graph keeping x axis as constant and > changing y from y1 to y2 respectively. I want to highlight the area > from y1 > to y2. > > Any suggestions > > Thank you > Jeet > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] levelplot and contour lines
On Thu, Jun 10, 2010 at 9:30 PM, wrote: > Hello list, > > Is there a way to add contour lines to a levelplot at different breakpoints > than are used for the colors? For example: > > > library(lattice) > > # colors good but too many contours > levelplot(volcano, at=94:195, contour=TRUE) > > # I thought something like this might work > levelplot(volcano, > panel=function(...) { > panel.levelplot(..., at=94:195) > panel.contourplot(..., at=c(100, 125, 150)) > }) Something like that does work, you just need to capture and modify the relevant arguments: levelplot(volcano, panel=function(..., at, contour, region) { panel.levelplot(..., at=94:195, contour = FALSE, region = TRUE) panel.contourplot(..., at=c(100, 125, 150), contour = TRUE, region = FALSE) }) Unless you capture the arguments explicitly, they get supplied to panel.contourplot etc. twice, once when you explicitly specify it, and once as part of the ...-s. -Deepayan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] nls model fitting errors
On 2010-06-10 8:27, Graves, Gregory wrote: What am I failing to understand here? Several things; see below. The script below works fine if the dataset being used is DNase1<- DNase[ DNase$Run == 1, ] per the example given in help(nlrob). Obviously, I am trying to understand how to use nls and nlrob to fit curves to data using R. #package=DAAG attach(codling) plot(pobs~dose) #next command returns 'step factor reduced below min factor error' m.nls<- nls( pobs ~ a/(1 + exp(( b - log(dose) )/c ) ), data = codling, start = list( a = 3, b = 0, c = 1 ), trace = TRUE ) s<-seq(min(pobs), max(pobs), .01) If pobs is your y-value (response) then what is 's' for? p.nls<-predict(m.nls,list(pobs=s)) Ah, you want predicted *response* values; so feed appropriate *predictor* values to predict(). But I don't see how this would not give you an error anyway if your nls() call resulted in an error. lines(s,p.nls,col='blue') #generates 'x and y lengths differ' error This error would result from incorrectly generating p.nls, (but I don't see how you got R to give you that anyway). I have 4 suggestions: 1. Define a new variable ldose=log(dose); It's usually less confusing to work on the log-scale in these cases. Then plot pobs vs ldose. 2. From the plot you should notice that the left asymptote is not likely to be zero (which is what your model assumes). It's roughly 0.2. 3. The right asymptote should probably be 1.0 since pobs is a proportion. So a start value of a=3 in your model makes no sense as you would also quickly see if you plotted the curve represented by your model on the plot of the data (use: curve(...,add=TRUE)). 4. Try this model: pobs ~ (A + exp((ldose - B)/C)) / (1 + exp((ldose - B)/C)) with starting values: A = 0.2, B = 3, C = 1 -Peter Ehlers Gregory A. Graves, Lead Scientist Everglades REstoration COoordination and VERification (RECOVER) Restoration Sciences Department South Florida Water Management District Phones: DESK: 561 / 682 - 2429 CELL: 561 / 719 - 8157 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.