14  Exam 1 R-Review Sheet

14.0.0.1 Functions and Arguments

Here are some important functions and arguments to know:

plot() - This is the function to graphically visualize your data. Within this function can be several arguments.

  • x,y:The independent and dependent variable you are interested in

  • main =,xlab =, ylab =, sub =: Title, x-axis lable, y-axis label, and caption.

  • xlim =,ylim =: These set parameters for the graph that will be drawn.

  • col = : Designates a desired color for the lines, and points that will be drawn.

  • pch =: Point character, assigns shape for points drawn.

  • points(): Plot additional points on an existing graph with pre-defined graphical parameters

-cor() - This function will return the correlation, or r, of an entire dataframe, or of specified variables.

-hist() - This function will create a histogram of a given variable, displaying its frequencies.

  • breaks = - This argument allows you to specify a bin width of your choice.

  • lm() - This function allows you to create a linear model from which you can predict a variable, from another.

    • the ~ is used to delineate between the predicting variable and the predictor variable.

      • For example: lm(x~y) is different than lm(y~x).
    • When using lm(), it is common to name the model something that makes sense + .mod..

-summary() - This can be used on entire datasets to return the minimum, maximum, and median values.

  • This can also be used to expand a linear model to give you values such as the coefficient of correlation, slope and intercept.

14.0.0.2 Syntax

When using R-Studio, it is important that the math you do in the console follows the same rules as the math you would do on a calculator or a piece of paper.

For example:

I have a dataset with a mean of 10, and a standard deviation of 7. What is the probability of having a score of 18?

We know the formula for this is the Z-Score formula: \[z = \frac{x - M}{\sigma}\] Depending on how you enter this data into R, you will get two different answers:


() are very important to R, and your answers will either be incorrect or will not be ouput corectly if the () are misplaced/misused. Depending on how difficult you want to make your calculations, keeping track of your () placement is very important.

The below equation will not render the correct answer:


Not too bad, we were only off by one hundred and fourteen thousand six hundred nintey-four.

14.0.0.2.1 Math Operators

() matter, quite a lot. Additionally, here are the math operators you can use:

+

-

*

/

^

sqrt()