Second Lecture

advertisement
Lecture 2
LISAM. Statistical software.
LISAM
What is LISAM? Social network for
 Creating personal pages
 Creating courses





Storing course materials (lectures, documents, useful links)
Publishing assignments to certain student groups (labs,
project work)
Uploading and submitting solutions to assignments
electronically
Correcting and grading the solutions
Communication between students and teacher
http://lisam.liu.se
Introduction to academic studies
How it looks like when you logon
Introduction to academic studies
Panels



Menu
Newsfeed: you find comments from people and courses
you have chosen to follow
Messages: important information from
teachers/administrators in your courses.
Important menus:
 About me (edit the profile, set the default language)
 My courses: See all courses that you registered yourself
for.
 About LISAM help information
Introduction to academic studies
If the webpage is in Swedish

About meEdit your profile
Introduction to academic studies
Accessing a course

My courses
Introduction to academic studies
Course structure
Introduction to academic studies
Course structure








Syllabus: compressed information about the course, teaching,
examination and admission requirements
Course documents: basic course material: lectures, files
(uploaded by teacher)
Collaborative workspace: teachers and students can publish
files there and make comments
Newsfeed: Teachers and students may start a conversation
there
Announcements: information from teacher
Timetable: link to schedule in TimeEdit
Submissions: Here you may find your labs/assignments and
submit the answer
Assessment record: The overview of your grades
Introduction to academic studies
Course menus
Note that each lab/assignment has a deadline
and an end date
Introduction to academic studies
Submit a report
Introduction to academic studies
Statistical and data mining software

Commerical






SAS
Minitab
SPSS
Matlab
Microsoft SQL Server
Free of charge:




R
WinBugs
Python
GGobi
Introduction to academic studies
SAS

SAS




Basic Module
SAS Enterprise Guide
SAS JMP
…
Introduction to academic studies
SAS
proc import datafile=’C:\Customers.xlsx' dbms=xlsx
out=Customers;
sheet='Sheet1';
run;
Learn:








How SAS is started
What is Library
What's in the Editor, Output, Log
What's in the Results
How to create a library
How to import XLS document to the library
Note data material (Column attributes)
Write a simple computer program and save the file






proc. gplot data = sashelp.class;
plot height * weight;
run;
Run the program
Sas file upload.
Help (contents, index, search, SAS/GRAPH, SAS/STAT)
Introduction to academic studies
R





R is a real computer language with full flexibility
Constantly increasing amount of packages (new
research)
Free of charge
Website: http://www.r-project.org/
Code Editor: http://rstudio.org/
Introduction to academic studies
Software: use RStudio


Install R: http://www.r-project.org/
Install RStudio: http://rstudio.org/
Workspace
Program
Plots
Execution
console
Introduction to academic studies
Basics in RStudio
Important to know:
 Create a new file and save it (File menu)
 Running one line or entire code (Edit menu)
 Running one line in console
 Workspace (Observe, Save, Clear)
 Setting current directory (Tools)
 Installing new package (Packages tabs)
Introduction to academic
studies
Call help

Specific function


Help browser


args(function)
Examples of how to use function:


help.search(“expression”)
Quick reminder of function arguments:


help.start()
Search for something in help


help(function)
example(function)
If some method is not installed on the computer:

RSiteSearch(”expression")
Introduction to academic studies
Introduction
R is case-sensitive (A and a)
 Each command on a new line
 Comment:
#R is a very cool language!

Initialize/set the variable
Use-> or <a<-3
3->b
Introduction to academic
studies
Vectors

Create a vector
x<-c(1,3)

See the result
x
print(x)
Introduction to academic studies
Operation with vectors





Element-wise: +-*/^
log exp sin cos
length –number of elements
sum - sum of all elements
max min sort order
Logicals:
TRUE or FALSE:
A=TRUE;
> >= < <= != & (and) | (or)
Introduction to
academic
studies
Sequence

Either‘: ‘ or seq()
Introduction to academic studies
Matrices
Use matrix()
a<-matrix(values,nrow=m,ncol=n)
Values should be listed columnvise
nrow= and ncol= can be skipped
Introduction to academic studies
Matrix operations
Introduction to
academic
studies
Matrix operations

Matrix operators/functions:

transpose
b=t(a)
b = aT

Inverse
b=solve(a)
b = a-1 (when needed)
Introduction to
academic
studies
Index
Positive index
x[1,6]
x[2:10]

Negative index
x[-(1:5)]
all except 1:5

Entire column or row
x[2,] entire column 2

Extraction
x[x>5]

Introduction to
academic
studies
Lists

List is a collection of objects
Introduction to
academic
studies
Data frame
Vectors and matrices of the row length can be collected into
a data frame
•
Used to store the data of different types into a single
table
Use data.frame(object 1, object 2, … , object k)
Introduction to academic
studies
Data frame

Any column in the data frame can be retrieved by
dataframe$object

Any row in the data frame can be extracted by using
matrix notation, for ex: z[1,]
Introduction to academic
studies
Read data from Excel file
1.
2.
3.
Save as ”comma-separated file”(csv)
Change current directory, Session Set Working
Directory or setwd()
Use
Dataframe<-read.csv2(file_name)
Exercise:

Use Excel file alb.xlsx and import it to R
Introduction to academic
studies
Conditioning and loops
If (x==3) {
…
…
} else {
…
}
for (i in 2:99) {
…
}
while(x!=29) {
…
}
Introduction to academic studies
Loops
for (name
{
…
}
in expr1 )
while (condition)
{
…
}
Introduction to academic studies
Using a function

Use ?name_of_function to see function parameters



For ex. ?lm
There are some obligatory parameters and optional parameters
The optional parameters can be specified in different order
X=1:10
Y=1:10+rnorm(10)
W=c(rep(1,5), rep(2,5))
mydata=data.frame(X,Y)
result=lm(Y~X, weights=W,data=mydata)
?predict.lm
Fit=predict(result)
plot(X,Y)
points(X,Fit, type="l", col="blue")
Introduction to academic studies
Writing your own functions


Function writing
must always end
with writing the
value which
should be
returned!
You may also
use
”return(value)” to
show what value
the function
should return
Introduction to academic studies
Download