Internal Code : MAS990
R-Studio Assignment
Question :
1.For all models in this problem set, report the constants, coefficients, standard errors, and p-values, the N and the R2 values in one table in your writeup. Label them, Model 1, Model 2, etc, as per the example table provided be-
low. When you are finished, you should have 5 models in you table. Use the format of Table 1 as a guide for creating this table in your word document. In the left hand column, you variable names should be included. Name the variables, DO NOT USE THE R CODE NAMES. In the columns to the right of the variable names, insert the different models you will make for this problem set. Each cell should contain the values of the coefficients and their standard errors in they are included in that model. Since the first model is bi- variate, the only cells that will have numbers will be the primary independent variable (the coefficient with SE’s in parentheses underneath), the constant
(the coefficient with SE’s in parentheses underneath), and the N and R2. Fill the subsequent columns as the problem set instructs.
2. Load the data; it should show you two dataframes. Use c for now. View the data frame and the variables. Make sure you know what each variable is and what it is measuring.
3. Report the descriptive statistics for all the above variables. This includes the type and level of measurement; for categorical variables, provide a prop-erly labeled frequency graph using the freq() command, and include the frequency, and percentage of each category in your write-up; for continu- ous, provide a histogram using hist() command and report the n, median,mean and standard deviation in your write-up. For the set of categorical vari-
ables that indicate regional differences, you will not need to make a graph, but you should consider them here as one category and report their number and frequency. Label each response as 3a-h.
4. Your primary interest is the relationship that attractiveness has on the percent- age of margin of victory. Create a scatter-plot using the plot() command for these two variables. The syntax for that command is plot(x,y). Use the label options you used for your histograms and frequency graphs to la- bel the Main Graph label (main=""), the x-axis label (xlab=""), and use ylab="" to label the y-axis. Put your scatterplot in your word document and spend a few sentences discussing whether you can distinguish the direc- tion of the relationship between the variables. Be sure to answer the follow- ing questions: Is a relationship apparent? What factors might explain why the scatterplot looks the way it does? Are there any concerns with outliers or leveraging observations?
5. Create a binary regression model using attractiveness and the percent margin of victory and the lm() command. Report the ? coefficient for attractiveness and report the standard error and p-value for the coefficient in a table, and
label the results Model 1. In your word document, report the statistical and substantive significance. Explain the relationship as you might to a person who is not familiar with statistics, but in such a way that a statistician would
recognize what you’ve done and would appreciate your work.
6. Write the R code necessary to find the R2 for the binary model you just made using the following equation. Report the value, and interpret what this particular R2 value means as you would to someone not familiar withstatistics.
R2 =?(Yi?Y ? )2??(Yi?Yˆi)2?(Yi?Y ? )2
7. We may be missing important confounding variables. Perceived candidate attractiveness can be correlated with a variety of other variables that could affect the percent margin of victory. Therefore, we need to include the neces-
sary variables. Run a model that includes all of the included control variables, and report the values in your table. In the table, label this model Model 2. Also in your writeup, interpret the results of every variable in the model, both
statistically (with p-values), and substantively (with size and directions of coefficients). Explain every relationship as you might to a person who is not familiar with statistics, but in such a way that a statistician would recognize 5 what you’ve done and would appreciate your work. You should use at least 2-3 sentences to properly explain the results of each variable.
8. If you followed instructions on the last part, R refused to include one of your variables. In a few sentences, identify which one and explain why it got dropped.
9. There are two particular control variables that may not have a linear relation- ship with the margin of victory. Identify the most likely candidate and create a new variable that is that variable but squared. Run a new regression model including this variable, and include it as Model 3 in your table. Explain the relationship that this variable has with the dependent variable.
10. From number 3 above, you may have identified former Rep. Henry Waxman as an outlier in our sample. Unfortunately, for reasons completely beyond his
control, Mr. Waxman may have affected our data. Mr. Waxman is observa-
tion 87. Report his attractiveness (for your own research, Google his image) and his percent margin of victory scores. In a few sentences, explain what impact might he have on our results.
11. We may need to remove Mr. Waxman from our sample. We will use a variant of the call function. For example, to remove the fifth observation from a data frame named x, you would write out: x<-x[-5,]. In a few sentences, provide a meaningful justification for removing Mr. Waxman.