1 / 31

Biostat 201: Winter 2011

Biostat 201: Winter 2011. Lab Session 2. SAS/STATA code key. I will use the following convention in these slides: statements : bold keywords : italics options : underlined Variables, or something you specify yourself : courier font . Assignment 2. What do we need to do?. Import data

milly
Download Presentation

Biostat 201: Winter 2011

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Biostat 201: Winter 2011 Lab Session 2

  2. SAS/STATA code key • I will use the following convention in these slides: • statements: bold • keywords: italics • options: underlined • Variables, or something you specify yourself: courier font

  3. Assignment 2

  4. What do we need to do? • Import data • Carry out a linear regression in each group • Fit the “sigmoid” model to each group • Obtain the predicted mean and standard error for a particular covariate profile • Calculate the correlation of the true values with the fitted values

  5. SAS: Importing data • http://www.ats.ucla.edu/stat/sas/faq/rwxls8.htm • http://www.ats.ucla.edu/stat/sas/faq/read_delim.htm • Can use import wizard:file  import data… • proc importout=datasetdatafile="directory_of_excel_file"dbms=excelreplace;sheet="sheet_name";run;

  6. SAS: Importing data • http://www.ats.ucla.edu/stat/sas/faq/rwxls8.htm • http://www.ats.ucla.edu/stat/sas/faq/read_delim.htm • Can use import wizard:file  import data… • procimport datafile="G:\TA - Biostat 201 Winter 2011\PHARM.csv" out=t dbms=csv replace; run;

  7. STATA: Importing data • http://www.ats.ucla.edu/stat/stata/faq/readcommatab.htm • cd "directory_of_csv_file" • insheetusingfile_name

  8. STATA: Importing data • http://www.ats.ucla.edu/stat/stata/faq/readcommatab.htm • cd "G:\TA - Biostat 201 Winter 2011" • insheetusingPHARM.csv

  9. SAS: Linear regression • proc sortdata=dataset; by grpvar;run;proc regdata=dataset;modelyvar = x1x2x3 / clb;bygrpvar;run; quit;

  10. SAS: Stratified modelExample from previous lab • proc sortdata=dataset; by grpvar;run;procregdata=dataset;modelyvar = x1x2x3;bygrpvar;run; quit; You must SORT by the grouping variable before you run the stratified model.

  11. SAS: Stratified modelExample from previous lab • procsort data=kidney; by cens; run; • procreg data=kidney; model cith=dage; by cens; run; quit;

  12. STATA: Stratified modelExample from previous lab • bysortgrpvar: regress yvarx1x2 • bysort cens: regress cith dage

  13. SAS: Nonlinear regression • proc sortdata=dataset; by grpvar;run; • proc nlindata=dataset;parametersp1=# p2=# …;modelyvar = eqn_with_parameters;run; quit; • proc nlindata=dataset;parametersp1=# p2=# …;modelyvar = eqn_with_parameters;bygrpvar;run; quit; Only 1 group More than 1 group

  14. SAS: Nonlinear regressionSAME Example in Lecture 5 • procnlin data=t; parameters b1=0.10 b2=0.04; model conc = (b1/(b1-b2))*( exp(-b2*time) - exp(-b1*time) ); output out=s predicted=pred residual=resid; run; quit; Hint: Example given here IS NOT the same as the HW assignment. In HW, you would need to run two nonlinear models. Therefore, you would need the “by” statement in your “proc nlin” since there are two treatment (drugs) to compare.

  15. SAS: Nonlinear regressionSAME Example in Lecture 5Output from SAS

  16. STATA: Nonlinear regression • nl (y = eqn_w_parameters), initial (p1 # p2 # …) • bysortgrpvar: nl (y = eqn_w_parameters), initial (p1 # p2 # …) Only 1 group More than 1 group

  17. STATA: Nonlinear regressionSAME Example in Lecture 5 • nl (conc = ({b1}/({b1}-{b2}))* (exp(-{b2}*time) - exp(-{b1}*time)) ), initial(b1 0.1 b2 0.04 ) Hint: Example given here IS NOT the same as the HW assignment. In HW, you would need to run two nonlinear models. Therefore, you would need the “bysort grpvar:” statement before your “nl” command since there are two treatment (drugs) to compare.

  18. STATA: Nonlinear regressionOutput from STATASAME Example in Lecture 5

  19. Final Model

  20. Notes on nonlinear regression • Iterative process to obtain parameter estimates • Note that you indicate what parameters need to be estimated, and you also provide initial estimates to get the iterative process started • It is assumed that other variables not denoted as parameters are variables in the dataset

  21. Predicted mean differences • Question:Observation 1 has “this” particular profile, and observation 2 has “that” particular profile. Is there a difference in their predicted mean response/outcome? • Example:Obs1: time = 49Obs2: time = 51

  22. Predicted mean differences • Strategy • Add observations with the specified covariate profiles with the outcome missing • Run the regression model and request the predicted outcome with standard error of the prediction • Look at the results

  23. SAS: Predicted mean differences • Add observations data profiles; input time; cards; 49 51 ; run; data t; set t profiles; run;

  24. SAS: Predicted mean differences • Analyze and request standard error of the prediction • Same as Proc Reg; The output line also works for proc nlin procnlin data=t; parameters b1=0.10 b2=0.04; model conc = (b1/(b1-b2))*( exp(-b2*time) - exp(-b1*time) ); output out=s predicted=pred residual=resid stdp=yprese; run;

  25. SAS: Predicted mean differences • Now if you open the “s” dataset, you can scroll down and view the predicted values and the standard error of the prediction

  26. STATA: Predicted mean differences • Add observations • It’s probably easiest to do this using the data editor • Our dataset has 51 observations: • setobs53replacetime=49in52replacetime=51in53

  27. STATA: Predicted mean differences • Analyze and request the standard error of the prediction • The same commands that work for reg will also work for nl • nl (conc = ({b1}/({b1}-{b2}))* (exp(-{b2}*time) - exp(-{b1}*time)) ), initial(b1 0.1 b2 0.04 ) • predict pred1 • predict se1, stdp • predict resid1, residuals

  28. STATA: Predicted mean differences • Now if you open the data browser, you can scroll down and view the predicted values and the standard error of the prediction

  29. SAS: Correlation • Correlation matrix: • proc corrdata=dataset;varx1 x2 x3 …;run; • Correlation matrix (by group): • proc corrdata=dataset;varx1 x2 x3 …;bygrpvar;run;

  30. STATA: Correlation Correlation matrix: corrx1 x2 x3 … Correlation matrix (by group): bysort grpvar: corrx1 x2 x3 …

  31. Examples of Pearson Correlation SAS CODE proccorr data=s; var conc pred; run; STATA CODE corrpred conc

More Related