[R] drawing dot plots with size, shape affecting dot characteristics
Hi all, I'm interested in doing a dot plot where *both* the size and color (more specifically, shade of grey) change with the associated value. I've found examples online for ggplot2 where you can scale the size of the dot with a value: http://had.co.nz/ggplot2/graphics/6a053f23cf5bdfe5155ab53d345a5e0b.png Or scale the color with the value: http://had.co.nz/ggplot2/graphics/b17bf93530ff6695afb366e65677c17f.png both of which are from here: http://had.co.nz/ggplot2/geom_point.html but I've been playing around with ggplot2 and couldn't figure out how to do both at the same time - ideally i want size to increase with a value, and the shade of grey to get lighter with increasing value. Any help's appreciated, thanks! Brian [[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] using functions with multiple arguments in the apply family
I can actually answer this!! I was trying to figure out how to use sapply for a function I wrote with multiple arguments. Suppose the function is called FUN(a,b), where a is a number and b is a number You can use mapply(FUN, a = VECTOR, b = VECTOR) where each vector is your input arguments. It will output a vector or a matrix (depending on the output of your function). This will also work: mapply(FUN, a = VECTOR, b = NUMBER) and will apply your function with each element of a but the same argument for b each time. Let me know if it works! -- View this message in context: http://r.789695.n4.nabble.com/using-functions-with-multiple-arguments-in-the-apply-family-tp1312027p2322067.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 dot plots with size, shape affecting dot characteristics
Try running this and see if it does what you want. It just uses plain old plot with the cex arg for size and the col arg for colour... greyDots - function() { # make up some data x - runif(50, 0, 10) y - runif(50, 0, 10) valueMax - 100 value - sample(valueMax, 50) # edit these to taste maxDotSize - 5 maxGreyLevel - 0.8 plot(x, y, pch=16, xlim=c(0,10), ylim=c(0,10), cex=maxDotSize * value / valueMax, col=grey(maxGreyLevel * value / valueMax)) } On 12 August 2010 13:14, Brian Tsai btsa...@gmail.com wrote: Hi all, I'm interested in doing a dot plot where *both* the size and color (more specifically, shade of grey) change with the associated value. __ 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] Derivative
This following works for me but I still favor the quick and dirty method suggested originally by David. options(scipen = 10) x - seq(0,2, by = .01) f - expression(5*cos(2*x)-2*x*sin(2*x)) D(f, 'x') f.prime - function(x){ -(5 * (sin(2 * x) * 2) + (2 * sin(2 * x) + 2 * x * (cos(2 * x) * 2))) } curve(expr = f.prime, from = 1, to = 2, n = 101) uniroot(f = f.prime, interval = c(1,2), tol = .1) On Aug 11, 2010, at 10:56 PM, David Winsemius wrote: On Aug 12, 2010, at 12:49 AM, Dennis Murphy wrote: Hi: Try the following: f - function(x) 5*cos(2*x)-2*x*sin(2*x) curve(f, -5, 5) abline(0, 0, lty = 'dotted') This shows rather clearly that your function has multiple roots, which isn't surprising given that it's a linear combination of sines and cosines. To find a specific root numerically, use function uniroot on f, as follows: uniroot(f, c(0, 2)) Except he was asking for the root of the derivative. If the classroom assignment allows use of R's limited symbolic differentiation you could try: df.dx - D(expression(5*cos(2*x)-2*x*sin(2*x)), x) df.dx -(5 * (sin(2 * x) * 2) + (2 * sin(2 * x) + 2 * x * (cos(2 * x) * 2))) (Which as one of the examples in the deriv help page notes is not the most simple form.) I was assuming that the OP wanted a solution to: d( abs(f(x)) )/dt = 0 in the domain [1,2] So: f.df.dx - function (x) { eval(parse(text=D(expression(5*cos(2*x)-2*x*sin(2*x)), x) ) ) } # no abs() but we should be satisfied with either a minimum or a maximum uniroot(f.df.dx, c(1,2) ) $root [1] 1.958218267 $f.root [1] 1.138013788e-05 $iter [1] 4 $estim.prec [1] 6.103515625e-05 It doesn't agree with my earlier method and I think this one has a greater probablity of being correct. I don't think I needed to take second differences. -- David. $root [1] 0.6569286 $f.root [1] -0.0001196119 $iter [1] 6 $estim.prec [1] 6.103516e-05 This catches the root that lies between x = 0 and x = 2. If you want to find a set of roots, you can try a loop. Fortunately, since the function is even, you really only need to find the roots on one side of zero, since the ones on the other side are the same with opposite sign. lo - seq(0, 4.5, by = 1.5) hi - seq(1.5, 6, by = 1.5) roots - numeric(length(lo)) for(i in seq_along(lo)) roots[i] - uniroot(f, c(lo[i], hi[i]))$root roots See ?uniroot for other options and tolerance settings. HTH, Dennis On Wed, Aug 11, 2010 at 6:21 PM, TGS cran.questi...@gmail.com wrote: How would I numerically find the x value where the derivative of the function below is zero? x - seq(1,2, by = .01) y - 5*cos(2*x)-2*x*sin(2*x) plot(x,abs(y), type = l, ylab = |y|) -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Odp: Running something without a loop when the result from the previous iteration is require for the current iteration
Hi without toy example it is rather complicated to check your function. So only few remarks: Instead of generating 1 random number inside a loop generate whole vector of random numbers outside a loop and choose a number Do not mix ifelse with if. ifelse is intended to work with whole vector. Work with matrices instead of data frames whenever possible if speed is an issue. If I understand correctly you want to put 1 or 0 into one column based on: previous value in the same column comparison of some random number with predefined probabilities in vector of 6 values So here is vectorised version of your 4 ifs based on assumption 0 in col1 0 in col 2 = 5 0 in col1 1 in col 2 = 9 1 in col1 0 in col 2 = 6 1 in col1 1 in col 2 =10 col1-sample(1:2, 20, replace=T) col2-sample(c(4,8), 20, replace=T) col1+col2 [1] 5 6 9 6 6 5 9 10 9 9 6 9 10 6 10 9 10 9 5 5 cols-as.numeric(as.factor(col1+col2)) cols [1] 1 2 3 2 2 1 3 4 3 3 2 3 4 2 4 3 4 3 1 1 And here is computed comparison of six values p (ortho obs used) with 20 generated random values ran-runif(20) p-runif(8) comparison - outer(ran,p, ) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [2,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE [3,] FALSE TRUE FALSE TRUE FALSE TRUE TRUE FALSE [4,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE [5,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE [6,] FALSE TRUE FALSE TRUE FALSE TRUE FALSE FALSE [7,] FALSE TRUE FALSE TRUE FALSE TRUE FALSE FALSE [8,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [9,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [10,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE [11,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE [12,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [13,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE [14,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [15,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [16,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [17,] FALSE TRUE FALSE TRUE FALSE TRUE FALSE FALSE [18,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [19,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [20,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE Now the only what you need to put in loop is to select appropriate column from matrix comparison based on value on cols vector and 0 or 1 in previous row of station column. Something like (untested) gen.log-rep(NA, nrow(genmat)-1) for (i in 2:nrow(genmat)) { gen.log[i] - if( genmat[i-1, num] ==0) comparison[i, cols[i]] else comparison[i,cols[i+5]] } genmat[2:nrow(genmat), num] - gen.log*1 Regards Petr r-help-boun...@r-project.org napsal dne 11.08.2010 18:35:37: Hello Everyone! Here's what I'm trying to do. I'm working on generating occurrences of precipitation based upon precipitation occurrence for a station during the previous day and two stations that have already been generated by joint probablities and 1st order Markov chains or by the same generation process. This has to be done for each remaining stations for each month. genmat # 7 stations in this example, line_before is the climatology of the last day of the previous month. Stations 4 and 6 have been generated already in this example [,1] [,2] [,3] [,4] [,5] [,6] [,7] line_before1110111 NA NA NA1 NA0 NA NA NA NA0 NA0 NA NA NA NA0 NA0 NA NA NA NA0 NA0 NA NA NA NA0 NA0 NA NA NA NA0 NA0 NA NA NA NA0 NA0 NA NA NA NA1 NA0 NA NA NA NA1 NA1 NA NA NA NA1 NA1 NA NA NA NA0 NA0 NA NA NA NA0 NA0 NA NA NA NA1 NA1 NA NA NA NA0 NA0 NA NA NA NA0 NA0 NA NA NA NA0 NA0 NA NA NA NA0 NA0 NA NA NA NA0 NA0 NA NA NA NA1 NA1 NA NA NA NA0 NA0 NA NA NA NA1 NA1 NA NA NA NA1 NA1 NA NA NA NA1 NA1 NA NA NA NA0 NA0 NA NA NA NA0 NA1 NA NA NA NA0 NA0 NA NA NA NA0 NA0 NA NA NA NA1 NA1 NA NA NA NA1 NA1 NA NA NA NA1 NA1 NA NA NA NA0 NA0 NA num # station to generate [1] 2 use1 # 1st station to use in generation [1] 6 use2 # 2nd station to use in generation
[R] termplot for mixed linear effects models
Is there an equivalent package for mixed linear effects models developed using the package nlme as there is for linear models? Tschüß Tony Meissner Principal Scientist (Monitoring/Statistics) Resource Monitoring Science, Monitoring and Information Division Department for Water Imagine © *(ph) (08) 8595 2209 *(mob) 0401 124 971 *(fax) (08) 8595 2232 * 28 Vaughan Terrace, Berri SA 5343 PO Box 240, Berri SA 5343 DX 51103 ***The information in this e-mail may be confidential and/or legally privileged. Use or disclosure of the information by anyone other than the intended recipient is prohibited and may be unlawful. If you have received this e-mail in error, please advise by return e-mail or by telephoning +61 8 8595 2209 [[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] Where the data file is stored?
Hi folks, OS - Ubuntu 10.04 On R I create a datafile named data. I can evoke it on R with; data On R Commander Data - Active data set - Select active data set - (data) OK only one data set there data - View data set I can read it - Edit data set showing 25 rows of data. Clicking the box shows a thick border around it. But I couldn't edit the data inside the box. I wonder where this datafile is stored on the OS On Ubuntu terminal; $ locate data.rda $ locate data.image $ locate data.images $ locate data.csv all without printout. TIA B.R. Stephen L __ 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 to polish plot in ggplot2
To illustrate the second option I proposed, library(ggplot2) library(gridExtra) category - paste(Geographical Category, 1:10) grp1 - rnorm(10, mean=10, sd=10) grp2 - rnorm(10, mean=20, sd=10) grp3 - rnorm(10, mean=15, sd=10) grp4 - rnorm(10, mean=12, sd=10) mydat - data.frame(category,grp1,grp2,grp3,grp4) dat.m - melt(mydat) p - qplot(1,value, data=dat.m, geom=bar, xlab=,ylab=Percentage of eco change,stat=identity,fill=variable, position=dodge) + coord_flip()+ facet_grid(category ~ ., space=free)+scale_x_discrete(breaks=c(2,4))+opts(strip.text.y = theme_text(hjust = 0)) labs - llply(category, textGrob) ## add a blank grob below as the y title is aligned with the full ggplot2 height, ## not just the panel my.labels - do.call(arrangeGrob, c(labs, list(ncol=1, left=My y title, sub= ))) # grid.draw(my.labels) ## hack: define the width of my.labels ylab - gTree(children=gList(my.labels, rectGrob()), cl=mylabels ) widthDetails.mylabels - function(x) max(stringWidth(category)) + unit(1, line) ## hack: tweak ggplot2's axis.title.y option to use our gTree foo - function() function(label, x, y) ylab p + opts(strip.text.y =theme_blank(), strip.background=theme_blank()) + opts( axis.title.y = foo()) HTH, baptiste On 12 August 2010 07:44, baptiste auguie baptiste.aug...@googlemail.com wrote: Hi, One way you could do it is to create a separate graph for each category. The y axis labels would replace the strip labels. You could then stack the graphs on the page, and add a common legend. The tricky part would be to make sure the different panels have the same width and height. Another option might be to hack a custom Grob (gTree) for the y-axis title so that it would draw the current y-axis title and also the labels for the facets next to it. Of course you'd also get rid of the strips in this case. Best, baptiste On 11 August 2010 15:39, Mahbubul Majumder mahbu...@gmail.com wrote: Hi, I wanted to generate a plot which is almost like the plot generated by the following codes. category - paste(Geographical Category, 1:10) grp1 - rnorm(10, mean=10, sd=10) grp2 - rnorm(10, mean=20, sd=10) grp3 - rnorm(10, mean=15, sd=10) grp4 - rnorm(10, mean=12, sd=10) mydat - data.frame(category,grp1,grp2,grp3,grp4) dat.m - melt(mydat) p - qplot(1,value, data=dat.m, geom=bar, xlab=,ylab=Percentage of eco change,stat=identity,fill=variable, position=dodge) p + coord_flip()+ facet_grid(category ~ ., space=free)+scale_x_discrete(breaks=c(2,4))+opts(strip.text.y = theme_text(hjust = 0)) Now the only modification I need from this plot is that I want the grid labels (text) on the left hand side with right justification and white background. My prospective plot should have labels like the the plot generated by the codes below. The reason why I don't like the plot below is that it does not show separate grid for each category. p - qplot(category,value, data=dat.m, geom=bar, ylab=Percentage of eco change,stat=identity,fill=variable, position=dodge) p + coord_flip() Can you help me generate my vision plot? -- Mahbub Majumder Graduate Student Dept. of Statistics Iowa 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] Where the data file is stored?
By default everything in an R workspace (data objects, functions etc) will be stored in a file called .RData in the working directory. Please see http://cran.r-project.org/doc/contrib/Paradis-rdebuts_en.pdf Michael __ 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] Where the data file is stored?
On R I create a datafile named data. I can evoke it on R with; data On R Commander Data - Active data set - Select active data set - (data) OK only one data set there data - View data set I can read it - Edit data set showing 25 rows of data. Clicking the box shows a thick border around it. But I couldn't edit the data inside the box. I wonder where this datafile is stored on the OS On Ubuntu terminal; $ locate data.rda $ locate data.image $ locate data.images $ locate data.csv You dont't tell us what you did to create a datafile - to me it sounds like you created an object (probably a data frame) in your R workspace. If that's the case it is stored in a file called .RData in your current work directory (together with other variables in your workspace). If that is not what you did please give us mre information. BTW: R has a function called data and it is not a very good idea to use function names as variable names. cu Philipp -- Dr. Philipp Pagel Lehrstuhl für Genomorientierte Bioinformatik Technische Universität München Wissenschaftszentrum Weihenstephan Maximus-von-Imhof-Forum 3 85354 Freising, Germany http://webclu.bio.wzw.tum.de/~pagel/ __ 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] Where the data file is stored?
- Original Message From: Michael Bedward michael.bedw...@gmail.com To: Stephen Liu sati...@yahoo.com Cc: r-help@r-project.org Sent: Thu, August 12, 2010 3:50:12 PM Subject: Re: [R] Where the data file is stored? By default everything in an R workspace (data objects, functions etc) will be stored in a file called .RData in the working directory. Please see http://cran.r-project.org/doc/contrib/Paradis-rdebuts_en.pdf Hi Michael, Ah I see. Thanks $ locate RData /home/userA/.RData /usr/lib/R/site-library/qtl/data/badorder.RData /usr/lib/R/site-library/qtl/data/bristle3.RData /usr/lib/R/site-library/qtl/data/bristleX.RData /usr/lib/R/site-library/qtl/data/fake.4way.RData /usr/lib/R/site-library/qtl/data/fake.bc.RData /usr/lib/R/site-library/qtl/data/fake.f2.RData /usr/lib/R/site-library/qtl/data/hyper.RData /usr/lib/R/site-library/qtl/data/listeria.RData /usr/lib/R/site-library/qtl/data/map10.RData I left out following step; write.csv(data, petdrug.csv) q() without saving. $ locate petdrug.csv /home/userA/petdrug.csv petdrug.csv can be read on OpenOffice Calc and edited there. B.R. Stephen L __ 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] Where the data file is stored?
- Original Message From: Philipp Pagel p.pa...@wzw.tum.de To: r-help@r-project.org Sent: Thu, August 12, 2010 3:54:53 PM Subject: Re: [R] Where the data file is stored? You dont't tell us what you did to create a datafile - to me it sounds like you created an object (probably a data frame) in your R workspace. If that's the case it is stored in a file called .RData in your current work directory (together with other variables in your workspace). If that is not what you did please give us mre information. Hi Philipp, Yes, it is data frame. I have run the step write.csv ... Other advice noted. Thanks B.R. Stephen L __ 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] Where the data file is stored?
Hi, You can find your current working directory with the getwd() function. Alain On 12-Aug-10 11:22, Stephen Liu wrote: - Original Message From: Philipp Pagelp.pa...@wzw.tum.de To: r-help@r-project.org Sent: Thu, August 12, 2010 3:54:53 PM Subject: Re: [R] Where the data file is stored? You dont't tell us what you did to create a datafile - to me it sounds like you created an object (probably a data frame) in your R workspace. If that's the case it is stored in a file called .RData in your current work directory (together with other variables in your workspace). If that is not what you did please give us mre information. Hi Philipp, Yes, it is data frame. I have run the step write.csv ... Other advice noted. Thanks B.R. Stephen L __ 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. -- Alain Guillet Statistician and Computer Scientist SMCS - IMMAQ - Université catholique de Louvain Bureau c.316 Voie du Roman Pays, 20 B-1348 Louvain-la-Neuve Belgium tel: +32 10 47 30 50 __ 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 usin scan on large matrix (caveats to what has been discussed before)
Dear all, I have a few points that I am unsure about using scan. I know that it is covered in the intro to R, and also has been discussed here: http://www.mail-archive.com/r-help@r-project.org/msg04869.html but nevertheless, I cannot get it to work. I have a potentially very large matrix that I need to read in (35MB). I am about to run it on a server with 16G of memory etc, so I hope it will work. I ultimately only need to run image() on it, producing a heatmap. read.table crashes on it, and is slow, so I would like to read it using scan. The file where I store it has the following format: V1 V2 V3 V4 V5 1 508 424 208 111 66 2 59 101 95 113 81 3 26 30 24 17 18 4 4 0 8 3 9 5 0 0 0 0 0 6 0 0 0 0 0 where the first line are column names, the first column rownames. read.table works perfectly without any parameters on this (the file has been output using write.table). I use: rows-length(R) cols - max(unlist(lapply(R,function(x) length(unlist(gregexpr( ,x,fixed=TRUE,useBytes=TRUE)) c-scan(file=f,what=list(c(,(rep(integer(0),cols, skip=1) m-matrix(c, nrow = rows, ncol=cols,byrow=TRUE); for some reason I end up with a character matrix, which I don't want. Is this the proper way to skip the first column (this is not documented anywhere - how does one skip the first column in scan???). is my way of specifying integer(0) correct? And finally - would any sparse matrix package be more appropriate, and can I use a sparse matrix for the image() function producing typical heat,aps? I have seen that some sparse matrix packages produce different looking outputs, which would not be appropriate. Thanks Martin __ 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] - combining lists
Hi all, I have used this library to create a (360 day)calendar for my rainfall data (which is divided over 9 gridcells): ## CODE## library(udunits) utInit() calendar - att.get.nc(nc,'time','calendar') T - var.get.nc(nc,time) times.list - utCalendar(T,days since 1961-01-01,style='array',calendar=calendar) ## END CODE## To separate months and years I use: ## CODE## times.ind - lapply(as.list(1:12), function(x,months) which(months == x), months = times.list$month) times.ind2 - lapply(as.list(1961:1990), function(x,years) which(years == x), years = times.list$year) ## END CODE## Now I have two lists, the first contains months, for example, for times.ind[1] I get a list of day numbers which are from January. (so 1:30, 361:390 etc) The other list does the same for years times.ind2[1] gives the days 1:360 It is now possible for me to create for example monthly averages for each grid cell ##CODE## pr.monthmean - sapply(times.ind, function(x,arr) rowMeans(arr[,,x],dims=2), arr = pr) ## END CODE## the same can be done for yearly averages. However, I would like to create a matrix with monthly averages for each year separately. I think I need to couple times.ind and times.ind2 in some way, but I do not know how to do this. Is there anyone who can help me with this? Thank you in advance, Kind regards, Saskia __ 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] Fiting a trend + periodic signal
Dear all, I have a time series and I like to fit S(t) = T(t) + P(t) T(t) = Linear Trend = a + bt P(t) = Periodic Signal = sum(Ai*cos(wt) + Bi*sin(wt) ) for i=1,...,3. Thanks in advance, Best 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] Difference in Monte Carlo calculation between chisq.test and fisher.test
Hello all, I would like to know what the difference is between chisq.test and fisher.test when using the Monte Carlo method with simulate.p.value=TRUE? Thank you -- View this message in context: http://r.789695.n4.nabble.com/Difference-in-Monte-Carlo-calculation-between-chisq-test-and-fisher-test-tp2322494p2322494.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help usin scan on large matrix (caveats to what has been discussed before)
On Aug 12, 2010, at 11:30 AM, Martin Tomko wrote: c-scan(file=f,what=list(c(,(rep(integer(0),cols, skip=1) m-matrix(c, nrow = rows, ncol=cols,byrow=TRUE); for some reason I end up with a character matrix, which I don't want. Is this the proper way to skip the first column (this is not documented anywhere - how does one skip the first column in scan???). is my way of specifying integer(0) correct? No. Well, integer(0) is just superfluous where 0L would do, since scan only looks at the types not the contents, but more importantly, what= wants a list of as many elements as there are columns and you gave it list(c(,(rep(integer(0),5 [[1]] [1] I think what you actually meant was c(list(NULL),rep(list(0L),5)) And finally - would any sparse matrix package be more appropriate, and can I use a sparse matrix for the image() function producing typical heat,aps? I have seen that some sparse matrix packages produce different looking outputs, which would not be appropriate. Thanks Martin __ 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. -- Peter Dalgaard Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@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] interactions in repeated measures ANOVA
Hello all, I apply Repeated measures ANOVA for analyzing ERPs data. To do this I use lme() function and glht() for the post hoc analysis. I followed the very useful suggestions found in this help list but I have a problem. I do not know how to test the interaction between different levels of my predictors. Consider I have 2 predictors, the first one has three levels: A,B,C; also the second one has three levels:1,2,3. How can I investigate, for example, the interaction between A and 2? Thank you in advance for your help. Nicola __ 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 usin scan on large matrix (caveats to what has been discussed before)
Hi Peter, thank you for your reply. I still cannot get it to work. I have modified your code as follows: rows-length(R) cols - max(unlist(lapply(R,function(x) length(unlist(gregexpr( ,x,fixed=TRUE,useBytes=TRUE)) c-scan(file=f,what=rep(c(list(NULL),rep(list(0L),cols-1),rows-1)), skip=1) m-matrix(c, nrow = rows-1, ncol=cols+1,byrow=TRUE); the list c seems ok, with all the values I would expect. Still, length(c) gives me a value = cols+1, which I find odd (I would expect =cols). I thine repeated it rows-1 times (to account for the header row). The values seem ok. Anyway, I tried to construct the matrix, but when I print it, the values are odd: m[1:10,1:10] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [2,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [3,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [4,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [5,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [6,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [7,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [8,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [9,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [10,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Any idea where the values are gone? Thanks Martin Hence, I filled it into the matrix of dimensions On 8/12/2010 12:24 PM, peter dalgaard wrote: On Aug 12, 2010, at 11:30 AM, Martin Tomko wrote: c-scan(file=f,what=list(c(,(rep(integer(0),cols, skip=1) m-matrix(c, nrow = rows, ncol=cols,byrow=TRUE); for some reason I end up with a character matrix, which I don't want. Is this the proper way to skip the first column (this is not documented anywhere - how does one skip the first column in scan???). is my way of specifying integer(0) correct? No. Well, integer(0) is just superfluous where 0L would do, since scan only looks at the types not the contents, but more importantly, what= wants a list of as many elements as there are columns and you gave it list(c(,(rep(integer(0),5 [[1]] [1] I think what you actually meant was c(list(NULL),rep(list(0L),5)) And finally - would any sparse matrix package be more appropriate, and can I use a sparse matrix for the image() function producing typical heat,aps? I have seen that some sparse matrix packages produce different looking outputs, which would not be appropriate. Thanks Martin __ 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. -- Martin Tomko Postdoctoral Research Assistant Geographic Information Systems Division Department of Geography University of Zurich - Irchel Winterthurerstr. 190 CH-8057 Zurich, Switzerland email: martin.to...@geo.uzh.ch site: http://www.geo.uzh.ch/~mtomko mob:+41-788 629 558 tel:+41-44-6355256 fax:+41-44-6356848 __ 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] Where the data file is stored?
- Original Message From: Alain Guillet alain.guil...@uclouvain.be To: Stephen Liu sati...@yahoo.com Cc: r-help@r-project.org Sent: Thu, August 12, 2010 5:28:32 PM Subject: Re: [R] Where the data file is stored? You can find your current working directory with the getwd() function. Hi Alain, Thanks for your advice. getwd() [1] /home/userA list.files(getwd()) [1] Desktop Documents Downloads [4] examples.desktop last-packages.txt Music [7] myR petdrug.csv Pictures [10] PublicR Templates [13] Videos list.files(getwd(),full.name=TRUE) [1] /home/userA/Desktop [2] /home/userA/Documents [3] /home/userA/Downloads [4] /home/userA/examples.desktop [5] /home/userA/last-packages.txt [6] /home/userA/Music [7] /home/userA/myR [8] /home/userA/petdrug.csv [9] /home/userA/Pictures [10] /home/userA/Public [11] /home/userA/R [12] /home/userA/Templates [13] /home/userA/Videos How to show on the printout which is directory? TIA B.R. Stephen L On 12-Aug-10 11:22, Stephen Liu wrote: - Original Message From: Philipp Pagelp.pa...@wzw.tum.de To: r-help@r-project.org Sent: Thu, August 12, 2010 3:54:53 PM Subject: Re: [R] Where the data file is stored? You dont't tell us what you did to create a datafile - to me it sounds like you created an object (probably a data frame) in your R workspace. If that's the case it is stored in a file called .RData in your current work directory (together with other variables in your workspace). If that is not what you did please give us mre information. Hi Philipp, Yes, it is data frame. I have run the step write.csv ... Other advice noted. Thanks B.R. Stephen L __ 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. -- Alain Guillet Statistician and Computer Scientist SMCS - IMMAQ - Université catholique de Louvain Bureau c.316 Voie du Roman Pays, 20 B-1348 Louvain-la-Neuve Belgium tel: +32 10 47 30 50 __ 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] Where the data file is stored?
On Thu, Aug 12, 2010 at 12:37 PM, Stephen Liu sati...@yahoo.com wrote: - Original Message From: Alain Guillet alain.guil...@uclouvain.be To: Stephen Liu sati...@yahoo.com Cc: r-help@r-project.org Sent: Thu, August 12, 2010 5:28:32 PM Subject: Re: [R] Where the data file is stored? You can find your current working directory with the getwd() function. Hi Alain, Thanks for your advice. getwd() [1] /home/userA list.files(getwd()) [1] Desktop Documents Downloads [4] examples.desktop last-packages.txt Music [7] myR petdrug.csv Pictures [10] Public R Templates [13] Videos list.files(getwd(),full.name=TRUE) [1] /home/userA/Desktop [2] /home/userA/Documents [3] /home/userA/Downloads [4] /home/userA/examples.desktop [5] /home/userA/last-packages.txt [6] /home/userA/Music [7] /home/userA/myR [8] /home/userA/petdrug.csv [9] /home/userA/Pictures [10] /home/userA/Public [11] /home/userA/R [12] /home/userA/Templates [13] /home/userA/Videos How to show on the printout which is directory? TIA Use file.info and check the $isdir part of the returned data frame. For example, to get names of only directories in your working dir, do: row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),isdir)) a quick modification gets you not-directories (which will be plain files plus special files): row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),!isdir)) see ?file.info and ?files Barry __ 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] Running something without a loop when the result from the previous iteration is require for the current iteration
Not quite what I was trying to say. The process generates a random uniform number between 0 and 1 and compares to a specific conditional probability. It is looking for this in particular: random number Pr( rain(station=i,day=d)=1 | rain(station=i,day=d-1)=0 rain(station=j,day=d)=0 rain(station=k,day=d)=0) In this particular example, if the random number is less than the probability the value for station i and day d will be given as 1, otherwise it will be zero. There are 8 possible combinations. i is the station to be generated, j and k are the two stations most strongly correlated with station i. Stations j and k have already been generated in the example I gave previously. So I want to know given what is going on at stations j and k during day d and at station i for day d-1 if the value for station i day d will be 1 or 0. Hope this provides some clarification. A On Thu, Aug 12, 2010 at 3:21 AM, Petr PIKAL petr.pi...@precheza.cz wrote: Hi without toy example it is rather complicated to check your function. So only few remarks: Instead of generating 1 random number inside a loop generate whole vector of random numbers outside a loop and choose a number Do not mix ifelse with if. ifelse is intended to work with whole vector. Work with matrices instead of data frames whenever possible if speed is an issue. If I understand correctly you want to put 1 or 0 into one column based on: previous value in the same column comparison of some random number with predefined probabilities in vector of 6 values So here is vectorised version of your 4 ifs based on assumption 0 in col1 0 in col 2 = 5 0 in col1 1 in col 2 = 9 1 in col1 0 in col 2 = 6 1 in col1 1 in col 2 =10 col1-sample(1:2, 20, replace=T) col2-sample(c(4,8), 20, replace=T) col1+col2 [1] 5 6 9 6 6 5 9 10 9 9 6 9 10 6 10 9 10 9 5 5 cols-as.numeric(as.factor(col1+col2)) cols [1] 1 2 3 2 2 1 3 4 3 3 2 3 4 2 4 3 4 3 1 1 And here is computed comparison of six values p (ortho obs used) with 20 generated random values ran-runif(20) p-runif(8) comparison - outer(ran,p, ) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [2,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE [3,] FALSE TRUE FALSE TRUE FALSE TRUE TRUE FALSE [4,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE [5,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE [6,] FALSE TRUE FALSE TRUE FALSE TRUE FALSE FALSE [7,] FALSE TRUE FALSE TRUE FALSE TRUE FALSE FALSE [8,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [9,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [10,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE [11,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE [12,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [13,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE [14,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [15,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [16,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [17,] FALSE TRUE FALSE TRUE FALSE TRUE FALSE FALSE [18,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [19,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [20,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE Now the only what you need to put in loop is to select appropriate column from matrix comparison based on value on cols vector and 0 or 1 in previous row of station column. Something like (untested) gen.log-rep(NA, nrow(genmat)-1) for (i in 2:nrow(genmat)) { gen.log[i] - if( genmat[i-1, num] ==0) comparison[i, cols[i]] else comparison[i,cols[i+5]] } genmat[2:nrow(genmat), num] - gen.log*1 Regards Petr r-help-boun...@r-project.org napsal dne 11.08.2010 18:35:37: Hello Everyone! Here's what I'm trying to do. I'm working on generating occurrences of precipitation based upon precipitation occurrence for a station during the previous day and two stations that have already been generated by joint probablities and 1st order Markov chains or by the same generation process. This has to be done for each remaining stations for each month. genmat # 7 stations in this example, line_before is the climatology of the last day of the previous month. Stations 4 and 6 have been generated already in this example [,1] [,2] [,3] [,4] [,5] [,6] [,7] line_before1110111 NA NA NA1 NA0 NA NA NA NA0 NA0 NA NA NA NA0 NA0 NA NA NA NA0 NA0 NA NA NA NA0 NA0 NA NA NA NA0 NA0 NA NA NA NA0 NA0 NA NA NA NA1 NA0 NA NA NA NA1 NA1 NA NA NA NA1 NA1 NA NA NA NA0 NA0 NA NA NA NA0 NA0
[R] DRC: Effective doses versus Predicted values
Hi! I want to use the DRC package in order to calculate the IC50 value of an enzyme inhibition assay. The problem is that the estimated ED50, is always out of the fitted curve. In the example below, I had a ED50 value of 2.2896, But when I predict the response level for this concentration I get a value of 45.71 instead of the expected value of 50. This is my data: #Dose unit is concentration (mM); response unit is % of inhibition dat - data.frame(dose=c(0.480,0.957,2.870,4.780,6.700,9.570), response=c(11.88171,28.62986,51.50847,65.51793,77.29431,82.83489)) model - drm(response ~ dose, data=dat, fct= W2.3()) ED(model,50) #get a ED50 valu of2.2896 predict(model, data.frame(dose=2.2896)) #get a response level of 45.714 plot(model) points(2.2896,50, col=red) #the ED50 value is out of the fitted curve -- View this message in context: http://r.789695.n4.nabble.com/DRC-Effective-doses-versus-Predicted-values-tp2322613p2322613.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] plot.circular
Dear all, I am using plot.circular(x, stack=TRUE) to plot a histogram from a list of angle. I would also like to draw a line from the origin at the angle of the mean (mean.circular), preferably with the resultant's length (rho.circular) as length. How do I achieve this on the circular plot, please? Thanks a lot, Tim -- -- Tim Gruene Institut fuer anorganische Chemie Tammannstr. 4 D-37077 Goettingen GPG Key ID = A46BEE1A signature.asc Description: Digital signature __ 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] Setting R_Interactive
We're using Rserve as a back-end in our application. A problem that we experienced is that the Rserve connection gets stuck when R is asking for some kind of user interaction. For example, when executing an 'install.packages' command for the first time without specifying the repos argument, R will prompt a list to specify a mirror, and does not return. To solve this, we need to set R to non-interactive (see ?interactive), but it's hard to find out how. Jeffrey Horner has been so kind to write a little piece of c code that sets the C level global variable R_Interactive (see package 'interactivity' on cran), but I was wondering if there is an easier way to start R in non interactive mode. -- View this message in context: http://r.789695.n4.nabble.com/Setting-R-Interactive-tp2322621p2322621.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help usin scan on large matrix (caveats to what has been discussed before)
Hi, I don't know if this can be useful to you, but I recently wrote a small function to read a large datafile like yours in a number of steps, with the possibility to save each intermediate block as .Rdata. This is based on read.table --- not as efficient as lower-level scan() but it might be good enough, file - 'test.txt' ## write.table(matrix(rnorm(1e6*14), ncol=14), file=file,row.names = F, ## col.names = F ) n - as.numeric(gsub([^0123456789],, system(paste(wc -l , file), int=TRUE))) n blocks - function(n=18, size=5){ res - c(replicate(n%/%size, size)) if(n%%size) res - c(res, n%%size) if(!sum(res) == n) stop(ERROR!!!) res } ## blocks(1003, 500) readBlocks - function(file, nbk=1e5, out=tmp, save.inter=TRUE, classes= c(numeric, numeric, rep(NULL, 6), numeric, numeric, rep(NULL, 4))){ n - as.numeric(gsub([^0123456789],, system(paste(wc -l , file), int=TRUE))) ncols - length(grep(NULL, classes, invert=TRUE)) results - matrix(0, nrow=n, ncol=ncols) Nb - blocks(n, nbk) skip - c(0, cumsum(Nb)) for(ii in seq_along(Nb)){ d - read.table(file, colClasses = classes, nrows=Nb[ii], skip=skip[ii], comment.char = ) if(save.inter){ save(d, file=paste(out, ., ii, .rda, sep=)) } print(ii) results[seq(1+skip[ii], skip[ii]+Nb[ii]), ] - as.matrix(d) rm(d) ; gc() } save(results, file=paste(out, .rda, sep=)) invisible(results) } ## test - readBlocks(file) HTH, baptiste On Aug 12, 2010, at 1:34 PM, Martin Tomko wrote: Hi Peter, thank you for your reply. I still cannot get it to work. I have modified your code as follows: rows-length(R) cols - max(unlist(lapply(R,function(x) length(unlist(gregexpr( ,x,fixed=TRUE,useBytes=TRUE)) c-scan(file=f,what=rep(c(list(NULL),rep(list(0L),cols-1),rows-1)), skip=1) m-matrix(c, nrow = rows-1, ncol=cols+1,byrow=TRUE); the list c seems ok, with all the values I would expect. Still, length(c) gives me a value = cols+1, which I find odd (I would expect =cols). I thine repeated it rows-1 times (to account for the header row). The values seem ok. Anyway, I tried to construct the matrix, but when I print it, the values are odd: m[1:10,1:10] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [2,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [3,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [4,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [5,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [6,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [7,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [8,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [9,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [10,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Any idea where the values are gone? Thanks Martin Hence, I filled it into the matrix of dimensions On 8/12/2010 12:24 PM, peter dalgaard wrote: On Aug 12, 2010, at 11:30 AM, Martin Tomko wrote: c-scan(file=f,what=list(c(,(rep(integer(0),cols, skip=1) m-matrix(c, nrow = rows, ncol=cols,byrow=TRUE); for some reason I end up with a character matrix, which I don't want. Is this the proper way to skip the first column (this is not documented anywhere - how does one skip the first column in scan???). is my way of specifying integer(0) correct? No. Well, integer(0) is just superfluous where 0L would do, since scan only looks at the types not the contents, but more importantly, what= wants a list of as many elements as there are columns and you gave it list(c(,(rep(integer(0),5 [[1]] [1] I think what you actually meant was c(list(NULL),rep(list(0L),5)) And finally - would any sparse matrix package be more appropriate, and can I use a sparse matrix for the image() function producing typical heat,aps? I have seen that some sparse matrix packages produce different looking outputs, which would not be appropriate. Thanks Martin __ 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. -- Martin Tomko Postdoctoral Research Assistant Geographic Information Systems Division Department of Geography University of Zurich - Irchel Winterthurerstr. 190 CH-8057 Zurich, Switzerland email:martin.to...@geo.uzh.ch site: http://www.geo.uzh.ch/~mtomko mob: +41-788 629 558 tel: +41-44-6355256 fax: +41-44-6356848
Re: [R] Where the data file is stored?
You're not seeing the .Rdata file containing the data objects. Try: list.files(getwd(),full.name=TRUE, all.files=TRUE) Stephen Liu sati...@yahoo.com wrote in message news:961426.85478...@web113203.mail.gq1.yahoo.com... - Original Message From: Alain Guillet alain.guil...@uclouvain.be To: Stephen Liu sati...@yahoo.com Cc: r-help@r-project.org Sent: Thu, August 12, 2010 5:28:32 PM Subject: Re: [R] Where the data file is stored? You can find your current working directory with the getwd() function. Hi Alain, Thanks for your advice. getwd() [1] /home/userA list.files(getwd()) [1] Desktop Documents Downloads [4] examples.desktop last-packages.txt Music [7] myR petdrug.csv Pictures [10] PublicR Templates [13] Videos list.files(getwd(),full.name=TRUE) [1] /home/userA/Desktop [2] /home/userA/Documents [3] /home/userA/Downloads [4] /home/userA/examples.desktop [5] /home/userA/last-packages.txt [6] /home/userA/Music [7] /home/userA/myR [8] /home/userA/petdrug.csv [9] /home/userA/Pictures [10] /home/userA/Public [11] /home/userA/R [12] /home/userA/Templates [13] /home/userA/Videos How to show on the printout which is directory? TIA B.R. Stephen L On 12-Aug-10 11:22, Stephen Liu wrote: - Original Message From: Philipp Pagelp.pa...@wzw.tum.de To: r-help@r-project.org Sent: Thu, August 12, 2010 3:54:53 PM Subject: Re: [R] Where the data file is stored? You dont't tell us what you did to create a datafile - to me it sounds like you created an object (probably a data frame) in your R workspace. If that's the case it is stored in a file called .RData in your current work directory (together with other variables in your workspace). If that is not what you did please give us mre information. Hi Philipp, Yes, it is data frame. I have run the step write.csv ... Other advice noted. Thanks B.R. Stephen L __ 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. -- Alain Guillet Statistician and Computer Scientist SMCS - IMMAQ - Université catholique de Louvain Bureau c.316 Voie du Roman Pays, 20 B-1348 Louvain-la-Neuve Belgium tel: +32 10 47 30 50 __ 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 usin scan on large matrix (caveats to what has been discussed before)
Hi baptiste, thanks a lot. Could you please comment on that code, I cannto figure out what it does. Appart from the file name, what parameters does it need? Seems to me like you need to know the size of the table a priori. Is that right? Do you have to set up the block size depending on that (so that you get full multiples of the block to form the resulting frame)? Cheers Martin On 8/12/2010 2:45 PM, baptiste Auguié wrote: Hi, I don't know if this can be useful to you, but I recently wrote a small function to read a large datafile like yours in a number of steps, with the possibility to save each intermediate block as .Rdata. This is based on read.table --- not as efficient as lower-level scan() but it might be good enough, file- 'test.txt' ## write.table(matrix(rnorm(1e6*14), ncol=14), file=file,row.names = F, ## col.names = F ) n- as.numeric(gsub([^0123456789],, system(paste(wc -l , file), int=TRUE))) n blocks- function(n=18, size=5){ res- c(replicate(n%/%size, size)) if(n%%size) res- c(res, n%%size) if(!sum(res) == n) stop(ERROR!!!) res } ## blocks(1003, 500) readBlocks- function(file, nbk=1e5, out=tmp, save.inter=TRUE, classes= c(numeric, numeric, rep(NULL, 6), numeric, numeric, rep(NULL, 4))){ n- as.numeric(gsub([^0123456789],, system(paste(wc -l , file), int=TRUE))) ncols- length(grep(NULL, classes, invert=TRUE)) results- matrix(0, nrow=n, ncol=ncols) Nb- blocks(n, nbk) skip- c(0, cumsum(Nb)) for(ii in seq_along(Nb)){ d- read.table(file, colClasses = classes, nrows=Nb[ii], skip=skip[ii], comment.char = ) if(save.inter){ save(d, file=paste(out, ., ii, .rda, sep=)) } print(ii) results[seq(1+skip[ii], skip[ii]+Nb[ii]), ]- as.matrix(d) rm(d) ; gc() } save(results, file=paste(out, .rda, sep=)) invisible(results) } ## test- readBlocks(file) HTH, baptiste On Aug 12, 2010, at 1:34 PM, Martin Tomko wrote: Hi Peter, thank you for your reply. I still cannot get it to work. I have modified your code as follows: rows-length(R) cols- max(unlist(lapply(R,function(x) length(unlist(gregexpr( ,x,fixed=TRUE,useBytes=TRUE)) c-scan(file=f,what=rep(c(list(NULL),rep(list(0L),cols-1),rows-1)), skip=1) m-matrix(c, nrow = rows-1, ncol=cols+1,byrow=TRUE); the list c seems ok, with all the values I would expect. Still, length(c) gives me a value = cols+1, which I find odd (I would expect =cols). I thine repeated it rows-1 times (to account for the header row). The values seem ok. Anyway, I tried to construct the matrix, but when I print it, the values are odd: m[1:10,1:10] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [2,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [3,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [4,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [5,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [6,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [7,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [8,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [9,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [10,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Any idea where the values are gone? Thanks Martin Hence, I filled it into the matrix of dimensions On 8/12/2010 12:24 PM, peter dalgaard wrote: On Aug 12, 2010, at 11:30 AM, Martin Tomko wrote: c-scan(file=f,what=list(c(,(rep(integer(0),cols, skip=1) m-matrix(c, nrow = rows, ncol=cols,byrow=TRUE); for some reason I end up with a character matrix, which I don't want. Is this the proper way to skip the first column (this is not documented anywhere - how does one skip the first column in scan???). is my way of specifying integer(0) correct? No. Well, integer(0) is just superfluous where 0L would do, since scan only looks at the types not the contents, but more importantly, what= wants a list of as many elements as there are columns and you gave it list(c(,(rep(integer(0),5 [[1]] [1] I think what you actually meant was c(list(NULL),rep(list(0L),5)) And finally - would any sparse matrix package be more appropriate, and can I use a sparse matrix for the image() function producing typical heat,aps? I have seen that some sparse matrix packages produce different looking outputs, which would not be appropriate. Thanks Martin __ 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,
Re: [R] Help with permutation / loops
Hello Nikhil, hope you are well today. I am sorry to be a pain but I have one follow up question, I am trying to express my results in a grid, which would look like a 6 by 6 matrix and would have just Yes or NO in each grid.. So what I am thinking is a way to store every result I get on apply(b,2,coint) in an array or vector, and express them is this matrix. So that I can just look at it and see whether assets swap2 and vol are cointegrated.. Do you reckon you point me in the right direction as to how to do that? Thank you! Thiago -Original Message- From: Nikhil Kaza [mailto:nikhil.l...@gmail.com] Sent: 11 August 2010 12:35 To: Ferreira, Thiago Alves [ICG-MKTS] Cc: 'r-help@R-project.org' Subject: Re: [R] Help with permutation / loops How about this? untested since no data is provided. a - paste(x,1:6,sep=) b- combn(a,2) coint-function (x) { x1 - get(x[1]) x2 - get(x[2]) adfdata(x1) adfdata(x2) engle-lm(x1~x2) residual-resid(engle) adfresd(residual, k=1) par(mfrow=c(2,1)) ts.plot(x1) ts.plot(x2) ts.plot(residual) } apply(b,2,coint) Careful with the plots, you may just overwrite them on default device. One way to overcome it is to plot them to a pdf and name them appropriately for each iteration. Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Aug 11, 2010, at 6:34 AM, Ferreira, Thiago Alves wrote: Hi everyone, I am writing a code for cointegration between n (n=6 initially) pairs. I have done the whole thing for 2 variables. There is a function coint(x1,x2) that takes 2 inputs x1 and x2 and does the following: coint-function (x1,x2) { adfdata(x1) adfdata(x2) engle-lm(x1~x2) residual-resid(engle) adfresd(residual, k=1) par(mfrow=c(2,1)) ts.plot(x1) ts.plot(x2) ts.plot(residual) } Where X1,x2,..,x6 are time series of length 250 or more Where adfdata() is a function that calculates the adf test for x1 and x2. There are 6 variables in total (x1,x2,...,x6) and I want to calculate this function coint for the permutation of these variables. That is coint(x1,x2); coint(x1,x3); coint(x1,x4);...coint(x6,x5) (without repetition because x1,x1 are cointegrated already) I thought about creating an array with the combinations Xi,Xj and apply the function to each combination in the array but I could not get it to work... I would really appreciate if someone could help me on this! Thank you, Kind regards, Thiago __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help usin scan on large matrix (caveats to what has been discussed before)
On Aug 12, 2010, at 1:34 PM, Martin Tomko wrote: Hi Peter, thank you for your reply. I still cannot get it to work. I have modified your code as follows: rows-length(R) cols - max(unlist(lapply(R,function(x) length(unlist(gregexpr( ,x,fixed=TRUE,useBytes=TRUE)) Notice that the above is completely useless to the reader unless you tell us what R is (except for a statistical programming language ;-)) c-scan(file=f,what=rep(c(list(NULL),rep(list(0L),cols-1),rows-1)), skip=1) What's the outer rep() and rows-1 doing in there???! Notice that the parentheses don't match up as I think you think they do, so there's really only one argument to rep(), making it a no-op. The rows-1 is going inside the c, which might be causing the apparent extra column. And the number of rows should not affect 'what=' anyway. Now if you had done what I wrote... m-matrix(c, nrow = rows-1, ncol=cols+1,byrow=TRUE); If you make a matrix from a list, odd things will happen. You need an unlist(c). And more than likely NOT byrow=TRUE. However, I think do.call(cbind,c) should do the trick more easily. the list c seems ok, with all the values I would expect. Still, length(c) gives me a value = cols+1, which I find odd (I would expect =cols). I thine repeated it rows-1 times (to account for the header row). The values seem ok. Anyway, I tried to construct the matrix, but when I print it, the values are odd: m[1:10,1:10] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [2,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [3,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [4,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [5,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [6,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [7,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [8,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [9,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [10,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Any idea where the values are gone? Thanks Martin Hence, I filled it into the matrix of dimensions On 8/12/2010 12:24 PM, peter dalgaard wrote: On Aug 12, 2010, at 11:30 AM, Martin Tomko wrote: c-scan(file=f,what=list(c(,(rep(integer(0),cols, skip=1) m-matrix(c, nrow = rows, ncol=cols,byrow=TRUE); for some reason I end up with a character matrix, which I don't want. Is this the proper way to skip the first column (this is not documented anywhere - how does one skip the first column in scan???). is my way of specifying integer(0) correct? No. Well, integer(0) is just superfluous where 0L would do, since scan only looks at the types not the contents, but more importantly, what= wants a list of as many elements as there are columns and you gave it list(c(,(rep(integer(0),5 [[1]] [1] I think what you actually meant was c(list(NULL),rep(list(0L),5)) And finally - would any sparse matrix package be more appropriate, and can I use a sparse matrix for the image() function producing typical heat,aps? I have seen that some sparse matrix packages produce different looking outputs, which would not be appropriate. Thanks Martin __ 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. -- Martin Tomko Postdoctoral Research Assistant Geographic Information Systems Division Department of Geography University of Zurich - Irchel Winterthurerstr. 190 CH-8057 Zurich, Switzerland email:martin.to...@geo.uzh.ch site: http://www.geo.uzh.ch/~mtomko mob: +41-788 629 558 tel: +41-44-6355256 fax: +41-44-6356848 -- Peter Dalgaard Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@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] Help with permutation / loops
The adfresd function that you have, prints the outcome of the test rather than `return' ing a value. If you would modify that function to return a value (True or false/ or p-value) you should automatically get vector that you desire. Then is a simple task of naming the resultant vector with. apply(b,2, paste, collapse=_) On Thu, Aug 12, 2010 at 10:15 AM, Ferreira, Thiago Alves thiago.alves.ferre...@citi.com wrote: Hello Nikhil, hope you are well today. I am sorry to be a pain but I have one follow up question, I am trying to express my results in a grid, which would look like a 6 by 6 matrix and would have just Yes or NO in each grid.. So what I am thinking is a way to store every result I get on apply(b,2,coint) in an array or vector, and express them is this matrix. So that I can just look at it and see whether assets swap2 and vol are cointegrated.. Do you reckon you point me in the right direction as to how to do that? Thank you! Thiago -Original Message- From: Nikhil Kaza [mailto:nikhil.l...@gmail.com] Sent: 11 August 2010 12:35 To: Ferreira, Thiago Alves [ICG-MKTS] Cc: 'r-help@R-project.org' Subject: Re: [R] Help with permutation / loops How about this? untested since no data is provided. a - paste(x,1:6,sep=) b- combn(a,2) coint-function (x) { x1 - get(x[1]) x2 - get(x[2]) adfdata(x1) adfdata(x2) engle-lm(x1~x2) residual-resid(engle) adfresd(residual, k=1) par(mfrow=c(2,1)) ts.plot(x1) ts.plot(x2) ts.plot(residual) } apply(b,2,coint) Careful with the plots, you may just overwrite them on default device. One way to overcome it is to plot them to a pdf and name them appropriately for each iteration. Nikhil Kaza Asst. Professor, City and Regional Planning University of North Carolina nikhil.l...@gmail.com On Aug 11, 2010, at 6:34 AM, Ferreira, Thiago Alves wrote: Hi everyone, I am writing a code for cointegration between n (n=6 initially) pairs. I have done the whole thing for 2 variables. There is a function coint(x1,x2) that takes 2 inputs x1 and x2 and does the following: coint-function (x1,x2) { adfdata(x1) adfdata(x2) engle-lm(x1~x2) residual-resid(engle) adfresd(residual, k=1) par(mfrow=c(2,1)) ts.plot(x1) ts.plot(x2) ts.plot(residual) } Where X1,x2,..,x6 are time series of length 250 or more Where adfdata() is a function that calculates the adf test for x1 and x2. There are 6 variables in total (x1,x2,...,x6) and I want to calculate this function coint for the permutation of these variables. That is coint(x1,x2); coint(x1,x3); coint(x1,x4);...coint(x6,x5) (without repetition because x1,x1 are cointegrated already) I thought about creating an array with the combinations Xi,Xj and apply the function to each combination in the array but I could not get it to work... I would really appreciate if someone could help me on this! Thank you, Kind regards, Thiago __ 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.
[R] Regression Error: Otherwise good variable causes singularity. Why?
This command cdmoutcome- glm(log(value)~factor(year) +log(gdppcpppconst)+log(gdppcpppconstAII) +log(co2eemisspc)+log(co2eemisspcAII) +log(dist) +fdiboth +odapartnertohost +corrupt +log(infraindex) +litrate +africa +imr , data=cdmdata2, subset=zero==1, gaussian(link = identity)) results in this table Coefficients: (1 not defined because of singularities) Estimate Std. Error t value Pr(|t|) (Intercept)1.216e+01 5.771e+01 0.211 0.8332 factor(year)2006 -1.403e+00 5.777e-01 -2.429 0.0157 * factor(year)2007 -2.799e-01 7.901e-01 -0.354 0.7234 log(gdppcpppconst) 2.762e-01 5.517e+00 0.050 0.9601 log(gdppcpppconstAII) -1.344e-01 9.025e-01 -0.149 0.8817 log(co2eemisspc) 5.655e+00 2.903e+00 1.948 0.0523 . log(co2eemisspcAII) -1.411e-01 4.245e-01 -0.332 0.7399 log(dist) -2.938e-01 4.023e-01 -0.730 0.4658 fdiboth1.326e-04 1.133e-04 1.171 0.2425 odapartnertohost 2.319e-03 1.437e-03 1.613 0.1078 corrupt1.875e+00 3.313e+00 0.566 0.5718 log(infraindex)4.783e+00 1.091e+01 0.438 0.6615 litrate0.47 -2.485e+01 3.190e+01 -0.779 0.4365 litrate0.499 -1.657e+01 2.591e+01 -0.639 0.5230 litrate0.523 -2.440e+01 3.427e+01 -0.712 0.4769 litrate0.528 -9.184e+00 1.379e+01 -0.666 0.5060 litrate0.595 -2.309e+01 2.776e+01 -0.832 0.4062 litrate0.66 -1.451e+01 2.734e+01 -0.531 0.5961 litrate0.675 -1.707e+01 2.813e+01 -0.607 0.5444 litrate0.68 -6.346e+00 1.063e+01 -0.597 0.5509 litrate0.699 2.717e+00 3.541e+00 0.768 0.4434 litrate0.706 -1.960e+01 2.933e+01 -0.668 0.5046 litrate0.714 -2.586e+01 4.002e+01 -0.646 0.5186 litrate0.736 5.641e+00 1.561e+01 0.361 0.7181 litrate0.743 -2.692e+01 4.253e+01 -0.633 0.5273 litrate0.762 -2.208e+01 3.100e+01 -0.712 0.4767 litrate0.802 -2.325e+01 3.766e+01 -0.617 0.5375 litrate0.847 -2.620e+01 3.948e+01 -0.664 0.5075 litrate0.86 -3.576e+01 4.950e+01 -0.722 0.4707 litrate0.864 -4.482e+01 6.274e+01 -0.714 0.4755 litrate0.872 -1.946e+01 2.715e+01 -0.717 0.4739 litrate0.877 -2.710e+01 3.702e+01 -0.732 0.4646 litrate0.879 -3.460e+01 5.147e+01 -0.672 0.5020 litrate0.886 -3.276e+01 4.860e+01 -0.674 0.5008 litrate0.889 -4.120e+01 5.755e+01 -0.716 0.4746 litrate0.904 -2.282e+01 2.985e+01 -0.764 0.4453 litrate0.91 -3.478e+01 5.037e+01 -0.691 0.4904 litrate0.923 -1.762e+01 2.551e+01 -0.691 0.4902 litrate0.925 -2.445e+01 3.611e+01 -0.677 0.4990 litrate0.926 -2.995e+01 4.565e+01 -0.656 0.5123 litrate0.928 -2.839e+01 3.933e+01 -0.722 0.4710 litrate0.937 -2.571e+01 3.795e+01 -0.677 0.4986 litrate0.94 -2.109e+01 3.051e+01 -0.691 0.4900 litrate0.959 -2.078e+01 2.895e+01 -0.718 0.4735 litrate0.96 -3.403e+01 4.798e+01 -0.709 0.4787 litrate0.962 -4.084e+01 5.755e+01 -0.710 0.4785 litrate0.971 -3.743e+01 5.247e+01 -0.713 0.4761 litrate0.98 -3.709e+01 5.170e+01 -0.717 0.4737 litrate0.986 -2.663e+01 4.437e+01 -0.600 0.5488 litrate0.991 -3.045e+01 4.166e+01 -0.731 0.4654 litrate1 -2.732e+01 4.459e+01 -0.613 0.5405 africaNA NA NA NA imr2.160e+00 9.357e-01 2.309 0.0216 * although it should result in something similar to this: Coefficients: (1 not defined because of singularities) Estimate Std. Error t value Pr(|t|) (Intercept)1.216e+01 5.771e+01 0.211 0.8332 factor(year)2006 -1.403e+00 5.777e-01 -2.429 0.0157 * factor(year)2007 -2.799e-01 7.901e-01 -0.354 0.7234 log(gdppcpppconst) 2.762e-01 5.517e+00 0.050 0.9601 log(gdppcpppconstAII) -1.344e-01 9.025e-01 -0.149 0.8817 log(co2eemisspc) 5.655e+00 2.903e+00 1.948 0.0523 . log(co2eemisspcAII) -1.411e-01 4.245e-01 -0.332 0.7399 log(dist) -2.938e-01 4.023e-01 -0.730 0.4658 fdiboth1.326e-04 1.133e-04 1.171 0.2425 odapartnertohost 2.319e-03 1.437e-03 1.613 0.1078 corrupt1.875e+00 3.313e+00 0.566 0.5718 log(infraindex)4.783e+00 1.091e+01 0.438 0.6615 litrate -2.485e+01 3.190e+01 -0.779 0.4365
[R] Traffic prediction contest
Hi useRs, A reminder. The IEEE ICDM Contest: Road Traffic Prediction, will end in 24 days. Hurry up if you want to play with traffic data and solve the problem of jams prediction. Prizes of $5,000 in total will be awarded for the best solutions. http://tunedit.org/challenge/IEEE-ICDM-2010 BTW, the previous contest in TunedIT was won by an R user: http://blog.tunedit.org/2010/07/20/no-alternatives-to-data-mining/ Cheers Marcin -- Marcin Wojnarski, Project Lead, TunedIT tel.: +48 22 662 31 96 http://tunedit.org http://www.facebook.com/TunedIT http://twitter.com/TunedIT Machine Learning Data Mining Research - Automated Tests, Repeatable Experiments, Meaningful Results __ 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 usin scan on large matrix (caveats to what has been discussed before)
Hi Peter, apologies, too fast copying and pasting. So, here is the explanation: f-C:/test/mytab.txt; R-readLines(con=f); where mytab.txt is a table formatted as noted in previous post (space delimited, with header, rownames, containing integers). Now, my understandign of scan was that I have to specify the FULL number of values in it (examples specify things like 200*2000 for a matrix etc). That's why I thought that I need to do cols*rows as well. Avoiding the first line with headers is simple, avoiding the first column is not - hence my questions. Sorry, the corrected, matching parentheses are here - why did the previous execute is a wonder... c-scan(file=f,what=rep(c(list(NULL),rep(list(0L),cols-1)),rows-1), skip=1) here, my reasoning was: * c(list(NULL),rep(list(0L),cols-1)) specifies a template for any line (first elelement to be ignored = NULL, it is a string in the table specified, and then a repetition of integers - I am still not sure how you derived 0L, and what it means and where to find a doc for that.); * the previous needs to be repeated rows-1 times, hence what=rep(c(list(NULL),rep(list(0L),cols-1)),rows-1) I do nto understand the following: You need an unlist(c). And more than likely NOT byrow=TRUE. However, I think do.call(cbind,c) should do the trick more easily. what will unlist(c) do; why should it not be bywrow=TRUE, and how would you go about integrating do.call(cbind,c) with matrix. Apologies to naive questions, I am a newbie, in principle. Cheers Martin On 8/12/2010 4:29 PM, peter dalgaard wrote: On Aug 12, 2010, at 1:34 PM, Martin Tomko wrote: Hi Peter, thank you for your reply. I still cannot get it to work. I have modified your code as follows: rows-length(R) cols- max(unlist(lapply(R,function(x) length(unlist(gregexpr( ,x,fixed=TRUE,useBytes=TRUE)) Notice that the above is completely useless to the reader unless you tell us what R is (except for a statistical programming language ;-)) c-scan(file=f,what=rep(c(list(NULL),rep(list(0L),cols-1),rows-1)), skip=1) What's the outer rep() and rows-1 doing in there???! Notice that the parentheses don't match up as I think you think they do, so there's really only one argument to rep(), making it a no-op. The rows-1 is going inside the c, which might be causing the apparent extra column. And the number of rows should not affect 'what=' anyway. Now if you had done what I wrote... m-matrix(c, nrow = rows-1, ncol=cols+1,byrow=TRUE); If you make a matrix from a list, odd things will happen. You need an unlist(c). And more than likely NOT byrow=TRUE. However, I think do.call(cbind,c) should do the trick more easily. the list c seems ok, with all the values I would expect. Still, length(c) gives me a value = cols+1, which I find odd (I would expect =cols). I thine repeated it rows-1 times (to account for the header row). The values seem ok. Anyway, I tried to construct the matrix, but when I print it, the values are odd: m[1:10,1:10] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [2,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [3,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [4,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [5,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [6,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [7,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [8,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [9,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 [10,] NULL Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Integer,15 Any idea where the values are gone? Thanks Martin Hence, I filled it into the matrix of dimensions On 8/12/2010 12:24 PM, peter dalgaard wrote: On Aug 12, 2010, at 11:30 AM, Martin Tomko wrote: c-scan(file=f,what=list(c(,(rep(integer(0),cols, skip=1) m-matrix(c, nrow = rows, ncol=cols,byrow=TRUE); for some reason I end up with a character matrix, which I don't want. Is this the proper way to skip the first column (this is not documented anywhere - how does one skip the first column in scan???). is my way of specifying integer(0) correct? No. Well, integer(0) is just superfluous where 0L would do, since scan only looks at the types not the contents, but more importantly, what= wants a list of as many elements as there are columns and you gave it list(c(,(rep(integer(0),5 [[1]] [1] I think what you actually meant was c(list(NULL),rep(list(0L),5)) And finally - would any sparse matrix package be more appropriate, and can I use a sparse matrix for the image() function producing typical heat,aps? I have seen
Re: [R] Regression Error: Otherwise good variable causes singularity. Why?
There appears to be a problem in both regressions, as a singularity is also reported in the second regression analysis as well. It appears that the litrate variable is considered a factor in the first analysis and continuous in the second. There also appears to be collinearity between the litrate variable and the Africa variable. Look at the package lm.influence for regression diagnostics. asdir dirkroettg...@gmail.com Sent by: r-help-boun...@r-project.org 08/12/2010 10:35 AM To r-help@r-project.org cc Subject [R] Regression Error: Otherwise good variable causes singularity. Why? This command cdmoutcome- glm(log(value)~factor(year) +log(gdppcpppconst)+log(gdppcpppconstAII) +log(co2eemisspc)+log(co2eemisspcAII) +log(dist) +fdiboth +odapartnertohost +corrupt +log(infraindex) +litrate +africa +imr , data=cdmdata2, subset=zero==1, gaussian(link = identity)) results in this table Coefficients: (1 not defined because of singularities) Estimate Std. Error t value Pr(|t|) (Intercept)1.216e+01 5.771e+01 0.211 0.8332 factor(year)2006 -1.403e+00 5.777e-01 -2.429 0.0157 * factor(year)2007 -2.799e-01 7.901e-01 -0.354 0.7234 log(gdppcpppconst) 2.762e-01 5.517e+00 0.050 0.9601 log(gdppcpppconstAII) -1.344e-01 9.025e-01 -0.149 0.8817 log(co2eemisspc) 5.655e+00 2.903e+00 1.948 0.0523 . log(co2eemisspcAII) -1.411e-01 4.245e-01 -0.332 0.7399 log(dist) -2.938e-01 4.023e-01 -0.730 0.4658 fdiboth1.326e-04 1.133e-04 1.171 0.2425 odapartnertohost 2.319e-03 1.437e-03 1.613 0.1078 corrupt1.875e+00 3.313e+00 0.566 0.5718 log(infraindex)4.783e+00 1.091e+01 0.438 0.6615 litrate0.47 -2.485e+01 3.190e+01 -0.779 0.4365 litrate0.499 -1.657e+01 2.591e+01 -0.639 0.5230 litrate0.523 -2.440e+01 3.427e+01 -0.712 0.4769 litrate0.528 -9.184e+00 1.379e+01 -0.666 0.5060 litrate0.595 -2.309e+01 2.776e+01 -0.832 0.4062 litrate0.66 -1.451e+01 2.734e+01 -0.531 0.5961 litrate0.675 -1.707e+01 2.813e+01 -0.607 0.5444 litrate0.68 -6.346e+00 1.063e+01 -0.597 0.5509 litrate0.699 2.717e+00 3.541e+00 0.768 0.4434 litrate0.706 -1.960e+01 2.933e+01 -0.668 0.5046 litrate0.714 -2.586e+01 4.002e+01 -0.646 0.5186 litrate0.736 5.641e+00 1.561e+01 0.361 0.7181 litrate0.743 -2.692e+01 4.253e+01 -0.633 0.5273 litrate0.762 -2.208e+01 3.100e+01 -0.712 0.4767 litrate0.802 -2.325e+01 3.766e+01 -0.617 0.5375 litrate0.847 -2.620e+01 3.948e+01 -0.664 0.5075 litrate0.86 -3.576e+01 4.950e+01 -0.722 0.4707 litrate0.864 -4.482e+01 6.274e+01 -0.714 0.4755 litrate0.872 -1.946e+01 2.715e+01 -0.717 0.4739 litrate0.877 -2.710e+01 3.702e+01 -0.732 0.4646 litrate0.879 -3.460e+01 5.147e+01 -0.672 0.5020 litrate0.886 -3.276e+01 4.860e+01 -0.674 0.5008 litrate0.889 -4.120e+01 5.755e+01 -0.716 0.4746 litrate0.904 -2.282e+01 2.985e+01 -0.764 0.4453 litrate0.91 -3.478e+01 5.037e+01 -0.691 0.4904 litrate0.923 -1.762e+01 2.551e+01 -0.691 0.4902 litrate0.925 -2.445e+01 3.611e+01 -0.677 0.4990 litrate0.926 -2.995e+01 4.565e+01 -0.656 0.5123 litrate0.928 -2.839e+01 3.933e+01 -0.722 0.4710 litrate0.937 -2.571e+01 3.795e+01 -0.677 0.4986 litrate0.94 -2.109e+01 3.051e+01 -0.691 0.4900 litrate0.959 -2.078e+01 2.895e+01 -0.718 0.4735 litrate0.96 -3.403e+01 4.798e+01 -0.709 0.4787 litrate0.962 -4.084e+01 5.755e+01 -0.710 0.4785 litrate0.971 -3.743e+01 5.247e+01 -0.713 0.4761 litrate0.98 -3.709e+01 5.170e+01 -0.717 0.4737 litrate0.986 -2.663e+01 4.437e+01 -0.600 0.5488 litrate0.991 -3.045e+01 4.166e+01 -0.731 0.4654 litrate1 -2.732e+01 4.459e+01 -0.613 0.5405 africaNA NA NA NA imr2.160e+00 9.357e-01 2.309 0.0216 * although it should result in something similar to this: Coefficients: (1 not defined because of singularities) Estimate Std. Error t value Pr(|t|) (Intercept)1.216e+01 5.771e+01 0.211 0.8332 factor(year)2006 -1.403e+00 5.777e-01 -2.429 0.0157 * factor(year)2007 -2.799e-01 7.901e-01 -0.354 0.7234 log(gdppcpppconst) 2.762e-01 5.517e+00 0.050 0.9601 log(gdppcpppconstAII)
Re: [R] question on contour function
Duncan and David, thank you so much. You are right. We can use z1 - outer(x, y, function(x,y) x^2+3*y^2) rather than xy - meshgrid(x,y) z2 - xy$x^2+ 3*xy$y^2 to get right answer. I run these codes on my computer and found that z2 is the transpose of z1. So I guess in order to obtain the expected result, there are at least two ways. x - seq(-1,1,0.1) y - seq(-1,1,0.1) z - outer(x,y, FUN=function(x,y) x^2+ 3*y^2) contour(x,y,z,col=blue,xlab=x,ylab=y) or require(RTOMO) x - seq(-1,1,0.1) y - seq(-1,1,0.1) xy - meshgrid(x,y) z - xy$x^2+ 3*xy$y^2 z - t(z) contour(x,y,z,col=blue,xlab=x,ylab=y) Of course, the first method is better since it only uses the base function. David Lee On 12 August 2010 01:54, David Winsemius dwinsem...@comcast.net wrote: On Aug 11, 2010, at 11:16 AM, ba ba wrote: Dear All, I tried to plot contour lines using R function contour, but got the results which are not expected. require(RTOMO) x - seq(-1,1,0.1) y - seq(-1,1,0.1) xy - meshgrid(x,y) z - xy$x^2+ 3*xy$y^2 contour(x,y,z,col=blue,xlab=x,ylab=y) The above code gave me the contour graph for z=3*x^2+y^2 rather than z=x^2+3*y^2. Is anyone know the reason? Because contour was expecting a matrix of z values for z and you gave it a list created by a function you did not understand? meshgrid function (a, b) { return(list(x = outer(b * 0, a, FUN = +), y = outer(b, a * 0, FUN = +))) } Instead: Use the base function outer(): x - seq(-1,1,0.1) y - seq(-1,1,0.1) xy - outer(x,y, FUN=function(x,y) x^2+ 3*y^2) contour(x,y,xy,col=blue,xlab=x,ylab=y) -- David Winsemius, MD West Hartford, CT [[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 to polish plot in ggplot2
baptiste, I have two more questions. How can I get the category labels right justified? It seems that I need to change the size of the text too. Since in my real data the text size are big and they appears to be even bigger than my plot area. So, my second question is how can I change the text size? Thanks again for your help. On Thu, Aug 12, 2010 at 8:02 AM, baptiste Auguié baptiste.aug...@googlemail.com wrote: you just need to remove the rectGrob() from ylab, as in ylab - gTree(children=gList(my.labels), cl=mylabels ) baptiste On Aug 12, 2010, at 2:59 PM, Mahbubul Majumder wrote: baptiste, This is exactly what I wanted. Many thanks for this. I have one problem though. How can I get rid of the boundary box of y axis title? On Thu, Aug 12, 2010 at 2:47 AM, baptiste auguie baptiste.aug...@googlemail.com wrote: To illustrate the second option I proposed, library(ggplot2) library(gridExtra) category - paste(Geographical Category, 1:10) grp1 - rnorm(10, mean=10, sd=10) grp2 - rnorm(10, mean=20, sd=10) grp3 - rnorm(10, mean=15, sd=10) grp4 - rnorm(10, mean=12, sd=10) mydat - data.frame(category,grp1,grp2,grp3,grp4) dat.m - melt(mydat) p - qplot(1,value, data=dat.m, geom=bar, xlab=,ylab=Percentage of eco change,stat=identity,fill=variable, position=dodge) + coord_flip()+ facet_grid(category ~ ., space=free)+scale_x_discrete(breaks=c(2,4))+opts(strip.text.y = theme_text(hjust = 0)) labs - llply(category, textGrob) ## add a blank grob below as the y title is aligned with the full ggplot2 height, ## not just the panel my.labels - do.call(arrangeGrob, c(labs, list(ncol=1, left=My y title, sub= ))) # grid.draw(my.labels) ## hack: define the width of my.labels ylab - gTree(children=gList(my.labels, rectGrob()), cl=mylabels ) widthDetails.mylabels - function(x) max(stringWidth(category)) + unit(1, line) ## hack: tweak ggplot2's axis.title.y option to use our gTree foo - function() function(label, x, y) ylab p + opts(strip.text.y =theme_blank(), strip.background=theme_blank()) + opts( axis.title.y = foo()) HTH, baptiste On 12 August 2010 07:44, baptiste auguie baptiste.aug...@googlemail.com wrote: Hi, One way you could do it is to create a separate graph for each category. The y axis labels would replace the strip labels. You could then stack the graphs on the page, and add a common legend. The tricky part would be to make sure the different panels have the same width and height. Another option might be to hack a custom Grob (gTree) for the y-axis title so that it would draw the current y-axis title and also the labels for the facets next to it. Of course you'd also get rid of the strips in this case. Best, baptiste On 11 August 2010 15:39, Mahbubul Majumder mahbu...@gmail.com wrote: Hi, I wanted to generate a plot which is almost like the plot generated by the following codes. category - paste(Geographical Category, 1:10) grp1 - rnorm(10, mean=10, sd=10) grp2 - rnorm(10, mean=20, sd=10) grp3 - rnorm(10, mean=15, sd=10) grp4 - rnorm(10, mean=12, sd=10) mydat - data.frame(category,grp1,grp2,grp3,grp4) dat.m - melt(mydat) p - qplot(1,value, data=dat.m, geom=bar, xlab=,ylab=Percentage of eco change,stat=identity,fill=variable, position=dodge) p + coord_flip()+ facet_grid(category ~ ., space=free)+scale_x_discrete(breaks=c(2,4))+opts(strip.text.y = theme_text(hjust = 0)) Now the only modification I need from this plot is that I want the grid labels (text) on the left hand side with right justification and white background. My prospective plot should have labels like the the plot generated by the codes below. The reason why I don't like the plot below is that it does not show separate grid for each category. p - qplot(category,value, data=dat.m, geom=bar, ylab=Percentage of eco change,stat=identity,fill=variable, position=dodge) p + coord_flip() Can you help me generate my vision plot? -- Mahbub Majumder Graduate Student Dept. of Statistics Iowa 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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Mahbub Majumder Graduate Student Dept. of Statistics Iowa State University -- Mahbub Majumder Graduate Student Dept. of Statistics Iowa State University [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help
Re: [R] Creating vectors
Thanks for the help, I tried to apply this to a vector with two columns, well I suppose it is not a vector but for instance like this: [,1] [,2] [1,]1 2 [2,]2 3 [3,]1 2 [4,]1 2 [5,]3 4 and return a vector : 1,2,1,1,3, so that it recognises both columns together. I tried match(x, unique(x)) as earlier suggested but this returns a vector of length 10 as opposed to 5, even though unique(x) does remove the repeated rows. Sorry if this is confusing, I am trying to do as originally posted but with 2 columns Thanks -- View this message in context: http://r.789695.n4.nabble.com/Creating-vectors-tp2321440p2322646.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] non-linear regression for 3D data
I've tried lm, but something is wrong. I've made a test dataset of 599 data points, my original equation is zz = 1 +0.5*xx -3.2*xx*xx -1*yy +4.2*yy*yy but the R gives this result: --- mp - read.csv(file=sample.csv,sep=;,header=TRUE) lm(zz ~ poly(xx,2) + poly(yy,2), data=mp) Call: lm(formula = zz ~ poly(xx, 2) + poly(yy, 2), data = mp) Coefficients: (Intercept) poly(xx, 2)1 poly(xx, 2)2 poly(yy, 2)1 poly(yy, 2)2 25.86 -2239.86 -595.01 2875.54776.84 --- which is definitely not the original. :( (In case of interest the test dataset is available here: szisziszilvi.lima-city.de/r) -- View this message in context: http://r.789695.n4.nabble.com/non-linear-regression-for-3D-data-tp2320982p2322779.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: evaluation nested too deeply
Hi guys, I have a code in R and it was work well but when I decrease the epsilon value (indicated in the code) , then I am getting this error Error: evaluation nested too deeply: infinite recursion / options(expressions=)? any help please y = 6.8; w = 7.4; z = 5.7; muy = 7; muw = 7; muz = 6; sigmay = 0.8; sigmaz = 0.76; sigmaw = 0.3; betayx = 0.03; betayz = 0.3; betayw = 0.67 s = c(3.2,0.8) em = function(W,s) { a= 1/2*(1/s[2]^2+betayx^2/sigmay^2); b= (y-muy+betayx*s[1]-betayz*(z-muz)-betayw*(w-muw))*betayx/sigmay^2+s[1]/s[2]^2; c=(1/2)*((y-muy+betayx*s[1]-betayz*(z-muz)-betayw*(w-muw))*betayx/sigmay^2+s[1]/s[2]^2)^2/(1/s[2]^2+betayx^2/sigmay^2); V = exp(-c+b^2/(4*a))/sqrt(pi/(1/(2*s[2]^2)+(1/2)*betayx^2/sigmay^2)); Omega = V*sqrt(pi/a); A = 4*a^2*Omega*betayx^2/sigmay^2; B = 4*a^2; C = 2*a*b*Omega; d = (2*a*b*Omega*betayx^2/sigmay^2)-(4*a^2*Omega*(y-muy-betayz*(z-muz)-betayw*(w-muw))*betayx/sigmay^2); E = 2*a*Omega+b^2*Omega; lambda = A*B; alpha = 2*A*C+d*B; delta = A*E+B^2+2*d*C; eta = C*B+d*E; s[1]=(1/6)*(-36*delta*alpha*lambda+108*eta*lambda^2+8*alpha^3+12*sqrt(3)*sqrt(4*delta^3*lambda-delta^2*alpha^2-18*delta*alpha*lambda*eta+27*eta^2*lambda^2+4*eta*alpha^3)*lambda)^(1/3)/lambda+(2/3)*(-3*delta*lambda+alpha^2)/(lambda*(-36*delta*alpha*lambda+108*eta*lambda^2+8*alpha^3+12*sqrt(3)*sqrt(4*delta^3*lambda-delta^2*alpha^2-18*delta*alpha*lambda*eta+27*eta^2*lambda^2+4*eta*alpha^3)*lambda)^(1/3))+(1/3)*alpha/lambda; s[2]=sqrt((B*s[1]^2-2*C*s[1]+E)/B); s } epsilon =0.0005 iter = function(W, s) { s1 = em(W,s) for (i in 1:2) { if (abs(s[i]-s1[i]) epsilon) { s=s1 iter(W,s) } else s1 } s1 } iter(W,s) -- View this message in context: http://r.789695.n4.nabble.com/Error-evaluation-nested-too-deeply-tp2322701p2322701.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] non-linear regression for 3D data
right. How does it come that if I devide the result vector with 10*interception, I get a much better result? zz2 - 25.86 -2239.86*mp$xx -595.01*mp$xx*mp$xx + 2875.54*mp$yy + 776.84*mp$yy*mp$yy mp$zz2 - zz2 library(lattice) cloud(zz2/258.6 + zz ~ xx * yy, data=mp) looks quite pretty. http://r.789695.n4.nabble.com/file/n2322812/output.jpeg -- View this message in context: http://r.789695.n4.nabble.com/non-linear-regression-for-3D-data-tp2320982p2322812.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] Linear regression on several groups
I have a simple dataset of a numerical dependent Y, a numerical independent X and a categorial variable Z with three levels. I want to do linear regression Y~X for each level of Z. How can I do this in a single command that is without using lm() applied three isolated times? -- View this message in context: http://r.789695.n4.nabble.com/Linear-regression-on-several-groups-tp2322835p2322835.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] Median abline how-to ?
Hi, I'm newbie with R and don't really know how to add a median line to each of the groups that is not all the plot long. Here is a small working code that i have adapted for my purpose. If somebody could tell me how to draw median lines on each group and not all plot long. ctl - c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) trt - c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69) group - gl(2,10,20, labels=c(Ctl,Trt)) weight - c(ctl, trt) ctlmed - median(weight[which(group == Ctl)]) trtmed - median(weight[which(group == Trt)]) plot.default(weight ~ group,axes=F) axis(2,col.axis = blue,las=1,cex.axis=0.7,xpd=TRUE) axis(1, labels=levels(group),at=1:length(unique(group)),las=2,cex.axis=0.7) #horizontal abline(h = ctlmed, col = blue, lwd = 2) # ?? how to make abline shorter ? abline(h = trtmed, col = red, lwd = 2) box(bty=c) ps: At this stage the boxplot is not interesting for me. thanks, david __ 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] Regression Error: Otherwise good variable causes singularity. Why?
On Aug 12, 2010, at 10:35 AM, asdir wrote: This command cdmoutcome- glm(log(value)~factor(year) +log(gdppcpppconst)+log(gdppcpppconstAII) +log(co2eemisspc)+log(co2eemisspcAII) +log(dist) +fdiboth +odapartnertohost +corrupt +log(infraindex) +litrate +africa +imr , data=cdmdata2, subset=zero==1, gaussian(link = identity)) results in this table Coefficients: (1 not defined because of singularities) Estimate Std. Error t value Pr(|t|) (Intercept)1.216e+01 5.771e+01 0.211 0.8332 factor(year)2006 -1.403e+00 5.777e-01 -2.429 0.0157 * factor(year)2007 -2.799e-01 7.901e-01 -0.354 0.7234 log(gdppcpppconst) 2.762e-01 5.517e+00 0.050 0.9601 log(gdppcpppconstAII) -1.344e-01 9.025e-01 -0.149 0.8817 log(co2eemisspc) 5.655e+00 2.903e+00 1.948 0.0523 . log(co2eemisspcAII) -1.411e-01 4.245e-01 -0.332 0.7399 log(dist) -2.938e-01 4.023e-01 -0.730 0.4658 fdiboth1.326e-04 1.133e-04 1.171 0.2425 odapartnertohost 2.319e-03 1.437e-03 1.613 0.1078 corrupt1.875e+00 3.313e+00 0.566 0.5718 log(infraindex)4.783e+00 1.091e+01 0.438 0.6615 You have probably created litrate as a factor without realizing it. That can easily happen if you just use read.table and one of the values cannot be gracefully interpreted as a numeric. Either read in with stringsAsFactors=FALSE or asIs=TRUE and then coerce it to numeric. or if you want to fix an existing factor f%^-up, then the FAQ tells you to use something like: cdmdata2$f_ed_variable - as.numeric(as.character(cdmdata2$f_ed_variable) litrate0.47 -2.485e+01 3.190e+01 -0.779 0.4365 litrate0.499 -1.657e+01 2.591e+01 -0.639 0.5230 litrate0.523 -2.440e+01 3.427e+01 -0.712 0.4769 litrate0.528 -9.184e+00 1.379e+01 -0.666 0.5060 litrate0.595 -2.309e+01 2.776e+01 -0.832 0.4062 litrate0.66 -1.451e+01 2.734e+01 -0.531 0.5961 litrate0.675 -1.707e+01 2.813e+01 -0.607 0.5444 litrate0.68 -6.346e+00 1.063e+01 -0.597 0.5509 litrate0.699 2.717e+00 3.541e+00 0.768 0.4434 litrate0.706 -1.960e+01 2.933e+01 -0.668 0.5046 litrate0.714 -2.586e+01 4.002e+01 -0.646 0.5186 litrate0.736 5.641e+00 1.561e+01 0.361 0.7181 litrate0.743 -2.692e+01 4.253e+01 -0.633 0.5273 litrate0.762 -2.208e+01 3.100e+01 -0.712 0.4767 litrate0.802 -2.325e+01 3.766e+01 -0.617 0.5375 litrate0.847 -2.620e+01 3.948e+01 -0.664 0.5075 litrate0.86 -3.576e+01 4.950e+01 -0.722 0.4707 litrate0.864 -4.482e+01 6.274e+01 -0.714 0.4755 litrate0.872 -1.946e+01 2.715e+01 -0.717 0.4739 litrate0.877 -2.710e+01 3.702e+01 -0.732 0.4646 litrate0.879 -3.460e+01 5.147e+01 -0.672 0.5020 litrate0.886 -3.276e+01 4.860e+01 -0.674 0.5008 litrate0.889 -4.120e+01 5.755e+01 -0.716 0.4746 litrate0.904 -2.282e+01 2.985e+01 -0.764 0.4453 litrate0.91 -3.478e+01 5.037e+01 -0.691 0.4904 litrate0.923 -1.762e+01 2.551e+01 -0.691 0.4902 litrate0.925 -2.445e+01 3.611e+01 -0.677 0.4990 litrate0.926 -2.995e+01 4.565e+01 -0.656 0.5123 litrate0.928 -2.839e+01 3.933e+01 -0.722 0.4710 litrate0.937 -2.571e+01 3.795e+01 -0.677 0.4986 litrate0.94 -2.109e+01 3.051e+01 -0.691 0.4900 litrate0.959 -2.078e+01 2.895e+01 -0.718 0.4735 litrate0.96 -3.403e+01 4.798e+01 -0.709 0.4787 litrate0.962 -4.084e+01 5.755e+01 -0.710 0.4785 litrate0.971 -3.743e+01 5.247e+01 -0.713 0.4761 litrate0.98 -3.709e+01 5.170e+01 -0.717 0.4737 litrate0.986 -2.663e+01 4.437e+01 -0.600 0.5488 litrate0.991 -3.045e+01 4.166e+01 -0.731 0.4654 litrate1 -2.732e+01 4.459e+01 -0.613 0.5405 africaNA NA NA NA imr2.160e+00 9.357e-01 2.309 0.0216 * although it should result in something similar to this: Coefficients: (1 not defined because of singularities) Estimate Std. Error t value Pr(|t|) (Intercept)1.216e+01 5.771e+01 0.211 0.8332 factor(year)2006 -1.403e+00 5.777e-01 -2.429 0.0157 * factor(year)2007 -2.799e-01 7.901e-01 -0.354 0.7234 log(gdppcpppconst) 2.762e-01 5.517e+00 0.050 0.9601 log(gdppcpppconstAII) -1.344e-01 9.025e-01 -0.149 0.8817 log(co2eemisspc) 5.655e+00 2.903e+00 1.948 0.0523 . log(co2eemisspcAII) -1.411e-01 4.245e-01 -0.332 0.7399 log(dist) -2.938e-01 4.023e-01 -0.730 0.4658 fdiboth
Re: [R] Where the data file is stored?
You're not seeing the .Rdata file containing the data objects. Try: list.files(getwd(),full.name=TRUE, all.files=TRUE) Hi Keith, Thanks for your advice On R console running list.files(getwd(),full.name=TRUE,all.files=TRUE) The output is similar to running following command on Ubuntu terminal; ls -al /home/userA/ Except the latter showing which are files and which are directories B.R. satimis - Original Message From: Keith Jewell k.jew...@campden.co.uk To: r-h...@stat.math.ethz.ch Sent: Thu, August 12, 2010 8:47:03 PM Subject: Re: [R] Where the data file is stored? You're not seeing the .Rdata file containing the data objects. Try: list.files(getwd(),full.name=TRUE, all.files=TRUE) Stephen Liu sati...@yahoo.com wrote in message news:961426.85478...@web113203.mail.gq1.yahoo.com... - Original Message From: Alain Guillet alain.guil...@uclouvain.be To: Stephen Liu sati...@yahoo.com Cc: r-help@r-project.org Sent: Thu, August 12, 2010 5:28:32 PM Subject: Re: [R] Where the data file is stored? You can find your current working directory with the getwd() function. Hi Alain, Thanks for your advice. getwd() [1] /home/userA list.files(getwd()) [1] Desktop Documents Downloads [4] examples.desktop last-packages.txt Music [7] myR petdrug.csv Pictures [10] PublicR Templates [13] Videos list.files(getwd(),full.name=TRUE) [1] /home/userA/Desktop [2] /home/userA/Documents [3] /home/userA/Downloads [4] /home/userA/examples.desktop [5] /home/userA/last-packages.txt [6] /home/userA/Music [7] /home/userA/myR [8] /home/userA/petdrug.csv [9] /home/userA/Pictures [10] /home/userA/Public [11] /home/userA/R [12] /home/userA/Templates [13] /home/userA/Videos How to show on the printout which is directory? TIA B.R. Stephen L On 12-Aug-10 11:22, Stephen Liu wrote: - Original Message From: Philipp Pagelp.pa...@wzw.tum.de To: r-help@r-project.org Sent: Thu, August 12, 2010 3:54:53 PM Subject: Re: [R] Where the data file is stored? You dont't tell us what you did to create a datafile - to me it sounds like you created an object (probably a data frame) in your R workspace. If that's the case it is stored in a file called .RData in your current work directory (together with other variables in your workspace). If that is not what you did please give us mre information. Hi Philipp, Yes, it is data frame. I have run the step write.csv ... Other advice noted. Thanks B.R. Stephen L __ 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. -- Alain Guillet Statistician and Computer Scientist SMCS - IMMAQ - Université catholique de Louvain Bureau c.316 Voie du Roman Pays, 20 B-1348 Louvain-la-Neuve Belgium tel: +32 10 47 30 50 __ 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] Creating vectors
I think I understand your question and the following would produce the result you've posted. (x - matrix(c(1, 2, 2, 3, 1, 2, 1, 2, 3, 4), nrow=5, byrow=TRUE)) On Aug 12, 2010, at 5:41 AM, clips10 wrote: Thanks for the help, I tried to apply this to a vector with two columns, well I suppose it is not a vector but for instance like this: [,1] [,2] [1,]1 2 [2,]2 3 [3,]1 2 [4,]1 2 [5,]3 4 and return a vector : 1,2,1,1,3, so that it recognises both columns together. I tried match(x, unique(x)) as earlier suggested but this returns a vector of length 10 as opposed to 5, even though unique(x) does remove the repeated rows. Sorry if this is confusing, I am trying to do as originally posted but with 2 columns Thanks -- View this message in context: http://r.789695.n4.nabble.com/Creating-vectors-tp2321440p2322646.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] normality tests
?RsiteSearch or consult package sos. Learn how to use R's search resources! -- Bert Gunter Genentech Nonclinical Statistics On Wed, Aug 11, 2010 at 8:21 PM, Geoffrey Smith g...@asu.edu wrote: Hello, does anyone know how to compute the following two normality tests using R: (1) the Kiefer-Salmon (1983) statistic, Economics Letters 11, p. 123-127 (2) the modified Shapiro-Wilk statistic? Thank you very much. Geoff [[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] Median abline how-to ?
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of David martin Sent: Thursday, August 12, 2010 7:42 AM To: r-h...@stat.math.ethz.ch Subject: [R] Median abline how-to ? Hi, I'm newbie with R and don't really know how to add a median line to each of the groups that is not all the plot long. Here is a small working code that i have adapted for my purpose. If somebody could tell me how to draw median lines on each group and not all plot long. ctl - c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) trt - c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69) group - gl(2,10,20, labels=c(Ctl,Trt)) weight - c(ctl, trt) ctlmed - median(weight[which(group == Ctl)]) trtmed - median(weight[which(group == Trt)]) plot.default(weight ~ group,axes=F) axis(2,col.axis = blue,las=1,cex.axis=0.7,xpd=TRUE) axis(1, labels=levels(group),at=1:length(unique(group)),las=2,cex.axis=0.7) You can use segments(), along with par(cxy), which gives the size of a typical plotting character in user units. E.g., w - par(cxy)[1] * 1.5 # width of pch times 1.5, half-width of median line ix - seq_len(nlevels(group)) mediansByGroup - tapply(weight, group, median) segments(x0=ix-w, x1=ix+w, y0=mediansByGroup, col=ix) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- #horizontal abline(h = ctlmed, col = blue, lwd = 2) # ?? how to make abline shorter ? abline(h = trtmed, col = red, lwd = 2) box(bty=c) ps: At this stage the boxplot is not interesting for me. thanks, david __ 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] Where the data file is stored?
Hi Barry, Following 2 commands are useful to me; row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),isdir)) showing directories. row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),!isdir)) showing files What is ! for? TIA B.R. Stephen L - Original Message From: Barry Rowlingson b.rowling...@lancaster.ac.uk To: Stephen Liu sati...@yahoo.com Cc: r-help@r-project.org Sent: Thu, August 12, 2010 8:05:10 PM Subject: Re: [R] Where the data file is stored? On Thu, Aug 12, 2010 at 12:37 PM, Stephen Liu sati...@yahoo.com wrote: - Original Message From: Alain Guillet alain.guil...@uclouvain.be To: Stephen Liu sati...@yahoo.com Cc: r-help@r-project.org Sent: Thu, August 12, 2010 5:28:32 PM Subject: Re: [R] Where the data file is stored? You can find your current working directory with the getwd() function. Hi Alain, Thanks for your advice. getwd() [1] /home/userA list.files(getwd()) [1] Desktop Documents Downloads [4] examples.desktop last-packages.txt Music [7] myR petdrug.csv Pictures [10] PublicR Templates [13] Videos list.files(getwd(),full.name=TRUE) [1] /home/userA/Desktop [2] /home/userA/Documents [3] /home/userA/Downloads [4] /home/userA/examples.desktop [5] /home/userA/last-packages.txt [6] /home/userA/Music [7] /home/userA/myR [8] /home/userA/petdrug.csv [9] /home/userA/Pictures [10] /home/userA/Public [11] /home/userA/R [12] /home/userA/Templates [13] /home/userA/Videos How to show on the printout which is directory? TIA Use file.info and check the $isdir part of the returned data frame. For example, to get names of only directories in your working dir, do: row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),isdir)) a quick modification gets you not-directories (which will be plain files plus special files): row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),!isdir)) see ?file.info and ?files Barry __ 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] XML file from scratch using XML package
I would like to build an XML file from scratch using the XML package. I would like to save the following vector in it: 1:10 Could someone help me by briefly outlining how I go about it ? And maybe provide a few lines of code? Thanks! Mark Mark Heckmann Dipl. Wirt.-Ing. cand. Psych. Vorstraße 93 B01 28359 Bremen Blog: www.markheckmann.de R-Blog: http://ryouready.wordpress.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.
Re: [R] Median abline how-to ?
thanks !!! On 12/08/10 17:49, William Dunlap wrote: segments(x0=ix-w, x1=ix+w, y0=mediansByGroup, col=ix) __ 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] Where the data file is stored?
On Aug 12, 2010, at 11:51 AM, Stephen Liu wrote: Hi Barry, Following 2 commands are useful to me; row .names(subset(file.info(list.files(getwd(),full.name=TRUE)),isdir)) showing directories. row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),! isdir)) showing files What is ! for? TIA ?! (learn to use R help facilities!) B.R. Stephen L - Original Message From: Barry Rowlingson b.rowling...@lancaster.ac.uk To: Stephen Liu sati...@yahoo.com Cc: r-help@r-project.org Sent: Thu, August 12, 2010 8:05:10 PM Subject: Re: [R] Where the data file is stored? On Thu, Aug 12, 2010 at 12:37 PM, Stephen Liu sati...@yahoo.com wrote: - Original Message From: Alain Guillet alain.guil...@uclouvain.be To: Stephen Liu sati...@yahoo.com Cc: r-help@r-project.org Sent: Thu, August 12, 2010 5:28:32 PM Subject: Re: [R] Where the data file is stored? You can find your current working directory with the getwd() function. Hi Alain, Thanks for your advice. getwd() [1] /home/userA list.files(getwd()) [1] Desktop Documents Downloads [4] examples.desktop last-packages.txt Music [7] myR petdrug.csv Pictures [10] PublicR Templates [13] Videos list.files(getwd(),full.name=TRUE) [1] /home/userA/Desktop [2] /home/userA/Documents [3] /home/userA/Downloads [4] /home/userA/examples.desktop [5] /home/userA/last-packages.txt [6] /home/userA/Music [7] /home/userA/myR [8] /home/userA/petdrug.csv [9] /home/userA/Pictures [10] /home/userA/Public [11] /home/userA/R [12] /home/userA/Templates [13] /home/userA/Videos How to show on the printout which is directory? TIA Use file.info and check the $isdir part of the returned data frame. For example, to get names of only directories in your working dir, do: row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),isdir)) a quick modification gets you not-directories (which will be plain files plus special files): row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),! isdir)) see ?file.info and ?files Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Where the data file is stored?
On Thu, Aug 12, 2010 at 4:51 PM, Stephen Liu sati...@yahoo.com wrote: Hi Barry, Following 2 commands are useful to me; row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),isdir)) showing directories. row.names(subset(file.info(list.files(getwd(),full.name=TRUE)),!isdir)) showing files What is ! for? TIA It means 'not'. So TRUE becomes FALSE and FALSE becomes TRUE. And NA stays NA. Use it when you need to invert logical values. Barry __ 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] Regression Error: Otherwise good variable causes singularity. Why?
@JLucke: As for the africa variable: I took it out of the model, so that we can exclude this variable itself and collinearity between the africa and the litrate variable as causes for the litrate-problem. This also removed the singularity remark at the top. However, the problem with litrate-variable seen as many factors remains. Just to clarify: The second results table is fictional to explain where I was headed with my regression. Anyway, thanks for the quick answer. @David: Thanks for the pointer. It was in fact a bad variable, but I created it myself. I changed the set halfway in between my calculations and thought I had adjusted everything. It turns out, that I forgot to adjust the set-length which is re-set in between the two steps of my Heckman-procedure. In any case: Thanks for the quick and helpful reply. :-) -- View this message in context: http://r.789695.n4.nabble.com/Regression-Error-Otherwise-good-variable-causes-singularity-Why-tp2322780p2322925.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] R install: documentation
Hello, when I ran R CMD INSTALL circular_0.4.tar.gz on a machine with Debian stable, the command also created the documentation in various fomrats (latex, html, online). The same command on Debian testing only provides the online documentation. How can I persuade R to create the different formats also on Debian testing? Both machines have texinfo installed. Cheers, Tim -- -- Tim Gruene Institut fuer anorganische Chemie Tammannstr. 4 D-37077 Goettingen GPG Key ID = A46BEE1A signature.asc Description: Digital signature __ 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] non-linear regression for 3D data
On 12/08/2010 10:35 AM, szisziszilvi wrote: I've tried lm, but something is wrong. I've made a test dataset of 599 data points, my original equation is zz = 1 +0.5*xx -3.2*xx*xx -1*yy +4.2*yy*yy but the R gives this result: --- mp - read.csv(file=sample.csv,sep=;,header=TRUE) lm(zz ~ poly(xx,2) + poly(yy,2), data=mp) Call: lm(formula = zz ~ poly(xx, 2) + poly(yy, 2), data = mp) Coefficients: (Intercept) poly(xx, 2)1 poly(xx, 2)2 poly(yy, 2)1 poly(yy, 2)2 25.86 -2239.86 -595.01 2875.54776.84 --- which is definitely not the original. :( I don't think you are interpreting the coefficients properly. The basis functions are orthogonal polynomials, not xx and xx^2, so the coefficients won't match the ones you used in your definition. You should compare the predictions of the model, e.g. by looking at range(predict(lm(zz ~ poly(xx,2) + poly(yy,2), data=mp)) - zz) If you insist on the power basis, just fit the model as lm(zz ~ xx + I(xx^2) + yy + I(yy^2), data=mp) but you might get less accurate predictions due to increased collinearity. 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] R install: documentation
On 12/08/2010 12:10 PM, Tim Gruene wrote: Hello, when I ran R CMD INSTALL circular_0.4.tar.gz on a machine with Debian stable, the command also created the documentation in various fomrats (latex, html, online). The same command on Debian testing only provides the online documentation. How can I persuade R to create the different formats also on Debian testing? Install an obsolete version of R. By default current versions only install one format, and generate the others on request. Duncan Murdoch Both machines have texinfo installed. Cheers, Tim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help usin scan on large matrix (caveats to what has been discussed before)
Martin Tomko wrote: Hi Peter, apologies, too fast copying and pasting. So, here is the explanation: f-C:/test/mytab.txt; R-readLines(con=f); where mytab.txt is a table formatted as noted in previous post (space delimited, with header, rownames, containing integers). Now, my understandign of scan was that I have to specify the FULL number of values in it (examples specify things like 200*2000 for a matrix etc). That's why I thought that I need to do cols*rows as well. Avoiding the first line with headers is simple, avoiding the first column is not - hence my questions. Sorry, the corrected, matching parentheses are here - why did the previous execute is a wonder... c-scan(file=f,what=rep(c(list(NULL),rep(list(0L),cols-1)),rows-1), skip=1) here, my reasoning was: * c(list(NULL),rep(list(0L),cols-1)) specifies a template for any line (first elelement to be ignored = NULL, it is a string in the table specified, and then a repetition of integers - I am still not sure how you derived 0L, and what it means and where to find a doc for that.); * the previous needs to be repeated rows-1 times, hence what=rep(c(list(NULL),rep(list(0L),cols-1)),rows-1) I do nto understand the following: You need an unlist(c). And more than likely NOT byrow=TRUE. However, I think do.call(cbind,c) should do the trick more easily. what will unlist(c) do; why should it not be bywrow=TRUE, and how would you go about integrating do.call(cbind,c) with matrix. Apologies to naive questions, I am a newbie, in principle. At this point I think you need to actually try my suggestions, and maybe read the documentation again. Explaining how you have misunderstood the documentation is not going to help... -- Peter Dalgaard Center for Statistics, Copenhagen Business School Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@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] Running something without a loop when the result from the previous iteration is require for the current iteration
Thanks everyone for your help and advice. For the R-help archives, here is what I ended up doing. First creating a separate function to handle one day at a time - byrow.gen2 - function(genmat,rownum,use1,use2,num,ortho_obs_used){ prev = rownum-1 ran = runif(length(rownum),0,1) if(genmat[rownum,use1]==0 genmat[rownum,use2]==0 genmat[prev,num]==0) { if(ranortho_obs_used$Pr[1]){ genmat[rownum,num] = 1 }else{ genmat[rownum,num] = 0} } if(genmat[rownum,use1]==0 genmat[rownum,use2]==0 genmat[prev,num]==1) { if(ranortho_obs_used$Pr[4]){ genmat[rownum,num] = 1 }else{ genmat[rownum,num] = 0} } if(genmat[rownum,use1]==0 genmat[rownum,use2]==1 genmat[prev,num]==0) { if(ranortho_obs_used$Pr[2]){ genmat[rownum,num] = 1 }else{ genmat[rownum,num] = 0} } if(genmat[rownum,use1]==0 genmat[rownum,use2]==1 genmat[prev,num]==1) { if(ranortho_obs_used$Pr[5]){ genmat[rownum,num] = 1 }else{ genmat[rownum,num] = 0} } if(genmat[rownum,use1]==1 genmat[rownum,use2]==0 genmat[prev,num]==0) { if(ranortho_obs_used$Pr[3]){ genmat[rownum,num] = 1 }else{ genmat[rownum,num] = 0} } if(genmat[rownum,use1]==1 genmat[rownum,use2]==0 genmat[prev,num]==1) { if(ranortho_obs_used$Pr[7]){ genmat[rownum,num] = 1 }else{ genmat[rownum,num] = 0} } if(genmat[rownum,use1]==1 genmat[rownum,use2]==1 genmat[prev,num]==0) { if(ranortho_obs_used$Pr[6]){ genmat[rownum,num] = 1 }else{ genmat[rownum,num] = 0} } if(genmat[rownum,use1]==1 genmat[rownum,use2]==1 genmat[prev,num]==1) { if(ranortho_obs_used$Pr[8]){ genmat[rownum,num] = 1 }else{ genmat[rownum,num] = 0} } genmat } Then applying the foreach package in the original function event.gen3 = function(genmat,use1,use2,num,ortho_obs_used){ rownum = 2:nrow(genmat) test = foreach(r=iter(rownum,by='row')) %dopar% { genmat = byrow.gen2(genmat,r,use1,use2,num,ortho_obs_used) } rm(test) genmat } The final results were exactly as I needed them to be in my initial post, but the processing time dropped from 2 seconds per station to 0.05 seconds per station. Thanks to everyone for giving me the advice and the idea to try this! Adrienne On Thu, Aug 12, 2010 at 8:15 AM, Adrienne Wootten amwoo...@ncsu.edu wrote: Not quite what I was trying to say. The process generates a random uniform number between 0 and 1 and compares to a specific conditional probability. It is looking for this in particular: random number Pr( rain(station=i,day=d)=1 | rain(station=i,day=d-1)=0 rain(station=j,day=d)=0 rain(station=k,day=d)=0) In this particular example, if the random number is less than the probability the value for station i and day d will be given as 1, otherwise it will be zero. There are 8 possible combinations. i is the station to be generated, j and k are the two stations most strongly correlated with station i. Stations j and k have already been generated in the example I gave previously. So I want to know given what is going on at stations j and k during day d and at station i for day d-1 if the value for station i day d will be 1 or 0. Hope this provides some clarification. A On Thu, Aug 12, 2010 at 3:21 AM, Petr PIKAL petr.pi...@precheza.czwrote: Hi without toy example it is rather complicated to check your function. So only few remarks: Instead of generating 1 random number inside a loop generate whole vector of random numbers outside a loop and choose a number Do not mix ifelse with if. ifelse is intended to work with whole vector. Work with matrices instead of data frames whenever possible if speed is an issue. If I understand correctly you want to put 1 or 0 into one column based on: previous value in the same column comparison of some random number with predefined probabilities in vector of 6 values So here is vectorised version of your 4 ifs based on assumption 0 in col1 0 in col 2 = 5 0 in col1 1 in col 2 = 9 1 in col1 0 in col 2 = 6 1 in col1 1 in col 2 =10 col1-sample(1:2, 20, replace=T) col2-sample(c(4,8), 20, replace=T) col1+col2 [1] 5 6 9 6 6 5 9 10 9 9 6 9 10 6 10 9 10 9 5 5 cols-as.numeric(as.factor(col1+col2)) cols [1] 1 2 3 2 2 1 3 4 3 3 2 3 4 2 4 3 4 3 1 1 And here is computed comparison of six values p (ortho obs used) with 20 generated random values ran-runif(20) p-runif(8) comparison - outer(ran,p, ) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [2,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE [3,] FALSE TRUE FALSE TRUE FALSE TRUE TRUE FALSE [4,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE [5,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE [6,] FALSE TRUE FALSE TRUE FALSE TRUE FALSE FALSE [7,] FALSE TRUE FALSE TRUE FALSE TRUE FALSE FALSE [8,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [9,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [10,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE [11,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE [12,] FALSE TRUE FALSE TRUE TRUE TRUE TRUE TRUE
[R] multicore mclapply error
I'm running r 2. on a mac running 10.6.4 and a dual-core macbook pro. I'm having a funny time with multicore. When I run it with 2 cores, mclapply, R borks with the following error. The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec(). Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug. If, however, I crank the # of cores back to 1, it runs just fine. The code looks as follows: mmi_fits-mclapply(responses, function(a_response){ gmult-glmulti(glm(make_formula(a_response, sp), data=df, family=binomial)) return(gmult) }, mc.cores=2) -Jarrett __ 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] reading fixed width format data with 2 types of lines
Hi, I know how to read fixed width format data with read.fwf, but suddenly I need to read in a large number of old fwf files with 2 types of lines. Lines that begin with 3 in first column carry one set of variables, and lines that begin with 4 carry another set, like this: … 3A00206546L07004901609004599 1015002 001001008010004002004007003 001 3A00206546L07004900609003099 1029001002001001006014002 3A00206546L07004900229000499 1015001001 3A00206546L070049001692559049033 1015 018036024 3A00206546L07004900229000499 1001 002 4A00176546L06804709001011100060651640015001001501063 065914 4A00176546L068047090010111000407616 1092 095614 4A00196546L098000100010111001706214450151062 065914 4A00176546L068047090010111000505913 1062 065914 4A00196546L09800010001011100260472140002001000201042 046114 4A00196546L0980001000101110025042214501200051042 046114 4A00196546L09800010001011100290372140005001220501032 036214 … I have searched for tricks to do this but I must not have used the right keywords, I found nothing. I suppose I could read the entire file as a single character variable for each line, then subset for lines that begin with 3 and save this in an ascii file that will then be reopened with a read.fwf call, and do the same with lines that begin with 4. But this does not appear to me to be very elegant nor efficient… Is there a better method? Thanks in advance, Denis Chabot __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] multicore mclapply error
On Thu, 12 Aug 2010, Jarrett Byrnes wrote: I'm running r 2. on a mac running 10.6.4 and a dual-core macbook pro. I'm having a funny time with multicore. When I run it with 2 cores, mclapply, R borks with the following error. The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec(). Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug. If, however, I crank the # of cores back to 1, it runs just fine. The code looks as follows: mmi_fits-mclapply(responses, function(a_response){ gmult-glmulti(glm(make_formula(a_response, sp), data=df, family=binomial)) return(gmult) }, mc.cores=2) You don't say what glmulti() is. If you mean the function from glmulti package, that package uses Java and rjava, and it wouldn't be altogether surprising if the connection to Java or the Java environment reacted badly to being forked. -thomas Thomas Lumley Professor of Biostatistics University 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] rpart package
Hi, I am a brand new user and may be my question is too simple. I have R on our (not Unix) server. I am trying to build a decision tree and the error message says couldn't find function rpart. Does it mean I have to ask our server guy to install an additional package? Thank you, Olga [[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] Creating vectors
I think your code will work but only for the two columns I gave. I used those as an example but my actual data is 200 in length with two columns and I need code that will give a label to each unique pair but still have the original length for instance, one that will turn something such as [,1] [,2] [1,] 12 [2,] 23 [3,] 12 [4,] 46 [5,] 23 1 into one vector of length 5, giving a number for each unique pair (1,2,1,3,4) so that the same pairs get the same number. but my actual data is of length 200 with two columns Thanks. -- View this message in context: http://r.789695.n4.nabble.com/Creating-vectors-tp2321440p2322933.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] Creating vectors
You can use following scriptI think #create a vector of random numbers on which to test script v-sample(1:3,size=90,replace=TRUE) #creates two matrixes out of vector v which can be assigned to M to test script M2-matrix(v,ncol=2) M3-matrix(v,ncol=3) M- #Assign you're matrix or a testmatrix to M and run script result-numeric() imaks-length(M[,1]) jmaks-length(unique(M)[,1]) for (i in 1:imaks){ for (j in 1:jmaks){ if (sum(M[i,]==unique(M)[j,])==length(M[1,])) { result[i]-j } } } result ## The script uses loops so its not efficient - in other words its slow and might be too slow for larger matrixes. BR Jesper -- View this message in context: http://r.789695.n4.nabble.com/Creating-vectors-tp2321440p2323090.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] multicore mclapply error
Ah. Indeed, this is from the glmulti. I had not realized there would be problems using Java. Is there a way around this to still use a multicore approach? For what other packages that use multiple cores will this not be a problem? -Jarrett On Aug 12, 2010, at 11:02 AM, Thomas Lumley wrote: On Thu, 12 Aug 2010, Jarrett Byrnes wrote: I'm running r 2. on a mac running 10.6.4 and a dual-core macbook pro. I'm having a funny time with multicore. When I run it with 2 cores, mclapply, R borks with the following error. The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec(). Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug. If, however, I crank the # of cores back to 1, it runs just fine. The code looks as follows: mmi_fits-mclapply(responses, function(a_response){ gmult-glmulti(glm(make_formula(a_response, sp), data=df, family=binomial)) return(gmult) }, mc.cores=2) You don't say what glmulti() is. If you mean the function from glmulti package, that package uses Java and rjava, and it wouldn't be altogether surprising if the connection to Java or the Java environment reacted badly to being forked. -thomas Thomas Lumley Professor of Biostatistics University 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.
Re: [R] rpart package
Olga Shaganova wrote: Hi, I am a brand new user and may be my question is too simple. I have R on our (not Unix) server. I am trying to build a decision tree and the error message says couldn't find function rpart. Does it mean I have to ask our server guy to install an additional package? You have to load the rpart package library(rpart) If that succeeds, you should have the rpart function available. I think rpart is a recommended package, so you should be OK. __ 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 dot plots with size, shape affecting dot characteristics
On Wed, Aug 11, 2010 at 10:14 PM, Brian Tsai btsa...@gmail.com wrote: Hi all, I'm interested in doing a dot plot where *both* the size and color (more specifically, shade of grey) change with the associated value. I've found examples online for ggplot2 where you can scale the size of the dot with a value: http://had.co.nz/ggplot2/graphics/6a053f23cf5bdfe5155ab53d345a5e0b.png Or scale the color with the value: http://had.co.nz/ggplot2/graphics/b17bf93530ff6695afb366e65677c17f.png both of which are from here: http://had.co.nz/ggplot2/geom_point.html but I've been playing around with ggplot2 and couldn't figure out how to do both at the same time - ideally i want size to increase with a value, and the shade of grey to get lighter with increasing value. qplot(mpg, wt, data = mtcars, colour = qsec, size = qsec) + scale_colour_grey() Hadley -- 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.
[R] Error in rowSums
Hi I am trying to calculate the row sums of a matrix i have created The matrix ( FeaturePresenceMatrix) has been created by 1) Read csv 2) Removing unnecesarry data using [-1:4,] command 3) replacing all the NA values with as.numeric(0) and all others with as.numeric (1) When I carry out the command TotalFeature - rowrowSums(FeaturePresenceMatrix, na.rm = TRUE) I get the following error. Error in rowSums(FeaturePresenceMatrix, na.rm = TRUE) : 'x' must be numeric Any tips onhow I can get round this? Thanks in Advance Amit __ 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] Error in rowSums
Amit Patel wrote: Hi I am trying to calculate the row sums of a matrix i have created The matrix ( FeaturePresenceMatrix) has been created by 1) Read csv 2) Removing unnecesarry data using [-1:4,] command 3) replacing all the NA values with as.numeric(0) and all others with as.numeric (1) When I carry out the command TotalFeature - rowrowSums(FeaturePresenceMatrix, na.rm = TRUE) I get the following error. Error in rowSums(FeaturePresenceMatrix, na.rm = TRUE) : 'x' must be numeric Any tips onhow I can get round this? Yes, follow the posting guide and give the list a reproducible example. We don't know a critical piece of information, the class of your data. We know it's *not* numeric though, which is what it needs to be. Use ?class, ?str, and possibly give us a small sample with ?dput. That way, we can reproduce the error. __ 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] Error in rowSums
Yes, please do as Erik said in the future but here's one way to do it. (A - matrix(data = rnorm(n = 9, mean = 0, sd = 1), nrow = 3, ncol = 3, byrow = FALSE, dimnames = NULL)) matrix(rowSums(A)) On Aug 12, 2010, at 11:28 AM, Amit Patel wrote: Hi I am trying to calculate the row sums of a matrix i have created The matrix ( FeaturePresenceMatrix) has been created by 1) Read csv 2) Removing unnecesarry data using [-1:4,] command 3) replacing all the NA values with as.numeric(0) and all others with as.numeric (1) When I carry out the command TotalFeature - rowrowSums(FeaturePresenceMatrix, na.rm = TRUE) I get the following error. Error in rowSums(FeaturePresenceMatrix, na.rm = TRUE) : 'x' must be numeric Any tips onhow I can get round this? Thanks in Advance Amit __ 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] Error in rowSums
Another suggestion: compare -1:4 with -(1:4) -Peter Ehlers On 2010-08-12 12:28, Amit Patel wrote: Hi I am trying to calculate the row sums of a matrix i have created The matrix ( FeaturePresenceMatrix) has been created by 1) Read csv 2) Removing unnecesarry data using [-1:4,] command 3) replacing all the NA values with as.numeric(0) and all others with as.numeric (1) When I carry out the command TotalFeature- rowrowSums(FeaturePresenceMatrix, na.rm = TRUE) I get the following error. Error in rowSums(FeaturePresenceMatrix, na.rm = TRUE) : 'x' must be numeric Any tips onhow I can get round this? Thanks in Advance Amit __ 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] shrout fleiss ICC´s with varying numbers o f judges
hi Peter, There's no single function for ICC with variable number of judges. To estimate the variances in that case you need hierarchical linear modeling. I posted code for this at Stackoverflow in answer to your question there: http://stackoverflow.com/questions/3205176/ Stats questions get answered rarely on Stackoverflow but you may want to try the new site focused on statistics: http://area51.stackexchange.com/proposals/33/statistical-analysis hope that helps, Turadg Aleahmad -- View this message in context: http://r.789695.n4.nabble.com/shrout-fleiss-ICC-s-with-varying-numbers-of-judges-tp2257858p2323230.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] conditional selection of dataframe rows
Dear helpeRs, I have a dataframe (14947 x 27) containing measurements collected every 5 seconds at several different sampling locations. If one measurement at a given location is less than zero on a given day, I would like to delete all measurements from that location on that day. Here is a toy example: toy - data.frame(CH = rep(3:5,3), DAY = c(rep(4,5), rep(5,4)), SLOPE = c(seq(0.2,0.6, .1),seq(0.2, -0.1, -0.1))) In this example, row 9 has a negative measurement for Chamber 5, so I would like to delete row 6, which is the same Chamber on the same day, but not row 3, which is the same chamber on a different day. In the full dataframe, there are, of course, many more days. Is there a handy R way to do this? Thank you for the assistance. Toby __ 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] x-axis label print in 45 degree
Hi how can print x-axis labels in 45 degree in boxplot() (or plot in general)? I can use las=2 to print in 90 degree, but it looks ugly. Is there a simple option to do 45 degree easily? Thanks John __ 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] x-axis label print in 45 degree
On Aug 12, 2010, at 2:14 PM, array chip wrote: Hi how can print x-axis labels in 45 degree in boxplot() (or plot in general)? I can use las=2 to print in 90 degree, but it looks ugly. Is there a simple option to do 45 degree easily? Thanks John John, See R FAQ 7.27 How can I create rotated axis labels? 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] conditional selection of dataframe rows
On Aug 12, 2010, at 3:11 PM, Toby Gass wrote: Dear helpeRs, I have a dataframe (14947 x 27) containing measurements collected every 5 seconds at several different sampling locations. If one measurement at a given location is less than zero on a given day, I would like to delete all measurements from that location on that day. Here is a toy example: toy - data.frame(CH = rep(3:5,3), DAY = c(rep(4,5), rep(5,4)), SLOPE = c(seq(0.2,0.6, .1),seq(0.2, -0.1, -0.1))) In this example, row 9 has a negative measurement for Chamber 5, so I would like to delete row 6, which is the same Chamber on the same day, but not row 3, which is the same chamber on a different day. In the full dataframe, there are, of course, many more days. Is there a handy R way to do this? toy[ - which(toy$SLOPE 0 ) , ] Thank you for the assistance. Toby __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] conditional selection of dataframe rows
Try this: subset(toy, !rowSums(mapply(is.element, toy[c('CH', 'DAY')], subset(toy, SLOPE 0, CH:DAY))) 1 | SLOPE 0) On Thu, Aug 12, 2010 at 4:11 PM, Toby Gass tobyg...@warnercnr.colostate.edu wrote: Dear helpeRs, I have a dataframe (14947 x 27) containing measurements collected every 5 seconds at several different sampling locations. If one measurement at a given location is less than zero on a given day, I would like to delete all measurements from that location on that day. Here is a toy example: toy - data.frame(CH = rep(3:5,3), DAY = c(rep(4,5), rep(5,4)), SLOPE = c(seq(0.2,0.6, .1),seq(0.2, -0.1, -0.1))) In this example, row 9 has a negative measurement for Chamber 5, so I would like to delete row 6, which is the same Chamber on the same day, but not row 3, which is the same chamber on a different day. In the full dataframe, there are, of course, many more days. Is there a handy R way to do this? Thank you for the assistance. Toby __ 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] conditional selection of dataframe rows
On Aug 12, 2010, at 2:11 PM, Toby Gass wrote: Dear helpeRs, I have a dataframe (14947 x 27) containing measurements collected every 5 seconds at several different sampling locations. If one measurement at a given location is less than zero on a given day, I would like to delete all measurements from that location on that day. Here is a toy example: toy - data.frame(CH = rep(3:5,3), DAY = c(rep(4,5), rep(5,4)), SLOPE = c(seq(0.2,0.6, .1),seq(0.2, -0.1, -0.1))) In this example, row 9 has a negative measurement for Chamber 5, so I would like to delete row 6, which is the same Chamber on the same day, but not row 3, which is the same chamber on a different day. In the full dataframe, there are, of course, many more days. Is there a handy R way to do this? Thank you for the assistance. Toby Not fully tested, but here is one possibility: toy CH DAY SLOPE 1 3 4 0.2 2 4 4 0.3 3 5 4 0.4 4 3 4 0.5 5 4 4 0.6 6 5 5 0.2 7 3 5 0.1 8 4 5 0.0 9 5 5 -0.1 subset(toy, ave(SLOPE, CH, DAY, FUN = function(x) any(x 0)) == 0) CH DAY SLOPE 1 3 4 0.2 2 4 4 0.3 3 5 4 0.4 4 3 4 0.5 5 4 4 0.6 7 3 5 0.1 8 4 5 0.0 See ?ave and ?subset 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] conditional selection of dataframe rows
On Aug 12, 2010, at 2:24 PM, Marc Schwartz wrote: On Aug 12, 2010, at 2:11 PM, Toby Gass wrote: Dear helpeRs, I have a dataframe (14947 x 27) containing measurements collected every 5 seconds at several different sampling locations. If one measurement at a given location is less than zero on a given day, I would like to delete all measurements from that location on that day. Here is a toy example: toy - data.frame(CH = rep(3:5,3), DAY = c(rep(4,5), rep(5,4)), SLOPE = c(seq(0.2,0.6, .1),seq(0.2, -0.1, -0.1))) In this example, row 9 has a negative measurement for Chamber 5, so I would like to delete row 6, which is the same Chamber on the same day, but not row 3, which is the same chamber on a different day. In the full dataframe, there are, of course, many more days. Is there a handy R way to do this? Thank you for the assistance. Toby Not fully tested, but here is one possibility: toy CH DAY SLOPE 1 3 4 0.2 2 4 4 0.3 3 5 4 0.4 4 3 4 0.5 5 4 4 0.6 6 5 5 0.2 7 3 5 0.1 8 4 5 0.0 9 5 5 -0.1 subset(toy, ave(SLOPE, CH, DAY, FUN = function(x) any(x 0)) == 0) CH DAY SLOPE 1 3 4 0.2 2 4 4 0.3 3 5 4 0.4 4 3 4 0.5 5 4 4 0.6 7 3 5 0.1 8 4 5 0.0 This can actually be slightly shortened to: subset(toy, !ave(SLOPE, CH, DAY, FUN = function(x) any(x 0))) CH DAY SLOPE 1 3 4 0.2 2 4 4 0.3 3 5 4 0.4 4 3 4 0.5 5 4 4 0.6 7 3 5 0.1 8 4 5 0.0 HTH, 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] x-axis label print in 45 degree
On Aug 12, 2010, at 3:17 PM, Marc Schwartz wrote: On Aug 12, 2010, at 2:14 PM, array chip wrote: Hi how can print x-axis labels in 45 degree in boxplot() (or plot in general)? I can use las=2 to print in 90 degree, but it looks ugly. Is there a simple option to do 45 degree easily? Thanks John John, See R FAQ 7.27 How can I create rotated axis labels? http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f Although several of the hits in a search on rotate axis labels did point to the FAQ, there are probably other worked examples you could easily have found in the other 130+ hits at Baron's search page (including it appears on a cursory examination one from Marc in each of the last 7 years). HTH, Marc Schwartz -- . David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rpart package
Hi Olga, not directly related to your question. We have also a server installation and subsequently our IT department determines which version and packages I can use on R. A few days ago I have switched to R-portable. Works without any problems from my USB stick on any locked-for-installation Windows PC or open PC. I am not sure, but I have the feeling that my scripts are also faster executed. Good luck, Boris On 2010-08-12 8:18 PM, Erik Iverson wrote: Olga Shaganova wrote: Hi, I am a brand new user and may be my question is too simple. I have R on our (not Unix) server. I am trying to build a decision tree and the error message says couldn't find function rpart. Does it mean I have to ask our server guy to install an additional package? You have to load the rpart package library(rpart) If that succeeds, you should have the rpart function available. I think rpart is a recommended package, so you should be OK. __ 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. No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.851 / Virus Database: 271.1.1/3066 - Release Date: 08/12/10 08:34:00 __ 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] Plotting one dot in a graph
I'd like to plot a point at the intersection of these two curves. Thanks x - seq(.2, .3, by = .01) f - function(x){ x*cos(x)-2*x**2+3*x-1 } plot(x,f(x), type = l) abline(h = 0) __ 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] x-axis label print in 45 degree
Than you Marc. John - Original Message From: Marc Schwartz marc_schwa...@me.com To: array chip arrayprof...@yahoo.com Cc: r-help@r-project.org Sent: Thu, August 12, 2010 12:17:12 PM Subject: Re: [R] x-axis label print in 45 degree On Aug 12, 2010, at 2:14 PM, array chip wrote: Hi how can print x-axis labels in 45 degree in boxplot() (or plot in general)? I can use las=2 to print in 90 degree, but it looks ugly. Is there a simple option to do 45 degree easily? Thanks John John, See R FAQ 7.27 How can I create rotated axis labels? 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] x-axis label print in 45 degree
I searched with print x-axis label in 45 degree which didn't return useful links. Apparently I used poor search keywords. - Original Message From: David Winsemius dwinsem...@comcast.net To: Marc Schwartz marc_schwa...@me.com Cc: array chip arrayprof...@yahoo.com; r-help@r-project.org Sent: Thu, August 12, 2010 12:34:16 PM Subject: Re: [R] x-axis label print in 45 degree On Aug 12, 2010, at 3:17 PM, Marc Schwartz wrote: On Aug 12, 2010, at 2:14 PM, array chip wrote: Hi how can print x-axis labels in 45 degree in boxplot() (or plot in general)? I can use las=2 to print in 90 degree, but it looks ugly. Is there a simple option to do 45 degree easily? Thanks John John, See R FAQ 7.27 How can I create rotated axis labels? http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f Although several of the hits in a search on rotate axis labels did point to the FAQ, there are probably other worked examples you could easily have found in the other 130+ hits at Baron's search page (including it appears on a cursory examination one from Marc in each of the last 7 years). HTH, Marc Schwartz -- . David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plotting one dot in a graph
Yes, I'm playing around with other things but the points() function is what I was looking for. Thanks On Aug 12, 2010, at 12:47 PM, David Winsemius wrote: On Aug 12, 2010, at 3:43 PM, TGS wrote: I'd like to plot a point at the intersection of these two curves. Thanks x - seq(.2, .3, by = .01) f - function(x){ x*cos(x)-2*x**2+3*x-1 } plot(x,f(x), type = l) abline(h = 0) Would this just be the uniroot strategy applied to f? You then plot the x and y values with points() -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plotting one dot in a graph
Actually I spoke too soon David. I'm looking for a function that will either tell me which point is the intersection so that I'd be able to plot a point there. Or, if I have to solve for the roots in the ways which were demonstrated yesterday, then would I be able to specify what the horizontal line is, for instance in the case where y (is-not) 0? On Aug 12, 2010, at 12:47 PM, David Winsemius wrote: On Aug 12, 2010, at 3:43 PM, TGS wrote: I'd like to plot a point at the intersection of these two curves. Thanks x - seq(.2, .3, by = .01) f - function(x){ x*cos(x)-2*x**2+3*x-1 } plot(x,f(x), type = l) abline(h = 0) Would this just be the uniroot strategy applied to f? You then plot the x and y values with points() -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help usin scan on large matrix (caveats to what has been discussed before)
I did. Did not work. Did you try your code? The matrix did not result into integer numbers as expected. MY approach resulted in a correct scan result, at least. M. Martin Tomko wrote: Hi Peter, apologies, too fast copying and pasting. So, here is the explanation: f-C:/test/mytab.txt; R-readLines(con=f); where mytab.txt is a table formatted as noted in previous post (space delimited, with header, rownames, containing integers). Now, my understandign of scan was that I have to specify the FULL number of values in it (examples specify things like 200*2000 for a matrix etc). That's why I thought that I need to do cols*rows as well. Avoiding the first line with headers is simple, avoiding the first column is not - hence my questions. Sorry, the corrected, matching parentheses are here - why did the previous execute is a wonder... c-scan(file=f,what=rep(c(list(NULL),rep(list(0L),cols-1)),rows-1), skip=1) here, my reasoning was: * c(list(NULL),rep(list(0L),cols-1)) specifies a template for any line (first elelement to be ignored = NULL, it is a string in the table specified, and then a repetition of integers - I am still not sure how you derived 0L, and what it means and where to find a doc for that.); * the previous needs to be repeated rows-1 times, hence what=rep(c(list(NULL),rep(list(0L),cols-1)),rows-1) I do nto understand the following: You need an unlist(c). And more than likely NOT byrow=TRUE. However, I think do.call(cbind,c) should do the trick more easily. what will unlist(c) do; why should it not be bywrow=TRUE, and how would you go about integrating do.call(cbind,c) with matrix. Apologies to naive questions, I am a newbie, in principle. At this point I think you need to actually try my suggestions, and maybe read the documentation again. Explaining how you have misunderstood the documentation is not going to help... -- Peter Dalgaard Center for Statistics, Copenhagen Business School Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@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] Plotting one dot in a graph
On Aug 12, 2010, at 3:54 PM, TGS wrote: Actually I spoke too soon David. I'm looking for a function that will either tell me which point is the intersection so that I'd be able to plot a point there. Or, if I have to solve for the roots in the ways which were demonstrated yesterday, then would I be able to specify what the horizontal line is, for instance in the case where y (is-not) 0? Isn't the abline h=0 represented mathematically by the equation y=0 and therefore you are solving just for the zeros of f (whaich are the same as for (f-0)? If it were something more interesting, like solving the intersection of two polynomials, you would be solving for the zeros of the difference of the equations. Or maybe I have not understood what you were requesting? On Aug 12, 2010, at 12:47 PM, David Winsemius wrote: On Aug 12, 2010, at 3:43 PM, TGS wrote: I'd like to plot a point at the intersection of these two curves. Thanks x - seq(.2, .3, by = .01) f - function(x){ x*cos(x)-2*x**2+3*x-1 } plot(x,f(x), type = l) abline(h = 0) Would this just be the uniroot strategy applied to f? You then plot the x and y values with points() David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] reading fixed width format data with 2 types of lines
I don't know if it's elegant enough for you, but you could split the file into two files with 'grep ^3 file file_3' and 'grep ^4 file file_4' and then read them in separately. Tim On Thu, Aug 12, 2010 at 01:57:19PM -0400, Denis Chabot wrote: Hi, I know how to read fixed width format data with read.fwf, but suddenly I need to read in a large number of old fwf files with 2 types of lines. Lines that begin with 3 in first column carry one set of variables, and lines that begin with 4 carry another set, like this: … 3A00206546L07004901609004599 1015002 001001008010004002004007003 001 3A00206546L07004900609003099 1029001002001001006014002 3A00206546L07004900229000499 1015001001 3A00206546L070049001692559049033 1015 018036024 3A00206546L07004900229000499 1001 002 4A00176546L06804709001011100060651640015001001501063 065914 4A00176546L068047090010111000407616 1092 095614 4A00196546L098000100010111001706214450151062 065914 4A00176546L068047090010111000505913 1062 065914 4A00196546L09800010001011100260472140002001000201042 046114 4A00196546L0980001000101110025042214501200051042 046114 4A00196546L09800010001011100290372140005001220501032 036214 … I have searched for tricks to do this but I must not have used the right keywords, I found nothing. I suppose I could read the entire file as a single character variable for each line, then subset for lines that begin with 3 and save this in an ascii file that will then be reopened with a read.fwf call, and do the same with lines that begin with 4. But this does not appear to me to be very elegant nor efficient… Is there a better method? Thanks in advance, Denis Chabot __ 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. -- -- Tim Gruene Institut fuer anorganische Chemie Tammannstr. 4 D-37077 Goettingen GPG Key ID = A46BEE1A signature.asc Description: Digital signature __ 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] Plotting one dot in a graph
I was meaning something like the following: x - seq(.2, .3, by = .01) f - function(x){ x*cos(x)-2*x**2+3*x-1 } plot(x,f(x), type = l) abline(h = -.1) But I'm guessing uniroot will do this?---I haven't looked far into the uniroot function to see if it will solve this. On Aug 12, 2010, at 1:00 PM, David Winsemius wrote: On Aug 12, 2010, at 3:54 PM, TGS wrote: Actually I spoke too soon David. I'm looking for a function that will either tell me which point is the intersection so that I'd be able to plot a point there. Or, if I have to solve for the roots in the ways which were demonstrated yesterday, then would I be able to specify what the horizontal line is, for instance in the case where y (is-not) 0? Isn't the abline h=0 represented mathematically by the equation y=0 and therefore you are solving just for the zeros of f (whaich are the same as for (f-0)? If it were something more interesting, like solving the intersection of two polynomials, you would be solving for the zeros of the difference of the equations. Or maybe I have not understood what you were requesting? On Aug 12, 2010, at 12:47 PM, David Winsemius wrote: On Aug 12, 2010, at 3:43 PM, TGS wrote: I'd like to plot a point at the intersection of these two curves. Thanks x - seq(.2, .3, by = .01) f - function(x){ x*cos(x)-2*x**2+3*x-1 } plot(x,f(x), type = l) abline(h = 0) Would this just be the uniroot strategy applied to f? You then plot the x and y values with points() David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] conditional selection of dataframe rows
Thank you all for the quick responses. So far as I've checked, Marc's solution works perfectly and is quite speedy. I'm still trying to figure out what it is doing. :) Henrique's solution seems to need some columns somewhere. David's solution does not find all the other measurements, possibly with positive values, taken on the same day. Thank you again for your efforts. Toby On 12 Aug 2010 at 14:32, Marc Schwartz wrote: On Aug 12, 2010, at 2:24 PM, Marc Schwartz wrote: On Aug 12, 2010, at 2:11 PM, Toby Gass wrote: Dear helpeRs, I have a dataframe (14947 x 27) containing measurements collected every 5 seconds at several different sampling locations. If one measurement at a given location is less than zero on a given day, I would like to delete all measurements from that location on that day. Here is a toy example: toy - data.frame(CH = rep(3:5,3), DAY = c(rep(4,5), rep(5,4)), SLOPE = c(seq(0.2,0.6, .1),seq(0.2, -0.1, -0.1))) In this example, row 9 has a negative measurement for Chamber 5, so I would like to delete row 6, which is the same Chamber on the same day, but not row 3, which is the same chamber on a different day. In the full dataframe, there are, of course, many more days. Is there a handy R way to do this? Thank you for the assistance. Toby Not fully tested, but here is one possibility: toy CH DAY SLOPE 1 3 4 0.2 2 4 4 0.3 3 5 4 0.4 4 3 4 0.5 5 4 4 0.6 6 5 5 0.2 7 3 5 0.1 8 4 5 0.0 9 5 5 -0.1 subset(toy, ave(SLOPE, CH, DAY, FUN = function(x) any(x 0)) == 0) CH DAY SLOPE 1 3 4 0.2 2 4 4 0.3 3 5 4 0.4 4 3 4 0.5 5 4 4 0.6 7 3 5 0.1 8 4 5 0.0 This can actually be slightly shortened to: subset(toy, !ave(SLOPE, CH, DAY, FUN = function(x) any(x 0))) CH DAY SLOPE 1 3 4 0.2 2 4 4 0.3 3 5 4 0.4 4 3 4 0.5 5 4 4 0.6 7 3 5 0.1 8 4 5 0.0 HTH, 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] build.pl in building library with Rtools211
What did you try? R CMD build (build all lower case) does work for me Uwe Ligges On 09.08.2010 22:30, Hintzen, Niels wrote: Dear all, As I couldn't find any thread on the internet I hope the help-list might help me out. I've tried to update Rtools from R210 used in combination with R2.9.1 to R211 in combination with R2.11.1. However, I do not succeed. I have R2.11.1 running, as well as Inno Setup 5, HTML help and MikTex. A version of Perl is installed too. Environment variable paths are set to link to these directories too. However, when I try to build a library using: R CMD BUILD mypackage it immediately crashes as apparently it cannot find the file 'build' in R-2.11.1/bin. Indeed, this file is not present there (only build.pl) while this file is present in the R-2.9.1/bin directory. What obvious thing am I doing wrong. Your help is much appreciated. With regards, Niels Hintzen [[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] Scatterplot - Overlap Frequency
Hi listers... I am working o a scatterplot where I would like to plot the variables according with another frequency variable. Another friend here proposed this code... x - rnorm(10) y - rnorm(10) ind - c(1,0,1,0,1,0,1,1,0,0) plot(x, y, col = ind + 1, pch = 16) # 1 is black, 2 is red But in my case I would like to identify with different colors according with a frequency variable. x - rnorm(10) y - rnorm(10) ind - c(3,0,1,0,3,0,2,2,0,0) I made some research and I would like to do something like the function HEXBIN does: source(http://bioconductor.org/biocLite.R;) biocLite(hexbin) library(hexbin) x - rnorm(1000) y - rnorm(1000) bin-hexbin(x, y, xbins=50) plot(bin, main=Hexagonal Binning) But in my case I have another variable with the frequency and not high density frequency according the two plotted variables... Any suggestions, thanks... Marcio -- View this message in context: http://r.789695.n4.nabble.com/Scatterplot-Overlap-Frequency-tp2323322p2323322.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] how to eliminate an element of a list
Hi, I want to eliminate an element of a list: list - seq(1,5,1) s - sample(list,1) lets say s=3 Now I want to remove 3 from the list: list2 = {1,2,4,5} Can someone give me a tip? Thanks, André [[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 eliminate an element of a list
Try this: setdiff(list, s) On Thu, Aug 12, 2010 at 5:32 PM, André de Boer rnie...@gmail.com wrote: Hi, I want to eliminate an element of a list: list - seq(1,5,1) s - sample(list,1) lets say s=3 Now I want to remove 3 from the list: list2 = {1,2,4,5} Can someone give me a tip? Thanks, André [[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] conditional selection of dataframe rows
On Aug 12, 2010, at 4:06 PM, Toby Gass wrote: Thank you all for the quick responses. So far as I've checked, Marc's solution works perfectly and is quite speedy. I'm still trying to figure out what it is doing. :) Henrique's solution seems to need some columns somewhere. David's solution does not find all the other measurements, possibly with positive values, taken on the same day. I assumed you only wanted to look at what appeared to be a data column, SLOPE. If you want to look at all columns for negatives then try: toy[ which( apply(toy, 1, function(x) all(x = 0)) ), ] # or toy[ apply(toy, 1, function(x) all(x = 0)) , ] This is how they differ w,r,t, their handling of NA's. toy[3,2] - NA toy[ apply(toy, 1, function(x) all(x = 0)) , ] CH DAY SLOPE 1 3 4 0.2 2 4 4 0.3 NA NA NANA 4 3 4 0.5 5 4 4 0.6 6 5 5 0.2 7 3 5 0.1 8 4 5 0.0 toy[ which(apply(toy, 1, function(x) all(x = 0)) ), ] CH DAY SLOPE 1 3 4 0.2 2 4 4 0.3 4 3 4 0.5 5 4 4 0.6 6 5 5 0.2 7 3 5 0.1 8 4 5 0.0 Thank you again for your efforts. Toby On 12 Aug 2010 at 14:32, Marc Schwartz wrote: On Aug 12, 2010, at 2:24 PM, Marc Schwartz wrote: On Aug 12, 2010, at 2:11 PM, Toby Gass wrote: Dear helpeRs, I have a dataframe (14947 x 27) containing measurements collected every 5 seconds at several different sampling locations. If one measurement at a given location is less than zero on a given day, I would like to delete all measurements from that location on that day. Here is a toy example: toy - data.frame(CH = rep(3:5,3), DAY = c(rep(4,5), rep(5,4)), SLOPE = c(seq(0.2,0.6, .1),seq(0.2, -0.1, -0.1))) In this example, row 9 has a negative measurement for Chamber 5, so I would like to delete row 6, which is the same Chamber on the same day, but not row 3, which is the same chamber on a different day. In the full dataframe, there are, of course, many more days. Is there a handy R way to do this? Thank you for the assistance. Toby Not fully tested, but here is one possibility: toy CH DAY SLOPE 1 3 4 0.2 2 4 4 0.3 3 5 4 0.4 4 3 4 0.5 5 4 4 0.6 6 5 5 0.2 7 3 5 0.1 8 4 5 0.0 9 5 5 -0.1 subset(toy, ave(SLOPE, CH, DAY, FUN = function(x) any(x 0)) == 0) CH DAY SLOPE 1 3 4 0.2 2 4 4 0.3 3 5 4 0.4 4 3 4 0.5 5 4 4 0.6 7 3 5 0.1 8 4 5 0.0 This can actually be slightly shortened to: subset(toy, !ave(SLOPE, CH, DAY, FUN = function(x) any(x 0))) CH DAY SLOPE 1 3 4 0.2 2 4 4 0.3 3 5 4 0.4 4 3 4 0.5 5 4 4 0.6 7 3 5 0.1 8 4 5 0.0 HTH, 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. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Scatterplot - Overlap Frequency
Hi Marcio, Your friend has given the answer. x - rnorm(10) y - rnorm(10) ind - c(3,0,1,0,3,0,2,2,0,0) plot(x, y, col = grey(0:max(ind)/max(ind))[ind], pch = 16) Mestat wrote: I am working o a scatterplot where I would like to plot the variables according with another frequency variable. Regards, Wu - A R learner. -- View this message in context: http://r.789695.n4.nabble.com/Scatterplot-Overlap-Frequency-tp2323322p2323349.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] Plotting one dot in a graph
# just to clean it up for my own understanding, the difference approach as you had suggested would be x - seq(.2, .3, by = .1) f1 - function(x){ x*cos(x)-2*x**2+3*x-1 } plot(x,f1(x), type = l) abline(h = -.1) abline(v = x[which.min(abs(diff((f1(x) - (-.1))**2)))], lty = 'dotted') points(x = x[which.min(abs(diff((f1(x) - (-.1))**2)))], y = -.1) # and the uniroot approach is: x - seq(.2, .3, by = .01) f1 - function(x){ x*cos(x)-2*x**2+3*x-1 } f2 - function(x){ -.1 } f3 - function(x){ f1(x) - f2(x) } plot(x,f1(x), type = l) abline(h = -.1) abline(v = uniroot(f = f3, interval = c(.2, .3))$root, lty = 'dotted') points(x = uniroot(f = f3, interval = c(.2, .3))$root, y = -.1) # Thanks David! On Aug 12, 2010, at 1:33 PM, David Winsemius wrote: On Aug 12, 2010, at 4:15 PM, TGS wrote: David, I was expecting this to work but how would I specify the vector in diff() in order for the following to work? x - seq(.2, .3, by = .01) f - function(x){ x*cos(x)-2*x**2+3*x-1 } plot(x,f(x), type = l) abline(h = -.1) abline(v = x[which.min(abs(diff(c(-.1, f(x)], lty = 'dotted') f2 - function(x) -0.1 f3 - function(x) f(x) -f2(x) abline(v=uniroot(f3, c(0.2, 0.3) )$root) points(x=uniroot(f3, c(0.2, 0.3) )$root, y= -0.1) If you are going to use the differences, then you probably want to minimize either the abs() or the square of the differences. -- David. On Aug 12, 2010, at 1:00 PM, David Winsemius wrote: On Aug 12, 2010, at 3:54 PM, TGS wrote: Actually I spoke too soon David. I'm looking for a function that will either tell me which point is the intersection so that I'd be able to plot a point there. Or, if I have to solve for the roots in the ways which were demonstrated yesterday, then would I be able to specify what the horizontal line is, for instance in the case where y (is-not) 0? Isn't the abline h=0 represented mathematically by the equation y=0 and therefore you are solving just for the zeros of f (whaich are the same as for (f-0)? If it were something more interesting, like solving the intersection of two polynomials, you would be solving for the zeros of the difference of the equations. Or maybe I have not understood what you were requesting? On Aug 12, 2010, at 12:47 PM, David Winsemius wrote: On Aug 12, 2010, at 3:43 PM, TGS wrote: I'd like to plot a point at the intersection of these two curves. Thanks x - seq(.2, .3, by = .01) f - function(x){ x*cos(x)-2*x**2+3*x-1 } plot(x,f(x), type = l) abline(h = 0) Would this just be the uniroot strategy applied to f? You then plot the x and y values with points() David Winsemius, MD West Hartford, CT David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.