Rafael Resendiz
[1] "Tue Nov 25 19:40:38 2014"
Load files and datasets and and have fun with them
data(iris) # Load data
lm(iris) # Make a lineal regression
Call:
lm(formula = iris)
Coefficients:
(Intercept) Sepal.Width Petal.Length
2.1713 0.4959 0.8292
Petal.Width Speciesversicolor Speciesvirginica
-0.3152 -0.7236 -1.0235
Setting the global options Example: The exponential distribution
lambda = 0.2 # lambda for all simulations
n = 20 # number of exponential random variables
nsims = 1:100 # number of simulated averages
set.seed(1)
means <- data.frame(x=sapply(nsims,function(x) {mean(rexp(n,lambda))})) # necessary means
head(means,2) # show the results
x
1 5.446627
2 4.274117
str(means) # See a summary of the results
'data.frame': 100 obs. of 1 variable:
$ x: num 5.45 4.27 5.17 6.76 4.12 ...
fit <- lm(iris) # Work with real data
confint(fit) # Identify intercepts and others
2.5 % 97.5 %
(Intercept) 1.6182321 2.72430044
Sepal.Width 0.3257653 0.66601260
Petal.Length 0.6937939 0.96469395
Petal.Width -0.6140049 -0.01630542
Speciesversicolor -1.1982739 -0.24885002
Speciesvirginica -1.6831329 -0.36386273
summary(fit$residuals)
Min. 1st Qu. Median Mean 3rd Qu. Max.
-0.794200 -0.218700 0.008987 0.000000 0.202500 0.731000
Plot your results and identify your creativity