The constant (_cons) is not significantly different from 0 at the 0.05 alpha level. However, having a significant intercept is seldom interesting.

47 Food Expenditure0100200300400500600Income010203040Food Expenditure data

48 SAS program notes *________________________________________________________________ * code: SLR-foodexample.sas * prog: Hui Li * input: food.csv ________________________________________________________________; ******************************************************************; * 1. Read in the data MAKE SURE you saved the data food.csv ******************************************************************; options nodate nonumber nocenter linesize=78; data food; infile 'C:\Users\lihq\Desktop\data\food.csv' delimiter = ',' MISSOVER firstobs=2; input food_exp income; lninc=log(income); *create a new variable "lninc" by taking logarithm; run; proc contents data=food position; * examine data set, y=food expenditure ($) x=weekly income ($100); run; proc print data=food(obs=10); * print first 10 obs; run; options nolabel; * turn off labels; proc means data=food; * summary statistics; run; symbol1 value=dot color=blue; * symbol for scatter diagram; /* axis statements are first for vertical axis and second for horizontal axis. Ranges of values determined by data min and max, and desire to include origin */ axis1 order=(0 to 600 by 100) label=("Food Expenditure"); axis2 order=(0 to 40 by 10) label=("Income"); /* specify plot option for vertical axis (vaxis) and horizontal axis (haxis) */ proc gplot data=food; plot food_exp*income/vaxis=axis1 haxis=axis2; title 'Food Expenditure data'; run;

49 proc reg data=food; * least squares regession; model food_exp = income; * specify model; title 'food expenditure regression'; run; /* proc means with options */ proc means data=food n mean std maxdec=3; *specify the decimal places of 3; var food_exp; run; /* print covariance matrix of least squares estimates */ proc reg data=food; model food_exp = income/covb; * option COVB for covariance; title 'regression with covariance options'; run; /* least squares residuals output to data set */ proc reg data=food; model food_exp = income / r; * residuals option; output out=foodout r=ehat; * name out dataset & resid; title 'regression with residual option'; run; /* detailed summary statistics with histogram */ proc univariate data=foodout; * proc univariate on foodout; var ehat; * select variable; histogram/normal; * histogram & normal curve; run; /* add a few observations on income when x=20 */ data morefood; input food_exp income; datalines; . 20 ; run; /* combine food data set with new observations and print */ data morefood; * open morefood; set food morefood; * combine food & morefood; run; proc print data=morefood; title 'Augmented food data';

50 run; /* regression on combine data with predict option */ proc reg data=morefood; model food_exp=income / p cli; * p option for predictions; title 'regression with predict option'; output out=foodpred p=yhat stdi=sef lcl=lcl ucl=ucl; * output p=predicted value stdi = standard error of forecast lcl = 95% prediction interval lower bound ucl = 95% prediction interval upper bound *; title 'food regression with prediction'; run; data foodpred; * open data set; set foodpred; * read data; tc = tinv(.975,38); * 97.5 percentile t(38); lb = yhat-tc*sef; * prediction lower bound; ub = yhat+tc*sef; * prediction upper bound; run; /* print observations 40 and 41 */ proc print data=foodpred(firstobs=40 obs=41); var income sef tc lcl lb yhat ub ucl; title 'predicted values'; run; proc print data=foodpred(firstobs=41 obs=43);

#### You've reached the end of your free preview.

Want to read all 62 pages?

- Fall '16
- Jane Lee
- Least Squares, Linear Regression, Regression Analysis, Yi