Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Scientific Computing with R

You're reading from   Mastering Scientific Computing with R Employ professional quantitative methods to answer scientific questions with a powerful open source data analysis environment

Arrow left icon
Product type Paperback
Published in Jan 2015
Publisher
ISBN-13 9781783555253
Length 432 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (12) Chapters Close

Preface 1. Programming with R 2. Statistical Methods with R FREE CHAPTER 3. Linear Models 4. Nonlinear Methods 5. Linear Algebra 6. Principal Component Analysis and the Common Factor Model 7. Structural Equation Modeling and Confirmatory Factor Analysis 8. Simulations 9. Optimization 10. Advanced Data Management Index

Basic sample simulations in R


We already showed you the basics of generating random variables from common probability distributions in Chapter 2, Statistical Methods with R. For example, to simulate four numbers from a normal distribution with a mean of 10 and standard deviation of 3, we use the rnorm() function with the mean and sd arguments set to 10 and 3, respectively:

> rnorm(4, mean=10, sd=3)
[1]  9.546714  8.600795 14.344557 11.669767

Similarly, we can simulate 10 numbers from a Poisson distribution with a lambda of 3 with rpois(10, lambda=3). A table showing the function names for the most common distributions is available in Chapter 2, Statistical Methods with R.

We can also select random variables from a predetermined vector using the sample() function. This function allows you to randomly select a specified number of elements with the size argument from a vector, with or without replacing the values taken with the replace argument set to TRUE or FALSE, respectively. For example...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image