Re: [R] Create column of frequency
On 9/29/2009 6:06 AM, abdul kudus wrote: Dear all, Given mypi mypi - c(0.1,0.2,0.2,0.1,0.3,0.4,0.4,0.4,0.4,0.2) I want to create myfreq as follows mypi myfreq 0.1 2 0.2 3 0.2 3 0.1 2 0.3 1 0.4 4 0.4 4 0.4 4 0.4 4 0.2 3 where myfreq is frequency of its corresponding observation. How to do that? mypi - c(0.1,0.2,0.2,0.1,0.3,0.4,0.4,0.4,0.4,0.2) ave(mypi, mypi, FUN=length) [1] 2 3 3 2 1 4 4 4 4 3 ?ave Thank you, Regards, A. Kudus Institute for Math Research Univ Putra Malaysia [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to calculate average correlation coefficient of a correlation matrix ?
On 10/13/2009 10:13 AM, Amit Kumar wrote: Hi! All, I have large correlation matrix Cor. I wish to calculate average correlation coefficient for this matrix. Is there any function in R to do this? Thanks in advance. cormat - cor(iris[,1:4]) corlowtri - cormat[lower.tri(cormat)] corlowtri [1] -0.1175698 0.8717538 0.8179411 -0.4284401 -0.3661259 0.9628654 mean(corlowtri) [1] 0.2900708 mean(abs(corlowtri)) [1] 0.594116 avgcor - function(x){mean(abs(x[lower.tri(x)]))} avgcor(cor(iris[,1:4])) [1] 0.594116 Amit __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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] Import SPSS file to R
On 10/19/2009 8:06 AM, Suman Kundu wrote: Hello, In R, How to read SPSS file and access the data item? RSiteSearch('SPSS', restrict='function') Thank you. Regards, Suman Kundu [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] modifying model coefficients
On 10/18/2009 11:26 PM, tdm wrote: I have build a model but want to then manipulate the coefficients in some way. I can extract the coefficients and do the changes I need, but how do I then put these new coefficients back in the model so I can use the predict function? my_model - lm(x ~ . , data=my_data) my_scores - predict(my_model, my_data) my_coeffs - coef(my_model) ## here we manipulate my_coeffs ## and then want to set the my_model ## coefficients to the new values so we ## predict using the new values my_model.coefs - my_coeffs ?? how is this done? ?? so that this will work with the new coefficients my_scores_new - predict(my_model, my_data) Any code snippets would be appreciated very much. Have you considered setting the coefficients to the values in my_coeffs using offset()? fm1 - lm(Sepal.Length ~ offset(0.90*Sepal.Width) + offset(0.50*Petal.Length) + offset(-0.50*Petal.Width), data = iris) summary(fm1) predict(fm1) all.equal(as.vector(predict(fm1)), c(as.matrix(cbind(1, iris[,2:4])) %*% c(1.8124, 0.9, 0.5, -0.5))) [1] TRUE ?offset -- 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 average subgroups in a dataframe? (not sure how to apply aggregate(..))
On 10/21/2009 7:03 AM, Tony Breyal wrote: Dear all, Lets say I have the following data frame: set.seed(1) col1 - c(rep('happy',9), rep('sad', 9)) col2 - rep(c(rep('alpha', 3), rep('beta', 3), rep('gamma', 3)),2) dates - as.Date(rep(c('2009-10-13', '2009-10-14', '2009-10-15'),6)) score=rnorm(18, 10, 3) df1-data.frame(col1=col1, col2=col2, Date=dates, score=score) col1 col2 Date score 1 happy alpha 2009-10-13 8.120639 2 happy alpha 2009-10-14 10.550930 3 happy alpha 2009-10-15 7.493114 4 happy beta 2009-10-13 14.785842 5 happy beta 2009-10-14 10.988523 6 happy beta 2009-10-15 7.538595 7 happy gamma 2009-10-13 11.462287 8 happy gamma 2009-10-14 12.214974 9 happy gamma 2009-10-15 11.727344 10 sad alpha 2009-10-13 9.083835 11 sad alpha 2009-10-14 14.535344 12 sad alpha 2009-10-15 11.169530 13 sad beta 2009-10-13 8.136278 14 sad beta 2009-10-14 3.355900 15 sad beta 2009-10-15 13.374793 16 sad gamma 2009-10-13 9.865199 17 sad gamma 2009-10-14 9.951429 18 sad gamma 2009-10-15 12.831509 Is it possible to get the following, whereby I am averaging the values within each group of values in col2: col1 col2 Date score Average 1 happy alpha 13/10/2009 8.120639 8.721561 2 happy alpha 14/10/2009 10.550930 8.721561 3 happy alpha 15/10/2009 7.493114 8.721561 4 happy beta 13/10/2009 14.785842 11.104320 5 happy beta 14/10/2009 10.988523 11.104320 6 happy beta 15/10/2009 7.538595 11.104320 7 happy gamma 13/10/2009 11.462287 11.801535 8 happy gamma 14/10/2009 12.214974 11.801535 9 happy gamma 15/10/2009 11.727344 11.801535 10 sad alpha 13/10/2009 9.083835 11.596236 11 sad alpha 14/10/2009 14.535344 11.596236 12 sad alpha 15/10/2009 11.169530 11.596236 13 sad beta 13/10/2009 8.136278 8.288990 14 sad beta 14/10/2009 3.355900 8.288990 15 sad beta 15/10/2009 13.374793 8.288990 16 sad gamma 13/10/2009 9.865199 10.882712 17 sad gamma 14/10/2009 9.951429 10.882712 18 sad gamma 15/10/2009 12.831509 10.882712 My feeling is that I should be using the ?aggregate is some fashion but can't see how to do it. Or possibly there's another function i should be using? ?ave For example, try something like this: transform(df1, Average = ave(score, col1, col2)) Thanks in advance, Tony O/S: Windows Vista Ultimate sessionInfo() R version 2.9.2 (2009-08-24) i386-pc-mingw32 locale: LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United Kingdom. 1252;LC_MONETARY=English_United Kingdom. 1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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] Simple question, I think
On 10/22/2009 12:37 PM, David Kaplan wrote: Greetings, I am recoding a dummy variable (coded 1,0) so that 0 = 2. I am using the line sciach$dummyba[sciach$ba==0] - 2 I notice that it creates a new column dummyba, with 0 coded as 2 but with 1's now coded as NA. Is there a simple way around this in the line I am using, or do I need to have an additional line sciach$dummyba[sciach$ba==1] - 1 You might do the recoding like this: with(sciach, ifelse(ba == 0, 2, ifelse(ba == 1, 1, NA))) or like this: sciach$ba * -1 + 2 Thanks in advance. David __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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] Bonferroni with unequal sample sizes
On 10/23/2009 1:30 PM, slrei...@vims.edu wrote: Hello- I have run an ANOVA on 4 treatments with unequal sample sizes (n=9,7,10 and 10). I want to determine where my sig. differences are between treatments using a Bonferroni test, and have run the code: pairwise.t.test(Wk16, Treatment, p.adf=bonf) I receive an error message stating that my arguments are of unequal length: Error in tapply(x, g, mean, na.rm = TRUE) : arguments must have same length Is there a way to run this test even with unequal sample sizes? Unequal sample sizes are not causing the reported error. The problem is that 'Wk16' and 'Treatment' do not have the same number of observations. If the group sizes are 9, 7, 10, and 10, then 'Wk16' and 'Treatment' should each contain 36 observations. Thanks. Stephanie Reiner Andrews Hall 410 Shipping: Rt. 1208 Greate Road Gloucester Point, VA 23062 work: 804-684-7869 cell: 443-286-4795 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] What is the difference between anova {stats} and aov?
On 10/27/2009 1:06 PM, Peng Yu wrote: There are anova {stats} and aov in R. It seems that anova takes an object returned by a model fitting function. But I don't see any examples for anova. Can somebody give me a simple example on anova? What is the difference between anova and aov? http://finzi.psych.upenn.edu/Rhelp08/2009-January/184619.html fm1 - aov(breaks ~ tension + wool, data=warpbreaks) fm2 - aov(breaks ~ tension * wool, data=warpbreaks) anova(fm1) anova(fm2) anova(fm1, fm2) See ?anova.lm and ?anova.glm for more anova() examples. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Johnson-Neyman procedure (ANCOVA)
On 10/30/2009 9:20 PM, Stropharia wrote: Dear R users, Does anyone know of a package that implements the Johnson-Neyman procedure - for testing differences among groups when the regression slopes are heterogeneous (in an ANCOVA model)? I did not get any matches for functions when searching using R Site Search. If it has not been implemented in R, does anyone know of another statistical package that has this procedure? I found very old scripts available for Mathematica, but have had difficulty getting them to work. http://www.comm.ohio-state.edu/ahayes/SPSS%20programs/modprobe.htm Thanks in advance. best, Steve -- 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] read.table (again)
On 11/4/2009 5:03 AM, Sybille Wendel (Udata) wrote: Dear R commnuity, Thanks a lot for your help. I want to read in tables, the problem is that the table is composed in a difficult way. In ariginal it looks like this: 669 736 842101610481029114711811166124312081128117611221026 9581024 992 685 720 829 925 995 96010241057116611501104106410711092 983 908 989 904 924 896 882 897 909 933 928 907 916 902 546 734 784 868 970 954 99210061012101610481045 9821057 989 914 956 960 948 947 949 939 916 950 562 598 771 827 941 922 905 877 860 862 931 952 954 977 960 901 978 975 970 950 973 953 958 931 912 558 593 725 786 884 866 838 797 815 802 809 822 853 833 863 852 903 9861015 9841019 993 955 932 918 874 518 580 600 764 834 804 814 824 849 831 939 757 769 790 809 892 89810251028104410371018 985 932 478 559 585 696 812 812 811 867 854 811 814 818 793 760 814 976 957104510551067106410501005 948 465 528 567 619 703 828 824 830 851 824 823 873 826 787 787 9791048105710621083108910841027 944 That is, that every 4 digits there is a new number, but when the number is 999, R thinks of course that the number consists of more than 4 digits. So, R can't read in the table. Is there a way I can tell R, that every 4 digits, a new number begins? ?read.fwf I treif different things with sep. data - read.table (RA19930101.txt,header=F,sep=) Thanks for your help again in this topic. Sybille -- 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 delete columns with NA values?
On 4/14/2010 10:56 AM, muting wrote: Hi everyone: I have a dataset: tm1 col1 col2 [1,]1 NA [2,]11 [3,]22 [4,]11 [5,]22 [6,]1 NA I need to delete entire column 2 that has NA in it(not all of them are NAs), and the result I want is tm1 col1 [1,]1 [2,]1 [3,]2 [4,]1 [5,]2 [6,]1 what should I do? subset(tm1, select=colMeans(is.na(tm1)) == 0) OR tm1[,colMeans(is.na(tm1)) == 0] I search a lot, all I found is how to delete column with all NA values.. Thanks a lot muting -- 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 make a boxplot with exclusion of certain groups
On 4/19/2010 12:21 PM, josef.kar...@phila.gov wrote: This seems like a simple thing, but I have been stuck for some time. My data has 2 columns. Column 1 is the value, and column 2 is the Site where data was collected. Column 2 contains 7 different Sites (i.e. groups). I am only interested in showing 3 groups on a single boxplot. I have tried various methods of subsetting the data, in order to only have the 3 groups in my subset. However even after doing this, all 7 groups carry forward, so that when I make a boxplot of my subsetted data, all 7 groups still appear in the x-axis labels; all 7 groups also appear in the boxplot summary (i.e. the values returned with boxplot (…plot=FALSE) ) . Even if I delete the unwanted groups from the ‘levels’ of Column 2, they still appear on the plot, and in the boxplot summary statistics. There are various tricks I can do with the boxplot summary statistics to correct for this, but they get complicated when I want to change the algorithm for calculating outliers and their corresponding groups. Rather than do all these tricks, it seems much simpler to fully exclude the unwanted groups from the beginning. But this doesn’t appear to work Any ideas? library(gdata) # for drop.levels() DF - data.frame(site = rep(LETTERS[1:7], each=20), y = runif(7*20)) boxplot(y ~ drop.levels(site), data=subset(DF, site %in% c('A','D','F'), drop=TRUE)) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] substract start from the end of the vector
with(df, substr(DESCRIPTION, start=1, stop=nchar(DESCRIPTION) - 10)) ?nchar On 4/23/2010 11:57 AM, arnaud Gaboury wrote: Dear group, Here is my df : df - structure(list(DESCRIPTION = c(PRM HGH GD ALUMINIUM USD 09/07/10 , PRM HGH GD ALUMINIUM USD 09/07/10 , PRIMARY NICKEL USD 04/06/10 ), CREATED.DATE = structure(c(18361, 18361, 18325), class = Date), QUANITY = c(-1L, 1L, 1L), CLOSING.PRICE = c(2,415.90, 2,415.90, 25,755.71)), .Names = c(DESCRIPTION, CREATED.DATE, QUANITY, CLOSING.PRICE), row.names = c(NA, 3L), class = data.frame) df DESCRIPTION CREATED.DATE QUANITY CLOSING.PRICE 1 PRM HGH GD ALUMINIUM USD 09/07/102020-04-09 -1 2,415.90 2 PRM HGH GD ALUMINIUM USD 09/07/102020-04-091 2,415.90 3 PRIMARY NICKEL USD 04/06/102020-03-041 25,755.71 In the DESCRIPTION column, I want to get rid of the date (09/07/10 .). I know the function substr(x, start, stop), but in my case, I need to indicate I want to start from the end of the vector, and I have no idea how to pass this argument. TY for any help *** Arnaud Gaboury Mobile: +41 79 392 79 56 BBM: 255B488F *** [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Determining Index of Last Element in Vector
On 4/25/2010 2:10 PM, Alan Lue wrote: Hi, Is there a way to specify the last element of a vector, similar to end in MATLAB? v[end] would be MATLAB for v(length(v)) in R. While `v(length(v))' does yield the last element, that approach fails in the following, rep(v, each=2)[-c(1,length(v))] which is meant to duplicate all elements of `v' except for the first and last. (I.e., if `v - 1:4', then we want '1 2 2 3 3 4'.) v - 1:4 rep(v, c(1, rep(2, length(v) - 2), 1)) [1] 1 2 2 3 3 4 So the question is, is there a better way specify the last element of a vector? If not, is there a better way to duplicate all elements of a vector except for the first and last? (I know you can achieve this using two lines, but I'm writing because I want to do it using one.) Alan -- 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] vectorize a power analysis?
On 5/12/2010 3:34 PM, Jack Siegrist wrote: We are doing a power analysis by generating noisy data sets according to a model, fitting the model to the data, and extracting a p-value. What is the best way to do this many times? We are just using for loops and it is too slow because we are repeating the analysis for many parameterizations. I can think of several ways to do this: for loop sapply using the plyr package using the lme4 package You don't mention replicate(), which I would consider. For example: replicate(10, t.test(rnorm(20))$p.value) [1] 0.2622419 0.1538739 0.9759340 [4] 0.7413474 0.1541895 0.4321595 [7] 0.5800549 0.7329299 0.9625038 [10] 0.1315875 If you write a function that does the data generating, model fitting, and p-value extraction, then replicate can run that function many times. I don't know how the timing compares, but I like the simplicity and readability of replicate(). hope this helps, Chuck Someone told me that the apply functions are barely any faster than for loops, so what is the best way, in general, to approach this type of problem in R-style? Could someone point to a discussion of the comparative time efficiencies of these and other appropriate methods? I'm not looking for specific code, just sort of a list of the common approaches with information about efficiency. Thanks, Jack -- 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 ls() only functions or anything else but functions?
On 5/13/2010 10:02 AM, John Edwards wrote: Hello, How ls() only functions or only data objects (basically anything other than functions) such as data.frame, numeric ...? c(ls.str(mode = function)) ls()[!(ls() %in% c(ls.str(mode=function)))] ?ls.str John [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How ls() only functions or anything else but functions?
On 5/13/2010 11:04 AM, Chuck Cleland wrote: On 5/13/2010 10:02 AM, John Edwards wrote: Hello, How ls() only functions or only data objects (basically anything other than functions) such as data.frame, numeric ...? c(ls.str(mode = function)) ls()[!(ls() %in% c(ls.str(mode=function)))] ?ls.str Or better ... c(lsf.str()) ls()[!(ls() %in% c(lsf.str()))] John [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Getting dates in an SPSS file in right format.
On 5/18/2010 12:38 PM, Praveen Surendran wrote: Dear all, I am trying to read an SPSS file into a data frame in R using method read.spss(), sample - read.spss(file.name,to.data.frame=TRUE) But dates in the data.frame 'sample' are coming as integers and not in the actual date format given in the SPSS file. Appreciate if anyone can help me to solve this problem. Date variables in SPSS contain the number of seconds since October 14, 1582. You might try something like this: sample$MYDATE - as.Date(as.POSIXct(sample$MYDATE, origin=1582-10-14, tz=GMT)) Kind Regards, Praveen Surendran 2G, Complex and Adaptive Systems Laboratory (UCD CASL) School of Medicine and Medical Sciences University College Dublin Belfield, Dublin 4 Ireland. Office : +353-(0)1716 5334 Mobile : +353-(0)8793 13071 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] switching elements of a vector
On 5/24/2010 6:02 AM, speretti wrote: Hi, I would like to receive help for the following matter: If I'm dealing with a numeric vectors containing increasing elements. i.e. a-c(1,2,2,2,2,3,3,3,4,4,4,5,5,6,7,7,7) There exist an efficient way to obtain an vector that indicates the position of the changing element of a? In this case it would be something like: index-c(1,6,9,12,14,15) a - c(1,2,2,2,2,3,3,3,4,4,4,5,5,6,7,7,7) rle(a) Run Length Encoding lengths: int [1:7] 1 4 3 3 2 1 3 values : num [1:7] 1 2 3 4 5 6 7 cumsum(head(rle(a)$lengths, -1)) + 1 [1] 2 6 9 12 14 15 ?rle usually I'm used cycles to obtain boolean vectors of the same length of a indicating the changing elements ...later I've muliplied them for their numeric sequence and after that I've selected elements different from zero ...it is quite long... can you find an easier solution? Thank you for you help -- 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] interaction effects in a Linear model
On 11/23/2009 1:06 AM, ashok varma wrote: hello, i am fitting a Linear model using R. I have to fit the model considering all the interaction effects of order 1 of the independent variables. But I have 9 variables. So, it will be difficult for me to write all the 36 combinations in the model. Can anyone please help how to get this done in much smarter way?? This will include all main effects and two-way interactions: lm(Y ~ (A + B + C + D + E + F + G + H + I)^2, data=mydata) thanks a lot, Ashok Varma. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] matching and extracting data
On 11/27/2009 10:25 AM, ram basnet wrote: Dear all, I have querry on how to extract the data by matching between two data set where one has the same elements multiple times? For example, I have two matrix X and Y. X [,1][,2] [,3] 1 A 5 P 2 B 6 P 3 C 7 P 4 D 5 Q 5 E 6 Q 6 F 7 Q 7 G 5 R 8 H 6 R 9 I 7 S 10 J 5 S 11 K6 T 12 L 7 T and Y [,1] 1 P 2 Q 3 R 4 S Now, I want to select and extract all the data of P, Q, R and S elements of column 3 of X matrix by matching with column 1 of Y matrix like below: [,1] [,2] [,3] 1 A 5 P 2 B 6 P 3 C 7 P 4 D 5 Q 5 E 6 Q 6 F 7 Q 7 G 5 R 8 H 6 R 9 I 7 S 10 J 5 S I guess, the answer might be simple but i am not getting way to figure out. And, i have to select subset from very huge data set. So, i need some kinds of automated procedure. If some one can help me, it will be great subset(X, X[,3] %in% Y[,1]) [,1] [,2] [,3] [1,] A 5 P [2,] B 6 P [3,] C 7 P [4,] D 5 Q [5,] E 6 Q [6,] F 7 Q [7,] G 5 R [8,] H 6 R [9,] I 7 S [10,] J 5 S Thanks in advance. Sincerely, Ram Kumar Basnet [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to z-standardize for subgroups?
On 11/29/2009 4:23 PM, John Kane wrote: http://finzi.psych.upenn.edu/R/library/QuantPsyc/html/Make.Z.html Make.Z in the QuantPsych package may already do it. For a single variable, you could use ave() and scale() together like this: with(iris, ave(Sepal.Width, Species, FUN = scale)) To scale more than one variable in a concise call, consider something along these lines: apply(iris[,1:4], 2, function(x){ave(x, iris$Species, FUN = scale)}) hope this helps, Chuck Cleland --- On Sun, 11/29/09, Karsten Wolf w...@uni-bremen.de wrote: From: Karsten Wolf w...@uni-bremen.de Subject: [R] How to z-standardize for subgroups? To: r-help@r-project.org Received: Sunday, November 29, 2009, 10:41 AM Hi folks, I have a dataframe df.vars with the follwing structure: var1 var2 var3 group Group is a factor. Now I want to standardize the vars 1-3 (actually - there are many more) by class, so I define z.mean.sd - function(data){ return.values - (data - mean(data)) / (sd(data)) return(return.values) } now I can call for each var z.var1 - by(df.vars$var1, group, z.mean.sd) which gives me the standardised data for each subgroup in a list with the subgroups z.var1 - unlist(z.var1) then gives me the z-standardised data for var1 in one vector. Great! Now I would like to do this for the whole dataframe, but probably I am not thinking vectorwise enough. z.df.vars - by(df.vars, group, z.mean.sd) does not work. I banged my head on other solutions trying out sapply and tapply, but did not succeed. Do I need to loop and put everything together by hand? But I want to keep the columnnames in the vector… -karsten - Karsten D. Wolf Didactical Design of Interactive Learning Environments Universität Bremen - Fachbereich 12 web: http://www.ifeb.uni-bremen.de/wolf/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ Do You Yahoo!? Tired of spam? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Finding cases in one subset that are closet to another subset
On 12/2/2009 3:01 PM, Peter Flom wrote: Good afternoon Running R2.10.0 on Windows I have a data frame that includes (among much else) a factor (In_2006) and a continuous variable (math_3_4). I would like to find the 2 cases for In_2006 = 0 that are closest to each case where In_2006 = 1. My data looks like In_2006 math_3_4 0 55.1 1 51.6 1 18.1 1 26.6 1 14.1 1 9.6 1 48.9 1 12.9 0 63.0 0 51.8 etc. for several hundred rows. I would like a new data frame that has all the cases where In_2006 = 1, and those cases of In_2006 that are closest to those cases Hi Peter: How about using one of the various matching packages (MatchIt, optmatch, Matching)? For example, something like this: DF - data.frame(X = rbinom(200, 1, .1), Y = runif(200)) library(MatchIt) DF.match - matchit(X ~ Y, data=DF, method='optimal', ratio=2) DF[c(rownames(DF.match$match.matrix), c(DF.match$match.matrix)),] hope this helps, Chuck Thanks in advance Peter Peter L. Flom, PhD Statistical Consultant Website: www DOT peterflomconsulting DOT com Writing; http://www.associatedcontent.com/user/582880/peter_flom.html Twitter: @peterflom __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] writing 'output.csv' file
On 12/4/2009 5:12 AM, Maithili Shiva wrote: Dear R helpers Suppose M - c(1:10) # length(M) = 10 N - c(25:50) # length(N) = 26 I wish to have an outut file giving M and N. So I have tried write.csv(data.frame(M, N), 'output.csv', row.names = FALSE) but I get the following error message Error in data.frame(M, N) : arguments imply differing number of rows: 10, 26 How do I modify my write.csv command to get my output in a single (csv) file irrespective of lengths. The first argument to write.csv() is preferably a matrix or data frame. If it is something else, write.csv() will try to make it a data frame. You may want to create the data frame like this: data.frame(M = c(M, rep(NA,length(N) - length(M))), N=N) M N 1 1 25 2 2 26 3 3 27 4 4 28 5 5 29 6 6 30 7 7 31 8 8 32 9 9 33 10 10 34 11 NA 35 12 NA 36 13 NA 37 14 NA 38 15 NA 39 16 NA 40 17 NA 41 18 NA 42 19 NA 43 20 NA 44 21 NA 45 22 NA 46 23 NA 47 24 NA 48 25 NA 49 26 NA 50 Plese Guide Thanks in advance Maithili The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Exchange NAs for mean
On 12/17/2009 9:31 AM, Joel Fürstenberg-Hägg wrote: Hi all, I'm have a matrix (X) with observations as rows and parameters as columns. I'm trying to exchange all missing values in a column by the column mean using the code below, but so far, nothing happens with the NAs... Can anyone see where the problem is? N-nrow(X) # Calculate number of rows = 108 p-ncol(X) # Calculate number of columns = 88 # Replace by columnwise mean for (i in colnames(X)) # Do for all columns in the matrix { for (j in rownames(X)) # Go through all rows { if(is.na(X[j,i])) # Search for missing value in the given position { X[j,i]=mean(X[1:p, i]) # Change missing value to the mean of the column } } } mymat - matrix(runif(50), ncol=5) mymat[c(3,4,9),c(1,2,5)] - NA mymat [,1] [,2] [,3] [,4] [,5] [1,] 0.05863667 0.23545794 0.25549983 0.96275422 0.1015316 [2,] 0.66107818 0.15846239 0.05112992 0.09081990 0.6097318 [3,] NA NA 0.86474629 0.73186676NA [4,] NA NA 0.26226776 0.31987242NA [5,] 0.78472732 0.09072242 0.24557669 0.57100857 0.1568413 [6,] 0.42431343 0.37551338 0.86085073 0.62782597 0.5090823 [7,] 0.44609972 0.90125504 0.52285650 0.41298482 0.3192929 [8,] 0.27676684 0.17200162 0.70648140 0.86983249 0.2035595 [9,] NA NA 0.34956846 0.07070571NA [10,] 0.01482263 0.20074897 0.41553916 0.82367719 0.9674044 apply(mymat, 2, function(x){x - replace(x, is.na(x), mean(x, na.rm=TRUE))}) [,1] [,2] [,3] [,4] [,5] [1,] 0.05863667 0.23545794 0.25549983 0.96275422 0.1015316 [2,] 0.66107818 0.15846239 0.05112992 0.09081990 0.6097318 [3,] 0.38092069 0.30488025 0.86474629 0.73186676 0.4096348 [4,] 0.38092069 0.30488025 0.26226776 0.31987242 0.4096348 [5,] 0.78472732 0.09072242 0.24557669 0.57100857 0.1568413 [6,] 0.42431343 0.37551338 0.86085073 0.62782597 0.5090823 [7,] 0.44609972 0.90125504 0.52285650 0.41298482 0.3192929 [8,] 0.27676684 0.17200162 0.70648140 0.86983249 0.2035595 [9,] 0.38092069 0.30488025 0.34956846 0.07070571 0.4096348 [10,] 0.01482263 0.20074897 0.41553916 0.82367719 0.9674044 All the best, Joel _ Hitta hetaste singlarna på MSN Dejting! http://dejting.se.msn.com/channel/index.aspx?trackingid=1002952 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Power calculation
On 6/10/2010 8:26 AM, Samuel Okoye wrote: Hello, Is there any R function which does power calculation for unbalanced groups (n1 neq n2)? Since power.t.test has n Number of observations (per group). Many thanks, Samuel See pwr.t2n.test() in the pwr package. http://finzi.psych.upenn.edu/R/library/pwr/html/pwr.t2n.test.html You might have found it by doing the following in R: RSiteSearch(power analysis, restrict='function') [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] If-error-resume-next
On 6/24/2010 10:30 AM, Christofer Bogaso wrote: In VBA there is a syntax if error resume next which sometimes acts as very beneficial on ignoring error. Is there any similar kind of function/syntax here in R as well? ?try Thanks for your attention [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Logistic regression with multiple imputation
On 6/30/2010 1:14 AM, Daniel Chen wrote: Hi, I am a long time SPSS user but new to R, so please bear with me if my questions seem to be too basic for you guys. I am trying to figure out how to analyze survey data using logistic regression with multiple imputation. I have a survey data of about 200,000 cases and I am trying to predict the odds ratio of a dependent variable using 6 categorical independent variables (dummy-coded). Approximatively 10% of the cases (~20,000) have missing data in one or more of the independent variables. The percentage of missing ranges from 0.01% to 10% for the independent variables. My current thinking is to conduct a logistic regression with multiple imputation, but I don't know how to do it in R. I searched the web but couldn't find instructions or examples on how to do this. Since SPSS is hopeless with missing data, I have to learn to do this in R. I am new to R, so I would really appreciate if someone can show me some examples or tell me where to find resources. Here is an example using the Amelia package to generate imputations and the mitools and mix packages to make the pooled inferences. titanic - read.table(http://lib.stat.cmu.edu/S/Harrell/data/ascii/titanic.txt;, sep=',', header=TRUE) set.seed(4321) titanic$sex[sample(nrow(titanic), 10)] - NA titanic$pclass[sample(nrow(titanic), 10)] - NA titanic$survived[sample(nrow(titanic), 10)] - NA library(Amelia) # generate multiple imputations library(mitools) # for MIextract() library(mix) # for mi.inference() titanic.amelia - amelia(subset(titanic, select=c('survived','pclass','sex','age')), m=10, noms=c('survived','pclass','sex'), emburn=c(500,500)) allimplogreg - lapply(titanic.amelia$imputations, function(x){glm(survived ~ pclass + sex + age, family=binomial, data = x)}) mice.betas.glm - MIextract(allimplogreg, fun=function(x){coef(x)}) mice.se.glm - MIextract(allimplogreg, fun=function(x){sqrt(diag(vcov(x)))}) as.data.frame(mi.inference(mice.betas.glm, mice.se.glm)) # Or using only mitools for pooled inference betas - MIextract(allimplogreg, fun=coef) vars - MIextract(allimplogreg, fun=vcov) summary(MIcombine(betas,vars)) Thank you! Daniel [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Change the colour of lines in the xyplot?
On 7/12/2010 2:52 AM, Jian Zhang wrote: I want to add the legend for my figure using auto.key in the xyplot function (library(lattice)). But I don't know how to change the colors of the lines in the legend part. I tried to add col=1:8 in the auto.key, but it changes the colors of the text of my Legend, not the lines. How can I change the colors of the lines? xyplot(estimated~year,data=res,type=l,group=sp, auto.key= list(points = FALSE, lines=TRUE, corner =c(0.1,0.6),size=5, col=1:8)) xyplot(estimated ~ year, data=res, type=l, group=sp, par.settings = list(superpose.line=list(col=1:8)), auto.key=list(points=FALSE, lines=TRUE, corner=c(0.1,0.6), size=5)) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] standardizing one variable by dividing each value by the mean - but within levels of a factor
On 1/20/2010 5:37 PM, Dimitri Liakhovitski wrote: Hello! I have a data frame with a factor and a numeric variable: x-data.frame(factor=c(b,b,d,d,e,e),values=c(1,2,10,20,100,200)) For each level of factor - I would like to divide each value of values by the mean of values that corresponds to the level of factor In other words, I would like to get a new variable that is equal to: 1/1.5 2/1.5 10/15 20/15 100/150 200/150 I realize I could do it through tapply starting with: factor.level.means-tapply(x$values,x$factor,mean) ... etc. But it seems clunky to me. Is there a more elegant way of doing it? with(x, ave(x=values, factor, FUN=function(x){x/mean(x)})) [1] 0.667 1.333 0.667 1.333 0.667 1.333 ?ave Thanks a lot! -- 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] Estimation of S.E. based on bootstrapping (functions with two or more arguments)
On 1/21/2010 7:45 AM, Tomas Zelinsky wrote: Hi all, I need to estimate S.E. of a certain indicator. The function to compute the value of indicator contains two arguments. Can anybody tell me how to do it? Example: We have data: a - c(1:10) b - c(11:20) data - data.frame(a, b) Function to compute value of the indicator: indicator - function(X, Y) sum(X)/(sum(Y)*2) Next I need to do the bootstrapping and estimate mean value of indicator and its standard error. If the function (indicator in my case) contained only one argument, there would not be a problem, the code would look like: resamples - lapply(1:1000, function(i) sample(data, replace = T)) r.indicator - sapply(resamples, indicator) mean(r.indicator) sqrt(var(r.indicator)) But in case of function with two arguments it doesn�t work. I tried to do it like: resamples - lapply(1:1000, function(i) data[sample(1:nrow(data), replace = TRUE),]) r.indicator - sapply(resamples, indicator) but it didn't work. Can anybody help? How about using boot() in package boot? Using your example: a - c(1:10) b - c(11:20) DF - data.frame(a,b) library(boot) boot(DF, statistic = function(d, ind){sum(d$a[ind])/sum(d$b[ind]*2)}, R = 1000) ORDINARY NONPARAMETRIC BOOTSTRAP Call: boot(data = DF, statistic = function(d, ind) { sum(d$a[ind])/sum(d$b[ind] * 2) }, R = 1000) Bootstrap Statistics : original biasstd. error t1* 0.1774194 -0.001594390 0.01902264 Thanks a lot. Tomas __ Informacia od ESET NOD32 Antivirus, verzia databazy 4792 (20100121) __ Tuto spravu preveril ESET NOD32 Antivirus. [1]http://www.eset.sk References 1. http://www.eset.sk/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Extract R-squared from summary of lm
On 1/22/2010 10:10 AM, Trafim Vanishek wrote: Dear all, I cannot find to explicitly get the R-squared or adjusted R-squared from summary(lm()) fm1 - lm(Sepal.Length ~ Sepal.Width, data=iris) summary(fm1) str(summary(fm1)) summary(fm1)$r.squared ?str Thanks a lot! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Selective Plot Color
On 1/27/2010 10:00 AM, Richardson, Patrick wrote: Is there a way (with a simple plot) to select all observations greater than a certain value and plot them with a different color than the rest of the observations in the plot? (i.e. for all observations greater than 10, I want to plot them in red, but the rest of the observations remain black. Where can I find how to do this? Patrick X - runif(30, min=5, max=15) Y - rnorm(30) plot(X, Y, col=ifelse(X 10, 'red', 'black'), pch=16) The information transmitted is intended only for the per...{{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. -- 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] extract R-squared and P-value from lm results
On 1/29/2010 9:04 AM, wenjun zheng wrote: Hi, R Users I find a problem in extracting the R-squared and P-value from the lm results described below (in Italic), *Residual standard error: 2.25 on 17 degrees of freedom* *Multiple R-squared: 0.001069, Adjusted R-squared: -0.05769 * *F-statistic: 0.01819 on 1 and 17 DF, p-value: 0.8943 * * * Any suggestions will be appreciated. Thanks. ?summary.lm In particular, see the 'Value' section which describes the components of the list returned when an lm() object is summarized. Notice the r.squared and coefficients components of the returned list. Wenjun [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using auto.key with two variable plots
On 1/30/2010 3:45 PM, Jonathan Greenberg wrote: Rhelpers: Having a problem solving this. I have an xyplot call that looks like this: print(xyplot(temp_species_EAM_Pred_Pop$x+temp_species_NULL_Pred_Pop$x~temp_species_EAM_Pred_Pop$Action,main=current_species, xlab=Action,ylab=Predicted Pop, xlim=c(xmin,xmax),ylim=c(ymin,ymax), auto.key=list(corner=c(1,1 This is just a scatterplot with two response variables sharing the same predictor variable (temp_species_EAM_Pred_Pop$Action). Right now, the key has the words temp_species_EAM_Pred_Pop$x and temp_species_NULL_Pred_Pop$x next to their symbols. I would like to rename these in the key, say EAM and NULL -- using the group= command doesn't work (since these aren't really different groups). What is the right way to rename these variables in the key? Is using auto.key the right approach? Did you try setting the text parameter of the auto.key list? Something like this: print(xyplot(temp_species_EAM_Pred_Pop$x + temp_species_NULL_Pred_Pop$x ~ temp_species_EAM_Pred_Pop$Action, main=current_species, xlab=Action,ylab=Predicted Pop, xlim=c(xmin,xmax),ylim=c(ymin,ymax), auto.key=list(text=c('EAM','NULL'), corner=c(1,1 Thanks! --j -- 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] Subset and plot
On 2/2/2010 2:51 PM, Marlin Keith Cox wrote: Here is a runable program. When I plot Day and Wgt, it graphs all the data points. All I need is daily.sub1 plotted. I also need each Tanks to have its own col or pch. When I run it with the line with pch, it gives me nothing. DF - data.frame(Trial=rep(c(1,2),each=12), Tanks=rep(c(a3,a4,c4,h4),each=3,2), Day=rep(c(1:12),2), Wgt=c(1:24)) with(subset(DF, Trial==2 Tanks %in% c(a4,'c4','h4')), plot(Day, Wgt, pch=as.numeric(Tanks))) library(lattice) trellis.device(new=TRUE, color=FALSE) xyplot(Wgt ~ Day, groups=Tanks, data=subset(DF, Trial==2 Tanks %in% c(a4,'c4','h4')), par.settings=list(superpose.symbol=list(pch=c(2,19,21 rm(list=ls()) Trial-rep(c(1,2),each=12) Tanks=rep(c(a3,a4,c4,h4),each=3,2) Day=rep(c(1:12),2) Wgt=c(1:24) daily-cbind(Trial, Tanks, Day, Wgt) daily daily.sub-subset(daily, subset=Trial==2 Tanks==a4|Trial==2 Tanks==c4|Trial==2 Tanks==h4) daily.sub1-as.data.frame(daily.sub) attach(daily.sub1) daily.sub1 x11() plot(Day, Wgt) #plot(Day, Wgt, pch=c(2,19,21)[Tanks]) detach(daily.sub1) -- 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] locate word in vector
kevinchang wrote: Hey All, I am wondering if there is a built-in function allowing us to locate a particular word in a character vector. ex: vector a a [1] superman xamn spiderman superman superman xman [7] spiderman Is there any built-in function that can show superman are the first, fourth and fifith element in a? Please help me out. Thanks. a - c(superman, xamn, spiderman, superman, superman, xman, spiderman) grep(^superman$, a) [1] 1 4 5 ?grep OR which(a %in% superman) [1] 1 4 5 ?which ?is.element -- Chuck Cleland, Ph.D. NDRI, Inc. 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] regression by groups
Jiong Zhang, PhD wrote: Hi All, I want to run regression (lm) on my dependant variable by gender and race. How do I integrate the by function in lm? thanks. Here is an example using the iris data: by(iris, iris$Species, function(x){ summary(lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width, data=x))}) jiong The email message (and any attachments) is for the sole...{{dropped:11}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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] save lm output into vectors
Henrique Dallazuanna wrote: Hi, mods - lapply(lapply(df[,which(sapply(df, is.factor))], function(reg)lm(df$value~reg)), summary) res - lapply(mods, [, c(4,10)) And for each model adjusted: 1-pf(res[[2]][[2]][1], res[[2]][[2]][2], res[[2]][[2]][3]) 1-pf(res[[1]][[2]][1], res[[1]][[2]][2], res[[1]][[2]][3]) Jiong: Here is another approach: mymodels - lapply(split(iris, list(iris$Species)), function(x){lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width, data = x)}) lapply(mymodels, function(x){coefficients(summary(x))}) $setosa Estimate Std. Error t value Pr(|t|) (Intercept) 2.3518898 0.39286751 5.9864707 3.034183e-07 Sepal.Width 0.6548350 0.09244742 7.0833236 6.834434e-09 Petal.Length 0.2375602 0.20801921 1.1420107 2.593594e-01 Petal.Width 0.2521257 0.34686362 0.7268727 4.709870e-01 $versicolor Estimate Std. Error t value Pr(|t|) (Intercept) 1.8955395 0.5070552 3.738329 5.112246e-04 Sepal.Width 0.3868576 0.2045449 1.891309 6.488965e-02 Petal.Length 0.9083370 0.1654325 5.490681 1.95e-06 Petal.Width -0.6792238 0.4353821 -1.560064 1.255990e-01 $virginica Estimate Std. Errort value Pr(|t|) (Intercept) 0.6998830 0.53360089 1.3116227 1.961563e-01 Sepal.Width 0.3303370 0.17432873 1.8949086 6.439972e-02 Petal.Length 0.9455356 0.09072204 10.4223360 1.074269e-13 Petal.Width -0.1697527 0.19807243 -0.8570233 3.958750e-01 lapply(mymodels, function(x){coefficients(summary(x))[,4]}) $setosa (Intercept) Sepal.Width Petal.Length Petal.Width 3.034183e-07 6.834434e-09 2.593594e-01 4.709870e-01 $versicolor (Intercept) Sepal.Width Petal.Length Petal.Width 5.112246e-04 6.488965e-02 1.95e-06 1.255990e-01 $virginica (Intercept) Sepal.Width Petal.Length Petal.Width 1.961563e-01 6.439972e-02 1.074269e-13 3.958750e-01 Once you have a list of fitted models and can see how to extract parts of the summaries, you can reorganize what you extract to meet your needs. hope this helps, Chuck On 09/10/2007, Jiong Zhang, PhD [EMAIL PROTECTED] wrote: Hi, May I ask how I can save the coefficients and the p values into a table? thanks. jiong The email message (and any attachments) is for the sol...{{dropped:20}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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] subset data.frame with constraint of many values?
Dong-hyun Oh wrote: Dear UseRs, Let us assume that I have data.frame named as dt. dt is as follows: abcd 1345 2332 1342 3245 4536 3257 2578 . . I want to subset dt with fileds a having 2 or 3 or 4, and I wrote following code. dt[dt$a == 2 | dt$a == 3 | dt$a == 4,] Is there more efficient way for subset? subset(dt, a %in% 2:4) Thanks in advance. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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] simple averaging question?
Jeff Miller wrote: Hi all, Suppose I have a column vector of 600 measurements taken in 1s intervals. What I want is a new vector with the averages for each min (so there would be 10 entries). Is there an efficient way to do this? I’ve been doing it with a ‘for’ loop but something tells me there is a simple command that is more efficient. How about something like this? y - runif(600) df - data.frame(minute = rep(1:10, each=60), y = y) with(df, tapply(y, minute, mean)) 1 2 3 4 5 0.4664301 0.4622071 0.5159511 0.4744836 0.5282750 6 7 8 910 0.4670941 0.5091410 0.4648349 0.5227221 0.5251926 Jeff Internal Virus Database is out-of-date. Checked by AVG Free Edition. 3:09 PM [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 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] running sum of a vector
Alexy Khrabrov wrote: I need a vector with sums of vectors up to each position in the original. The imperative version is simple: # running sum: the traditional imperative way sumr.1 - function(x) { s - c() ss - 0 for (i in 1:length(x)) { ss - ss + x[i] s[i] - ss } s } Yet I want a functional way, which is shorter: # running sum: functional way, but inefficient one! sumr.2 - function(x) { sapply(1:length(x), function(i) sum(x[1:i])) } -- the problem with the latter is, we need to create indices to run over them, and the sum is recomputed anew for each position, while the imperative version iterates without recomputing. Is there a better functional solution? ?cumsum X - runif(20) sumr.1(X) [1] 0.6359909 0.9435293 1.2167988 1.6229179 [5] 2.2816672 3.2687057 4.1973724 4.4421475 [9] 4.5601287 4.7500524 5.0639924 5.5831643 [13] 6.5071247 6.9861566 7.0352500 7.6723079 [17] 7.8560394 7.9281423 8.4757938 8.9985340 sumr.2(X) [1] 0.6359909 0.9435293 1.2167988 1.6229179 [5] 2.2816672 3.2687057 4.1973724 4.4421475 [9] 4.5601287 4.7500524 5.0639924 5.5831643 [13] 6.5071247 6.9861566 7.0352500 7.6723079 [17] 7.8560394 7.9281423 8.4757938 8.9985340 cumsum(X) [1] 0.6359909 0.9435293 1.2167988 1.6229179 [5] 2.2816672 3.2687057 4.1973724 4.4421475 [9] 4.5601287 4.7500524 5.0639924 5.5831643 [13] 6.5071247 6.9861566 7.0352500 7.6723079 [17] 7.8560394 7.9281423 8.4757938 8.9985340 all(cumsum(X) == sumr.1(X)) [1] TRUE Cheers, Alexy __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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] producing output as *.spo (spss output format)
Ivan Uemlianin wrote: Dear All I am considering moving from SPSS to R as my stats environment of choice. I have read around and everything looks favourable. There is just one issue on which I have been unable to find information. Many clients ask me to send them output (tables, graphs, etc) as an spss output file (ie .spo). I haven't asked them why, I've just said yes. I know R can produce graphics as nice as SPSS, and presumably they can be output in some portable format for pasting into a word-processor document. I need to find out why the client wants spo. In the meantime let's assume they have a good reason. Can R write .spo files? Failing that does any one know of any spo writers that I could wire up to R (eg with some python gluecode)? Failing that any suggestions for overcoming the output hurdle would be welcome, as R looks very attractive (platform independent, easy to use and to automate, fast). RSiteSearch(SPSS, restrict=function) shows nothing relevant to *.spo files. I don't think you will ever see an R *.spo writer. You might look into one or more of the following to produce accessible and attractive output for clients: Sweave OdfWeave R2HTML Best wishes Ivan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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] factors levels ?
W Eryk Wolski wrote: Hi, It's just some example code.. The application is uninteresting. I am searching for some functionality. X - rnorm(100) //my data Y - seq(-3,3,by=0.1) // bin boundaries. Now I would like to generate a - list of factors, length as X... i.e.: all values in the range [-3,-2.9) have the same factor... [-3,-2.9) etc. I would assume R has such a function but I cant recall which one it is. ?cut -- Chuck Cleland, Ph.D. NDRI, Inc. 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] Effect size of comparison of two levels of a factor in multiple linear regression
(no.of.sims, sims.model[,(Intercept)] + sims.model[,treatment1], sqrt(sims.model[,sigma2])) sims.treat2 - rnorm(no.of.sims, sims.model[,(Intercept)] + sims.model[,treatment2], sqrt(sims.model[,sigma2])) # Calculate Cohen's d for simulated values cohens.d(sims.treat1, sims.treat0) [1] 3.683093 cohens.d(sims.treat2, sims.treat0) [1] 5.782622 These values are reasonably close to the ones (4 and 6) I plugged in at the beginning. It would be even nicer to have a confidence interval for them, but if I bootstrap one out of the simulated outcomes its width depends on the number of simulations and is therefore arbitrary. If anyone knew a better way to get at the effect sizes I'm looking for or how I could also get confidence intervals for them, that would be greatly appreciated. Thanks, Christoph -- Christoph Mathys, M.S. Music and Neuroimaging Laboratory Beth Israel Deaconess Medical Center and Harvard Medical School __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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] Sampling
On 2/5/2008 1:52 PM, Judith Flores wrote: Hi there, I want to generate different samples using the followindg code: g-sample(LETTERS[1:2], 24, replace=T) How can I specify that I need 12 As and 12 Bs? Thank you, Judith x - rep(c(A,B), each=12) x [1] A A A A A A A A A A A [12] A B B B B B B B B B B [23] B B # sample(x) generates a random permutation of the elements of x g - sample(x) g [1] A A B A B B B B A B A [12] A B A A A B B B A A B [23] A B Be a better friend, newshound, and __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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] Row percentages for a table object
On 2/7/2008 2:03 PM, Tom Backer Johnsen wrote: I an stumbling on something that is probably very simple, but I cannot see the solution. I have an object generated by the table () function and want to recompute this table so each cell represents the percentage of the corresponding row sum. Of course a dedicated function can be written (which I have done), containing the necessary loops etc., but there should be a simpler way. I'd prefer something simple and as transparent as possible since it is for use in a text I am writing for my students. I have fiddled around with the apply () function but have so far been unable to find something that works. Any suggestions? See ?prop.table and also possibly ?CrossTable in the gmodels package. Tom __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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] reshape question
On 2/8/2008 9:15 AM, Ista Zahn wrote: I know there are a lot of reshape questions on the mailing list, but I haven't been able to find an answer to this particular issue. I am trying to get a datafame structured like this: sub - rep(1:5) ta1 - rep(1,5) ta2 - rep(2,5) tb1- rep(3,5) tb2 - rep(4,5) DF - data.frame(sub,ta1,ta2,tb1,tb2) DF sub ta1 ta2 tb1 tb2 1 1 1 2 3 4 2 2 1 2 3 4 3 3 1 2 3 4 4 4 1 2 3 4 5 5 1 2 3 4 into a form like this: sub time x1 x2 1.1 11 1 3 1.2 12 2 4 2.1 21 1 3 2.2 22 2 4 3.1 31 1 3 3.2 32 2 4 4.1 41 1 3 4.2 42 2 4 5.1 51 1 3 5.2 52 2 4 using the reshape command. But when I try reshaping I don't get the desired structure: DF.L - reshape(DF, varying = 2:5, idvar=sub, v.names = c(x1, x2), times=c(1,2), direction=long) library(doBy) orderBy(~sub, data=DF.L) sub time x1 x2 1.1 11 1 2 1.2 12 3 4 2.1 21 1 2 2.2 22 3 4 3.1 31 1 2 3.2 32 3 4 4.1 41 1 2 4.2 42 3 4 5.1 51 1 2 5.2 52 3 4 The varying argument to reshape() can be a list. For example: DF.long - reshape(DF, varying = list(c(ta1,ta2), c(tb1,tb2)), idvar=sub, v.names = c(x1,x2), times=c(1,2), direction=long) DF.long[order(DF.long$sub),] sub time x1 x2 1.1 11 1 3 1.2 12 2 4 2.1 21 1 3 2.2 22 2 4 3.1 31 1 3 3.2 32 2 4 4.1 41 1 3 4.2 42 2 4 5.1 51 1 3 5.2 52 2 4 I can get the desired result by rearranging the original dataframe, like DF2 - data.frame(sub,ta1,tb1,ta2,tb2) before running the reshape command, but I'm hoping someone knows a way to do the desired reshaping without this step, as it becomes very time consuming with large numbers of repeated measurements. Thanks, Ista __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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] reverse vector elements
On 2/12/2008 7:47 AM, mohamed nur anisah wrote: Dear lists, I want to write a function of a vector and reverse the order of its elements. Here is my code: revector-function(n){ y=vector(length=n) for(i in n:1){ y[i]=i } return(y) } i want my output to be like this: y [1] 10 9 8 7 6 5 4 3 2 1 Any suggestion?? Thanks!! Cheers, Anisah ?rev rev(1:10) [1] 10 9 8 7 6 5 4 3 2 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. -- Chuck Cleland, Ph.D. NDRI, Inc. 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 run one-way anova R?
On 2/12/2008 8:54 AM, Kes Knave wrote: Dear all, How do I run a basic one-way anova in R? Have you read the relevant sections of An Introduction to R, as the posting guide requests? Have you tried searching for documentation using, for example: RSiteSearch(oneway ANOVA) or help.search(oneway) ?? Regards Kes [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 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] Creating a data.frame
On 2/13/2008 5:17 PM, Joe Trubisz wrote: OK...newbie question here. Either I'm reading the docs wrong, or I'm totally confused. Given the following: x-c(aaa,bbb,ccc) y-rep(0,3) z-rep(0,3) is.character(x) [1] TRUE is.numeric(y) [1] TRUE Now...I want to create a data frame, but keep the data types. In reading the docs, I assume you do it this way: d-data.frame(cbind(x=I(x),y=y,z=z) But, when I do str(d), I get the following: 'data.frame': 3 obs. of 3 variables: $ x: Factor w/ 3 levels aaa,bbb,ccc: 1 2 3 $ y: Factor w/ 1 level 0: 1 1 1 $ z: Factor w/ 1 level 0: 1 1 1 I thought the I() prevents character from becoming factors, right? Secondly, how do I force y and z in the data frame to become numeric? Don't use cbind() inside of data.frame(). Using cbind() coerces the variables into a matrix where all variables share a common type. I think you want this: d - data.frame(x=I(x), y=y, z=z) Thanks in advance Joe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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] Removing columns that are all NA from a matrix
On 2/14/2008 7:59 AM, Martin Waller wrote: Hi, I guess this might be a FAQ or something, and there's probably a nice simple way to do it, but I can't think of it: Given a matrix, I want to remove columns that are _entirely_ filled with NAs (partial NAs are fine). How please? mymat[,which(colMeans(is.na(mymat)) 1)] Thanks, Martin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 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] Levene's test for homogeneity of variances (befor using ANOVA)
On 2/14/2008 9:47 AM, Kes Knave wrote: Dear all I have tried to find this function in R, but don't find it by searching in the help function. Anybody who knows if R has the function Levene's test for homogeneity of variances? Note: Im a R-begginer I wonder how you searched for a function. For example, when I do the following: RSiteSearch(levene, restrict=function) levene.test() functions in the car and lawstat packages are the first two hits. Regards Kes [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 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] lmList, tapply() and lm()
On 2/15/2008 11:00 AM, Marc Belisle wrote: Howdee, *** I know that the lmList() function exists, yet I don't want to use it. *** Would anyone be kind enough to tell how I can apply the function lm() to each level of a given factor so to obtain the intercept and slope for each factor level within a matrix? For instance, suppose a dataframe containing 3 variables: id, x and y. I want to compute the function lm() for each level contained in id, as lmList would do... Something like this? t(sapply(split(df, list(df$id)), function(subd){coef(lm(y ~ x, data = subd))})) Thanks for your time, Marc === Marc Bélisle Professeur adjoint Chaire de recherche du Canada en écologie spatiale et en écologie du paysage Département de biologie Université de Sherbrooke 2500 Boul. de l'Université Sherbrooke, Québec J1K 2R1 Canada Tél: +1-819-821-8000 poste 61313 Fax: +1-819-821-8049 Courriél: [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. -- Chuck Cleland, Ph.D. NDRI, Inc. 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] reshaping data frame
On 2/20/2008 1:14 PM, ahimsa campos-arceiz wrote: Dear all, I'm having a few problems trying to reshape a data frame. I tried with reshape{stats} and melt{reshape} but I was missing something. Any help is very welcome. Please find details below: # # data in its original shape: indiv - rep(c(A,B),c(10,10)) level.1 - rpois(20, lambda=3) covar.1 - rlnorm(20, 3, 1) level.2 - rpois(20, lambda=3) covar.2 - rlnorm(20, 3, 1) my.dat - data.frame(indiv,level.1,covar.1,level.2,covar.2) # the values of level.1 and level.2 represent the number of cases for the particular # combination of indiv*level*covar value # I would like to do two things: # 1. reshape to long reducing my.dat[,2:5] into two colums factor (levels= level.1 level.2) # and the covariate # 2. create one new row for each case in level.1 and level.2 # the new reshaped data.frame would should look like this: # indiv factorcovar case.id # A level.1 4.6141051 # A level.1 4.6141052 # A level.2 31.0644051 # A level.2 31.0644052 # A level.2 31.0644053 # A level.2 31.0644054 # A level.1 19.1857841 # A level.2 48.4559291 # A level.2 48.4559292 # A level.2 48.4559293 # etc... # Maybe there is a better way, but this seems to do what you want: # # data in its original shape: indiv - rep(c(A,B),c(10,10)) level.1 - rpois(20, lambda=3) covar.1 - rlnorm(20, 3, 1) level.2 - rpois(20, lambda=3) covar.2 - rlnorm(20, 3, 1) my.dat - data.frame(indiv,level.1,covar.1,level.2,covar.2) long - reshape(my.dat, varying = list(c(level.1,level.2), c(covar.1,covar.2)), timevar=level, idvar=case.id, v.names=c(ncases,covar), direction=long) newdf - with(long, data.frame(indiv = rep( indiv, ncases), level = rep( level, ncases), covar = rep( covar, ncases), case.id = rep(case.id, ncases))) The idea is to first reshape() and then rep() each variable ncases times. You can then convert newdf$level into a factor if you like. Thank you very much!! Ahimsa -- Chuck Cleland, Ph.D. NDRI, Inc. 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] using subset() in data frame
On 2/22/2008 8:01 PM, Robert Walters wrote: R folks, As an R novice, I struggle with the mystery of subsetting. Textbook and online examples of this seem quite straightforward yet I cannot get my mind around it. For practice, I'm using the code in MASS Ch. 6, whiteside data to analyze a different data set with similar variables and structure. Here is my data frame: ###subset one of three cases for the variable 'position' data.b-data.a[data.a$position==inrow,] print(data.b) position porosityx y 1 inrow macro 1.40 16.5 2 inrow macro . . . .. . . . . . 7 inrow micro 8 inrow micro Now I want to do separate lm's for each case of porosity, macro and micro. The code as given in MASS, p.141, slightly modified would be: fit1 - lm(y ~ x, data=data.b, subset = porosity == macro) fit2 - update(fit1, subset = porosity == micro) ###simplest code with subscripting fit1 - lm(y ~ x, data.b[porosity==macro]) Assuming data.b has two dimensions, you need a comma after porosity==macro to indicate that you are selecting a subset of rows of the data frame: fit1 - lm(y ~ x, data.b[porosity==macro,]) ###following example in ?subset fit1 - lm(y ~ x, data.b, subset(data.b, porosity, select=macro)) The select argument to subset is meant to select variables (i.e., it indicates columns to select from a data frame) and you are misusing it by specifying the level of a factor. If you make your call to subset by itself (a good idea when you are learning how a function works), you should get an error like this: subset(whiteside, Insul, select=Before) Error in subset.data.frame(whiteside, Insul, select = Before) : 'subset' must evaluate to logical What I think you intended was this: subset(data.b, porosity == macro) Even with the correct call to subset, you also don't want both data.b and the subset piece, because subset returns a data frame. In other words, you would be passing lm() two different data frames. So try this instead: fit1 - lm(y ~ x, subset(data.b, porosity == macro)) None of th above, plus many permutations thereof, works. Can anyone educate me? Thanks, Robert Walters __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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] using subset() in data frame
On 2/23/2008 6:09 AM, Chuck Cleland wrote: On 2/22/2008 8:01 PM, Robert Walters wrote: R folks, As an R novice, I struggle with the mystery of subsetting. Textbook and online examples of this seem quite straightforward yet I cannot get my mind around it. For practice, I'm using the code in MASS Ch. 6, whiteside data to analyze a different data set with similar variables and structure. Here is my data frame: ###subset one of three cases for the variable 'position' data.b-data.a[data.a$position==inrow,] print(data.b) position porosityx y 1 inrow macro 1.40 16.5 2 inrow macro . . . .. . . .. . 7 inrow micro 8 inrow micro Now I want to do separate lm's for each case of porosity, macro and micro. The code as given in MASS, p.141, slightly modified would be: fit1 - lm(y ~ x, data=data.b, subset = porosity == macro) fit2 - update(fit1, subset = porosity == micro) ###simplest code with subscripting fit1 - lm(y ~ x, data.b[porosity==macro]) Assuming data.b has two dimensions, you need a comma after porosity==macro to indicate that you are selecting a subset of rows of the data frame: fit1 - lm(y ~ x, data.b[porosity==macro,]) Actually, that should be: fit1 - lm(y ~ x, data.b[data.b$porosity==macro,]) because [.data.frame needs to know where to find porosity, and it won't know to look inside of data.b unless you direct it to look there. ###following example in ?subset fit1 - lm(y ~ x, data.b, subset(data.b, porosity, select=macro)) The select argument to subset is meant to select variables (i.e., it indicates columns to select from a data frame) and you are misusing it by specifying the level of a factor. If you make your call to subset by itself (a good idea when you are learning how a function works), you should get an error like this: subset(whiteside, Insul, select=Before) Error in subset.data.frame(whiteside, Insul, select = Before) : 'subset' must evaluate to logical What I think you intended was this: subset(data.b, porosity == macro) Even with the correct call to subset, you also don't want both data.b and the subset piece, because subset returns a data frame. In other words, you would be passing lm() two different data frames. So try this instead: fit1 - lm(y ~ x, subset(data.b, porosity == macro)) None of th above, plus many permutations thereof, works. Can anyone educate me? Thanks, Robert Walters __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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] Bootstrapping data with a regression model
On 2/24/2008 4:03 PM, Felipe Carrillo wrote: Hello all: Just wondering if I can get advice on what kind of bootstrapping I should use when using a regression model to estimate juvenile fish passage data. I use rotary screw traps to do fish mark-recapture trials and the efficiency of every trial is added to the graph generating a different R-square and equation everytime. I plot river flows along the X axis and % trap efficiency along the Y axis. I have read about the different bootstrapping approaches but I am not sure how to do it..any help is appreciated. You might check out the the relevant web appendix by John Fox in the Contributed Documentation section of CRAN: http://cran.r-project.org/doc/contrib/Fox-Companion/appendix.html http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-bootstrapping.pdf Felipe D. Carrillo Fishery Biologist US Fish Wildlife Service California, USA Never miss a thing. Make Yahoo your home page. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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] Newbie: Where is lmFit function?
On 2/24/2008 4:02 PM, Keizer_71 wrote: Hi Everyone, I am trying to use lmFit function; however, i cannot find it function anywhere. I have been trying to find the function in Bioconductor and elsewhere. I re-install bioconductor source, update package and update R as well. no luck Is there a command in R where i can just type, and it will download it for me? RSiteSearch(lmFit) shows there is a function with that name in the limma package. -- Chuck Cleland, Ph.D. NDRI, Inc. 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] efficient is.na tabulation?
On 2/25/2008 8:59 AM, Angelo Passalacqua wrote: I am aware of table(is.na(df$var)) but is there an efficient way of create a table that shows the number of missing values in each variable of a data frame? Right now I am forced to create a new variable, varna-is.na(df$var), for each variable of the data frame, bind them to a new data frame and tabulate it, but surely there is a simpler way? any help is greatly appreciated, angelo Are you looking for colSums(is.na(df)) or colMeans(is.na(df)) ? The is.na function can be applied to whole data frames. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 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 convert a table to adjacency matrix used in social network analysis?
On 2/27/2008 3:13 AM, Samuel wrote: Hi Guys, Do you any one know how to convert a long format table to an adjacency matrix used in sna? The long table looks like p1 p2 counts a b 100 a c 200 a d 100 b c 80 b d 90 b e 100 c d 100 c e 40 d e 60 and I want to convert it to an adjacency matrix which can be used in sna? Any methods will be appreciated! The graph package has some nice tools for this. mydf - data.frame(p1=c('a','a','a','b','b','b','c','c','d'), p2=c('b','c','d','c','d','e','d','e','e'), counts=c(100,200,100,80,90,100,100,40,60)) library(graph) myadjM - ftM2adjM(as.matrix(mydf[,1:2]), W=mydf$counts) myadjM a b c d e a 0 100 200 100 0 b 0 0 80 90 100 c 0 0 0 100 40 d 0 0 0 0 60 e 0 0 0 0 0 btw, besides sna package, is there any better package can be used in social network analysis, specially good at plotting? For plotting I would look into the Rgraphviz package. Here is a simple diagram of the network: library(Rgraphviz) mygraph - ftM2graphNEL(as.matrix(mydf[,1:2]), W=mydf$counts) plot(mygraph) I'm not sure how to incorporate the weights for each edge into the diagram, but maybe that is explained in the documentation for the sna and Rgraphviz packages. Thanks in advance! Regards, -- Chuck Cleland, Ph.D. NDRI, Inc. 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] Kaiser-Meyer-Olkin
On 2/28/2008 1:42 AM, Robert Kopp wrote: I am a beginner when it comes to using R, though fortunately I already know something about statistics. I think factor analysis should be used sparingly, but I occasionally use it. It doesn't seem to me that factanal() provides Kaiser's Measure of Sampling Adequacy, which should be computed for factor problems based on a small number of subjects, though perhaps it is elsewhere. Does anyone know? (Better yet, is there a complete list of procedures that can be performed by all available packages?) I have coded MSA in C++, so I could add it if it is not yet available. In that case I suppose I should find out how to submit it. See this post from the archives: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/106430.html which I found using RSiteSearch(Kaiser sampling adequacy). I don't know of a complete list of all procedures (functions) in all packages, but, among other things, RSiteSearch() is very useful when the question is, Is there a package or function to do X? Robert Tim Kopp http://analytic.tripod.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. -- Chuck Cleland, Ph.D. NDRI, Inc. 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] I need to buy a book in R
On 3/3/2008 2:27 PM, kayj wrote: Hi All, I am a new user in R and I would like to buy a book that teaches me how to use R. In addition, I may nees to do some advanced statistical analysis. Does anyone recommend some books or websites where I can learn R. I would start with An Introduction to R, which is available here: http://cran.r-project.org/manuals.html You might find some of the contributed documentation (organized by language and length) useful: http://cran.r-project.org/other-docs.html Depending on what your background and interests are, one of the books on this list may meet your needs: http://www.r-project.org/doc/bib/R-books.html Thanks -- Chuck Cleland, Ph.D. NDRI, Inc. 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] subsetting a dataframe
On 3/4/2008 8:41 AM, John Sorkin wrote: windows XP R 2.6.0 I am having problems deleting a row from a data frame. I create my dataframe by subsetting a larger dataframe: ShortLavin-Lavin[Lavin[,Site]==PP | Lavin[,Site]==CC | Lavin[,Site]==FH,] I would do that in the following way: ShortLavin - subset(Lavin, Site %in% c(PP,CC,FH)) I then perform a glm using the data frame and plot the results. fit1poisson-glm(NumUniqOpPt~Seq+Site,family=poisson(link = log),data=ShortLavin,offset=log(NumUniqPt)) plot(fit1poisson) Of course, you could have done the subsetting within the call to glm: fit1poisson - glm(NumUniqOpPt~Seq+Site,family=poisson(link = log), data=subset(Lavin, Site %in% c(PP,CC,FH)), offset=log(NumUniqPt)) On the plots I see a point labeled as 127 that is an extreme value. I want to re-run the glm excluding the extreme observation. I have tried several methods to exclude the observation (shown below), none have worked. Minus127-ShortLavin[-127,] Minus127-ShortLavin[-127,] Minus127-ShortLavin[-c(127),] Minus127-ShortLavin[-c(127),] None of these worked. Suggestions on how I can remove observation 127 would be appreciated Minus127 - subset(ShortLavin, !rownames(ShortLavin) %in% 127) Thank you, John John Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) Confidentiality Statement: This email message, including any attachments, is for th...{{dropped:6}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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] Asking, are simple effects different from 0
On 3/4/2008 2:45 PM, Jarrett Byrnes wrote: Hello, R-i-zens. I'm working on an data set with a factorial ANOVA that has a significant interaction. I'm interested in seeing whether the simple effects are different from 0, and I'm pondering how to do this. So, I have my.anova-lm(response ~ trtA*trtB) The output for which gives me a number of coefficients and whether they are different from 0. However, I want the simple effects only, incorporating their intercepts, with their error estimates. Can I somehow manipulate this object to get that? Or, would a good shortcut be my.simple.anova-lm(response ~ trtA:trtB + 0) and then use those coefficients and their error estimates? One approach would be to use glht() in the multcomp package. You need to work out how to formulate the matrix of coefficients that give the desired contrasts. Here is an example using the warpbreaks data frame: fm - lm(breaks ~ tension*wool, data=warpbreaks) # names(coef(fm)) # (Intercept) tensionM tensionH woolB tensionM:woolB tensionH:woolB cm - rbind( A vs. B at L = c(0, 0, 0,-1, 0, 0), A vs. B at M = c(0, 0, 0,-1,-1, 0), A vs. B at H = c(0, 0, 0,-1, 0,-1), M vs. L at A = c(0, 1, 0, 0, 0, 0), M vs. H at A = c(0, 1,-1, 0, 0, 0), L vs. H at A = c(0, 0,-1, 0, 0, 0), M vs. L at B = c(0, 1, 0, 0, 1, 0), M vs. H at B = c(0, 1,-1, 0, 1,-1), L vs. H at B = c(0, 0,-1, 0, 0,-1)) library(multcomp) summary(glht(fm, linfct = cm), test = adjusted(type=none)) Simultaneous Tests for General Linear Hypotheses Fit: lm(formula = breaks ~ tension * wool, data = warpbreaks) Linear Hypotheses: Estimate Std. Error t value p value A vs. B at L == 0 16. 5.1573 3.167 0.002677 ** A vs. B at M == 0 -4.7778 5.1573 -0.926 0.358867 A vs. B at H == 0 5.7778 5.1573 1.120 0.268156 M vs. L at A == 0 -20.5556 5.1573 -3.986 0.000228 *** M vs. H at A == 0 -0.5556 5.1573 -0.108 0.914665 L vs. H at A == 0 20. 5.1573 3.878 0.000320 *** M vs. L at B == 0 0.5556 5.1573 0.108 0.914665 M vs. H at B == 0 10. 5.1573 1.939 0.058392 . L vs. H at B == 0 9. 5.1573 1.831 0.073270 . --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Adjusted p values reported -- none method) If so, I realize that R gives me t tests for each coefficient. Now, for those I know I'm using the residual degrees of freedom. Would it then be more appropriate to use those, all with the same residual DF and apply a bonferroni correction, or, use the mean and SE estimate with the sample size for that particular treatment and perform an uncorrected one sample t-test to see if the value is different from 0? I won't comment on whether to adjust and if so how, but you can implement various adjustments when summarizing. For example: summary(glht(fm, linfct = cm), test = adjusted(type=bonferroni)) Simultaneous Tests for General Linear Hypotheses Fit: lm(formula = breaks ~ tension * wool, data = warpbreaks) Linear Hypotheses: Estimate Std. Error t value p value A vs. B at L == 0 16. 5.1573 3.167 0.02409 * A vs. B at M == 0 -4.7778 5.1573 -0.926 1.0 A vs. B at H == 0 5.7778 5.1573 1.120 1.0 M vs. L at A == 0 -20.5556 5.1573 -3.986 0.00205 ** M vs. H at A == 0 -0.5556 5.1573 -0.108 1.0 L vs. H at A == 0 20. 5.1573 3.878 0.00288 ** M vs. L at B == 0 0.5556 5.1573 0.108 1.0 M vs. H at B == 0 10. 5.1573 1.939 0.52553 L vs. H at B == 0 9. 5.1573 1.831 0.65943 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Adjusted p values reported -- bonferroni method) Sorry for the bonehead question, but it's a situation I haven't seen before. -Jarrett __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 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] Asking, are simple effects different from 0
On 3/5/2008 10:09 AM, jebyrnes wrote: Huh. Very interesting. I haven't really worked with manipulating contrast matrices before, save to do a prior contrasts. Could you explain the matrix you laid out just a bit more so that I can generalize it to my case? Each column corresponds to one of the coefficients in the model, and each row specifies a particular contrast. The numbers in the matrix indicate how the model coefficients are combined to indicate a particular difference in means. For example, the first row indicates that the third coefficient (woolB) is multiplied by -1. The baseline categories are A and L for the wool and tension factors, so the woolB effect in fm is the simple effect of B vs. A in the baseline category of the tension factor. Multiplying this coefficient by -1 produces an A vs. B comparison in the baseline category of the tension factor. When I want to check that contrasts are as intended, I use contrast() in the contrast package (by Steve Weston, Jed Wing, Max Kuhn). That function allows you to specify factor levels by name to construct the contrast. For example: library(contrast) # M vs. H at B contrast(fm, a=list(tension = M, wool = B), b=list(tension = H, wool = B)) lm model parameter contrast Contrast S.E. LowerUppert df Pr(|t|) 10 5.157299 -0.3694453 20.36945 1.94 48 0.0584 It also allows you to print the design matrix for a contrast: contrast(fm, a=list(tension = M, wool = B), b=list(tension = H, wool = B))$X (Intercept) tensionM tensionH woolB tensionM:woolB tensionH:woolB 1 01 -1 0 1 -1 Chuck Cleland wrote: One approach would be to use glht() in the multcomp package. You need to work out how to formulate the matrix of coefficients that give the desired contrasts. Here is an example using the warpbreaks data frame: fm - lm(breaks ~ tension*wool, data=warpbreaks) # names(coef(fm)) # (Intercept) tensionM tensionH woolB tensionM:woolB tensionH:woolB cm - rbind( A vs. B at L = c(0, 0, 0,-1, 0, 0), A vs. B at M = c(0, 0, 0,-1,-1, 0), A vs. B at H = c(0, 0, 0,-1, 0,-1), M vs. L at A = c(0, 1, 0, 0, 0, 0), M vs. H at A = c(0, 1,-1, 0, 0, 0), L vs. H at A = c(0, 0,-1, 0, 0, 0), M vs. L at B = c(0, 1, 0, 0, 1, 0), M vs. H at B = c(0, 1,-1, 0, 1,-1), L vs. H at B = c(0, 0,-1, 0, 0,-1)) library(multcomp) summary(glht(fm, linfct = cm), test = adjusted(type=none)) Simultaneous Tests for General Linear Hypotheses Fit: lm(formula = breaks ~ tension * wool, data = warpbreaks) Linear Hypotheses: Estimate Std. Error t value p value A vs. B at L == 0 16. 5.1573 3.167 0.002677 ** A vs. B at M == 0 -4.7778 5.1573 -0.926 0.358867 A vs. B at H == 0 5.7778 5.1573 1.120 0.268156 M vs. L at A == 0 -20.5556 5.1573 -3.986 0.000228 *** M vs. H at A == 0 -0.5556 5.1573 -0.108 0.914665 L vs. H at A == 0 20. 5.1573 3.878 0.000320 *** M vs. L at B == 0 0.5556 5.1573 0.108 0.914665 M vs. H at B == 0 10. 5.1573 1.939 0.058392 . L vs. H at B == 0 9. 5.1573 1.831 0.073270 . --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Adjusted p values reported -- none method) -- Chuck Cleland, Ph.D. NDRI, Inc. 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] Asking, are simple effects different from 0
On 3/5/2008 1:32 PM, jebyrnes wrote: Ah. I see. So, if I want to test to see whether each simple effect is different from 0, I would do something like the following: cm2 - rbind( A:L = c(1, 0, 0, 0, 0, 0), A:M = c(1, 1, 0, 0, 0, 0), A:H = c(1, 0, 1, 0, 0, 0), B:L = c(1, 0, 0, 1, 0, 0), B:M = c(1, 1, 0, 1, 1, 0), B:H = c(1, 0, 1, 1, 0, 1)) That does not corresponds to what I think of as the simple effects. That specifies the six cell means, but it does not *compare* any cell means. I think of a simple effect as the effect of one factor at a specific level of some other factor. summary(glht(fm, linfct = cm2), test = adjusted(type=none)) Correct? What is the df on those t-tests then? Is it 48? Yes, df = 48 for each contrast. Interestingly, I find this produces results no different than fm2-lm(breaks ~ tension:wool+0, data=warpbreaks) summary(fm2) Yes, but those are not what I would call the simple effects. Those are essentially one-sample t-tests for each of the 6 cell means. Also, here, it would seem each t-test was done with the full 48df. Hrm. The df are based on the whole model, not the 9 observations in one cell. Chuck Cleland wrote: Each column corresponds to one of the coefficients in the model, and each row specifies a particular contrast. The numbers in the matrix indicate how the model coefficients are combined to indicate a particular difference in means. For example, the first row indicates that the third coefficient (woolB) is multiplied by -1. The baseline categories are A and L for the wool and tension factors, so the woolB effect in fm is the simple effect of B vs. A in the baseline category of the tension factor. Multiplying this coefficient by -1 produces an A vs. B comparison in the baseline category of the tension factor. -- Chuck Cleland, Ph.D. NDRI, Inc. 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] Asking, are simple effects different from 0
On 3/5/2008 3:19 PM, jebyrnes wrote: Indeed, but are not each of the cell means also evaluations of the effect of one factor at the specific level of another factor? Is this an issue of Tomato, tomahto. I don't think it is tomato, tomahto. Say the grand mean is around 100 and the within cell standard deviations are around 10. You could easily have a situation in which all of the cell means are significantly different from 0, but there is nothing at all interesting going on with the two explanatory factors. In other words, the cell means can be very different from 0 with no explanatory variable effects of any kind, based only on the overall location of the response. I guess my question is, if I want to know if each of those is different from 0, then should I use the 48df from the full model, or the 9 for each cell? Chuck Cleland wrote: That does not corresponds to what I think of as the simple effects. That specifies the six cell means, but it does not *compare* any cell means. I think of a simple effect as the effect of one factor at a specific level of some other factor. summary(glht(fm, linfct = cm2), test = adjusted(type=none)) Correct? What is the df on those t-tests then? Is it 48? Yes, df = 48 for each contrast. Interestingly, I find this produces results no different than fm2-lm(breaks ~ tension:wool+0, data=warpbreaks) summary(fm2) Yes, but those are not what I would call the simple effects. Those are essentially one-sample t-tests for each of the 6 cell means. Also, here, it would seem each t-test was done with the full 48df. Hrm. The df are based on the whole model, not the 9 observations in one cell. -- Chuck Cleland, Ph.D. NDRI, Inc. 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] Correlation matrix one side with significance
On 3/6/2008 2:07 PM, Martin Kaffanke wrote: Am Mittwoch, den 05.03.2008, 14:38 -0300 schrieb Henrique Dallazuanna: Try this: On 05/03/2008, Martin Kaffanke [EMAIL PROTECTED] wrote: Hi there! In my case, cor(d[1:20]) makes me a good correlation matrix. Now I'd like to have it one sided, means only the left bottom side to be printed (the others are the same) and I'd like to have * where the p-value is lower than 0.05 and ** lower than 0.01. How can I do this? d - matrix(rexp(16, 2), 4) corr - cor(d) sign - symnum(cor(d), cutpoints=c(0.05, 0.01), corr = T, symbols=c(***, **, *), abbr=T, diag=F) noquote(mapply(function(x, y)paste(x, format(y, dig=3), sep=''), as.data.frame(unclass(sign)), as.data.frame(corr))) Seems that we mark the value itself, but not the p-value. So lets say, in a way I have to get the lower left half of a cor(el[1:20]) Then I need to calc all the values with a cor.test() to see for the p-value. And the p-value should be lower than .05 or .01 - this should make the * to the value. Thanks, Martin Do you want something like the following, but with the upper triangle removed? corstars - function(x){ require(Hmisc) x - as.matrix(x) R - rcorr(x)$r p - rcorr(x)$P mystars - ifelse(p .01, **|, ifelse(p .05, * |, |)) R - format(round(cbind(rep(-1.111, ncol(x)), R), 3))[,-1] Rnew - matrix(paste(R, mystars, sep=), ncol=ncol(x)) diag(Rnew) - paste(diag(R), |, sep=) rownames(Rnew) - colnames(x) colnames(Rnew) - paste(colnames(x), |, sep=) Rnew - as.data.frame(Rnew) return(Rnew) } corstars(swiss[,1:4]) Fertility| Agriculture| Examination| Education| Fertility 1.000 | 0.353* |-0.646**| -0.664**| Agriculture 0.353* | 1.000 |-0.687**| -0.640**| Examination -0.646**|-0.687**| 1.000 | 0.698**| Education-0.664**|-0.640**| 0.698**| 1.000 | I will leave the removing the upper triangle part to you - should be examples in the archives. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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] Finding Interaction and main effects contrasts for two-wayANOVA
) # ignoring the second available df contrasts(twoway$material) [,1] [,2] 11 -0.41 2 -1 -0.41 30 0.82 contrasts(twoway$temp) [,1] [,2] 500 -0.82 651 0.41 80 -1 0.41 summary.aov(fit, split=list(material=list('m1-m2'=1), temp=list ('t50 - t80'=1))) Df Sum Sq Mean Sq F value Pr(F) material 2 1068453427.91 0.00198 ** material: m1-m2 1 380038005.63 0.02506 * temp 2 39119 19559 28.97 1.9e-07 *** temp: t50 - t80 1 11310 11310 16.75 0.00035 *** material:temp 4 961424033.56 0.01861 * material:temp: m1-m2.t50 - t80 1 497049707.36 0.01146 * Residuals27 18231 675 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 # other examples of setting contrasts # compare m1 vs m2 and m2 vs m3 contrasts(twoway$material) - matrix(c(1,-1,0,1,1,-2), nrow=3) contrasts(twoway$material) [,1] [,2] 110 2 -11 30 -1 # compare m1 vs m2 and m1+m2 vs m3 contrasts(twoway$material) - matrix(c(1,-1,0,1,1,-2), nrow=3) contrasts(twoway$material) [,1] [,2] 111 2 -11 30 -2 I'm not sure if 'summary.aov' is the only lm-family summary method with the split argument. DaveT. * Silviculture Data Analyst Ontario Forest Research Institute Ontario Ministry of Natural Resources [EMAIL PROTECTED] http://ofri.mnr.gov.on.ca * -Original Message- From: Steele [mailto:[EMAIL PROTECTED] Sent: March 6, 2008 09:08 PM To: [EMAIL PROTECTED] Subject: [R] Finding Interaction and main effects contrasts for two-way ANOVA I've tried without success to calculate interaction and main effects contrasts using R. I've found the functions C(), contrasts(), se.contrasts() and fit.contrasts() in package gmodels. Given the url for a small dataset and the two-way anova model below, I'd like to reproduce the results from appended SAS code. Thanks. --Dale. ## the dataset (from Montgomery) twoway - read.table(http://dsteele.veryspeedy.net/sta501/ twoway.txt, col.names=c('material', 'temp','voltage'),colClasses=c('factor', 'factor', 'numeric')) ## the model fit - aov(voltage ~ material*temp, data=twoway) /* SAS code */ proc glm data=twoway; class material temp; model voltage = material temp material*temp; contrast '21-22-31+32' material*temp 0 0 0 1 -1 0 -1 1 0; estimate '21-22-31+32' material*temp 0 0 0 1 -1 0 -1 1 0; contrast 'material1-material2' material 1 -1 0; estimate 'material1-material2' material 1 -1 0; contrast 'temp50 - temp80' temp 1 0 -1; estimate 'temp50 - temp80' temp 1 0 -1; run; __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- Chuck Cleland, Ph.D. NDRI, Inc. 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] Weighting data when running regressions
On 3/10/2008 7:49 AM, Elena Wilson wrote: Dear R-Help, I'm new to R and struggling with weighting data when I run regression. I've tried to use search to solve my problem but haven't found anything helpful so far. I (successfully) import data from SPSS (15) and try to run a linear regression on a subset of my data file where WEIGHT is the name of my weighting variable (numeric), e.g.: library(foreign) data1=read.spss(File.sav, use.value.labels = FALSE, to.data.frame = TRUE) summary(data1) ' shows me all the variables OK attach(data1) linmod=lm(Y~X1+X2+X3+X4W, subset=(X5==1 X6==7), weights==WEIGHT) and I get the following Error message: Error in weights == WEIGHT : comparison (1) is possible only for atomic and list types It works perfectly if I don't use the , weights==WEIGHT bit Try it with just one equals sign after weights: linmod=lm(Y~X1+X2+X3+X4W, subset=(X5==1 X6==7), weights=WEIGHT) Could you please let me know what I am doing wrong? Thank you in advance, Lena [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 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 get the value of last element in a vector/array ?
On 3/15/2008 1:30 AM, Ng Stanley wrote: Hi, a[length(a)] gives the value of last element. Is there an alternative without using functions ? I'm not sure what you mean by without using functions, but how about this: tail(a, 1) ?tail [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] locating minimum value in matrix
On 3/15/2008 7:47 PM, Gonçalo Ferraz wrote: Hi, I have a matrix BEE and want to find the row and column numbers of the minimum value in that matrix. The command which(BEE==min(BEE)) returns only one value which, I take, is the position of the minimum in a vector with as many elements as the matrix. Is there a quick and simple way of getting row and column numbers? See the second argument to which(). which(BEE==min(BEE), arr.ind=TRUE) Thanks, Gonçalo [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 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] MDS
On 3/23/2008 2:28 PM, Sharma, Manju wrote: hello what is the function for multidimensional scaling in R? cheers manju Here are two ways to search for specific functionality in R: RSiteSearch(multidimensional scaling, restrict=functions) help.search(multidimensional scaling) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] maximum of identical elements in a vector
On 3/30/2008 5:35 PM, Daniel Malter wrote: Hi, the problem I have is seemingly very simple, but not simple enough for me to figure out. I just want to find the most (or least) frequent element in the vector. a=c(Alice,Alice,Alice,Alice,Bob,Bob) unique(a) length(which(a==Alice)) unique(a) shows me that the elements in my vector are Alice and Bob. The latter expression gives 4 as the frequency of Alice in vector a. To find the maximum frequency of the unique elements, however, it assumes that I know that Alice is the most (or least) frequent element. Therefore, how can find that Alice is the most frequent element in this vector? I assume there is an easier way than computationally intensive loops (for long vectors). names(which.max(table(a))) [1] Alice Cheers, Daniel - cuncta stricte discussurus __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Reverse seq
On 3/31/2008 6:31 AM, Mario Maiworm wrote: Hi all, I thought I was not SUCH a nooby:) How can I reverse a sequence/ vector? i.e., turn X - 3 5 4 2 6 5 4 3 6 Into X - 6 3 4 5 6 2 4 5 3 I mean without looping and indexing. There should be a very easy solution, shouldn't it? rev(X) [1] 6 3 4 5 6 2 4 5 3 ?rev Mario __ Mario Maiworm Biological Psychology and Neuropsychology University of Hamburg Von-Melle-Park 11 D-20146 Hamburg Phone: +49 40 42838 3515 Fax: +49 40 42838 6591 http://bpn.uni-hamburg.de/Maiworm_e.html http://cinacs.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. -- 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] convert delimited string to vector
On 3/31/2008 9:43 AM, Brad Christoffersen wrote: Hi R Users, Simple question: How might I convert the text a, b, c (or for that matter a b c with any delimiter - space, comma, etc.) into a 3-element character vector? [1] a b c Thanks, Brad unlist(strsplit(a b c, split= )) [1] a b c unlist(strsplit(a, b, c, split=, )) [1] a b c ?strsplit __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] SAS-like method of recoding variables?
On 6/22/2009 2:27 PM, Mark Na wrote: Dear R-helpers, I am helping a SAS user run some analyses in R that she cannot do in SAS and she is complaining about R's peculiar (to her!) way of recoding variables. In particular, she is wondering if there is an R package that allows this kind of SAS recoding: IF TYPE='TRUCK' and count=12 THEN VEHICLES=TRUCK+((CAR+BIKE)/2.2); Thanks for any help or suggestions you might be able to provide! If the variables are in a data frame called mydf, she might do something like this: mydf$VEHICLE - with(mydf, ifelse(TYPE=='TRUCK' count==12, TRUCK+((CAR+BIKE)/2.2), NA)) or mydf - transform(mydf, VEHICLE = ifelse(TYPE=='TRUCK' count==12, TRUCK+((CAR+BIKE)/2.2), NA)) Mark Na __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] vector and NA
On 6/23/2009 5:41 AM, Alfredo Alessandrini wrote: Hi, I've a vector like this: -- inc[,5] [1]NANANANANANANA [8]NANANANANANANA [15]NANANANANANANA [22]NANANANANANANA [29]NANANANANANANA [36]NANANANANANANA [43]NANANANANANANA [50]NANANANANANANA [57]NANANANANANANA [64]NANANANANANANA [71]NANANANANANANA [78]NANANANA 13.095503 10.140119 7.989186 [85] 8.711888 7.201234 13.029250 14.430755 8.662832 8.810785 14.421302 [92] 7.614985 7.548091 9.843389 14.977402 20.875255 7.787543 2.005056 [99] 4.016916 3.601773 4.140390 7.241999 13.280794 18.038902 18.762169 [106] 4.280065 5.942021 6.292010 11.866446 19.450442 11.942362 6.224328 [113] 3.176050 5.456117 2.733487 3.992823 13.633171 19.514301 25.085256 [120] 5.640089 5.890486 12.421150 18.821420 22.478664 11.503805 7.051254 [127] 7.560921 12.000394 20.464875 16.147598 13.746290 9.416060 35.848221 [134] 36.739481 23.516759 7.317599 3.928247 10.371437 11.202935 12.574649 [141] 6.906980 9.191260 7.080267 2.810271 5.494705 10.617141 14.578020 [148] 10.981610 7.343975 2.179511 2.726651 10.794842 9.872493 19.842701 [155] 10.525064 16.134541 29.283385 18.352996 9.216318 6.253805 2.704267 [162] 4.274514 3.138237 12.296835 20.982433 13.001104 2.606328 3.333271 [169] 5.514425 2.179244 5.381514 6.848380 3.794428 5.114591 4.975830 [176] 3.809948 10.131608 14.145913 --- How can I extract a vector without the NA value? na.omit(inc[,5]) ?na.omit Regards, Alfredo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] distinguish regression lines in grouped, black and white lattice xyplot
On 6/24/2009 3:28 PM, Katharina May wrote: Hi, I've got the following problem which I cannot think of a solution right now: if got a lattice xyplot in black and white and a grouping variable with many (more than 8 values) and I plot it as regression lines (type=r), just like this one (not reproducable but that's I guess not the point here): xyplot(log(AGWB) ~ log(BM_roots), data=sub_agwb_data, groups=species, type=r, lty=c(1:6),panel=allo.panel.5) The problem is that I've got 26 different values for the grouping variable species and only 6 default values for the line type lty (and according to the par {graphics} help page customizable to up to 8 different line types). Does anybody have any idea how these 26 different lines can be made distinguishable from each other without the use of colors? If you need to distinguish individual regression lines, I would consider 26 panels rather than attempting one panel with 26 regression lines each of a different line type. Something like this: xyplot(log(AGWB) ~ log(BM_roots) | species, data=sub_agwb_data, type=r, panel=allo.panel.5) Thanks, Katharina __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] variable driven summary of one column
On 6/25/2009 5:44 AM, Anne Skoeries wrote: Hello, how can I get a variable driven summary of one column of my data.frame? Usually I would do summary(data$columnname) to get a summary of column named columnname of my data.frame named data. In my case the columnname is not static but can be set dynamically. So I save the chosen columname in something like variable - columnname but how can I now get the summary of the specified column? summary(data$get(variable)) doesn't work. summary(paste(data$, variable, sep=) doesn't work either! and if I try summary(data[get(variable)] it gives me back a different result since the data isn't a factor anymore but a list. vname - Species summary(subset(iris, select=vname)) Species setosa:50 versicolor:50 virginica :50 vname - Sepal.Width summary(subset(iris, select=vname)) Sepal.Width Min. :2.000 1st Qu.:2.800 Median :3.000 Mean :3.057 3rd Qu.:3.300 Max. :4.400 Thanks for the help, Anne __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] assessing data variation
On 7/10/2009 5:21 AM, e-letter wrote: I have data like so: time datum 3012 6024 9037 120 41 150 8 In addition to standard deviation, I want to measure the average of the differences in data for each time interval, i.e. average of 24-12, 37-24, 41-37, 8-41. Is there a statistical term for this task? Which package should I use please? I don't know a term for it, but you might try something like this: mydf - data.frame(time = c(30,60,90,120,150), datum = c(12,24,37,41,8)) diff(mydf$datum) [1] 12 13 4 -33 mean(abs(diff(mydf$datum))) [1] 15.5 ?diff rh...@conference.jabber.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. -- 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] duplicate data points on a line graph
On 7/15/2009 2:19 PM, NDC/jshipman wrote: Hi, I am new to R plot. I am trying to increase the data point observation when duplicate data points exist xy 110 110 23 45 9 8 in the about example 1, 10 would be displayed larger than the other data points. Could someone give me some assistance with this problem A couple of simple approaches: x - c(1,1,2,4,9) y - c(10,10,3,5,8) plot(jitter(x), jitter(y)) plot(x, y, cex=c(2,2,1,1,1)) 757-864-7114 LARC/J.L.Shipman/jshipman jeffery.l.ship...@nasa.gov __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] duplicate data points on a line graph
On 7/15/2009 9:56 PM, Carl Witthoft wrote: If you want to take the second approach, it can be relatively easily generalized by calculating the cex values based on the count of ordered pairs in the original dataset. Here's a data set: xy x y [1,] 1 4 [2,] 1 5 [3,] 2 3 [4,] 3 3 [5,] 4 5 [6,] 5 2 [7,] 1 4 [8,] 2 3 Here's the same set fully sorted: xy[order(x,y),]-xyord x y [1,] 1 4 [2,] 1 4 [3,] 1 5 [4,] 2 3 [5,] 2 3 [6,] 3 3 [7,] 4 5 [8,] 5 2 There's gotta be some very simple way to create a series of values for cex but I'm missing it, other than a loop like cexvec-rep(1,8) for i in 2:8 { if (xyord[i,1]==xyord[i-1,1] xyord[i,2]== xyord[i-1,2] ) { cexvec[i]-cexvec[i-1]+1 } } How about using ave() like this: x - sample(0:4, 60, replace=TRUE) y - sample(0:4, 60, replace=TRUE) xy - data.frame(x, y) xy$freq - ave(xy$x, x, y, FUN=length) with(xy, plot(x, y, cex=freq)) You get the idea, sort of :-) Carl On 7/15/2009 2:19 PM, NDC/jshipman wrote: Hi, I am new to R plot. I am trying to increase the data point observation when duplicate data points exist xy 110 110 23 45 9 8 in the about example 1, 10 would be displayed larger than the other data points. Could someone give me some assistance with this problem A couple of simple approaches: x - c(1,1,2,4,9) y - c(10,10,3,5,8) plot(jitter(x), jitter(y)) plot(x, y, cex=c(2,2,1,1,1)) 757-864-7114 LARC/J.L.Shipman/jshipman Jeffery.L.Shipman at nasa.gov __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] calculating median with a condition
On 7/20/2009 2:59 PM, Manisha Brahmachary wrote: Hello, I am trying to calculate the median of numbers across each row for the data shown below , with the condition that if the number is negative, that it should be ignored and the median should be taken of only the positive numbers. For eg: data is in Column A,B,C. Column D and E demonstrates what I want to get as answer A B C Median median value -13.6688115 -32.50914055 -50.54011892 all negative, so ignore NA NA -53.65656268 42.58599666 median C 42.58599666 33.30683089 18.93765489 -25.17024229 median A,B 26.12224289 The R script I have written is below( which doesnot do the job properly) median.value- matrix(nrow=nrow(data),ncol=1) for(k in 1:nrow(data)){ median.value[k]-median(data[which(data[k,]0)])} Can someone suggest me the correct R script to do what I have explained above. X - as.data.frame(matrix(rnorm(100), ncol=10)) apply(X, 1, function(x){median(x[x 0])}) [1] 0.2297943 0.6476565 0.4699609 0.8744830 [5] 1.0242502 0.7800703 0.6648436 0.2930191 [9] 0.6001506 1.0767194 Thanks Manisha [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to transform m/d/yyyy to yyyymmdd?
On 7/21/2009 1:16 PM, liujb wrote: Hello, I have a set of data that has a Date column looks like this: 12/9/2007 12/16/2007 1/1/2008 1/3/2008 1/12/2008 etc. I'd like the date to look something like the follow (so that I could sort by date easily). 20071209 20071216 20080101 20080103 20080112 How to do it? Thank you very much Julia dates - c(2/27/1992, 2/27/1992, 1/14/1992, 2/28/1992, 2/1/1992) as.character(as.Date(dates, %m/%d/%Y), %Y%m%d) [1] 19920227 19920227 19920114 19920228 19920201 ?as.Date -- 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] Find multiple elements in a vector
On 7/22/2009 3:32 PM, Michael Knudsen wrote: Hi, Given a vector, say x=sample(0:9,10) x [1] 0 6 3 5 1 9 7 4 8 2 I can find the location of an element by which(x==2) [1] 10 but what if I want to find the location of more than one number? I could do c(which(x==2),which(x==3)) but isn't there something more streamlined? My first guess was y=c(2,3) which(x==y) integer(0) which doesn't work. I haven't found any clue in the R manual. How about this? which(x %in% c(2,3)) Thanks! -- 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] Calculate weighted mean for each group
On 7/23/2009 5:18 PM, Alexis Maluendas wrote: Hi R experts, I need know how calculate a weighted mean by group in a data frame. I have tried with aggragate() function: data.frame(x=c(15,12,3,10,10),g=c(1,1,1,2,2,3,3),w=c(2,3,1,5,5,2,5)) - d aggregate(d$x,by=list(d$g),weighted.mean,w=d$w) Generating the following error: Error en FUN(X[[1L]], ...) : 'x' and 'w' must have the same length DF - data.frame(x=c(15,12, 3,10,10,14,12), g=c( 1, 1, 1, 2, 2, 3, 3), w=c( 2, 3, 1, 5, 5, 2, 5)) sapply(split(DF, DF$g), function(x){weighted.mean(x$x, x$w)}) 123 11.5 10.0 12.57143 Thanks in advance [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Welch Anova ?
On 7/24/2009 2:51 AM, Hardi wrote: Hi, I need to do factor analysis with non-constant variance. Is there a package that contains Welch ANOVA ? Thanks, ?oneway.test __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] metafor
On 7/24/2009 11:40 AM, Frank Pearson wrote: I had found the author's (Wolfgang Viechtbauer) earlier meta-analytic code in R, MiMa, useful. so I have been exploring metafor using an example dataset from MiMa. metafor provides a lot more. However, MiMa provided parameter estimates, standard errors, z values, etc. for individual moderators in the meta-analysis, but I don't see how to obtain these from metafor. Have you any help about how to get this? Frank Hi Frank: Which function in the metafor package are you using to fit the meta-regression model? The following works for me to reproduce one of the analyses in the MiMa Tutorial (http://www.wvbauer.com/downloads/mima_tutorial.pdf): library(metafor) f - STUDY N1 N2 YI VI MINUTES TRAINED MEANAGE 1 30 30 0.444 0.068 30 0 28 2 46 39 -0.495 0.049 10 0 42 3 15 15 0.195 0.134 20 1 31 4 10 10 0.546 0.207 40 1 39 5 12 12 0.840 0.181 20 1 17 6 10 10 0.105 0.200 30 1 51 7 26 24 0.472 0.082 15 1 26 8 18 14 -0.205 0.128 10 0 64 9 12 12 1.284 0.201 45 1 48 10 12 12 0.068 0.167 30 1 40 11 15 15 0.234 0.134 30 1 52 12 12 12 0.811 0.180 30 1 33 13 15 15 0.204 0.134 30 1 20 14 18 18 1.271 0.134 60 1 27 15 15 15 1.090 0.153 45 1 52 16 43 35 -0.059 0.052 10 1 61 madf - read.table(textConnection(f), sep= , header=TRUE) rma(YI, VI, mods=cbind(MINUTES, TRAINED, MEANAGE), data=madf) Mixed-Effects Model (k = 16; tau^2 estimator: REML) tau^2 (estimate of residual amount of heterogeneity): 0 (SE = 0.0472) tau (sqrt of the estimate of residual heterogeneity): 0 Test for Residual Heterogeneity: QE(df = 12) = 9.1238, p-val = 0.6923 Test of Moderators (coefficient(s) 2,3,4): QM(df = 3) = 28.8348, p-val = 0 Model Results: estimate se zvalpvalci.lb ci.ub intrcpt -0.2956 0.3488 -0.8473 0.3968 -0.9792 0.3881 MINUTES0.0250 0.0067 3.7149 0.0002 0.0118 0.0381 *** TRAINED0.3011 0.1953 1.5415 0.1232 -0.0817 0.6839 MEANAGE -0.0060 0.0063 -0.9518 0.3412 -0.0182 0.0063 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 sessionInfo() R version 2.9.1 (2009-06-26) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] metafor_0.5-0 hope this helps, Chuck [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] edit.row.names taking row names from the edited dataframe
On 7/30/2009 2:46 PM, Ross Culloch wrote: Hi all, I am struggling to work out how to use the rownames from an edited dataframe rather than the row names from the original dataframe. In my data set i'm trying to extract several rows of data on particular individuals, i don't doubt i'm using the long way round but what i have in the way of a script is this: ##selecting the IDs from the dataframe individually A1-mumpup[ID==A1,] B1-mumpup[ID==B1,] B2-mumpup[ID==B2,] B3-mumpup[ID==B3,] B4-mumpup[ID==B4,] B6-mumpup[ID==B6,] B7-mumpup[ID==B7,] B8-mumpup[ID==B8,] B9-mumpup[ID==B9,] B13-mumpup[ID==B13,] C1-mumpup[ID==C1,] G1-mumpup[ID==G1,] data-rbind(A1,B1,B2,B3,B4,B6,B7,B8,B9,B13,C1,G1) It works fine to a certain extent, the only problem being that i get are all the IDs in the original dataframe so if i use summary(data$ID) I get: A1 B1 B10 B13 B2 B3 B4 B6 B7 B8 B9 C1 G1 G3 H2 H9 J1 J2 J3 K1 354 354 0 354 354 354 354 354 354 354 354 246 210 0 0 0 0 0 0 0 So it does take the data out of the dataframe but it keeps the IDs for some reason. I have looked at the edit.data.frame help and i understand why it is happening, it is taking the rownames from the original dataframe and not the edit and it seems i should use edit.row.names=T in my script, but i can't get that to work. Does anyone have any suggestions at all? Any help is much appreciated, If I understand, you may want something like this: myIDs - c('A1','B1','B2','B3','B4','B6','B7','B8','B9','B13','C1','G1') subset(mumpup, ID %in% myIDs) Best wishes, Ross -- 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] lme funcion in R
On 8/3/2009 1:15 PM, Hongwei Dong wrote: Hi, R users, I'm using the lme function in R to estimate a 2 level mixed effects model, in which the size of the subject groups are different. It turned out that It takes forever for R to converge. I also tried the same thing in SPSS and SPSS can give the results out within 20 minutes. Anyone can give me some advice on the lme function in R, especially why R does not converge? Thanks. Harry: You are much more likely to get helpful advice if you include the code you used to attempt to fit the model and a brief description of the data. For example, something along these lines but for your data and model: library(nlme) fm2 - lme(distance ~ age + Sex, data = Orthodont, random = ~ 1) str(Orthodont) Classes ‘nfnGroupedData’, ‘nfGroupedData’, ‘groupedData’ and 'data.frame': 108 obs. of 4 variables: $ distance: num 26 25 29 31 21.5 22.5 23 26.5 23 22.5 ... $ age : num 8 10 12 14 8 10 12 14 8 10 ... $ Subject : Ord.factor w/ 27 levels M16M05M02..: 15 15 15 15 3 3 3 3 7 7 ... $ Sex : Factor w/ 2 levels Male,Female: 1 1 1 1 1 1 1 1 1 1 ... - attr(*, outer)=Class 'formula' length 2 ~Sex .. ..- attr(*, .Environment)=environment: R_GlobalEnv - attr(*, formula)=Class 'formula' length 3 distance ~ age | Subject .. ..- attr(*, .Environment)=environment: R_GlobalEnv - attr(*, labels)=List of 2 ..$ x: chr Age ..$ y: chr Distance from pituitary to pterygomaxillary fissure - attr(*, units)=List of 2 ..$ x: chr (yr) ..$ y: chr (mm) - attr(*, FUN)=function (x) ..- attr(*, source)= chr function (x) max(x, na.rm = TRUE) - attr(*, order.groups)= logi TRUE hope this helps, Chuck Harry [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Obtaining the first /or last record of a subject in a longitudinal study
On 8/7/2008 6:21 AM, Luwis Tapiwa Diya wrote: Dear R users, I was wondering if anyone knows how to obtain(subset) the first and/or the last record of a subject in a longitudinal setup. Normally in SAS one uses first.variable1 and last.variable1. So my question is that is there an R way of doing this. Regards, How about a combination of aggregate() and head() or tail()? library(nlme) aggregate(Oxboys[,-1], list(Subject = Oxboys$Subject), head, n=1) Subject age height Occasion 1 10 -1 126.21 2 26 -1 132.21 3 25 -1 135.51 49 -1 132.71 52 -1 136.91 66 -1 142.41 77 -1 141.31 8 17 -1 134.91 9 16 -1 142.81 10 15 -1 137.51 11 8 -1 141.71 12 20 -1 146.51 13 1 -1 140.51 14 18 -1 145.51 15 5 -1 145.81 16 23 -1 144.51 17 11 -1 142.51 18 21 -1 143.91 19 3 -1 150.01 20 24 -1 147.81 21 22 -1 147.41 22 12 -1 149.91 23 13 -1 148.91 24 14 -1 151.61 25 19 -1 156.91 26 4 -1 155.71 aggregate(Oxboys[,-1], list(Subject = Oxboys$Subject), tail, n=1) .. -- 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] multiple tapply
On 8/7/2008 7:01 AM, glaporta wrote: Hi folk, I tried this and it works just perfectly tapply(iris[,1],iris[5],mean) but, how to obtain a single table from multiple variables? In tapply x is an atomic object so this code doesn't work tapply(iris[,1:4],iris[5],mean) Thanx and great summer holidays Gianandrea Here is one way: apply(iris[,1:4], 2, function(x){tapply(x, list(iris[,5]), mean)}) Sepal.Length Sepal.Width Petal.Length Petal.Width setosa5.006 3.4281.462 0.246 versicolor5.936 2.7704.260 1.326 virginica 6.588 2.9745.552 2.026 Here is another: library(reshape) iris.melt - melt(iris, measure.var=names(iris)[1:4]) cast(iris.melt, variable + Species ~ ., mean) variableSpecies (all) 1 Sepal.Length setosa 5.006 2 Sepal.Length versicolor 5.936 3 Sepal.Length virginica 6.588 4 Sepal.Width setosa 3.428 5 Sepal.Width versicolor 2.770 6 Sepal.Width virginica 2.974 7 Petal.Length setosa 1.462 8 Petal.Length versicolor 4.260 9 Petal.Length virginica 5.552 10 Petal.Width setosa 0.246 11 Petal.Width versicolor 1.326 12 Petal.Width virginica 2.026 -- 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] multiple tapply
On 8/7/2008 7:01 AM, glaporta wrote: Hi folk, I tried this and it works just perfectly tapply(iris[,1],iris[5],mean) but, how to obtain a single table from multiple variables? In tapply x is an atomic object so this code doesn't work tapply(iris[,1:4],iris[5],mean) Thanx and great summer holidays Gianandrea And a third approach: sapply(split(iris[,1:4], iris$Species), colMeans) setosa versicolor virginica Sepal.Length 5.006 5.936 6.588 Sepal.Width 3.428 2.770 2.974 Petal.Length 1.462 4.260 5.552 Petal.Width 0.246 1.326 2.026 -- 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] ANOVA
On 8/10/2008 11:35 AM, Angelo Scozzarella wrote: Hi, How can I make an ANOVA if I haven't got all data set but I know the numbers of subjects for each group, the mean and di standard deviation for each group? See anova.mean() in the HH package: http://finzi.psych.upenn.edu/R/library/HH/html/anova.mean.html Thanks Angelo Scozzarella __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] R-help? how to take difference in next two elements
On 8/11/2008 11:26 AM, dott wrote: Hi, I'd like to take difference for a sequence a between a_i and a_i-2, for instance, a-c(2,3,4,8,1) I need (2, 5, -3) as a result. If not using a for loop, can anyone help me? Thanks a lot. Dot a - c(2,3,4,8,1) diff(a, lag=2) [1] 2 5 -3 ?diff -- 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] Newbie programming help
On 8/22/2008 5:34 PM, Ranney, Steven wrote: All - Not sure if this is a real programming question, but here goes: I have data that looks like Lake Length Weight 1 158 45 1 179 70 1 200 125 1 202 150 1 206 145 1 209 165 1 210 140 1 215 175 1 216 152 1 220 150 1 221 165 ... where lake goes from 1 - 84 and the number of rows for each lake is variable (but ~20). I'm trying to do two things: 1) build a simple linear model of the form {lm(log10(Weight)~log10(Length)} for every separate lake in the data set; 2) I'd like to save the intercepts and slopes from each of these linear regressions into a seperate data frame. Any ideas? I think it would probably require some kind of 'for' statement, but I'm just not that smart. Assuming the data are in a data frame called mydf: library(nlme) fm1 - lmList(log10(Weight)~log10(Length) | Lake, mydf) coef(fm1) ?lmList or t(sapply(split(mydf, mydf$Lake), function(x){coef(lm(log10(Weight)~log10(Length), data=x))})) Thanks for your help, SR Steven H. Ranney Graduate Research Assistant (Ph.D) USGS Montana Cooperative Fishery Research Unit Montana State University PO Box 173460 Bozeman, MT 59717-3460 phone: (406) 994-6643 fax: (406) 994-7479 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to increase row number
On 9/2/2008 12:30 PM, ram basnet wrote: Hi I think this may be simple task but creating trouble to me. In my calculation, i have got large number of rows (5546) and column 182 but i am not able to see all the rows. May be somebody have idea how i can see all the rows ? I will be greatful if any body help me. Thanks in advance See the max.print argument to options(). options(max.print = 999) should allow you to see all of the elements. ?options Sincerely, Ram Kumar Basnet Graduate student Wageningen University Netherlands [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.