How do I specify the type of regression in calling a procedure/ In the following I call the procedure to do a probit regression. Of course, I can change "probit" into "lm" in procedure "myreg" to do a linear regression. My question is, how do I automate this (choice of lm or probit) in calling "myreg", with a proper input (e.g., model=lm)? Thank you. --- eq1<-d~sex+age+children b<-myreg(eq1,data=mydata); summary(b) myreg<-function(formula,data){ data<-model.frame(formula,data) reg<-probit(formula,data=data) return(reg) }
"Automate" is vague and ill-defined. But perhaps ?do.call is what you're looking for; e.g. myProc <- function(FUN, ...) do.call(FUN,...) This is one of the cool things about functional type programming -- you can pass functions as arguments. If this is not it, maybe someone else will groc what you mean -- or you could define yourself more clearly. Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." Clifford Stoll On Mon, Dec 22, 2014 at 2:53 PM, Steven Yen <syen04 at gmail.com> wrote:> How do I specify the type of regression in calling a procedure/ > In the following I call the procedure to do a probit regression. Of course, > I can change "probit" into "lm" in procedure "myreg" to do a linear > regression. > > My question is, how do I automate this (choice of lm or probit) in calling > "myreg", with a proper input (e.g., model=lm)? Thank you. > > --- > eq1<-d~sex+age+children > b<-myreg(eq1,data=mydata); summary(b) > > myreg<-function(formula,data){ > data<-model.frame(formula,data) > reg<-probit(formula,data=data) > return(reg) > } > > ______________________________________________ > 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.
.. that should have been either myProc <- function(FUN, ...) do.call(FUN,list(...)) or myProc <- function(FUN, ...) FUN(...) My other comments still apply. Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." Clifford Stoll On Mon, Dec 22, 2014 at 3:08 PM, Bert Gunter <bgunter at gene.com> wrote:> "Automate" is vague and ill-defined. But perhaps ?do.call is what > you're looking for; e.g. > > myProc <- function(FUN, ...) do.call(FUN,...) > > This is one of the cool things about functional type programming -- > you can pass functions as arguments. > > If this is not it, maybe someone else will groc what you mean -- or > you could define yourself more clearly. > > Cheers, > Bert > > Bert Gunter > Genentech Nonclinical Biostatistics > (650) 467-7374 > > "Data is not information. Information is not knowledge. And knowledge > is certainly not wisdom." > Clifford Stoll > > > > > On Mon, Dec 22, 2014 at 2:53 PM, Steven Yen <syen04 at gmail.com> wrote: >> How do I specify the type of regression in calling a procedure/ >> In the following I call the procedure to do a probit regression. Of course, >> I can change "probit" into "lm" in procedure "myreg" to do a linear >> regression. >> >> My question is, how do I automate this (choice of lm or probit) in calling >> "myreg", with a proper input (e.g., model=lm)? Thank you. >> >> --- >> eq1<-d~sex+age+children >> b<-myreg(eq1,data=mydata); summary(b) >> >> myreg<-function(formula,data){ >> data<-model.frame(formula,data) >> reg<-probit(formula,data=data) >> return(reg) >> } >> >> ______________________________________________ >> 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.
I like to multiple the first and second column of a 10 x 3 matrix by 100. The following did not work. I need this in an operation with a much larger scale. Any help? aa<-matrix(1:30,nrow=10,ncol=3); aa bb<-matrix(c(100,100,1),nrow=1,ncol=3); bb dim(aa) dim(bb) aa*bb Results: > aa<-matrix(1:30,nrow=10,ncol=3); aa [,1] [,2] [,3] [1,] 1 11 21 [2,] 2 12 22 [3,] 3 13 23 [4,] 4 14 24 [5,] 5 15 25 [6,] 6 16 26 [7,] 7 17 27 [8,] 8 18 28 [9,] 9 19 29 [10,] 10 20 30 > bb<-matrix(c(100,100,1),nrow=1,ncol=3); bb [,1] [,2] [,3] [1,] 100 100 1 > dim(aa) [1] 10 3 > dim(bb) [1] 1 3 > aa*bb Error in aa * bb : non-conformable arrays >