[R] how to specify the multinomial distribution in R
Dear All, Could we specify the multinomial distribution in R when doing Bayesian data analysis through R2WinBUGS? See below for my issues. t2[i,1:2] ~ dmulti(p2[i,1:2],n2[i]) #t2[] is a matrix with two columns, the problem is how to specify it in R p2[i,1] - (p[i] * s1[t[i]] * s2[t[i]] + (1 - p[i]) * (1 - c1[t[i]]) * (1 - c2[t[i]]))/p1[i] p2[i,2] - (p[i] * s1[t[i]] * (1 - s2[t[i]]) +(1 - p[i]) * (1 - c1[t[i]]) * c2[t[i]])/p1[i] t2-modeldata[,c(6,7)] #This is the method that i used. Unfortunately, it seems not to work. data-list(m,...,t2) #data[[10]] is just t2 The error information is :Error in is.finite(x) : default method not implemented for type 'list' when using traceback(), i get: 6: FUN(X[[10L]], ...) #so, i guess i didnot specify t2 correctly 5: lapply(data.list, formatC, digits = digits, format = E) 4: write.datafile(lapply(data.list, formatC, digits = digits, format = E), file.path(dir, data.file)) 3: bugs.data(data, dir = getwd(), digits) 2: bugs(data, inits, model.file = BayesGeostat.txt, parameters = c(p, a, u, tau.u, tau.s, phi, t1.p), n.chains = 3, n.iter = 1000, OpenBUGS.pgm = C:/Program Files (x86)/OpenBUGS/OpenBUGS322/OpenBUGS.exe) 1: debug(bugs(data, inits, model.file = BayesGeostat.txt, parameters = c(p, a, u, tau.u, tau.s, phi, t1.p), n.chains = 3, n.iter = 1000, OpenBUGS.pgm = C:/Program Files (x86)/OpenBUGS/OpenBUGS322/OpenBUGS.exe)) Any guys have ever met this problem or know how to fix it? Thanks a lot. -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] ZhiJie Zhang,MD,PhD Dept.of Epidemiology, School of Public Health,Fudan University Office:Room 443, Building 8 Office Tel./Fax.:+86-21-54237410 Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:epis...@gmail.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Join points with arrows based a TIME variable
Hi Uwe, It works. Why does the following argument generate different results? with(data, arrows(x[-length(x)], y[-length(x)], x[-1], y[-1])) #correct,multiple joins with(data, arrows(x[1], y[1], x[length(x)], y[length(x)])) #wrong,seems to be only one join From the ?arrows, the second argument should work. What is the problem? Thanks a lot. #codes: x-c(1:6);y-c(1:6);time-c(6:1);data-cbind(x,y,time);data data-data.frame(data[order(data[,time]),]) with(data, plot(x,y)) with(data, arrows(x[-length(x)], y[-length(x)], x[-1], y[-1])) with(data, plot(x,y)) with(data, arrows(x[1], y[1], x[length(x)], y[length(x)])) 2009/11/4 Uwe Ligges lig...@statistik.tu-dortmund.de zhijie zhang wrote: Hi, I have a data set with three variables,X Y and Time. X and Y are the coordinates of points, i want to join these points according to the Time sequence using arrows? Demo Example data: x-c(1:6) y-c(1:6) time-c(6:1) data-cbind(x,y,time) data x y time [1,] 1 16 [2,] 2 25 [3,] 3 34 [4,] 4 43 [5,] 5 52 [6,] 6 61 I hope to join the six points with points' time=1 as starting point and points' time=6 as endpoint. So the sequence is time=1,2,3,4,5,6 and join the corresponding points with arrows. Any ideas on it? data - data.frame(data[order(data[,time]),]) with(data, plot(y ~ x)) with(data, arrows(x[-length(x)], y[-length(x)], x[-1], y[-1])) Uwe Ligges [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Join points with arrows based a TIME variable
Hi Uwe, I mistook the arguments for the function of arrows. I understand now. Thanks again. 2009/11/5 Uwe Ligges lig...@statistik.tu-dortmund.de zhijie zhang wrote: Hi Uwe, It works. Why does the following argument generate different results? with(data, arrows(x[-length(x)], y[-length(x)], x[-1], y[-1])) #correct,multiple joins In the former you select all elements of the vectors except the first or last one, respectively. In the next call you select just one arguemnt of each vector, namely the first or last one. Uwe Ligges with(data, arrows(x[1], y[1], x[length(x)], y[length(x)])) #wrong,seems to be only one join From the ?arrows, the second argument should work. What is the problem? Thanks a lot. #codes: x-c(1:6);y-c(1:6);time-c(6:1);data-cbind(x,y,time);data data-data.frame(data[order(data[,time]),]) with(data, plot(x,y)) with(data, arrows(x[-length(x)], y[-length(x)], x[-1], y[-1])) with(data, plot(x,y)) with(data, arrows(x[1], y[1], x[length(x)], y[length(x)])) 2009/11/4 Uwe Ligges lig...@statistik.tu-dortmund.de zhijie zhang wrote: Hi, I have a data set with three variables,X Y and Time. X and Y are the coordinates of points, i want to join these points according to the Time sequence using arrows? Demo Example data: x-c(1:6) y-c(1:6) time-c(6:1) data-cbind(x,y,time) data x y time [1,] 1 16 [2,] 2 25 [3,] 3 34 [4,] 4 43 [5,] 5 52 [6,] 6 61 I hope to join the six points with points' time=1 as starting point and points' time=6 as endpoint. So the sequence is time=1,2,3,4,5,6 and join the corresponding points with arrows. Any ideas on it? data - data.frame(data[order(data[,time]),]) with(data, plot(y ~ x)) with(data, arrows(x[-length(x)], y[-length(x)], x[-1], y[-1])) Uwe Ligges [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Join points with arrows based a TIME variable
Hi, I have a data set with three variables,X Y and Time. X and Y are the coordinates of points, i want to join these points according to the Time sequence using arrows? Demo Example data: x-c(1:6) y-c(1:6) time-c(6:1) data-cbind(x,y,time) data x y time [1,] 1 16 [2,] 2 25 [3,] 3 34 [4,] 4 43 [5,] 5 52 [6,] 6 61 I hope to join the six points with points' time=1 as starting point and points' time=6 as endpoint. So the sequence is time=1,2,3,4,5,6 and join the corresponding points with arrows. Any ideas on it? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating a Clustered-Stacked Column Chart
Hi David, Your codes are for stacked chart. Actually, i hope to Create a Clustered-Stacked Column Chart, which means that a chart will combine the traits of stacked chart and clustered chart, see the example in the page http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html. Thanks. 2009/10/10 David Winsemius dwinsem...@comcast.net library(lattice) barchart(Titanic, scales = list(x = free), auto.key = list(title = Survived)) Or if you prefer vertical: barchart(Titanic, scales = list(x = free), auto.key = list(title = Survived), horizontal=FALSE) There are adjustments available to the space between bars. barchart(Titanic, scales = list(x = free), auto.key = list(title = Survived), horizontal=FALSE, box.ratio=100) On Oct 9, 2009, at 9:57 PM, zhijie zhang wrote: Thanks a lot. Maybe someone else has the method to solve that. 2009/10/9 John Kane jrkrid...@yahoo.ca I don't think I've seen an R version, probably because the technique is not very good for displaying data. Have a look at http://chartsgraphs.wordpress.com/tag/r-and-excel/ for an alternative method of displaying the data using lattice. --- On Fri, 10/9/09, zhijie zhang rusers...@gmail.com wrote: From: zhijie zhang rusers...@gmail.com Subject: [R] Creating a Clustered-Stacked Column Chart To: r-h...@stat.math.ethz.ch Received: Friday, October 9, 2009, 5:31 AM Hi all, In R, is there some functions or ways to create a Clustered-Stacked Column Chart as the example in the following page http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html? I have browsed the R Graph Gallery ( http://addictedtor.free.fr/graphiques/) and searched the R site, and didnot find an appropriate method to do it. Anybody has met this problem before? 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.htmlhttp://www.r-project.org/posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ Get the name you've always wanted @ymail.com or @rocketmail.com! Go to http://ca.promos.yahoo.com/jacko/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating a Clustered-Stacked Column Chart
Thanks for your ideas and suggestions. I need to point out that most of us will create the Clustered-Stacked Column Chart in the matrix layout as David gave above, but here i hope to display the graph side by side as the example in the link http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html, which may be not a good method to display the information. Actually, i browsed the lattice package and re-run the examples in its help before posting this question. As John said above, I don't think I've seen an R version, probably because the technique is not very good for displaying data.. Following Peter's suggestion, i browsed the layout= argument in the link http://www.stat.ucl.ac.be/ISdidactique/Rhelp/library/lattice/html/xyplot.html and tried it, but cannot successfully get the correct graph. library(lattice) barchart(Titanic, scales = list(x = free),auto.key = list(title = Survived)) barchart(Titanic, scales = list(x = free),auto.key = list(title = Survived),layout=c(2,1)) #missed the children's graph barchart(Titanic, scales = list(x = free),auto.key = list(title = Survived),layout=c(1,2)) #missed the children's graph Thanks a lot. 2009/10/10 Peter Ehlers ehl...@ucalgary.ca I think you're missing the point. David _did_ show you how to create a graph showing 4 clusters of stacked barcharts. If you want them side-by-side instead of in the matrix layout David gave, use the layout= argument. -Peter Ehlers zhijie zhang wrote: Hi David, Your codes are for stacked chart. Actually, i hope to Create a Clustered-Stacked Column Chart, which means that a chart will combine the traits of stacked chart and clustered chart, see the example in the page http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html. Thanks. 2009/10/10 David Winsemius dwinsem...@comcast.net library(lattice) barchart(Titanic, scales = list(x = free), auto.key = list(title = Survived)) Or if you prefer vertical: barchart(Titanic, scales = list(x = free), auto.key = list(title = Survived), horizontal=FALSE) There are adjustments available to the space between bars. barchart(Titanic, scales = list(x = free), auto.key = list(title = Survived), horizontal=FALSE, box.ratio=100) On Oct 9, 2009, at 9:57 PM, zhijie zhang wrote: Thanks a lot. Maybe someone else has the method to solve that. 2009/10/9 John Kane jrkrid...@yahoo.ca I don't think I've seen an R version, probably because the technique is not very good for displaying data. Have a look at http://chartsgraphs.wordpress.com/tag/r-and-excel/ for an alternative method of displaying the data using lattice. --- On Fri, 10/9/09, zhijie zhang rusers...@gmail.com wrote: From: zhijie zhang rusers...@gmail.com Subject: [R] Creating a Clustered-Stacked Column Chart To: r-h...@stat.math.ethz.ch Received: Friday, October 9, 2009, 5:31 AM Hi all, In R, is there some functions or ways to create a Clustered-Stacked Column Chart as the example in the following page http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html? I have browsed the R Graph Gallery ( http://addictedtor.free.fr/graphiques/) and searched the R site, and didnot find an appropriate method to do it. Anybody has met this problem before? 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.htmlhttp://www.r-project.org/posting-guide.html http://www.r-project.org/posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ Get the name you've always wanted @ymail.com or @rocketmail.com! Go to http://ca.promos.yahoo.com/jacko/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R
[R] Creating a Clustered-Stacked Column Chart
Hi all, In R, is there some functions or ways to create a Clustered-Stacked Column Chart as the example in the following page http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html? I have browsed the R Graph Gallery (http://addictedtor.free.fr/graphiques/) and searched the R site, and didnot find an appropriate method to do it. Anybody has met this problem before? 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.
Re: [R] Creating a Clustered-Stacked Column Chart
Thanks a lot. Maybe someone else has the method to solve that. 2009/10/9 John Kane jrkrid...@yahoo.ca I don't think I've seen an R version, probably because the technique is not very good for displaying data. Have a look at http://chartsgraphs.wordpress.com/tag/r-and-excel/ for an alternative method of displaying the data using lattice. --- On Fri, 10/9/09, zhijie zhang rusers...@gmail.com wrote: From: zhijie zhang rusers...@gmail.com Subject: [R] Creating a Clustered-Stacked Column Chart To: r-h...@stat.math.ethz.ch Received: Friday, October 9, 2009, 5:31 AM Hi all, In R, is there some functions or ways to create a Clustered-Stacked Column Chart as the example in the following page http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html? I have browsed the R Graph Gallery ( http://addictedtor.free.fr/graphiques/) and searched the R site, and didnot find an appropriate method to do it. Anybody has met this problem before? 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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ Get the name you've always wanted @ymail.com or @rocketmail.com! Go to http://ca.promos.yahoo.com/jacko/ [[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] cannot allocate a vector with 1920165909 length
Dear Rusers, The error for the following was that it cannot allocate the vector of length 1920165909. a - expand.grid(se1=0:100/100, sp1=0:100/100, se2=0:100/100, sp2=0:100/100, DR=0:100/100) How to solve it? Maybe setwd(dir) can, i am not very sure about it. Any ideas about it? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How should i change the SAS Codes into R Codes?
Dear R users, I have a SAS codes with several loops in it, and i hope to use R to do the same task. The SAS codes are as follows, /*to generate the dataset*/ DATA Single_Simulation; DO se=0 to 1 by 0.01; DO sp=0 to 1 by 0.01; DO DR=0 to 1 by 0.01; TR=(DR+sp-1)/(se+sp-1+1.0e-12); Adjust_Factor=TR/(DR+1.0e-12); OUTPUT; END; END; END; RUN; /*to select some data*/ DATA sampledata; SET Single_Simulation; IF DR=0.02 sp=1; RUN; #I tried the following codes with R,failed num-seq(0, 1, by = 0.01) for (se in num) { for (sp in num) { for (DR in num) { TR=(DR+sp-1)/(se+sp-1+1.0e-12) Adjust_Factor=TR/(DR+1.0e-12) } } } My questions are, 1. What is the correct codes for R to do the similar task? 2. Sometimes, the simulated dataset are very large, so i need to put the generated dataset in a file with large disk place, not in the memory, how to do it? SAS can do it with the 'libname' argument, do R have the similar method? 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.
Re: [R] How should i change the SAS Codes into R Codes?
Thanks a lot. Matt's code works very well. Could i use several 'for' arguments to get the results as what i think first? 2009/7/28 John Kane jrkrid...@yahoo.ca I see Matt Aldridge has given you the answers to your specific questions. If you are used to using SAS you might find Bob Meunchen's book Muenchen, R. A. (2008). R for SAS and SPSS Users (1st ed.). Springer. useful. A shorter version is available as a pdf at http://rforsasandspssusers.com/. The pdf is a very useful guide for anyone beginning to use R. --- On Mon, 7/27/09, zhijie zhang rusers...@gmail.com wrote: From: zhijie zhang rusers...@gmail.com Subject: [R] How should i change the SAS Codes into R Codes? To: r-h...@stat.math.ethz.ch Received: Monday, July 27, 2009, 11:03 AM Dear R users, I have a SAS codes with several loops in it, and i hope to use R to do the same task. The SAS codes are as follows, /*to generate the dataset*/ DATA Single_Simulation; DO se=0 to 1 by 0.01; DO sp=0 to 1 by 0.01; DO DR=0 to 1 by 0.01; TR=(DR+sp-1)/(se+sp-1+1.0e-12); Adjust_Factor=TR/(DR+1.0e-12); OUTPUT; END; END; END; RUN; /*to select some data*/ DATA sampledata; SET Single_Simulation; IF DR=0.02 sp=1; RUN; #I tried the following codes with R,failed num-seq(0, 1, by = 0.01) for (se in num) { for (sp in num) { for (DR in num) { TR=(DR+sp-1)/(se+sp-1+1.0e-12) Adjust_Factor=TR/(DR+1.0e-12) } } } My questions are, 1. What is the correct codes for R to do the similar task? 2. Sometimes, the simulated dataset are very large, so i need to put the generated dataset in a file with large disk place, not in the memory, how to do it? SAS can do it with the 'libname' argument, do R have the similar method? 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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now http://ca.toolbar.yahoo.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Does R have function or method to finish my task?
Dear all, Does R have function or method to finish the following task. Say i have a dataset. The response variable is Y, and the indepedent variables are X1, X2, X3, and YEAR. See an example. Y X1X2X3 X4YEAR 13.4 2.8 3.5 2.5 1.8 1990 10.51.82.4 2 3 1991 . In ecology, Y may be not only related with X1, X2, X3 in the same year as Y, but also may be related with X1, X2, X3 and Y in the previous one , two or more years as Y. But which year has the closest relationship is not know and this may be one of the analysis aim. Take Year=1995 as an example, Y_1995 may be related with X1_1995 , X2_1995 , X3_1995, X1_1994 , X2_1994 , X3_1994, Y_1994, (previous one year) X1_1993 , X2_1993 , X3_1993, Y_1993 (previous two years) ... ... (previous more years) Pay attention to the situation that Y itself may also affect its own value of the next several years. Anybody knows whether R have functions or methods to finish the above task. I hope i have explained it clearly. Any suggestions or help are greatly appreciated. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Does R have function or method to finish my task?
Actually, i had checked out the methods of time series (TS), but i had thought it cannot solve it. TS may only considers the autocorrelation of Y in different time, but not Xs. Besides Y, i also have several independent variables. Following your suggestion, i browsed the dynlm package and found it is helpful. Lag function (e.g.lag(x, lag = -k)) may solve the problem. That is, TS plus Lag function may finally solve my task. But one question is how to determine the best k for Y and Xs. Thanks. 2009/3/6 Greg Snow greg.s...@imail.org I think that the dynlm package was designed for just such a problem. I also would not be surprised if there are tools in the zoo package to do this. You should probably check out the time series task view on CRAN as well. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of zhijie zhang Sent: Thursday, March 05, 2009 8:56 AM To: r-h...@stat.math.ethz.ch Subject: [R] Does R have function or method to finish my task? Dear all, Does R have function or method to finish the following task. Say i have a dataset. The response variable is Y, and the indepedent variables are X1, X2, X3, and YEAR. See an example. Y X1X2X3 X4 YEAR 13.4 2.8 3.5 2.5 1.8 1990 10.51.82.4 2 3 1991 . In ecology, Y may be not only related with X1, X2, X3 in the same year as Y, but also may be related with X1, X2, X3 and Y in the previous one , two or more years as Y. But which year has the closest relationship is not know and this may be one of the analysis aim. Take Year=1995 as an example, Y_1995 may be related with X1_1995 , X2_1995 , X3_1995, X1_1994 , X2_1994 , X3_1994, Y_1994, (previous one year) X1_1993 , X2_1993 , X3_1993, Y_1993 (previous two years) ... ... (previous more years) Pay attention to the situation that Y itself may also affect its own value of the next several years. Anybody knows whether R have functions or methods to finish the above task. I hope i have explained it clearly. Any suggestions or help are greatly appreciated. [[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-http://www.r-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] glmer documentation
r-sig-mixed-mod...@r-project.org maybe more appropriate for your question. You may find answers there. 2009/1/17 Raphaelle rmet...@rvc.ac.uk Hello, I am fitting a gmler using poisson, and I was looking for a documentation to interpret correctly the output. I'm quite a beginner with these kind of models. I couldn't find something in the lme4 package manual. and on the internet neither... Thank you, Raphaelle -- View this message in context: http://www.nabble.com/glmer-documentation-tp21506036p21506036.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Where to find the source codes for the internal function in stats package
Dear all, I want to see the source codes for dchisq(x, df, ncp=0, log = FALSE), but cannot find it. I input dchisq in the R interface, and then enter, the following message return: dchisq /*/ function (x, df, ncp = 0, log = FALSE) { if (missing(ncp)) .Internal(dchisq(x, df, log)) else .Internal(dnchisq(x, df, ncp, log)) } environment: namespace:stats /*/ It seems that dchisq() is the internal function in STATS package. So go to C:\Program Files\R\R-2.7.2\library\stats to look for it. I browsed the files in this catalog, but it seems that i missed it. Anybody can tell me how and where to find the codes, 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.
[R] Questions on the results from glmmPQL(MASS)
Dear Rusers, I have used R,S-PLUS and SAS to analyze the sample data bacteria in MASS package. Their results are listed below. I have three questions, anybody can give me possible answers? Q1:From the results, we see that R get 'NAs'for AIC,BIC and logLik, while S-PLUS8.0 gave the exact values for them. Why? I had thought that R should give the same results as SPLUS here. Q2: The model to analyse the data is logity=b0+u+b1*trt+b2*I(week2), but the results for Random effects in R/SPLUS confused me. SAS may be clearer. Random effects: Formula: ~1 | ID (Intercept) Residual StdDev:1.410637 0.7800511 Which is the random effect 'sigma'? I think it is 1.410637, but what does 0.7800511 mean? That is, i want ot know how to explain/use the above two data for Random effects. Q3:In SAS and other softwares, we can get *p*-values for the random effect 'sigma', but i donot see the *p*-values in the results of R/SPLUS. I have used attributes() to look for them, but no *p* values. Anybody knows how to get *p*-values for the random effect 'sigma',. Any suggestions or help are greatly appreciated. #R Results:MASS' version 7.2-44; R version 2.7.2 library(MASS) summary(glmmPQL(y ~ trt + I(week 2), random = ~ 1 | ID,family = binomial, data = bacteria)) Linear mixed-effects model fit by maximum likelihood Data: bacteria AIC BIC logLik NA NA NA Random effects: Formula: ~1 | ID (Intercept) Residual StdDev:1.410637 0.7800511 Variance function: Structure: fixed weights Formula: ~invwt Fixed effects: y ~ trt + I(week 2) Value Std.Error DF t-value p-value (Intercept) 3.4120140.5185033 169 6.580506 0. trtdrug -1.247355 0.6440635 47 -1.936696 0.0588 trtdrug+-0.7543270.6453978 47 -1.168779 0.2484 I(week 2)TRUE -1.607257 0.3583379 169 -4.485311 0. Correlation: (Intr) trtdrg trtdr+ trtdrug -0.598 trtdrug+-0.571 0.460 I(week 2)TRUE -0.537 0.047 -0.001 #S-PLUS8.0: The results are the same as R except the followings: AIC BIClogLik 1113.622 1133.984 -550.8111 #SAS9.1.3 proc nlmixed data=b; parms b0=-1 b1=1 b2=1 sigma=0.4; yy=b0+u+b1*trt+b2*week; p=1/(1+exp(-yy)); Model response~binary(p); Random u~normal(0,sigma) subject=id; Run; -2 Log Likelihood = 192.2 AIC (smaller is better)=200.2 AICC (smaller is better) =200.3 BIC (smaller is better)= 207.8 Parameter Estimates Standard Parameter Estimate ErrorDF t Value Pr |t| Alpha Lower Upper Gradient b0 3.49660.651249 5.37.00010.05 2.18804.8052 -4.69E-6 trt -0.67630.335249-2.020.04910.05 -1.3500 -0.00266 -0.1 I(week2) -1.61320.478549-3.370.00150.05 -2.5747 -0.6516 -9.35E-7 sigma1.53010.963249 1.590.11860.05 -0.40543.4656 -2.42E-6 -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] ZhiJie Zhang ,PhD Dept.of Epidemiology, School of Public Health,Fudan University Office:Room 443, Building 8 Office Tel./Fax.:+86-21-54237410 Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] [EMAIL PROTECTED] Website: www.statABC.com http://www.statabc.com/ [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[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] Needs suggestions for choosing appropriate R packages
Dear all, I am thinking to fit a multilevel dataset with R. I have found several possible packages for my task, such as glmmPQL(MASS),glmm(repeated),glmer(lme4), et al. I am a little confused by these functions. Could anybody tell me which function/package is the correct one to analyse my dataset? My dataset is as follows: the response variable P is binary variable (the subject is a patient or not); two explanatory variables X1 (age) and X2 (sex); this dataset was sampled from three different level, district,school,individual, so this was regarded as a multilevel dataset. I hope to fit the 3-level model(Y is binary variable): Logit(Pijk)=(a0+b0k+c0jk)+b1*X1+b2*X2 i-individual, first level; j-school, 2nd level; k-district,3rd level. I know that the GLIMMIX procedure in the latest version SAS9.2 is a choice for that, but unfortunately we donot have the latest version. R must have the similar functions to do that, can anybody give me some suggestions or help on analysing my dataset? Q1: Which package/functions is appropriate for my task? Could u show me some example codes if possible? Q2: Logit(Pijk)=(a0+b0k+c0jk)+(b1+b1j)*X1+b2*X2 If the randome effect was also specified in X1 as above, Which package/functions is possible? Thanks a lot. -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] ZhiJie Zhang ,PhD Dept.of Epidemiology, School of Public Health,Fudan University Office:Room 443, Building 8 Office Tel./Fax.:+86-21-54237410 Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] [EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[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] Generating series of distributions with the same skewness and different kurtosis or with same kurtosis and different skewness?
Dear R users, I hope to explain the concepts of skewness and kurtosis by generating series of distributions with same skewness and different kurtosis or with same kurtosis and different skewness, but it seems that i cannot find the right functions. I have searched the mailing list, but no answers were found. Is it possible to do that in R? Which function could be used? Thanks a lot. -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:+86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] [EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Generating series of distributions with the same skewness and different kurtosis or with same kurtosis and different skewness?
Yihui, Could you please show me an example? What u have refered is clear for me, but i think the thing that i donot know how to handle with is to link the relationships between skewness/kurtosis and the distributions? Thanks. On Tue, Sep 23, 2008 at 11:48 PM, Yihui Xie [EMAIL PROTECTED] wrote: Hi, Certainly it's possible. Use any distribution function as long as you can change its skewness and kurtosis, e.g. the Chi-square distribution. The corresponding R functions are p*, q*, d*, and r* - I think you know these functions already (e.g. rchisq()). The only thing that you should be clear about is the relationship between the arguments of distribution functions in R and those in a certain theoretical distribution. Refer to http://en.wikipedia.org/wiki/Probability_distribution if you don't remember those formulae for skewness and kurtosis. Regards, Yihui -- Yihui Xie [EMAIL PROTECTED] Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China On Tue, Sep 23, 2008 at 10:59 PM, zhijie zhang [EMAIL PROTECTED] wrote: Dear R users, I hope to explain the concepts of skewness and kurtosis by generating series of distributions with same skewness and different kurtosis or with same kurtosis and different skewness, but it seems that i cannot find the right functions. I have searched the mailing list, but no answers were found. Is it possible to do that in R? Which function could be used? Thanks a lot. -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:+86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] Website: www.statABC.com http://www.statabc.com/ [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:+86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] [EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[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] High resolution figures for a paper?
Dear Rusers, My manuscript has been conditionally accepted recently. The problem to generate the high resolution figures in R for the manuscript cannot be solved by me. The journal editor ask me to generate the figures with a minimum resolution of 500 dpi. I have tried the *menu-driven method* to save the figures as JPEG (100% printed quality), but the results seem not to be very good. I have submitted the generated figures twice using the above-mentioned method, but the Editor think the resolution is still very low. Finally, i used the Photoshop to check the figure. It seems that its resolution for JPEG (100% printed quality) is about 72dpi. *Does anybody know a better method to save a figure with user-defined resolution in R software, especially high resolution? Could u please show me an example if possible?* I hope to save the figures as TIFF/JPEG format at 1000 dpi. Thanks a lot. -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:+86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] [EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] High resolution figures for a paper?
Thanks for the above mentioned methods. I will try them one by one. Thanks again. On 6/3/08, Sarah Goslee [EMAIL PROTECTED] wrote: The production of publication-quality graphics has been discussed at great length on R-sig-eco over the past week or so. The archive is available here: https://stat.ethz.ch/pipermail/r-sig-ecology/2008-May/thread.html and the thread is very near the bottom. Very detailed recommendations have been provided. (Also see the past two days, which are not of course in the May archive.) Sarah On Mon, Jun 2, 2008 at 11:12 AM, zhijie zhang [EMAIL PROTECTED] wrote: Dear Rusers, My manuscript has been conditionally accepted recently. The problem to generate the high resolution figures in R for the manuscript cannot be solved by me. The journal editor ask me to generate the figures with a minimum resolution of 500 dpi. I have tried the *menu-driven method* to save the figures as JPEG (100% printed quality), but the results seem not to be very good. I have submitted the generated figures twice using the above-mentioned method, but the Editor think the resolution is still very low. Finally, i used the Photoshop to check the figure. It seems that its resolution for JPEG (100% printed quality) is about 72dpi. *Does anybody know a better method to save a figure with user-defined resolution in R software, especially high resolution? Could u please show me an example if possible?* I hope to save the figures as TIFF/JPEG format at 1000 dpi. Thanks a lot. -- Sarah Goslee http://www.functionaldiversity.org -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:+86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] [EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[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] What is the correct model formula for the results of piecewise linear function?
Dear friends, I used the B-spline (degree=1) method to fit the piecewise linear function and the results are listed below. m.glm-glm(mark~x+poly(elevation,2)+bs(distance,degree=1,knots=c(16.13,24)) +bs(y,degree=1,knots=c(-0.4357,-0.3202 )),family=binomial(logit),data=point) summary(m.glm) Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept) 12.104 3.138 3.857 0.000115 *** x 5.815 1.987 2.926 0.003433 ** poly(elevation, 2)1 6.654 4.457 1.493 0.135444 poly(elevation, 2)2 -6.755 3.441 - 1.963 0.049645 * bs(distance, degree = 1, knots = c(16.13, 24))1 -1.291 1.139 - 1.133 0.257220 bs(distance, degree = 1, knots = c(16.13, 24))2 -10.348 2.025 -5.110 3.22e-07 *** bs(distance, degree = 1, knots = c(16.13, 24))3 -3.530 3.752 - 0.941 0.346850 bs(y, degree = 1, knots = c(-0.4357, -0.3202))1 -6.828 1.836 - 3.719 0.000200 *** bs(y, degree = 1, knots = c(-0.4357, -0.3202))2 -4.426 1.614 - 2.742 0.006105 ** bs(y, degree = 1, knots = c(-0.4357, -0.3202))3-11.216 2.861 - 3.920 8.86e-05 *** I think bs(degree=1) has fitted the piecewise linear functions. Now i hope to write the model formua for the above results, but not very sure about how to write the correct results for *distance* and *y,* because they have three parts . Logitp=12.104 + 5.815*x + 6.654*elevation - 6.755*elevation^2 -1.291*distance1 - 10.348*distance2 - 3.53*distance3 -6.828*y1 - 4.426*y2 - 11.216*y3 In the above formula, distance1-3 denotes the three linear functions for*distance *, my problem is how to replace distace1-3 using original variable *distance *? The same question is for *y*. Could anybody please show me the correct model formula according to the above result? Thanks a lot. -- With Kind Regards, Zhi Jie [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Great difference for piecewise linear function between R and SAS
Dear Murdoch, Compare the predictions, not the coefficients., this is the key point. I have checked their predicted probability and their results are the same. What do you mean by You're using different bases? Could you please give me a little more info on it, so that i can go to find some materials? Thanks a lot. On 3/24/08, Duncan Murdoch [EMAIL PROTECTED] wrote: On 24/03/2008 5:23 AM, zhijie zhang wrote: Dear Rusers, I am now using R and SAS to fit the piecewise linear functions, and what surprised me is that they have a great differrent result. See below. You're using different bases. Compare the predictions, not the coefficients. To see the bases that R uses, do this: matplot(distance, bs(distance,degree=1,knots=c(16.13,24))) matplot(y, bs(y,degree=1,knots=c(-0.4357,-0.3202))) Duncan Murdoch #R code--Knots for distance are 16.13 and 24, respectively, and Knots for y are -0.4357 and -0.3202 m.glm-glm(mark~x+poly(elevation,2)+bs(distance,degree=1,knots=c(16.13 ,24)) +bs(y,degree=1,knots=c(-0.4357,-0.3202 )),family=binomial(logit),data=point) summary(m.glm) Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept) 12.104 3.138 3.857 0.000115 *** x 5.815 1.987 2.926 0.003433 ** poly(elevation, 2)1 6.654 4.457 1.493 0.135444 poly(elevation, 2)2 -6.755 3.441 - 1.963 0.049645 * bs(distance, degree = 1, knots = c(16.13, 24))1 -1.291 1.139 - 1.133 0.257220 bs(distance, degree = 1, knots = c(16.13, 24))2-10.348 2.025 - 5.110 3.22e-07 *** bs(distance, degree = 1, knots = c(16.13, 24))3-3.530 3.752 - 0.941 0.346850 bs(y, degree = 1, knots = c(-0.4357, -0.3202))1-6.828 1.836 - 3.719 0.000200 *** bs(y, degree = 1, knots = c(-0.4357, -0.3202))2-4.426 1.614 - 2.742 0.006105 ** bs(y, degree = 1, knots = c(-0.4357, -0.3202))3-11.216 2.861 - 3.920 8.86e-05 *** #SAS codes data b; set a; if distance 16.13 then d1=1; else d1=0; distance2=d1*(distance - 16.13); if distance 24 then d2=1; else d2=0; distance3=d2*(distance - 24); if y-0.4357 then dd1=1; else dd1=0; y2=dd1*(y+0.4357); if y-0.3202 then dd2=1; else dd2=0; y3=dd2*(y+0.3202); run; proc logistic descending data=b; model mark =x elevation elevation*elevation distance distance2 distance3 y y2 y3; run; The LOGISTIC Procedure Analysis of Maximum Likelihood Estimates Standard Wald Parameter DFEstimate Error Chi-SquarePr ChiSq Intercept1 -2.6148 2.1445 1.4867 0.2227 x1 5.8146 1.9872 8.5615 0.0034 elevation1 0.4457 0.1506 8.7545 0.0031 elevation*elevation 1 -0.0279 0.0142 3.8533 0.0496 distance 1 -0.1091 0.0963 1.2836 0.2572 distance21 -1.0418 0.2668 15.2424 .0001 distance31 2.8633 0.7555 14.3625 0.0002 y1-16.2032 4.3568 13.8314 0.0002 y2 1 36.9974 10.3219 12.8476 0.0003 y3 1-58.4938 14.0279 17.3875 .0001 Q: What is the problem? which one is correct for the piecewise linear function? Thanks very much. -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:+86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Specify a correct formula in R for Piecewise Linear Functions?
*example*( pmin ) is useful. I will use it from now on. Thanks a lot. On Jan 3, 2008 2:50 AM, Charles C. Berry [EMAIL PROTECTED] wrote: On Thu, 3 Jan 2008, zhijie zhang wrote: Some developments with confusions. I tried the spline method and dummy variable approach to do it. But their results are very different. See following. [volumes of output and gratuitous SAS code deleted] Q1: Why are these two methods so different for the results, e.g. the coefficients? For the same reason that Thomas replied to my email suggesting a different approach than the one I showed you. viz. The spline basis differs from the basis vectors he constructed. Q2: The spline method is useful for piecewise linear functions, e.g. bs(distance_trans,degree=1,knots=c(13,25)), but how should i do if i want to fit a linear function for the case the distance_trans13,and quadratic curve when distance_trans=13? bs(distance_trans,degree=c(1,2),knots=13) cannot works. And even for more than three parts. 13,13~25, 25. Whew! My response would be don't go there. Fit a richer basis than you need and use penalization to damp out unneeded variation in the fit. Or use GAMs. But if you feel you must, you can construct things like bs( pmax( 13, pmin( 25 , x ) ) Q3:fit - glm( y ~ pmax(x,20)+pmin(x,20), family=binomial) is good. But if i divide x into three or more parts, how should i specify it in this way? As above. Hope somone can help.Thanks a lot. You can help youself a lot by taking a few minutes to learn to do in R what you did in SAS. Reading the help pages AND running the examples is often illuminating. For example, example( pmin ) should give you some helpful hints. HTH, Chuck On Jan 2, 2008 11:58 PM, Thomas Lumley [EMAIL PROTECTED] wrote: On Tue, 1 Jan 2008, Charles C. Berry wrote: On Tue, 1 Jan 2008, zhijie zhang wrote: Dear all, I have two variables, y and x. It seems that the relationship between them is Piecewise Linear Functions. The cutpoint is 20. That is, when x20, there is a linear relationship between y and x; while x=20, there is another different linear relationship between them. How can i specify their relationships in R correctly? # glm(y~I(x20)+I(x=20),family = binomial, data = point) something like this? Try this: library(splines) fit - glm( y ~ bs( x, deg=1, knots=20 ), family=binomial) In the linear case I would actually argue that there is a benefit from constructing the spline basis by hand, so that you know what the coefficients mean. (For quadratic and higher order splines I agree that pre-existing code for the B-spline basis makes a lot more sense). For example, in fit - glm( y ~ pmax(x,20)+pmin(x,20), family=binomial) the coefficients are the slope when is 20 and the slope when x20. -thomas Thomas Lumley Assoc. Professor, Biostatistics [EMAIL PROTECTED]University of Washington, Seattle -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:+86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com http://www.statabc.com/ [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:[EMAIL PROTECTED] UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:+86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help on ROC analysis
Thanks. library(ROCR) was used finally. It also automatically generate a plot beside the value of AUC. On Dec 31, 2007 11:38 PM, Frank E Harrell Jr [EMAIL PROTECTED] wrote: zhijie zhang wrote: Dear all, Some functions like 'ROC(Epi)' can be used to perform ROC analyssi, but it needs us to specify the fitting model in the argument. Now i have got the predicted p-values (0,1) for the 0/1 response variable using some other approach, see the following example dataset: id mark predict.pvalue 1 1 0.927 2 0 0.928 3 1 0.928 .. *mark* is the true classes, *predict.pvalue* is the predicted p-values, which was used to determine the predicted classes. So i need to specify some cut points for *predict.pvalue*, and then compare it with *mark*class, generate the 2*2 tables, and then calculate some sensitivity, specifitystatistcs, and ROC curve. I have searched some functions, such as roc(analogue),'ROC(Epi),etc. They may need to specify the fitting model in the codes or group varibles, and may be not appropriate for my condition. I think that it should have been performed in some package for ROC analysis. Anybody can tell me which function is for this case? Thanks very much. Forming the ROC curve can lead to bad statistical practice, e.g., use of non-pre-specified cutpoints and use of cutpoints in general. The area under the ROC curve is a valid measure of predictive discrimination though (even though it cannot be used to compare 2 models as it is not sensitive enough). To get the ROC area you can use the simple somers2 function in the Hmisc package. Frank -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:+86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[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] Specify a correct formula in R for Piecewise Linear Functions?
Dear all, I have two variables, y and x. It seems that the relationship between them is Piecewise Linear Functions. The cutpoint is 20. That is, when x20, there is a linear relationship between y and x; while x=20, there is another different linear relationship between them. How can i specify their relationships in R correctly? # glm(y~I(x20)+I(x=20),family = binomial, data = point) something like this? Thanks a lot. -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:+86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] help on ROC analysis
Dear all, Some functions like 'ROC(Epi)' can be used to perform ROC analyssi, but it needs us to specify the fitting model in the argument. Now i have got the predicted p-values (0,1) for the 0/1 response variable using some other approach, see the following example dataset: id mark predict.pvalue 1 1 0.927 2 0 0.928 3 1 0.928 .. *mark* is the true classes, *predict.pvalue* is the predicted p-values, which was used to determine the predicted classes. So i need to specify some cut points for *predict.pvalue*, and then compare it with *mark*class, generate the 2*2 tables, and then calculate some sensitivity, specifitystatistcs, and ROC curve. I have searched some functions, such as roc(analogue),'ROC(Epi),etc. They may need to specify the fitting model in the codes or group varibles, and may be not appropriate for my condition. I think that it should have been performed in some package for ROC analysis. Anybody can tell me which function is for this case? Thanks very much. -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:+86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Two repeated warnings when runing gam(mgcv) to analyze my dataset?
Dear Simon, Sorry for an incomplete listing of the question. #mgcv version is 1.3-29, R 2.6.1, windows XP #m.gam-gam(mark~s(x)+s(y)+s(lstday2004)+s(ndvi2004)+s(slope)+s(elevation)+disbinary,family=binomial(logit),data=point) The above program's the core codes in my following loop programs. It works well if i run the above codes only one time for my dataset, but warnings will occur if i run many times for the following loop. while (j1001) { + index=sample(ID, replace=F) + m.data$x=coords[index,]$x + m.data$y=coords[index,]$y + # For each permutation, we run the GAM using the optimal span for the above model m.gam + s.gam -gam(mark~s(x)+s(y)+s(lstday2004)+s(ndvi2004)+s(slope)+s(elevation)+disbinary,,sp=c( 5.582647e-07,4.016504e-02,2.300424e-04,1.274065e+03,9.558236e-09, 1.868827e-08),family=binomial(logit),data=m.data) + permresults[,i]=predict.gam(s.gam) + i=i+1 + if (j%%100==0) print(i) + j=j+1 + } [1] 101 [1] 201 [1] 301 [1] 401 [1] 501 [1] 601 [1] 701 [1] 801 [1] 901 [1] 1001 warnings() over 50 warnings() 1: In gam.fit(G, family = G$family, control = control, gamma = gamma, ... : fitted probabilities numerically 0 or 1 occurred .. 14: In gam.fit(G, family = G$family, control = control, gamma = gamma, ... : Algorithm did not converge .. On Dec 17, 2007 4:54 PM, Simon Wood [EMAIL PROTECTED] wrote: What mgcv version are you running (and on what platform)? n Thursday 13 December 2007 17:46, zhijie zhang wrote: Dear all, I run the GAMs (generalized additive models) in gam(mgcv) using the following codes. m.gam -gam(mark~s(x)+s(y)+s(lstday2004)+s(ndvi2004)+s(slope)+s(elevation)+disbin ary,family=binomial(logit),data=point) And two repeated warnings appeared. Warnings: 1: In gam.fit(G, family = G$family, control = control, gamma = gamma, ... : Algorithm did not converge 2: In gam.fit(G, family = G$family, control = control, gamma = gamma, ... : fitted probabilities numerically 0 or 1 occurred Q1: For warning1, could it be solved by changing the value of mgcv.toloptions for gam.control(mgcv.tol=1e-7)? Q1: For warning2, is there any impact for the results if the fitted probabilities numerically 0 or 1 occurred ? How can i solve it? I didn't try the possible solutions for them, because it took such a longer time to run the whole programs. Could anybody suggest their solutions? Any help or suggestions are greatly appreciated. Thanks. -- Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK +44 1225 386603 www.maths.bath.ac.uk/~sw283 -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:+86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[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] Two repeated warnings when runing gam(mgcv) to analyze my dataset?
Dear all, I run the GAMs (generalized additive models) in gam(mgcv) using the following codes. m.gam -gam(mark~s(x)+s(y)+s(lstday2004)+s(ndvi2004)+s(slope)+s(elevation)+disbinary,family=binomial(logit),data=point) And two repeated warnings appeared. Warnings: 1: In gam.fit(G, family = G$family, control = control, gamma = gamma, ... : Algorithm did not converge 2: In gam.fit(G, family = G$family, control = control, gamma = gamma, ... : fitted probabilities numerically 0 or 1 occurred Q1: For warning1, could it be solved by changing the value of mgcv.toloptions for gam.control(mgcv.tol=1e-7)? Q1: For warning2, is there any impact for the results if the fitted probabilities numerically 0 or 1 occurred ? How can i solve it? I didn't try the possible solutions for them, because it took such a longer time to run the whole programs. Could anybody suggest their solutions? Any help or suggestions are greatly appreciated. Thanks. -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:+86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[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] Hep on using GAM() in R
Dear friends, I met some problem on using GAM() function in R. Any help or suggestions are greatly appreciated. # My programs and problems are list below# library(splines) library(gam) point-read.csv(d:/gam.csv,sep=,,header=TRUE) #read the data gam.opt-gam(mark~lo(x,y,span=0.2)+lo(lstday2004,span=0.2)+lo(slope,span=0.2)+lo(ndvi2004,span= 0.2)+lo(elevation,span=0.2)+disbinary, family=binomial(logit),data=point) #span is 0.2 #when you run the above codes, 30 warnings() appear warnings() Warning message: 1: In lo.wam(x, z, wz, fit$smooth, which, fit$smooth.frame, ... : lo.wam convergence not obtained in 30 iterations 2: In lo.wam(x, z, wz, fit$smooth, which, fit$smooth.frame, ... : lo.wam convergence not obtained in 30 iterations . gam.opt2-gam(mark~lo(x,y,span=0.05)+lo(lstday2004,span=0.05)+lo(slope,span= 0.05)+lo(ndvi2004,span=0.05)+lo(elevation,span=0.05 )+disbinary,family=binomial(logit),data=point)#span is 0.05 #22 warnings() warnings() 1: In lo.wam(x, z, wz, fit$smooth, which, fit$smooth.frame, ... : k-d tree limited by memory; nvmax= 226 2: In lo.wam(x, z, wz, fit$smooth, which, fit$smooth.frame, ... : pseudoinverse used at 14923 3: In lo.wam(x, z, wz, fit$smooth, which, fit$smooth.frame, ... : neighborhood radius 1 4: In lo.wam(x, z, wz, fit$smooth, which, fit$smooth.frame, ... : reciprocal condition number 0 Q1: Their warning messages were differernt, are there any problem with the codes that i used? What does these warnings mean? Q2: As we know, the span is an important role for smoothing, so i try to choose the optimal span by the AIC criterion. But it seemed that i can't run it successfully, My codes are listed below. hmin-0.05; hmax-0.95; hstart-hmin; nh-100 hstep-(hmax-hmin)/(nh-1) aic.h- matrix(NA,nrow=nh,ncol=2) for (i in 1:nh) { htry-hstart+(i-1)*hstep m.gam -gam(mark~lo(x,y,span=htry)+lo(lstday2004,span=htry)+lo(slope,span=htry)+lo(ndvi2004,span=htry)+lo(elevation,span=htry)+disbinary,family=binomial(logit),data=point) aic.h[i,2]-m.gam$aic aic.h[i,1]-htry } aic.h #only the first line in aic.h has values, there must be errors in my codes Where goes wrong? How should i do for determining the best span for different variables? Any help or suggestions are greatly appreciated? BTW, I'd like to send you my dataset off this mailing list if possible. -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:+86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[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] Probelms on using gam(mgcv)
Dear all, Following the help from gam(mgcv) help page, i tried to analyze my dataset with all the default arguments. Unfortunately, it can't be run successfully. I list the errors below. #m.gam-gam(mark~s(x,y)+s(lstday2004)+s(slope)+s(ndvi2004)+s(elevation)+s(disbinary),family=binomial(logit),data=point) m.gam-gam(mark~s(x,y,k=10)+s(lstday2004,k=10)+s(slope,k=10)+s(ndvi2004,k=10)+s(elevation,k=10)+s(disbinary,k=10),family=binomial(logit),data=point) m.gam-gam(mark~s(x.1,y.1,k=10)+s(lstday2004,k=10)+s(slope,k=10)+s(ndvi2004,k=10)+s(elevation,k=10)+s(disbinary,k=10),family=binomial(logit),data=point) #?? Errors: smooth.construct.tp.smooth.spec(object, data, knots) : A term has fewer unique covariate combinations than specified maximum degrees of freedom. ## Descriptions for my dataset ## There are 1 response variable mark (1-case,0-control), and 7 explanatory covariables. x/y are spatial coordinates, lstday2004, slope, ndvi2004, elevation: continuous variables; disbinary : binary variable. Is there any problems with the above codes? How should i solve it? Any help or suggestions are greatly appreciated. -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:+86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com http://www.statabc.com/ [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[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] question on image() function?
Dear friends, My dataset is like the following: xy mcpvalue 0.4603578 0.6247629 1.001 0.4603715 0.62477881.001 0.4603852 0.6247948 1.001 0.4110561 0.5664841 0.995 The x and y variables are unsorted. I use the function image(x,y,mcpvalue) to generate a plot, but the error is that increasing 'x' and 'y' values are expected. So i use image(x=seq(min(x),max(x)), y=seq(min(y),max(y)),z=as.matrix (result$mcpvalue)) to do it again, but there is still an error dimensions of z are not length(x)(-1) times length(y)(-1). Anybody can show me how to use the image() correctly with the original x/y unsorted? Thanks very much. -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:+86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[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] Anybody has ever met the problem to add a legend to a figure generated by image()?
Dear friends, Anybody has ever met the problem to add a legend to a figure generated by image()? I have three variables,x,y and z. x and y are the coordinates, and z is the third values. we can use image(x, y, z,...) to generate a figure according to the z-values, but the problem is the figure legend. How can the legend be added to a figure generated by image()? Note that filled.contour() can add the figure legend automatically, but there are some problems sometime. I want to know the specific method for adding the legend to the figure generated by image(). Thanks very much. -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to add legend for image()?
Dear friends, The following is an example to explain my question. I want to get a legend which will show the z-values according to different colors in image() function. x-sort(runif(10)) #x-coordinates y-sort(runif(10)) #y-coordinates z-matrix(runif(100),nrow=10) #attributes values image(x,y,z,col=gray((6:3)/6)) # legend(x,y,legend=z,col=gray((6:3)/6)) #error. the colors should denote different z-values, i want to get this legend. Thanks. -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[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] return(x=x,y=y,prob=prob) hasn't been used in R now?
Dear friends, Now, when i use the argument return(x=x,y=y,prob=prob) , R displays the waring message: Warning message: The return value for multiple variables wasn't used in: return(x = x, y = gy, prob = prob) I used the methods of help.search(return) and ?return to get some help, but didn't find info on it. Anybody knows how it should be used correctly? #EXAMPLES a-function(x,y,z) { gx-seq(1,10,length.out=20) gy-gx prob-matrix(20,20) for (i in 1:20) { for (j in 1:20) { prob-0.1 } } return(x=gx,y=gy,prob=prob) } a(1,1,1) # the warning message will display Thanks. -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] return(x=x,y=y,prob=prob) hasn't been used in R now?
It works well. Thanks a lot. On 9/23/07, Christian Ritz [EMAIL PROTECTED] wrote: Hi! Use a list structure for all the components you want to have returned by the function: return(list(x=x, y=y, prob=prob)) Christian -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] return(x=x,y=y,prob=prob) hasn't been used in R now?
Dear Prof. Brian Ripley, You are absolutely right. The warning message in R for my Chinese Windows system is Chinese words, so i translate it into english, which maybe not that exact in the meanings. Thanks very much. On 9/23/07, Prof Brian Ripley [EMAIL PROTECTED] wrote: On Sun, 23 Sep 2007, Peter Dalgaard wrote: zhijie zhang wrote: Dear friends, Now, when i use the argument return(x=x,y=y,prob=prob) , R displays the waring message: Warning message: The return value for multiple variables wasn't used in: return(x = x, y = gy, prob = prob) I used the methods of help.search(return) and ?return to get some help, but didn't find info on it. Anybody knows how it should be used correctly? Return(value) takes only one argument. To return a list, return(list(x=x,y=y,prob=prob)) I bet the author of help(return) thought that this was implied clearly enough. and the warning message in English is not what is quoted here: f - function() return(x=pi, y=pi) f() $x [1] 3.141593 $y [1] 3.141593 Warning message: In return(x = pi, y = pi) : multi-argument returns are deprecated so they are in fact used. What is puzzling is that anyone is still trying to use them years after they were deprecated (and as the help page says they were never documented in S, quite how they ever got into circulation in R). #EXAMPLES a-function(x,y,z) { gx-seq(1,10,length.out=20) gy-gx prob-matrix(20,20) for (i in 1:20) { for (j in 1:20) { prob-0.1 } } return(x=gx,y=gy,prob=prob) } a(1,1,1) # the warning message will display Thanks. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[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] What's the corresponding function in R for lo() function in S-PLUS?
Dear friends, In S-PLUS, we can use the following argument, but not in R. mode12 - gam(score1 ~ lo(latitude) + lo(longitude)) I searched the help in S-PLUS, it says lo() Allows the user to specify a Loess fit in a GAM formula, but i didn't find the correponding function in R. Anybody knows how to do the similar task in R? Thanks very much. -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[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] Calculate the angles for a point dataset?
Dear Rusers, I'd like to take the cases of cancer of the larynx in chorley(spatstat) to explain my question. I want to join the points of cancer of the larynx with the disused industrial incinerator to generate lines, and then calculate the angles of these line comparing the horizontal line? How can i get it? It seems to be difficult to get the angles Thanks a lot. -- With Kind Regards, oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [***] Zhi Jie,Zhang ,PHD Tel:86-21-54237149 Dept. of Epidemiology,School of Public Health,Fudan University Address:No. 138 Yi Xue Yuan Road,Shanghai,China Postcode:200032 Email:[EMAIL PROTECTED] Website: www.statABC.com [***] oooO: (..): :\.(:::Oooo:: ::\_)::(..):: :::)./::: ::(_/ : [[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.