COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Drop down to R and use Zelig Statistical Package for General Linear Models(with Mixed models)

• Email
• Follow

```Hi SAS-Lrs,

This will allow programmers to develop General Linear Models without
SAS-Stat. The techniques below can be used with many of the other
2000+ packages on CRAN. Programmers can then use some of the new SG,
SVG and ods graphics on the data back from R.

For a cleaner version with more details:

http://homepage.mac.com/magdelina/.Public/utl.html
utl_tipweb.txt

/* T005210 DROP DOWN TO R IN A DATASTEP FOR STATISTICAL ANALYSIS

As a lark I wrote prototype SAS code that does the following:

The code lets you do general linear models with just base SAS
I use the Zelig package in R which seems very powerful?

Within one datastep it is possible mix SAS and R code. In fact you
can:
1.  Send data to R (putxpt)
2.  Run the R code imbeded between SAS  statements in the data step
3.  Get results back from R (getxpt)
4.  Run additional SAS code on the R datasets

This is a simpler version of the code on my site:

data regress;
set sashelp.class;
run;
data _null_;
call putxpt('regress'); /* create xport dataset for R */
/* R CODE FOR ANALYSIS OF VARIANCE */
pgm=compbl("
library(SASxport);
library(foreign);
library(Zelig);
z.o1 <- zelig(AGE ~ SEX + WEIGHT + HEIGHT, model =
""aov"", data = cls);
coefs<-z.o1\$coefficients;
coef=data.frame(names(coefs),coefs);
write.xport(coef,file='C:\\utl\
\coef.xpt',autogen.formats=FALSE);");
/* EXECUTE R CODE */
call rxeq(pgm);
call getxpt('coef');    /* Convert V5 export dataset COEF
from R to SAS dataset */
run;
proc print data=coef noobs;run;

The results of this could be

Analysis of Variance Table(AOVTBL) :: Model=AGE = SEX + WEIGHT +
HEIGHT

Obs    ROWNAMES     DF     SUM_SQ    MEAN_SQ    F_VALUE     PR__F_

1     SEX           1     0.1497     0.1497     0.2031    0.65867
2     WEIGHT        1    25.0028    25.0028    33.9212    0.00003
3     HEIGHT        1     3.8965     3.8965     5.2863    0.03628
4     Residuals    15    11.0563     0.7371      .         .

details
===========
1. Communications with R are via a pipe (I pipe R statements
into R.exe)
2. Results to and from R are V5 transport datasets (8 char names
and 200 byte char values but lossless)
3. You have to call fcmp to 'put' and 'get' xpt datasets
4. I use multiple macro variables for the R code due to a
262 byte limit in run_marco (I allow for 1000 byte R
programs)
5. Semicolns must end each R statement and cannot be used
anywhere else
6. Program expects the PWD - working directory to be C:\\utl -
Cap C and \\ are  needed for R(you use macros variables)
7. SAS 9.2
8. You need 2.7 or later R. install.packages(Zelig) also
SASxport and foreign
```
 0
Reply xlr82sas (391) 2/21/2010 9:57:15 AM

See related articles to this posting

0 Replies
51 Views

Similar Articles

12/6/2013 2:37:34 PM
page loaded in 58627 ms. (0)