150 likes | 314 Views
Stat 6601 Project: Model Formulae (V&R 6.2). Antonio Curtis Wai Mak Alvin Hsieh Statistics Students, CSUH. Model. where,. Multiple Regression Formula. Algebraic Expression. Data. Working Directory R - File>Change dir…>Click Browse>Select Desktop>Click OK
E N D
Stat 6601 Project:Model Formulae (V&R 6.2) Antonio Curtis Wai Mak Alvin Hsieh Statistics Students, CSUH
Model where, Multiple Regression Formula Algebraic Expression
Data Working Directory R - File>Change dir…>Click Browse>Select Desktop>Click OK SAS - where your program resides (*.sas) reading.txt Group Words Group Words Group Words X 700 Y 480 Z 500 X 850 Y 460 Z 550 X 820 Y 500 Z 480 X 640 Y 570 Z 600 X 920 Y 580 Z 610
R Program - Reading reading <- read.table("data/reading.txt",sep=' ', col.names=c('group','words')) obj <- lm(words ~ group, reading) anova(obj)
SAS Program - Reading data reading; infile "./data/reading.txt"; input group $ words @@; proc anova data=reading; title 'Analysis of Reading Data'; class group; model words = group; run;
Interaction • More than one independent variable • Relationship with independent variables • R code • y ~ a + b + a:b • y ~ (a + b)^2 • y ~ a * b • SAS code • y = a | b • y = a b a*b
Data ritalin.txt 50 45 55 52 67 60 58 65 70 72 68 75 51 57 48 55
R Program - Ritalin ritalin <- data.frame(group = factor(rep(c('normal','hyper'),each=8)), drug = factor(rep(c('placebo','ritalin'),each=4,times=2)), subj = factor(rep(1:4,4)), activity = factor(t(read.table("data/ritalin.txt",sep=' ')))) ritalin$activity <- as.numeric(ritalin$activity) names(ritalin) attach(ritalin) # Column 1 -- Group (Normal or Hyperactive) # Column 2 -- Drug (Placebo, Ritalin) # Column 3 -- Subject (1-4) # Column 4 -- Activity (Activity measurement) obj <- lm(activity ~ group * drug) obj anova(obj)
SAS Program - Ritalin data ritalin; infile "./data/ritalin.txt"; do group = 'normal','hyper '; do drug = 'placebo','ritalin'; do subj = 1 to 4; input activity @; output; end; end; end; run; procanova data=ritalin; title 'Activity Study'; class group drug; model activity = group | drug; run;
Difference R and SAS Reading in Data Defining variables Invoking commands Lines of codes Learning curve
Summary Model - General form Interaction R example SAS example Differences in R and SAS
Reference Applied Statistics and SAS Programming Language (4th ed) by Ronald P. Cody and Jeffrey K. Smith, Prentice-Hall, Inc., 1997 Modern Applied Statistics with S (4th ed) by W.N. Venables and B.D. Ripley, Springer-Verlag New York, Inc.,2002
Thank You! Any Questions? Have a nice day!
Extra - Contrasts • 4 supplied contrast functions: • contr.helmert (default) - unordered factors • contr.treatment - omitting level 1 (1=0) • Unbalanced layouts (GLM and survival models) • contr.sum - coefficients add to 0 (=0) • contr.poly (default - ordered) - equally spaced, equally replicated Code to specify contrasts: options(contrasts = c(“contr.helmert”,”contr.poly”))