R Reference Card Page 4

ADVERTISEMENT

In the normal Lattice formula, y x|g1*g2 has combinations of optional con-
rpois(n, lambda) Poisson
ditioning variables g1 and g2 plotted on separate panels. Lattice functions
rweibull(n, shape, scale=1) Weibull
take many of the same arguments as base graphics plus also data= the data
rcauchy(n, location=0, scale=1) Cauchy
frame for the formula variables and subset= for subsetting. Use panel=
rbeta(n, shape1, shape2) beta
to define a custom panel function (see apropos("panel") and ?llines).
rt(n, df) ‘Student’ (t)
2
Lattice functions return an object of class trellis and have to be print-ed to
rf(n, df1, df2) Fisher–Snedecor (F) (χ
)
produce the graph. Use print(xyplot(...)) inside functions where auto-
rchisq(n, df) Pearson
matic printing doesn’t work. Use lattice.theme and lset to change Lattice
rbinom(n, size, prob) binomial
defaults.
rgeom(n, prob) geometric
rhyper(nn, m, n, k) hypergeometric
Optimization and model fitting
rlogis(n, location=0, scale=1) logistic
optim(par, fn, method = c("Nelder-Mead", "BFGS",
rlnorm(n, meanlog=0, sdlog=1) lognormal
"CG", "L-BFGS-B", "SANN") general-purpose optimization;
rnbinom(n, size, prob) negative binomial
par is initial values, fn is function to optimize (normally minimize)
runif(n, min=0, max=1) uniform
nlm(f,p) minimize function f using a Newton-type algorithm with starting
rwilcox(nn, m, n), rsignrank(nn, n) Wilcoxon’s statistics
values p
All these functions can be used by replacing the letter r with d, p or q to
lm(formula) fit linear models; formula is typically of the form response
get, respectively, the probability density (dfunc(x, ...)), the cumulative
termA + termB + ...; use I(x*y) + I(xˆ2) for terms made of
probability density (pfunc(x, ...)), and the value of quantile (qfunc(p,
nonlinear components
...), with 0
1).
p
glm(formula,family=) fit generalized linear models, specified by giv-
ing a symbolic description of the linear predictor and a description of
the error distribution; family is a description of the error distribution
and link function to be used in the model; see ?family
Programming
nls(formula) nonlinear least-squares estimates of the nonlinear model
function( arglist ) expr function definition
parameters
return(value)
approx(x,y=) linearly interpolate given data points; x can be an xy plot-
if(cond) expr
ting structure
if(cond) cons.expr else alt.expr
spline(x,y=) cubic spline interpolation
for(var in seq) expr
loess(formula) fit a polynomial surface using local fitting
while(cond) expr
Many of the formula-based modeling functions have several common argu-
repeat expr
ments: data= the data frame for the formula variables, subset= a subset of
break
variables used in the fit, na.action= action for missing values: "na.fail",
next
"na.omit", or a function. The following generics often apply to model fitting
Use braces
around statements
functions:
ifelse(test, yes, no) a value with the same shape as test filled
predict(fit,...) predictions from fit based on input data
with elements from either yes or no
df.residual(fit) returns the number of residual degrees of freedom
do.call(funname, args) executes a function call from the name of
coef(fit) returns the estimated coefficients (sometimes with their
the function and a list of arguments to be passed to it
standard-errors)
residuals(fit) returns the residuals
deviance(fit) returns the deviance
fitted(fit) returns the fitted values
logLik(fit) computes the logarithm of the likelihood and the number of
parameters
AIC(fit) computes the Akaike information criterion or AIC
Statistics
aov(formula) analysis of variance model
anova(fit,...) analysis of variance (or deviance) tables for one or more
fitted model objects
density(x) kernel density estimates of x
binom.test(),
pairwise.t.test(),
power.t.test(),
prop.test(), t.test(), ... use help.search("test")
Distributions
rnorm(n, mean=0, sd=1) Gaussian (normal)
rexp(n, rate=1) exponential
rgamma(n, shape, scale=1) gamma

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 4