This lesson introduces R and shows how to organize paired financial data in vectors and calculate a correlation coefficient. These skills help you assess how closely the returns of two investments move together before fitting a regression model.
R is a free, open-source tool used for statistical analysis, graphing, and programming. Many statistical operations in R are performed with functions. For common analyses, the data are first stored in an appropriate structure, such as a vector.
All flashcards
What is R?
R is a free, open-source programming language and software environment for statistical analysis and graphing.
What does `c()` do in R?
It combines values into a vector, which can be stored under a name with `<-`.
What does `cor(x, y)` return?
The correlation coefficient summarizing the direction and strength of the linear association between paired values in two numeric vectors.
What does `lm(y ~ x)` fit?
A linear model with `y` as the dependent variable and `x` as the independent variable.
What does `predict(model, newdata)` do?
It estimates response values from a fitted model using predictor values supplied in `newdata`.
Quiz questions
In the simple linear model y^=a+bx, what does the slope b represent?Answer: The estimated change in y for a one-unit increase in x.
In the simple linear model y^=a+bx, what does the intercept a represent?Answer: The model's predicted value of y when x equals zero.
In a fitted linear model, what does multiple R-squared describe?Answer: The proportion of response variation accounted for by the fitted model in the sample.
In R, which `predict()` argument requests an interval for an individual response?Answer: `interval = "predict"`
For an observation used to fit a regression model, how is its residual calculated?Answer: Observed response minus the model-predicted response.
Based on Principles of Finance by Julie Dahlquist, Rainford Knight (OpenStax), licensed CC BY 4.0. Adapted into a summary, flashcards and quizzes.