Re: [R] Legend colors not matching with Intxplot line colors
Hi Richard, Thanks for the solution. A.K. From: Richard M. Heiberger r...@temple.edu To: arun smartpink...@yahoo.com Sent: Monday, June 4, 2012 1:47 AM Subject: Re: [R] Legend colors not matching with Intxplot line colors Thank you for catching that. I will repair it in the next version of HH. The problem is that the colors of the key are not automatically detected by intxplot. Here is the workaround: tmp - intxplot(Response ~ time, data = dat3, groups = trt, ylim=c(0,1), par.settings=par.settings, main= Response) tmp$legend$right$args$key$lines$col - par.settings$superpose.line$col tmp On Sun, Jun 3, 2012 at 8:40 PM, arun smartpink...@yahoo.com wrote: Dear R help, I am using intxplot() from the library(HH). I have a dataset with 12 treatment groups. At first, I tried intxplot with no color settings. Then, the legend color was matching with the plot line colors, but some of the colors were repeated. So, I set the colors using par.settings. Now, I have the plot lines with different colors, but it seemed to be not matching with legend color. Legend colors are repeated. I am pasting below sample dataset with codes. set.seed(1) dat1-rnorm(120,0.5,0.2) dat2-data.frame(time=rep(c(1:20),rep(12,20)),trt=rep(LETTERS[1:12],each=1)) dat3-data.frame(dat2,dat1) colnames(dat3)-c(names(dat2),Response) dat3-transform(dat3,trt=ordered(trt,levels=LETTERS[1:12])) dat3$time-factor(dat3$time) position(dat3$time)-as.numeric(levels(dat3$time)) library(HH) par.settings-simpleTheme(col=c(8,12,28,36,41,47,81,92,98,113,125,155)) intxplot(Response ~ time, data = dat3, groups = trt, ylim=c(0,1), par.settings=par.settings, main= Response) Any help will be appreciated. Thanks, A.K. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Variate
Dear Mc kay, thankyou very much for your reply. we are extremly greatful to you. we actually wanted all on one scale. we want to compare them all on one axis. kindle see if you could help us on that. one more thing, does this practice give us normal reduced variant on x-axis because we stricktly want normal reduced variant on x-axis. i hope you will cooperate. eliza botto waters inn Date: Mon, 4 Jun 2012 11:54:11 +1000 To: r-help@r-project.org From: mac...@northnet.com.au Subject: Re: [R] Variate Hi Eliza You will not want 1 panel with 96 lines - too confusing after about 20 Instead 1 per panel or with groups using useOuterStrips and combineLimits from latticeExtra package Try this -- a minimal example with an 12 row 8 col grid done on the fly setseed(12) Sites - 1:92 dat - data.frame(y = rep(rnorm(5),92), x = rep(1:5,92), site = rep(Sites,each = 5)) xyplot(y ~ x|site,dat, as.table=T, strip = F, layout = c(8,12), scales = list(x = list(alternating = 2),y=list(alternating=1)), type = b, panel = function(x,y,...){ pnl=panel.number() panel.xyplot(x,y,...) panel.text(4,-1.5,Sites[pnl], cex = 0.6) } ) or with groupings for Site something like (untested) xyplot(y ~ x|groupings,dat, as.table=T, strip = F, strip.left = T, groups = site, scales = list(x = list(alternating = 2),y=list(alternating=1)), type = b, panel = function(x,y,...){ pnl=panel.number() panel.xyplot(x,y,...) panel.text(4,-1.5,Sites[pnl], cex = 0.6) } ) You will need an extra column for groupings This can also be done with the base plot function but lattice gives more flexibility, see ?xyplot and particularly par.settings into get things right size Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 11:01 4/06/2012, you wrote: Content-Type: text/plain Content-Disposition: inline Content-length: 2431 Dear R users, We are working on a project called,Environmental Impact Assessment. We are stationed at alpine regions of Ireland to see the impact of rainfall on localities. We have divided our study area into 92 stations. We have also collected 1 year data from each station. Afterwards we placed data into a matrix in such a way that we got 366*92 matrix. 366 stands for number of days. What we want is a lognormal probability plot, of each station(which is individual column of matrix) with normal reduced variant on x-axis. In this way, we should be getting, at the end, 92 curves, one for each station, on same coordinate axis. Kindly help us on that. We are all very new to R. Eliza botto Waters Inn CC: r-help@r-project.org From: dwinsem...@comcast.net To: eliza_bo...@hotmail.com Subject: Re: [R] Log-normal probability plot Date: Sun, 3 Jun 2012 13:11:35 -0400 On Jun 2, 2012, at 9:38 PM, eliza botto wrote: You might consider the strategy of reading the Posting Guide, followed by posting an intelligible message. Dear R users, You can literally safe my life my telling me the solution of my problem. I have created matrix of a data frame with 3 columns, with each column representing data of different year. 2 ...snipped useless srting of numbers mangled by mailer processing of HTML. 4 I now want to plot Lognormal probability plot of each column data against its respective normal reduced variante(z). Normal reduced variate? What is that? Is it a set of numbers that have been centered and scaled, also known as a z-transform? If so, I do not think it should affect the results of a probability plot since it is just a linear transformation and the theoretical quantiles will be unaffected. You might look at qqplot() How to do that? If you don't know the answer, consider me dead. What greater lifesaving project are you trying to accomplish, other than getting homework done? [[alternative HTML version deleted]] -- 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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and
Re: [R] Variate
Hello, Sorry for not understanding your problem, but it really seemed like homework. Now, when I answered scale(x) I meant it, it transforms a matrix in (x - mean)/sd, column by column. If you're new to R, to use the on-line help the instruction is help(scale) ?scale # shortcut As for your graph, I agree with Duncan, 92 lines on the same graph doesn't seem to be a good idea. Anyway, using base R, it could be done along the lines of set.seed(1) nc - 92 # number of columns nr - 366 # number of rows x - matrix(rexp(nr*nc), ncol=nc) x1 - scale(x) # z, standard normal (in fact, studentized) y1 - apply(x, 2, plnorm) # log-normal colrs - rainbow(nc) plot(1, type=n, xlim=c(min(x1), max(x1)), ylim=c(min(y1), max(y1)), xlab=, ylab=) # if you want lines sapply(seq_len(nc), function(j){ i - order(x1[, j]) lines(x1[i, j], y1[i, j], col=colrs[j])}) # if you want points sapply(seq_len(nc), function(j) points(x1[, j], y1[, j], col=colrs[j], pch=.)) Hope this helps, Rui Barradas Em 04-06-2012 07:38, eliza botto escreveu: Dear Mc kay, thankyou very much for your reply. we are extremly greatful to you. we actually wanted all on one scale. we want to compare them all on one axis. kindle see if you could help us on that. one more thing, does this practice give us normal reduced variant on x-axis because we stricktly want normal reduced variant on x-axis. i hope you will cooperate. eliza botto waters inn Date: Mon, 4 Jun 2012 11:54:11 +1000 To: r-help@r-project.org From: mac...@northnet.com.au Subject: Re: [R] Variate Hi Eliza You will not want 1 panel with 96 lines - too confusing after about 20 Instead 1 per panel or with groups using useOuterStrips and combineLimits from latticeExtra package Try this -- a minimal example with an 12 row 8 col grid done on the fly setseed(12) Sites- 1:92 dat- data.frame(y = rep(rnorm(5),92), x = rep(1:5,92), site = rep(Sites,each = 5)) xyplot(y ~ x|site,dat, as.table=T, strip = F, layout = c(8,12), scales = list(x = list(alternating = 2),y=list(alternating=1)), type = b, panel = function(x,y,...){ pnl=panel.number() panel.xyplot(x,y,...) panel.text(4,-1.5,Sites[pnl], cex = 0.6) } ) or with groupings for Site something like (untested) xyplot(y ~ x|groupings,dat, as.table=T, strip = F, strip.left = T, groups = site, scales = list(x = list(alternating = 2),y=list(alternating=1)), type = b, panel = function(x,y,...){ pnl=panel.number() panel.xyplot(x,y,...) panel.text(4,-1.5,Sites[pnl], cex = 0.6) } ) You will need an extra column for groupings This can also be done with the base plot function but lattice gives more flexibility, see ?xyplot and particularly par.settings into get things right size Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 11:01 4/06/2012, you wrote: Content-Type: text/plain Content-Disposition: inline Content-length: 2431 Dear R users, We are working on a project called,Environmental Impact Assessment. We are stationed at alpine regions of Ireland to see the impact of rainfall on localities. We have divided our study area into 92 stations. We have also collected 1 year data from each station. Afterwards we placed data into a matrix in such a way that we got 366*92 matrix. 366 stands for number of days. What we want is a lognormal probability plot, of each station(which is individual column of matrix) with normal reduced variant on x-axis. In this way, we should be getting, at the end, 92 curves, one for each station, on same coordinate axis. Kindly help us on that. We are all very new to R. Eliza botto Waters Inn CC: r-help@r-project.org From: dwinsem...@comcast.net To: eliza_bo...@hotmail.com Subject: Re: [R] Log-normal probability plot Date: Sun, 3 Jun 2012 13:11:35 -0400 On Jun 2, 2012, at 9:38 PM, eliza botto wrote: You might consider the strategy of reading the Posting Guide, followed by posting an intelligible message. Dear R users, You can literally safe my life my telling me the solution of my problem. I have created matrix of a data frame with 3 columns, with each column representing data of different year. 2 ...snipped useless srting of numbers mangled by mailer processing of HTML. 4 I now want to plot Lognormal probability plot of each column data against its respective normal reduced variante(z). Normal reduced variate? What is that? Is it a set of numbers that have been centered and scaled, also known as a z-transform? If so, I do not think it should affect the results of a probability plot since it is just a linear transformation and the theoretical quantiles will be unaffected. You might look at qqplot()
Re: [R] plotting evolution of dates
On 06/03/2012 11:27 PM, stef salvez wrote: Dear R users, I have the following problem I have a panel data across countries and individuals. For each country I have a sequence of dates For France for example 22/02/09 22/03/09 19/04/09 17/05/09 12/07/09 09/08/09 06/09/09 04/10/09 01/11/09 29/11/09 27/12/09 31/01/10 For Italy 14/06/09 12/07/09 09/08/09 06/09/09 04/10/09 01/11/09 29/11/09 27/12/09 31/01/10 28/02/10 28/03/10 The structure of the MS excel file is the following France Italy.. 22/02/09 14/06/09 22/03/09 12/7/2009 19/04/09 9/8/2009 17/05/096/9/2009 12/7/2009 4/10/2009 09/08/09 01/11/09 6/9/200929/11/09 4/10/2009 27/12/09 01/11/09 31/01/10 29/11/09 28/02/10 27/12/09 28/03/10 31/01/10 I want to plot (in one graph) these sequences of dates in the sense that I want to have a visual contact of the behaviour of each of these 2 sequences because as you can see I do not have the same start date and end date for each country and each next date is not always every other 28 days. So the difference between 2 successive dates is not always 28 days but 35 is some cases or otherwise. Put differently, I have jumps. I would like to visualize these characteristics of the series of dates by making a plot similar to http://i46.tinypic.com/2h7gpvn.png But this is not enough. I want to measure the distance between 2 successive knots (the difference between 2 successive dates) and note on the plot the number of weeks that separate apart the successive knots-dates Something like http://www.survey-design.com.au/stripplot3.png where as you can see between the knots there are some red lines. In my case these red lines would inform the reader about the number of weeks between successive knots-dates Hi stef, This is rather messy and needs some axis tuning, but it might do what you want: France-c(22/02/09,22/03/09,19/04/09,17/05/09,12/07/09, 09/08/09,06/09/09,04/10/09,01/11/09,29/11/09,27/12/09, 31/01/10) Italy-c(14/06/09,12/07/09,09/08/09,06/09/09,04/10/09, 01/11/09,29/11/09,27/12/09,31/01/10,28/02/10,28/03/10) Francedates-as.Date(France,%d/%m/%y) Italydates-as.Date(Italy,%d/%m/%y) require(plotrix) plot(Francedates,rep(1,length(France)), xlim=as.Date(c(01/01/09,01/04/10),%d/%m/%y),ylim=c(0,3), yaxt=n,type=b,xlab=,ylab=) axis(2,at=1:2,labels=c(France,Italy),las=1) points(Italydates,rep(2,length(Italy)),type=b,pch=2) segments(as.numeric(Francedates)[1:(length(Francedates)-1)]+ diff(as.numeric(Francedates))/2,rep(1,length(Francedates)-1), seq(min(as.numeric(Francedates)),max(as.numeric(Francedates)), length.out=length(Francedates)-1),rep(0.25,length(Francedates)-1)) boxed.labels(seq(min(as.numeric(Francedates)), max(as.numeric(Francedates)),length.out=length(Francedates)-1), rep(0.25,length(Francedates)-1), diff(as.numeric(Francedates))/7) segments(as.numeric(Italydates)[1:(length(Italydates)-1)]+ diff(as.numeric(Italydates))/2,rep(2,length(Italydates)-1), seq(min(as.numeric(Italydates)),max(as.numeric(Italydates)), length.out=length(Italydates)-1),rep(2.75,length(Italydates)-1)) boxed.labels(seq(min(as.numeric(Italydates)), max(as.numeric(Italydates)),length.out=length(Italydates)-1), rep(2.75,length(Italydates)-1), diff(as.numeric(Italydates))/7) You have also alerted me to the fact that the spread.labels function doesn't do quite what I would like it to do, so it will be revised. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Convert 2-dim array to 3-dim array
Hello R-users, I'd like to load data from a CSV-file to a 3-dimensional array. However the default seems to be 2-dimensional. It would also be ok to load the data and then convert it to a 3-dimensional structure. I've been trying: dat = read.csv(filename) myArr = as.array(dat, dim = c(12,100,3)) However, I get an error message: Error in `dimnames-.data.frame`(`*tmp*`, value = list(n)) : invalid 'dimnames' given for data frame And I don't know how how to set the dimnames. I would appreciate any help! Best Wishes Dave [[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] Read txt File contains character
Hi Dear friend, I encountered a problem when I read in one huge txt file which contains the character ** when I run read.table(D:/test.txt,header=T,sep=\t,quote=) the lines can only be read before appears. Once appears, it will stop there. Could you help me on this . Many thanks. ! -- View this message in context: http://r.789695.n4.nabble.com/Read-txt-File-contains-character-tp4632286.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 ignore NA with NA or NULL
Hello dear R-users, I have a problem in my code about ignoring NA values without removing them. I'm working on a list of files. The aim is to fill one file from another according to the highest correlation (correlation coeff between all my files, so the file which looks like the most to the one I want to fill). When I have just small gaps of NA, my function works well. The problem is when I have only NAs in some files. As a consequence, it cannot calculate any correlation coefficients (my previous function in the case of only NAs in the file returns NA for the correlation coefficient), and so it cannot fill it or make any calculation with it. Nevertheless in my work I need to keep these NA files in my list (and so to keep their dimensions). Otherwise it creates some dimensions problems, and my function needs to me automatic for every files. So my question in this post is: how to ignore (or do nothing with them if you prefer) NA files with NA correlation coefficients? The function for filling files (where there's the problem) is: na.fill - function(x, y){ i - is.na(x[1:8700,1]) xx - y[1:8700,1] new - data.frame(xx=xx) x[1:8700,1][i] - predict(lm(x[1:8700,1]~xx, na.action=na.exclude), new)[i] x } My error message is: Error in model.frame.default(formula = x[1:8700, 1] ~ xx, na.action = na.exclude, : : invalid type (NULL) for variable 'xx' I tried to add in the function: ifelse( all(is.null(xx))==TRUE,return(NA),xx) or ifelse( all(is.null(xx))==TRUE,return(NULL),xx) but it still doesn't work. How can I write that in my function? With NA, NULL or in another way? Thank you very much for your answers -- View this message in context: http://r.789695.n4.nabble.com/how-to-ignore-NA-with-NA-or-NULL-tp4632287.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] Problems installing Packages
Thanks for the replies, 1st, installing the BLAS library indeed worked out, and I was able to load the packages. 2nd, I was trying to build from repository directly. But even worse, I cannot tell you if i touched the BLAS linker flags, BUT there seem to be more problems of a similar nature, ie. I am trying to install a package which utilises Java, and when it tests during installation if it can compile Java, it failes and aborts the installation. Since I did this on the linux console, I cant copy and paste the error into this message, but it clearly is missing the link to /javac and /javah. i'll type it down anyway: checking Java Support in R... configure: Error: cannot determine complete Java config JAVA_HOME: usr/lib/jvm/java-6-openjdk-i386/jre JAVA: usr/bin/java JAVAC: JAVAH: JAVA_CPPFLAGS: JAVA_LIBS: ... Running javareconf did not show any results, although java is installed correctly through the ubuntu software center, supposing that works without errors. The package I am failing with is StatET for R: install.packages(c(rj, rj.gd), repos=http://download.walware.de/rj-1.1;) It fails trying to compile Java, and aborts. I am on R 2.15 and ubuntu 12.04 and java6openjdk thanks -- View this message in context: http://r.789695.n4.nabble.com/Problems-installing-Packages-tp4632217p4632288.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] how to ignore NA with NA or NULL
I find that avoiding using the return() function at all makes my code easier to follow. In your case it is simply incorrect, though, since ifelse is a vector function and return is a control flow function. Your code is not reproducible and your description isn't clear about how you are handling the return result from this function, so I can't be sure what you are really asking, but I suspect you just want flow control, so use (untested): na.fill - function(x, y){ i - is.na(x[1:8700,1]) xx - y[1:8700,1] new - data.frame(xx=xx) if ( !all(is.na(xx)) ) { x[1:8700,1][i] - predict(lm(x[1:8700,1]~xx, na.action=na.exclude),new)[i] } x } --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. jeff6868 geoffrey_kl...@etu.u-bourgogne.fr wrote: Hello dear R-users, I have a problem in my code about ignoring NA values without removing them. I'm working on a list of files. The aim is to fill one file from another according to the highest correlation (correlation coeff between all my files, so the file which looks like the most to the one I want to fill). When I have just small gaps of NA, my function works well. The problem is when I have only NAs in some files. As a consequence, it cannot calculate any correlation coefficients (my previous function in the case of only NAs in the file returns NA for the correlation coefficient), and so it cannot fill it or make any calculation with it. Nevertheless in my work I need to keep these NA files in my list (and so to keep their dimensions). Otherwise it creates some dimensions problems, and my function needs to me automatic for every files. So my question in this post is: how to ignore (or do nothing with them if you prefer) NA files with NA correlation coefficients? The function for filling files (where there's the problem) is: na.fill - function(x, y){ i - is.na(x[1:8700,1]) xx - y[1:8700,1] new - data.frame(xx=xx) x[1:8700,1][i] - predict(lm(x[1:8700,1]~xx, na.action=na.exclude), new)[i] x } My error message is: Error in model.frame.default(formula = x[1:8700, 1] ~ xx, na.action = na.exclude, : : invalid type (NULL) for variable 'xx' I tried to add in the function: ifelse( all(is.null(xx))==TRUE,return(NA),xx) or ifelse( all(is.null(xx))==TRUE,return(NULL),xx) but it still doesn't work. How can I write that in my function? With NA, NULL or in another way? Thank you very much for your answers -- View this message in context: http://r.789695.n4.nabble.com/how-to-ignore-NA-with-NA-or-NULL-tp4632287.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] Error while trying to install RPostgreSQL.
On 06/04/2012 12:14 AM, Prakash Thomas wrote: I am getting the following error while trying to install RPostgreSQL. RS-PostgreSQL.h:23:26: fatal error: libpq-fe.h: No such file or directory compilation terminated. You need the PostgreSQL front end development headers installed. How you get those depends on how postgres was installed in the first place, and/or what OS/distribution you are using. Since you didn't tell us that it is hard to provide any additional help. Please read the posting guide http://www.R-project.org/posting-guide.html HTH, Joe -- Joe Conway credativ LLC: http://www.credativ.us Linux, PostgreSQL, and general Open Source Training, Service, Consulting, 24x7 Support __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Modify pdf file with Illustrator.
On 6/3/2012 2:42 AM, Jinyan Huang wrote: Dear list, Some times I want to modify the pdf file which produced by R with illustrator. But when I use Illustrator open the pdf file, it often makes the pdf some little changed. Anyone have some suggestions? Is it better to use other file type, not pdf? Or when I produced the pdf, I should set some other parameters? Thank you You first have to remove clipping masks from the plot inside Illustrator. See http://www.psych.yorku.ca/quantmethods/BrownBag/Sigal-2011-Post-Processing-Handouts.pdf for a nice tutorial. -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele StreetWeb: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Ternary plot and filled contour
Dear R-Users, I'd like to have some tips for a ternaryplot (vcd). I have this dataframe: a- c (0.1, 0.5, 0.5, 0.6, 0.2, 0, 0, 0.00417, 0.45) b- c (0.75,0.5,0,0.1,0.2,0.951612903,0.918103448,0.7875,0.45)c- c (0.15,0,0.5,0.3,0.6,0.048387097,0.081896552,0.20833,0.1) d- c (500,2324.90,2551.44,1244.50, 551.22,-644.20,-377.17,-100, 2493.04) df- data.frame (a, b, c, d) and I'm building a ternary plot: ternaryplot(df[,1:3], df$d) How can I map the continue variable d, obtaining a result similar to this one? [see the link] http://www.pmel.noaa.gov/maillists/tmap/ferret_users/fu_2007/jpgCqrZqdDwYG.jpg Many thanks! [[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] Modify pdf file with Illustrator.
Thanks for the links! It is a very nice tutorial. On Mon, Jun 4, 2012 at 8:47 PM, Michael Friendly frien...@yorku.ca wrote: On 6/3/2012 2:42 AM, Jinyan Huang wrote: Dear list, Some times I want to modify the pdf file which produced by R with illustrator. But when I use Illustrator open the pdf file, it often makes the pdf some little changed. Anyone have some suggestions? Is it better to use other file type, not pdf? Or when I produced the pdf, I should set some other parameters? Thank you You first have to remove clipping masks from the plot inside Illustrator. See http://www.psych.yorku.ca/quantmethods/BrownBag/Sigal-2011-Post-Processing-Handouts.pdf for a nice tutorial. -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Street Web: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 with Rgraphviz
On 06/03/2012 07:38 PM, slipkid90515 wrote: Hi All, After a lengthy battle just to get the package installed, I am not able to actually use Rgraphviz to generate any plots. I tried just using the sample code in the documentation (http://www2.warwick.ac.uk/fac/sci/moac/people/students/peter_cock/r/rgraphviz/) and I get the following: *library(Rgraphviz) test.matrix-matrix(rep(c(0,1,0,0), 9), ncol=6, nrow=6) rownames(test.matrix)-c(a, b, c, d, e, f) colnames(test.matrix)-c(a, b, c, d, e, f) test.matrix a b c d e f a 0 0 0 0 0 0 b 1 0 1 0 1 0 c 0 0 0 0 0 0 d 0 1 0 1 0 1 e 0 0 0 0 0 0 f 1 0 1 0 1 0 am.graph-new(graphAM, adjMat=test.matrix, edgemode=directed) am.graph A graphAM graph with directed edges Number of Nodes = 6 Number of Edges = 9 plot(am.graph, attrs = list(node = list(fillcolor = lightblue), + edge = list(arrowsize=0.5))) There were 18 warnings (use warnings() to see them) warnings() Warning messages: 1: In plot.xy(xy.coords(x, y), type = type, ...) : len is not a graphical parameter 2: In plot.xy(xy.coords(x, y), type = type, ...) : edgemode is not a graphical parameter 3: In plot.xy(xy.coords(x, y), type = type, ...) : len is not a graphical parameter 4: In plot.xy(xy.coords(x, y), type = type, ...) : edgemode is not a graphical parameter 5: In plot.xy(xy.coords(x, y), type = type, ...) : len is not a graphical parameter 6: In plot.xy(xy.coords(x, y), type = type, ...) : edgemode is not a graphical parameter 7: In plot.xy(xy.coords(x, y), type = type, ...) : len is not a graphical parameter 8: In plot.xy(xy.coords(x, y), type = type, ...) : edgemode is not a graphical parameter 9: In plot.xy(xy.coords(x, y), type = type, ...) : len is not a graphical parameter 10: In plot.xy(xy.coords(x, y), type = type, ...) : edgemode is not a graphical parameter 11: In plot.xy(xy.coords(x, y), type = type, ...) : len is not a graphical parameter 12: In plot.xy(xy.coords(x, y), type = type, ...) : edgemode is not a graphical parameter 13: In plot.xy(xy.coords(x, y), type = type, ...) : len is not a graphical parameter 14: In plot.xy(xy.coords(x, y), type = type, ...) : edgemode is not a graphical parameter 15: In plot.xy(xy.coords(x, y), type = type, ...) : len is not a graphical parameter 16: In plot.xy(xy.coords(x, y), type = type, ...) : edgemode is not a graphical parameter 17: In plot.xy(xy.coords(x, y), type = type, ...) : len is not a graphical parameter 18: In plot.xy(xy.coords(x, y), type = type, ...) : edgemode is not a graphical parameter* Anyone with the same problem? Any ideas on how to fix? Hi Jess -- Rgraphviz is a bioconductor package so please ask on that list. http://bioconductor.org/help/mailing-list/ I don't see those warnings when running your code, maybe you are using an older version of R or a mismatch between R and Rgraphviz versions, or have additional packages that have modified plotting functions? Here's my sessionInfo() sessionInfo() R version 2.15.0 Patched (2012-05-01 r59304) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] grid stats graphics grDevices utils datasets methods [8] base other attached packages: [1] Rgraphviz_1.34.0 graph_1.34.0 loaded via a namespace (and not attached): [1] BiocGenerics_0.2.0 stats4_2.15.0 tools_2.15.0 Thanks, Jess -- View this message in context: http://r.789695.n4.nabble.com/Plotting-with-Rgraphviz-tp4632274.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. -- Computational Biology Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: M1-B861 Telephone: 206 667-2793 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Chi square value of anova(binomialglmnull, binomglmmod, test=Chisq)
Hi all, I have done a backward stepwise selection on a full binomial GLM where the response variable is gender. At the end of the selection I have found one model with only one explanatory variable (cohort, factor variable with 10 levels). I want to test the significance of the variable cohort that, I believe, is the same as the significance of this selected model: anova(mod4,update(mod4,~.-cohort),test=Chisq) Analysis of Deviance Table Model 1: site ~ cohort Model 2: site ~ 1 Resid. Df Resid. Dev Df Deviance P(|Chi|) 1 993 1283.7 2 1002 1368.2 -9 -84.554 2.002e-14 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 My question is: When I report this result, I would say /cohorts were unevenly distributed between sites ( Chi2=84.5, df=9, p 0.001)/, is that correct? is the Chi2 value the difference of deviance between model with cohort effect and null model? -- View this message in context: http://r.789695.n4.nabble.com/Chi-square-value-of-anova-binomialglmnull-binomglmmod-test-Chisq-tp4632293.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] Non-linear curve fitting (nls): starting point and quality of fit
Hi all, Like a lot of people I noticed that I get different results when I use nls in R compared to the exponential fit in excel. A bit annoying because often the R^2 is higher in excel but when I'm reading the different topics on this forum I kind of understand that using R is better than excel? (I don't really understand how the difference occurs, but I understand that there is a different way in fitting, in excel a single value can make the difference, in R it looks at the whole function? I read this: Fitting a function is an approximation, trying to find a minimum. Think of frozen mountain lake surrounded by mountains. Excel's Solver will report the highest tip of the snowflake on the lake, if it finds it. nls will find out that the lake is essentially flat compare to the surrounding and tell you this fact in unkind word. ) I have several questions about nls: 1. The nls method doesn't give an R^2. But I want to determine the quality of the fit. To understand how to use nls I read Technical note: Curve fitting with the R environment for Statistical Computing. In that document they suggested this to calculate R^2: RSS.p-sum(residuals(fit)^2) TSS-sum((y-mean(y))^2) r.squared-1-(RSS.p/TSS) LIST.rsq-r.squared (with fit my results of the nls: formula y ~ exp.f(x, a, b) : y : a*exp(-b*x)) While I was reading on the internet to find a possible reason why I get different results using R and excel, I also read lots of different things about the R^2 problem in nls. Is the method I'm using now ok, or should someone suggest to use something else? 2. Another question I have is like a lot of people about the singular gradient problem. I didn't know the best way to chose my starting values for my coefficients. when it was too low, I got this singular gradient error. Raising the value helped me to get rid of that error. Changing that value didn't change my coefficients nor R^2. I was wondering if that's ok, just to raise the starting value of one of my coefficients? The only things that change are the Achieved convergence tolerance and number of iterations to convergence. P values, residual standard error and the coefficients have always exactly the same results. What does the achieved convergence tolerance actually mean? What are its implications? (I suppose the time to calculate it changes) (the most useful information about nls and singular gradient error i found is this one (and that's why I started playing with changing the starting values): if the estimate of the rank that results is less than the number of columns in the gradient (the number of nonlinear parameters), or less than the number of rows (the number of observations), nls stops.) I hope someone can help me with this questions. I would like to know what's happening and not just having to accept the results I get now :). Kind regards, Nerak -- View this message in context: http://r.789695.n4.nabble.com/Non-linear-curve-fitting-nls-starting-point-and-quality-of-fit-tp4632295.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] Convert 2-dim array to 3-dim array
On Jun 4, 2012, at 5:08 AM, David Zastrau wrote: Hello R-users, I'd like to load data from a CSV-file to a 3-dimensional array. However the default seems to be 2-dimensional. No. that is not the problem. It would also be ok to load the data and then convert it to a 3-dimensional structure. I've been trying: dat = read.csv(filename) myArr = as.array(dat, dim = c(12,100,3)) However, I get an error message: Error in `dimnames-.data.frame`(`*tmp*`, value = list(n)) : invalid 'dimnames' given for data frame A dataframe is a list structure while both array and matrix are expecting the first argument to be an atomic vector. Try this (although it is a blind guess because you have not provided the structure of 'dat' myArr = as.array( unlist(dat), dim = c(12,100,3)) -- David. And I don't know how how to set the dimnames. I would appreciate any help! Best Wishes Dave [[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. 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] Read txt File contains character
Hello, There's a ascii 26, hex 1a, between the quotes. Get rid of it and it will probably work. Hope this helps, Rui Barradas Em 04-06-2012 08:43, climmi escreveu: Hi Dear friend, I encountered a problem when I read in one huge txt file which contains the character ** when I run read.table(D:/test.txt,header=T,sep=\t,quote=) the lines can only be read before appears. Once appears, it will stop there. Could you help me on this . Many thanks. ! -- View this message in context: http://r.789695.n4.nabble.com/Read-txt-File-contains-character-tp4632286.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] Chi square value of anova(binomialglmnull, binomglmmod, test=Chisq)
On Jun 4, 2012, at 7:00 AM, lincoln wrote: Hi all, I have done a backward stepwise selection on a full binomial GLM where the response variable is gender. At the end of the selection I have found one model with only one explanatory variable (cohort, factor variable with 10 levels). I want to test the significance of the variable cohort that, I believe, is the same as the significance of this selected model: anova(mod4,update(mod4,~.-cohort),test=Chisq) Analysis of Deviance Table Model 1: site ~ cohort Model 2: site ~ 1 Resid. Df Resid. Dev Df Deviance P(|Chi|) 1 993 1283.7 2 1002 1368.2 -9 -84.554 2.002e-14 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 My question is: When I report this result, I would say /cohorts were unevenly distributed between sites ( Chi2=84.5, df=9, p 0.001)/, is that correct? is the Chi2 value the difference of deviance between model with cohort effect and null model? I thought you said the response variable was gender? It seems to be 'site' in these two models. Maybe you should give us some more information about how you constructed 'mod4'? -- 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] how to ignore NA with NA or NULL
Hello, 'ifelse' is vectorized, what you want is the plain 'if'. if(all(is.na(xx))) return(NA) Hope this helps, Rui Barradas Em 04-06-2012 09:56, jeff6868 escreveu: Hello dear R-users, I have a problem in my code about ignoring NA values without removing them. I'm working on a list of files. The aim is to fill one file from another according to the highest correlation (correlation coeff between all my files, so the file which looks like the most to the one I want to fill). When I have just small gaps of NA, my function works well. The problem is when I have only NAs in some files. As a consequence, it cannot calculate any correlation coefficients (my previous function in the case of only NAs in the file returns NA for the correlation coefficient), and so it cannot fill it or make any calculation with it. Nevertheless in my work I need to keep these NA files in my list (and so to keep their dimensions). Otherwise it creates some dimensions problems, and my function needs to me automatic for every files. So my question in this post is: how to ignore (or do nothing with them if you prefer) NA files with NA correlation coefficients? The function for filling files (where there's the problem) is: na.fill- function(x, y){ i- is.na(x[1:8700,1]) xx- y[1:8700,1] new- data.frame(xx=xx) x[1:8700,1][i]- predict(lm(x[1:8700,1]~xx, na.action=na.exclude), new)[i] x } My error message is: Error in model.frame.default(formula = x[1:8700, 1] ~ xx, na.action = na.exclude, : : invalid type (NULL) for variable 'xx' I tried to add in the function: ifelse( all(is.null(xx))==TRUE,return(NA),xx) or ifelse( all(is.null(xx))==TRUE,return(NULL),xx) but it still doesn't work. How can I write that in my function? With NA, NULL or in another way? Thank you very much for your answers -- View this message in context: http://r.789695.n4.nabble.com/how-to-ignore-NA-with-NA-or-NULL-tp4632287.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] Convert 2-dim array to 3-dim array
On Mon, Jun 04, 2012 at 11:08:24AM +0200, David Zastrau wrote: Hello R-users, I'd like to load data from a CSV-file to a 3-dimensional array. However the default seems to be 2-dimensional. It would also be ok to load the data and then convert it to a 3-dimensional structure. I've been trying: dat = read.csv(filename) myArr = as.array(dat, dim = c(12,100,3)) However, I get an error message: Error in `dimnames-.data.frame`(`*tmp*`, value = list(n)) : invalid 'dimnames' given for data frame Hello: The structure obtained form read.csv() is a data frame, which is a list of columns of equal length. You can convert it to a matrix using as.matrix() and then perform further transformation. The command array(as.matrix(dat), dim = c(12,100,3)) makes sense if either the matrix is 1200 times 3 or if it is 12 times 300. In the former case, the row number 1:1200 will be translated to the values of the first two indices. In the latter case, the column number 1:300 will be translated to the last two indices. Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 ignore NA with NA or NULL
Thanks for answering Jeff. Yes sorry it's not easy to explain my problem. I'll try to give you a reproductible example (even if it'll not be exactly like my files), and I'll try to explain my function and what I want to do more precisely. Imagine for the example: df1, df2 and df3 are my files: df1 - data.frame(x1=c(rnorm(1:5),NA,NA,rnorm(8:10))) df2 - data.frame(x2=rnorm(1:10)) df3 - data.frame(x3=c(NA,NA,NA,NA,NA,NA,NA,NA,NA,NA)) df - list(df1,df2,df3) I want to fill each NA gaps of my files. If I have only df1 and df2 in my list, it'll work. If I introduce df3 (a file with only NAs), R won't understand what to do. In my function: na.fill - function(x, y){ i - is.na(x[1:10,1]) xx - y[1:10,1] new - data.frame(xx=xx) x[1:10,1][i] - predict(lm(x[1:10,1]~xx, na.action=na.exclude), new)[i] x } x is the file I want to fill. So i lists all the NA gaps of the file. xx is the file that will be used to fill x (actually the best correlated file with x according to all my files). And then I apply a linear regression between my 2 files: x and xx to take predicted values from xx to put in the gaps of x. Before I got files containing only NAs, it was working well. But since I introduced some files with no data and so only NAs, I have my problem. I got different NA problems when I tried a few solutions: Error in model.frame.default(formula = x[1:8700,1] ~xx, na.action = na.exclude, : : invalid type (NULL) for variable 'xx' OR 0 (non-NA) cases OR is.na() applied to non-(list or vector) of type 'NULL Actually I'm looking for a solution in na.fill to avoid these problems, in order to ignore these only NA files from the calculation (maybe something like na.pass) but I would like to keep them in the list. So the aim would be maybe to keep them unchanged (if I have for example ST1 file with 30 only NA in input, I want to have ST1 file with 30 only NA in output) but calculation should work with these kinds of files in my list even if the code does nothing with them. Hope you've understood. Thanks again for your help. -- View this message in context: http://r.789695.n4.nabble.com/how-to-ignore-NA-with-NA-or-NULL-tp4632287p4632314.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] how to ignore NA with NA or NULL
Hello Rui, Sorry I read your post after having answered to jeff. If seems effectively to be better than ifelse, thanks. But I still have some errors: Error in x[1:8700, 1] : incorrect number of dimensions AND In is.na(xx) : is.na() applied to non-(list or vector) of type 'NULL It seems to have modified the length of my data, due to these NAs -- View this message in context: http://r.789695.n4.nabble.com/how-to-ignore-NA-with-NA-or-NULL-tp4632287p4632315.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] how to ignore NA with NA or NULL
Hello again, The complete function would be na.fill - function(x, y){ # do this immediatly, may save copying if(all(is.na(y[1:8700,1]))) return(NA) i - is.na(x[1:8700,1]) xx - y[1:8700,1] new - data.frame(xx=xx) x[1:8700,1][i] - predict(lm(x[1:8700,1]~xx, na.action=na.exclude), new)[i] x } Rui Barradas Em 04-06-2012 16:05, Rui Barradas escreveu: Hello, 'ifelse' is vectorized, what you want is the plain 'if'. if(all(is.na(xx))) return(NA) Hope this helps, Rui Barradas Em 04-06-2012 09:56, jeff6868 escreveu: Hello dear R-users, I have a problem in my code about ignoring NA values without removing them. I'm working on a list of files. The aim is to fill one file from another according to the highest correlation (correlation coeff between all my files, so the file which looks like the most to the one I want to fill). When I have just small gaps of NA, my function works well. The problem is when I have only NAs in some files. As a consequence, it cannot calculate any correlation coefficients (my previous function in the case of only NAs in the file returns NA for the correlation coefficient), and so it cannot fill it or make any calculation with it. Nevertheless in my work I need to keep these NA files in my list (and so to keep their dimensions). Otherwise it creates some dimensions problems, and my function needs to me automatic for every files. So my question in this post is: how to ignore (or do nothing with them if you prefer) NA files with NA correlation coefficients? The function for filling files (where there's the problem) is: na.fill- function(x, y){ i- is.na(x[1:8700,1]) xx- y[1:8700,1] new- data.frame(xx=xx) x[1:8700,1][i]- predict(lm(x[1:8700,1]~xx, na.action=na.exclude), new)[i] x } My error message is: Error in model.frame.default(formula = x[1:8700, 1] ~ xx, na.action = na.exclude, : : invalid type (NULL) for variable 'xx' I tried to add in the function: ifelse( all(is.null(xx))==TRUE,return(NA),xx) or ifelse( all(is.null(xx))==TRUE,return(NULL),xx) but it still doesn't work. How can I write that in my function? With NA, NULL or in another way? Thank you very much for your answers -- View this message in context: http://r.789695.n4.nabble.com/how-to-ignore-NA-with-NA-or-NULL-tp4632287.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] merging single column from different dataframe
Thanks a lot, appreciate it. On Sun, Jun 3, 2012 at 10:25 PM, David Winsemius dwinsem...@comcast.netwrote: On Jun 3, 2012, at 3:22 PM, Kai Mx wrote: Hi all, probably really simple to solve, but having no background in programming I haven't been able to figure this out: I have two dataframes like df1 - data.frame(names1=c('aa','ab', 'ac', 'ad'), var1=c(1,5,7,12)) df2 - data.frame(names2=c('aa', 'ab', 'ac', 'ad', 'ae'), var2=c(3,6,9,12,15)) Now I want merge var1 to df2 by matching the dataframes by the 'names' columns, i.e. something like df3 - merge (df2, df1, by.x='names2', by.y='names1', all.x=T) However, the original dataframes have quite a lot of columns and I thought that I should be able to address the var1 column by something like df1$var[[df2$name2]]. Well there is no df1$var object or even a column with that reference. Even if you meant to type `var1`, the object df1$var[[df2$name2]] would not make much sense, since that would still be a failed attempt to access an named vector and df1$var1 is not named. names( df1$var1) NULL The [[ operation is different than the [ operation. [[ returns only one item. [ returns multiple items. In the case of dataframes (of which df1$var1 is _not_ an example) , [[ returns one entire column as a vector. If you had been trying to access a named vector using the 'names' in the character vector df1$names1 and there were any matches then you might have had some success with '['. Even then there are gators in the swamp. vec1 - c(aa=3, gx =10, ac=4, cc = 12) vec1[df1$names1] aa gx ac cc 3 10 4 12 WTF? Well, by default R's dataframes construct factor variables for character arguments and have an underlying numeric representation, so by the time df1$names got coerced it ended up as 1,2,3,4 and referenced all of vec1. These other methods would return something appropriate: vec1[as.character(df1$names1)] aa NA ac NA 3 NA4 NA vec1[which(names(vec1) %in% df1$names1)] aa ac 3 4 I happen to think that returning NA is unfortunate in the first inatance, but I did not construct the language and there must have been some good reason to make it that way. Could somebody please enlighten me and/or maybe suggest a short tutorial for the extraction operator? Arguments to [ can be numeric, character, or logical. If numeric, it will return values at the sequence locations along the referenced object. If character, it will return the matched items with those names. if logical, the call will return those items for which the index is TRUE (and there will be argument recycling, so this will return every second item in df1$var1 df1$var1[c(FALSE, TRUE)] [1] 5 12 Spend some time working through the examples on ?Extract and then re-reading that help page at least three times, although I probably took me ten or twenty times to get a pretty good grasp of it. The material there is accurate and precise, but the subtleties are numerous. -- 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.
[R] Why do I have a column called row.names?
I'm trying to read in a tab separated table with read.delim(). I don't particularly care what the row names are. My data file looks like this: start stopSymbol Insert sequence Clone End Pair FISH 203048 67173930ABC8-43024000D23TI:993812543 TI:993834585 255176 87869359ABC8-43034700N15TI:995224581 TI:995237913 1022033 1060472 ABC27-1253C21 TI:2094436044 TI:2094696079 1022033 1061172 ABC23-1388A1TI:2120730727 TI:2121592459 I have to do something with row.names because my first column has duplicate entries. So I read in the file like this: BACS-read.delim(testdata.txt, row.names=NULL, fill=TRUE) head(BACS) row.namesstart stop Symbol Insert.sequence Clone.End.Pair 1203048 67173930 ABC8-43024000D23 NATI:993812543 TI:993834585 2255176 87869359 ABC8-43034700N15 NATI:995224581 TI:995237913 3 1022033 1060472ABC27-1253C21 NA TI:2094436044 TI:2094696079 4 1022033 1061172 ABC23-1388A1 NA TI:2120730727 TI:2121592459 FISH 1 NA 2 NA 3 NA 4 NA Why is there a column named row.names? I've tried a few different ways of invoking this, but I always get the first column named row.names, and the rest of the columns shifted by one. Obviously I could fix this by using row.names-, but I'd like to understand why this happens. Any insight? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Why do I have a column called row.names?
Try help(read.delim) - always a good strategy before using a function for the first time: In it, you will find: Using row.names = NULL forces row numbering. Missing or NULL row.names generate row names that are considered to be 'automatic' (and not preserved by as.matrix). -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Ed Siefker Sent: Monday, June 04, 2012 12:47 PM To: r-help@r-project.org Subject: [R] Why do I have a column called row.names? I'm trying to read in a tab separated table with read.delim(). I don't particularly care what the row names are. My data file looks like this: start stopSymbol Insert sequence Clone End Pair FISH 203048 67173930ABC8-43024000D23TI:993812543 TI:993834585 255176 87869359ABC8-43034700N15TI:995224581 TI:995237913 1022033 1060472 ABC27-1253C21 TI:2094436044 TI:2094696079 1022033 1061172 ABC23-1388A1TI:2120730727 TI:2121592459 I have to do something with row.names because my first column has duplicate entries. So I read in the file like this: BACS-read.delim(testdata.txt, row.names=NULL, fill=TRUE) head(BACS) row.namesstart stop Symbol Insert.sequence Clone.End.Pair 1203048 67173930 ABC8-43024000D23 NATI:993812543 TI:993834585 2255176 87869359 ABC8-43034700N15 NATI:995224581 TI:995237913 3 1022033 1060472ABC27-1253C21 NA TI:2094436044 TI:2094696079 4 1022033 1061172 ABC23-1388A1 NA TI:2120730727 TI:2121592459 FISH 1 NA 2 NA 3 NA 4 NA Why is there a column named row.names? I've tried a few different ways of invoking this, but I always get the first column named row.names, and the rest of the columns shifted by one. Obviously I could fix this by using row.names-, but I'd like to understand why this happens. Any insight? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Convert 2-dim array to 3-dim array
On Jun 4, 2012, at 12:54 PM, arun wrote: Hi Dave, I tested the as.array. It gives a different dimension when compared to array Interesting. `as.array basically throws away a 'dim' argument and substitutes length(x). Thanks for the correction. -- David. set.seed(1) datE-data.frame(A=rnorm(30,0.5)) myArr=as.array(unlist(datE),dim=c(5,2,3)) myArr A1 A2 A3 A4 A5 A6 -0.12645381 0.68364332 -0.33562861 2.09528080 0.82950777 -0.32046838 A7 A8 A9 A10 A11 A12 0.98742905 1.23832471 1.07578135 0.19461161 2.01178117 0.88984324 A13 A14 A15 A16 A17 A18 -0.12124058 -1.71469989 1.62493092 0.45506639 0.48380974 1.44383621 A19 A20 A21 A22 A23 A24 1.32122120 1.09390132 1.41897737 1.28213630 0.57456498 -1.48935170 A25 A26 A27 A28 A29 A30 1.11982575 0.44387126 0.34420449 -0.97075238 0.02184994 0.91794156 is.array(myArr) [1] TRUE dim(myArr) [1] 30 myArr1=array(unlist(datE),dim=c(5,2,3)) myArr1 , , 1 [,1] [,2] [1,] -0.1264538 -0.3204684 [2,] 0.6836433 0.9874291 [3,] -0.3356286 1.2383247 [4,] 2.0952808 1.0757814 [5,] 0.8295078 0.1946116 , , 2 [,1] [,2] [1,] 2.0117812 0.4550664 [2,] 0.8898432 0.4838097 [3,] -0.1212406 1.4438362 [4,] -1.7146999 1.3212212 [5,] 1.6249309 1.0939013 , , 3 [,1][,2] [1,] 1.418977 0.44387126 [2,] 1.282136 0.34420449 [3,] 0.574565 -0.97075238 [4,] -1.489352 0.02184994 [5,] 1.119826 0.91794156 dim(myArr1) [1] 5 2 3 A.K. - Original Message - From: David Winsemius dwinsem...@comcast.net To: David Zastrau dav...@tzi.de Cc: r-help@r-project.org Sent: Monday, June 4, 2012 10:45 AM Subject: Re: [R] Convert 2-dim array to 3-dim array On Jun 4, 2012, at 5:08 AM, David Zastrau wrote: Hello R-users, I'd like to load data from a CSV-file to a 3-dimensional array. However the default seems to be 2-dimensional. No. that is not the problem. It would also be ok to load the data and then convert it to a 3-dimensional structure. I've been trying: dat = read.csv(filename) myArr = as.array(dat, dim = c(12,100,3)) However, I get an error message: Error in `dimnames-.data.frame`(`*tmp*`, value = list(n)) : invalid 'dimnames' given for data frame A dataframe is a list structure while both array and matrix are expecting the first argument to be an atomic vector. Try this (although it is a blind guess because you have not provided the structure of 'dat' myArr = as.array( unlist(dat), dim = c(12,100,3)) --David. And I don't know how how to set the dimnames. I would appreciate any help! Best Wishes Dave [[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. 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. 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] Why do I have a column called row.names?
I did read that, and I still don't understand why I have a column called row.names. I used row.names = NULL in order to get numbered row names, which was successful: row.names(BACS) [1] 1 2 3 4 I don't see what this has to do with an extraneous column name. Can you be more explicit as to what exactly I'm supposed to take away from this segment of the help file? Thanks. On Mon, Jun 4, 2012 at 1:05 PM, David L Carlson dcarl...@tamu.edu wrote: Try help(read.delim) - always a good strategy before using a function for the first time: In it, you will find: Using row.names = NULL forces row numbering. Missing or NULL row.names generate row names that are considered to be 'automatic' (and not preserved by as.matrix). -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Ed Siefker Sent: Monday, June 04, 2012 12:47 PM To: r-help@r-project.org Subject: [R] Why do I have a column called row.names? I'm trying to read in a tab separated table with read.delim(). I don't particularly care what the row names are. My data file looks like this: start stop Symbol Insert sequence Clone End Pair FISH 203048 67173930 ABC8-43024000D23 TI:993812543 TI:993834585 255176 87869359 ABC8-43034700N15 TI:995224581 TI:995237913 1022033 1060472 ABC27-1253C21 TI:2094436044 TI:2094696079 1022033 1061172 ABC23-1388A1 TI:2120730727 TI:2121592459 I have to do something with row.names because my first column has duplicate entries. So I read in the file like this: BACS-read.delim(testdata.txt, row.names=NULL, fill=TRUE) head(BACS) row.names start stop Symbol Insert.sequence Clone.End.Pair 1 203048 67173930 ABC8-43024000D23 NA TI:993812543 TI:993834585 2 255176 87869359 ABC8-43034700N15 NA TI:995224581 TI:995237913 3 1022033 1060472 ABC27-1253C21 NA TI:2094436044 TI:2094696079 4 1022033 1061172 ABC23-1388A1 NA TI:2120730727 TI:2121592459 FISH 1 NA 2 NA 3 NA 4 NA Why is there a column named row.names? I've tried a few different ways of invoking this, but I always get the first column named row.names, and the rest of the columns shifted by one. Obviously I could fix this by using row.names-, but I'd like to understand why this happens. Any insight? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Why do I have a column called row.names?
Actually, I think it's ?data.frame that he should read. The salient points are that: 1. All data frames must have unique row names. If not provided, they are produced. Row numbers **are** row names. 2. The return value of read methods are data frames. -- Bert On Mon, Jun 4, 2012 at 11:05 AM, David L Carlson dcarl...@tamu.edu wrote: Try help(read.delim) - always a good strategy before using a function for the first time: In it, you will find: Using row.names = NULL forces row numbering. Missing or NULL row.names generate row names that are considered to be 'automatic' (and not preserved by as.matrix). -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Ed Siefker Sent: Monday, June 04, 2012 12:47 PM To: r-help@r-project.org Subject: [R] Why do I have a column called row.names? I'm trying to read in a tab separated table with read.delim(). I don't particularly care what the row names are. My data file looks like this: start stop Symbol Insert sequence Clone End Pair FISH 203048 67173930 ABC8-43024000D23 TI:993812543 TI:993834585 255176 87869359 ABC8-43034700N15 TI:995224581 TI:995237913 1022033 1060472 ABC27-1253C21 TI:2094436044 TI:2094696079 1022033 1061172 ABC23-1388A1 TI:2120730727 TI:2121592459 I have to do something with row.names because my first column has duplicate entries. So I read in the file like this: BACS-read.delim(testdata.txt, row.names=NULL, fill=TRUE) head(BACS) row.names start stop Symbol Insert.sequence Clone.End.Pair 1 203048 67173930 ABC8-43024000D23 NA TI:993812543 TI:993834585 2 255176 87869359 ABC8-43034700N15 NA TI:995224581 TI:995237913 3 1022033 1060472 ABC27-1253C21 NA TI:2094436044 TI:2094696079 4 1022033 1061172 ABC23-1388A1 NA TI:2120730727 TI:2121592459 FISH 1 NA 2 NA 3 NA 4 NA Why is there a column named row.names? I've tried a few different ways of invoking this, but I always get the first column named row.names, and the rest of the columns shifted by one. Obviously I could fix this by using row.names-, but I'd like to understand why this happens. Any insight? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Why do I have a column called row.names?
Hello, It must be something else. Mandatory row names have nothing to do with a column header. I've put the data example in a tab separated file and the strange behavior was not reproduced. read.delim(test.txt, row.names=NULL, fill=TRUE) start stop Symbol Insert.sequence Clone.End.Pair FISH 1 203048 67173930 ABC8-43024000D23TI:993812543 TI:993834585 NA 2 255176 87869359 ABC8-43034700N15TI:995224581 TI:995237913 NA 3 1022033 1060472ABC27-1253C21 TI:2094436044 TI:2094696079 NA 4 1022033 1061172 ABC23-1388A1 TI:2120730727 TI:2121592459 NA With read.table, I tried with and without header=TRUE. No success. Rui Barradas Em 04-06-2012 19:30, Bert Gunter escreveu: Actually, I think it's ?data.frame that he should read. The salient points are that: 1. All data frames must have unique row names. If not provided, they are produced. Row numbers **are** row names. 2. The return value of read methods are data frames. -- Bert On Mon, Jun 4, 2012 at 11:05 AM, David L Carlsondcarl...@tamu.edu wrote: Try help(read.delim) - always a good strategy before using a function for the first time: In it, you will find: Using row.names = NULL forces row numbering. Missing or NULL row.names generate row names that are considered to be 'automatic' (and not preserved by as.matrix). -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Ed Siefker Sent: Monday, June 04, 2012 12:47 PM To: r-help@r-project.org Subject: [R] Why do I have a column called row.names? I'm trying to read in a tab separated table with read.delim(). I don't particularly care what the row names are. My data file looks like this: start stopSymbol Insert sequence Clone End Pair FISH 203048 67173930ABC8-43024000D23TI:993812543 TI:993834585 255176 87869359ABC8-43034700N15TI:995224581 TI:995237913 1022033 1060472 ABC27-1253C21 TI:2094436044 TI:2094696079 1022033 1061172 ABC23-1388A1TI:2120730727 TI:2121592459 I have to do something with row.names because my first column has duplicate entries. So I read in the file like this: BACS-read.delim(testdata.txt, row.names=NULL, fill=TRUE) head(BACS) row.namesstart stop Symbol Insert.sequence Clone.End.Pair 1203048 67173930 ABC8-43024000D23 NATI:993812543 TI:993834585 2255176 87869359 ABC8-43034700N15 NATI:995224581 TI:995237913 3 1022033 1060472ABC27-1253C21 NA TI:2094436044 TI:2094696079 4 1022033 1061172 ABC23-1388A1 NA TI:2120730727 TI:2121592459 FISH 1 NA 2 NA 3 NA 4 NA Why is there a column named row.names? I've tried a few different ways of invoking this, but I always get the first column named row.names, and the rest of the columns shifted by one. Obviously I could fix this by using row.names-, but I'd like to understand why this happens. Any insight? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Why do I have a column called row.names?
You will probably need to show us the first few lines of the .csv file. Assuming that the lines look like this start,stop,Symbol,Insert sequence,Clone End Pair,FISH 203048,67173930,ABC8-43024000D23,TI:993812543,TI:993834585 255176,87869359,ABC8-43034700N15,TI:995224581,TI:995237913 1022033,1060472,ABC27-1253C21,TI:2094436044,TI:2094696079 1022033,1061172,ABC23-1388A1,TI:2120730727,TI:2121592459 If I copy those lines to the clipboard and then use the command read.csv(clipboard) start stop Symbol Insert.sequence Clone.End.Pair FISH 1 203048 67173930 ABC8-43024000D23TI:993812543 TI:993834585 NA 2 255176 87869359 ABC8-43034700N15TI:995224581 TI:995237913 NA 3 1022033 1060472ABC27-1253C21 TI:2094436044 TI:2094696079 NA 4 1022033 1061172 ABC23-1388A1 TI:2120730727 TI:2121592459 NA I get numbered rows but no row.names (and I get the same when row.names=NULL and FILL=TRUE is included). -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: Ed Siefker [mailto:ebs15...@gmail.com] Sent: Monday, June 04, 2012 1:16 PM To: dcarl...@tamu.edu Subject: Re: [R] Why do I have a column called row.names? I did read that, and I still don't understand why I have a column called row.names. I used row.names = NULL in order to get numbered row names, which was successful: row.names(BACS) [1] 1 2 3 4 I don't see what this has to do with an extraneous column name. Can you be more explicit as to what exactly I'm supposed to take away from this segment of the help file? Thanks. On Mon, Jun 4, 2012 at 1:05 PM, David L Carlson dcarl...@tamu.edu wrote: Try help(read.delim) - always a good strategy before using a function for the first time: In it, you will find: Using row.names = NULL forces row numbering. Missing or NULL row.names generate row names that are considered to be 'automatic' (and not preserved by as.matrix). -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Ed Siefker Sent: Monday, June 04, 2012 12:47 PM To: r-help@r-project.org Subject: [R] Why do I have a column called row.names? I'm trying to read in a tab separated table with read.delim(). I don't particularly care what the row names are. My data file looks like this: start stop Symbol Insert sequence Clone End Pair FISH 203048 67173930 ABC8-43024000D23 TI:993812543 TI:993834585 255176 87869359 ABC8-43034700N15 TI:995224581 TI:995237913 1022033 1060472 ABC27-1253C21 TI:2094436044 TI:2094696079 1022033 1061172 ABC23-1388A1 TI:2120730727 TI:2121592459 I have to do something with row.names because my first column has duplicate entries. So I read in the file like this: BACS-read.delim(testdata.txt, row.names=NULL, fill=TRUE) head(BACS) row.names start stop Symbol Insert.sequence Clone.End.Pair 1 203048 67173930 ABC8-43024000D23 NA TI:993812543 TI:993834585 2 255176 87869359 ABC8-43034700N15 NA TI:995224581 TI:995237913 3 1022033 1060472 ABC27-1253C21 NA TI:2094436044 TI:2094696079 4 1022033 1061172 ABC23-1388A1 NA TI:2120730727 TI:2121592459 FISH 1 NA 2 NA 3 NA 4 NA Why is there a column named row.names? I've tried a few different ways of invoking this, but I always get the first column named row.names, and the rest of the columns shifted by one. Obviously I could fix this by using row.names-, but I'd like to understand why this happens. Any insight? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Why do I have a column called row.names?
To jump into the fray, he really needs to read the Details section of ?read.table and arguably, the source code for read.table(). It is not that the resultant data frame has row names, but that an additional first *column name* called 'row.names' is created, which does not exist in the source data. The Details section has: If row.names is not specified and the header line has one less entry than the number of columns, the first column is taken to be the row names. This allows data frames to be read in from the format in which they are printed. If row.names is specified and does not refer to the first column, that column is discarded from such files. The number of data columns is determined by looking at the first five lines of input (or the whole file if it has less than five lines), or from the length of col.names if it is specified and is longer. This could conceivably be wrong if fill or blank.lines.skip are true, so specify col.names if necessary (as in the ‘Examples’). In the source code for read.table(), which is called by read.delim() with differing defaults, there is: rlabp - (cols - col1) == 1L and a few lines further down: if (rlabp) col.names - c(row.names, col.names) So the last code snippet is where a new first column name called 'row.names' is pre-pended to the column names found from reading the header row. 'cols' and 'col1' are defined in prior code based upon various conditions. Not having the full data set and possibly having line wrap and TAB problems with the text that Ed pasted into his original post, I cannot properly replicate the conditions that cause the above code to be triggered. If Ed can put the entire file someplace and provide a URL for download, perhaps we can better trace the source of the problem, or Ed might use ?debug to follow the code execution in read.table() and see where the relevant flags get triggered. The latter option would help Ed learn how to use the debugging tools that R provides to dig more deeply into such issues. Regards, Marc Schwartz On Jun 4, 2012, at 1:30 PM, Bert Gunter wrote: Actually, I think it's ?data.frame that he should read. The salient points are that: 1. All data frames must have unique row names. If not provided, they are produced. Row numbers **are** row names. 2. The return value of read methods are data frames. -- Bert On Mon, Jun 4, 2012 at 11:05 AM, David L Carlson dcarl...@tamu.edu wrote: Try help(read.delim) - always a good strategy before using a function for the first time: In it, you will find: Using row.names = NULL forces row numbering. Missing or NULL row.names generate row names that are considered to be 'automatic' (and not preserved by as.matrix). -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Ed Siefker Sent: Monday, June 04, 2012 12:47 PM To: r-help@r-project.org Subject: [R] Why do I have a column called row.names? I'm trying to read in a tab separated table with read.delim(). I don't particularly care what the row names are. My data file looks like this: start stopSymbol Insert sequence Clone End Pair FISH 203048 67173930ABC8-43024000D23TI:993812543 TI:993834585 255176 87869359ABC8-43034700N15TI:995224581 TI:995237913 1022033 1060472 ABC27-1253C21 TI:2094436044 TI:2094696079 1022033 1061172 ABC23-1388A1TI:2120730727 TI:2121592459 I have to do something with row.names because my first column has duplicate entries. So I read in the file like this: BACS-read.delim(testdata.txt, row.names=NULL, fill=TRUE) head(BACS) row.namesstart stop Symbol Insert.sequence Clone.End.Pair 1203048 67173930 ABC8-43024000D23 NATI:993812543 TI:993834585 2255176 87869359 ABC8-43034700N15 NATI:995224581 TI:995237913 3 1022033 1060472ABC27-1253C21 NA TI:2094436044 TI:2094696079 4 1022033 1061172 ABC23-1388A1 NA TI:2120730727 TI:2121592459 FISH 1 NA 2 NA 3 NA 4 NA Why is there a column named row.names? I've tried a few different ways of invoking this, but I always get the first column named row.names, and the rest of the columns shifted by one. Obviously I could fix this by using row.names-, but I'd like to understand why this happens. Any insight? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 curve fitting (nls): starting point and quality of fit
Nerak nerak.t at hotmail.com writes: Hi all, Like a lot of people I noticed that I get different results when I use nls in R compared to the exponential fit in excel. A bit annoying because often the R^2 is higher in excel but when I'm reading the different topics on this forum I kind of understand that using R is better than excel? (I don't really understand how the difference occurs, but I understand that there is a different way in fitting, in excel a single value can make the difference, in R it looks at the whole function? I read this: Fitting a function is an approximation, trying to find a minimum. Think of frozen mountain lake surrounded by mountains. Excel's Solver will report the highest tip of the snowflake on the lake, if it finds it. nls will find out that the lake is essentially flat compare to the surrounding and tell you this fact in unkind word. ) Snarky, but I like it. Two alternatives to nls are (1) Gabor Grothendieck's nls2 package: nls2 is an R package that adds the brute-force algorithm and multiple starting values to the R nls function. nls2 is free software licensed under the GPL and available from CRAN. It provides a function, nls2, which is a superset of the R nls function which it, in turn, calls. Or John Nash's nlmrt package https://r-forge.r-project.org/R/?group_id=395 : nlmrt provides tools for working with nonlinear least squares problems using a calling structure similar to, but much simpler than, that of the nls() function. Moreover, where nls() specifically does NOT deal with small or zero residual problems, nlmrt is quite happy to solve them. It also attempts to be more robust in finding solutions, thereby avoiding singular gradient messages that arise in the Gauss-Newton method within nls(). The Marquardt-Nash approach in nlmrt generally works more reliably to get a solution, though this may be one of a set of possibilities, and may also be statistically unsatisfactory. I have several questions about nls: 1. The nls method doesn't give an R^2. But I want to determine the quality of the fit. To understand how to use nls I read Technical note: Curve fitting with the R environment for Statistical Computing. In that document they suggested this to calculate R^2: RSS.p-sum(residuals(fit)^2) TSS-sum((y-mean(y))^2) r.squared-1-(RSS.p/TSS) LIST.rsq-r.squared (with fit my results of the nls: formula y ~ exp.f(x, a, b) : y : a*exp(-b*x)) While I was reading on the internet to find a possible reason why I get different results using R and excel, I also read lots of different things about the R^2 problem in nls. Is the method I'm using now ok, or should someone suggest to use something else? You could use the residual sum of squares as the quality of the fit: (i.e. RSS.p above). If you want a _unitless_ metric of the quality of the fit, I'm not sure what you should do. 2. Another question I have is like a lot of people about the singular gradient problem. I didn't know the best way to chose my starting values for my coefficients. when it was too low, I got this singular gradient error. Raising the value helped me to get rid of that error. Changing that value didn't change my coefficients nor R^2. I was wondering if that's ok, just to raise the starting value of one of my coefficients? [snip] If you can find a set of starting coefficients that give you a sensible fit to the data without any convergence warnings, you shouldn't worry that other sets of starting coefficients that *don't* work also exist. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Who knows how to use it in Vertica 6
Hi All, As you may already know, Vertica announced it now supports user defined R function. Does anybody tried this alreay or maybe have more info than Vertica site? http://www.vertica.com/content/vertica-an-hp-company-enables-users-to-connect-access-analyze-and-manage-any-data-anywhere/ Best, -Alex [[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] Why do I have a column called row.names?
On 6/4/2012 12:12 PM, Marc Schwartz wrote: To jump into the fray, he really needs to read the Details section of ?read.table and arguably, the source code for read.table(). It is not that the resultant data frame has row names, but that an additional first *column name* called 'row.names' is created, which does not exist in the source data. The Details section has: If row.names is not specified and the header line has one less entry than the number of columns, the first column is taken to be the row names. This allows data frames to be read in from the format in which they are printed. If row.names is specified and does not refer to the first column, that column is discarded from such files. The number of data columns is determined by looking at the first five lines of input (or the whole file if it has less than five lines), or from the length of col.names if it is specified and is longer. This could conceivably be wrong if fill or blank.lines.skip are true, so specify col.names if necessary (as in the ‘Examples’). In the source code for read.table(), which is called by read.delim() with differing defaults, there is: rlabp- (cols - col1) == 1L and a few lines further down: if (rlabp) col.names- c(row.names, col.names) So the last code snippet is where a new first column name called 'row.names' is pre-pended to the column names found from reading the header row. 'cols' and 'col1' are defined in prior code based upon various conditions. Not having the full data set and possibly having line wrap and TAB problems with the text that Ed pasted into his original post, I cannot properly replicate the conditions that cause the above code to be triggered. If Ed can put the entire file someplace and provide a URL for download, perhaps we can better trace the source of the problem, or Ed might use ?debug to follow the code execution in read.table() and see where the relevant flags get triggered. The latter option would help Ed learn how to use the debugging tools that R provides to dig more deeply into such issues. I agree that the actual file would be helpful. But I can get it to happen if there are extra delimiters at the end of the data lines (which there can be with a separator of tab which is not obviously visible). I can get it with: BACS-read.delim(textConnection( start\tstop\tSymbol\tInsert sequence\tClone End Pair\tFISH 203048\t67173930\t\tABC8-43024000D23\tTI:993812543\tTI:993834585\t 255176\t87869359\t\tABC8-43034700N15\tTI:995224581\tTI:995237913\t 1022033\t1060472\t\tABC27-1253C21\tTI:2094436044\tTI:2094696079\t 1022033\t1061172\t\tABC23-1388A1\tTI:2120730727\tTI:2121592459\t), row.names=NULL, fill=TRUE) which gives BACS row.namesstart stop Symbol Insert.sequence 1203048 67173930 NA ABC8-43024000D23TI:993812543 2255176 87869359 NA ABC8-43034700N15TI:995224581 3 1022033 1060472 NAABC27-1253C21 TI:2094436044 4 1022033 1061172 NA ABC23-1388A1 TI:2120730727 Clone.End.Pair FISH 1 TI:993834585 NA 2 TI:995237913 NA 3 TI:2094696079 NA 4 TI:2121592459 NA or str(BACS) 'data.frame': 4 obs. of 7 variables: $ row.names : chr 203048 255176 1022033 1022033 $ start : int 67173930 87869359 1060472 1061172 $ stop : logi NA NA NA NA $ Symbol : Factor w/ 4 levels ABC23-1388A1,..: 3 4 2 1 $ Insert.sequence: Factor w/ 4 levels TI:2094436044,..: 3 4 1 2 $ Clone.End.Pair : Factor w/ 4 levels TI:2094696079,..: 3 4 1 2 $ FISH : logi NA NA NA NA The extra delimiter at the end of the line triggers the one-more-data-than-column-name condition, which then gives the row.names column. Regards, Marc Schwartz On Jun 4, 2012, at 1:30 PM, Bert Gunter wrote: Actually, I think it's ?data.frame that he should read. The salient points are that: 1. All data frames must have unique row names. If not provided, they are produced. Row numbers **are** row names. 2. The return value of read methods are data frames. -- Bert On Mon, Jun 4, 2012 at 11:05 AM, David L Carlsondcarl...@tamu.edu wrote: Try help(read.delim) - always a good strategy before using a function for the first time: In it, you will find: Using row.names = NULL forces row numbering. Missing or NULL row.names generate row names that are considered to be 'automatic' (and not preserved by as.matrix). -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Ed Siefker Sent: Monday, June 04, 2012 12:47 PM To: r-help@r-project.org Subject: [R] Why do I have a column called row.names? I'm trying to read in a tab separated table with read.delim(). I don't particularly care what the row names are. My data file looks like this: start stopSymbol Insert sequence Clone End Pair FISH
[R] Spliting Lists into matrices
Dear Rui Barradas, Mackay and all R Users, Thankyou very much for your reply. You helped me a lot. I got what I wanted. I just want one more favor from you, if you could. Suppose I have certain number of lists of data frame, say 50. Each list has yearly data in it. Of-course, some lists have 365 readings and some have 366(due to leap year). Now I want to split lists into two different matrices, one containing leap years and other with normal years. I hope you will be kind enough to help me as you did before. Eliza Botto Waters Inn Date: Mon, 4 Jun 2012 10:51:49 +0100 From: ruipbarra...@sapo.pt To: eliza_bo...@hotmail.com CC: r-help@r-project.org Subject: Re: [R] Variate Hello, Sorry for not understanding your problem, but it really seemed like homework. Now, when I answered scale(x) I meant it, it transforms a matrix in (x - mean)/sd, column by column. If you're new to R, to use the on-line help the instruction is help(scale) ?scale # shortcut As for your graph, I agree with Duncan, 92 lines on the same graph doesn't seem to be a good idea. Anyway, using base R, it could be done along the lines of set.seed(1) nc - 92 # number of columns nr - 366 # number of rows x - matrix(rexp(nr*nc), ncol=nc) x1 - scale(x) # z, standard normal (in fact, studentized) y1 - apply(x, 2, plnorm) # log-normal colrs - rainbow(nc) plot(1, type=n, xlim=c(min(x1), max(x1)), ylim=c(min(y1), max(y1)), xlab=, ylab=) # if you want lines sapply(seq_len(nc), function(j){ i - order(x1[, j]) lines(x1[i, j], y1[i, j], col=colrs[j])}) # if you want points sapply(seq_len(nc), function(j) points(x1[, j], y1[, j], col=colrs[j], pch=.)) Hope this helps, Rui Barradas Em 04-06-2012 07:38, eliza botto escreveu: Dear Mc kay, thankyou very much for your reply. we are extremly greatful to you. we actually wanted all on one scale. we want to compare them all on one axis. kindle see if you could help us on that. one more thing, does this practice give us normal reduced variant on x-axis because we stricktly want normal reduced variant on x-axis. i hope you will cooperate. eliza botto waters inn Date: Mon, 4 Jun 2012 11:54:11 +1000 To: r-help@r-project.org From: mac...@northnet.com.au Subject: Re: [R] Variate Hi Eliza You will not want 1 panel with 96 lines - too confusing after about 20 Instead 1 per panel or with groups using useOuterStrips and combineLimits from latticeExtra package Try this -- a minimal example with an 12 row 8 col grid done on the fly setseed(12) Sites- 1:92 dat- data.frame(y = rep(rnorm(5),92), x = rep(1:5,92), site = rep(Sites,each = 5)) xyplot(y ~ x|site,dat, as.table=T, strip = F, layout = c(8,12), scales = list(x = list(alternating = 2),y=list(alternating=1)), type = b, panel = function(x,y,...){ pnl=panel.number() panel.xyplot(x,y,...) panel.text(4,-1.5,Sites[pnl], cex = 0.6) } ) or with groupings for Site something like (untested) xyplot(y ~ x|groupings,dat, as.table=T, strip = F, strip.left = T, groups = site, scales = list(x = list(alternating = 2),y=list(alternating=1)), type = b, panel = function(x,y,...){ pnl=panel.number() panel.xyplot(x,y,...) panel.text(4,-1.5,Sites[pnl], cex = 0.6) } ) You will need an extra column for groupings This can also be done with the base plot function but lattice gives more flexibility, see ?xyplot and particularly par.settings into get things right size Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 11:01 4/06/2012, you wrote: Content-Type: text/plain Content-Disposition: inline Content-length: 2431 Dear R users, We are working on a project called,Environmental Impact Assessment. We are stationed at alpine regions of Ireland to see the impact of rainfall on localities. We have divided our study area into 92 stations. We have also collected 1 year data from each station. Afterwards we placed data into a matrix in such a way that we got 366*92 matrix. 366 stands for number of days. What we want is a lognormal probability plot, of each station(which is individual column of matrix) with normal reduced variant on x-axis. In this way, we should be getting, at the end, 92 curves, one for each station, on same coordinate axis. Kindly help us on that. We are all very new to R. Eliza botto Waters Inn CC: r-help@r-project.org From: dwinsem...@comcast.net To: eliza_bo...@hotmail.com
[R] regression methods for rare events?
Hi everybody! I have a sample with n=2.000. This sample contains rare events (10, 20, 30 individuals with a specific illness). Now I'd like to do a logistic regression in order to identify risk factors. I have several independent variables on an interval scale. Does anyone know whether the number of these rare events is sufficient in order to calculate a multivariate logistic regression? Or are there any alternative models I should use? (which are available in R) Thank you very much any advice! David [[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] regular expression and R
Dear R People: Are there any courses which describe how to use regular expressions in R, please? Or any books, please? I know a little bit (very little) but would like to know more. Thanks, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] regular expression and R
On Jun 4, 2012, at 3:48 PM, Erin Hodgess wrote: Dear R People: Are there any courses which describe how to use regular expressions in R, please? Or any books, please? I know a little bit (very little) but would like to know more. Thanks, Erin Hi Erin, The two places that I typically use for reference are: http://www.regular-expressions.info/ and Mastering Regular Expressions Jeffrey Friedl http://www.amazon.com/Mastering-Regular-Expressions-Second-Edition/dp/0596002890 Regards, 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] how a latent state matrix is updated using package R2WinBUGS
Thanks! Jean Uwe Ligges lig...@statistik.tu-dortmund.de wrote on 05/26/2012 09:30:28 AM: On 23.05.2012 17:20, Jean V Adams wrote: I'm trying to understand how a latent state matrix is updated by the MCMC iterations in a WinBUGS model, using the package R2WinBUGS and an example from Kery and Schaub's (2012) book, Bayesian Population Analysis Using WinBUGS. The example I'm using is 7.3.1. from a chapter on the Cormack-Jolly-Seber model. Some excerpted code is included at the end of this message; the full code is available at http://www.vogelwarte.ch/downloads/files/publications/BPA/bpa-code.txt The latent state of individual i on occasion t is stored in the z matrix where rows index individuals (owls that are marked and released) and columns index capture occasions. Each value in the matrix represents the latent state for individual i at occasion t: z[i,t]=0 if individual i is dead at time t, and =1 if individual i is alive at time t. In the example, a matrix of known values for z is created from the capture histories and provided as data; I will call it known.z. And a matrix of initial values (where z is unknown) is also created and provided; I will call it init.z. The dimensions of these two matrices are 250 individuals by 6 capture occasions. However, if I save z as a parameter of interest, the dimensions of the last saved z matrix from the last chain, last.z- cjs.c.c$last.values[[cjs.c.c$n.chains]]$z, are 217 by 5. Why are the dimensions different? What happened to the other 33 rows (individuals) and 1 column (occasion)? I thought perhaps that the missing rows corresponded to those rows where all the latent states are known, but that does not appear to be the case. There were no individuals with 6 known latent states, and only 4 (not 33) with 5: table(apply(!is.na(known.z), 1, sum)) 0 1 2 3 4 5 162 39 27 14 4 4 Also, how can I verify that the known values of z are maintained in the iterated z matrices? Even with the loss of 33 rows, those individuals with 5 known 1=alive latent states don't seem to line up. seq(known.z[,1])[apply(known.z[,-1], 1, paste, collapse=)==1] [1] 2 6 17 46 seq(last.z[,1])[apply(last.z, 1, paste, collapse=)==1] [1] 1 26 110 112 115 116 I would appreciate any insight you might have to offer. I am experienced with R, but relatively inexperienced with WinBUGS and the R2WinBUGS package. I am using R 2.15.0, R2WinBUGS 2.1-18, and WinBUGS 1.4.3 on Windows 7. R2WinBUGS is just an interface package for R that exports data, calls WinBUGS and imports the results. For BUGS related questions, i.e. in particular the correct specification of the model (file), I'd recommend to ask on the BUGS related mailing lists. Note that the new version of WinBUGS is called OpenBUGS and the is a more direct R interface called BRugs. Best, Uwe Ligges Thanks. Jean init.z[1:10, ] [,1] [,2] [,3] [,4] [,5] [,6] [1,] NA00000 [2,] NA NA NA NA NA NA [3,] NA NA0000 [4,] NA00000 [5,] NA00000 [6,] NA NA NA NA NA NA [7,] NA00000 [8,] NA NA0000 [9,] NA NA NA000 [10,] NA NA NA000 known.z[1:10, ] [,1] [,2] [,3] [,4] [,5] [,6] [1,] NA NA NA NA NA NA [2,] NA11111 [3,] NA1 NA NA NA NA [4,] NA NA NA NA NA NA [5,] NA NA NA NA NA NA [6,] NA11111 [7,] NA NA NA NA NA NA [8,] NA1 NA NA NA NA [9,] NA11 NA NA NA [10,] NA11 NA NA NA last.z[1:10, ] [,1] [,2] [,3] [,4] [,5] [1,]11111 [2,]00001 [3,]00001 [4,]00000 [5,]00001 [6,]11100 [7,]00000 [8,]00001 [9,]00000 [10,]00000 model { # Priors and constraints for (i in 1:nind){ for (t in f[i]:(n.occasions-1)){ phi[i,t]- mean.phi p[i,t]- mean.p } #t } #i mean.phi ~ dunif(0, 1) # Prior for mean survival mean.p ~ dunif(0, 1)# Prior for mean recapture # Likelihood for (i in 1:nind){ # Define latent state at first capture z[i,f[i]]- 1 for (t in (f[i]+1):n.occasions){ # State process z[i,t] ~ dbern(mu1[i,t]) mu1[i,t]- phi[i,t-1] * z[i,t-1] # Observation process y[i,t] ~ dbern(mu2[i,t])
[R] cSpade sequenceID
hi I have any problems with cspade; I convert my columns in factor, and then I coerce my data frame in transaction; but when I want do the cspade exit this message: slot transactionInfo: missing 'sequenceID' or 'eventID So I ask to everybody: somebody help me? because i tried everything without results. Thank to everybody -- View this message in context: http://r.789695.n4.nabble.com/cSpade-sequenceID-tp4632311.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] probit analysis
Hello! I have a very simple set of data and I would like to analyze them with probit analysis. The data are: X Event Trial 1210 8 8 121 6 8 60.5 6 8 I want to estimate the value of X that will give a 95% hit rate (Event/Trial) and the corresponding 95% CI. you can help me? Thanks!! Trinh [[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] simulation of modified bartlett's test
Hi, I run this code to get the power of the test for modified bartlett's test..but I'm not really sure that my coding is right.. #normal distribution unequal variance asim-5000 pv-rep(NA,asim) for(i in 1:asim) {print(i) set.seed(i) n1-20 n2-20 n3-20 mu-0 sd1-sqrt(25) sd2-sqrt(50) sd3-sqrt(100) g1-rnorm(n1,mu,sd1) g2-rnorm(n2,mu,sd2) g3-rnorm(n3,mu,sd3) x=c(g1,g2,g3) group=c(rep(1,n1),rep(2,n2),rep(3,n3)) N=60 k=3 v1=var(g1) v2=var(g2) v3=var(g3) #pooled variance A=((n1-1)*v1+(n2-1)*v2+(n3-1)*v3)/(N-k) #calculate B B=((N-k)*(log(A)))-((n1-1)*log(v1)+(n2-1)*log(v2)+(n3-1)*log(v3)) #calculate C C=1+(1/(3*(k-1))*(((1/(n1-1))+(1/(n2-1))+(1/(n3-1)))-(1/(N-k #calculate layard estimator xbar1=mean(g1) xbar2=mean(g2) xbar3=mean(g3) sum1=sum((g1-xbar1)^4) sum2=sum((g2-xbar2)^4) sum3=sum((g3-xbar3)^4) sum4=sum((g1-xbar1)^2) sum5=sum((g2-xbar2)^2) sum6=sum((g3-xbar3)^2) y= (N*(sum1+sum2+sum3))/((sum4+sum5+sum6)^2) #calculate bartlett modified statistic bar2=B/(C*(1/2)*(y-1)) bar2 pv[i]-pchisq(bar2,2,lower=FALSE) } mean(pv0.01) mean(pv0.05) -- View this message in context: http://r.789695.n4.nabble.com/simulation-of-modified-bartlett-s-test-tp4632305.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] simulation of modified bartlett's test
Hi, I run this code to get the power of the test for modified bartlett's test..but I'm not really sure that my coding is right.. #normal distribution unequal variance asim-5000 pv-rep(NA,asim) for(i in 1:asim) {print(i) set.seed(i) n1-20 n2-20 n3-20 mu-0 sd1-sqrt(25) sd2-sqrt(50) sd3-sqrt(100) g1-rnorm(n1,mu,sd1) g2-rnorm(n2,mu,sd2) g3-rnorm(n3,mu,sd3) x=c(g1,g2,g3) group=c(rep(1,n1),rep(2,n2),rep(3,n3)) N=60 k=3 v1=var(g1) v2=var(g2) v3=var(g3) #pooled variance A=((n1-1)*v1+(n2-1)*v2+(n3-1)*v3)/(N-k) #calculate B B=((N-k)*(log(A)))-((n1-1)*log(v1)+(n2-1)*log(v2)+(n3-1)*log(v3)) #calculate C C=1+(1/(3*(k-1))*(((1/(n1-1))+(1/(n2-1))+(1/(n3-1)))-(1/(N-k #calculate layard estimator xbar1=mean(g1) xbar2=mean(g2) xbar3=mean(g3) sum1=sum((g1-xbar1)^4) sum2=sum((g2-xbar2)^4) sum3=sum((g3-xbar3)^4) sum4=sum((g1-xbar1)^2) sum5=sum((g2-xbar2)^2) sum6=sum((g3-xbar3)^2) y= (N*(sum1+sum2+sum3))/((sum4+sum5+sum6)^2) #calculate bartlett modified statistic bar2=B/(C*(1/2)*(y-1)) bar2 pv[i]-pchisq(bar2,2,lower=FALSE) } mean(pv0.01) mean(pv0.05) -- View this message in context: http://r.789695.n4.nabble.com/simulation-of-modified-bartlett-s-test-tp4632308.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] X11 font error on headless server running Xvfb
I am trying to run an R script to create a .png file containing a tree map on a headless Linux server using Xvfb. When I try to run tmPlot, I get the following errors and warnings: Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : X11 font -adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*, face 1 at size 9 could not be loaded Calls: tmPlot ... Anonymous - widthDetails - widthDetails.text - grid.Call In addition: Warning messages: 1: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : X11 protocol error: BadMatch (invalid parameter attributes) ... etc. (complete error message below) The .png file does contain a partially constructed graph. When I try something simple like plot(x,y) I get a plot with warnings. The results from capabilities() and X11Fonts() (see end of message) suggest to me that it should work. Any idea what is happening and how to fix the problem (or work around it)? Thanks, Jay -- sessionInfo() R version 2.15.0 (2012-03-30) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] grid stats graphics grDevices utils datasets methods [8] base other attached packages: [1] treemap_1.0-4 data.table_1.8.0 RColorBrewer_1.0-5 capabilities() jpeg png tifftcltk X11 aqua http/ftp sockets TRUE TRUE TRUE TRUE TRUEFALSE TRUE TRUE libxml fifo clediticonv NLS profmemcairo TRUE TRUEFALSE TRUE TRUEFALSEFALSE X11Fonts() $serif [1] -*-times-%s-%s-*-*-%d-*-*-*-*-*-*-* $sans [1] -*-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-* $mono [1] -*-courier-%s-%s-*-*-%d-*-*-*-*-*-*-* $Times [1] -adobe-times-%s-%s-*-*-%d-*-*-*-*-*-*-* $Helvetica [1] -adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-* $CyrTimes [1] -cronyx-times-%s-%s-*-*-%d-*-*-*-*-*-*-* $CyrHelvetica [1] -cronyx-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-* $Arial [1] -monotype-arial-%s-%s-*-*-%d-*-*-*-*-*-*-* $Mincho [1] -*-mincho-%s-%s-*-*-%d-*-*-*-*-*-*-* png(file=/tmp/tmpzT4H0e.png,width = 800, height = 800) tmPlot(myDF,index=c(vars[1],vars[2]), + vSize=vars[4], + vColor=vars[3], + type=value) Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : X11 font -adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*, face 1 at size 9 could not be loaded Calls: tmPlot ... Anonymous - widthDetails - widthDetails.text - grid.Call In addition: Warning messages: 1: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : X11 protocol error: BadMatch (invalid parameter attributes) 2: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : X11 protocol error: BadMatch (invalid parameter attributes) 3: In grid.Call.graphics(L_rect, x$x, x$y, x$width, x$height, resolveHJust(x$just, : X11 protocol error: BadMatch (invalid parameter attributes) 4: In grid.Call.graphics(L_rect, x$x, x$y, x$width, x$height, resolveHJust(x$just, : X11 protocol error: BadMatch (invalid parameter attributes) 5: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : X11 protocol error: BadMatch (invalid parameter attributes) 6: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : X11 protocol error: BadMatch (invalid parameter attributes) 7: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : X11 protocol error: BadMatch (invalid parameter attributes) 8: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : X11 protocol error: BadMatch (invalid parameter attributes) 9: In grid.Call.graphics(L_rect, x$x, x$y, x$width, x$height, resolveHJust(x$just, : X11 protocol error: BadMatch (invalid parameter attributes) 10: In grid.Call.graphics(L_rect, x$x, x$y, x$width, x$height, resolveHJust(x$just, : X11 protocol error: BadMatch (invalid parameter attributes) Execution halted __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] get index of current element in vector
(Just learning R) I have this vector: v - c(1:10) Now, I want to multiply each element of that vector with a scalar value multiplied with its index: vm - v * scalar * indexOfCurrentElementOf_v Is that possible without using a loop? In a loop I would do this: for (i in 1:length(a)) a[i] - scalar * a[i] [[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] Chi square value of anova(binomialglmnull, binomglmmod, test=Chisq)
So sorry, My response variable is site (not gender!). The selection process was: str(data) 'data.frame': 1003 obs. of 5 variables: $ site : Factor w/ 2 levels 0,1: 1 1 1 1 1 1 1 1 1 1 ... $ sex : Factor w/ 2 levels 0,1: NA NA NA NA 1 NA NA NA NA NA ... $ age : Factor w/ 2 levels 0,1: 1 1 1 1 1 1 1 1 1 1 ... $ cohort: Factor w/ 10 levels 1999,2000,..: 10 10 10 10 10 10 10 10 10 10 ... $ birth : Factor w/ 3 levels 5,6,7: 3 3 2 2 2 2 2 2 2 2 ... datasex-subset(data, sex !=NA) *Here below the structure of the analysis and only the anova.glm of the last, selected model, mod4: * mod1 - glm(site ~ sex + birth + cohort + sex:birth, data=datasex, family = binomial) summary(mod1) anova(mod1,update(mod1,~.-sex:birth),test=Chisq) mod2 - glm(site ~ sex + birth + cohort, data=datasex, family = binomial) summary(mod2) anova(mod2,update(mod2,~.-sex),test=Chisq) mod3 - glm(site ~ birth + cohort, data=data, family = binomial) summary(mod3) anova(mod3,update(mod3,~.-birth),test=Chisq) mod4 - glm(site ~ cohort, data=data, family = binomial) summary(mod4) anova(mod4,update(mod4,~.-cohort),test=Chisq) Analysis of Deviance Table Model 1: site ~ cohort Model 2: site ~ 1 Resid. Df Resid. Dev Df Deviance P(|Chi|) 1 993 1283.7 2 1002 1368.2 -9 -84.554 2.002e-14 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 *My question:* In this case, the Chi2 value would be the difference in deviance between models and d.f. the difference in d.f. (84.554 and 9)? In other words may I correctly assess: /cohorts were unevenly distributed between sites ( Chi2=84.5, df=9, p 0.001)/? -- View this message in context: http://r.789695.n4.nabble.com/Chi-square-value-of-anova-binomialglmnull-binomglmmod-test-Chisq-tp4632293p4632312.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] Negative variance with lavaan in a multigroup analysis.
Hi list members, I saw a couple lavaan posts here so I think I’m sending this to the correct list. I am trying to run a multigroup analysis with lavaan in order to compare behavioural correlations across two populations. I’m following the method suggested in the paper by Dingemanse et al. (2010) in Behavioural Ecology. In one of the groups, lavaan returns negative variance for one path and I’m unable to obtain the corresponding R-square. As far as I know, this is not due to measurement error so I’m wondering what else could be causing this. Since the behavioral variables were standardized at the population level prior to SEM analysis, lavaan should return 1 for the variance and all paths coefficients should vary between 0 and 1, right? Is there anything wrong in my code that may be causing this? Thanks a lot for your help! Raphael Royaute PhD candidate Dept Natural Resource Sciences McGill University, Macdonald campus Below is my code and output (my apologies, this is a pretty lengthy output): Riskmodel2_cfa - '# Latent variable SySt =~ Activity+Aggression+Voracity # Residuals Boldness~~Boldness' fit.riskmodel2_multi_Ad_cfa - cfa(Riskmodel2_cfa, data=Ad_scale, std.lv=T,std.ov=T, se= boot,test=bootstrap, bootstrap=5000L,group=Site) summary(fit.riskmodel2_multi_Ad_cfa,standardized=T, rsquare=T) lavaan (0.4-14) converged normally after 50 iterations Number of observations per group 1 56 0 41 Estimator ML Minimum Function Chi-square 6.171 Degrees of freedom 6 P-value 0.404 P-value (Bollen-Stine Bootstrap) 0.566 Chi-square for each group: 1 4.832 0 1.339 Parameter estimates: Information Observed Standard Errors Bootstrap Number of requested bootstrap draws 5000 Number of successful bootstrap draws 3423 Group 1 [1]: Estimate Std.err Z-value P(|z|) Std.lv Std.all Latent variables: SySt =~ Activity 0.295 0.193 1.532 0.126 0.295 0.298 Aggression 0.962 7.533 0.128 0.898 0.962 0.971 Voracity 0.481 1.223 0.393 0.694 0.481 0.485 Intercepts: Activity 0.000 0.132 0.000 1.000 0.000 0.000 Aggression 0.000 0.131 0.000 1.000 0.000 0.000 Voracity -0.000 0.133 -0.000 1.000 -0.000 -0.000 Boldness 0.000 0.130 0.000 1.000 0.000 0.000 SySt 0.000 0.000 0.000 Variances: Boldness 0.982 0.192 0.982 1.000 Activity 0.895 0.194 0.895 0.911 Aggression 0.056 291.974 0.056 0.057 Voracity 0.751 31.367 0.751 0.765 SySt 1.000 1.000 1.000 Group 2 [0]: Estimate Std.err Z-value P(|z|) Std.lv Std.all Latent variables: SySt =~ Activity 1.599 11.281 0.142 0.887 1.599 1.619 Aggression 0.162 0.219 0.740 0.459 0.162 0.164 Voracity 0.260 0.238 1.094 0.274 0.260 0.263 Intercepts: Activity 0.000 0.155 0.000 1.000 0.000 0.000 Aggression -0.000 0.154 -0.000 1.000 -0.000 -0.000 Voracity 0.000 0.156 0.000 1.000 0.000 0.000 Boldness 0.000 0.156 0.000 1.000 0.000 0.000 SySt 0.000 0.000 0.000 Variances: Boldness 0.976 0.156 0.976 1.000 Activity -1.580 459.764 -1.580 -1.620 Aggression 0.949 0.197 0.949 0.973 Voracity 0.908 0.248 0.908 0.931 SySt 1.000 1.000 1.000 R-Square Group 1: Activity 0.089 Aggression 0.943 Voracity 0.235 R-Square Group 0: Activity NA Aggression 0.027 Voracity 0.069 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Convert 2-dim array to 3-dim array
Hi Dave, I tested the as.array. It gives a different dimension when compared to array set.seed(1) datE-data.frame(A=rnorm(30,0.5)) myArr=as.array(unlist(datE),dim=c(5,2,3)) myArr A1 A2 A3 A4 A5 A6 -0.12645381 0.68364332 -0.33562861 2.09528080 0.82950777 -0.32046838 A7 A8 A9 A10 A11 A12 0.98742905 1.23832471 1.07578135 0.19461161 2.01178117 0.88984324 A13 A14 A15 A16 A17 A18 -0.12124058 -1.71469989 1.62493092 0.45506639 0.48380974 1.44383621 A19 A20 A21 A22 A23 A24 1.32122120 1.09390132 1.41897737 1.28213630 0.57456498 -1.48935170 A25 A26 A27 A28 A29 A30 1.11982575 0.44387126 0.34420449 -0.97075238 0.02184994 0.91794156 is.array(myArr) [1] TRUE dim(myArr) [1] 30 myArr1=array(unlist(datE),dim=c(5,2,3)) myArr1 , , 1 [,1] [,2] [1,] -0.1264538 -0.3204684 [2,] 0.6836433 0.9874291 [3,] -0.3356286 1.2383247 [4,] 2.0952808 1.0757814 [5,] 0.8295078 0.1946116 , , 2 [,1] [,2] [1,] 2.0117812 0.4550664 [2,] 0.8898432 0.4838097 [3,] -0.1212406 1.4438362 [4,] -1.7146999 1.3212212 [5,] 1.6249309 1.0939013 , , 3 [,1] [,2] [1,] 1.418977 0.44387126 [2,] 1.282136 0.34420449 [3,] 0.574565 -0.97075238 [4,] -1.489352 0.02184994 [5,] 1.119826 0.91794156 dim(myArr1) [1] 5 2 3 A.K. - Original Message - From: David Winsemius dwinsem...@comcast.net To: David Zastrau dav...@tzi.de Cc: r-help@r-project.org Sent: Monday, June 4, 2012 10:45 AM Subject: Re: [R] Convert 2-dim array to 3-dim array On Jun 4, 2012, at 5:08 AM, David Zastrau wrote: Hello R-users, I'd like to load data from a CSV-file to a 3-dimensional array. However the default seems to be 2-dimensional. No. that is not the problem. It would also be ok to load the data and then convert it to a 3-dimensional structure. I've been trying: dat = read.csv(filename) myArr = as.array(dat, dim = c(12,100,3)) However, I get an error message: Error in `dimnames-.data.frame`(`*tmp*`, value = list(n)) : invalid 'dimnames' given for data frame A dataframe is a list structure while both array and matrix are expecting the first argument to be an atomic vector. Try this (although it is a blind guess because you have not provided the structure of 'dat' myArr = as.array( unlist(dat), dim = c(12,100,3)) --David. And I don't know how how to set the dimnames. I would appreciate any help! Best Wishes Dave [[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. 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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 methods for rare events?
On Jun 4, 2012, at 3:47 PM, David Studer wrote: Hi everybody! I have a sample with n=2.000. This sample contains rare events (10, 20, 30 individuals with a specific illness). Now I'd like to do a logistic regression in order to identify risk factors. I have several independent variables on an interval scale. Does anyone know whether the number of these rare events is sufficient in order to calculate a multivariate logistic regression? Or are there any alternative models I should use? (which are available in R) Thank you very much any advice! David The quick answer is yes you can, but you will be very limited in how many covariates you can include in each of the respective models. You are looking at event rates of 0.5%, 1.0% and 1.5% which in my experience are not truly rare, per se. We had a recent post with an event rate on the order of 0.006%, albeit with millions of records. That is rare... :-) Typical rules of thumb, to avoid over-fitting for LR models would suggest that you should have between 10 and 20 events per covariate degree of freedom. A continuous covariate would be 1 df, an N-level factor would be N-1 df. With your sample and the number of events, you would be limited to perhaps no more than 2 or 3 covariate df and even then you should give consideration to using penalization to avoid over-fitting. Two references that would be helpful to you are: Frank's Regression Modeling Strategies book: http://www.amazon.com/exec/obidos/ASIN/0387952322/ There is a helpful and updated PDF download here: http://biostat.mc.vanderbilt.edu/wiki/pub/Main/RmS/rms.pdf and I would focus, in your case, on the use of the lrm() function in Frank's rms CRAN package, along with related tools for penalization and validation. Also, Steyerberg's Clinical Prediction Models book: http://www.amazon.com/Clinical-Prediction-Models-Development-Validation/dp/038777243X which is an excellent reference and has relevant examples using R. The rumor is that Frank is working on a new edition of his book with a greater focus on the use of R and is due RSN. Perhaps there will be copies at useR in Nashville next week? One could hope... :-) Regards, 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] Spliting Lists into matrices
Hello, I'm glad it helped. To answer to this new question, we need to see what your data looks like. When you say 'list' are you refering to the type of R data structure 'list'? Or to data.frames? For us to see the best way is to use function dput. Example: df1 - data.frame(A=rnorm(10), B=runif(10)) df2 - data.frame(A=rnorm(11), B=runif(11)) lst1 - list(df1, df2) # a list of data.frames dput(lst1) # - paste the output of this in a post (If your data.frames are not in a list do NOT create a list just to post, dput them _as_they_are_.) Can be dput(df1); dput(df2) If they are in a list, don't dput the entire list, 50x365 or 366 is endless, just enough for us to see. If you have several (50) data.frames, do they share something such as a name prefix? Any information you find relevant, post it. Rui Barradas Em 04-06-2012 21:41, eliza botto escreveu: Dear Rui Barradas, Mackay and all R Users, Thankyou very much for your reply. You helped me a lot. I got what I wanted. I just want one more favor from you, if you could. Suppose I have certain number of lists of data frame, say 50. Each list has yearly data in it. Of-course, some lists have 365 readings and some have 366(due to leap year). Now I want to split lists into two different matrices, one containing leap years and other with normal years. I hope you will be kind enough to help me as you did before. Eliza Botto Waters Inn Date: Mon, 4 Jun 2012 10:51:49 +0100 From: ruipbarra...@sapo.pt To: eliza_bo...@hotmail.com CC: r-help@r-project.org Subject: Re: [R] Variate Hello, Sorry for not understanding your problem, but it really seemed like homework. Now, when I answered scale(x) I meant it, it transforms a matrix in (x - mean)/sd, column by column. If you're new to R, to use the on-line help the instruction is help(scale) ?scale # shortcut As for your graph, I agree with Duncan, 92 lines on the same graph doesn't seem to be a good idea. Anyway, using base R, it could be done along the lines of set.seed(1) nc- 92 # number of columns nr- 366 # number of rows x- matrix(rexp(nr*nc), ncol=nc) x1- scale(x) # z, standard normal (in fact, studentized) y1- apply(x, 2, plnorm) # log-normal colrs- rainbow(nc) plot(1, type=n, xlim=c(min(x1), max(x1)), ylim=c(min(y1), max(y1)), xlab=, ylab=) # if you want lines sapply(seq_len(nc), function(j){ i- order(x1[, j]) lines(x1[i, j], y1[i, j], col=colrs[j])}) # if you want points sapply(seq_len(nc), function(j) points(x1[, j], y1[, j], col=colrs[j], pch=.)) Hope this helps, Rui Barradas Em 04-06-2012 07:38, eliza botto escreveu: Dear Mc kay, thankyou very much for your reply. we are extremly greatful to you. we actually wanted all on one scale. we want to compare them all on one axis. kindle see if you could help us on that. one more thing, does this practice give us normal reduced variant on x-axis because we stricktly want normal reduced variant on x-axis. i hope you will cooperate. eliza botto waters inn Date: Mon, 4 Jun 2012 11:54:11 +1000 To: r-help@r-project.org From: mac...@northnet.com.au Subject: Re: [R] Variate Hi Eliza You will not want 1 panel with 96 lines - too confusing after about 20 Instead 1 per panel or with groups using useOuterStrips and combineLimits from latticeExtra package Try this -- a minimal example with an 12 row 8 col grid done on the fly setseed(12) Sites- 1:92 dat- data.frame(y = rep(rnorm(5),92), x = rep(1:5,92), site = rep(Sites,each = 5)) xyplot(y ~ x|site,dat, as.table=T, strip = F, layout = c(8,12), scales = list(x = list(alternating = 2),y=list(alternating=1)), type = b, panel = function(x,y,...){ pnl=panel.number() panel.xyplot(x,y,...) panel.text(4,-1.5,Sites[pnl], cex = 0.6) } ) or with groupings for Site something like (untested) xyplot(y ~ x|groupings,dat, as.table=T, strip = F, strip.left = T, groups = site, scales = list(x = list(alternating = 2),y=list(alternating=1)), type = b, panel = function(x,y,...){ pnl=panel.number() panel.xyplot(x,y,...) panel.text(4,-1.5,Sites[pnl], cex = 0.6) } ) You will need an extra column for groupings This can also be done with the base plot function but lattice gives more flexibility, see ?xyplot and particularly par.settings into get things right size Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 11:01 4/06/2012, you wrote: Content-Type: text/plain Content-Disposition: inline Content-length: 2431 Dear R users, We are working on a project called,Environmental Impact Assessment. We are stationed at alpine regions of Ireland to see the impact of rainfall on localities. We have
Re: [R] R and igraph problems
On Sun, Jun 3, 2012 at 3:43 AM, peter dalgaard pda...@gmail.com wrote: On Jun 2, 2012, at 15:43 , jalantho...@verizon.net wrote: Why is igraph 0.5.5 not on the igraph sourceforgwe home page? You'll have to ask the igraph developers... Possibly, they just ran out of round tuits. Yes, kind of. :) Also, there is no real difference between 0.5.4 and 0.5.5, only some R-specific changes, to make the package on different platforms, to make 'R CMD check' clean, etc. G. -- Peter Dalgaard, Professor, 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. -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] X11 font error on headless server running Xvfb
You could try the Cairo() device from the Cairo package. It's my understanding (from a time when I was using Xvgb for the same reason) that Cairo does not depend on X Windows. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 6/4/12 9:31 AM, Jonathan Levine js...@erols.com wrote: I am trying to run an R script to create a .png file containing a tree map on a headless Linux server using Xvfb. When I try to run tmPlot, I get the following errors and warnings: Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : X11 font -adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*, face 1 at size 9 could not be loaded Calls: tmPlot ... Anonymous - widthDetails - widthDetails.text - grid.Call In addition: Warning messages: 1: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : X11 protocol error: BadMatch (invalid parameter attributes) ... etc. (complete error message below) The .png file does contain a partially constructed graph. When I try something simple like plot(x,y) I get a plot with warnings. The results from capabilities() and X11Fonts() (see end of message) suggest to me that it should work. Any idea what is happening and how to fix the problem (or work around it)? Thanks, Jay -- sessionInfo() R version 2.15.0 (2012-03-30) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] grid stats graphics grDevices utils datasets methods [8] base other attached packages: [1] treemap_1.0-4 data.table_1.8.0 RColorBrewer_1.0-5 capabilities() jpeg png tifftcltk X11 aqua http/ftp sockets TRUE TRUE TRUE TRUE TRUEFALSE TRUE TRUE libxml fifo clediticonv NLS profmemcairo TRUE TRUEFALSE TRUE TRUEFALSEFALSE X11Fonts() $serif [1] -*-times-%s-%s-*-*-%d-*-*-*-*-*-*-* $sans [1] -*-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-* $mono [1] -*-courier-%s-%s-*-*-%d-*-*-*-*-*-*-* $Times [1] -adobe-times-%s-%s-*-*-%d-*-*-*-*-*-*-* $Helvetica [1] -adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-* $CyrTimes [1] -cronyx-times-%s-%s-*-*-%d-*-*-*-*-*-*-* $CyrHelvetica [1] -cronyx-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-* $Arial [1] -monotype-arial-%s-%s-*-*-%d-*-*-*-*-*-*-* $Mincho [1] -*-mincho-%s-%s-*-*-%d-*-*-*-*-*-*-* png(file=/tmp/tmpzT4H0e.png,width = 800, height = 800) tmPlot(myDF,index=c(vars[1],vars[2]), + vSize=vars[4], + vColor=vars[3], + type=value) Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : X11 font -adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*, face 1 at size 9 could not be loaded Calls: tmPlot ... Anonymous - widthDetails - widthDetails.text - grid.Call In addition: Warning messages: 1: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : X11 protocol error: BadMatch (invalid parameter attributes) 2: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : X11 protocol error: BadMatch (invalid parameter attributes) 3: In grid.Call.graphics(L_rect, x$x, x$y, x$width, x$height, resolveHJust(x$just, : X11 protocol error: BadMatch (invalid parameter attributes) 4: In grid.Call.graphics(L_rect, x$x, x$y, x$width, x$height, resolveHJust(x$just, : X11 protocol error: BadMatch (invalid parameter attributes) 5: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : X11 protocol error: BadMatch (invalid parameter attributes) 6: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : X11 protocol error: BadMatch (invalid parameter attributes) 7: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : X11 protocol error: BadMatch (invalid parameter attributes) 8: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : X11 protocol error: BadMatch (invalid parameter attributes) 9: In grid.Call.graphics(L_rect, x$x, x$y, x$width, x$height, resolveHJust(x$just, : X11 protocol error: BadMatch (invalid parameter attributes) 10: In grid.Call.graphics(L_rect, x$x, x$y, x$width, x$height, resolveHJust(x$just, : X11 protocol error: BadMatch (invalid parameter attributes) Execution halted __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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
Re: [R] igraph and igraph0
On Sat, Jun 2, 2012 at 9:58 AM, jalantho...@verizon.net jalantho...@verizon.net wrote: Could someone tell me the difference between igraph and igraph0? I searched the CRAN web site, but cannot find an explantion of the differences. You are right that this should be in the package description. There is no difference currently. igraph will have an update soon that will make it incompatible with current packages and code, igraph0 will serve as a backward compatible snapshot. All future development will go to 'igraph'. Gabor Thanks, Alan [[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. -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] get index of current element in vector
On Jun 4, 2012, at 4:25 PM, Erdal Karaca wrote: (Just learning R) I have this vector: v - c(1:10) Now, I want to multiply each element of that vector with a scalar value multiplied with its index: vm - v * scalar * indexOfCurrentElementOf_v Almost: vm - v * scalar * seq(v) Is that possible without using a loop? -- 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] regular expression and R
On Mon, Jun 4, 2012 at 4:48 PM, Erin Hodgess erinm.hodg...@gmail.com wrote: Dear R People: Are there any courses which describe how to use regular expressions in R, please? Or any books, please? I know a little bit (very little) but would like to know more. You might want to go through the regular expression links on the gsubfn home page: http://code.google.com/p/gsubfn/#REGULAR_EXPRESSION_LINKS The last link is a list of books but some of the other links might be useful too. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at 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] Spliting Lists into matrices
i realy appreciate your concern.. here is a small piece of my data. if you see the first and last part data, they contain 366 entries but the middle one has 365 entries. i want to put first and last entries is one matrix. list(c(0.86, 0.86, 0.86, 0.86, 0.86, 1.08, 1.08, 1.08, 1.08, 1.08, 1.08, 1.4, 1.4, 23, 11.18, 38.83, 23, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.02, 2.58, 2.58, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 3.02, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.8, 2.8, 2.8, 4.1, 4.1, 13.55, 9.34, 8.32, 7.31, 4.5, 4.1, 14.63, 24.88, 39.99, 23.69, 14.63, 7.31, 4.5, 7.31, 16.82, 21.35, 24.88, 20.2, 24.88, 26.07, 30.98, 49.58, 51.01, 26.07, 24.88, 30.98, 34.77, 58.26, 30.98, 23.69, 26.07, 19.06, 16.82, 20.2, 16.82, 23.69, 14.63, 16.82, 11.42, 11.42, 11.42, 11.42, 10.38, 10.38, 8.32, 7.31, 6.31, 16.82, 6.31, 6.31, 6.31, 4.9, 4.9, 4.5, 4.5, 4.5, 4.5, 4.5, 4.1, 4.1, 2.8, 2.4, 2.4, 26.07, 45.4, 16.82, 7.31, 4.5, 3.2, 3.2, 2.8, 2.8, 2.4, 2.4, 2.8, 3.2, 3.2, 4.9, 4.9, 36.05, 65.8, 76.86, 53.87, 26.07, 20.2, 21.36, 14.63, 10.38, 10.38, 7.31, 7.31, 51.01, 16.82, 14.63, 12.48, 14.63, 10.38, 11.42, 52.44, 64.27, 36.05, 26.07, 21.36, 21.36, 23.69, 47.79, 52.44, 167.9, 97.12, 76.86, 144.71, 90.18, 34.77, 30.98, 28.5, 26.07, 26.07, 14.63, 14.63, 6.31, 6.31, 6.31, 4.5, 4.1, 3.2, 6.31, 6.31, 16.82, 4.5, 3.2, 3.2, 3.2, 3.2, 4.5, 8.32, 10.38, 10.38, 8.32, 11.42, 10.38, 7.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 8.32, 6.31, 6.31, 20.2, 14.63, 7.31, 4.9, 34.77, 26.07, 14.63, 10.38, 6.31, 4.9, 7.31, 4.9, 4.5, 4.5, 4.5, 21.36, 12.48, 7.31, 4.5, 4.5, 6.31, 4.9, 4.9, 6.31, 8.32, 7.31, 6.31, 6.31, 14.63, 11.42, 6.31, 6.31, 4.9, 6.31, 14.63, 7.31, 12.48, 6.31, 6.31, 24.88, 15.72, 33.49, 111.57, 44.03, 39.99, 44.03, 24.88, 12.48, 39.99, 11.42, 7.31, 4.9, 4.5, 4.1, 4.5, 4.1, 4.1, 3.2, 3.2, 3.2, 3.2, 3.2, 2.8, 2.8, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 2.8, 2.8, 3.2, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 4.1, 4.1, 2.4, 3.2, 10.38, 8.32, 4.5, 3.2, 3.2, 2.8, 3.2, 3.2, 3.2, 2.4, 2.4, 2.4, 15.72, 23.69, 12.48, 14.63, 4.5, 4.1, 4.5, 4.1, 4.1, 4.1, 3.2, 2.8, 2.8, 3.2, 2.8, 2.4, 4.5, 4.5, 12.48, 68.9, 30.98, 39.99, 29.73, 95.37, 44.03, 26.07, 41.33, 49.58, 23.69, 28.5), c(16.82, 14.63, 6.31, 6.31, 4.5, 4.5, 4.1, 4.1, 4.1, 3.2, 3.2, 4.1, 3.2, 3.2, 4.1, 4.5, 4.1, 4.1, 167.9, 75.24, 44.03, 23.69, 19.06, 15.72, 11.42, 8.32, 6.31, 4.9, 6.31, 4.9, 4.9, 4.1, 4.1, 3.2, 4.1, 4.1, 4.1, 90.18, 102.45, 39.99, 29.73, 8.32, 21.36, 21.36, 21.36, 12.48, 11.42, 12.48, 11.42, 12.48, 14.63, 14.63, 15.72, 23.69, 28.5, 29.73, 33.49, 29.73, 23.69, 21.36, 6.31, 16.82, 15.72, 15.72, 15.72, 15.72, 16.82, 20.2, 20.2, 21.36, 21.36, 26.07, 28.5, 29.73, 33.49, 29.73, 33.49, 34.77, 26.07, 26.07, 23.69, 23.69, 26.07, 21.36, 23.69, 23.69, 23.69, 24.88, 21.36, 20.2, 16.82, 19.06, 20.2, 21.36, 20.2, 20.2, 24.88, 23.69, 26.07, 29.73, 23.69, 24.88, 29.73, 36.05, 33.49, 34.77, 28.5, 28.5, 26.07, 153, 70.47, 58.26, 81.77, 36.05, 39.99, 30.98, 33.49, 28.5, 28.5, 33.49, 29.73, 28.5, 24.88, 30.98, 38.67, 30.98, 50.01, 65.8, 51.01, 38.67, 34.77, 29.73, 29.73, 33.49, 30.98, 30.98, 30.98, 33.49, 34.77, 33.49, 30.98, 88.48, 14.63, 8.32, 19.06, 14.63, 104.25, 44.03, 33.49, 21.36, 20.2, 15.72, 15.72, 11.42, 7.31, 6.31, 4.9, 4.5, 4.5, 4.5, 3.2, 8.32, 8.32, 14.63, 97.12, 310.8, 88.48, 36.05, 24.88, 19.06, 14.63, 12.48, 8.32, 23.69, 11.42, 19.06, 90.18, 90.18, 33.49, 16.82, 70.47, 38.67, 29.73, 34.77, 33.49, 68.9, 102.45, 176.7, 78.48, 45.4, 106.06, 83.43, 45.4, 68.9, 39.99, 28.5, 23.69, 20.2, 36.05, 38.67, 30.98, 26.07, 20.2, 47.79, 52.44, 28.5, 23.69, 20.2, 14.63, 14.63, 14.63, 12.48, 21.36, 24.88, 47.79, 38.67, 34.77, 21.36, 16.82, 8.32, 153, 47.79, 53.87, 29.73, 23.69, 15.72, 19.06, 97.12, 33.49, 15.72, 10.38, 6.31, 4.5, 11.42, 6.31, 6.31, 6.31, 4.5, 19.06, 14.63, 4.9, 4.9, 28.5, 70.47, 15.72, 4.9, 4.1, 41.33, 241, 85.1, 38.67, 28.5, 20.2, 15.72, 12.48, 12.48, 20.2, 14.63, 12.48, 10.38, 7.31, 7.31, 15.72, 33.49, 20.2, 15.72, 12.48, 8.32, 7.31, 6.31, 4.9, 4.5, 4.1, 4.9, 4.5, 4.9, 20.2, 11.42, 6.31, 4.9, 4.9, 4.9, 4.5, 4.5, 4.5, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 6.31, 6.31, 4.5, 4.9, 4.9, 4.5, 4.5, 4.5, 4.9, 4.5, 15.72, 24.88, 4.1, 58.26, 23.69, 26.07, 28.5, 174.5, 58.26, 49.58, 23.69, 23.69, 23.69, 28.5, 26.07, 15.72, 20.2, 26.07, 23.69, 19.06, 21.36, 15.72, 4.1, 4.1, 6.31, 15.72, 24.88, 39.99, 45.4, 23.69, 33.49, 33.49, 33.49, 23.69, 23.69, 20.2, 24.88, 19.06, 23.69, 20.2, 8.32, 6.31, 6.31, 4.1, 4.1, 14.63, 106.06, 51.01, 26.07, 23.69, 20.2, 15.72, 15.72, 12.48, 19.06, 16.82, 14.63, 12.48, 12.48, 11.42, 11.42, 12.2), c(8.32, 8.32, 8.32, 8.32, 8.32, 8.32, 8.32, 8.32, 8.32, 8.32, 8.32, 8.32, 8.32, 7.31, 8.32, 8.32, 8.32, 8.32, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31,
Re: [R] get index of current element in vector
Hello, Just learning the alphabet? If yes, there's a difference between 'v' and 'a'. Now more seriously. Your description and your loop don't do the same. Description: vm - scalar * v * seq_along(v) Loop: a - scalar * a Also, seq_along is the way to do it, it works even if length(a) == 0. Hope this helps, Rui Barradas Em 04-06-2012 21:25, Erdal Karaca escreveu: (Just learning R) I have this vector: v- c(1:10) Now, I want to multiply each element of that vector with a scalar value multiplied with its index: vm- v * scalar * indexOfCurrentElementOf_v Is that possible without using a loop? In a loop I would do this: for (i in 1:length(a)) a[i]- scalar * a[i] [[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] Spliting Lists into matrices
Hello, Try # 'x' is your list xlen - sapply(x, length) i1 - which(xlen == 365) i2 - which(xlen == 366) mat365 - matrix(unlist(x[i1]), nrow=365) mat366 - matrix(unlist(x[i2]), nrow=366) Hope this helps, Rui Barradas Em 04-06-2012 22:46, eliza botto escreveu: i realy appreciate your concern.. here is a small piece of my data. if you see the first and last part data, they contain 366 entries but the middle one has 365 entries. i want to put first and last entries is one matrix. list(c(0.86, 0.86, 0.86, 0.86, 0.86, 1.08, 1.08, 1.08, 1.08, 1.08, 1.08, 1.4, 1.4, 23, 11.18, 38.83, 23, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.02, 2.58, 2.58, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 3.02, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.8, 2.8, 2.8, 4.1, 4.1, 13.55, 9.34, 8.32, 7.31, 4.5, 4.1, 14.63, 24.88, 39.99, 23.69, 14.63, 7.31, 4.5, 7.31, 16.82, 21.35, 24.88, 20.2, 24.88, 26.07, 30.98, 49.58, 51.01, 26.07, 24.88, 30.98, 34.77, 58.26, 30.98, 23.69, 26.07, 19.06, 16.82, 20.2, 16.82, 23.69, 14.63, 16.82, 11.42, 11.42, 11.42, 11.42, 10.38, 10.38, 8.32, 7.31, 6.31, 16.82, 6.31, 6.31, 6.31, 4.9, 4.9, 4.5, 4.5, 4.5, 4.5, 4.5, 4.1, 4.1, 2.8, 2.4, 2.4, 26.07, 45.4, 16.82, 7.31, 4.5, 3.2, 3.2, 2.8, 2.8, 2.4, 2.4, 2.8, 3.2, 3.2, 4.9, 4.9, 36.05, 65.8, 76.86, 53.87, 26.07, 20.2, 21.36, 14.63, 10.38, 10.38, 7.31, 7.31, 51.01, 16.82, 14.63, 12.48, 14.63, 10.38, 11.42, 52.44, 64.27, 36.05, 26.07, 21.36, 21.36, 23.69, 47.79, 52.44, 167.9, 97.12, 76.86, 144.71, 90.18, 34.77, 30.98, 28.5, 26.07, 26.07, 14.63, 14.63, 6.31, 6.31, 6.31, 4.5, 4.1, 3.2, 6.31, 6.31, 16.82, 4.5, 3.2, 3.2, 3.2, 3.2, 4.5, 8.32, 10.38, 10.38, 8.32, 11.42, 10.38, 7.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 8.32, 6.31, 6.31, 20.2, 14.63, 7.31, 4.9, 34.77, 26.07, 14.63, 10.38, 6.31, 4.9, 7.31, 4.9, 4.5, 4.5, 4.5, 21.36, 12.48, 7.31, 4.5, 4.5, 6.31, 4.9, 4.9, 6.31, 8.32, 7.31, 6.31, 6.31, 14.63, 11.42, 6.31, 6.31, 4.9, 6.31, 14.63, 7.31, 12.48, 6.31, 6.31, 24.88, 15.72, 33.49, 111.57, 44.03, 39.99, 44.03, 24.88, 12.48, 39.99, 11.42, 7.31, 4.9, 4.5, 4.1, 4.5, 4.1, 4.1, 3.2, 3.2, 3.2, 3.2, 3.2, 2.8, 2.8, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 2.8, 2.8, 3.2, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 4.1, 4.1, 2.4, 3.2, 10.38, 8.32, 4.5, 3.2, 3.2, 2.8, 3.2, 3.2, 3.2, 2.4, 2.4, 2.4, 15.72, 23.69, 12.48, 14.63, 4.5, 4.1, 4.5, 4.1, 4.1, 4.1, 3.2, 2.8, 2.8, 3.2, 2.8, 2.4, 4.5, 4.5, 12.48, 68.9, 30.98, 39.99, 29.73, 95.37, 44.03, 26.07, 41.33, 49.58, 23.69, 28.5), c(16.82, 14.63, 6.31, 6.31, 4.5, 4.5, 4.1, 4.1, 4.1, 3.2, 3.2, 4.1, 3.2, 3.2, 4.1, 4.5, 4.1, 4.1, 167.9, 75.24, 44.03, 23.69, 19.06, 15.72, 11.42, 8.32, 6.31, 4.9, 6.31, 4.9, 4.9, 4.1, 4.1, 3.2, 4.1, 4.1, 4.1, 90.18, 102.45, 39.99, 29.73, 8.32, 21.36, 21.36, 21.36, 12.48, 11.42, 12.48, 11.42, 12.48, 14.63, 14.63, 15.72, 23.69, 28.5, 29.73, 33.49, 29.73, 23.69, 21.36, 6.31, 16.82, 15.72, 15.72, 15.72, 15.72, 16.82, 20.2, 20.2, 21.36, 21.36, 26.07, 28.5, 29.73, 33.49, 29.73, 33.49, 34.77, 26.07, 26.07, 23.69, 23.69, 26.07, 21.36, 23.69, 23.69, 23.69, 24.88, 21.36, 20.2, 16.82, 19.06, 20.2, 21.36, 20.2, 20.2, 24.88, 23.69, 26.07, 29.73, 23.69, 24.88, 29.73, 36.05, 33.49, 34.77, 28.5, 28.5, 26.07, 153, 70.47, 58.26, 81.77, 36.05, 39.99, 30.98, 33.49, 28.5, 28.5, 33.49, 29.73, 28.5, 24.88, 30.98, 38.67, 30.98, 50.01, 65.8, 51.01, 38.67, 34.77, 29.73, 29.73, 33.49, 30.98, 30.98, 30.98, 33.49, 34.77, 33.49, 30.98, 88.48, 14.63, 8.32, 19.06, 14.63, 104.25, 44.03, 33.49, 21.36, 20.2, 15.72, 15.72, 11.42, 7.31, 6.31, 4.9, 4.5, 4.5, 4.5, 3.2, 8.32, 8.32, 14.63, 97.12, 310.8, 88.48, 36.05, 24.88, 19.06, 14.63, 12.48, 8.32, 23.69, 11.42, 19.06, 90.18, 90.18, 33.49, 16.82, 70.47, 38.67, 29.73, 34.77, 33.49, 68.9, 102.45, 176.7, 78.48, 45.4, 106.06, 83.43, 45.4, 68.9, 39.99, 28.5, 23.69, 20.2, 36.05, 38.67, 30.98, 26.07, 20.2, 47.79, 52.44, 28.5, 23.69, 20.2, 14.63, 14.63, 14.63, 12.48, 21.36, 24.88, 47.79, 38.67, 34.77, 21.36, 16.82, 8.32, 153, 47.79, 53.87, 29.73, 23.69, 15.72, 19.06, 97.12, 33.49, 15.72, 10.38, 6.31, 4.5, 11.42, 6.31, 6.31, 6.31, 4.5, 19.06, 14.63, 4.9, 4.9, 28.5, 70.47, 15.72, 4.9, 4.1, 41.33, 241, 85.1, 38.67, 28.5, 20.2, 15.72, 12.48, 12.48, 20.2, 14.63, 12.48, 10.38, 7.31, 7.31, 15.72, 33.49, 20.2, 15.72, 12.48, 8.32, 7.31, 6.31, 4.9, 4.5, 4.1, 4.9, 4.5, 4.9, 20.2, 11.42, 6.31, 4.9, 4.9, 4.9, 4.5, 4.5, 4.5, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 6.31, 6.31, 4.5, 4.9, 4.9, 4.5, 4.5, 4.5, 4.9, 4.5, 15.72, 24.88, 4.1, 58.26, 23.69, 26.07, 28.5, 174.5, 58.26, 49.58, 23.69, 23.69, 23.69, 28.5, 26.07, 15.72, 20.2, 26.07, 23.69, 19.06, 21.36, 15.72, 4.1, 4.1, 6.31, 15.72, 24.88, 39.99, 45.4, 23.69, 33.49, 33.49, 33.49, 23.69, 23.69, 20.2, 24.88, 19.06, 23.69, 20.2, 8.32, 6.31, 6.31, 4.1, 4.1, 14.63, 106.06, 51.01, 26.07, 23.69, 20.2, 15.72, 15.72, 12.48, 19.06, 16.82, 14.63, 12.48, 12.48,
Re: [R] Chi square value of anova(binomialglmnull, binomglmmod, test=Chisq)
On Jun 4, 2012, at 11:31 AM, lincoln wrote: So sorry, My response variable is site (not gender!). The selection process was: If there is a natural probability interpretation to site==1 being a sort of event, (say perhaps a non-lymphatic site for the primary site of a lymphoma) then you can say that the log-odds for 'site' being 1 compared to the log-odds for being 0 are different among the cohorts. (Or equivalently that the odds ratios are significantly different.) Worries: The fact that 'age' codes are 1/0 and' birth' is 5,6,or 7 makes me wonder what sort of measurements these are. I worry when variables usually considered as continuous get so severely discretized. The fact that this is data measured over time also raised further concerns about independence. Were controls observed in 1999 still subject to risk in 2000 and subsequent years? Were there substantial differences in the time to events? I also worry when words normally used as a location are interpreted as events and there is no context offered. -- David. str(data) 'data.frame': 1003 obs. of 5 variables: $ site : Factor w/ 2 levels 0,1: 1 1 1 1 1 1 1 1 1 1 ... $ sex : Factor w/ 2 levels 0,1: NA NA NA NA 1 NA NA NA NA NA ... $ age : Factor w/ 2 levels 0,1: 1 1 1 1 1 1 1 1 1 1 ... $ cohort: Factor w/ 10 levels 1999,2000,..: 10 10 10 10 10 10 10 10 10 10 ... $ birth : Factor w/ 3 levels 5,6,7: 3 3 2 2 2 2 2 2 2 2 ... datasex-subset(data, sex !=NA) *Here below the structure of the analysis and only the anova.glm of the last, selected model, mod4: * mod1 - glm(site ~ sex + birth + cohort + sex:birth, data=datasex, family = binomial) summary(mod1) anova(mod1,update(mod1,~.-sex:birth),test=Chisq) mod2 - glm(site ~ sex + birth + cohort, data=datasex, family = binomial) summary(mod2) anova(mod2,update(mod2,~.-sex),test=Chisq) mod3 - glm(site ~ birth + cohort, data=data, family = binomial) summary(mod3) anova(mod3,update(mod3,~.-birth),test=Chisq) mod4 - glm(site ~ cohort, data=data, family = binomial) summary(mod4) anova(mod4,update(mod4,~.-cohort),test=Chisq) Analysis of Deviance Table Model 1: site ~ cohort Model 2: site ~ 1 Resid. Df Resid. Dev Df Deviance P(|Chi|) 1 993 1283.7 2 1002 1368.2 -9 -84.554 2.002e-14 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 *My question:* In this case, the Chi2 value would be the difference in deviance between models and d.f. the difference in d.f. (84.554 and 9)? In other words may I correctly assess: /cohorts were unevenly distributed between sites ( Chi2=84.5, df=9, p 0.001)/? -- View this message in context: http://r.789695.n4.nabble.com/Chi-square-value-of-anova-binomialglmnull-binomglmmod-test-Chisq-tp4632293p4632312.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. 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] Double-buffering problem, this time with an example.
FOR what it's worth this dev.hold/dev/flush combination does not seem to prevent flickering on the quartz device on Macs. Best, luke On Sat, 2 Jun 2012, Duncan Murdoch wrote: On 12-06-02 4:02 PM, Daniel Carr wrote: Most of my animations that used to work on windows() version 2.11.1 and earlier now flash as if the double buffering is turned off or buffer swapping is triggered by other events than in the past. The simplified example below using symbols should illustrate the problem in a windows environment. windows() radius- 8 n- 6 ang- seq(0,2*pi,length=n+1)[-(n+1)] ca- cos(ang) sa- sin(ang) size- c(.1, .3, .5, .7, .9, 1) colors- rainbow(length(size)) for (i in 1:1000){ radius- radius*.998 bnd- (radius+1)* c(-1, 1) cenX- radius*ca cenY- radius*sa symbols(cenX, cenY, circles = size, xlim=bnd, ylim=bnd, bg=colors) } I have not isolated the version when the flashing started but it somewhere between 2.11.1 and 2.14.1. I did some searching on double-buffering problems in R but didn't find indications of this particular problem. Slowing the animation down did not help. I don't think there was ever a guarantee that double buffering would be sufficient for what you were doing: you just got lucky. What you need to do (and this should work, at least on the windows() device and some others), is use dev.hold() to stop redrawing, and dev.flush() when you are ready to display the new stuff. Your loop becomes something like this: for (i in 1:1000){ dev.hold() radius - radius*.998 bnd - (radius+1)* c(-1, 1) cenX - radius*ca cenY - radius*sa symbols(cenX, cenY, circles = size, xlim=bnd, ylim=bnd, bg=colors) dev.flush() } The dev.hold() function was introduced in 2.14.0. I think dev.flush() existed earlier, but not for all systems. 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. -- Luke Tierney Chair, Statistics and Actuarial Science Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics andFax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: luke-tier...@uiowa.edu Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Spliting Lists into matrices
dear rui, lots of hugs for you. thnkyou very much 4 your support. eliza Date: Mon, 4 Jun 2012 22:58:12 +0100 From: ruipbarra...@sapo.pt To: eliza_bo...@hotmail.com CC: r-help@r-project.org Subject: Re: Spliting Lists into matrices Hello, Try # 'x' is your list xlen - sapply(x, length) i1 - which(xlen == 365) i2 - which(xlen == 366) mat365 - matrix(unlist(x[i1]), nrow=365) mat366 - matrix(unlist(x[i2]), nrow=366) Hope this helps, Rui Barradas Em 04-06-2012 22:46, eliza botto escreveu: i realy appreciate your concern.. here is a small piece of my data. if you see the first and last part data, they contain 366 entries but the middle one has 365 entries. i want to put first and last entries is one matrix. list(c(0.86, 0.86, 0.86, 0.86, 0.86, 1.08, 1.08, 1.08, 1.08, 1.08, 1.08, 1.4, 1.4, 23, 11.18, 38.83, 23, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.02, 2.58, 2.58, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 3.02, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.8, 2.8, 2.8, 4.1, 4.1, 13.55, 9.34, 8.32, 7.31, 4.5, 4.1, 14.63, 24.88, 39.99, 23.69, 14.63, 7.31, 4.5, 7.31, 16.82, 21.35, 24.88, 20.2, 24.88, 26.07, 30.98, 49.58, 51.01, 26.07, 24.88, 30.98, 34.77, 58.26, 30.98, 23.69, 26.07, 19.06, 16.82, 20.2, 16.82, 23.69, 14.63, 16.82, 11.42, 11.42, 11.42, 11.42, 10.38, 10.38, 8.32, 7.31, 6.31, 16.82, 6.31, 6.31, 6.31, 4.9, 4.9, 4.5, 4.5, 4.5, 4.5, 4.5, 4.1, 4.1, 2.8, 2.4, 2.4, 26.07, 45.4, 16.82, 7.31, 4.5, 3.2, 3.2, 2.8, 2.8, 2.4, 2.4, 2.8, 3.2, 3.2, 4.9, 4.9, 36.05, 65.8, 76.86, 53.87, 26.07, 20.2, 21.36, 14.63, 10.38, 10.38, 7.31, 7.31, 51.01, 16.82, 14.63, 12.48, 14.63, 10.38, 11.42, 52.44, 64.27, 36.05, 26.07, 21.36, 21.36, 23.69, 47.79, 52.44, 167.9, 97.12, 76.86, 144.71, 90.18, 34.77, 30.98, 28.5, 26.07, 26.07, 14.63, 14.63, 6.31, 6.31, 6.31, 4.5, 4.1, 3.2, 6.31, 6.31, 16.82, 4.5, 3.2, 3.2, 3.2, 3.2, 4.5, 8.32, 10.38, 10.38, 8.32, 11.42, 10.38, 7.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 8.32, 6.31, 6.31, 20.2, 14.63, 7.31, 4.9, 34.77, 26.07, 14.63, 10.38, 6.31, 4.9, 7.31, 4.9, 4.5, 4.5, 4.5, 21.36, 12.48, 7.31, 4.5, 4.5, 6.31, 4.9, 4.9, 6.31, 8.32, 7.31, 6.31, 6.31, 14.63, 11.42, 6.31, 6.31, 4.9, 6.31, 14.63, 7.31, 12.48, 6.31, 6.31, 24.88, 15.72, 33.49, 111.57, 44.03, 39.99, 44.03, 24.88, 12.48, 39.99, 11.42, 7.31, 4.9, 4.5, 4.1, 4.5, 4.1, 4.1, 3.2, 3.2, 3.2, 3.2, 3.2, 2.8, 2.8, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 2.8, 2.8, 3.2, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 4.1, 4.1, 2.4, 3.2, 10.38, 8.32, 4.5, 3.2, 3.2, 2.8, 3.2, 3.2, 3.2, 2.4, 2.4, 2.4, 15.72, 23.69, 12.48, 14.63, 4.5, 4.1, 4.5, 4.1, 4.1, 4.1, 3.2, 2.8, 2.8, 3.2, 2.8, 2.4, 4.5, 4.5, 12.48, 68.9, 30.98, 39.99, 29.73, 95.37, 44.03, 26.07, 41.33, 49.58, 23.69, 28.5), c(16.82, 14.63, 6.31, 6.31, 4.5, 4.5, 4.1, 4.1, 4.1, 3.2, 3.2, 4.1, 3.2, 3.2, 4.1, 4.5, 4.1, 4.1, 167.9, 75.24, 44.03, 23.69, 19.06, 15.72, 11.42, 8.32, 6.31, 4.9, 6.31, 4.9, 4.9, 4.1, 4.1, 3.2, 4.1, 4.1, 4.1, 90.18, 102.45, 39.99, 29.73, 8.32, 21.36, 21.36, 21.36, 12.48, 11.42, 12.48, 11.42, 12.48, 14.63, 14.63, 15.72, 23.69, 28.5, 29.73, 33.49, 29.73, 23.69, 21.36, 6.31, 16.82, 15.72, 15.72, 15.72, 15.72, 16.82, 20.2, 20.2, 21.36, 21.36, 26.07, 28.5, 29.73, 33.49, 29.73, 33.49, 34.77, 26.07, 26.07, 23.69, 23.69, 26.07, 21.36, 23.69, 23.69, 23.69, 24.88, 21.36, 20.2, 16.82, 19.06, 20.2, 21.36, 20.2, 20.2, 24.88, 23.69, 26.07, 29.73, 23.69, 24.88, 29.73, 36.05, 33.49, 34.77, 28.5, 28.5, 26.07, 153, 70.47, 58.26, 81.77, 36.05, 39.99, 30.98, 33.49, 28.5, 28.5, 33.49, 29.73, 28.5, 24.88, 30.98, 38.67, 30.98, 50.01, 65.8, 51.01, 38.67, 34.77, 29.73, 29.73, 33.49, 30.98, 30.98, 30.98, 33.49, 34.77, 33.49, 30.98, 88.48, 14.63, 8.32, 19.06, 14.63, 104.25, 44.03, 33.49, 21.36, 20.2, 15.72, 15.72, 11.42, 7.31, 6.31, 4.9, 4.5, 4.5, 4.5, 3.2, 8.32, 8.32, 14.63, 97.12, 310.8, 88.48, 36.05, 24.88, 19.06, 14.63, 12.48, 8.32, 23.69, 11.42, 19.06, 90.18, 90.18, 33.49, 16.82, 70.47, 38.67, 29.73, 34.77, 33.49, 68.9, 102.45, 176.7, 78.48, 45.4, 106.06, 83.43, 45.4, 68.9, 39.99, 28.5, 23.69, 20.2, 36.05, 38.67, 30.98, 26.07, 20.2, 47.79, 52.44, 28.5, 23.69, 20.2, 14.63, 14.63, 14.63, 12.48, 21.36, 24.88, 47.79, 38.67, 34.77, 21.36, 16.82, 8.32, 153, 47.79, 53.87, 29.73, 23.69, 15.72, 19.06, 97.12, 33.49, 15.72, 10.38, 6.31, 4.5, 11.42, 6.31, 6.31, 6.31, 4.5, 19.06, 14.63, 4.9, 4.9, 28.5, 70.47, 15.72, 4.9, 4.1, 41.33, 241, 85.1, 38.67, 28.5, 20.2, 15.72, 12.48, 12.48, 20.2, 14.63, 12.48, 10.38, 7.31, 7.31, 15.72, 33.49, 20.2, 15.72, 12.48, 8.32, 7.31, 6.31, 4.9, 4.5, 4.1, 4.9, 4.5, 4.9, 20.2, 11.42, 6.31, 4.9, 4.9, 4.9, 4.5, 4.5, 4.5, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 6.31, 6.31, 4.5, 4.9, 4.9, 4.5, 4.5, 4.5, 4.9, 4.5,
Re: [R] Spliting Lists into matrices
Dear R users, we generally apply approx() command to a list data. how can we apply this command to a matrix, so that we can approximate 366 readings from certain number of each column over 365 intervals?? hope i am clear in my statement. eliza botto From: eliza_bo...@hotmail.com To: ruipbarra...@sapo.pt Date: Mon, 4 Jun 2012 22:13:10 + CC: r-help@r-project.org Subject: Re: [R] Spliting Lists into matrices dear rui, lots of hugs for you. thnkyou very much 4 your support. eliza Date: Mon, 4 Jun 2012 22:58:12 +0100 From: ruipbarra...@sapo.pt To: eliza_bo...@hotmail.com CC: r-help@r-project.org Subject: Re: Spliting Lists into matrices Hello, Try # 'x' is your list xlen - sapply(x, length) i1 - which(xlen == 365) i2 - which(xlen == 366) mat365 - matrix(unlist(x[i1]), nrow=365) mat366 - matrix(unlist(x[i2]), nrow=366) Hope this helps, Rui Barradas Em 04-06-2012 22:46, eliza botto escreveu: i realy appreciate your concern.. here is a small piece of my data. if you see the first and last part data, they contain 366 entries but the middle one has 365 entries. i want to put first and last entries is one matrix. list(c(0.86, 0.86, 0.86, 0.86, 0.86, 1.08, 1.08, 1.08, 1.08, 1.08, 1.08, 1.4, 1.4, 23, 11.18, 38.83, 23, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.02, 2.58, 2.58, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 3.02, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.8, 2.8, 2.8, 4.1, 4.1, 13.55, 9.34, 8.32, 7.31, 4.5, 4.1, 14.63, 24.88, 39.99, 23.69, 14.63, 7.31, 4.5, 7.31, 16.82, 21.35, 24.88, 20.2, 24.88, 26.07, 30.98, 49.58, 51.01, 26.07, 24.88, 30.98, 34.77, 58.26, 30.98, 23.69, 26.07, 19.06, 16.82, 20.2, 16.82, 23.69, 14.63, 16.82, 11.42, 11.42, 11.42, 11.42, 10.38, 10.38, 8.32, 7.31, 6.31, 16.82, 6.31, 6.31, 6.31, 4.9, 4.9, 4.5, 4.5, 4.5, 4.5, 4.5, 4.1, 4.1, 2.8, 2.4, 2.4, 26.07, 45.4, 16.82, 7.31, 4.5, 3.2, 3.2, 2.8, 2.8, 2.4, 2.4, 2.8, 3.2, 3.2, 4.9, 4.9, 36.05, 65.8, 76.86, 53.87, 26.07, 20.2, 21.36, 14.63, 10.38, 10.38, 7.31, 7.31, 51.01, 16.82, 14.63, 12.48, 14.63, 10.38, 11.42, 52.44, 64.27, 36.05, 26.07, 21.36, 21.36, 23.69, 47.79, 52.44, 167.9, 97.12, 76.86, 144.71, 90.18, 34.77, 30.98, 28.5, 26.07, 26.07, 14.63, 14.63, 6.31, 6.31, 6.31, 4.5, 4.1, 3.2, 6.31, 6.31, 16.82, 4.5, 3.2, 3.2, 3.2, 3.2, 4.5, 8.32, 10.38, 10.38, 8.32, 11.42, 10.38, 7.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 8.32, 6.31, 6.31, 20.2, 14.63, 7.31, 4.9, 34.77, 26.07, 14.63, 10.38, 6.31, 4.9, 7.31, 4.9, 4.5, 4.5, 4.5, 21.36, 12.48, 7.31, 4.5, 4.5, 6.31, 4.9, 4.9, 6.31, 8.32, 7.31, 6.31, 6.31, 14.63, 11.42, 6.31, 6.31, 4.9, 6.31, 14.63, 7.31, 12.48, 6.31, 6.31, 24.88, 15.72, 33.49, 111.57, 44.03, 39.99, 44.03, 24.88, 12.48, 39.99, 11.42, 7.31, 4.9, 4.5, 4.1, 4.5, 4.1, 4.1, 3.2, 3.2, 3.2, 3.2, 3.2, 2.8, 2.8, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 2.8, 2.8, 3.2, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 4.1, 4.1, 2.4, 3.2, 10.38, 8.32, 4.5, 3.2, 3.2, 2.8, 3.2, 3.2, 3.2, 2.4, 2.4, 2.4, 15.72, 23.69, 12.48, 14.63, 4.5, 4.1, 4.5, 4.1, 4.1, 4.1, 3.2, 2.8, 2.8, 3.2, 2.8, 2.4, 4.5, 4.5, 12.48, 68.9, 30.98, 39.99, 29.73, 95.37, 44.03, 26.07, 41.33, 49.58, 23.69, 28.5), c(16.82, 14.63, 6.31, 6.31, 4.5, 4.5, 4.1, 4.1, 4.1, 3.2, 3.2, 4.1, 3.2, 3.2, 4.1, 4.5, 4.1, 4.1, 167.9, 75.24, 44.03, 23.69, 19.06, 15.72, 11.42, 8.32, 6.31, 4.9, 6.31, 4.9, 4.9, 4.1, 4.1, 3.2, 4.1, 4.1, 4.1, 90.18, 102.45, 39.99, 29.73, 8.32, 21.36, 21.36, 21.36, 12.48, 11.42, 12.48, 11.42, 12.48, 14.63, 14.63, 15.72, 23.69, 28.5, 29.73, 33.49, 29.73, 23.69, 21.36, 6.31, 16.82, 15.72, 15.72, 15.72, 15.72, 16.82, 20.2, 20.2, 21.36, 21.36, 26.07, 28.5, 29.73, 33.49, 29.73, 33.49, 34.77, 26.07, 26.07, 23.69, 23.69, 26.07, 21.36, 23.69, 23.69, 23.69, 24.88, 21.36, 20.2, 16.82, 19.06, 20.2, 21.36, 20.2, 20.2, 24.88, 23.69, 26.07, 29.73, 23.69, 24.88, 29.73, 36.05, 33.49, 34.77, 28.5, 28.5, 26.07, 153, 70.47, 58.26, 81.77, 36.05, 39.99, 30.98, 33.49, 28.5, 28.5, 33.49, 29.73, 28.5, 24.88, 30.98, 38.67, 30.98, 50.01, 65.8, 51.01, 38.67, 34.77, 29.73, 29.73, 33.49, 30.98, 30.98, 30.98, 33.49, 34.77, 33.49, 30.98, 88.48, 14.63, 8.32, 19.06, 14.63, 104.25, 44.03, 33.49, 21.36, 20.2, 15.72, 15.72, 11.42, 7.31, 6.31, 4.9, 4.5, 4.5, 4.5, 3.2, 8.32, 8.32, 14.63, 97.12, 310.8, 88.48, 36.05, 24.88, 19.06, 14.63, 12.48, 8.32, 23.69, 11.42, 19.06, 90.18, 90.18, 33.49, 16.82, 70.47, 38.67, 29.73, 34.77, 33.49, 68.9, 102.45, 176.7, 78.48, 45.4, 106.06, 83.43, 45.4, 68.9, 39.99, 28.5, 23.69, 20.2, 36.05, 38.67, 30.98, 26.07, 20.2, 47.79, 52.44, 28.5, 23.69, 20.2, 14.63, 14.63, 14.63, 12.48, 21.36, 24.88, 47.79, 38.67, 34.77, 21.36,
Re: [R] community finding in a graph and heatplot
On Sun, Jun 3, 2012 at 4:11 PM, Aziz, Muhammad Fayez az...@illinois.edu wrote: Hmm interesting. To come to think of it there could be many disconnected components in the graph and thus there should be a generic way to either mitigate the disconnectedness in the dendrogram or in the original graph. I had no luck in finding such a trick though google search. I then ran the script on minute-scale graphs and have following results: 1) disconnected graph with three modules: *Vertices 9 *Edges 1 2 1 2 3 1 3 1 1 4 5 1 5 6 1 6 4 1 7 8 1 8 9 1 9 7 1 corresponding fgc$merges matrix: [,1] [,2] [1,] 1 0 [2,] 2 9 [3,] 7 6 [4,] 8 11 [5,] 4 3 [6,] 5 13 2) connected graph by adding links 1-2 and 4-7 in graph 1): *Vertices 9 *Edges 1 2 1 2 3 1 3 1 1 4 5 1 5 6 1 6 4 1 7 8 1 8 9 1 9 7 1 1 4 1 4 7 1 corresponding fgc$merges matrix: [,1] [,2] [1,] 2 1 [2,] 0 9 [3,] 8 7 [4,] 6 11 [5,] 5 4 [6,] 3 13 [7,] 14 12 [8,] 15 10 There needs to be a generic way to get fgc$merges of the form 2) from 1). Hints please. Well, how do you merge the unconnected components? I guess you could come up with an order based on modularity, or just merge them in arbitrary order. The following is from igraph 0.6, and I haven't tried it on your data, but it might just work. It merges the individual subtrees in arbitrary order. complete.dend - function(comm) { merges - comm$merges if (nrow(merges) comm$vcount-1) { miss - seq_len(comm$vcount + nrow(merges))[-as.vector(merges)] miss - c(miss, seq_len(length(miss)-2) + comm$vcount+nrow(merges)) miss - matrix(miss, byrow=TRUE, ncol=2) merges - rbind(merges, miss) } storage.mode(merges) - integer merges } Best, Gabor [...] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Spliting Lists into matrices
Dear R users, we generally apply approx() command to a list data. how can we apply this command to a matrix, so that we can approximate 366 readings from certain number of each column over 365 intervals?? more precisely, i want to interpolate 366 discharge readings, in each 8 columns of a matrix, over 365 days. hope i am clear in my statement. eliza botto From: eliza_bo...@hotmail.com To: ruipbarra...@sapo.pt Date: Mon, 4 Jun 2012 22:13:10 + CC: r-help@r-project.org Subject: Re: [R] Spliting Lists into matrices dear rui, lots of hugs for you. thnkyou very much 4 your support. eliza Date: Mon, 4 Jun 2012 22:58:12 +0100 From: ruipbarra...@sapo.pt To: eliza_bo...@hotmail.com CC: r-help@r-project.org Subject: Re: Spliting Lists into matrices Hello, Try # 'x' is your list xlen - sapply(x, length) i1 - which(xlen == 365) i2 - which(xlen == 366) mat365 - matrix(unlist(x[i1]), nrow=365) mat366 - matrix(unlist(x[i2]), nrow=366) Hope this helps, Rui Barradas Em 04-06-2012 22:46, eliza botto escreveu: i realy appreciate your concern.. here is a small piece of my data. if you see the first and last part data, they contain 366 entries but the middle one has 365 entries. i want to put first and last entries is one matrix. list(c(0.86, 0.86, 0.86, 0.86, 0.86, 1.08, 1.08, 1.08, 1.08, 1.08, 1.08, 1.4, 1.4, 23, 11.18, 38.83, 23, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.02, 2.58, 2.58, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 3.02, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.8, 2.8, 2.8, 4.1, 4.1, 13.55, 9.34, 8.32, 7.31, 4.5, 4.1, 14.63, 24.88, 39.99, 23.69, 14.63, 7.31, 4.5, 7.31, 16.82, 21.35, 24.88, 20.2, 24.88, 26.07, 30.98, 49.58, 51.01, 26.07, 24.88, 30.98, 34.77, 58.26, 30.98, 23.69, 26.07, 19.06, 16.82, 20.2, 16.82, 23.69, 14.63, 16.82, 11.42, 11.42, 11.42, 11.42, 10.38, 10.38, 8.32, 7.31, 6.31, 16.82, 6.31, 6.31, 6.31, 4.9, 4.9, 4.5, 4.5, 4.5, 4.5, 4.5, 4.1, 4.1, 2.8, 2.4, 2.4, 26.07, 45.4, 16.82, 7.31, 4.5, 3.2, 3.2, 2.8, 2.8, 2.4, 2.4, 2.8, 3.2, 3.2, 4.9, 4.9, 36.05, 65.8, 76.86, 53.87, 26.07, 20.2, 21.36, 14.63, 10.38, 10.38, 7.31, 7.31, 51.01, 16.82, 14.63, 12.48, 14.63, 10.38, 11.42, 52.44, 64.27, 36.05, 26.07, 21.36, 21.36, 23.69, 47.79, 52.44, 167.9, 97.12, 76.86, 144.71, 90.18, 34.77, 30.98, 28.5, 26.07, 26.07, 14.63, 14.63, 6.31, 6.31, 6.31, 4.5, 4.1, 3.2, 6.31, 6.31, 16.82, 4.5, 3.2, 3.2, 3.2, 3.2, 4.5, 8.32, 10.38, 10.38, 8.32, 11.42, 10.38, 7.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 8.32, 6.31, 6.31, 20.2, 14.63, 7.31, 4.9, 34.77, 26.07, 14.63, 10.38, 6.31, 4.9, 7.31, 4.9, 4.5, 4.5, 4.5, 21.36, 12.48, 7.31, 4.5, 4.5, 6.31, 4.9, 4.9, 6.31, 8.32, 7.31, 6.31, 6.31, 14.63, 11.42, 6.31, 6.31, 4.9, 6.31, 14.63, 7.31, 12.48, 6.31, 6.31, 24.88, 15.72, 33.49, 111.57, 44.03, 39.99, 44.03, 24.88, 12.48, 39.99, 11.42, 7.31, 4.9, 4.5, 4.1, 4.5, 4.1, 4.1, 3.2, 3.2, 3.2, 3.2, 3.2, 2.8, 2.8, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 2.8, 2.8, 3.2, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 4.1, 4.1, 2.4, 3.2, 10.38, 8.32, 4.5, 3.2, 3.2, 2.8, 3.2, 3.2, 3.2, 2.4, 2.4, 2.4, 15.72, 23.69, 12.48, 14.63, 4.5, 4.1, 4.5, 4.1, 4.1, 4.1, 3.2, 2.8, 2.8, 3.2, 2.8, 2.4, 4.5, 4.5, 12.48, 68.9, 30.98, 39.99, 29.73, 95.37, 44.03, 26.07, 41.33, 49.58, 23.69, 28.5), c(16.82, 14.63, 6.31, 6.31, 4.5, 4.5, 4.1, 4.1, 4.1, 3.2, 3.2, 4.1, 3.2, 3.2, 4.1, 4.5, 4.1, 4.1, 167.9, 75.24, 44.03, 23.69, 19.06, 15.72, 11.42, 8.32, 6.31, 4.9, 6.31, 4.9, 4.9, 4.1, 4.1, 3.2, 4.1, 4.1, 4.1, 90.18, 102.45, 39.99, 29.73, 8.32, 21.36, 21.36, 21.36, 12.48, 11.42, 12.48, 11.42, 12.48, 14.63, 14.63, 15.72, 23.69, 28.5, 29.73, 33.49, 29.73, 23.69, 21.36, 6.31, 16.82, 15.72, 15.72, 15.72, 15.72, 16.82, 20.2, 20.2, 21.36, 21.36, 26.07, 28.5, 29.73, 33.49, 29.73, 33.49, 34.77, 26.07, 26.07, 23.69, 23.69, 26.07, 21.36, 23.69, 23.69, 23.69, 24.88, 21.36, 20.2, 16.82, 19.06, 20.2, 21.36, 20.2, 20.2, 24.88, 23.69, 26.07, 29.73, 23.69, 24.88, 29.73, 36.05, 33.49, 34.77, 28.5, 28.5, 26.07, 153, 70.47, 58.26, 81.77, 36.05, 39.99, 30.98, 33.49, 28.5, 28.5, 33.49, 29.73, 28.5, 24.88, 30.98, 38.67, 30.98, 50.01, 65.8, 51.01, 38.67, 34.77, 29.73, 29.73, 33.49, 30.98, 30.98, 30.98, 33.49, 34.77, 33.49, 30.98, 88.48, 14.63, 8.32, 19.06, 14.63, 104.25, 44.03, 33.49, 21.36, 20.2, 15.72, 15.72, 11.42, 7.31, 6.31, 4.9, 4.5, 4.5, 4.5, 3.2, 8.32, 8.32, 14.63, 97.12, 310.8, 88.48, 36.05, 24.88, 19.06, 14.63, 12.48, 8.32, 23.69, 11.42, 19.06, 90.18, 90.18, 33.49, 16.82, 70.47, 38.67, 29.73, 34.77, 33.49, 68.9, 102.45, 176.7,
[R] approximating matrix columns
Dear R users, we generally apply approx() command to a list data. how can we apply this command to a matrix, so that we can approximate 366 readings from certain number of each column over 365 intervals?? more precisely, i want to interpolate 366 discharge readings, in each 8 columns of a matrix, over 365 days. hope i am clear in my statement. eliza botto From: eliza_bo...@hotmail.com To: ruipbarra...@sapo.pt Date: Mon, 4 Jun 2012 22:13:10 + CC: r-help@r-project.org Subject: Re: [R] Spliting Lists into matrices dear rui, lots of hugs for you. thnkyou very much 4 your support. eliza Date: Mon, 4 Jun 2012 22:58:12 +0100 From: ruipbarra...@sapo.pt To: eliza_bo...@hotmail.com CC: r-help@r-project.org Subject: Re: Spliting Lists into matrices Hello, Try # 'x' is your list xlen - sapply(x, length) i1 - which(xlen == 365) i2 - which(xlen == 366) mat365 - matrix(unlist(x[i1]), nrow=365) mat366 - matrix(unlist(x[i2]), nrow=366) Hope this helps, Rui Barradas Em 04-06-2012 22:46, eliza botto escreveu: i realy appreciate your concern.. here is a small piece of my data. if you see the first and last part data, they contain 366 entries but the middle one has 365 entries. i want to put first and last entries is one matrix. list(c(0.86, 0.86, 0.86, 0.86, 0.86, 1.08, 1.08, 1.08, 1.08, 1.08, 1.08, 1.4, 1.4, 23, 11.18, 38.83, 23, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.02, 2.58, 2.58, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 3.02, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.8, 2.8, 2.8, 4.1, 4.1, 13.55, 9.34, 8.32, 7.31, 4.5, 4.1, 14.63, 24.88, 39.99, 23.69, 14.63, 7.31, 4.5, 7.31, 16.82, 21.35, 24.88, 20.2, 24.88, 26.07, 30.98, 49.58, 51.01, 26.07, 24.88, 30.98, 34.77, 58.26, 30.98, 23.69, 26.07, 19.06, 16.82, 20.2, 16.82, 23.69, 14.63, 16.82, 11.42, 11.42, 11.42, 11.42, 10.38, 10.38, 8.32, 7.31, 6.31, 16.82, 6.31, 6.31, 6.31, 4.9, 4.9, 4.5, 4.5, 4.5, 4.5, 4.5, 4.1, 4.1, 2.8, 2.4, 2.4, 26.07, 45.4, 16.82, 7.31, 4.5, 3.2, 3.2, 2.8, 2.8, 2.4, 2.4, 2.8, 3.2, 3.2, 4.9, 4.9, 36.05, 65.8, 76.86, 53.87, 26.07, 20.2, 21.36, 14.63, 10.38, 10.38, 7.31, 7.31, 51.01, 16.82, 14.63, 12.48, 14.63, 10.38, 11.42, 52.44, 64.27, 36.05, 26.07, 21.36, 21.36, 23.69, 47.79, 52.44, 167.9, 97.12, 76.86, 144.71, 90.18, 34.77, 30.98, 28.5, 26.07, 26.07, 14.63, 14.63, 6.31, 6.31, 6.31, 4.5, 4.1, 3.2, 6.31, 6.31, 16.82, 4.5, 3.2, 3.2, 3.2, 3.2, 4.5, 8.32, 10.38, 10.38, 8.32, 11.42, 10.38, 7.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 8.32, 6.31, 6.31, 20.2, 14.63, 7.31, 4.9, 34.77, 26.07, 14.63, 10.38, 6.31, 4.9, 7.31, 4.9, 4.5, 4.5, 4.5, 21.36, 12.48, 7.31, 4.5, 4.5, 6.31, 4.9, 4.9, 6.31, 8.32, 7.31, 6.31, 6.31, 14.63, 11.42, 6.31, 6.31, 4.9, 6.31, 14.63, 7.31, 12.48, 6.31, 6.31, 24.88, 15.72, 33.49, 111.57, 44.03, 39.99, 44.03, 24.88, 12.48, 39.99, 11.42, 7.31, 4.9, 4.5, 4.1, 4.5, 4.1, 4.1, 3.2, 3.2, 3.2, 3.2, 3.2, 2.8, 2.8, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 2.8, 2.8, 3.2, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 4.1, 4.1, 2.4, 3.2, 10.38, 8.32, 4.5, 3.2, 3.2, 2.8, 3.2, 3.2, 3.2, 2.4, 2.4, 2.4, 15.72, 23.69, 12.48, 14.63, 4.5, 4.1, 4.5, 4.1, 4.1, 4.1, 3.2, 2.8, 2.8, 3.2, 2.8, 2.4, 4.5, 4.5, 12.48, 68.9, 30.98, 39.99, 29.73, 95.37, 44.03, 26.07, 41.33, 49.58, 23.69, 28.5), c(16.82, 14.63, 6.31, 6.31, 4.5, 4.5, 4.1, 4.1, 4.1, 3.2, 3.2, 4.1, 3.2, 3.2, 4.1, 4.5, 4.1, 4.1, 167.9, 75.24, 44.03, 23.69, 19.06, 15.72, 11.42, 8.32, 6.31, 4.9, 6.31, 4.9, 4.9, 4.1, 4.1, 3.2, 4.1, 4.1, 4.1, 90.18, 102.45, 39.99, 29.73, 8.32, 21.36, 21.36, 21.36, 12.48, 11.42, 12.48, 11.42, 12.48, 14.63, 14.63, 15.72, 23.69, 28.5, 29.73, 33.49, 29.73, 23.69, 21.36, 6.31, 16.82, 15.72, 15.72, 15.72, 15.72, 16.82, 20.2, 20.2, 21.36, 21.36, 26.07, 28.5, 29.73, 33.49, 29.73, 33.49, 34.77, 26.07, 26.07, 23.69, 23.69, 26.07, 21.36, 23.69, 23.69, 23.69, 24.88, 21.36, 20.2, 16.82, 19.06, 20.2, 21.36, 20.2, 20.2, 24.88, 23.69, 26.07, 29.73, 23.69, 24.88, 29.73, 36.05, 33.49, 34.77, 28.5, 28.5, 26.07, 153, 70.47, 58.26, 81.77, 36.05, 39.99, 30.98, 33.49, 28.5, 28.5, 33.49, 29.73, 28.5, 24.88, 30.98, 38.67, 30.98, 50.01, 65.8, 51.01, 38.67, 34.77, 29.73, 29.73, 33.49, 30.98, 30.98, 30.98, 33.49, 34.77, 33.49, 30.98, 88.48, 14.63, 8.32, 19.06, 14.63, 104.25, 44.03, 33.49, 21.36, 20.2, 15.72, 15.72, 11.42, 7.31, 6.31, 4.9, 4.5, 4.5, 4.5, 3.2, 8.32, 8.32, 14.63, 97.12, 310.8, 88.48, 36.05, 24.88, 19.06, 14.63, 12.48, 8.32, 23.69,
[R] data analysis problem
Dear R users, I have data on 4 types of interest rates. These rates evolve over time and across regions of countries . So for each type of interest rates I want to run a regression of rates on some other variables. So my regression for one type of interest rate will be I_{ij}_t= a +regressors +error term. where I_{ij}_t is the absolute difference in rates between two locations i and j at time t. Note that i and j can be locations in the same country or locations at different countries. What I need is construct a vector with all the pairs of locations for a specific t. Put differently, I want to see how the interest rate differential evolves over time for each pair of region. But the monthly time series data I have available are heterogeneous across countries Take a look at the following table Country Acountry B country C country D country E country F '2-11-2002 '07-12-2002' '23-11-2002' '26-10-2002''27-12-2002' . . . 09-10-2004' '06-11-2004' 02-10-2004' 09-10-2004' From the above table, In country A the time starts at 2/11/02 , in country B the time starts at 07/12/02 and so forth. Furthermore, in country A the time ends at 9/10/04 , in country B the time ends at 06/11/02 and so forth. As a result of this anomaly in the beginning of time, the time duration for each country differs So I cannot construct these pairs because for a particular time, t, the rate exists in one location, but the rate in another location starts after t or ends before t. So the main thing I need to define is what I want done when data has not yet started or is already finished in another country. I do not know actually what the best solution is. This is my main question. I found something about extrapolation (if this is to be the solution) but I learn that extrapolation usually has quite a wide margin of error!! Apart from that, I have no idea how to implement it in R. Do you think that it would be better to try and create a more symmetric sample so as the start and end dates across countries to be very similar? It is a data analysis problem. I need some help __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Variate
Hi Rui You got in before me - time zone differences and other commitments I have done a base graphics of my lattice with your data - it might give some more insight Sites - 1:92 windows(8,10) par(mfrow = c(12,8), mai = c(0,0,0,0) ) invisible( sapply(seq_len(nc), function(j){ i - order(x1[, j]) plot(1, type=n, xlim=c(min(x1), max(x1)), ylim=c(min(y1), max(y1)), axes = F, xlab=, ylab=) box() lines(x1[i, j], y1[i, j], col=colrs[j]) points(x1[i, j], y1[i, j], col=colrs[j], cex = 0.7, pch=20) text(4,0.2,Sites[j], cex = 0.7) }) ) Back to lattice limits in lattice are controlled by xlim, ylim as a vector of the max and min as arguments to xyplot. With the proviso of the scales argument relation = same. Further information at http://lmdvr.r-forge.r-project.org/figures/figures.html Regards Duncan Mackay At 19:51 4/06/2012, you wrote: Hello, Sorry for not understanding your problem, but it really seemed like homework. Now, when I answered scale(x) I meant it, it transforms a matrix in (x - mean)/sd, column by column. If you're new to R, to use the on-line help the instruction is help(scale) ?scale # shortcut As for your graph, I agree with Duncan, 92 lines on the same graph doesn't seem to be a good idea. Anyway, using base R, it could be done along the lines of set.seed(1) nc - 92 # number of columns nr - 366 # number of rows x - matrix(rexp(nr*nc), ncol=nc) x1 - scale(x) # z, standard normal (in fact, studentized) y1 - apply(x, 2, plnorm) # log-normal colrs - rainbow(nc) plot(1, type=n, xlim=c(min(x1), max(x1)), ylim=c(min(y1), max(y1)), xlab=, ylab=) # if you want lines sapply(seq_len(nc), function(j){ i - order(x1[, j]) lines(x1[i, j], y1[i, j], col=colrs[j])}) # if you want points sapply(seq_len(nc), function(j) points(x1[, j], y1[, j], col=colrs[j], pch=.)) Hope this helps, Rui Barradas Em 04-06-2012 07:38, eliza botto escreveu: Dear Mc kay, thankyou very much for your reply. we are extremly greatful to you. we actually wanted all on one scale. we want to compare them all on one axis. kindle see if you could help us on that. one more thing, does this practice give us normal reduced variant on x-axis because we stricktly want normal reduced variant on x-axis. i hope you will cooperate. eliza botto waters inn Date: Mon, 4 Jun 2012 11:54:11 +1000 To: r-help@r-project.org From: mac...@northnet.com.au Subject: Re: [R] Variate Hi Eliza You will not want 1 panel with 96 lines - too confusing after about 20 Instead 1 per panel or with groups using useOuterStrips and combineLimits from latticeExtra package Try this -- a minimal example with an 12 row 8 col grid done on the fly setseed(12) Sites- 1:92 dat- data.frame(y = rep(rnorm(5),92), x = rep(1:5,92), site = rep(Sites,each = 5)) xyplot(y ~ x|site,dat, as.table=T, strip = F, layout = c(8,12), scales = list(x = list(alternating = 2),y=list(alternating=1)), type = b, panel = function(x,y,...){ pnl=panel.number() panel.xyplot(x,y,...) panel.text(4,-1.5,Sites[pnl], cex = 0.6) } ) or with groupings for Site something like (untested) xyplot(y ~ x|groupings,dat, as.table=T, strip = F, strip.left = T, groups = site, scales = list(x = list(alternating = 2),y=list(alternating=1)), type = b, panel = function(x,y,...){ pnl=panel.number() panel.xyplot(x,y,...) panel.text(4,-1.5,Sites[pnl], cex = 0.6) } ) You will need an extra column for groupings This can also be done with the base plot function but lattice gives more flexibility, see ?xyplot and particularly par.settings into get things right size Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au At 11:01 4/06/2012, you wrote: Content-Type: text/plain Content-Disposition: inline Content-length: 2431 Dear R users, We are working on a project called,Environmental Impact Assessment. We are stationed at alpine regions of Ireland to see the impact of rainfall on localities. We have divided our study area into 92 stations. We have also collected 1 year data from each station. Afterwards we placed data into a matrix in such a way that we got 366*92 matrix. 366 stands for number of days. What we want is a lognormal probability plot, of each station(which is individual column of matrix) with normal reduced variant on x-axis. In this way, we should be getting, at the end, 92 curves, one for each station, on same coordinate axis. Kindly help us on that. We are all very new to R. Eliza botto Waters Inn CC: r-help@r-project.org From: dwinsem...@comcast.net To: eliza_bo...@hotmail.com Subject: Re: [R] Log-normal probability
[R] Seeking pointers to various regression techniques with R?
Hi all, Could you please point me to good materials on various tricks/intuitions/techniques of regression, and hopefully in R? For example, what does lm(y~ x * w - 1) mean vs. lm(y ~ x/w -1 ) vs. lm (y ~ x:w-1), etc... I just found that even simple linear regression is not that simple and there are a lot of tricks/techniques in using them... Hopefully I can find good materials on these! Thank you! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Seeking pointers to various regression techniques with R?
Hi Michael, This is far from exhaustive (I wrote it as an introduction some years ago) but you may find it useful to start: https://joshuawiley.com/R/formulae_in_R.aspx Cheers, Josh On Mon, Jun 4, 2012 at 9:06 PM, Michael comtech@gmail.com wrote: Hi all, Could you please point me to good materials on various tricks/intuitions/techniques of regression, and hopefully in R? For example, what does lm(y~ x * w - 1) mean vs. lm(y ~ x/w -1 ) vs. lm (y ~ x:w-1), etc... I just found that even simple linear regression is not that simple and there are a lot of tricks/techniques in using them... Hopefully I can find good materials on these! Thank you! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, Statistical Consulting Group University of California, Los Angeles https://joshuawiley.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] data analysis problem
Stef: 1. Read and follow the posting guide. I could make no sense of your post. This may be because I didn't work hard enough to decrypt it - which I shouldn't have to do -- or because I'm too stupid -- which I can't do anything about anyway. 2. What does this have to do with R anyway? Try posting on a statistical list like stats.stackexchange.com if your primary concern is What should I do rather than How do I do _this_ in R? -- Bert On Mon, Jun 4, 2012 at 5:11 PM, stef salvez loggy...@googlemail.com wrote: Dear R users, I have data on 4 types of interest rates. These rates evolve over time and across regions of countries . So for each type of interest rates I want to run a regression of rates on some other variables. So my regression for one type of interest rate will be I_{ij}_t= a +regressors +error term. where I_{ij}_t is the absolute difference in rates between two locations i and j at time t. Note that i and j can be locations in the same country or locations at different countries. What I need is construct a vector with all the pairs of locations for a specific t. Put differently, I want to see how the interest rate differential evolves over time for each pair of region. But the monthly time series data I have available are heterogeneous across countries Take a look at the following table Country A country B country C country D country E country F '2-11-2002 ' 07-12-2002' '23-11-2002' '26-10-2002' '27-12-2002' . . . 09-10-2004' '06-11-2004' 02-10-2004' 09-10-2004' From the above table, In country A the time starts at 2/11/02 , in country B the time starts at 07/12/02 and so forth. Furthermore, in country A the time ends at 9/10/04 , in country B the time ends at 06/11/02 and so forth. As a result of this anomaly in the beginning of time, the time duration for each country differs So I cannot construct these pairs because for a particular time, t, the rate exists in one location, but the rate in another location starts after t or ends before t. So the main thing I need to define is what I want done when data has not yet started or is already finished in another country. I do not know actually what the best solution is. This is my main question. I found something about extrapolation (if this is to be the solution) but I learn that extrapolation usually has quite a wide margin of error!! Apart from that, I have no idea how to implement it in R. Do you think that it would be better to try and create a more symmetric sample so as the start and end dates across countries to be very similar? It is a data analysis problem. I need some help __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] approximating matrix columns
1. Please follow the posting guide and provide a small reproducible example. See ?dput to provide data. 2. Please do not double post. -- Bert On Mon, Jun 4, 2012 at 4:47 PM, eliza botto eliza_bo...@hotmail.com wrote: Dear R users, we generally apply approx() command to a list data. how can we apply this command to a matrix, so that we can approximate 366 readings from certain number of each column over 365 intervals?? more precisely, i want to interpolate 366 discharge readings, in each 8 columns of a matrix, over 365 days. hope i am clear in my statement. eliza botto From: eliza_bo...@hotmail.com To: ruipbarra...@sapo.pt Date: Mon, 4 Jun 2012 22:13:10 + CC: r-help@r-project.org Subject: Re: [R] Spliting Lists into matrices dear rui, lots of hugs for you. thnkyou very much 4 your support. eliza Date: Mon, 4 Jun 2012 22:58:12 +0100 From: ruipbarra...@sapo.pt To: eliza_bo...@hotmail.com CC: r-help@r-project.org Subject: Re: Spliting Lists into matrices Hello, Try # 'x' is your list xlen - sapply(x, length) i1 - which(xlen == 365) i2 - which(xlen == 366) mat365 - matrix(unlist(x[i1]), nrow=365) mat366 - matrix(unlist(x[i2]), nrow=366) Hope this helps, Rui Barradas Em 04-06-2012 22:46, eliza botto escreveu: i realy appreciate your concern.. here is a small piece of my data. if you see the first and last part data, they contain 366 entries but the middle one has 365 entries. i want to put first and last entries is one matrix. list(c(0.86, 0.86, 0.86, 0.86, 0.86, 1.08, 1.08, 1.08, 1.08, 1.08, 1.08, 1.4, 1.4, 23, 11.18, 38.83, 23, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.45, 3.02, 2.58, 2.58, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 2.15, 3.02, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.72, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.4, 2.8, 2.8, 2.8, 4.1, 4.1, 13.55, 9.34, 8.32, 7.31, 4.5, 4.1, 14.63, 24.88, 39.99, 23.69, 14.63, 7.31, 4.5, 7.31, 16.82, 21.35, 24.88, 20.2, 24.88, 26.07, 30.98, 49.58, 51.01, 26.07, 24.88, 30.98, 34.77, 58.26, 30.98, 23.69, 26.07, 19.06, 16.82, 20.2, 16.82, 23.69, 14.63, 16.82, 11.42, 11.42, 11.42, 11.42, 10.38, 10.38, 8.32, 7.31, 6.31, 16.82, 6.31, 6.31, 6.31, 4.9, 4.9, 4.5, 4.5, 4.5, 4.5, 4.5, 4.1, 4.1, 2.8, 2.4, 2.4, 26.07, 45.4, 16.82, 7.31, 4.5, 3.2, 3.2, 2.8, 2.8, 2.4, 2.4, 2.8, 3.2, 3.2, 4.9, 4.9, 36.05, 65.8, 76.86, 53.87, 26.07, 20.2, 21.36, 14.63, 10.38, 10.38, 7.31, 7.31, 51.01, 16.82, 14.63, 12.48, 14.63, 10.38, 11.42, 52.44, 64.27, 36.05, 26.07, 21.36, 21.36, 23.69, 47.79, 52.44, 167.9, 97.12, 76.86, 144.71, 90.18, 34.77, 30.98, 28.5, 26.07, 26.07, 14.63, 14.63, 6.31, 6.31, 6.31, 4.5, 4.1, 3.2, 6.31, 6.31, 16.82, 4.5, 3.2, 3.2, 3.2, 3.2, 4.5, 8.32, 10.38, 10.38, 8.32, 11.42, 10.38, 7.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 6.31, 8.32, 6.31, 6.31, 20.2, 14.63, 7.31, 4.9, 34.77, 26.07, 14.63, 10.38, 6.31, 4.9, 7.31, 4.9, 4.5, 4.5, 4.5, 21.36, 12.48, 7.31, 4.5, 4.5, 6.31, 4.9, 4.9, 6.31, 8.32, 7.31, 6.31, 6.31, 14.63, 11.42, 6.31, 6.31, 4.9, 6.31, 14.63, 7.31, 12.48, 6.31, 6.31, 24.88, 15.72, 33.49, 111.57, 44.03, 39.99, 44.03, 24.88, 12.48, 39.99, 11.42, 7.31, 4.9, 4.5, 4.1, 4.5, 4.1, 4.1, 3.2, 3.2, 3.2, 3.2, 3.2, 2.8, 2.8, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 2.8, 2.8, 3.2, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 4.1, 4.1, 2.4, 3.2, 10.38, 8.32, 4.5, 3.2, 3.2, 2.8, 3.2, 3.2, 3.2, 2.4, 2.4, 2.4, 15.72, 23.69, 12.48, 14.63, 4.5, 4.1, 4.5, 4.1, 4.1, 4.1, 3.2, 2.8, 2.8, 3.2, 2.8, 2.4, 4.5, 4.5, 12.48, 68.9, 30.98, 39.99, 29.73, 95.37, 44.03, 26.07, 41.33, 49.58, 23.69, 28.5), c(16.82, 14.63, 6.31, 6.31, 4.5, 4.5, 4.1, 4.1, 4.1, 3.2, 3.2, 4.1, 3.2, 3.2, 4.1, 4.5, 4.1, 4.1, 167.9, 75.24, 44.03, 23.69, 19.06, 15.72, 11.42, 8.32, 6.31, 4.9, 6.31, 4.9, 4.9, 4.1, 4.1, 3.2, 4.1, 4.1, 4.1, 90.18, 102.45, 39.99, 29.73, 8.32, 21.36, 21.36, 21.36, 12.48, 11.42, 12.48, 11.42, 12.48, 14.63, 14.63, 15.72, 23.69, 28.5, 29.73, 33.49, 29.73, 23.69, 21.36, 6.31, 16.82, 15.72, 15.72, 15.72, 15.72, 16.82, 20.2, 20.2, 21.36, 21.36, 26.07, 28.5, 29.73, 33.49, 29.73, 33.49, 34.77, 26.07, 26.07, 23.69, 23.69, 26.07, 21.36, 23.69, 23.69, 23.69, 24.88, 21.36, 20.2, 16.82, 19.06, 20.2, 21.36, 20.2, 20.2, 24.88, 23.69, 26.07, 29.73, 23.69, 24.88, 29.73, 36.05, 33.49, 34.77, 28.5, 28.5, 26.07, 153, 70.47, 58.26, 81.77, 36.05, 39.99, 30.98, 33.49, 28.5, 28.5, 33.49, 29.73, 28.5, 24.88, 30.98, 38.67, 30.98, 50.01, 65.8, 51.01, 38.67, 34.77, 29.73, 29.73, 33.49, 30.98, 30.98, 30.98, 33.49, 34.77, 33.49, 30.98, 88.48, 14.63, 8.32,