node9 Lab 2 - Using Scripts and Writing Functions STAT 510 - Applied Time Series Analysis

# Node9 Lab 2 - Using Scripts and Writing Functions STAT 510 - Applied Time Series Analysis

This preview shows pages 1–3. Sign up to view the full content.

This is Google's cache of http://onlinecourses.science.psu.edu/stat510/node/9 . It is a snapshot of the page as it appeared on 13 Aug 2010 20:18:51 GMT. The current page could have changed in the meantime. Learn more Text-only version STAT 510 - Applied Time Series Analysis ANGEL Department of Statistics Eberly College of Science Home Lab 2 - Using Scripts and Writing Functions Using Scripts In this lab, we are going to learn to use scripts and to write functions in R. 1. Make a new folder called "lab2" and save the file " globtemp.dat " into this directory. Go to the file menu in R and select "New script". We are going to read in the data from " globtemp.dat " (The global average temperature from 1900-1997). In the first line of the script, enter global= scan("globtemp.dat") 2. Let us now enter the commands to save a plot of this variable into a pdf file. Enter into your script the following: pdf("globalplot.pdf") plot.ts(global) dev.off() 3. Now, we need to save this script. Select "save" from the file menu. Save this script as "lab2.R". Choose, "Source R code. .." and select "lab2.R". You will notice that the pdf file is created in your folder. Note that you can take this pdf file and drag and drop it into a word processor program or double click it to view. An alternative to using the "Source R code. .." command to run the script is to type source("lab2.R") on the command line. 4. We can add to the script by saving plots of this data differenced and also ACF plots of the data and the

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
differenced data. globaldiff=diff(global) pdf("globaldiffplot.pdf") plot.ts(globaldiff) dev.off() pdf("globalacf.pdf") acf(global) dev.off() pdf("globaldiffacf.pdf") acf(globaldiff) dev.off() Save and run the script. Lab 2 - Using Scripts
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 09/10/2010 for the course STAT 510 at Penn State.

### Page1 / 5

Node9 Lab 2 - Using Scripts and Writing Functions STAT 510 - Applied Time Series Analysis

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online