# Load the needed libraries.
library(psych)
library(pastecs)
library(gplots)
library(TSA)
# We'll take a look at a new data file of global social indicators, World95.
World95<-read.csv("http://www.courseserve.info/files/world95r.csv")
attach(World95)
# We can see the variables using the summary() function.
summary(World95)
# Let's take a look at some of the graphic functions.
# First, we'll look at a scatterplot, and then add a regression
# line to the graph.
plot(urban, gdp_cap, xlab="Percent Population Urban", ylab="GDP per Capita")
abline(lm(gdp_cap~urban))
# Next, we can look at a boxplot, for describing central
# tendency and variability.
plot(religion, lifeexpf, xlab="Religion", ylab="Life Expectancy for Women")
# Next, we'll look at a graph that combines scatterplots for a
# series of variables. First, we'll take a subset of the variables.
World95b<-subset(World95, select=lifeexpf:literacy)
pairs(World95b)
# Now we'll consider the barplot.
barplot(by(literacy,region,mean),xlab="Mean Literacy Rate")
# This plot is similar to the boxplot, except that you can plot
# more than one function. You could, for example plot the standard
# deviations in order to graphically compare groups by the
# amount of dispersion.
barplot(by(literacy,region,sd),xlab="Mean Literacy Rate")
# Let's look at a plot of a time series.
data(wages, package="TSA")
plot(wages)
# We can get a sense of whether or not the observations are
# independent by looking at the relationship between each
# observation and the one previous.
plot(zlag(wages),wages,xlab="Wages (t-1)",ylab="Wages (t)")