lab5_exercises_new_2022

docx

School

University of Southern California *

*We aren’t endorsed by this school

Course

MISC

Subject

Statistics

Date

Apr 3, 2024

Type

docx

Pages

13

Uploaded by MegaElkPerson49

Report
Lab #5 Exercises  Use the subjdata.sas7bdat dataset located in the Lab Datasets folder in the Datasets section of Canvas. Please provide all relevant code and output to receive full credit for the lab.  Macro programming 1. Write a program to read in SUBJDATA and create a new variable that is the natural log of FEV. Run a linear regression of FEV on height. libname subject 'Z:\OneDrive\Documents\sas' ; options nofmterr ; data subject; set subject.lab9; logfev=log(fev); run ; proc reg data =subject; model logfev=height; run ;
2. Write a MACRO to perform a linear regression, with both the dependent (Y) and independent variable(s) (X) defined as macro variables. Make sure to include a descriptive title that utilizes the values of your macro variables. Test your macro with Y=FEV and X=height and check against your results in 1. Look at your LOG window to see how SAS generated program code from your MACRO (remember to include ‘options mprint’ to see this). options MPRINT ; %macro runreg(Y,X); proc reg data = subject; model &Y = &X; title 'Regression of &Y on &X' ; %mend runreg; % runreg (fev, height); run ;
3. Use the same MACRO you created in question 2 to run the following regressions: a. FEV vs. weight proc reg data =subject; model FEV=weight; run ; options MPRINT ; %macro runreg(Y,X); proc reg data = subject; model &Y = &X; title 'Regression of &Y on &X' ; %mend runreg; % runreg (FEV, height); run ; %mend runreg; % runreg (FEV, Height); % runreg (FEV, PM10 age height); % runreg (MMEF, PM10 sex height asthma); % runreg (Logfev, height); run ;
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
b. FEV vs. PM10, age and height
c. MMEF vs. PM10, sex, height, and asthma
d. Ln(FEV) vs. height (create a new variable to store Ln(FEV))
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
4. Write a new MACRO that revolves around the use of PROC GLM to perform regression analysis instead of PROC REG. Include three macro variables: CLASSVAR, Y, X, where Y and X are as defined above, and CLASSVAR is one or more variables that can be included as classification variables ( i.e. , variables for which we would use the CLASS statement in GLM). Test your program by running the following models: options MPRINT ; %macro model (dep, indepc, indep); proc glm data=subject;class race /ref = first; model &dep = &indep &indepc / solution; title 'Regression of FEV on &X' ; %mend model; % model (fev, race); % model (fev, height race); % model (fev, height); % model (logfev, height);
Run ; a. FEV vs. Race b. FEV vs. height and Race c. FEV vs. height (Hint: you can send a blank argument to a macro variable by putting a blank space in your call to the macro instead of providing a name. Remember to include a comma to separate the blank space from the other macro arguments).
d. Ln(FEV) vs. height 5. Augment your MACRO in question 4 to include the following features: Output predicted and residual values Plot the residual values against the X variable Plot the residual values against the predicted values Examine the distribution of residuals for normality Again, include descriptive titles for each new PROC added to your macro. Test your program using the models in 4c and 4d.   options MPRINT ; %macro model (dep, indepc, indep); proc glm data=subject;class race /ref = first; model &dep = &indep &indepc / solution; title 'Regression of FEV on &X' ; output out=regout p=pred r=resid; proc univariate data= regout normal plot;
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
var resid; ID id; title 'Check normality for regression of &Y on &X' ; proc gplot data=regout; plot resid*pred; title 'Resid vs Pred for Regression of &y on &X' ; %mend model; % model (fev, height); % model (logfev, height); run ;
a. Based on your output for these two models, does the use of FEV or Ln(FEV) better satisfy the assumptions of regression? Logfev and fev are pretty similar when is comes to the assumption of linear regression however, I think logfev would bet better because its natural log is always the safest way to go. b. Are there any apparent outliers? If so, which ID (‘s) appear to be problematic? (Hint: use the ‘ID’ statement in UNIVARIATE). Logfev fev 6. Perform the same regressions as those in question 5 (the newly augmented regressions), but instead of using a Macro, use a %let statement to change your variables. %let a = 5.5146; %let b = 0.014819; %let af = -2153.39711; %let bf = 29.691074; data subject; set subject; if logfev > 0 then do ; heightp = &a + &b * logfev;
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
end ; if fev > 0 then do ; heightpfev = &af + &bf * FEV; end ; run ; Proc print data =subject; run ; 7. Comment on which type of macro (%MACRO vs %LET) would be better to use in this situation? % Macro is the way to go. We can use % Macro multiple times inside a single SAS program. % LET is good for a short program. So in this situation it would be better to use % Macro.