Regression Modeling in Practice, Week 2: Basics of linear regression
SAS syntax to test a basic linear regression model
LIBNAME mydata "/courses/d1406ae5ba27fe300 " access=readonly; data new; set mydata.gapminder; label internetuserate="Internet use rate" urbanrate="Urban population";
/* DATA MANAGEMENT */ if polityscore GE 6; /* subsetting dataset to only include democracy regime category countries */ if urbanrate ne . and internetuserate ne .; /* setting aside missing data */ urbanrate_ctrd=urbanrate-59.6938636; /* quan exp var; centring the mean=0 or close to zero */ proc means; var urbanrate; /* means procedure */ proc means; var urbanrate_ctrd; /* means procedure to validate */
/* SCATTERPLOT LINEAR REGRESSION LINE */ proc sgplot; reg x=urbanrate y=internetuserate; xaxis label="Urban population (% of total)"; yaxis label="Internet use rate (per 100 people)";
/* LINEAR REGRESSION MODEL */ proc glm; model internetuserate=urbanrate_ctrd/solution;
run;
Output
Means procedure for explanatory variable “urbanrate” and “urbanrate_ctrd” where the mean=0 or close to zero
Scatterplot graph with linear regression line
GLM procedure
Interpretation
Using the Gapminder dataset, I am testing a basic linear regression model for the association between my primary quantitative explanatory variable (i.e., urbanization rate) and a response variable (i.e., internet use rate).
To start off, I have subset my data to include only the sample of countries which belong to democracy regime type based on the Polity IV dataset within Gapminder. In my data management steps, I have also accounted for missing data within the dataset.
Since I am using a quantitative explanatory variable, in this case the urbanization rate, for my linear regression model, I have centred the mean so that it equals to zero or close to zero. The mean was also calculated using the means procedure in SAS to check the centring step.
Using the PROC GLM procedure, I analyzed the data within the framework of general linear models and used it to test my basic linear regression model on the correlation between number of internet users and urbanization rate. To recap, the first goal was to determine the equation of the best fit line between the two variables:
y = ß0 + ß1x where, - y represents the response variable - ß0 represnts population y intercept - ß1 represents population slope coefficient - x represents the explanatory variable
In this case, the equation of the best fit line of this scatterplot of the linear regression line is:
internetuserate = 42.48 + 0.91 * urbanrate
The number of observations with complete data that was used in this model is 88. The F statistic is 74.59 and the Pr > F is <.0001, both of which are significant and show that there is a signficant relationship between internet use rate and urbanization. Additionally, the Pr > |t| gives us the p value for the explanatory variable’s association with the response variable, which is <.0001 and it is the same value we would get if a pearson correlation was also run.
The R-Square value is the proportion of the variance in the response variable that can be explained by an increase or decrease in the explanatory variable, and in this case this is 46.4%. In other words, this basic linear regression model counts for 46.4% of the variability we expect to see in the response variable internet use rate. So, the R-Square essentially tells us that by knowing the urbanization rate we would also be able to report the predicted value (as opposed to the observed value) of internet use rate; or, predict what the expected data could potentially look like.














