Re: [R] Passing variable name
Hi Bert, Thanks a lot for informing me regarding the html format of my email. I also would like to thank to Erdogan CEVHER and Jim LEMON for their kind reply/suggestions. Yes I am aware of names function in R which is not the one I am looking for in here. Let me try to explain in another way. The below part includes data generation, making cross-tab, Chi-Squared test and bar plot through ggplot. ### MyData<-data.frame("Gender" = c("F", "F", "F", "F", "M", "M", "M", "M", "M", "M", "F", "F"), "Hand" = c("R", "R", "L", "L", "R", "R", "L", "L", "R", "R", "L", "L"), "Gr" = c(1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2) ) MyData <- within(MyData, { Gender <- factor(Gender) Hand <- factor(Hand) Gr <- factor(Gr) } ) str(MyData) library(ggplot2) # Part 1 # MyT <- table(MyData$Gender, MyData$Hand) print(MyT) MyChi<- chisq.test(MyT) print(MyChi) dMyT <- data.frame(as.table(as.matrix(table(MyData$Gender, MyData$Hand, useNA = "ifany" name2<- c("Gender", "Hand", "Frequency") names(dMyT) <- name2 ggplot(data = na.omit(dMyT), aes(fill=Hand, y=Frequency, x=Gender)) + geom_bar(position="dodge", stat="identity") ### Let’s say I have hundreds of variables (e.g SNP data). By using above codes I can perform what I need. However , I need to copy/paste variable name(s) for making table, Chi-Square test, and ggplot. This increase the chance of incorrectly copying/pasting variable name(s). What I can do is define variable name(s) earlier and pass that names to making table, Chi-Square test, and ggplot part. I believe there is a way to do it. I tried “paste” function (as below), but it did not work either. Any comment/help is deeply appreciated. Kind Regards Seyit Ali ## V1 <- "Gender" V2 <- "Hand" MyT2 <- table(paste('MyData$',V1), paste('MyData$',V2) ) print(MyT) MyChi<- chisq.test(MyT) print(MyChi) dMyT <- data.frame(as.table(as.matrix(table(paste('MyData$',V1), paste('MyData$',V2), useNA = "ifany" name2<- c(V1, V2, "Frequency") names(dMyT) <- name2 ggplot(data = na.omit(dMyT), aes(fill=V2, y=Frequency, x=V1)) + geom_bar(position="dodge", stat="identity") # From: Bert Gunter [mailto:bgunter.4...@gmail.com] Sent: Monday, 28 December 2020 12:08 AM To: seyitali.ka...@ibu.edu.tr Cc: R-help Subject: Re: [R] Passing variable name This is a *plain text* list. As you can see from the included text that I received, the HTML version that you sent was somewhat mangled by the server. I do not know whether or not enough got through for you to get a helpful reply, but if not, re-send *to the list, not me* in *plain text*. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sun, Dec 27, 2020 at 12:25 PM Seyit Ali KAYIS mailto:seyitali.ka...@ibu.edu.tr> > wrote: Dear R users, � I have a data frame as below. In part 1, I have created a table for Gender and Hand, performed Chi-Square test and made graph using ggplot. � I want to replace the original variable names (Gender and Hand) with V1 and V2 and to be able to perform those things again as in #part 2. Is there a way to be able to replace the original names? � Any help is deeply appreciated � Kind Regards � Seyit Ali � # � MyData<-data.frame("Gender" = c("F", "F","F","F", "M", "M", "M", "M", "M", "M", "F", "F"), "Hand" = c("R", "R","L","L", "R","R","L", "L","R","R", "L","L"), "Gr" = c(1, 2, 1, 2, 1,
[R] Passing variable name
Dear R users, � I have a data frame as below. In part 1, I have created a table for Gender and Hand, performed Chi-Square test and made graph using ggplot. � I want to replace the original variable names (Gender and Hand) with V1 and V2 and to be able to perform those things again as in #part 2. Is there a way to be able to replace the original names? � Any help is deeply appreciated � Kind Regards � Seyit Ali � # � MyData<-data.frame("Gender" = c("F", "F","F","F", "M", "M", "M", "M", "M", "M", "F", "F"), "Hand" = c("R", "R","L","L", "R","R","L", "L","R","R", "L","L"), "Gr" = c(1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2) ) MyData <- within(MyData, { Gender <- factor(Gender) Hand <- factor(Hand) Gr <- factor(Gr) } ) � str(MyData) � library(ggplot2) � # Part 1 # � MyT <- table(MyData$Gender, MyData$Hand) print(MyT) � MyChi<- chisq.test(MyT) print(MyChi) dMyT <- data.frame(as.table(as.matrix(table(MyData$Gender, MyData$Hand, useNA = "ifany" name2<- c("Gender", "Hand", "Frequency") names(dMyT) <- name2 � ggplot(data = na.omit(dMyT), aes(fill=Hand, y=Frequency, x=Gender)) + geom_bar(position="dodge", stat="identity") � # Part 2 � # I want to be able to pass Gender and Hand as V1 and V2 , respectively to # table, Chi-Square test and ggplot � V1 <- "Gender" V2 <- "Hand" � MyT2 <- table(MyData$V1, MyData$V2) � print(MyT) � MyChi<- chisq.test(MyT) print(MyChi) dMyT <- data.frame(as.table(as.matrix(table(MyData$V1, MyData$V2, useNA = "ifany" name2<- c(V1, V2, "Frequency") names(dMyT) <- name2 � ggplot(data = na.omit(dMyT), aes(fill=V2, y=Frequency, x=V1)) + geom_bar(position="dodge", stat="identity") � � � � Dr. Seyit Ali KAYIS Bolu Abant Izzet Baysal University, Faculty of Medicine Department of Biostatistics and Medical Informatics Bolu, Turkey <mailto:s_a_ka...@yahoo.com> s_a_ka...@yahoo.com, <mailto:s_a_ka...@hotmail.com> s_a_ka...@hotmail.com Tel: +90 374 254 30 32 Mobile: +90 535 587 1139 Greetings from Bolu, Turkey -- � [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 me pls
Dear All, I need to create eps file which is the required figure format of the journal that I want to submit a paper. I am able to create files in pdf or wmf format but not in eps format. Is there a way to convert pdf or wmf to eps? or alternatively, how can I create an eps file in R? Any help is deeply appreciated. Kind Regards Seyit Ali __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] pairs
Dear all, I have two sets of data (say set1 and set2) as follow: set1 x1 x2 x3 0.30 0.43 3.88 0.38 0.59 3.53 0.30 0.42 2.12 0.33 0.53 2.12 0.30 0.47 3.76 set2 y1 y2 y3 0.32 0.47 5.18 0.23 0.26 1.06 0.42 0.65 3.88 0.28 0.38 3.76 0.35 0.47 1.41 The pairs function (such as pairs(~x1+x2+x3 data=set1, main=Simple Scatterplot Matrix) ) is producing scatterplot matrix where lower and upper diagonals have scatter plots of set1 variables. I want to produce a scatterplot matrix where in upper panel (diagonal) I should have plots from set1 variables and in lower panel (diagonal) I should have plots from set2 variables. Is there a way that I can do this? Any help is deeply appreciated. Kind Regards Seyit Ali -- Dr. Seyit Ali KAYIS Selcuk University Faculty of Agriculture Kampus, Konya, TURKEY s_a_ka...@yahoo.com,s_a_ka...@hotmail.com Tell: +90 332 223 2830 Mobile: +90 535 587 1139 Fax: +90 332 241 0108 Greetings from Konya, TURKEY http://www.ziraat.selcuk.edu.tr/skayis/ -- _ Facebook. k-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-nz:SI_SB_2:092010 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Drawing dendrogram
Dear all, I would like to draw a dendrogram and mark some parts/branches (by using segments) including their labels. If I draw it without specifying the length of x axix, I am able to do that (as in My dendrogram 1 of the following codes). However, if I want to specify the x axix, I am not able to draw marking line (by using segments) including labels (as in My dendrogram 2 of the following codes). Is there a way that I can include my labels into as well? Any help is deeply appreciated. Kind Regards Seyit Ali Codes: set.seed(201) x-matrix(rnorm(100, 0, 1), ncol=20, byrow=TRUE) myclust- hclust(dist(cor(x), method='euclidian'), method=ave) mydend-as.dendrogram(myclust) par(mfrow=c(1,2), mar=c(5,4,4,3), oma=c(1, 3, 1, 3)) plot(mydend, xlim=c(4, -0.2), horiz = TRUE, main=My Dendrogram 1) x0- -0.35 y0- 0.5 x1- 1.8 y1- 0.5 segments(x0, y0, x1, y1, col=red, lty=2) x0- -0.35 y0- 4.4 x1- 1.8 y1- 4.4 segments(x0, y0, x1, y1, col=red, lty=2) x0- -0.35 y0- 0.5 x1- -0.35 y1- 4.4 segments(x0, y0, x1, y1, col=red, lty=2) x0- 1.8 y0- 0.5 x1- 1.8 y1- 4.4 segments(x0, y0, x1, y1, col=red, lty=2) plot(mydend, xlim=c(4, 0.5), horiz = TRUE, main=My Dendrogram 2, dLeaf=0.35)#, yaxt=n) x0- 0.3 y0- 0.5 x1- 1.8 y1- 0.5 segments(x0, y0, x1, y1, col=red, lty=2) x0- 0.3 y0- 4.4 x1- 1.8 y1- 4.4 segments(x0, y0, x1, y1, col=red, lty=2) x0- 0.3 y0- 0.5 x1- 0.3 y1- 4.4 segments(x0, y0, x1, y1, col=red, lty=2) x0- 1.8 y0- 0.5 x1- 1.8 y1- 4.4 segments(x0, y0, x1, y1, col=red, lty=2) -- Dr. Seyit Ali KAYIS Selcuk University Faculty of Agriculture Kampus, Konya, TURKEY s_a_ka...@yahoo.com,s_a_ka...@hotmail.com Tell: +90 332 223 2830 Mobile: +90 535 587 1139 Fax: +90 332 241 0108 Greetings from Konya, TURKEY http://www.ziraat.selcuk.edu.tr/skayis/ -- _ [[elided Hotmail spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Sampling in R
Dear R users, I need to do sampling without replacement (bootstraps). I have two variables (Xvar, Yvar). I have a correlation from original data set cor(Xvar, Yvar)=0.6174221. I am doing 5 sampling, and in each sampling calculating correlations, saving, sorting and getting 95% cutt off point (0.1351877). I am getting maximum value as 0.3507219 (much smaller than correlation of my original data). I repeated the sampling a couple of time and none of them produced a correlation coefficient higher than my original data set. However, if I sort out my Xvar and Yvar and obtain correlation it is 0.9657125 which is much higher than correlation for my original data. I am doing sampling in another program and getting at least 1% higher correlation than mine. Now I am getting confused with sampling(random data) in R. My data and codes for the scenario above are below Xvar-c(0.1818182,0.5384615,0.5535714,0.4680851,0.4545455,0.4385965,0.5185185,0.4035088,0.4901961,0.3650794,0.462963,0.4,0.56,0.3965517,0.4909091, 0.4716981,0.4310345,0.2,0.1509434,0.2647059,0.173913,0.1914894,0.1914894,0.1489362,0.1363636,0.2244898,0.2325581,0.133,0.1818182,0.1702128, 0.2173913,0.2380952,0.1632653,0.5614035,0.3396226,0.4909091,0.3770492,0.5,0.5185185,0.5,0.467,0.4464286,0.362069,0.4285714,0.4561404, 0.4736842,0.4545455,0.417,0.4181818,0.4590164,0.517,0.5423729,0.483,0.5454545,0.4393939,0.5172414,0.4098361,0.4745763,0.4754098, 0.517,0.5,0.4603175,0.42,0.4038462,0.4897959,0.3148148,0.3673469,0.4,0.458,0.3877551,0.4375,0.4117647,0.4313725,0.533,0.3962264, 0.3548387,0.5272727,0.4137931,0.3928571,0.467,0.4210526,0.4363636,0.4545455,0.4310345,0.4237288,0.4814815,0.4912281,0.433,0.4,0.4285714, 0.4516129,0.5090909,0.4464286,0.4642857,0.417,0.4098361,0.4909091,0.3809524,0.5272727,0.4814815,0.5254237,0.627451,0.5,0.5471698,0.5454545, 0.5925926,0.5769231,0.5818182,0.444,0.4915254,0.4727273,0.4107143,0.4285714,0.4310345,0.4237288,0.4285714,0.440678,0.4237288,0.4807692, 0.4150943,0.4615385,0.4107143,0.4814815,0.4074074,0.4210526,0.5263158,0.440678,0.4576271,0.5344828,0.5,0.5636364,0.4677419,0.5,0.5192308, 0.4642857,0.5090909,0.58,0.4482759,0.5098039,0.4035088,0.4210526,0.5098039,0.4385965,0.5283019,0.5471698,0.625,0.4310345,0.4912281,0.5283019, 0.4576271,0.5471698,0.4745763,0.4821429) Yvar-c(0.2553191,0.4107143,0.5660377,0.389,0.3606557,0.2898551,0.3818182,0.4,0.4,0.3278689,0.2903226,0.4074074,0.4181818,0.3,0.2238806,0.3728814, 0.3709677,0.2307692,0.2830189,0.2244898,0.2142857,0.2131148,0.22,0.2258065,0.2321429,0.2,0.2264151,0.22,0.2115385,0.2459016,0.117,0.1785714, 0.2068966,0.6,0.4285714,0.3134328,0.4461538,0.3965517,0.4769231,0.6181818,0.4827586,0.3709677,0.3965517,0.4821429,0.4545455,0.359375,0.4576271, 0.4516129,0.5272727,0.4603175,0.4,0.4912281,0.5384615,0.5,0.4516129,0.4126984,0.4655172,0.5263158,0.4925373,0.358209,0.4285714,0.4920635, 0.4482759,0.3235294,0.4,0.4375,0.440678,0.3898305,0.35,0.4528302,0.58,0.4153846,0.3174603,0.5185185,0.3870968,0.2894737,0.3709677,0.369863, 0.3676471,0.3636364,0.3088235,0.328125,0.4032258,0.4084507,0.3188406,0.3636364,0.3823529,0.2816901,0.472,0.5,0.3521127,0.4393939,0.3787879, 0.453125,0.4324324,0.4057971,0.4545455,0.4492754,0.5,0.4098361,0.4067797,0.367,0.3928571,0.4285714,0.5,0.2923077,0.4561404,0.45,0.5538462, 0.4626866,0.4057971,0.3676471,0.5322581,0.5428571,0.375,0.4411765,0.4571429,0.4,0.3846154,0.3870968,0.4915254,0.530303,0.4375,0.4918033,0.4179104, 0.4032258,0.3606557,0.5178571,0.4848485,0.390625,0.375,0.4375,0.367,0.4,0.4477612,0.2571429,0.4032258,0.3382353,0.4814815,0.4090909,0.3548387, 0.4821429,0.5,0.557377,0.433,0.5454545,0.4590164,0.3943662,0.5076923,0.5,0.3283582,0.3676471,0.559322) my.cor-cor(Xvar, Yvar) print(my.cor) nperm-4 Perm.Cor-NULL for (iperm in 1:nperm) { XvarNew-sample(Xvar, size=length(Xvar), replace=FALSE) YvarNew-sample(Yvar, size=length(Yvar), replace=FALSE) perm.cor-cor(XvarNew, YvarNew) Perm.Cor-c(Perm.Cor, perm.cor) } print(max(Perm.Cor)) XvarSorted-sort(Xvar, decreasing=TRUE) YvarSorted-sort(Yvar, decreasing=TRUE) max.cor-cor(XvarSorted, YvarSorted) print(max.cor) if(mat.cor0) Perm.Cor.Sorted-sort(Perm.Cor, decreasing=TRUE) if(mat.cor0) Perm.Cor.Sorted-sort(Perm.Cor, decreasing=FALSE) T95-Perm.Cor.Sorted[(nperm+1)*0.05]# 95% treshold value T99-Perm.Cor.Sorted[(nperm+1)*0.01]# 99% treshold value I want to understand where I am making a mistake. Any comment is deeply appreciated. Kind Regards Seyit Ali -- Dr. Seyit Ali KAYIS Selcuk University Faculty of Agriculture Kampus, Konya, TURKEY
[R] Sampling in R
Dear R users, I need to do sampling without replacement (bootstraps). I have two variables (Xvar, Yvar). I have a correlation from original data set cor(Xvar, Yvar)=0.6174221. I am doing 5 sampling, and in each sampling calculating correlations, saving, sorting and getting 95% cutt off point (0.1351877). I am getting maximum value as 0.3507219 (much smaller than correlation of my original data). I repeated the sampling a couple of time and none of them produced a correlation coefficient higher than my original data set. However, if I sort out my Xvar and Yvar and obtain correlation it is 0.9657125 which is much higher than correlation for my original data. I am doing sampling in another program and getting at least 1% higher correlation than mine. Now I am getting confused with sampling(random data) in R. My data and codes for the scenario above are in the attached file. I want to understand where I am making a mistake. Any comment is deeply appreciated. Kind Regards Seyit Ali -- Dr. Seyit Ali KAYIS Selcuk University Faculty of Agriculture Kampus, Konya, TURKEY s_a_ka...@yahoo.com,s_a_ka...@hotmail.com Tell: +90 332 223 2830 Mobile: +90 535 587 1139 Fax: +90 332 241 0108 Greetings from Konya, TURKEY http://www.ziraat.selcuk.edu.tr/skayis/ -- _ No-one wants to be lonely this Autumn Find someone to snuggle up with Fchannel%2Findex%2Easpx%3Ftrackingid%3D1048628_t=773568480_r=nzWINDOWSliveMAILemailTAGLINES_m=EXTXvar-c(0.1818182,0.5384615,0.5535714,0.4680851,0.4545455,0.4385965,0.5185185,0.4035088,0.4901961,0.3650794,0.462963,0.4,0.56,0.3965517,0.4909091, 0.4716981,0.4310345,0.2,0.1509434,0.2647059,0.173913,0.1914894,0.1914894,0.1489362,0.1363636,0.2244898,0.2325581,0.133,0.1818182,0.1702128, 0.2173913,0.2380952,0.1632653,0.5614035,0.3396226,0.4909091,0.3770492,0.5,0.5185185,0.5,0.467,0.4464286,0.362069,0.4285714,0.4561404, 0.4736842,0.4545455,0.417,0.4181818,0.4590164,0.517,0.5423729,0.483,0.5454545,0.4393939,0.5172414,0.4098361,0.4745763,0.4754098, 0.517,0.5,0.4603175,0.42,0.4038462,0.4897959,0.3148148,0.3673469,0.4,0.458,0.3877551,0.4375,0.4117647,0.4313725,0.533,0.3962264, 0.3548387,0.5272727,0.4137931,0.3928571,0.467,0.4210526,0.4363636,0.4545455,0.4310345,0.4237288,0.4814815,0.4912281,0.433,0.4,0.4285714, 0.4516129,0.5090909,0.4464286,0.4642857,0.417,0.4098361,0.4909091,0.3809524,0.5272727,0.4814815,0.5254237,0.627451,0.5,0.5471698,0.5454545, 0.5925926,0.5769231,0.5818182,0.444,0.4915254,0.4727273,0.4107143,0.4285714,0.4310345,0.4237288,0.4285714,0.440678,0.4237288,0.4807692, 0.4150943,0.4615385,0.4107143,0.4814815,0.4074074,0.4210526,0.5263158,0.440678,0.4576271,0.5344828,0.5,0.5636364,0.4677419,0.5,0.5192308, 0.4642857,0.5090909,0.58,0.4482759,0.5098039,0.4035088,0.4210526,0.5098039,0.4385965,0.5283019,0.5471698,0.625,0.4310345,0.4912281,0.5283019, 0.4576271,0.5471698,0.4745763,0.4821429) Yvar-c(0.2553191,0.4107143,0.5660377,0.389,0.3606557,0.2898551,0.3818182,0.4,0.4,0.3278689,0.2903226,0.4074074,0.4181818,0.3,0.2238806,0.3728814, 0.3709677,0.2307692,0.2830189,0.2244898,0.2142857,0.2131148,0.22,0.2258065,0.2321429,0.2,0.2264151,0.22,0.2115385,0.2459016,0.117,0.1785714, 0.2068966,0.6,0.4285714,0.3134328,0.4461538,0.3965517,0.4769231,0.6181818,0.4827586,0.3709677,0.3965517,0.4821429,0.4545455,0.359375,0.4576271, 0.4516129,0.5272727,0.4603175,0.4,0.4912281,0.5384615,0.5,0.4516129,0.4126984,0.4655172,0.5263158,0.4925373,0.358209,0.4285714,0.4920635, 0.4482759,0.3235294,0.4,0.4375,0.440678,0.3898305,0.35,0.4528302,0.58,0.4153846,0.3174603,0.5185185,0.3870968,0.2894737,0.3709677,0.369863, 0.3676471,0.3636364,0.3088235,0.328125,0.4032258,0.4084507,0.3188406,0.3636364,0.3823529,0.2816901,0.472,0.5,0.3521127,0.4393939,0.3787879, 0.453125,0.4324324,0.4057971,0.4545455,0.4492754,0.5,0.4098361,0.4067797,0.367,0.3928571,0.4285714,0.5,0.2923077,0.4561404,0.45,0.5538462, 0.4626866,0.4057971,0.3676471,0.5322581,0.5428571,0.375,0.4411765,0.4571429,0.4,0.3846154,0.3870968,0.4915254,0.530303,0.4375,0.4918033,0.4179104, 0.4032258,0.3606557,0.5178571,0.4848485,0.390625,0.375,0.4375,0.367,0.4,0.4477612,0.2571429,0.4032258,0.3382353,0.4814815,0.4090909,0.3548387, 0.4821429,0.5,0.557377,0.433,0.5454545,0.4590164,0.3943662,0.5076923,0.5,0.3283582,0.3676471,0.559322) my.cor-cor(Xvar, Yvar) print(my.cor) nperm-4 Perm.Cor-NULL for (iperm in 1:nperm) { XvarNew-sample(Xvar, size=length(Xvar