Advertisement
Guest User

Untitled

a guest
May 19th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. ---
  2. title: "Assignment 1"
  3. author: "Vincent Viola, Twan Kerkhof, Jaymon Veldkamp"
  4. date: "19 May 2019"
  5. output: html_document
  6. ---
  7.  
  8. ```{r setup, include=FALSE}
  9. library(Hmisc)
  10. library(AER)
  11. library(mfx)
  12. library(ggplot2)
  13. data("HMDA")
  14. df <- HMDA
  15. ```
  16.  
  17. ## Assignment 1.1(A)
  18.  
  19. ```{r}
  20. summary(df)
  21. ```
  22.  
  23. The summary function in R provides you with a concise overview of the data. What it returns depends on the type of values a certain variable entails. For binary variables, which is yes/no or 1/0. It returns the count for each value present for a certain variable. So for example, for the variable 'deny' you can see that there are 2095 'no' values in the dataset and 285 'yes' values. For nominal values, (for example the 'chist' variable, which ranges from 1 to 6) it also provides you with the count of all values present in the space of that variable. So for Chist you can see that there are 1353 values with the value 1, 441 for the value 2, 126 for the value 3 and so forth. For numeric variables it provides you with different statistics. When a variable is numeric it provides you with the Minimum value present in that variable, and also with the maximum value. It provides you with the mean, which is the average of all values of a certain variable. The median, which is the value that separates the lower half from the upper half. So it is the middle value in a row of numbers which are ordered. It also provides you with the value of the 1st Quantile, which seperates the first quarter of the dataset and the other 3 quarters. The 3rd quantile value is the value that seperates the lower 75% of the dataset and the upper 25%.
  24.  
  25.  
  26. ## Assignment 1.1(B)
  27. ```{r}
  28. rej_appl <- nrow(df[df$deny == "no", ])/nrow(df)
  29. print(rej_appl)
  30. ```
  31. The probability of not getting a mortgage loan by this calculation is 0.88. Ofcourse one can doubt if this is close to the real probability of not getting a loan, since there are a lot more variables which come into play when calculating such a probability. So to get a more accurate probability it would be wise to take more variables into account.
  32.  
  33.  
  34. ## Assignment 1.1(C)
  35. ```{r}
  36. ggplot(df, aes(x=deny, y=pirat, fill=deny)) +
  37. geom_boxplot() + ggtitle("Boxplot of variable pirat grouped by variable deny")
  38. ```
  39. It seems when Deny = yes the mean is a little bit higher than when the variable of deny has the value of no. But from this boxplot it is hard to see since there is an outlier in the dataset which scales the boxplot. But overall, the'yes' group seems to have a slightly higher pirat score than the 'no' group.
  40.  
  41. ## Assignment 1.1(D)
  42. ```{r}
  43. df1 <- df[(df$pirat < mean(df$pirat) + 12*var(df$pirat)^(1/2)) & (df$pirat > mean(df$pirat) - 12*var(df$pirat)^(1/2)),]
  44.  
  45. ggplot(df1, aes(x=deny, y=pirat, fill=deny)) +
  46. geom_boxplot() + ggtitle("Boxplot of variable pirat grouped by variable deny without outlier")
  47. ```
  48. Now that the outlier has been removed a much clearer boxplot has been created. You can still see, but clearer now that overall the values which have the value 'yes' for the 'deny' variable have a higher pirat score than when the value is 'no'. The cleaning process hasn't changed the boxplot itself because the boxplot is quite robust against outliers. Since the boxplot does not show the mean for example, but only the median and the quantiles.
  49.  
  50. ## Assignment 1.2(A)
  51.  
  52. The model should become:
  53. $deny = \beta_0 + \beta_1 \times pirat + u$
  54. The first component of the model, namely $deny$, is the probability of a mortgage being denied.
  55. The second component. $\beta_0$ is the intercept. This would be the value if $pirat$ would be 0.
  56. The third component, the $\beta_1$ is the coefficient, this beta determines the effect of $pirat$ on the probability of $deny$.
  57. The last component $u$, is the error term.
  58. ```{r}
  59. #First the deny column has to be converted to numeric values 1 and 0.
  60. #We also added a -1 because otherwise the values would be changed to 1 and 2 instead of 0 and 1.
  61. HMDA$deny2 <- as.numeric(HMDA$deny) - 1
  62.  
  63. ```
  64.  
  65. ```{r}
  66.  
  67.  
  68. lindeny <- lm(formula = deny ~ pirat, data=df)
  69. summary(lindeny)
  70.  
  71. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement