Basics of R
Data import and manipulation, graphs, functions, modeling
R. Condit
Ohio State University Department of Music
May 2013
Assignments
Tuesday, 7 May
Write a script to manipulate studyOneCleanData
Start with the ascii table of data
Import into a dataframe
Mean and SD of columns
Add a new column for average of high and low temperature
Graph Tempo vs. Mid-temperature
Save graph as pdf
Save the new data.frame as R object
Export the new table as tab-delimited ascii
Write a script to manipulate study3Opera
Start with the ascii table of data
Import into a dataframe
Mean and SD of columns
Mean authority for males vs. females
Mean tessitura for males vs. females
Graph tessitura vs. age, different colored points for males and females
Save graph as pdf
Wednesday, 8 May
Regression: —– data
Possible terms
simple model: log(AGB) vs. log(dbh)
second order term: log(dbh) squared
rainfall and elevation
Graph
log(AGB) vs. log(dbh)
add curve of best fit
overlay curves for high rainfall and low rainfall
Character variable (factors)
use ForestType in the model
log
(
volume
)
~
log
(
dbh
) +
ForestType
compare to 3 independent models (3 forest types)
log
(
volume
[
dry
])
~
log
(
dbh
[
dry
])
etc.
Save a graph
Thursday, 9 May
Write a function to do regression, draw graph, add line
Arguments x, y
Save graph
Loop through several x variables
Write a function with a loop
Friday, 10 May
Use lmer for regression of logagb on logdbh with species and forest type as
factors
Include squared term for logdbh
Add locality as a group effect (does it change the fixed effect)
Test forest type as fixed effect and as group effect
Graph points and lines
Compare alternative models
Use lmer for regression of pup Wt on momcat with year as a mixed effect
Variable intercept, slope, or both
Graph all points
Use xyplot for groups (Lattice)
Overlay lines of all random effects
Compare alternative models
Use lmer for regression of log(ht) on log(dbh) with species as a mixed effect