Dear all, I'm newbie with R (changing from STATA), and I can't find some commands. One of those is the "combine", which I use to combine means like this: -------------------------------------------- n1 m1 sd1 n2 m2 sd2 combine 12 3 1 34 45 4 Combine has calculated the following values: combined n = 46 combined mean = 34.043478 combined SD = 18.964829 -------------------------------------------- Does anybody knows a simmilar command in R to combine means? Thanks in advance. Carlos. [[alternative HTML version deleted]]
Stata's documentation lists this as a meta-analysis tool. You may want to look at the rma function in the metafor package for various approaches to that problem. S Ellison> -----Original Message----- > From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Carlos R. > Moreira Maia > Sent: 30 June 2016 16:03 > To: r-help at r-project.org > Subject: [R] Command to combine means? > > Dear all, > I'm newbie with R (changing from STATA), and I can't find some commands. > One of those is the "combine", which I use to combine means like this: > > -------------------------------------------- > n1 m1 sd1 n2 m2 sd2 > > combine 12 3 1 34 45 4 > > Combine has calculated the following values: > combined n = 46 > combined mean = 34.043478 > combined SD = 18.964829 > -------------------------------------------- > > Does anybody knows a simmilar command in R to combine means? > > Thanks in advance. > > Carlos. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}
... Time to do your homework. Have you gone through any R tutorials? Some recommendations here: https://www.rstudio.com/online-learning/#R Cheers, Bert 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 Thu, Jun 30, 2016 at 8:02 AM, Carlos R. Moreira Maia <crm.maia at gmail.com> wrote:> Dear all, > I'm newbie with R (changing from STATA), and I can't find some commands. > One of those is the "combine", which I use to combine means like this: > > -------------------------------------------- > n1 m1 sd1 n2 m2 sd2 > > combine 12 3 1 34 45 4 > > Combine has calculated the following values: > combined n = 46 > combined mean = 34.043478 > combined SD = 18.964829 > -------------------------------------------- > > Does anybody knows a simmilar command in R to combine means? > > Thanks in advance. > > Carlos. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.
Hi Carlos, The STATA function assumes estimated population SDs. If you have sample SDs you can specify with this: combine<-function(n,mu,sd,sd.type=c("pop","sample")) { N<-sum(n) mean<-sum(n*mu)/N if(sd.type[1]=="sample") { meanss<-(n[1]*(mean-mu[1])^2+n[2]*(mean-mu[2])^2)/N SD<-sqrt(sum(sd*sd*n)/N+meanss) } else { meanss<-(n[1]*(mean-mu[1])^2+n[2]*(mean-mu[2])^2)/(N-1) SD<-sqrt(sum(sd*sd*(n-1))/(N-1)+meanss) } return(list(N,mean,SD)) } combine(c(12,34),c(3,45),c(1,4)) combine(c(12,34),c(3,45),c(1,4),"sample") Jim On Fri, Jul 1, 2016 at 1:02 AM, Carlos R. Moreira Maia <crm.maia at gmail.com> wrote:> Dear all, > I'm newbie with R (changing from STATA), and I can't find some commands. > One of those is the "combine", which I use to combine means like this: > > -------------------------------------------- > n1 m1 sd1 n2 m2 sd2 > > combine 12 3 1 34 45 4 > > Combine has calculated the following values: > combined n = 46 > combined mean = 34.043478 > combined SD = 18.964829 > -------------------------------------------- > > Does anybody knows a simmilar command in R to combine means? > > Thanks in advance. > > Carlos. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.
thank you very much Jim! I'll try it. bw c Sent from my iPhone> Em 30/06/2016, ?s 20:33, Jim Lemon <drjimlemon at gmail.com> escreveu: > > Hi Carlos, > The STATA function assumes estimated population SDs. If you have > sample SDs you can specify with this: > > combine<-function(n,mu,sd,sd.type=c("pop","sample")) { > N<-sum(n) > mean<-sum(n*mu)/N > if(sd.type[1]=="sample") { > meanss<-(n[1]*(mean-mu[1])^2+n[2]*(mean-mu[2])^2)/N > SD<-sqrt(sum(sd*sd*n)/N+meanss) > } else { > meanss<-(n[1]*(mean-mu[1])^2+n[2]*(mean-mu[2])^2)/(N-1) > SD<-sqrt(sum(sd*sd*(n-1))/(N-1)+meanss) > } > return(list(N,mean,SD)) > } > combine(c(12,34),c(3,45),c(1,4)) > combine(c(12,34),c(3,45),c(1,4),"sample") > > Jim > > > On Fri, Jul 1, 2016 at 1:02 AM, Carlos R. Moreira Maia > <crm.maia at gmail.com> wrote: >> Dear all, >> I'm newbie with R (changing from STATA), and I can't find some commands. >> One of those is the "combine", which I use to combine means like this: >> >> -------------------------------------------- >> n1 m1 sd1 n2 m2 sd2 >> >> combine 12 3 1 34 45 4 >> >> Combine has calculated the following values: >> combined n = 46 >> combined mean = 34.043478 >> combined SD = 18.964829 >> -------------------------------------------- >> >> Does anybody knows a simmilar command in R to combine means? >> >> Thanks in advance. >> >> Carlos. >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at 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.