Using R for Numerical Analysis in Science and Engineering
Victor A. Bloomfield
- 359 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Using R for Numerical Analysis in Science and Engineering
Victor A. Bloomfield
About This Book
Instead of presenting the standard theoretical treatments that underlie the various numerical methods used by scientists and engineers, Using R for Numerical Analysis in Science and Engineering shows how to use R and its add-on packages to obtain numerical solutions to the complex mathematical problems commonly faced by scientists and engineers. This practical guide to the capabilities of R demonstrates Monte Carlo, stochastic, deterministic, and other numerical methods through an abundance of worked examples and code, covering the solution of systems of linear algebraic equations and nonlinear equations as well as ordinary differential equations and partial differential equations. It not only shows how to use R's powerful graphic tools to construct the types of plots most useful in scientific and engineering work, but also:
-
- Explains how to statistically analyze and fit data to linear and nonlinear models
- Explores numerical differentiation, integration, and optimization
- Describes how to find eigenvalues and eigenfunctions
- Discusses interpolation and curve fitting
- Considers the analysis of time series
Using R for Numerical Analysis in Science and Engineering provides a solid introduction to the most useful numerical methods for scientific and engineering data analysis using R.
Frequently asked questions
Information
Chapter 1
Introduction
1.1 Obtaining and installing R
http://cran.r-project.org/
. Choose the appropriate link for your operating system (Mac OS X, Windows, or Linux), and follow the (not very complicated) directions. Unless you have some special requirements for customization, you should choose the precompiled binary rather than the source code.http://www.rstudio.org/
/ide.1.2 Learning R
http://cran.r-project.org/ → Documentation
. The section Learning more about R at the end of this chapter lists numerous books and online resources.1.3 Learning numerical methods
1.4 Finding help
help (function.name)
or ?function.name
. For example, ?solve
tells us that “This generic function solves the equation a%*% x = b
for x, where b can be either a vector or a matrix.” As one example, it gives inversion of a Hilbert matrix:hilbert <- function(n) {i <- 1:n; 1 / outer(i - 1, i, "+")} h8 <- hilbert(8); h8 sh8 <- solve(h8) round(sh8 %*% h8, 3)
http://cran.r-project.org/doc/contrib/Short-refcard.pdf
.apropos()
. For example, if you’re interested in spectral analysis, apropos(spec)
gives[1] "plot.spec" "plot.spec.coherency" "plot.spec.phase" "spec.ar" [5] "spec.pgram’’ "spec.taper" "spectrum"
Special
, which yields special mathematical functions related to the beta and gamma functions. apropos()
allows searches using regular expressions; enter ?apropos
to see some examples.help.search()
“allows for searching the help system for documentation matching a given character string in the (file) name, alias, title, concept or keyword entries (or any combination thereof), using either fuzzy matching or regular expression matching.” Note that the character string must be in quotes. For example, help.search("spectral")
turns up five topics, with descriptions:- eigen: Spectral Decomposition of a Matrix
- plot.spec: Plotting Spectral Densities
- spec.ar: Estimate Spectral Density of a Time Series from AR Fit
- spec.pgram: Estimate Spectral Density of a Time Series by a Smoothed Periodogram
- spectrum: Spectral Density Estimation
help.search(^spec)
brings up those help pages containing information about topics whose title, alias, or concept contain words that begin with “spec”: Special, specific, spectral, specification, etc.help.start()
opens your web browser to R’s online documentation. The manual “An Introduction to R” is the standard online reference to the language. Click on “Search Engine & Keywords” to search for keywords, function and data names, and concepts, and also for words or phrases within help-page titles. A list of keywords arranged by topics (Basics; Graphics; MASS (the book); Mathematics; Programming, Input/Output, and Miscellaneous; and Statistics) is provided to help target the search.http://r.789695.n4.nabble.com/.
Searching this database can provide leads to existing resources, or show how others have solved puzzling problems.http://www.dangoldstein.com/search_r.html
and http://www.rseek.org/
.http://www.r-project.org/
> Mailing Lists
. The third item down is R-help. (The first two are R-announce, “for major announcements about the development of R and the availability of new code” and R-packages, “for announcements ... on the availability of new or enhanced contributed packages.”) The posting guide gives important advice about “how to ask good questions that prompt useful answers.” Follow that advice to avoid grumpy responses from the experts.http://www.r-bloggers.com/
), which collects “daily news and tutorials about R, contributed by over 450 bloggers.”1.5 Augmenting R with packages
base
, graphics
, stats
, utils
, splines
, datasets
, and several others. Some other packages are “recommended,” and are included in all binary distributions of R. Most pertinent for our purposes among these are Matrix
(which we will discuss in Chapters 2 and 5), cluster
(functions for cluster analysis), and nlme
(for nonlinear mixed-effects models). These must be loaded with the library("package-name")
or require("package-name")
function. (library
and require
can generally be used interchangeably, although require
is intended for use within other functions and the two will give different messages if the package is not available. See ?library
for details of their usage.)install.packages("package-name")
. (Mac OS X and Windows users can also install packages via the R menu system.) The packages can then be loaded with require(package-name)
or library(package-name)
. Packages are in many ways analogous to the add-ons for other mathematical languages, but are generally free and open source. We will describe and use a number of such packages in this book, including packages for ordinary and partial differential equations, orthogonal polynomials, root-finding, optimization, and more.library().
The datasets in some packages can be of use as examples in learning about statistical analysis of data, as we will do in Chapter 10. To get summary help about a package you have installed in R, type library(help = "package.name")
or help(package = "package.name")
. Navigating to individual packages in the CRAN archive will give access to their reference manuals and (sometimes) vignettes, as downloadable pdf files.ChemPhys
task view refers to packages useful in chemometrics and chemical physics that carry out such tasks as linear and nonlinear regression models, curve resolution, differential equations, optimization, cellular automata, etc. The NumericalMathematics
, DifferentialEquations
, Optimization
, and TimeSeries
task views are particularly pertinent to the material in this book.findFn
function in the sos
package. Its documentation states “The sos
package provides a means to quickly and flexibly search the help pages of contributed packages, finding functions and datasets in seconds or minutes that could not be found in hours or days by any other means we know.”http://www.inside-r.org/
enables you to search for the packages that contain the keyword(s) of interest, and then to browse the help files of those packages. A similar function is served by the community site crantastic! (http://crantastic.org/
), which also provides information about new and upgraded packages, and allows reviews by users.RSiteSearch("keyword")
at the R prompt opens a web-based interface to search functions, contributed packages, and R-help postings. For example, typing RSiteSearch("orthogonal polynomials")
yielded 194 documents matching the query within function, package vignette, and task view targets.installed = installed.packages() available = available.packages() ia = merge(installed, available, by="Package") [,c ("Package", "Version.x", "Version.y")] updates = ia[as.character(ia$Version.x) != as.character(ia$Version.y),] updates
update.packages
.