Re: [R] macro facility in R

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Mon 03 Jul 2006 - 23:16:57 EST

> Try this:
>
> # test data
> set.seed(1)
> mat <- matrix(rnorm(900), nc = 9)
> colnames(mat) <- letters[1:9]
> DF <- as.data.frame(mat)
>
> # run lm's and display coefs
> for(i in seq(1, 5, 2)) {
> dat <- cbind(z = DF[,i] - DF[,i+1], DF[7:9])
> Coef <- coef(lm(z ~., dat))
> cat("y: DF[,", i, "] - DF[,", i+1, "], coef: ", Coef, "\n")
> }
>

In case of lm(), this could also be written as:

y <- mat[, c(1, 3, 5)] - mat[, c(2, 4, 6)] x <- mat[, 7:9]
lm(y ~ x)

Best,
Dimitris



Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


>
>
> On 7/3/06, John Sorkin <jsorkin@grecc.umaryland.edu> wrote:
>> R 2.2 on windows XP
>> I have a dataset with multiple columns. Some of the columns
>> represent
>> independent variables, some represent dependent variables. I would
>> like
>> to run the same analyses on a fixed set of independent variables,
>> changing only the dependent variable, e.g.
>> y1-y2=x1+x2+x3
>> y3-y4=x1+x2+x3
>> y5-y6=x1+x2+x3, etc.
>> I know I can write a function to perform the analyses, however in
>> order
>> to make the analyses easy to do, I really need a macro scripting
>> language that will allow preprocessing of the function and
>> substitution
>> of macro variables with parameters passed to the macro, i.e. I need
>> someting akin to the macro facility in SAS. Is there a macro
>> facility
>> that I can use with R? I have tried help.search("macro") and did
>> not
>> have any success.
>> Thanks,
>> John
>>
>> John Sorkin M.D., Ph.D.
>> Chief, Biostatistics and Informatics
>> Baltimore VA Medical Center GRECC,
>> University of Maryland School of Medicine Claude D. Pepper OAIC,
>> University of Maryland Clinical Nutrition Research Unit, and
>> Baltimore VA Center Stroke of Excellence
>>
>> University of Maryland School of Medicine
>> Division of Gerontology
>> Baltimore VA Medical Center
>> 10 North Greene Street
>> GRECC (BT/18/GR)
>> Baltimore, MD 21201-1524
>>
>> 410-605-7119

>> jsorkin@grecc.umaryland.edu
>>
>> ______________________________________________
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
>>
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Jul 03 23:15:26 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 04 Jul 2006 - 00:14:23 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.