R For College Mathematics and Statistics
eBook - ePub

R For College Mathematics and Statistics

Thomas Pfaff

  1. 326 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

R For College Mathematics and Statistics

Thomas Pfaff

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

R for College Mathematics and Statistics encourages the use of R in mathematics and statistics courses. Instructors are no longer limited to ``nice'' functions in calculus classes. They can require reports and homework with graphs. They can do simulations and experiments. R can be useful for student projects, for creating graphics for teaching, as well as for scholarly work. This book presents ways R, which is freely available, can enhance the teaching of mathematics and statistics.

R has the potential to help students learn mathematics due to the need for precision, understanding of symbols and functions, and the logical nature of code. Moreover, the text provides students the opportunity for experimenting with concepts in any mathematics course.

Features:



  • Does not require previous experience with R


  • Promotes the use of R in typical mathematics and statistics course work


  • Organized by mathematics topics


  • Utilizes an example-based approach


  • Chapters are largely independent of each other

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
R For College Mathematics and Statistics è disponibile online in formato PDF/ePub?
Sì, puoi accedere a R For College Mathematics and Statistics di Thomas Pfaff in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Économie e Statistiques pour les entreprises et l'économie. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

1
Getting Started
If you do not have R on your desktop then download it now from https://www.r-project.org/. When you click on download R, you will first be asked to choose a CRAN mirror, a location to download the software from, and then will be to a page to choose between Windows, Mac, or Linux. Following the Download R for Windows link will take you to the page for Windows that has a download R for the first time link. After that link you will be directed to a page with a download link at the top. Following the Download R for (Mac) OS X link takes you to a download R for Mac OS X page. Click on the first link on the left under the Latest release header. Linux users can follow the Download R for Linux link. In all cases you can search for videos if you are having difficulties loading R.
When you open R you will see the R Console box with > prompt. Take a few moments and play with R as a calculator with * as multiplication and for exponents. For example we calculate 2^6*3*643.
R Code
> 2^6*3*643
[1] 123456
Throughout this text these boxes will represent the R code and its output. Now that you are comfortable using the R console we want to stop using it as our primary input method as scripts are preferred. Open up a new script (document for Macs) by going to File -> New script. A new window opens with the name Untitled – R Editor. Save this file to a location of your choosing and name it FirstScript and note that it is a .R filetype. The R Editor allows you to type your commands and edit them before you run them in the R console. The file can also be saved for future reference and reuse.
Working in the R Editor
• Text following # will be ignored by R. This is how you add comments to your commands so that you can easily read them later.
• Ctrl + R (Command Return with a Mac) will send the current line in the editor to the console. Similarly, any highlighted commands in the editor will be sent to the console when you press Ctrl + R.
• A + sign in the R console means that R is expecting something more. For example you might be missing a parenthesis or bracket. To get out and back to the > prompt use the Esc key.
• Recognize that your toolbar and submenu options depend on which window, console or editor, is selected.
Here are two quick examples to get started, but first a few conventions of this book. R code is taken from the console and so lines of code are preceded by >. If a line does not have a > then the line above was broken and started a new line to fit the page. It is meant to be part of the single line started above and preceded by >. A line that starts with a + is, in fact, a separate line of code, but is part of a larger collection of code. The code in this book uses color, but to see the color you will need to run the code as this book is in black and white.
The first example, graphs the function f (x) = x3 – 3x2 – 9x + 2 on the interval [−4, 6]. To do this, we first define the function. The syntax sets f equal to function(x), a function with variable x, with the expression defined enclosed in braces. Note that * is necessary to represent multiplication. Entering 9x will generate an error as it must be 9*x. The curve function here has five input elements separated by a comma. The first is the function to be graphed. The next two define the x-axis interval for the graph. The first three entries are not optional and must be in this order. The next two elements are optional and can be in any order. We set lwd=2 for the line width and col to red, in quotes, for the color of the graph. A grid is added with grid. The first two elements, NULL, set the grid lines to the tick marks given by the graph created with curve. There are other options here that can be used. The last entry sets the color of the grid lines, with a default of gray. To add another function to the graph, curve can be used again, but the option add=TRUE must be included. To learn more about curve and grid run ?curve or ?grid, which will open a webpage with details about the functions. In general, a question mark followed by a command will open an R documentation page with details about the command.
R Code
> f=function(x){x^3-3*x^2-9*x+2}
> curve(f,-4,6,lwd=2,col="red")
> grid(NULL,NULL,col="black")
Image
The next example begins by generating a random data set of size 150 from a random normal distribution with mean 0 and standard deviation 1. The data returned by rnorm is set to the variable example. At this point example is a vector of length 150. We use summary to return the five number summary plus the mean of the data set example. Note, that the data set is randomly generated so results will differ. Use set.seed(42) to get the same results. We can use sd(example) for the standard deviation and boxplot(data) to create a boxplot of the data.
R Code
> example=rnorm(150,0,1)
> summary(example)
Min. 1st Qu. Median Mean 3rd Qu. Max.
−2.99309 −0.61249 −0.04096 −0.02874 0.64116 2.70189
For an example of a t-test, we test the data example with an alternative of μ < 0. The function t.test() is used. The first entry is the data and is not optional. The other three inputs set the value of μ0 to 0, the alternative hypothesis to less than, and the confidence level to 0.90. The default μ0 is 0 so this isn’t necessary here. The default alternative is two-sided and the options for alternative are two.sided, less, and greater and must be in quotes. The default confidence level is 0.95. To learn more about these functions run?t.test or ?boxplot, for example.
R Code
> t.test(example,mu=0,alternative="less", conf.level=0.90)
One Sample t-test
data: example
t = -0.35007, df = 149, p-value = 0.3634
alternative hypothesis: true mean is less than 0
90 percent confidence interval:
-Inf 0.07694166
sample estimates:
mean of x
-0.02874049
At this point, you should feel free to explore the chapters. The next section is specifically for importing data into R that you may not need at the moment. Depending on your interests, two good chapters to turn to next are Chapter 2, Functions and Their Graphs or one of the basic statistics chapters, Chapters 11, 12, or 13. One last tip: Some chapters use a package. A package can be thought of as an add-on to R that does something more than the base distribution. There are over 10,000 packages for R. To use a package, it must first be downloaded, which only has to be done once. To download a package, make sure the console window is highlighted and use the package menu along the top. You will first need to select as CRAN location, as is done when loading R, and then select the package. Search load package in R if there are any difficulties. When you want to use a particular package run library(name), which you will see in this book anytime a package is used.
1.1 Importing Data into R
One of the strengths of R is statistical computing, but entering large data sets directly into R is not a common practice. Typically, for colleges mathematics and statistics courses, your data will come from a spreadsheet and you will want to import that data into R. The example below assumes that a csv file has been created, likely from Excel, from the Arctic Sea Ice data from Appendix B.
Importing a csv File
• Make sure your csv file is free of commas and apostrophes within cells, has only one tab, and you have deleted unnecessary cells. Also, your first cell cannot be named ID.
• With the Console window selected go to File -> Change dir… and select the folder that contains the csv file. In a Mac, Change Dir is under Misc.
• Enter the command DataName=read.table(“File Name.csv”, header=TRUE, sep=“,”). Here DataName gives the data a name within the R environment. Choose a meaningful name. Note header=TRUE tells R that you have column nam...

Indice dei contenuti

Stili delle citazioni per R For College Mathematics and Statistics

APA 6 Citation

Pfaff, T. (2019). R For College Mathematics and Statistics (1st ed.). CRC Press. Retrieved from https://www.perlego.com/book/1513929/r-for-college-mathematics-and-statistics-pdf (Original work published 2019)

Chicago Citation

Pfaff, Thomas. (2019) 2019. R For College Mathematics and Statistics. 1st ed. CRC Press. https://www.perlego.com/book/1513929/r-for-college-mathematics-and-statistics-pdf.

Harvard Citation

Pfaff, T. (2019) R For College Mathematics and Statistics. 1st edn. CRC Press. Available at: https://www.perlego.com/book/1513929/r-for-college-mathematics-and-statistics-pdf (Accessed: 14 October 2022).

MLA 7 Citation

Pfaff, Thomas. R For College Mathematics and Statistics. 1st ed. CRC Press, 2019. Web. 14 Oct. 2022.