Perfect Essay Writing

Linear regression assignment

Order ready-to-submit essays. No Plagiarism Guarantee!

Note:  All our papers are written from scratch by human writers to ensure authenticity and originality.

Linear regression assignment

Check your essay before you submit. See exactly what your professor sees.

See your AI and plagiarism results before your instructor does.Get the exact same report your professor uses. Trusted by 50,000+ students worldwide.

The following assignment will give you a taste of using linear regression. The dataset supplied is called the Boston Housing Dataset. The data are from the 1970s so they are a bit dated.

The dataset is posted to blackboard in this same folder.

Each row in the dataset represents one (unnamed) suburb of Boston. The following 13 variables are provided:

1. MEDV: median value of owner-occupied homes in $1000 (so 24 means $24,000). This is the variable Y we are trying to predict by one of the X variables below. Note that because MEDV is in thousands of dollars, when you interpret Beta_1, the change in Y should be in thousands. For instance, if Beta_1=2.5, this means a change of one unit in X increases Y by 2.5, which in this case means $2,500 (2.5*1000).

2. CRIM: per-capita (per person) CRIMe rate by town. For instance, 0.006 means there were 0.006 crimes per person living in the town, or 6 crimes per 1,000 people (multiply each by 1,000)

3. ZN: proportion (between 0 and 100%) of residential land ZoNed for lots over 25,000 square feet. If more lots—land allowed for a house—are big (over 25,000 square feet) this means houses have more land so are more expensive.

4. INDUS: proportion (between 0 and 100%) of non-retail business acres per town. If 12%, this means 12% of acres in the town are zoned for businesses that are not retail (i.e., brick-and-mortar stores), for instance factories or office buildings. A higher value means the area is more INDUStrial rather than residential/commercial.

5. NOX: measure of air pollution: Nitric OXides concentration (parts per 10 million) in the air

6. RM: Average number of RooMs per residential dwelling in the town

7. AGE: proportion of (between 0 and 100%) of owner-occupied units (as opposed to rentals) that were built prior to 1940. If AGE is higher, this means more of the houses were built prior to 1940, which means they overall tend to be older. Older houses are generally less expensive, though not necessarily.

8. DIS: weighted DIStances to five Boston employment centers (higher values mean the home is generally further from major employment centers in the area). This means, for instance, that a given suburb is located 1, 5, 10, 10, and 20 miles from the 5 major employment centers. DIS is some kind of average of these distances, for instance, the mean =(1/5)*(1+5+10+10+20)=9.2 miles, in which case each weighted equally, or perhaps, the employment centers have higher weights by size. For instance, (1/3)*(1+5)+(1/6)*(10+10)+(1/2)*20, if the 5th (20 miles) is the biggest.

9. RAD: Index of accessibility of RADial highways, meaning highways that lead to urban centers (as opposed to, say, interstate highways that don’t primarily serve major cities). Higher numbers mean more accessible, generally a good thing, but you also don’t want highways right next to your house, either.

10. TAX: full-value property-TAX rate per $10,000 (higher property taxes may mean, for instance, that the schools in an area are better because public schools are often funded by property taxes). For instance, if TAX is $296, the owner pays $296 in property taxes for each $10,000 their house is worth. So a $100,000 house would cost the person $2,960 in property tax.

11. PRATIO: teacher to Pupil (student) RATIO, meaning the number of students per teacher by town (higher means more students per teacher, generally a bad thing in classrooms because students get less attention).

12. B: =1000*(Bk – 0.63)^2, where ‘Bk’ represents the proportion (between 0 and 1) of Blacks living in each town. The further Bk is from 0.63, either up or down, the higher this is (since it is squared). If Bk is low (a mostly non-black neighborhood, probably mostly white), then increasing Bk, the black proportion, probably decreases housing values if people are racist and view black neighbors negatively. However, If Bk is near 1 (mostly black neighborhood) then the relationship is different. The idea is to make a variable B from Bk that has a closer to linear relationship to MEDV.

13. LSTAT: percentage (0 to 100%) of the population that is Lower socio-economic STATus (i.e., “poorer”)

Goal: you need to perform a single variable linear regression to predict MEDV, using ONLY ONE of the remaining 12 variables. It is possible that with only one variable you will not get a good answer in terms of a model that fits MEDV well, but that is okay.

Remember we are looking for MEDV to have a (roughly) linear relationship with another variable. You should start off by plotting scatterplots of each other variable paired with MEDV. There is not necessarily a “right” answer here so I expect people to work individually and to have a variety of variables chosen. You do not have to find “the best” linear model, just pick one and talk about it.

Note: in the following examples, I will be showing you regression using a different dataset than the one you will actually be using. This dataset involves predicting car MPG ratings based on car attributes like model year, weight, horsepower, etc.

Scatterplot

To do a scatterplot, highlight the two columns of data you want to use. The left column will be on the X axis. Seeing a clearer positive or negative relationship between two variables means that they may be good candidates for performing a linear regression of one on the other.

To select a column, you may click on the tab above the worksheet with the letter names of the columns (A, B, C), etc. To select the second column, hold down the CTRL button and then click on that column.

Insert -> Scatterplot

You want to have MEDV on the Y axis. The easiest way to make sure this happens is to just cut and paste the MEDV column so it is to the right of all the other columns, so that it will automatically be the Y axis. I have already modified the spreadsheet for this.

Alternatively, right click on the points in your scatterplot and click “Select data”, then click “Edit” and manually change the inputs for the X and Y (be careful not to use the arrow keys because this will mess it up). The first solution is easier.

You should manually edit the title and axis labels so that it is clear what is being displayed.

You can add labels to the X and Y axis by left-clicking in the chart area. Axis and chart labels can be manually edited by clicking on them.

· Windows: A green “+” will appear in the right corner. Click on it to add chart elements, check “axis titles” and “chart title” (should be there already). 

· Mac: Click on “Add chart element” at the left of the “Chart design” ribbon, once the chart is selected. Click on “Axis titles” and (repeating twice) click on primary horizontal/vertical axis. You can do the same for the regression output graphs.

Here I have done a scatterplot between MPG (Y) and WEIGHT (X) of the car. You can see a fairly clear relationship, where lower WEIGHT is associated with LOWER MPG, although we will see later there may be a slight heteroskedasticity (error/residual variance not equal).

Notice I have edited the graph so that the axis and chart labels are descriptive.

Regression

You will need to use the “Data Analysis” tool, which should appear on the far right under the Data menu.

If your excel does not have it loaded, you will have to add it in first:

· For Windows: File-> Options-> Add-ins -> “Analysis toolpak”. You may have to click on “Go…” next to “Manage” menu in the Add-in window to load it.

In this menu, check “Analysis Toolpak” then click OK to load it

· For Mac: Tools -> Add-ins -> “Data analysis toolpak”. If you have a Mac with Excel 2016 or above, you will be fine with this. If you have Excel 2011 or earlier you will not be able to load the Toolpak onto your computer, and will likely need to use a school computer to do so. You can do the initial regression on a school computer, then save the Excel workbook with the results and do the rest of the work on your own computer. On a Mac, you may have to click “save” or reload to use the toolpak for the first time.

To perform regression, click on Data-> Data Analysis -> select Regression

Input Y range: select the MEDV column (excluding the variable name in the top row), click ENTER

Input X range: select the variable you want (excluding the variable name in the top row), click ENTER

If you include the variable name you will get a warning that your data includes non-numeric (text) values

Confidence level: check the box and type 95 in the box (this tells you it will do 95% confidence intervals for parameters)

Under output options, select “New worksheet ply”. This will output to another sheet in the same workbook

Under “Residuals”, check the boxes “Residuals”, “Residual Plots”, and “Line fit plots”.

The icon may flash for a few seconds as it calculates. Then go to the new worksheet.

You will see a bunch of numbers and plots.

Regression statistics:

1. R square and Adjusted R square: give you a measure of how well the X variable explains the variation in the Y variable (MPG or MEDV). This number will be between 0 and 1, with higher meaning better. In our case the R square is relatively high, so weight and MPG can be well-explained by a linear relationship. Use the “R square”, not “Adjusted R square”. The correlation (R, not shown) is the square root of R^2.

2. Standard error: The standard deviation of the error term in the regression (the bigger this is, the more error in predicting Y from your model).

The interpretation of standard error (s) is that 95% of the time, you expect your prediction to be within 2*s of the actual value of Y.

Regression Statistics
Multiple R 0.831740933
R Square 0.69179298
Adjusted R Square 0.691014679
Standard Error 4.344628058
Observations 398

Skip the ANOVA box

You will now see a box with the regression model (you may have to widen or shorten the column widths in Word to get – signs on the same line):

  Coefficients Standard Error t Stat P-value Lower 95% Upper 95%
Intercept 46.31736442 0.79524523 58.24286987 2.7534E-196 44.75393408 47.88079476
X Variable 1 -0.00767661 0.000257487 -29.81359895 2.9728E-103 -0.008182822 -0.007170398

You can use the following tool (under Home -> Number -> Decrease decimal) to round so the numbers are more readable. Alternatively, format the numbers to have fewer decimal places by highlighting the numbers, right click -> Format Cells 0-> Number.

Note, the last two columns are duplicates of the ones next to them.

  Coefficients Standard Error t Stat P-value Lower 95% Upper 95%
Intercept 46.3174 0.7952 58.2429 0.0000 44.7539 47.8808
X Variable 1 -0.0077 0.0003 -29.8136 0.0000 -0.0082 -0.0072

Note: the table above has two rows, the first for the intercept (Beta_0), the second for the slope (Beta_1). In #5-6, there is also a hypothesis test being conducted on if Beta_0=0, while we are only concerned with the same test about the value of Beta_1. You can ignore the test and confidence interval done in the first row.

1. The first column tells you if the statistics are for the intercept (Beta_0) or X variable (Beta_1) term.

2. Coefficients: the value of the estimate of Beta_0 or Beta_1. For instance, this means that an increase in weight of 1 pound will decrease MPG by 0.0077 (Beta_1).

Beta_0, your intercept, is what your model says Y (MPG) would be if X (WEIGHT) is 0. It is not meaningful if 0 is out of range for your X variable. For instance, it is impossible to have a car that weighs 0 pounds (WEIGHT=0), so in our case it is not meaningful due to logic. However, in some cases it may be logically meaningful but you may not have 0 in the range just because your data doesn’t include any of these examples. For instance for the Boston variable LSTAT (socio-economic status), 0 would mean there are no people of low socio-economic status in that suburb. In theory Beta_0 there would be what the model predicts for housing value if there are no such people. But because LSTAT is always positive (between about 5 and 45 in the data), Beta_0 would not have a meaningful interpretation there.

3. Standard error: the standard deviation of the estimate

4. T Stat: the T-statistic calculated for the coefficient, for testing if it =0.

5. P-value: the p-value. This is the p-value for the hypothesis test that the coefficient=0. Note, if you see something like 2.7534E-196, this means 0. Reformat the cell as a number to show more decimal places (right click -> Format Cells ->Number -> “Number” under category). For Beta_1, the p-value being low (below 0.05) means that we statistically say there IS a relationship between the variables because we are saying the slope IS NOT ZERO.

6. Lower 95% and Upper 95% are the values of the 95% confidence interval for the term. The interpretation here is related to the p-value. For instance, the p-value for Beta_1 is zero, so we say there is a relationship (slope is NOT 0). Therefore the confidence interval for Beta_1 does not include 0, since it indicates the relationship between WEIGHT and MPG is firmly positive.

The tables below show the residuals for the model and the predicted value of MPG (predicted Y) for each observation.

Plots: You should change the default plot titles so they are actually descriptive.

· X variable 1 residual plot: shows the residuals (errors) plotted on the y-axis. Remember these should basically be distributed equally above and below the x-axis (0) along the range of the data (homoscedasticity).

In this case what you see is that there tends to be more error in the prediction when WEIGHT is lower than higher. This is some evidence of heteroscedasticity (the error is not evenly distributed at all values of WEIGHT), but not a whole lot.

The fact that the error is not evenly distributed means a linear model may not be very appropriate (see the line fit model). This also affects our interpretation of the standard error of the error term (4.344 above). The interpretation is that about 95% of the time, our prediction for MPG is within about 2*4.344 (=8.688) of the actual MPG (remember this is like the empirical rule for a normal distribution). However, if there is heteroscedasticity, this may be off, but not necessarily. Even if it is still accurate, it means that the value of the error depends on what WEIGHT is.

For a similar but more extreme example, see a regression where X is HORSEPOWER instead: The scatterplot and line fit plot suggest that the relationship between horsepower and MPG is not a line, but rather a curve (more horsepower decreases MPG, but at higher horsepower the amount of decrease is less).

The residuals (errors) confirm this. You see at low and high values of horsepower, the errors tend to be positive not negative. This means a linear model may not be the best in our situation.

· X variable 1 line plot: shows a scatterplot of the variables with the best regression line plotted.

Note that in this plot, the regression line is plotted as the predicted points, rather than as a solid line. If you want to change this, follow these steps:

· Left click on the orange points so they are highlighted, then right-click on the orange points, and select “Add trendline”. The “linear” option should be selected by default.

· This will overlay the line onto the points, as shown below: 

· To get rid of the orange points, left click on them again, so they are selected, then right click, and click on “Format data series” 

· In the “Format data series” on the right, click on the left icon (that looks like a graduation hat), then on “Marker”, then “Marker Options”. Click on “None.”

· You can remove the entry in the legend for “Predicted Y”, since the orange dots don’t appear, by right clicking on it and then “Delete” (NOT “Delete series”).

· Your graph should now look like this:

Assignment: The following should take you 2-3 pages to do, and no more than 3 pages.

When you write up your assignment, please write it in essay form like it is a report or paper. Do not answer the questions below in a numbered way as if they were individual problems.

Conduct scatterplot analysis to try to determine which variables may be good to try in regression. Pick one only, and explain your observations about this variable ONLY. Make sure to address/complete all the following items in your analysis.

1. Choose one variable to perform regression with. Include the initial scatterplot without the regression line in your document. Explain your observations from the scatterplot.

2. Explain logically (before doing any regression) why you think that variable would have a relationship with MEDV, and what it should be. Address the following aspects:

a. Why should the relationship be positive or negative?

b. Should it be weak or strong?

c. Do you think that there is some causal relationship (e.g. X directly causes Y) or it is just an association? If an association, is there another variable that might explain the relationship? If you think there is another variable (it doesn’t have to be one of the other 11 variables in the dataset) that may be behind the relationship, you don’t have to do additional analysis (like more scatterplots), just explain your reasoning. For instance, “I think that there is a relationship between MEDV and property tax that is negative, where higher property taxes reduce median house value on average. Since TAX is per $10,000 of value, not total amount paid, it is possible that higher property values pay higher total tax but lower per-dollar tax. Maybe property tax goes mostly to public schools, and maybe people in richer areas (with higher MEDV) send their kids to private schools, so the per-house-dollar-value property tax assessment is lower.”

3. Perform regression as indicated above. Include the linear regression plot (the scatterplot plus the line)

4. In your document, copy ONLY the tables for regression statistics and the coefficient estimates.

5. In the text body, mention what the R-squared value (coefficient of determination) is and say what that means about the quality of your regression. If it is big or small, what does this mean?

6. In the text body, report the coefficient estimates for Beta_0 and Beta_1 are. Explain what the value of Beta_0 and Beta_1 mean in this and say if this means the relationship is positive or negative. Also explain if Beta_0 is meaningful in this situation (it is meaningful if the variable X value 0 has a real meaning or is within the range of X values in your dataset). For instance, in the example I gave you would say

a. Beta_0=4.317 is not meaningful because WEIGHT can never be 0

b. Beta_1=-0.0077 means an increase in WEIGHT of 1 pound will decrease MPG by 0.0077.

7. State what the p-value for Beta_1 in your regression is and what it means. Does it mean there definitely is or isn’t a relationship between the two variables? If Beta_1=0, the regression is a horizontal line so there is no relationship.

8. In the text body, report the 95% confidence interval for the value of Beta_1. Does this support your answer to #7 about the hypothesis test on Beta_1? Explain.

9. Include the residual (error) plot. Do the residuals show it is a well-fit model (remember we need homoscedasticity)? If there is an even distribution of the residuals above and below the horizontal 0 line, that is good. Do they show that a linear model is appropriate in this case? What about the line plot? Describe what you see.

MPG of car and weight

SOURCE: WWW.ROYALRESEARCHERS.COM
Havent found the Essay You Want?
We Can Help
The Essay is Written From Scratch for You

🛒Place Your Order

ORDER AN ESSAY WRITTEN FROM SCRATCH at : https://royalresearchers.com/

PLACE YOUR ORDER

Share your love