Assignment 0. Nothing here to hand in

Similar documents
History, installation and connection

Keep Track of Your Passwords Easily

Installing a Custom AutoCAD Toolbar (CUI interface)

Word: Print Address Labels Using Mail Merge

How to Rescue a Deleted File Using the Free Undelete 360 Program

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

My First Cocoa Program

Some (semi-)advanced tips for LibreOffice

Microsoft Office Word. Part1

Title and Modify Page Properties

Barchard Introduction to SPSS Marks

Your . A setup guide. Last updated March 7, Kingsford Avenue, Glasgow G44 3EU

Interactive Tourist Map

MarkMagic 6 Bar Code Labels, RFID Tags, and Electronic Forms Software for IBM System i

Burning CDs in Windows XP

Boise State University. Getting To Know FrontPage 2000: A Tutorial

Barchard Introduction to SPSS Marks

Creating a Box-and-Whisker Graph in Excel: Step One: Step Two:

Depending on the computer you find yourself in front of, here s what you ll need to do to open SPSS.

ADOBE DREAMWEAVER CS4 BASICS

GradeConnect.com. User Manual

Microsoft Word 2010 Introduction to Mail Merge

The smarter, faster guide to Microsoft Outlook

Introduction to SPSS

A Document Created By Lisa Diner Table of Contents Western Quebec School Board October, 2007

Adobe Dreamweaver CC 17 Tutorial

Chapter 5 Making Life Easier with Templates and Styles

The first thing we ll need is some numbers. I m going to use the set of times and drug concentration levels in a patient s bloodstream given below.

Tips & Tricks for Microsoft Word

This Tutorial is for Word 2007 but 2003 instructions are included in [brackets] after of each step.

Imagery International website manual

Browsing the World Wide Web with Firefox

Civil Engineering Computation

2013 edition (version 1.1)

ORB Education Quality Teaching Resources

Get comfortable using computers

Adobe Dreamweaver CS5 Tutorial

ATMS ACTION TRACKING MANAGEMENT SYSTEM. Quick Start Guide. The ATMS dev team

CPAC. Bookmark CPAC 1

How To Upload Your Newsletter

This Tutorial is for Word 2007 but 2003 instructions are included in [brackets] after of each step.

Creating An Account With Outlook

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

Welcome to the world of .

Beginners Guide to Snippet Master PRO

I put a shortcut onto your desktop, the screen that you look at after you log in.

ebook Writing Workshop Practical 1: A First Logfile-Style ebook

Installing a Custom AutoCAD Toolbar (CUI interface)

Strategic Series-7001 Introduction to Custom Screens Version 9.0

Graphing Interface Overview

Using SourceTree on the Development Server

**Method 3** By attaching a style sheet to your web page, and then placing all your styles in that new style sheet.

My First iphone App. 1. Tutorial Overview

STAT:5400 Computing in Statistics

Example how not to do it: JMP in a nutshell 1 HR, 17 Apr Subject Gender Condition Turn Reactiontime. A1 male filler

Title and Modify Page Properties

Outlook Web Access. In the next step, enter your address and password to gain access to your Outlook Web Access account.

CIS 231 Windows 7 Install Lab #2

Rescuing Lost Files from CDs and DVDs

PowerPoint Basics: Create a Photo Slide Show

PYTHON YEAR 10 RESOURCE. Practical 01: Printing to the Shell KS3. Integrated Development Environment

Measures of Central Tendency:

Lab 1. Introduction to R & SAS. R is free, open-source software. Get it here:

PRACTICE-LABS User Guide

Tableau Tutorial Using Canadian Arms Sales Data

Soundburst has been a music provider for Jazzercise since Our site is tailored just for Jazzercise instructors. We keep two years of full

FACULTY AND STAFF COMPUTER FOOTHILL-DE ANZA

Using Dreamweaver. 4 Creating a Template. Logo. Page Heading. Home About Us Gallery Ordering Contact Us Links. Page content in this area

Tutorial 1: Unix Basics

XP: Backup Your Important Files for Safety

Intro. Scheme Basics. scm> 5 5. scm>

Step 7 How to convert a YouTube Video to Music As I mentioned in the YouTube Introduction, you can convert a Video to a MP3 file using Free Video To

1 Introduction to Using Excel Spreadsheets

JS Lab 1: (Due Thurs, April 27)

Your current address will be used to access schooltool. Please provide the school registrar with this if you haven t already done so.

CS Multimedia and Communications REMEMBER TO BRING YOUR MEMORY STICK TO EVERY LAB!

HTML4 TUTORIAL PART 2

Lutheran High North Technology The Finder

the NXT-G programming environment

Microsoft Expression Web is usually obtained as a program within Microsoft Expression Studio. This tutorial deals specifically with Versions 3 and 4,

Programming Lab 1 (JS Hwk 3) Due Thursday, April 28

IBM Emptoris User Guide

Developing a Home Page

Section 6: Dreamweaver

Introduction to Cascade Server (web content management system) Logging in to Cascade Server Remember me Messages Dashboard Home

CSCU9B2 Practical 1: Introduction to HTML 5

Lab 2. CSE 3, Summer 2010 In this lab you will learn about file structures and advanced features of Microsoft Word.

CSCI 201 Lab 1 Environment Setup

5 R1 The one green in the same place so either of these could be green.

1. Please, please, please look at the style sheets job aid that I sent to you some time ago in conjunction with this document.

Password Memory 7 User s Guide

Document Imaging User Guide

Introductory SAS example

Touring the Mac. S e s s i o n 3 : U S E A N APPLICATION

MyDispense User Guide

GoLive will first ask you if your new site will be for one individual or a work group; select for a Single User, and click Next.

FRONTPAGE STEP BY STEP GUIDE

How to Make a Book Interior File

Spectroscopic Analysis: Peak Detector

Microsoft Office 2010 consists of five core programs: Word, Excel,

Transcription:

Assignment 0 Nothing here to hand in The questions here have solutions attached. Follow the solutions to see what to do, if you cannot otherwise guess. Though there is nothing here to hand in, it is very much worth your while to work through these two problems, because they will get you used to how SAS and R operate, and gain you some comfort in coding simple things. If you do not work through these problems now, any issues that you could have dealt with this week (with me around to help) will come back to bite you next week, when you will have an assignment due. This is stress you would do well to be without. There are 12 things to do here, plus more optional stuff; you ll have to go fast to finish them in an hour. If you don t get to the end in tutorial, it s a good idea to finish them on your own time this week. 1. This question will introduce you to SAS. Open up a web browser (sometimes Firefox works better than Chrome for this) and go to https: //odamid.oda.sas.com. Bookmark this page. You ll see this (only without a username and password filled in): 1

(a) Click on Register for an Account (unless you happen to have one already, in which case sign in with username and password). Fill in your first name, last name, e-mail address (twice) and select Country. Click Submit. (b) Check your e-mail (the address you used above). There should be an e-mail from SAS with a link in it. Click that link. This will take you to a page where you choose a password. Enter your e-mail address again, and enter a password (twice). Note the password rules at the bottom. You need characters from at least three of the four categories, so that if your password contains uppercase and lowercase letters and numbers, you don t need any punctuation characters. Click Create Account. (c) Next, you get a window with your new user ID in it. Note it down, or save it somehow. 1 There s a link to the Sign In screen. 2 Click it, and sign in with your user ID and the password you chose. Solution: If you did that properly, you ll be greeted with something like this: Page 2

(d) Click on SAS Studio. You will eventually see something like what appears in the Solution below. This is usually the slowest part of the whole operation. If it seems to be taking a long time, 3 leave the rest of this question for now and come back to it later. Solution: This is the kind of thing you will (eventually) see: (e) Go over to where it says Enter your code here. We are going to do two things: first, we ll enter some data and save it, and then (in the next part), we ll write some code to read in the data and run that code. First, the data. The first row is the name of the variable, x, and below that come the values. We only have one variable this time: Page 3

Now to save this. Click on the disk icon (its tooltip says save program ). The Save button at the bottom is pale blue, meaning that you can t save anything yet. Click on the line Files (Home), which should turn the Save button dark blue. Then go down to the Name box, erase what is there, and put just a in the box. Leave the Save as Type alone: I only appear to be able to see half my Save button, but that s OK: I can click on what I can see. When you have what you see above, click Save. You should see the file a.sas appear over on the left under Files (Home). Files there are yours and are saved until you delete them. (f) Next, to read in that data file. Find the New button. This is the leftmost one of the six buttons under Server Files and Folders. Click it. From the dropdown, select SAS Program. (Don t select Import Data, though you might be tempted to do so. That is a wizard, but we are going to write code to read in the data file, to get practice for later.) You ll now have two tabs: one called a.sas with the saved data, and one still called Program 1 since we haven t saved it yet. Type the code shown below into the new tab, and save it as firstcode.sas, the same way you saved the data file. When you have done that, you should see what is below: Page 4

Check the code very carefully. Make sure that the lines that end with semicolons in my code above also end in semicolons in yours. Finally, for this part, go back to the line that starts datafile=, and change megan3 to your username, the one you used to log into SAS Studio with. Save your code again. (Just clicking on the Save button will do it, since SAS Studio knows where to save it.) Solution: What does that code do? Two things: it reads the data in from a file (the proc import and the five lines below that), and then it displays it on the screen (the proc print). I like to use the indentation shown, though unlike Python it doesn t actually matter, because I want to be able to see that the lines down to getnames belong to proc import and the proc print is a separate thing. SAS Studio helps by using a bold font for the proc lines and a regular font for everything else. The lines under the proc import say this: 1. where the data file is stored. Mine means the file called a.sas under the account with username megan3 on SAS s servers. 2. the kind of file it is. We are pretending that this is a.csv file, even though it isn t really. 3. the name of the SAS data set to create (which doesn t matter here since we never refer to it by name) 4. Replace any previous SAS data set called mydata that we might have created. 5. Get the variable name(s) from the first line of the data file, which is why we put the name x there before. proc print displays the most recently-created data set, showing you all the variables in it. This is the usual structure of SAS code: proc import to read some data in from a file, and one or more other procs to do something with it. (g) Now try your code and see whether it works. Look for the running humanoid under the Code tab, and click it. Page 5

Solution: One of two things will happen: either it will work, and you ll see your data set displayed in the Results tab: or there will be an Error, and you ll get taken to the Log tab. Here I mistakenly typed the username megan2 instead of megan3: To find out what the error was, scroll up in the Log tab until you find the first red Error, which is here: The first line (in black) is telling you what the error is: the file I am asking for doesn t exist, either because I have the filename wrong, or because I have the username wrong. There are many other possible errors, but, whatever error you have, the strategy is to find the first place where there was a problem, since that might have caused other errors. In this case, the data set couldn t be created because SAS couldn t find the data file to create it from. Fix that, and the second error will fix itself. (h) (Come back to this part later if you re running short on time). Add some lines to your code to make it look like this: Page 6

Run it. What do you get? (You ll probably need to scroll down in the Results tab to see it all.) Solution: Here is my code again: proc import datafile='/home/ken/a.sas' dbms=csv out=mydata replace; getnames=yes; proc print; proc means; proc sgplot; vbox x; and here is the output it produces in the Results tab: Obs x 1 10 2 11 3 13 4 17 5 22 6 29 Page 7

The MEANS Procedure Analysis Variable : x N Mean Std Dev Minimum Maximum ----------------------------------------------------------------- 6 17.0000000 7.3484692 10.0000000 29.0000000 ----------------------------------------------------------------- Page 8

Page 9

This is: a listing of the data (as before) a summary of the variable x: the mean, SD, min and max, produced by proc means (which makes a summary of all the variables, but here we only have one). a boxplot of x. proc sgplot produces all kinds of different plots; vbox is a regular (vertical) boxplot; hbox produces a sideways one. The diamond in the middle of the boxplot is the mean; it is a bit bigger than the median. Also, the long upper whisker adds to the impression of the data being skewed to the right. Which was how I expected it to be, looking at the data values. In the Results tab, there are buttons that allow you to download the results (for handing in). The most general approach seems to be to download the Results tab as HTML, and then open that in Word. This allows you to add text (your explanations of what is going on). There is a download as Word tab but that was greyed out for me. Try it yourself. 4 Here s what my HTML-opened-in-Word looks like. I added a little text and made it a different font (Arial) so that you can distinguish it: You can experiment with putting the text after the output, and making it a non-bold smaller font. 2. This question uses the same data as the previous one, but is to be done in R. (a) Start R Studio. (Use the Start button bottom left, and search for it in the menus.) Solution: You ought to see something like this: Page 10

It won t look exactly like that, but there should be one thing on the left half, which will probably be white, and at the top right it ll say Environment is empty. (b) We re going to do some straightforward stuff in R here, just to get used to it. First, make an R Script by selecting File, New File and R Script. Solution: Note the Run button along the top of the R Script window. We ll be using that in a moment. (c) Type the code shown below into the R Script window. Don t type the numbers on the beginning of the lines; R Studio provides those: Page 11

Solution: What this does, in order: store those six values in a variable x; display x; display the mean of x, then the standard deviation of x, then a boxplot of x. In approximately five seconds, you ll be demonstrating that for yourself. (d) Run these commands. To do that, put the cursor on the first line (as in my screenshot), then click the Run button. This runs the first line and moves the cursor down to the second line. When you are ready, run that as well, and so on. Solution: Here s what I get (yours should be the same). Note that the first line (the storing of values in x) does not produce any output, but the other lines all do. x=c(10,11,13,17,22,29) x ## [1] 10 11 13 17 22 29 mean(x) ## [1] 17 sd(x) ## [1] 7.348469 boxplot(x) Page 12

10 15 20 25 Note where answers come out: numerical stuff in the console, along with a copy of the code that produced it, and graphs in the bottom-right window. As you create new variables (x here), you see them appear in the Environment (by default top right). You can also run more than one line at once by selecting all the lines you want to run and then clicking Run. After it s done, you ll need to de-select the lines and move the cursor yourself. 3. Some more R practice, using the same data as before, but rather more like what we ll be doing later. Optional, but worth your while to do now. (a) First, we type the data into a file. Select File, New File and Text File. A window called Untitled1 appears top left. Into that, type the same data that you used in SAS: the name x and six numbers. The numbers on the left are line numbers; R Studio produces those, so you don t type them: Page 13

(b) Save this somewhere that you ll be able to find it (using File and Save As). This could be on the Desktop, or in the folder that R is currently in, or anything else that you can remember. Call the file a.txt. (c) Create a new R Script. To do this, from the File menu select New File and then R Script. Solution: You ll see something like this, with the new (empty) R Script top left in a second tab: (d) Click in your R Script window, and type library(tidyverse). Leave the cursor on the end of that text, and find the Run button at the top of the window. Click it. This will run the code you just typed. Page 14

Solution: One of two things will happen. Go look in the Console window to find which one it was. You might get an error like this (which I got because I mistyped the name, but you would also get the same error if you hadn t installed the package yet): If that happens to you, go to the console window and type install.packages("tidyverse") (including the quotes). Let it do what it will. When it s finished, run the library command from your script window again. This time you should see what is just below. The second thing that can happen is that everything is OK, and then you will see this: (e) Into your script window type f=file.choose(), and run it. You ll be invited to choose a file, as if you were opening it or saving it. Choose the data file that you typed in and saved earlier, clicking Open to finish the job. This records where the file is, in the variable f. If you like, go to the Console and type f and Enter, and it should show you which file you chose. Solution: Mine looks like this: On Windows, yours will look a bit different, but you should see a username, a folder, possibly a subfolder, and a file name on the end. (f) Now read in the data file. To do this, type (in your script) mydata=read csv(f) and run it. Solution: In the console, you should see parsed with column specification and it should tell you that you have one column x which is integers. To check what you have, in the console window, type the name of your data (mydata is mine), which should display all the data you read in. My output looks like this: Page 15

The thing mydata is a data frame (sometimes known as a tibble ). (g) Obtain the mean and standard deviation of x, and compare with the values you got from SAS (if you did). Solution: Go back to your Script window, type in this code and run it: mydata %>% summarize(xmean=mean(x),xsd=sd(x)) To get that funny symbol with the percent signs, you can type control-shift-m. To run this code, put the cursor on the first line and click Run once. Because R Studio recognizes that these lines belong together, it will run them both. Or, if you prefer, select both lines (the usual way), and then click Run, which will run any number of lines in one shot. Either way, you should get this: Mean of 17, SD of about 7.35. (Note here: if I ask you on an assignment what the values are, I want you to tell me; it s not enough to obtain the output that has the values on it somewhere.) These are exactly the same values as SAS got (which is a relief). Page 16

As an aside, if you calculate a summary this way, the summary itself is also a data frame (and you could, if you wished, go on to do other things with it). (h) Obtain a boxplot of x. Does it look like the one from SAS (if you obtained it)? Solution: The code is this odd-looking stuff: ggplot(mydata,aes(x=1,y=x))+geom_boxplot() Put it in the script window and run it. Graphical output appears bottom right: This boxplot has the same qualitative features 5 as SAS s. The median is more than halfway down the box, and the upper whisker is longer, pointing to a right skew again. It is actually rather strange that SAS puts the mean on its boxplot; the original prescription for a boxplot is that it should be based on the five-number summary, that is, the median, quartiles and extreme values. R plays this by the book. (i) Try opening a Word document and grabbing the output from R Studio. Your code, from the Script window, and the text output, from the Console window, can just be copy-pasted. But make sure you make the font of the R commands a fixed-width font like Courier 6, so that what should line up in columns actually does. To copy the graph, click the Export button above the graph. You should be able to copy it to the Clipboard and paste it into your document from there. If not, Save it as Image and Insert From File in your document. If all else fails, take a screenshot and paste that in. Solution: This, shrunk a bit: Page 17

On mine, some of the text output came out rather pale (because it was originally on a dark background). On a white background (in R Studio), the text is probably a good colour to be used on a white background in Word. Page 18

Notes 1 If you forget it, there s a way to get it back, but it s better not to have to go that way. 2 This is the same screen as you bookmarked earlier. You can use your bookmark if you prefer, now or later. 3 This is because you are competing against everyone else in the world for access to SAS s servers. 4 Downloading as HTML is better than downloading as PDF, because you can edit the former but not the latter. 5 A fancy way of saying it looks the same. 6 Or another font with something like mono in its name, which is short for monospaced, meaning that all the characters have the same width. Page 19