[R] Break up a data frame
Hi R users, I have a dataframe in the below format xyz 01/03/200715.25USD xyz 01/04/200715.32USD xyz 01/02/200823.22USD abc 01/03/200745.2 EUR abc 01/04/200745.00EUR abc 01/02/200868.33EUR I want to change the above data into the below format xyz 01/03/200715.25USD abc 01/03/200745.2 EUR xyz 01/04/200715.32USD abc 01/04/200745.00EUR xyz 01/02/200823.22USD abc 01/02/200868.33EUR Any help would be welcome Thank you Ravi This e-mail may contain confidential and/or privileged i...{{dropped:13}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] create matrix
Hi all, I have a dataset consisting of 5 columns and over 5000 rows. Each row gives information about an individual animal, including longevity, i.e. at what age an animal died. For the model I use I need to create n rows for each animal, n being its longevity, and a new column 'survival' with a binary 0/1 outcome. When an animal died e.g. at age 5, there have to be 5 rows of identical data, except 4 with 0 (=alive) for 'survival', and 1 row with '1' for 'survival'. I thought of creating matrices for each individual, adding first one column 'survival' containing zeros to the original dataset, then creating matrices with data = 'the vector containing all elements of an individual/row' ([1,], nrow = [a,b], exctracting the element for longevity, and then with byrow = TRUE letting the data be filled in by row. At the end I would have to set the last element in 'survival' to '1', and then combine all matrices into one single one. So far I've used Excel to create these datesets manually, but with more than 1000 individuals this gets really tedious. I haven't used R before for this sort of a bit more advanced data manipulation, and I would really appreciate any input/primer about how people would go about doing this. Thanks, Felix __ ::Felix Zajitschek Evolution Ecology Research Centre School of Biological, Earth and Environmental Sciences University of New South Wales - Sydney NSW 2052 - Australia Tel +61 (0)2 9385 8068 Fax +61 (0)2 9385 1558 eMail mailto:[EMAIL PROTECTED] [EMAIL PROTECTED] http://www.bees.unsw.edu.au/school/researchstudents/zajitschekfelix.htm l www.bees.unsw.edu.au/school/researchstudents/zajitschekfelix.html [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to cope with : /usr/bin/ld/: cannot find -lgfortran
Good Morning, I am running R-2.6.1-1.rh5.i386.rpm under RED HAT Enterprise Linux 5, but I get this message error /usr/bin/ld/: cannot find -lgfortran when trying installing R CMD INSTALL ade4_1.4-5.tar.gz. Please help me to cope with this problem. Best regards, Souleymane _ [[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] executable script
Can you please give me some additional informations. I never created a .bat I have no experience. Peter Alspach wrote: Kia ora unknown requestor One option is to create a .bat file along the following lines: path_to_R\bin\R CMD BATCH yourScript.R Peter Alspach -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of mysimbaa Sent: Thursday, 15 November 2007 6:10 a.m. To: r-help@r-project.org Subject: [R] executable script Dear All, Apologies for this simple question and thanks in advance for any help given. I want to make from my .R script an .exe file. Is there any way to transfort my script to an autolaunch file? It means it runs the script by double clicking on it. p.s.: I'm using windows -- View this message in context: http://www.nabble.com/executable-script-tf4806651.html#a13751752 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. -- View this message in context: http://www.nabble.com/executable-script-tp13751752p16173775.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] basic help
On 3/20/2008 12:59 AM, מוטי אסולין wrote: Hi, I am a new R user (used SPSS for many years) and I need help. I have a data frame mydata with 8 variables m2008:m2001 I wanted to add a new variable mydata$firstvalid that tells me what is the first non missing variable for each case (without using for-next). I tried many variations of this: lst = paste(m,2008:2001,sep=) mydata$firstvalid = match(FALSE, is.na(mydata[lst]),0) Instead of a different value for each case, I get the same value for all cases - the first non missing value in the whole data frame. Many thanks, Moti Assouline X - as.data.frame(matrix(sample(c(NA,NA,1:5), 100, replace=TRUE), ncol=5)) X V1 V2 V3 V4 V5 1 NA NA NA NA NA 2 2 4 NA 3 3 3 2 3 NA NA NA 4 4 3 2 NA 2 5 2 3 2 NA NA 6 5 3 2 5 NA 7 NA 5 NA 3 3 8 3 NA 3 2 2 9 4 5 5 NA 3 10 2 5 NA NA 1 11 1 2 NA NA 2 12 2 4 NA 5 2 13 NA 5 NA NA NA 14 5 5 4 5 NA 15 2 NA 5 2 NA 16 NA 1 4 NA NA 17 NA 5 NA 5 NA 18 5 2 NA 4 1 19 3 5 2 4 5 20 4 NA 2 1 NA X$FVALID - apply(is.na(X), 1, function(x){ifelse(all(x), 0, which.min(x))}) X V1 V2 V3 V4 V5 FVALID 1 NA NA NA NA NA 0 2 2 4 NA 3 3 1 3 2 3 NA NA NA 1 4 4 3 2 NA 2 1 5 2 3 2 NA NA 1 6 5 3 2 5 NA 1 7 NA 5 NA 3 3 2 8 3 NA 3 2 2 1 9 4 5 5 NA 3 1 10 2 5 NA NA 1 1 11 1 2 NA NA 2 1 12 2 4 NA 5 2 1 13 NA 5 NA NA NA 2 14 5 5 4 5 NA 1 15 2 NA 5 2 NA 1 16 NA 1 4 NA NA 2 17 NA 5 NA 5 NA 2 18 5 2 NA 4 1 1 19 3 5 2 4 5 1 20 4 NA 2 1 NA 1 Checked by AVG. 20:52 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to cope with : /usr/bin/ld/: cannot find -lgfortran
Good Morning, Please don't post twice! Please don't post twice! (The two R-help addresses you used are the same list.) Did I mention that posting twice is counter-productive? On Thu, 20 Mar 2008, Ndoye Souleymane wrote: Good Morning, I am running R-2.6.1-1.rh5.i386.rpm under RED HAT Enterprise Linux 5, but I get this message error /usr/bin/ld/: cannot find -lgfortran when trying installing R CMD INSTALL ade4_1.4-5.tar.gz. Please help me to cope with this problem. You need to install it from the appropriate RPM. This will happen if you install the R-devel RPM, and while you are at it we urge you to the upgrade (as the posting guide asked you to do before posting). The RPMs you need are at http://cran.r-project.org/bin/linux/redhat/el5/i386/, namely http://cran.r-project.org/bin/linux/redhat/el5/i386/R-2.6.2-1.rh5.i386.rpm http://cran.r-project.org/bin/linux/redhat/el5/i386/R-devel-2.6.2-1.rh5.i386.rpm But if you don't want to do that, just install the gcc-gfortran RPM. Best regards, Souleymane _ [[alternative HTML version deleted]] You were asked in the posting guide not to send HTML. R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. PLEASE do! -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 plot the dendrogram or tree for kmeans ?
On Thu, Mar 20, 2008 at 5:45 AM, [EMAIL PROTECTED] wrote: Why do you think there is one? kmeans is an agglomerative clustering algorithm, not a recursively dividing one. Since there is no clustering hierarchy, so there is no dendrogram. However, you could create a clustergram: @article{schonlau:2002, Author = {Schonlau, Matthias}, Journal = {The Stata Journal}, Pages = {316-327}, Title = {The clustergram: A graph for visualizing hierarchical and non-hierarchical cluster analyses}, Volume = {3}, Year = {2002}, Url = {http://www.schonlau.net/clustergram.html} } Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Break up a data frame
Is this close to what you want? x - read.table('clipboard') x V1 V2V3 V4 1 xyz 01/03/2007 15.25 USD 2 xyz 01/04/2007 15.32 USD 3 xyz 01/02/2008 23.22 USD 4 abc 01/03/2007 45.20 EUR 5 abc 01/04/2007 45.00 EUR 6 abc 01/02/2008 68.33 EUR x.m - melt(x) Using V1, V2, V4 as id variables x V1 V2V3 V4 1 xyz 01/03/2007 15.25 USD 2 xyz 01/04/2007 15.32 USD 3 xyz 01/02/2008 23.22 USD 4 abc 01/03/2007 45.20 EUR 5 abc 01/04/2007 45.00 EUR 6 abc 01/02/2008 68.33 EUR cast(x.m, V2~V4) V2 EUR USD 1 01/02/2008 68.33 23.22 2 01/03/2007 45.20 15.25 3 01/04/2007 45.00 15.32 On Thu, Mar 20, 2008 at 1:22 AM, Ravi S. Shankar [EMAIL PROTECTED] wrote: Hi R users, I have a dataframe in the below format xyz 01/03/200715.25USD xyz 01/04/200715.32USD xyz 01/02/200823.22USD abc 01/03/200745.2 EUR abc 01/04/200745.00EUR abc 01/02/200868.33EUR I want to change the above data into the below format xyz 01/03/200715.25USD abc 01/03/200745.2 EUR xyz 01/04/200715.32USD abc 01/04/200745.00EUR xyz 01/02/200823.22USD abc 01/02/200868.33EUR Any help would be welcome Thank you Ravi This e-mail may contain confidential and/or privileged i...{{dropped:13}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] create matrix
Since you did not provide a sample of your data, here is an example of how to take a vector and create a matrix with 5 entries for each value, with the extra ones having a zero in the second column: x - sample(1:7, 20, T) table(x) x 1 2 3 4 5 6 7 2 4 3 2 4 4 1 # create a matrix with 5 rows of each value in the vector 'x' with the extra rows # having 0 in the second column x.l - lapply(split(x, x), function(.val){ + # pad with at least 5 extra rows to make sure matrix is filled out + z - cbind(c(.val, rep(.val[1],5)), c(rep(1, length(.val)), rep(0,5))) + z[1:5,] # only return the first 5 + }) # output the new matrix do.call(rbind, x.l) [,1] [,2] [1,]11 [2,]11 [3,]10 [4,]10 [5,]10 [6,]21 [7,]21 [8,]21 [9,]21 [10,]20 [11,]31 [12,]31 [13,]31 [14,]30 [15,]30 [16,]41 [17,]41 [18,]40 [19,]40 [20,]40 [21,]51 [22,]51 [23,]51 [24,]51 [25,]50 [26,]61 [27,]61 [28,]61 [29,]61 [30,]60 [31,]71 [32,]70 [33,]70 [34,]70 [35,]70 On Thu, Mar 20, 2008 at 1:51 AM, Felix Zajitschek - UNSW [EMAIL PROTECTED] wrote: Hi all, I have a dataset consisting of 5 columns and over 5000 rows. Each row gives information about an individual animal, including longevity, i.e. at what age an animal died. For the model I use I need to create n rows for each animal, n being its longevity, and a new column 'survival' with a binary 0/1 outcome. When an animal died e.g. at age 5, there have to be 5 rows of identical data, except 4 with 0 (=alive) for 'survival', and 1 row with '1' for 'survival'. I thought of creating matrices for each individual, adding first one column 'survival' containing zeros to the original dataset, then creating matrices with data = 'the vector containing all elements of an individual/row' ([1,], nrow = [a,b], exctracting the element for longevity, and then with byrow = TRUE letting the data be filled in by row. At the end I would have to set the last element in 'survival' to '1', and then combine all matrices into one single one. So far I've used Excel to create these datesets manually, but with more than 1000 individuals this gets really tedious. I haven't used R before for this sort of a bit more advanced data manipulation, and I would really appreciate any input/primer about how people would go about doing this. Thanks, Felix __ ::Felix Zajitschek Evolution Ecology Research Centre School of Biological, Earth and Environmental Sciences University of New South Wales - Sydney NSW 2052 - Australia Tel +61 (0)2 9385 8068 Fax +61 (0)2 9385 1558 eMail mailto:[EMAIL PROTECTED] [EMAIL PROTECTED] http://www.bees.unsw.edu.au/school/researchstudents/zajitschekfelix.htm l www.bees.unsw.edu.au/school/researchstudents/zajitschekfelix.html [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 can I reorder a dendrogram?
Hi! I am trying to reorder a dendrogram via reorder.dendrogram. However, I observed some problems with this, and I will illustrate them with an example. Take the following clustering problem: datamatrix - matrix(c(2,2,2.5,2,1.5,2,2,1.5,2,2.5, 6,2,6.5,2,5.5,2,6,1.5,6,2.5, 4,4,4.5,4,3.5,4,4,3.5,4,4.5), ncol=2, byrow=TRUE) distmatrix - dist(datamatrix, method=manhattan) hc - hclust(distmatrix, method=single) dendro - as.dendrogram(hc) The datamatrix contains three equidistant (for manhattan distance) clusters, each of which contains 5 points. Now, I want to impose an order: weights - c(2.0, 2.0, 2.0, 2.0, 2.0, 6.0, 6.0, 6.0, 6.0, 6.0, 4.0, 4.0, 4.0, 4.0, 4.0) ddd - reorder(dendro, weights, agglo.FUN=mean) but if you compare the order of ddd with dendro, you see no change: unlist(ddd) [1] 15 14 13 11 12 5 4 3 1 2 10 9 8 6 7 unlist(dendro) [1] 15 14 13 11 12 5 4 3 1 2 10 9 8 6 7 I would have expected something like: 5 4 3 1 2 15 14 13 11 12 10 9 8 6 7 or something of the sort. (I still do not know, if the order should be ascending or descending, but in the obtained result, it is neither nor). I do not see, where my mistake is ... Thanks for your advice! Thomas. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] gui to run script
Dear R users, I'm trying since longtime to make an autolaunch of my code, but no results. I have programmed three codes. And depending on my data(logfile collected from another source) I have (frequently) to run one of the three codes. I'm looking for a better solution that run on of the codes without lauching R, specifiying the path of the code and compile. My idea is to make a gui (popup window) asking me : - what of the three codes you want to run? -autoload the corresponding code. -save graphics in memory (when I type ctr+v it will appears.) Is there any simple solution ? Thanks for any help. p.s. I running R under windows XP. -- View this message in context: http://www.nabble.com/gui-to-run-script-tp16175981p16175981.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 can I reorder a dendrogram?
Oups ... sorry, actually I found the problem. The problem lies not with the reordering but with the construction of the dendrogram: if a hierarchical method is used, there are never more than 2 branches for a node. Therefore, the reordering does not give the expected result. I will have to try something different ... Thanks anyway. Thomas. Thomas Walter wrote: Hi! I am trying to reorder a dendrogram via reorder.dendrogram. However, I observed some problems with this, and I will illustrate them with an example. Take the following clustering problem: datamatrix - matrix(c(2,2,2.5,2,1.5,2,2,1.5,2,2.5, 6,2,6.5,2,5.5,2,6,1.5,6,2.5, 4,4,4.5,4,3.5,4,4,3.5,4,4.5), ncol=2, byrow=TRUE) distmatrix - dist(datamatrix, method=manhattan) hc - hclust(distmatrix, method=single) dendro - as.dendrogram(hc) The datamatrix contains three equidistant (for manhattan distance) clusters, each of which contains 5 points. Now, I want to impose an order: weights - c(2.0, 2.0, 2.0, 2.0, 2.0, 6.0, 6.0, 6.0, 6.0, 6.0, 4.0, 4.0, 4.0, 4.0, 4.0) ddd - reorder(dendro, weights, agglo.FUN=mean) but if you compare the order of ddd with dendro, you see no change: unlist(ddd) [1] 15 14 13 11 12 5 4 3 1 2 10 9 8 6 7 unlist(dendro) [1] 15 14 13 11 12 5 4 3 1 2 10 9 8 6 7 I would have expected something like: 5 4 3 1 2 15 14 13 11 12 10 9 8 6 7 or something of the sort. (I still do not know, if the order should be ascending or descending, but in the obtained result, it is neither nor). I do not see, where my mistake is ... Thanks for your advice! Thomas. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- - Thomas Walter EMBL Heidelberg Meyerhofstrasse 1 69117 Heidelberg Germany Tel: +49 (0)6221 387-8857 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Cointegration no constant
Hi, I am trying to estimate a VECM without constant using the following code: data(finland) sjf - finland sjf.reg-ca.jo(sjf, type = c(eigen), ecdet = c(none), K = 2,spec=c(transitory), season = NULL, dumvar = NULL) cajools(sjf.reg) While the cointegration test does not use a constant, it is used in the cajools which I do not want. I am sure I am doing something wrong - what should I change? Hello Ralph, are you really sure that you do want to include a constant in cajools? If so, this can be swiftly accomplished by: [EMAIL PROTECTED] - [EMAIL PROTECTED], -1] cajools(sjf.reg) i.e., you drop the constant from the slot Z1 (have a look at cajools to see how the regression are set up). You might want consider using cajorls, too. Best, Bernhard Any help very much appreciated! Ralph _ Need to know the score, the latest news, or you need your Hotmail(r)-get your fix. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. * Confidentiality Note: The information contained in this ...{{dropped:10}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Problem with diff(strptime(...
Hi all, I have been chipping away at a problem I encountered in calculating rates per year from a moderately large data file (46412 rows). When I ran the following command, I got obviously wrong output: interval- c(NA,as.numeric(diff( strptime(mkdf$MEAS_DATE,%d/%m/%Y)))/365.25) The values in MEAS_DATE looked like this: mkdf$MEAS_DATE[1:10] [1] 1/5/1962 1/5/1963 1/5/1964 1/3/1965 1/4/1966 1/4/1967 1/6/1968 [8] 25/3/1969 1/4/1971 1/2/1974 146 Levels: 10/10/1967 1/10/1947 1/10/1965 1/10/1967 1/10/1983 ... 9/1/1992 To abbreviate three evenings of work, I finally found that values 17170 and 17171 were the same. If I ran the entire set, or anything over 1:17170, I would get output like this: interval[1:10] [1]NA 86340.86 86577.41 71911.29 93673.92 86340.86 101006.98 [8] 70255.44 174337.58 245292.81 If I ran any set of values up to 17170, I would get the correct output: interval[1:10] [1]NA 0.9993155 1.0020534 0.8323066 1.0841889 0.9993155 1.1690623 [8] 0.8131417 2.0177960 2.8390372 If I changed value 17171 by one day (and added that level), the command worked correctly: interval[1:10] [1]NA 0.9993155 1.0020534 0.8323066 1.0841889 0.9993155 1.1690623 [8] 0.8131417 2.0177960 2.8390372 There have been a few messages about this problem, but apparently no solution. The problem can be seen with these examples (I haven't included the real data as it is not mine): foodate-c(1/7/1991,1/8/1991,1/8/1991,3/8/1991) as.numeric(diff(strptime(foodate,%d/%m/%Y))/365.25) [1] 7333.05950. 473.1006 foodate-factor(c(1/7/1991,1/8/1991,1/8/1991,3/8/1991)) as.numeric(diff(strptime(foodate,%d/%m/%Y))/365.25) [1] 7333.05950. 473.1006 foodate-factor(c(1/7/1991,1/8/1991,2/8/1991,3/8/1991)) as.numeric(diff(strptime(foodate,%d/%m/%Y))/365.25) [1] 0.084873374 0.002737851 0.002737851 Beats me. 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] interperting a regression tree
hello i am trying to decipher a dendrogram i have from performing a 'tree'. (attached file) my response variable is factored - low, medium and high threat and the 8 explanatory variables are numeric values. i could do with some help to understand what the values 0.25, 0.5 and 0.75 are on the tree branches? how does one interpret this??? cheers, mann Manju Sharma Ashoka Trust for Research in Ecology and the Environment, Banaglore, India __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Break up a data frame
Or perhaps: xtabs(V3 ~ V2 + V4, data=x) On 20/03/2008, Ravi S. Shankar [EMAIL PROTECTED] wrote: Hi R users, I have a dataframe in the below format xyz 01/03/200715.25USD xyz 01/04/200715.32USD xyz 01/02/200823.22USD abc 01/03/200745.2 EUR abc 01/04/200745.00EUR abc 01/02/200868.33EUR I want to change the above data into the below format xyz 01/03/200715.25USD abc 01/03/200745.2 EUR xyz 01/04/200715.32USD abc 01/04/200745.00EUR xyz 01/02/200823.22USD abc 01/02/200868.33EUR Any help would be welcome Thank you Ravi This e-mail may contain confidential and/or privileged i...{{dropped:13}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] conditional matching of rows of tables
Hi, Given matrix A of 4 cols. 1 a 0 4 1 b 5 8 2 a 0 3 2 b 4 7 I have another matrix B of 3 cols. How to assign (a or b) to the rows such that in each row its 1st value must match the 1st col. of A, 2nd and 3rd values must lie between 3rd and 4rd cols (inclusive) of A 1 2 3 - a 2 4 5 - b 2 0 3 - a 1 7 8 - b [[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] Equal vertical spaced labels on plot with log=y
Daniel Brewer wrote: Hello, I have a series of labels that I want to place on a plot with a log scale y axis. I want these labels to be equally spaced vertically as seen on the plot. I have been trying this: ylab - 160 - log2(1:length(labels)) but that does not seem to work (where 160 is basically the top of the plot). Hi Daniel, The method I use is to get the real coordinates on the plot: xylim-par(usr) turn off the log transformation: par(ylog=FALSE) say I have three labels that I want to space: ypos-xylim[3]+(xylim[4]-xylim[3])*c(0.2,0.5,0.8) text(xpos,ypos,c(first,second,third)) # turn the y log transformation on again if necessary par(ylog=TRUE) I assume you can work out xpos for yourself. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with diff(strptime(...
You are throwing away the clue in your use of as.numeric. First. strptime returns a POSIXlt value, which you will convert to POSIXct when you do arithetic (using diff()). Why are you doing that? So foodate-factor(c(1/7/1991,1/8/1991,1/8/1991,3/8/1991)) diff(strptime(foodate,%d/%m/%Y)) Time differences in secs [1] 2678400 0 172800 attr(,tzone) [1] is correct. I think you intended diff(as.Date(foodate,%d/%m/%Y))/365.25 or even add as.numeric() inside diff(). On Thu, 20 Mar 2008, Jim Lemon wrote: Hi all, I have been chipping away at a problem I encountered in calculating rates per year from a moderately large data file (46412 rows). When I ran the following command, I got obviously wrong output: interval- c(NA,as.numeric(diff( strptime(mkdf$MEAS_DATE,%d/%m/%Y)))/365.25) The values in MEAS_DATE looked like this: mkdf$MEAS_DATE[1:10] [1] 1/5/1962 1/5/1963 1/5/1964 1/3/1965 1/4/1966 1/4/1967 1/6/1968 [8] 25/3/1969 1/4/1971 1/2/1974 146 Levels: 10/10/1967 1/10/1947 1/10/1965 1/10/1967 1/10/1983 ... 9/1/1992 To abbreviate three evenings of work, I finally found that values 17170 and 17171 were the same. If I ran the entire set, or anything over 1:17170, I would get output like this: interval[1:10] [1]NA 86340.86 86577.41 71911.29 93673.92 86340.86 101006.98 [8] 70255.44 174337.58 245292.81 If I ran any set of values up to 17170, I would get the correct output: interval[1:10] [1]NA 0.9993155 1.0020534 0.8323066 1.0841889 0.9993155 1.1690623 [8] 0.8131417 2.0177960 2.8390372 If I changed value 17171 by one day (and added that level), the command worked correctly: interval[1:10] [1]NA 0.9993155 1.0020534 0.8323066 1.0841889 0.9993155 1.1690623 [8] 0.8131417 2.0177960 2.8390372 There have been a few messages about this problem, but apparently no solution. The problem can be seen with these examples (I haven't included the real data as it is not mine): foodate-c(1/7/1991,1/8/1991,1/8/1991,3/8/1991) as.numeric(diff(strptime(foodate,%d/%m/%Y))/365.25) [1] 7333.05950. 473.1006 foodate-factor(c(1/7/1991,1/8/1991,1/8/1991,3/8/1991)) as.numeric(diff(strptime(foodate,%d/%m/%Y))/365.25) [1] 7333.05950. 473.1006 foodate-factor(c(1/7/1991,1/8/1991,2/8/1991,3/8/1991)) as.numeric(diff(strptime(foodate,%d/%m/%Y))/365.25) [1] 0.084873374 0.002737851 0.002737851 Beats me. 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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Multiple plots question
Hello (Sorry if this appears twice, had some mail problems...) I have a number of different data sets, each loaded as a matrix. I'd like to plot them in a way that the data in the first column of each matrix is plotted on the same pair of axes. What I'm doing now is to call plot() for the data on the first matrix, then call points() for the other ones. However, the axes are set by R according to the data passed to plot(), and sometimes the data passed to points() has larger values on the x axis, and the plot ends up being cut (the y axis is not a problem since they're all probabilities). Is there a way to dynamically adapt the axes so that all data can be seen? I know I could build a new matrix with the columns I want to plot but each matrix has 1 million rows, so I figure this would be inefficient. Do I have to check beforehand which column has the largest value and call plot() on it, and then points() on the others, or is there an automatic way to do this? Thanks in advance, Andre __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 can I reorder a dendrogram?
Hello, Perhaps, you should chose another toy example closer to the reality. Cases with exactly same distance rarely occur in the field. You should, at least, add some random error: datamatrix - matrix(c(2,2,2.5,2,1.5,2,2,1.5,2,2.5, 6,2,6.5,2,5.5,2,6,1.5,6,2.5, 4,4,4.5,4,3.5,4,4,3.5,4,4.5) + rnorm(30, sd = 0.1), ncol = 2, byrow = TRUE) distmatrix - dist(datamatrix, method = manhattan) hc - hclust(distmatrix, method = single) dendro - as.dendrogram(hc) plot(dendro) #Now, I want to impose an order: weights - c(2.0, 2.0, 2.0, 2.0, 2.0, 6.0, 6.0, 6.0, 6.0, 6.0, 4.0, 4.0, 4.0, 4.0, 4.0) ddd - reorder(dendro, weights, agglo.FUN=mean) plot(ddd) unlist(ddd) # [1] 4 2 3 1 5 13 14 15 11 12 10 7 9 6 8 unlist(dendro) # [1] 10 7 9 6 8 13 14 15 11 12 4 2 3 1 5 Best, Philippe Grosjean ..°})) ) ) ) ) ) ( ( ( ( (Prof. Philippe Grosjean ) ) ) ) ) ( ( ( ( (Numerical Ecology of Aquatic Systems ) ) ) ) ) Mons-Hainaut University, Belgium ( ( ( ( ( .. Thomas Walter wrote: Hi! I am trying to reorder a dendrogram via reorder.dendrogram. However, I observed some problems with this, and I will illustrate them with an example. Take the following clustering problem: datamatrix - matrix(c(2,2,2.5,2,1.5,2,2,1.5,2,2.5, 6,2,6.5,2,5.5,2,6,1.5,6,2.5, 4,4,4.5,4,3.5,4,4,3.5,4,4.5), ncol=2, byrow=TRUE) distmatrix - dist(datamatrix, method=manhattan) hc - hclust(distmatrix, method=single) dendro - as.dendrogram(hc) The datamatrix contains three equidistant (for manhattan distance) clusters, each of which contains 5 points. Now, I want to impose an order: weights - c(2.0, 2.0, 2.0, 2.0, 2.0, 6.0, 6.0, 6.0, 6.0, 6.0, 4.0, 4.0, 4.0, 4.0, 4.0) ddd - reorder(dendro, weights, agglo.FUN=mean) but if you compare the order of ddd with dendro, you see no change: unlist(ddd) [1] 15 14 13 11 12 5 4 3 1 2 10 9 8 6 7 unlist(dendro) [1] 15 14 13 11 12 5 4 3 1 2 10 9 8 6 7 I would have expected something like: 5 4 3 1 2 15 14 13 11 12 10 9 8 6 7 or something of the sort. (I still do not know, if the order should be ascending or descending, but in the obtained result, it is neither nor). I do not see, where my mistake is ... Thanks for your advice! Thomas. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] create matrix
There may be a less baroque way of doing it, but does this do what you want? Say you have a data.frame called dat: dat x1 x2 Longevity 1 -1.9582519 a 4 2 0.8724081 b 2 3 -0.9150847 c 5 # now create a new long data.frame: dat.long - as.data.frame(mapply(function (x) rep(x, dat$Longevity), dat[,1:2])) # Add in the survival column: dat.long$Survival - unlist(sapply(dat$Longevity, function (x) c(rep(0, x-1),1))) dat.long x1 x2 Survival 1 -1.95825191986208 a0 2 -1.95825191986208 a0 3 -1.95825191986208 a0 4 -1.95825191986208 a1 5 0.872408144284977 b0 6 0.872408144284977 b1 7 -0.91508470125413 c0 8 -0.91508470125413 c0 9 -0.91508470125413 c0 10 -0.91508470125413 c0 11 -0.91508470125413 c1 HTH, Simon. Simon Blomberg, BSc (Hons), PhD, MAppStat. Lecturer and Consultant Statistician Faculty of Biological and Chemical Sciences The University of Queensland St. Lucia Queensland 4072 Australia T: +61 7 3365 2506 email: S.Blomberg1_at_uq.edu.au Policies: 1. I will NOT analyse your data for you. 2. Your deadline is your problem. The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. - John Tukey. -Original Message- From: [EMAIL PROTECTED] on behalf of Felix Zajitschek - UNSW Sent: Thu 20/03/2008 4:51 PM To: r-help@r-project.org Subject: [R] create matrix Hi all, I have a dataset consisting of 5 columns and over 5000 rows. Each row gives information about an individual animal, including longevity, i.e. at what age an animal died. For the model I use I need to create n rows for each animal, n being its longevity, and a new column 'survival' with a binary 0/1 outcome. When an animal died e.g. at age 5, there have to be 5 rows of identical data, except 4 with 0 (=alive) for 'survival', and 1 row with '1' for 'survival'. I thought of creating matrices for each individual, adding first one column 'survival' containing zeros to the original dataset, then creating matrices with data = 'the vector containing all elements of an individual/row' ([1,], nrow = [a,b], exctracting the element for longevity, and then with byrow = TRUE letting the data be filled in by row. At the end I would have to set the last element in 'survival' to '1', and then combine all matrices into one single one. So far I've used Excel to create these datesets manually, but with more than 1000 individuals this gets really tedious. I haven't used R before for this sort of a bit more advanced data manipulation, and I would really appreciate any input/primer about how people would go about doing this. Thanks, Felix __ ::Felix Zajitschek Evolution Ecology Research Centre School of Biological, Earth and Environmental Sciences University of New South Wales - Sydney NSW 2052 - Australia Tel +61 (0)2 9385 8068 Fax +61 (0)2 9385 1558 eMail mailto:[EMAIL PROTECTED] [EMAIL PROTECTED] http://www.bees.unsw.edu.au/school/researchstudents/zajitschekfelix.htm l www.bees.unsw.edu.au/school/researchstudents/zajitschekfelix.html [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] analyzing binomial data with spatially correlated errors
Ben Bolker bolker at ufl.edu writes: Jean-Baptiste Ferdy Jean-Baptiste.Ferdy at univ-montp2.fr writes: Dear R users, I want to explain binomial data by a serie of fixed effects. My problem is that my binomial data are spatially correlated. Naively, I thought I could found something similar to gls to analyze such data. After some reading, I decided that lmer is probably to tool I need. The model I want to fit would look like (...) You could *almost* use glmmPQL from the MASS package, which allows you to fit any lme model structure within a GLM 'wrapper', but as far as I know it wraps only lme ( which requires at least one random effect) and not gls. The trick used in: Dormann, C. F., McPherson, J. M., Araujo, M. B., Bivand, R., Bolliger, J., Carl, G., Davies, R. G., Hirzel, A., Jetz, W., Kissling, W. D., Kühn, I., Ohlemüller, R., Peres-Neto, P. R., Reineking, B., Schröder, B., Schurr, F. M. Wilson, R. J. (2007): Methods to account for spatial autocorrelation in the analysis of species distributional data: a review. Ecography 30: 609–628 (see online supplement), is to add a constant term group, and set random=~1|group. The specific use with a binomial family there is for a (0,1) response, rather than a two-column matrix. You could try gee or geoRglm -- neither trivially easy, I think ... The same paper includes a GEE adaptation, but for a specific spatial configuration rather than a general one. Roger Bivand Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with diff(strptime(...
Prof Brian Ripley wrote: You are throwing away the clue in your use of as.numeric. First. strptime returns a POSIXlt value, which you will convert to POSIXct when you do arithetic (using diff()). Why are you doing that? So foodate-factor(c(1/7/1991,1/8/1991,1/8/1991,3/8/1991)) diff(strptime(foodate,%d/%m/%Y)) Time differences in secs [1] 2678400 0 172800 attr(,tzone) [1] is correct. I think you intended diff(as.Date(foodate,%d/%m/%Y))/365.25 or even add as.numeric() inside diff(). This is true, but I am puzzled as to why I get the correct output except when there are two consecutive input values that are the same. The idea was to get the number of years between each date in order to calculate a rate per year. If I put the as.numeric inside diff: diff(as.numeric(strptime(foodate,%d/%m/%Y))/365.25) Error in Ops.POSIXt(as.numeric(strptime(foodate, %d/%m/%Y)), 365.25) : / not defined for POSIXt objects 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] Rmpi and C Code, where to get the communicator
Hello, I try to write parts of my code in C to accelerate the for-loops. But basic operations I want to do in R (e.g. start cluster). My R code looks something like this: library(Rmpi) mpi.spawn.Rslaves() mpi.remote.exec() dyn.load(test.so) erg - .Call(test, ) mpi.close.Rslaves() mpi.quit() And my C function looks something like this: #include mpi.h #include R.h #include Rdefines.h #include Rinternals.h SEXP test (SEXP a, ..){ int rank; comm ?? MPI_Comm_rank (comm, rank); .. } For all MPI functions I need the right communicator (MPI_Comm *comm;) to communicate with the existing slaves. This variable will be generated by spawning the Rslaves (mpi.spawn.Rslaves). But how to get to this variable in my C function? Is the communicator variable somewhere stored in a R variable? ( I use R 2.6.2 and Rmpi 0.5-5) Thanks Markus -- Dipl.-Tech. Math. Markus Schmidberger Ludwig-Maximilians-Universität München IBE - Institut für medizinische Informationsverarbeitung, Biometrie und Epidemiologie Marchioninistr. 15, D-81377 Muenchen URL: http://ibe.web.med.uni-muenchen.de Mail: Markus.Schmidberger [at] ibe.med.uni-muenchen.de Tel: +49 (089) 7095 - 4599 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] analyzing binomial data with spatially correlated errors
Roger Bivand wrote: Ben Bolker bolker at ufl.edu writes: Jean-Baptiste Ferdy Jean-Baptiste.Ferdy at univ-montp2.fr writes: Dear R users, I want to explain binomial data by a serie of fixed effects. My problem is that my binomial data are spatially correlated. Naively, I thought I could found something similar to gls to analyze such data. After some reading, I decided that lmer is probably to tool I need. The model I want to fit would look like (...) You could *almost* use glmmPQL from the MASS package, which allows you to fit any lme model structure within a GLM 'wrapper', but as far as I know it wraps only lme ( which requires at least one random effect) and not gls. The trick used in: Dormann, C. F., McPherson, J. M., Araujo, M. B., Bivand, R., Bolliger, J., Carl, G., Davies, R. G., Hirzel, A., Jetz, W., Kissling, W. D., Kühn, I., Ohlemüller, R., Peres-Neto, P. R., Reineking, B., Schröder, B., Schurr, F. M. Wilson, R. J. (2007): Methods to account for spatial autocorrelation in the analysis of species distributional data: a review. Ecography 30: 609–628 (see online supplement), is to add a constant term group, and set random=~1|group. The specific use with a binomial family there is for a (0,1) response, rather than a two-column matrix. You could try gee or geoRglm -- neither trivially easy, I think ... The same paper includes a GEE adaptation, but for a specific spatial configuration rather than a general one. Roger Bivand Ben Bolker I suggest you also check out the package geoRglm, where you can model binomial and Poisson spatially correlated data. I used it to model spatially correlated binomial data but without covariates, i.e. without your fixed effects (so my model was a logistic regression with the intercept only) (Reference below). But I understand that you can add covariates and use them to estimate the non-random set of predictors. Here is the geoRglm webpage: http://www.daimi.au.dk/~olefc/geoRglm/ This approach would be like tackling the problem from the point of view of geostatistics, rather than from mixed models. But I believe the likelihood-based geostatistical model is the same as a generalized linear mixed model where the distance is the random effect. In SAS you can do this using the macro glimmix but from the point of view of generalized linear mixed models because there they have implemented a correlation term, so that you can identify typical spatial correlation functions such as Gauss and exponential, particular cases of the Matern family. Rubén Roa-Ureta, R. and E.N. Niklitschek (2007) Biomass estimation from surveys with likelihood-based geostatistics. ICES Journal of Marine Science 64:1723-1734 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] analyzing binomial data with spatially correlated errors
On Wed, Mar 19, 2008 at 3:02 PM, Ben Bolker [EMAIL PROTECTED] wrote: Jean-Baptiste Ferdy Jean-Baptiste.Ferdy at univ-montp2.fr writes: Dear R users, I want to explain binomial data by a serie of fixed effects. My problem is that my binomial data are spatially correlated. Naively, I thought I could found something similar to gls to analyze such data. After some reading, I decided that lmer is probably to tool I need. The model I want to fit would look like lmer ( cbind(n.success,n.failure) ~ (x1 + x2 + ... + xn)^2 , family=binomial, correlation=corExp(1,form=~longitude+latitude)) This doesn't work because lmer says it needs a random effect in the model. And, apart from the spatial random effect that I want to capture by computing the correlation matrix, I have no other random effect. There must be something I do not understand here... I can't get why gls can do this on gaussian data but lmer can't on binomial ones. This is a hard problem. The proximal issue is that lmer does not yet include a correlation term (I'm a little surprised you didn't get an error to that effect), and won't for some time since it is still in heavy development for more basic features. The lmer function does have a ... argument that will swallow up the correlation argument (and proceed to ignore it). I think there are advantages to including a ... argument but one of the disadvantages is this quietly ignoring arguments that are not defined in the function (and are not mentioned in any documentation about the function). If your data were normal you could use gls from the nlme package, but nlme doesn't do generalized LMMs (only LMMs and NLMMs). You could *almost* use glmmPQL from the MASS package, which allows you to fit any lme model structure within a GLM 'wrapper', but as far as I know it wraps only lme ( which requires at least one random effect) and not gls. I don't think it is at all trivial to define a model for a binary or binomial response with a spatial correlation structure. It may be well-known; it's just that I don't know how to do it easily. I just saw the post by Roger Bivand who gave a reference on one approach (although usually when one finds oneself using something like a group factor with only one level to define the random effects it is a sign that something suspicious is underway. Expecting to estimate a variance from a single observation should raise a few red flags.) The way Jose and I approached correlation structures in lme is to pre-whiten the data and the model matrices, conditional on the parameters that determine the (additional) marginal correlation of the responses. That works when the conditional distribution of the response is normal. I don't see how it could work for a binary or binomial response. A linear combination of normals is normal. A non-trivial linear combination of binomials is not binomial. In writing lmer I have found that I must think about the model very carefully before I can determine a suitable computational method. I spent most of the month of January staring at a sequence of transformations on the whiteboard in my office trying to determine what should go where and how to implement the whole chain in data structures and algorithms. The normal distribution and linear predictors fit together in such a way that one can factor out correlation structures or variance functions. Get away from the normal distribution and things start to break. Think of the typical way in which we write a linear model: y = X b + e where y is an n-dimensional response, X is an n by p model matrix, b is a p-dimensional coefficient vector to be estimated and e is the noise term with a multivariate normal distribution that has mean 0. Now, try to write a generalized linear model that way. It doesn't work. You must express a GLM differently, relating the mean to the liner predictor, and taking into account the way the variance relates to the mean. This is more than a notational difference. In a linear model the effect of b is limited to the linear predictor and, through that, the mean. The variance-covariance specification can be separated from the mean and, hence, can be specified separately. It is easy to fool yourself into thinking that the same should be true for generalized linear models, just like it is easy to fool yourself into thinking that all the arguments for the lme function will work unchanged in lmer. You could try gee or geoRglm -- neither trivially easy, I think ... Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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
Re: [R] Smoothing z-values according to their x, y positions
Emmanuel Levy [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: Dear David, Thanks a lot for pointing out kde2d, just tried it out but the problem is that it indeed takes the density of points into account, which I dont want. For example, if in an region of surface S I've got 10,000 points, and that their average height is 0.5, and in an other region I've got only ten points and their average value if also 0.5, I'd like all these points to be transformed to the same 0.5 value. At the moment, it seems that it's not the case. For example, the range of the values I give is: 0.2 - 3.7, but the range of the values that are outputed is 0 - 0.17. Emmanuel Levy [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: Dear Bert, Thanks for your reply - I indeed saw a lot of functions using: help.search(smooth) The problem is that most seem to not be very appropriate to what I'd like, or they seem extremely complicated (e.g. gma). I am probably missing something as I don't see how to use Loess. From my poor understanding, it seems to be for 2D data. Here I want to smooth the third z component. Your description of what is desired leads me to believe you were misreading the loess documentation. For proof I suggest you visit Deepayan Sarkar's webpage and in particular see Figure 6.8 where 3d plots of loess fits for more complex data arrangements are exemplified: Choose Figure 6.8 (code on right side of window): http://lmdvr.r-forge.r-project.org/figures/figures.html Code: http://dsarkar.fhcrc.org/lattice/book/Chapter06-Trivariate/all.R PNG image: http://dsarkar.fhcrc.org/lattice/book/images/Figure_06_08_stdClassic.png -- David Winsemius __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] coxme - bug / error
Hello everyone, Many thanks to Terry Therneau for giving me a solution for my previous problem re coxme function. Now, I am using a bigger dataset to fit the same model; random treatment effect nested within centre. I used the command coxme(Surv(time, status) ~ factor(treat), data=data1, random = ~1 | centre/treat) But as soon as I entered this command, R dies with an error message R for windows GUI front-end has encountered a problem and need to close . I am using R in Windows, R version is 2.6.0. Has anyone ever had this type of error? Thanks for any help. Ruwanthi __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] comparing length-weight regressions]
[EMAIL PROTECTED] wrote: I'd like to compare length-weight regressions among years. Any information would be appreciated. a. gray fisheries consultant Your message is rather cryptic for a general statistical audience, whereas I'm sure in a fisheries group everybody would understand what you want. Use a glm with family=Gaussian(link=log) for all data sets together (in original units) with year as a factor, then run the model again ignoring the year factor, and compare the different fits using anova(name of your glm objects) for a likelihood ratio test, or inspect the AICs for a non-frequentist model selection method. R. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] ggplot - axis labels angle
dear R-tists, im an struggling with labeling ticks of the axis in a ggplot. i would like to print the text associated with the ticks being ploted with a 90 degree angle. how can i possibly do this? cheers. bernd. ~ Bernd Ebersberger Management Center Innsbruck, Austria [[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] Break up a data frame
Ravi S. Shankar [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: Hi R users, I have a dataframe in the below format xyz 01/03/200715.25USD xyz 01/04/200715.32USD xyz 01/02/200823.22USD abc 01/03/200745.2 EUR abc 01/04/200745.00EUR abc 01/02/200868.33EUR I want to change the above data into the below format xyz 01/03/200715.25USD abc 01/03/200745.2 EUR xyz 01/04/200715.32USD abc 01/04/200745.00EUR xyz 01/02/200823.22USD abc 01/02/200868.33EUR Seeing what appeared to be wordwrap, I interpreted your request as asking for display of xyz rows adjacent to abc rows. If that is the case, then this seems to work for the toy example: xz - read.table(clipboard) xz V1 V2V3 V4 1 xyz 01/03/2007 15.25 USD 2 xyz 01/04/2007 15.32 USD 3 xyz 01/02/2008 23.22 USD 4 abc 01/03/2007 45.20 EUR 5 abc 01/04/2007 45.00 EUR 6 abc 01/02/2008 68.33 EUR cbind(xz[xz$V1==xyz,],xz[xz$V1==abc,]) V1 V2V3 V4 V1 V2V3 V4 1 xyz 01/03/2007 15.25 USD abc 01/03/2007 45.20 EUR 2 xyz 01/04/2007 15.32 USD abc 01/04/2007 45.00 EUR 3 xyz 01/02/2008 23.22 USD abc 01/02/2008 68.33 EUR If it was instead a request for USD next to EUR, then the needed modifications should be obvious. -- David Winsemius __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rmpi and C Code, where to get the communicator
Hello, I try to write parts of my code in C to accelerate the for-loops. But basic operations I want to do in R (e.g. start cluster). My R code looks something like this: library(Rmpi) mpi.spawn.Rslaves() mpi.remote.exec() dyn.load(test.so) erg - .Call(test, ) mpi.close.Rslaves() mpi.quit() And my C function looks something like this: #include mpi.h #include R.h #include Rdefines.h #include Rinternals.h SEXP test (SEXP a, ..){ int rank; comm ?? MPI_Comm_rank (comm, rank); .. } For all MPI functions I need the right communicator (MPI_Comm *comm;) to communicate with the existing slaves. This variable will be generated by spawning the Rslaves (mpi.spawn.Rslaves). But how to get to this variable in my C function? Is the communicator variable somewhere stored in a R variable? ( I use R 2.6.2 and Rmpi 0.5-5) Thanks Markus -- Dipl.-Tech. Math. Markus Schmidberger Ludwig-Maximilians-Universität München IBE - Institut für medizinische Informationsverarbeitung, Biometrie und Epidemiologie Marchioninistr. 15, D-81377 Muenchen URL: http://ibe.web.med.uni-muenchen.de Mail: Markus.Schmidberger [at] ibe.med.uni-muenchen.de Tel: +49 (089) 7095 - 4599 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] analyzing binomial data with spatially correlated errors
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Douglas Bates wrote: | On Wed, Mar 19, 2008 at 3:02 PM, Ben Bolker [EMAIL PROTECTED] wrote: | Jean-Baptiste Ferdy Jean-Baptiste.Ferdy at univ-montp2.fr writes: | | | Dear R users, | | I want to explain binomial data by a serie of fixed effects. My problem is | that my binomial data are spatially correlated. Naively, I thought I could | found something similar to gls to analyze such data. After some reading, I | decided that lmer is probably to tool I need. The model I want to fit would | look like | | lmer ( cbind(n.success,n.failure) ~ (x1 + x2 + ... + xn)^2 , family=binomial, | correlation=corExp(1,form=~longitude+latitude)) | | This is more than a notational difference. In a linear model the | effect of b is limited to the linear predictor and, through that, the | mean. The variance-covariance specification can be separated from the | mean and, hence, can be specified separately. It is easy to fool | yourself into thinking that the same should be true for generalized | linear models, just like it is easy to fool yourself into thinking | that all the arguments for the lme function will work unchanged in | lmer. ~ Fair enough. I guess the model I was thinking of was ~ Y ~ Binomial(p,N) ~ logit(p) ~ MVN(mu,Sigma) ~ mu = (determined by model matrix and predictors) ~ Sigma = (exponential spatial correlation matrix)*sigma^2 ~ This model is certainly different from the model that the original poster may have been thinking of, because in the limit where there is no extra-binomial variation, there can't be any correlation either. On the other hand, it seems to be a sensible model. ~ cheers ~Ben Bolker -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFH4m/zc5UpGjwzenMRAi02AJ9UNy8WsUkN8hVI5ih1yOLxtQn3TwCfeovt Q1iOmczhkWqi4d4VeZDcylo= =Mr7v -END PGP SIGNATURE- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Use of Factors
Relatively new to R, I'm trying to do a relatively simple task. I have data set that has several variables arranged by SubjID and visit, with multiple observations for that combination. I do linear regression on those multiple observations, then generated a set of interpolated values from the regression at fixed intervals along x. I now want to average each of those across all the SubjID's. When I use either by() or tapply(), I get an error indicating the interpolated values are factors, even though they display looking like floating point numbers. The mean function returns a value that is obviously wrong, though the count of observations in the subsets is correct. I am including code snippets to try to demostrate how this is all created:, sorry for the length of this Here is output when I try to use the mean function, mean_interp_HR=tapply(cpx_interp$HR[cpx_interp$visit==1 cpx_interp$xl==0],cpx_interp$SubjId[cpx_interp$visit==1 cpx_interp$xl==0],mean) Warning in mean.default(X[[1L]], ...) : argument is not numeric or logical: returning NA Warning in mean.default(X[[2L]], ...) : argument is not numeric or logical: returning NA Warning in mean.default(X[[3L]], ...) : argument is not numeric or logical: returning NA Warning in mean.default(X[[4L]], ...) : argument is not numeric or logical: returning NA Warning in mean.default(X[[5L]], ...) : argument is not numeric or logical: returning NA Look at the data I am submitting to tapply and mean: cpx_interp$HR[cpx_interp$visit==1 cpx_interp$xl==0] [1] 62.5252140470478 67.6151493460742 68.3931063786315 78.6591518601803 59.7674671000443 90 Levels: 62.5252140470478 66.046907240618 69.5686004341883 69.8766646005142 71.9631282463843 ... 85.4270562298357 cpx_interp$SubjId[cpx_interp$visit==1 cpx_interp$xl==0] [1] ADENPV07 ADENPVJN ADENPV0Z ADENPVM9 ADENPVMB Levels: ADENPV07 ADENPVJN ADENPV0Z ADENPVM9 ADENPVMB Why is the $HR variable listed as 90 levels as if it is a factor? Why is it not treated as floating point to get simple mean? Here is how the HR values are generated: # create the array interp_out=array(,c(18,length(cols2))) # create the values to interpolate to interp_out[,3]=c(0,25,50,75,100,125,150,175,200,0,25,50,75,100,125,150,1 75,200); # fill the visits interp_out[,2]=c(1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2) # fill the SubjID interp_out[,1]=SubjID; Now fill in interplated values for each visit. interp_out[1:9,4]=hrv1;interp_out[10:18,4]=hrv2; # hrv1 hrv2 come from the following function, the lm parameter is output from the standard lm() function: interpolateToXL = function(lm,maxxl){ int_values=matrix(nrow=9,ncol=1) int_values[1,]=coef(lm)[1]; if (maxxl25) int_values[2,]=coef(lm)[1]+coef(lm)[2] * 25 if (maxxl50) int_values[3,]=coef(lm)[1]+coef(lm)[2] * 50 if (maxxl75) int_values[4,]=coef(lm)[1]+coef(lm)[2] * 75 if (maxxl100) int_values[5,]=coef(lm)[1]+coef(lm)[2] * 100 if (maxxl125) int_values[6,]=coef(lm)[1]+coef(lm)[2] * 125 if (maxxl150) int_values[7,]=coef(lm)[1]+coef(lm)[2] * 150 if (maxxl175) int_values[8,]=coef(lm)[1]+coef(lm)[2] * 175 if (maxxl200) int_values[9,]=coef(lm)[1]+coef(lm)[2] * 200 return (int_values) } Ken Beck PhD Research Scientist Boston Scientific CRM (Guidant) 10-212 [EMAIL PROTECTED] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] little subplot in corner
I want to draw a little subplot (overview) into my detailed plot. It should be placed in say the top right corner and have the size of some legend (like legend(x=topright, inset=0.03, ...) #main plot plot(rnorm(100)) #give little density in corner plot(seq(-2,2,length=300),dnorm(seq(-2,2,length=300)),type=l) I don't want something like par(mfrow=c(1,2)) as this gives subplots of equal size. I saw that gridBase is very flexible, but could not find a suitable example. Thanks for help, Thomas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Installation of R, Sweave, ESS and [X]Emacs on Windows?
I'm trying to get R, Sweave, ESS and XEmacs or emacs all installed and working together on my Windows XP Pro system. I've got R 2.6.0 working just fine, installed from the R Windows installer. I also have CYGWIN_NT-5.1 with XEmacs 21.4 working okay. Can anyone point me to any documentation on how to bring these together so that R code typed in Xemacs can be run in R? I found the ESS installation directions here at http://ess.r-project.org/Manual/ess.html#Microsoft-Windows-installation but they seem daunting. I'm not sure that Xemacs from cygwin can work with R installed alone. Can anyone confirm that I just have to follow these directions to have everything I want? Thank you all for your help and advice. -Kevin Kevin Zembower Internet Services Group manager Center for Communication Programs Bloomberg School of Public Health Johns Hopkins University 111 Market Place, Suite 310 Baltimore, Maryland 21202 410-659-6139 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Fwd: time series regression
Hi Everyone, I am trying to do a time series regression using the lm function. However, according to the durbin watson test the errors are autocorrelated. And then I tried to use the gls function to accomodate for the autocorrelated errors. My question is how do I know what ARMA process (order) to use in the gls function? Or is there any other way to do the time series regression in R? I highly appreciate your help. Thanks, Bereket [[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] Fwd: time series regression
Hi Everyone, One more information to my question. I am trying to do a time series regression using the lm function. *My intention is to investigate the relationship between a dependent time series variable and several independent time series variables.* According to the durbin watson test the errors are autocorrelated. And then I tried to use the gls function to accomodate for the autocorrelated errors. My question is how do I know what ARMA process (order) to use in the gls function? Or is there any other way to do the time series regression in R? I highly appreciate your help. Thanks, Bereket [[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] Installation of R, Sweave, ESS and [X]Emacs on Windows?
Hi Kevin, Go here: http://vgoulet.act.ulaval.ca/en/ressources/emacs/ and get Vincent Goulet's Emacs for Windows. Not sure how cygwin enters into the picture; you don't need it for either R, [X]Emacs, nor ESS. In fact, if you ever plan to build packages on Windows having cygwin installed can be an impediment. Best, Jim Zembower, Kevin wrote: I'm trying to get R, Sweave, ESS and XEmacs or emacs all installed and working together on my Windows XP Pro system. I've got R 2.6.0 working just fine, installed from the R Windows installer. I also have CYGWIN_NT-5.1 with XEmacs 21.4 working okay. Can anyone point me to any documentation on how to bring these together so that R code typed in Xemacs can be run in R? I found the ESS installation directions here at http://ess.r-project.org/Manual/ess.html#Microsoft-Windows-installation but they seem daunting. I'm not sure that Xemacs from cygwin can work with R installed alone. Can anyone confirm that I just have to follow these directions to have everything I want? Thank you all for your help and advice. -Kevin Kevin Zembower Internet Services Group manager Center for Communication Programs Bloomberg School of Public Health Johns Hopkins University 111 Market Place, Suite 310 Baltimore, Maryland 21202 410-659-6139 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- James W. MacDonald, M.S. Biostatistician Affymetrix and cDNA Microarray Core University of Michigan Cancer Center 1500 E. Medical Center Drive 7410 CCGC Ann Arbor MI 48109 734-647-5623 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Installation of R, Sweave, ESS and [X]Emacs on Windows?
Kevin, Save yourself a lot of trouble and use my modified version of GNU Emacs available from http://vgoulet.act.ulaval.ca/en/emacs and also linked from the ESS home page. It comes bundled with ESS and AUCTeX, so the only other thing you will need to install for the purposes you mention is R itself (upgrade while you're at it, you're two versions behind) and a TeX distribution (consider TeX Live or MiKTeX). There is no need for Cygwin with this setup. Hope this helps --- Vincent Goulet, Associate Professor École d'actuariat Université Laval, Québec [EMAIL PROTECTED] http://vgoulet.act.ulaval.ca Le jeu. 20 mars à 11:34, Zembower, Kevin a écrit : I'm trying to get R, Sweave, ESS and XEmacs or emacs all installed and working together on my Windows XP Pro system. I've got R 2.6.0 working just fine, installed from the R Windows installer. I also have CYGWIN_NT-5.1 with XEmacs 21.4 working okay. Can anyone point me to any documentation on how to bring these together so that R code typed in Xemacs can be run in R? I found the ESS installation directions here at http://ess.r-project.org/Manual/ess.html#Microsoft-Windows- installation but they seem daunting. I'm not sure that Xemacs from cygwin can work with R installed alone. Can anyone confirm that I just have to follow these directions to have everything I want? Thank you all for your help and advice. -Kevin Kevin Zembower Internet Services Group manager Center for Communication Programs Bloomberg School of Public Health Johns Hopkins University 111 Market Place, Suite 310 Baltimore, Maryland 21202 410-659-6139 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rmpi and C Code, where to get the communicator
Hi Markus -- Usually comm is an argument with default value in the mpi.* functions, so implicitly the user is managing these, e.g., by default, using comm 1. Presumably you'll have an R wrapper to .Call that has a default argument comm=1, and will passs this to the C level. Martin Markus Schmidberger wrote: Hello, I try to write parts of my code in C to accelerate the for-loops. But basic operations I want to do in R (e.g. start cluster). My R code looks something like this: library(Rmpi) mpi.spawn.Rslaves() mpi.remote.exec() dyn.load(test.so) erg - .Call(test, ) mpi.close.Rslaves() mpi.quit() And my C function looks something like this: #include mpi.h #include R.h #include Rdefines.h #include Rinternals.h SEXP test (SEXP a, ..){ int rank; comm ?? MPI_Comm_rank (comm, rank); .. } For all MPI functions I need the right communicator (MPI_Comm *comm;) to communicate with the existing slaves. This variable will be generated by spawning the Rslaves (mpi.spawn.Rslaves). But how to get to this variable in my C function? Is the communicator variable somewhere stored in a R variable? ( I use R 2.6.2 and Rmpi 0.5-5) Thanks Markus -- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M2 B169 Phone: (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.
Re: [R] Installation of R, Sweave, ESS and [X]Emacs on Windows?
Jim and Vincent, thank you both so much. Vincent, I really appreciate the time and effort you've put into this project. I was hoping for exactly what you've provide. Thanks, again. -Kevin -Original Message- From: Vincent Goulet [mailto:[EMAIL PROTECTED] Sent: Thursday, March 20, 2008 12:02 PM To: Zembower, Kevin Cc: [EMAIL PROTECTED] Subject: Re: [R] Installation of R, Sweave, ESS and [X]Emacs on Windows? Kevin, Save yourself a lot of trouble and use my modified version of GNU Emacs available from http://vgoulet.act.ulaval.ca/en/emacs and also linked from the ESS home page. It comes bundled with ESS and AUCTeX, so the only other thing you will need to install for the purposes you mention is R itself (upgrade while you're at it, you're two versions behind) and a TeX distribution (consider TeX Live or MiKTeX). There is no need for Cygwin with this setup. Hope this helps --- Vincent Goulet, Associate Professor École d'actuariat Université Laval, Québec [EMAIL PROTECTED] http://vgoulet.act.ulaval.ca Le jeu. 20 mars à 11:34, Zembower, Kevin a écrit : I'm trying to get R, Sweave, ESS and XEmacs or emacs all installed and working together on my Windows XP Pro system. I've got R 2.6.0 working just fine, installed from the R Windows installer. I also have CYGWIN_NT-5.1 with XEmacs 21.4 working okay. Can anyone point me to any documentation on how to bring these together so that R code typed in Xemacs can be run in R? I found the ESS installation directions here at http://ess.r-project.org/Manual/ess.html#Microsoft-Windows- installation but they seem daunting. I'm not sure that Xemacs from cygwin can work with R installed alone. Can anyone confirm that I just have to follow these directions to have everything I want? Thank you all for your help and advice. -Kevin Kevin Zembower Internet Services Group manager Center for Communication Programs Bloomberg School of Public Health Johns Hopkins University 111 Market Place, Suite 310 Baltimore, Maryland 21202 410-659-6139 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Fwd: time series regression
Your entering into a complex danger zone here because you really need to check first if all the dependent and independent variables are stationary. Otherwise, your lm results are meaningless ( you're estimation a spurious regression ). I would look at Bernhard Pfaff's yellow book or any other decent time series econometrics text ( hayashi, hamilton ) for more on this topic. It's a quite complex problem you are working on so you need to get familiar with the cointegration/unit root concepts, if you aren't already. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of bereket weldeslassie Sent: Thursday, March 20, 2008 11:54 AM To: [EMAIL PROTECTED]; r-help@r-project.org Subject: [R] Fwd: time series regression Hi Everyone, One more information to my question. I am trying to do a time series regression using the lm function. *My intention is to investigate the relationship between a dependent time series variable and several independent time series variables.* According to the durbin watson test the errors are autocorrelated. And then I tried to use the gls function to accomodate for the autocorrelated errors. My question is how do I know what ARMA process (order) to use in the gls function? Or is there any other way to do the time series regression in R? I highly appreciate your help. Thanks, Bereket [[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] Fwd: time series regression
bereket weldeslassie wrote: Hi Everyone, One more information to my question. I am trying to do a time series regression using the lm function. *My intention is to investigate the relationship between a dependent time series variable and several independent time series variables.* According to the durbin watson test the errors are autocorrelated. And then I tried to use the gls function to accomodate for the autocorrelated errors. My question is how do I know what ARMA process (order) to use in the gls function? Or is there any other way to do the time series regression in R? I highly appreciate your help. Thanks, Bereket [[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. Hi, Temporal autocorrelation seems to be a contagious process... even for emails. I received yours three times in 5 minutes. Concerning your question, I am no expert in time series, but you may also try ordinary least squares after 'removing' autocorrelation. This can be achieved by regression onto a lagged variable (see lag.listw in spdep, which can also be applied to temporal context), or onto eigenvectors of a temporal proximity matrix. Cheers, Thibaut. -- ## Thibaut JOMBART CNRS UMR 5558 - Laboratoire de Biométrie et Biologie Evolutive Universite Lyon 1 43 bd du 11 novembre 1918 69622 Villeurbanne Cedex Tél. : 04.72.43.29.35 Fax : 04.72.43.13.88 [EMAIL PROTECTED] http://lbbe.univ-lyon1.fr/-Jombart-Thibaut-.html?lang=en http://adegenet.r-forge.r-project.org/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] conditional matching of rows of tables
Not exactly clear on the transformation that you want to do. In your example, '1 2 3 - a', where does the '2 3' come from since I don't see a value of 2 in the 3rd 4th columns. So a better explanation of what you are trying to do would be help and show where the values came from in each case. On 3/20/08, Ng Stanley [EMAIL PROTECTED] wrote: Hi, Given matrix A of 4 cols. 1 a 0 4 1 b 5 8 2 a 0 3 2 b 4 7 I have another matrix B of 3 cols. How to assign (a or b) to the rows such that in each row its 1st value must match the 1st col. of A, 2nd and 3rd values must lie between 3rd and 4rd cols (inclusive) of A 1 2 3 - a 2 4 5 - b 2 0 3 - a 1 7 8 - b [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Fwd: time series regression
Use the arima function with the xreg option that is a vector or matrix of external regressors. Use AIC or BIC when identifying the error process. Hannu On Thu, Mar 20, 2008 at 5:54 PM, bereket weldeslassie [EMAIL PROTECTED] wrote: Hi Everyone, One more information to my question. I am trying to do a time series regression using the lm function. *My intention is to investigate the relationship between a dependent time series variable and several independent time series variables.* According to the durbin watson test the errors are autocorrelated. And then I tried to use the gls function to accomodate for the autocorrelated errors. My question is how do I know what ARMA process (order) to use in the gls function? Or is there any other way to do the time series regression in R? I highly appreciate your help. Thanks, Bereket [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] I need help integrating ggplot2 into Excel
Dear all I use ggplot2 extensively for my plotting routines and rexcel to have the best of two worlds. (RExcel v 1.75 and R (D)Com v. 2.5) I can run my ggplot functions, such as qplot(...), in scratchpad mode, but not in Macro nor Worksheet functions mode. I have tried the following in Macro mode: Call RInterface.RRun(library(ggplot2)) ... Call RInterface.RRun(qplot(x=Hours,y=pH,data=ds,facets=Sample~.,geom=line,group=Cell)) With no output ... I have tried the following in Worksheet function mode: if Range(H40:I42) contains: (Embedded image moved to file: pic10654.jpg) and Range(H48) contains: qplot The following call: =Rcalla(H48;makeargs(H40:I42)) Gives me no output Scratchpad mode However, right clicking a cell containing: qplot(x=Hours,y=pH,data=ds,facets=Sample~.,geom=line,group=Cell) and then selecting Run R works like a dream! I would like to develop an excel based GUI for R-data treatment and plotting, and I would like to use ggplot2 as my plotting engine. What am I doing wrong? Thank you for your help Jannik Vindeløv, Ph.D. Project Manager Dairy Culture Development Innovation P.O. Box 64 Arpajon Cedex F-91292 France Phone: +33 (0)1 6988 3636 Direct Phone: +33 (0)1 6988 3629__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] time series regression
Hi Everyone, I am trying to do a time series regression using the lm function. However, according to the durbin watson test the errors are autocorrelated. And then I tried to use the gls function to accomodate for the autocorrelated errors. My question is how do I know what ARMA process (order) to use in the gls function? Or is there any other way to do the time series regression in R? I highly appreciate your help. Thanks, Bereket [[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] minimum distances
Hi, I have a question about computing shortest Euclidean distances between two data frames of spatial points... I have 2 dataframes (not yet converted to spatial class) Sewers-data.frame(x=c(10,20,35,50),y=c(100,150,200,300)) transect - data.frame(x=seq(from=0, to=50, by=1),y=seq(from=100, to=150, by=1)) I would like to be able to compute the shortest distance from the transect points the nearest sewer (Euclidean distance) I've tried a number of different loops, but so far ave had no luck. Any help would be appreciated __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] little subplot in corner
I don't if is this what you want, but: plot(rnorm(100)) par(fig=c(0, 1/2, 0, 1/2), new=T) plot(seq(-2,2,length=300),dnorm(seq(-2,2,length=300)),type=l, axes = F, xlab=, ylab=) On 20/03/2008, Thomas Steiner [EMAIL PROTECTED] wrote: I want to draw a little subplot (overview) into my detailed plot. It should be placed in say the top right corner and have the size of some legend (like legend(x=topright, inset=0.03, ...) #main plot plot(rnorm(100)) #give little density in corner plot(seq(-2,2,length=300),dnorm(seq(-2,2,length=300)),type=l) I don't want something like par(mfrow=c(1,2)) as this gives subplots of equal size. I saw that gridBase is very flexible, but could not find a suitable example. Thanks for help, Thomas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] little subplot in corner
perfect, exactly what I was looking for. Thanks a lot! many eggs to you... Thomas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] logLik calculations
Does the logLik function applied to a glm and glm.nb (from MASS package) calculate the complete log-likelihoods, or does it drop the constant terms of the equation? (Its not clear from the associated help pages, and Ive found no reference from searching the R help mailing list) Thank you, Kelly Young __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] minimum distances
Dave Depew ddepew at sciborg.uwaterloo.ca writes: Hi, I have a question about computing shortest Euclidean distances between two data frames of spatial points... I have 2 dataframes (not yet converted to spatial class) Sewers-data.frame(x=c(10,20,35,50),y=c(100,150,200,300)) transect - data.frame(x=seq(from=0, to=50, by=1),y=seq(from=100, to=150, by=1)) I would like to be able to compute the shortest distance from the transect points the nearest sewer (Euclidean distance) I've tried a number of different loops, but so far ave had no luck. Any help would be appreciated Sewers-data.frame(x=c(10,20,35,50),y=c(100,150,200,300)) transect - data.frame(x=0:50,y=100:150) dist - sqrt((outer(Sewers$x,transect$x,-))^2+ (outer(Sewers$y,transect$y,-))^2) mindist = apply(dist,2,min) closest = apply(dist,2,which.min) library(MASS) eqscplot(Sewers,pch=16,col=1:4) points(transect,col=closest) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] I need help integrating ggplot2 into Excel
I expect that this is the same as FAQ 7.22, though the FAQ should probably be updated to include ggplot as well as lattice/trellis. Basically you need to print the graph (in some modes it is automatically printed, so you see it, in other modes it is not autoprinted, so you see nothing), just wrap the calls in print() commands. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jannik Vindeloev Sent: Thursday, March 20, 2008 8:16 AM To: r-help@r-project.org Subject: [R] I need help integrating ggplot2 into Excel Dear all I use ggplot2 extensively for my plotting routines and rexcel to have the best of two worlds. (RExcel v 1.75 and R (D)Com v. 2.5) I can run my ggplot functions, such as qplot(...), in scratchpad mode, but not in Macro nor Worksheet functions mode. I have tried the following in Macro mode: Call RInterface.RRun(library(ggplot2)) ... Call RInterface.RRun(qplot(x=Hours,y=pH,data=ds,facets=Sample~.,ge om=line,group=Cell)) With no output ... I have tried the following in Worksheet function mode: if Range(H40:I42) contains: (Embedded image moved to file: pic10654.jpg) and Range(H48) contains: qplot The following call: =Rcalla(H48;makeargs(H40:I42)) Gives me no output Scratchpad mode However, right clicking a cell containing: qplot(x=Hours,y=pH,data=ds,facets=Sample~.,geom=line,group=Cell) and then selecting Run R works like a dream! I would like to develop an excel based GUI for R-data treatment and plotting, and I would like to use ggplot2 as my plotting engine. What am I doing wrong? Thank you for your help Jannik Vindeløv, Ph.D. Project Manager Dairy Culture Development Innovation P.O. Box 64 Arpajon Cedex F-91292 France Phone: +33 (0)1 6988 3636 Direct Phone: +33 (0)1 6988 3629 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] little subplot in corner
Look at the subplot function in the TeachingDemos package (the cnvrt.coords function in the same package can be used to help in finding coordinates to place the plot). Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Thomas Steiner Sent: Thursday, March 20, 2008 9:04 AM To: [EMAIL PROTECTED] Subject: [R] little subplot in corner I want to draw a little subplot (overview) into my detailed plot. It should be placed in say the top right corner and have the size of some legend (like legend(x=topright, inset=0.03, ...) #main plot plot(rnorm(100)) #give little density in corner plot(seq(-2,2,length=300),dnorm(seq(-2,2,length=300)),type=l) I don't want something like par(mfrow=c(1,2)) as this gives subplots of equal size. I saw that gridBase is very flexible, but could not find a suitable example. Thanks for help, Thomas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Interpretation of Variance decomposition in VAR model
Hi all, This question is not really R related, rather on Statistics subject itself. Even I did not do those using R. however still I want to post it here, because my hope is I could get help from great statisticians who are the very active member of this group. My problem is to interpret Variance decomposition of VAR model in layman's language. Using EViews I got following : Variance Decomposition of LN_FU: Period S.E.LN_SPOT LN_FU 1 0.02442293.669596.330413 2 0.03483894.365065.634938 3 0.04228094.607125.392882 4 0.04854094.307255.692747 5 0.05406093.990396.009611 6 0.05904293.675456.324554 7 0.06362193.334056.665951 8 0.06788592.993477.006529 9 0.07189392.659667.340337 10 0.07568792.332667.667341 Variance Decomposition of LN_SPOT: Period S.E.LN_SPOT LN_FU 1 0.023745100.0.00 2 0.03374199.511220.488785 3 0.04101899.253390.746605 4 0.04720498.983541.016462 5 0.05266098.624011.375990 6 0.05760098.249851.750151 7 0.06215597.863032.136970 8 0.06640097.461972.538034 9 0.07039497.056552.943451 10 0.07417696.651023.348978 Cholesky Ordering: LN_SPOT LN_FU Myquestion is How to interpret those result in layman language? If I sayfollowing : 93.66959% of tomorrow's volatility in LN_FU is explainedby LN_SPOT's today volatility and remaining 6.330413% is explained byit's today's Volatility, is this statement correct? Then what will bethe interpretation of remaining numbers like : 94.36506,5.634938,..etc? And also What could be the interpretation of the SE in layman's term? I already gone through Eviews help file however, did not get anything. If u people here help me on this regard, I will be very very grateful. Regards, Send instant messages to your online friends http://uk.messenger.yahoo.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Interpretation of Variance decomposition in VAR model
Hi all, This question is not really R related, rather on Statistics subject itself. Even I did not do those using R. however still I want to post it here, because my hope is I could get help from great statisticians who are the very active member of this group. My problem is to interpret Variance decomposition of VAR model in layman's language. Using EViews I got following : Variance Decomposition of LN_FU: Period S.E.LN_SPOT LN_FU 1 0.02442293.669596.330413 2 0.03483894.365065.634938 3 0.04228094.607125.392882 4 0.04854094.307255.692747 5 0.05406093.990396.009611 6 0.05904293.675456.324554 7 0.06362193.334056.665951 8 0.06788592.993477.006529 9 0.07189392.659667.340337 10 0.07568792.332667.667341 Variance Decomposition of LN_SPOT: Period S.E.LN_SPOT LN_FU 1 0.023745100.0.00 2 0.03374199.511220.488785 3 0.04101899.253390.746605 4 0.04720498.983541.016462 5 0.05266098.624011.375990 6 0.05760098.249851.750151 7 0.06215597.863032.136970 8 0.06640097.461972.538034 9 0.07039497.056552.943451 10 0.07417696.651023.348978 Cholesky Ordering: LN_SPOT LN_FU Myquestion is How to interpret those result in layman language? If I sayfollowing : 93.66959% of tomorrow's volatility in LN_FU is explainedby LN_SPOT's today volatility and remaining 6.330413% is explained byit's today's Volatility, is this statement correct? Then what will bethe interpretation of remaining numbers like : 94.36506,5.634938,..etc? And also What could be the interpretation of the SE in layman's term? I already gone through Eviews help file however, did not get anything. If u people here help me on this regard, I will be very very grateful. Regards, Send instant messages to your online friends http://uk.messenger.yahoo.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] basic help
Thank you, it worked perfectly. Moti -Original Message- From: Chuck Cleland [mailto:[EMAIL PROTECTED] Sent: Thursday, March 20, 2008 10:40 AM To: מוטי אסולין Cc: r-help@r-project.org Subject: Re: [R] basic help On 3/20/2008 12:59 AM, מוטי אסולין wrote: Hi, I am a new R user (used SPSS for many years) and I need help. I have a data frame mydata with 8 variables m2008:m2001 I wanted to add a new variable mydata$firstvalid that tells me what is the first non missing variable for each case (without using for-next). I tried many variations of this: lst = paste(m,2008:2001,sep=) mydata$firstvalid = match(FALSE, is.na(mydata[lst]),0) Instead of a different value for each case, I get the same value for all cases - the first non missing value in the whole data frame. Many thanks, Moti Assouline X - as.data.frame(matrix(sample(c(NA,NA,1:5), 100, replace=TRUE), ncol=5)) X V1 V2 V3 V4 V5 1 NA NA NA NA NA 2 2 4 NA 3 3 3 2 3 NA NA NA 4 4 3 2 NA 2 5 2 3 2 NA NA 6 5 3 2 5 NA 7 NA 5 NA 3 3 8 3 NA 3 2 2 9 4 5 5 NA 3 10 2 5 NA NA 1 11 1 2 NA NA 2 12 2 4 NA 5 2 13 NA 5 NA NA NA 14 5 5 4 5 NA 15 2 NA 5 2 NA 16 NA 1 4 NA NA 17 NA 5 NA 5 NA 18 5 2 NA 4 1 19 3 5 2 4 5 20 4 NA 2 1 NA X$FVALID - apply(is.na(X), 1, function(x){ifelse(all(x), 0, which.min(x))}) X V1 V2 V3 V4 V5 FVALID 1 NA NA NA NA NA 0 2 2 4 NA 3 3 1 3 2 3 NA NA NA 1 4 4 3 2 NA 2 1 5 2 3 2 NA NA 1 6 5 3 2 5 NA 1 7 NA 5 NA 3 3 2 8 3 NA 3 2 2 1 9 4 5 5 NA 3 1 10 2 5 NA NA 1 1 11 1 2 NA NA 2 1 12 2 4 NA 5 2 1 13 NA 5 NA NA NA 2 14 5 5 4 5 NA 1 15 2 NA 5 2 NA 1 16 NA 1 4 NA NA 2 17 NA 5 NA 5 NA 2 18 5 2 NA 4 1 1 19 3 5 2 4 5 1 20 4 NA 2 1 NA 1 Checked by AVG. 20:52 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 No virus found in this incoming message. Checked by AVG. 19/03/2008 09:54 Checked by AVG. 19/03/2008 09:54 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] analysis on Pcap dataset
Hi, I want to do some analysis on pcap datasets.. so is there any package which take cares of that.. If someone has already worked on this, could you give me some tips... thanks, Neo23 -- View this message in context: http://www.nabble.com/analysis-on-Pcap-dataset-tp16187570p16187570.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] download webpage in R
Hi, everyone I want to download a XML webpage and save it as a file in my local machine. Is there any way to do it in R? Thanks a lot Gilbert [[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] download webpage in R
If you do help.search(download) you find ?download.file G. On Thu, Mar 20, 2008 at 04:51:22PM -0500, gilbert feng wrote: Hi, everyone I want to download a XML webpage and save it as a file in my local machine. Is there any way to do it in R? Thanks a lot Gilbert [[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. -- Csardi Gabor [EMAIL PROTECTED]UNIL DGM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] download webpage in R
Also the XML package for processing the file once retrieved. Martin Gabor Csardi wrote: If you do help.search(download) you find ?download.file G. On Thu, Mar 20, 2008 at 04:51:22PM -0500, gilbert feng wrote: Hi, everyone I want to download a XML webpage and save it as a file in my local machine. Is there any way to do it in R? Thanks a lot Gilbert [[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. -- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M2 B169 Phone: (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] Importing an Excel spreadsheet
Hello I am trying to import an *.xls spreadsheet into R. I am doing this as follows: read.table(file(A5_DL.xls)) But obtain the error: Error in type.convert(data[[i]], as.is = as.is[i], dec = dec, na.strings = character(0)) : invalid multibyte string at '?' So I copied it all over to a text document and tried to import that, thus: read.table(A5.txt) The error I got then was: Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line 26 did not have 34 elements Having gone over the line in question, it all seems to be the same as any other row. I really don't want to have to manually re-enter the data (some 98 rows x 26 columns). Can someone advise me on what I am overlooking here please. Thanks Andy -- If they can get you asking the wrong questions, they don't have to worry about the answers. - Thomas Pynchon, Gravity's Rainbow __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] download webpage in R
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 And if the Web page requires anything more than basic access, e.g. if it uses a password or SSL (via https), you can use RCurl to make more advanced, customizable HTTP/FTP requests. ~ D. Gabor Csardi wrote: | If you do | | help.search(download) | | you find | | ?download.file | | G. | | On Thu, Mar 20, 2008 at 04:51:22PM -0500, gilbert feng wrote: | Hi, everyone | | I want to download a XML webpage and save it as a file in my local machine. | Is there any way to do it in R? | | Thanks a lot | | Gilbert | | [[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. | -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFH4uT+9p/Jzwa2QP4RAnsqAJ9IL0HqWqXaPl2uJBrRlOKpJKc5LwCeOsJI sNHT3DAQnlbowTVdeelpzX0= =ggop -END PGP SIGNATURE- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Importing an Excel spreadsheet
andy geek_show at dsl.pipex.com writes: I am trying to import an *.xls spreadsheet into R. I am doing this as follows: read.table(file(A5_DL.xls)) So I copied it all over to a text document and tried to import that, thus: read.table(A5.txt) The error I got then was: Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line 26 did not have 34 elements Having gone over the line in question, it all seems to be the same as any other row. I really don't want to have to manually re-enter the data (some 98 rows x 26 columns). Thanks Andy read.table deduces that your data set has 34 elements, not 26, according to the error message. Could there be spaces in the column names? ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Importing an Excel spreadsheet
If you open the spreadsheet in Excel you can then do Save as... and select type CSV (comma-delimited text). Once you have the data in CSV format, you can use the R function read.csv to import the data. Cheers, Bryan andy wrote: Hello I am trying to import an *.xls spreadsheet into R. I am doing this as follows: read.table(file(A5_DL.xls)) But obtain the error: Error in type.convert(data[[i]], as.is = as.is[i], dec = dec, na.strings = character(0)) : invalid multibyte string at '?' So I copied it all over to a text document and tried to import that, thus: read.table(A5.txt) The error I got then was: Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line 26 did not have 34 elements Having gone over the line in question, it all seems to be the same as any other row. I really don't want to have to manually re-enter the data (some 98 rows x 26 columns). Can someone advise me on what I am overlooking here please. Thanks Andy -- Bryan Woods Dept. of Geology Geophysics Yale University, KGL 106D / KGL 234 210 Whitney Ave New Haven, CT 06511 203.432.5669 (office) 978.726.3462 (cell) 203.432.3134 (fax) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Importing an Excel spreadsheet
Bryan K Woods wrote: If you open the spreadsheet in Excel you can then do Save as... and select type CSV (comma-delimited text). Once you have the data in CSV format, you can use the R function read.csv to import the data. Cheers, Bryan andy wrote: Hello I am trying to import an *.xls spreadsheet into R. I am doing this as follows: read.table(file(A5_DL.xls)) But obtain the error: Error in type.convert(data[[i]], as.is = as.is[i], dec = dec, na.strings = character(0)) : invalid multibyte string at '?' So I copied it all over to a text document and tried to import that, thus: read.table(A5.txt) The error I got then was: Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : line 26 did not have 34 elements Having gone over the line in question, it all seems to be the same as any other row. I really don't want to have to manually re-enter the data (some 98 rows x 26 columns). Can someone advise me on what I am overlooking here please. Thanks Andy That did it - thanks!! Very steep learning curve ... so appreciate your help. Cheers Andy -- If they can get you asking the wrong questions, they don't have to worry about the answers. - Thomas Pynchon, Gravity's Rainbow __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] setMethod for [
Hi R-Help, Please consider the following simple case: I have a class like setClass(myClass, representation(x=matrix, y=character)) and I would like to use the method *[* for a *myClass* objects (but changing the default *drop* argument from TRUE to FALSE): setMethod([,myClass, function(x,i,j,...,drop=FALSE) { x - [EMAIL PROTECTED] callNextMethod() x-as.myClass(x) } ) suppose that *as.myClass* method has been already defined. Actually, all I want is to pass all the arguments to *[* method for *matrix*, except changing the default behaviour for *drop*. When I execute: test-new(myClass,x=cbind(1:3,4:6),y=a) test[1,] # works as expected [1] 1 4 test[1,drop=TRUE] # does not work Error: argument j is missing, with no default Error in callNextMethod() : error in evaluating a 'primitive' next method but with a matrix the two cases work: m-cbind(1:3,4:6) m[1,] [1] 1 4 m[1,drop=TRUE] [1] 1 Can you please advise me a solution for this problem? Thank you in advance for the help. Musa [[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] Error in function (classes, fdef, mtable): unable to find an inherited method for function indexProbes, for signature exprSet, character
Hello Everyone, I am writing programs in R from 7 months and I am able to solve most of the errors/issues except for this current post. My Task is to read a Microsoft Excel file(textE_to_affy.csv) which contains the Microarray Expression Values collected from the Illumina Microarray experiment. These collected intensity values need to be normalized(Rank Invariant Normalization) by using the R function normalize.AffyBatch.invariantset(). Since the normalize.AffyBatch.invariantset() method requires the input argument to be an AffyBatch Object, I used the read.exprSet() method to convert the intensity values present in the (textE_to_affy.csv) file into an AffyBatch Object as follows: testFile - tempfile() textAffy-read.table(textE_to_affy.csv,header=TRUE,sep=,,row.names=1) textAffy Sample1 Sample2 Sample3 GI_10047089-S -6.100 -5.12500 -5.61250 GI_10047091-S 10.7259.70625 10.21562 GI_10047093-S 1392.100 1378.7 1385.4 GI_10047099-S 264.925 260.98125 262.95312 GI_10047103-S 5315.675 5412.01875 5363.84688 GI_10047105-S 21.750 22.53750 22.14375 write.table(TA,testFile,quote = FALSE, sep = \t, row.names = TRUE, col.names = TRUE) testFile [1] C:\\DOCUME~1\\Jaswanth\\LOCALS~1\\Temp\\RtmpXrUE8T\\file2ea6bb3 eSet - read.exprSet(testFile) Warning messages: 1: read.exprSet is deprecated, use readExpresionSet instead 2: read.phenoData is deprecated, use read.AnnotatedDataFrame instead 3: The phenoData class is deprecated, use AnnotatedDataFrame (with ExpressionSet) instead 4: The exprSet class is deprecated, use ExpressionSet instead 5: The exprSet class is deprecated, use ExpressionSet instead 6: The exprSet class is deprecated, use ExpressionSet instead 7: The exprSet class is deprecated, use ExpressionSet instead 8: The exprSet class is deprecated, use ExpressionSet instead 9: The exprSet class is deprecated, use ExpressionSet instead eSet Expression Set (exprSet) with 6 genes 3 samples phenoData object with 1 variables and 3 cases varLabels sample: arbitrary numbering Warning messages: 1: The exprSet class is deprecated, use ExpressionSet instead 2: The exprSet class is deprecated, use ExpressionSet instead 3: The phenoData class is deprecated, use AnnotatedDataFrame (with ExpressionSet) instead RInormalizedData-normalize.AffyBatch.invariantset(eSet,prd.td=c(0.003, 0.007),baseline.type=mean,type=together) Error in function (classes, fdef, mtable) : unable to find an inherited method for function pmindex, for signature exprSet I have observed that this same error message has been posted and answered in a different context in this forum. Even though I am not using the S4 class and method concepts here, I am getting this error. I have also uploaded the input file on which the normalization needed to be performed. Hence, I would be grateful for you if you can give some direction/advice for me to overcome this error. Thanks a lot, Suprabhath Reddy http://www.nabble.com/file/p16190637/textE_to_affy.csv textE_to_affy.csv -- View this message in context: http://www.nabble.com/Error-in-function-%28classes%2C-fdef%2C-mtable%29%3A-unable-to-find-an-inherited-method-for-function-%22indexProbes%22%2C-for-signature-%22exprSet%22%2C-%22character%22-tp16190637p16190637.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] setMethod for [
Hi Musa -- Musa Parmaksiz wrote: Hi R-Help, Please consider the following simple case: I have a class like setClass(myClass, representation(x=matrix, y=character)) and I would like to use the method *[* for a *myClass* objects (but changing the default *drop* argument from TRUE to FALSE): setMethod([,myClass, function(x,i,j,...,drop=FALSE) { x - [EMAIL PROTECTED] callNextMethod() I think you are hoping that [EMAIL PROTECTED] will be subsetted, and it appears that it is. But I think this is a bug. 'callNextMethod' without any arguments should be using the 'x' in the signature. This should result in an error like the one seen here setMethod([, signature=signature(x=myClass), function(x, i, j, ..., drop=FALSE) { callNextMethod() }) test[1,] Error in x[i = i, j = , ...] : object is not subsettable Normally, to change the value of the variable 'seen' by the next method, one would expect to have to write something like setMethod([, signature=signature(x=myClass), function(x, i, j, ..., drop=FALSE) { callNextMethod([EMAIL PROTECTED], i=i, j=j, ..., drop=drop) }) You can now see how this is a little more complicated -- if j is missing in the original function call, then it can't be used in an assignment in callNextMethod. You'd have to write something like setMethod([, signature=signature(x=myClass), function(x, i, j, ..., drop=FALSE) { if (missing(i) missing(j)) callNextMethod([EMAIL PROTECTED],,, ..., drop=drop) else if (missing(j)) callNextMethod([EMAIL PROTECTED], i=i, , ..., drop=drop) else if (missing(i)) callNextMethod([EMAIL PROTECTED], , j=j, ..., drop=drop) else callNextMethod([EMAIL PROTECTED], i=i, j=j, ..., drop=drop) }) or, since this is really an implementation that dispatches on the 'misssing'-ness of i, j, a series of methods like setMethod([, signature=signature( x=myClass, i=ANY', j=missing) function(x, i, j, ..., drop=FALSE) { callNextMethod([EMAIL PROTECTED], i=i, , ..., drop=drop) }) Notice too how it is necessary to specify the argument list in quite an odd way, with a ',' for the 'missing' variable(s). This is because [ is a so-called 'Primitive' function, and primitive functions match by position rather than the usual matching by name: matrix(1:20,5)[4,2] [1] 9 matrix(1:20,5)[j=4,i=2] [1] 9 ! I read somewhere that when faced with learning complicated systems, otherwise intelligent people will develop wildly inaccurate stories to explain why the system 'works'. The above is my story. Martin x-as.myClass(x) } ) suppose that *as.myClass* method has been already defined. Actually, all I want is to pass all the arguments to *[* method for *matrix*, except changing the default behaviour for *drop*. When I execute: test-new(myClass,x=cbind(1:3,4:6),y=a) test[1,] # works as expected [1] 1 4 test[1,drop=TRUE] # does not work Error: argument j is missing, with no default Error in callNextMethod() : error in evaluating a 'primitive' next method but with a matrix the two cases work: m-cbind(1:3,4:6) m[1,] [1] 1 4 m[1,drop=TRUE] [1] 1 Can you please advise me a solution for this problem? Thank you in advance for the help. Musa [[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. -- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M2 B169 Phone: (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.
Re: [R] Error in function (classes, fdef, mtable): unable to find an inherited method for function indexProbes, for signature exprSet, character
This is a Bioconductor package, ask on the Bioc mailing list http://bioconductor.org More comments below... Suprabhath wrote: Hello Everyone, I am writing programs in R from 7 months and I am able to solve most of the errors/issues except for this current post. My Task is to read a Microsoft Excel file(textE_to_affy.csv) which contains the Microarray Expression Values collected from the Illumina Microarray experiment. These collected intensity values need to be normalized(Rank Invariant Normalization) by using the R function normalize.AffyBatch.invariantset(). Since the normalize.AffyBatch.invariantset() method requires the input argument to be an AffyBatch Object, I used the read.exprSet() method to convert the intensity values present in the (textE_to_affy.csv) file into an AffyBatch Object as follows: testFile - tempfile() textAffy-read.table(textE_to_affy.csv,header=TRUE,sep=,,row.names=1) textAffy Sample1 Sample2 Sample3 GI_10047089-S -6.100 -5.12500 -5.61250 GI_10047091-S 10.7259.70625 10.21562 GI_10047093-S 1392.100 1378.7 1385.4 GI_10047099-S 264.925 260.98125 262.95312 GI_10047103-S 5315.675 5412.01875 5363.84688 GI_10047105-S 21.750 22.53750 22.14375 write.table(TA,testFile,quote = FALSE, sep = \t, row.names = TRUE, col.names = TRUE) testFile [1] C:\\DOCUME~1\\Jaswanth\\LOCALS~1\\Temp\\RtmpXrUE8T\\file2ea6bb3 eSet - read.exprSet(testFile) Warning messages: 1: read.exprSet is deprecated, use readExpresionSet instead Pay attention to these messages. Use readExpressionSet instead! 2: read.phenoData is deprecated, use read.AnnotatedDataFrame instead 3: The phenoData class is deprecated, use AnnotatedDataFrame (with ExpressionSet) instead 4: The exprSet class is deprecated, use ExpressionSet instead 5: The exprSet class is deprecated, use ExpressionSet instead 6: The exprSet class is deprecated, use ExpressionSet instead 7: The exprSet class is deprecated, use ExpressionSet instead 8: The exprSet class is deprecated, use ExpressionSet instead 9: The exprSet class is deprecated, use ExpressionSet instead eSet Expression Set (exprSet) with 6 genes 3 samples phenoData object with 1 variables and 3 cases varLabels sample: arbitrary numbering Warning messages: 1: The exprSet class is deprecated, use ExpressionSet instead 2: The exprSet class is deprecated, use ExpressionSet instead 3: The phenoData class is deprecated, use AnnotatedDataFrame (with ExpressionSet) instead RInormalizedData-normalize.AffyBatch.invariantset(eSet,prd.td=c(0.003, 0.007),baseline.type=mean,type=together) Error in function (classes, fdef, mtable) : unable to find an inherited method for function pmindex, for signature exprSet This error should not occur with an ExpressionSet. I have observed that this same error message has been posted and answered in a different context in this forum. Even though I am not using the S4 class and method concepts here, I am getting this error. You are using a package that uses S4. I have also uploaded the input file on which the normalization needed to be performed. Hence, I would be grateful for you if you can give some direction/advice for me to overcome this error. Thanks a lot, Suprabhath Reddy http://www.nabble.com/file/p16190637/textE_to_affy.csv textE_to_affy.csv -- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M2 B169 Phone: (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.
Re: [R] conditional matching of rows of tables
Second try :P I have matrix A of 4 cols: 1 a 0 4 1 b 5 8 2 a 0 3 2 b 4 7 And matrix B of 3 cols: 1 2 3 2 4 5 2 0 3 1 7 8 I would like to assign (a or b) to the rows of matrix B. The rules are that in each row of matrix B, the 1st value must match the 1st col. of matrix A, 2nd and 3rd values must lie between 3rd and 4rd cols (inclusive) of matrix A. For example, the 1st row of matrix B is 1 2 3, the 1st value 1 corresponds to 1st and 2nd row of matrix A. Next, its 2nd and 3rd values 2 and 3 lie between 0 and 4 of 1st row of matrix A. Thus 1st row of matrix B is assigned a. Similarly, the assignments for remaining rows of matrix B are 2 4 5 - b 2 0 3 - a 1 7 8 - b -Original Message- From: jim holtman [mailto:[EMAIL PROTECTED] Sent: Friday, March 21, 2008 00:33 To: Ng Stanley Cc: r-help Subject: Re: [R] conditional matching of rows of tables Not exactly clear on the transformation that you want to do. In your example, '1 2 3 - a', where does the '2 3' come from since I don't see a value of 2 in the 3rd 4th columns. So a better explanation of what you are trying to do would be help and show where the values came from in each case. On 3/20/08, Ng Stanley [EMAIL PROTECTED] wrote: Hi, Given matrix A of 4 cols. 1 a 0 4 1 b 5 8 2 a 0 3 2 b 4 7 I have another matrix B of 3 cols. How to assign (a or b) to the rows such that in each row its 1st value must match the 1st col. of A, 2nd and 3rd values must lie between 3rd and 4rd cols (inclusive) of A 1 2 3 - a 2 4 5 - b 2 0 3 - a 1 7 8 - b [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] setMethod for [
Hi Martin, Thanks for the suggestions. If possible I would avoid defining several methods with different signatures. For the first solution,namely setMethod([, signature=signature(x=myClass), function(x, i, j, ..., drop=FALSE) { if (missing(i) missing(j)) callNextMethod([EMAIL PROTECTED],,, ..., drop=drop) else if (missing(j)) callNextMethod([EMAIL PROTECTED], i=i, , ..., drop=drop) else if (missing(i)) callNextMethod([EMAIL PROTECTED], , j=j, ..., drop=drop) else callNextMethod([EMAIL PROTECTED], i=i, j=j, ..., drop=drop) }) one cannot distinguish between test[1] and test[1,] ! I suspect we could use nargs()... On Fri, Mar 21, 2008 at 12:43 AM, Martin Morgan [EMAIL PROTECTED] wrote: Hi Musa -- Musa Parmaksiz wrote: Hi R-Help, Please consider the following simple case: I have a class like setClass(myClass, representation(x=matrix, y=character)) and I would like to use the method *[* for a *myClass* objects (but changing the default *drop* argument from TRUE to FALSE): setMethod([,myClass, function(x,i,j,...,drop=FALSE) { x - [EMAIL PROTECTED] callNextMethod() I think you are hoping that [EMAIL PROTECTED] will be subsetted, and it appears that it is. But I think this is a bug. 'callNextMethod' without any arguments should be using the 'x' in the signature. This should result in an error like the one seen here setMethod([, signature=signature(x=myClass), function(x, i, j, ..., drop=FALSE) { callNextMethod() }) test[1,] Error in x[i = i, j = , ...] : object is not subsettable Normally, to change the value of the variable 'seen' by the next method, one would expect to have to write something like setMethod([, signature=signature(x=myClass), function(x, i, j, ..., drop=FALSE) { callNextMethod([EMAIL PROTECTED], i=i, j=j, ..., drop=drop) }) You can now see how this is a little more complicated -- if j is missing in the original function call, then it can't be used in an assignment in callNextMethod. You'd have to write something like setMethod([, signature=signature(x=myClass), function(x, i, j, ..., drop=FALSE) { if (missing(i) missing(j)) callNextMethod([EMAIL PROTECTED],,, ..., drop=drop) else if (missing(j)) callNextMethod([EMAIL PROTECTED], i=i, , ..., drop=drop) else if (missing(i)) callNextMethod([EMAIL PROTECTED], , j=j, ..., drop=drop) else callNextMethod([EMAIL PROTECTED], i=i, j=j, ..., drop=drop) }) or, since this is really an implementation that dispatches on the 'misssing'-ness of i, j, a series of methods like setMethod([, signature=signature( x=myClass, i=ANY', j=missing) function(x, i, j, ..., drop=FALSE) { callNextMethod([EMAIL PROTECTED], i=i, , ..., drop=drop) }) Notice too how it is necessary to specify the argument list in quite an odd way, with a ',' for the 'missing' variable(s). This is because [ is a so-called 'Primitive' function, and primitive functions match by position rather than the usual matching by name: matrix(1:20,5)[4,2] [1] 9 matrix(1:20,5)[j=4,i=2] [1] 9 ! I read somewhere that when faced with learning complicated systems, otherwise intelligent people will develop wildly inaccurate stories to explain why the system 'works'. The above is my story. Martin x-as.myClass(x) } ) suppose that *as.myClass* method has been already defined. Actually, all I want is to pass all the arguments to *[* method for *matrix*, except changing the default behaviour for *drop*. When I execute: test-new(myClass,x=cbind(1:3,4:6),y=a) test[1,] # works as expected [1] 1 4 test[1,drop=TRUE] # does not work Error: argument j is missing, with no default Error in callNextMethod() : error in evaluating a 'primitive' next method but with a matrix the two cases work: m-cbind(1:3,4:6) m[1,] [1] 1 4 m[1,drop=TRUE] [1] 1 Can you please advise me a solution for this problem? Thank you in advance for the help. Musa [[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. -- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M2 B169 Phone: (206) 667-2793 [[alternative HTML version
[R] coredump at the of 'configure' and error for 'make'
Hi, I got some errors when I attempted to build R on my Solaris 9 box. Can someone please provide some suggestion on what to do next? The configure process was fine expect that I got a some warning message and a coredump at the end. What does that affect? Can I still build it? ./configure --prefix=/var/tmp/R/ --with-x=no R is now configured for i386-pc-solaris2.9 Source directory: . Installation directory:/var/tmp/R/ C compiler:gcc -g -O2 Fortran 77 compiler: g77 -g -O2 C++ compiler: g++ -g -O2 Fortran 90/95 compiler:g77 -g -O2 Obj-C compiler: -g -O2 Interfaces supported: External libraries:readline Additional capabilities: PNG, JPEG, iconv, MBCS, NLS Options enabled: shared BLAS, R profiling, Java Recommended packages: yes configure: WARNING: you cannot build the object documentation system configure: WARNING: I could not determine a browser configure: WARNING: I could not determine a PDF viewer ./configure[64111]: 10817 Segmentation Fault(coredump) I tried to build it anyway. When I ran make, I got an error. What may go wrong here? make[3]: Leaving directory `/var/tmp/R-2.6.2/src/library/profile' make[3]: Entering directory `/var/tmp/R-2.6.2/src/library/base' building package 'base' all.R is unchanged ../../../library/base/R/base is unchanged ../../../bin/R: bad substitution make[3]: *** [all] Error 1 make[3]: Leaving directory `/var/tmp/R-2.6.2/src/library/base' make[2]: *** [R] Error 1 make[2]: Leaving directory `/var/tmp/R-2.6.2/src/library' make[1]: *** [R] Error 1 make[1]: Leaving directory `/var/tmp/R-2.6.2/src' make: *** [R] Error 1 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] conditional matching of rows of tables
This should do it for you: A V1 V2 V3 V4 1 1 a 0 4 2 1 b 5 8 3 2 a 0 3 4 2 b 4 7 B V1 V2 V3 1 1 2 3 2 2 4 5 3 2 0 3 4 1 7 8 B1 - B # create a copy and add a new column B1$key - for (i in seq(nrow(B))){ + indx - which((B[i,1] == A[,1]) (B[i,2] = A[,3]) (B[i,3] = A[,4])) + if (length(indx) == 0){ + warning(No match for row:, i) + next + } + if (length(indx) 1) warning(multiple matches for row:, i) + B1$key[i] - as.character(A$V2[indx[1]]) # take first match if multiples + } B1 V1 V2 V3 key 1 1 2 3 a 2 2 4 5 b 3 2 0 3 a 4 1 7 8 b On Thu, Mar 20, 2008 at 7:00 PM, Stanley Ng [EMAIL PROTECTED] wrote: Second try :P I have matrix A of 4 cols: 1 a 0 4 1 b 5 8 2 a 0 3 2 b 4 7 And matrix B of 3 cols: 1 2 3 2 4 5 2 0 3 1 7 8 I would like to assign (a or b) to the rows of matrix B. The rules are that in each row of matrix B, the 1st value must match the 1st col. of matrix A, 2nd and 3rd values must lie between 3rd and 4rd cols (inclusive) of matrix A. For example, the 1st row of matrix B is 1 2 3, the 1st value 1 corresponds to 1st and 2nd row of matrix A. Next, its 2nd and 3rd values 2 and 3 lie between 0 and 4 of 1st row of matrix A. Thus 1st row of matrix B is assigned a. Similarly, the assignments for remaining rows of matrix B are 2 4 5 - b 2 0 3 - a 1 7 8 - b -Original Message- From: jim holtman [mailto:[EMAIL PROTECTED] Sent: Friday, March 21, 2008 00:33 To: Ng Stanley Cc: r-help Subject: Re: [R] conditional matching of rows of tables Not exactly clear on the transformation that you want to do. In your example, '1 2 3 - a', where does the '2 3' come from since I don't see a value of 2 in the 3rd 4th columns. So a better explanation of what you are trying to do would be help and show where the values came from in each case. On 3/20/08, Ng Stanley [EMAIL PROTECTED] wrote: Hi, Given matrix A of 4 cols. 1 a 0 4 1 b 5 8 2 a 0 3 2 b 4 7 I have another matrix B of 3 cols. How to assign (a or b) to the rows such that in each row its 1st value must match the 1st col. of A, 2nd and 3rd values must lie between 3rd and 4rd cols (inclusive) of A 1 2 3 - a 2 4 5 - b 2 0 3 - a 1 7 8 - b [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Use of Factors
Do 'str' on your object and you will see that they are 'factors'. May have gotten that way when you read them in and there was character data in the column. To convert it back to numeric, do: cpx_interp$HR - as.numeric(as.character(cpx_interp$HR)) On Thu, Mar 20, 2008 at 9:26 AM, Beck, Kenneth (STP) [EMAIL PROTECTED] wrote: Relatively new to R, I'm trying to do a relatively simple task. I have data set that has several variables arranged by SubjID and visit, with multiple observations for that combination. I do linear regression on those multiple observations, then generated a set of interpolated values from the regression at fixed intervals along x. I now want to average each of those across all the SubjID's. When I use either by() or tapply(), I get an error indicating the interpolated values are factors, even though they display looking like floating point numbers. The mean function returns a value that is obviously wrong, though the count of observations in the subsets is correct. I am including code snippets to try to demostrate how this is all created:, sorry for the length of this Here is output when I try to use the mean function, mean_interp_HR=tapply(cpx_interp$HR[cpx_interp$visit==1 cpx_interp$xl==0],cpx_interp$SubjId[cpx_interp$visit==1 cpx_interp$xl==0],mean) Warning in mean.default(X[[1L]], ...) : argument is not numeric or logical: returning NA Warning in mean.default(X[[2L]], ...) : argument is not numeric or logical: returning NA Warning in mean.default(X[[3L]], ...) : argument is not numeric or logical: returning NA Warning in mean.default(X[[4L]], ...) : argument is not numeric or logical: returning NA Warning in mean.default(X[[5L]], ...) : argument is not numeric or logical: returning NA Look at the data I am submitting to tapply and mean: cpx_interp$HR[cpx_interp$visit==1 cpx_interp$xl==0] [1] 62.5252140470478 67.6151493460742 68.3931063786315 78.6591518601803 59.7674671000443 90 Levels: 62.5252140470478 66.046907240618 69.5686004341883 69.8766646005142 71.9631282463843 ... 85.4270562298357 cpx_interp$SubjId[cpx_interp$visit==1 cpx_interp$xl==0] [1] ADENPV07 ADENPVJN ADENPV0Z ADENPVM9 ADENPVMB Levels: ADENPV07 ADENPVJN ADENPV0Z ADENPVM9 ADENPVMB Why is the $HR variable listed as 90 levels as if it is a factor? Why is it not treated as floating point to get simple mean? Here is how the HR values are generated: # create the array interp_out=array(,c(18,length(cols2))) # create the values to interpolate to interp_out[,3]=c(0,25,50,75,100,125,150,175,200,0,25,50,75,100,125,150,1 75,200); # fill the visits interp_out[,2]=c(1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2) # fill the SubjID interp_out[,1]=SubjID; Now fill in interplated values for each visit. interp_out[1:9,4]=hrv1;interp_out[10:18,4]=hrv2; # hrv1 hrv2 come from the following function, the lm parameter is output from the standard lm() function: interpolateToXL = function(lm,maxxl){ int_values=matrix(nrow=9,ncol=1) int_values[1,]=coef(lm)[1]; if (maxxl25) int_values[2,]=coef(lm)[1]+coef(lm)[2] * 25 if (maxxl50) int_values[3,]=coef(lm)[1]+coef(lm)[2] * 50 if (maxxl75) int_values[4,]=coef(lm)[1]+coef(lm)[2] * 75 if (maxxl100) int_values[5,]=coef(lm)[1]+coef(lm)[2] * 100 if (maxxl125) int_values[6,]=coef(lm)[1]+coef(lm)[2] * 125 if (maxxl150) int_values[7,]=coef(lm)[1]+coef(lm)[2] * 150 if (maxxl175) int_values[8,]=coef(lm)[1]+coef(lm)[2] * 175 if (maxxl200) int_values[9,]=coef(lm)[1]+coef(lm)[2] * 200 return (int_values) } Ken Beck PhD Research Scientist Boston Scientific CRM (Guidant) 10-212 [EMAIL PROTECTED] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] hist - modify maximum frequency (vertical axis)
Hello, Is there a way to easily specify the maximum value to draw a histogram with the hist function? I have 6 histograms, but each of them is drawn with a different frequency range (scaling them to the best visible way), however I need all the histograms to be scaled so that the maximum frequency is a specific number (say 300, is the maximum value of the vertical axis). This value is the maximum value shown overall in all the histograms. Is that possible? Thanks, Omar -- Omar Baqueiro Espinosa Computer Science PhD Candidate Computer Systems Engineer Workpage: www.csc.liv.ac.uk/~omar/ HomePage (spanish):http://www.baqueiro.co.uk/ PGP Key available at: www.csc.liv.ac.uk/~omar/pgp.html _ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] I need help integrating ggplot2 into Excel
Create an R script,name it Myggplot2 and place it on your desktop.In excel open the vb editor and write this code: Sub Myggplot2() 'start R Call rinterface.StartRServer 'Put the dataframe into R,assuming that your 'data is in sheet1 cells A1:D1 Call rinterface.PutDataframe(yourdataframename, Range(Sheet1!A1:D Range(D1).End(xlDown).Row)) Call rinterface.RRun(attach(yourdataframename)) 'dataframe is attached,now run r script rinterface.RRun source(C:/Documents and Settings/Owner/Desktop/Myggplot2.r) Call rinterface.StopRServer End Sub Running code from RExcel you must use print(myplot)at the end of the code good luck Dear all I use ggplot2 extensively for my plotting routines and rexcel to have the best of two worlds. (RExcel v 1.75 and R (D)Com v. 2.5) I can run my ggplot functions, such as qplot(...), in scratchpad mode, but not in Macro nor Worksheet functions mode. I have tried the following in Macro mode: Call RInterface.RRun(library(ggplot2)) ... Call RInterface.RRun(qplot(x=Hours,y=pH,data=ds,facets=Sample~.,geom=line,group=Cell)) With no output ... I have tried the following in Worksheet function mode: if Range(H40:I42) contains: (Embedded image moved to file: pic10654.jpg) and Range(H48) contains: qplot The following call: =Rcalla(H48;makeargs(H40:I42)) Gives me no output Scratchpad mode However, right clicking a cell containing: qplot(x=Hours,y=pH,data=ds,facets=Sample~.,geom=line,group=Cell) and then selecting Run R works like a dream! I would like to develop an excel based GUI for R-data treatment and plotting, and I would like to use ggplot2 as my plotting engine. What am I doing wrong? Thank you for your help Jannik Vindeløv, Ph.D. Project Manager Dairy Culture Development Innovation P.O. Box 64 Arpajon Cedex F-91292 France Phone: +33 (0)1 6988 3636 Direct Phone: +33 (0)1 6988 3629 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Felipe D. Carrillo Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] hist - modify maximum frequency (vertical axis)
Hi, type ?hist in the R prompt and look for the ylim argument. Example: x=rep(1:10,1:10) hist(x,ylim=c(0,20)) Manipulate the ylim values as needed. Cheers, Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Omar Baqueiro Gesendet: Thursday, March 20, 2008 11:18 PM An: r-help@r-project.org Betreff: [R] hist - modify maximum frequency (vertical axis) Hello, Is there a way to easily specify the maximum value to draw a histogram with the hist function? I have 6 histograms, but each of them is drawn with a different frequency range (scaling them to the best visible way), however I need all the histograms to be scaled so that the maximum frequency is a specific number (say 300, is the maximum value of the vertical axis). This value is the maximum value shown overall in all the histograms. Is that possible? Thanks, Omar -- Omar Baqueiro Espinosa Computer Science PhD Candidate Computer Systems Engineer Workpage: www.csc.liv.ac.uk/~omar/ HomePage (spanish):http://www.baqueiro.co.uk/ PGP Key available at: www.csc.liv.ac.uk/~omar/pgp.html _ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] interperting a regression tree
If you have fitted a tree model, the diagram (which did not survive the mailing list, of course) would have been a decision tree, not a dendrogram. In a decision tree, the internal nodes refer to decisions to be made as to whether to proceed to the left or to the right at that stage. This is based on the value of a selected predictor variable. If tm is the tree model, you would normally display it using plot(tm) text(tm) Each internal node is then labelled with a message line age 25.5, which shows that at that point the decision is made on the variable, 'age'. If the age of the case is less than 25.5 choose the left branch, otherwise the right branch. When you arrive at a terminal node, bingo! You get a prize. Bill Venables -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Sharma, Manju Sent: Thursday, 20 March 2008 8:54 PM To: r-help@r-project.org Subject: [R] interperting a regression tree hello i am trying to decipher a dendrogram i have from performing a 'tree'. (attached file) my response variable is factored - low, medium and high threat and the 8 explanatory variables are numeric values. i could do with some help to understand what the values 0.25, 0.5 and 0.75 are on the tree branches? how does one interpret this??? cheers, mann Manju Sharma Ashoka Trust for Research in Ecology and the Environment, Banaglore, India __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] logLik calculations
library(MASS) methods(logLik) [1] logLik.Arima*logLik.fitdistr* logLik.gam logLik.glm* [5] logLik.glmmPQL* logLik.lm* logLik.negbin* logLik.nls* [9] logLik.polr* Non-visible functions are asterisked glmgenerates an object of class glm, so tick! glm.nb generates an object of class ... negbin, so tick! Because the methods are starred, though, they will not be directly accessible. (I am to blame for choosing class name negbin for objects generated by glm.nb, but it's far too late to do anything about it now!) Bill Venables. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of kyoung Sent: Friday, 21 March 2008 2:53 AM To: r-help@r-project.org Subject: [R] logLik calculations Does the logLik function applied to a glm and glm.nb (from MASS package) calculate the complete log-likelihoods, or does it drop the constant terms of the equation? (It's not clear from the associated help pages, and I've found no reference from searching the R help mailing list) Thank you, Kelly Young __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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.