Introduction to R ปราณี นิลกรณ์.

Slides:



Advertisements
งานนำเสนอที่คล้ายกัน
โครงสร้างโปรแกรมภาษา C
Advertisements

บำรุง พ่วงเกิด Office: ME201 Homepage: 12/17/2008
Texture การประมวลผลภาพแบบดิจิตอล Ian Thomas
รายวิชา ง40206 โครงสร้างข้อมูลและขั้นตอนวิธี
Multi-Version Text Viewer / Editor COE Chaiwat Sookpanya : Kannawat Chaiyarajsamee :
Accessing Web Application Data at Any Time 1. 2 อาจารย์ที่ปรึกษาโครงการ ผศ. กานดา สายแก้ว อาจารย์ผู้ร่วมประเมินโครงการ ผศ. อนัตต์ เจ่าสกุล รศ. วนิดา แก่นอากาศ.
การรับค่าและแสดงผล.
Functional programming part II
Accessing Web Application Data at Any Time
Stack.
6. โครงสร้างข้อมูลแบบแฟ้ม
: Chapter 1: Introduction 1 Montri Karnjanadecha ac.th/~montri Image Processing.
ออโตมาตาจำกัด FINITE AUTOMATA
ผังงานโปรแกรม (Program Flowchart)
ภาษามาตรฐานสำหรับนิยามข้อมูล และการใช้ข้อมูล
การใช้โปรแกรมคอมพิวเตอร์ช่วยในการวิเคราะห์ข้อมูล
เนื้อหา ประเภทของโปรแกรมภาษา ขั้นตอนการพัฒนาโปรแกรม
Object Oriented Programing
โปรแกรมสำเร็จรูปทางสถิติ
การติดตั้ง R และ R Commander
ASP:ACCESS Database.
Functions & Sub Program ฟังก์ชันและโปรแกรมย่อย
CHAPTER 1 Major Sources of Errors in Numerical Methods
ข้อแตกต่างระหว่าง กับ ผู้ชนะ ผู้แพ้.
การเขียนโปรแกรมคอมพิวเตอร์และอัลกอริธึม
Asst.Prof. Dr.Surasak Mungsing
ให้ประหยัดการใช้หน่วยความจำ (space) ด้วยความรวดเร็ว (time)
Merchant Marine Training Centre วิชาการเป็นเลิศ เชิดชู คุณธรรม ผู้นำ.
Menu and Interactive with Powerpoint ให้นำเรื่อง Input /Output Technology มา จัดทำ การนำเสนอ โดยใช้หลักการ Menu and Interactive with powerpoint มาประยุกต์
การเปลี่ยนแปลงเกี่ยวกับตัวแปร
โครงสร้างควบคุมการทำงาน
Wh-Question.
วิธีการ Auto ship.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Java Programming Language.
List ADTs By Pantharee S..
เขียนโปรแกรมเพื่อแสดงข้อมูลพนักงาน ด้วย ADO.NET vs. DataReader
วิชาคอมพิวเตอร์กราฟิก intro_vb_net_06 การสร้างกราฟเส้นตรงด้วย VB.NET
การสร้าง WebPage ด้วย Java Script Wachirawut Thamviset.
ฟังก์ชัน.
หลักสูตรอบรมครู คอมพิวเตอร์ หลักสูตรอบรมครู คอมพิวเตอร์ หลักสูตรที่ ๑ ทักษะการโปรแกรม เบื้องต้น วันที่สาม.
In-Class Exercises Discrete Mathematics
Chapter 04 Flowchart ผู้สอน อ.ยืนยง กันทะเนตร
สาขาวิชาเทคโนโลยี สารสนเทศ คณะเทคโนโลยีสารสนเทศ และการสื่อสาร.
Present Continuous.
 How do we improve the test?  Why do we have to improve the test?
1 Functions กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร มหาวิทยาลัยนเรศวร พะเยา.
Part of Speech Conjunction.
Introduction to SQL (MySQL) – Special Problem (Database)
ว เคมีพื้นฐาน พันธะเคมี
เครื่องมือในการจัดการและวิเคราะห์ข้อมูล
Customer Relationship Management (CRM)
นายรัฐราษฎร์ เกื้อสกุล 1. 2 Disk Password Protection เป็นชุดของโปรแกรมสำหรับปกป้องและจำกัด การเข้าถึง Harddisk สามารถปกป้อง Disk/Partition ด้วย Password,
How do scientists think and find( พบ ) answers?.
กลุ่ม rraid. What's your name. คุณชื่ออะไร = Miss Bangon Buntanoom How old are you. - คุณอายุเท่าไหร่ = Ages 36 Years What you have finished your course.
ภาษาอังกฤษ ชั้นมัธยมศึกษาปึที่ 4 Grammar & Reading ครูรุจิรา ทับศรีนวล.
1 exit() and break C++ provides a way to leave a program early (before its natural finish) with the exit() function. The format of exit() is as follows:
Practice File. Our Executive Coaching Program is proven effective. Our customer survey show ROI of coaching can be as high as 3 times the investment value.
"วิธีวิเคราะห์แบบสอบถาม หรือแบบประเมิน ด้วยโปรแกรม SPSS"
การออกแบบอีเลิร์นนิง
INC 161 , CPE 100 Computer Programming
1. นี่เป็นสิ่งที่พระเยซูทรงทำ พระองค์ทรงรักษาทุกคน ที่เจ็บป่วยให้หายดี
หน่วยที่ 2 ข้อมูลและสารสนเทศ
การใช้โปรแกรมเบื้องต้น (Application Overview)
บทที่ 1 ความรู้เบื้องต้น เกี่ยวกับระบบสารสนเทศ
Multimedia Production
ผลการดำเนินงานโครงการทัศนศึกษาต่างประเทศ (มาเลเซีย-สิงคโปร์)
ที่มาและหน่วยงานกาชาดต่างๆ
แล้วไงเกี่ยวกับความจริง What About Truth?
1. พระเยซูทรงต้องการให้เราเป็น เหมือนพระองค์
โครงการสัมมนาเชิงปฏิบัติการบูรณาการภาครัฐและเอกชนในการจัดยุทธศาสตร์เศรษฐกิจภาคตะวันออก This template can be used as a starter file to give updates for.
ใบสำเนางานนำเสนอ:

Introduction to R ปราณี นิลกรณ์

R คืออะไร? R เป็นภาษาและโปรแกรมสำเร็จรูปสำหรับการ คำนวณทางสถิติและสร้างกราฟประเภทให้เปล่า ( free open source package ) ที่พัฒนาขึ้นมาจาก ภาษา S ( S language, Bell Labs) โดย Robert Gentleman และ Ross Ihaka แห่งUniversity of Auckland, New Zealandเมื่อปี 2538 เหมาะทั้งสำหรับการเขียนโปรแกรมเอง และใช้แบบ โปรแกรมสำเร็จรูป มีฟังก์ชันทางสถิติให้เรียกใช้มากมาย และมีผู้พัฒนา เพิ่มอย่างต่อเนื่อง

R คืออะไร? ข้อมูลทุกอย่างเกี่ยวกับ R หาอ่านได้จาก http://www.R-project.org R system ประกอบด้วย 2 ส่วนหลัก คือ Base system – ประกอบด้วย R language software และส่วนเพิ่มเติมอื่นๆที่มีความ จำเป็นต้องใช้บ่อยๆ User contributed add-on packages

การใช้ R จะหาโปรแกรม R ได้จากไหน? ไป download ได้ที่ www.r-project.org หรือที่ http://CRAN.R-project.org โดยเลือกลงโปรแกรมพื้นฐาน ( Base Package) ถ้าต้องการใช้แบบเมนู จะต้องติดตั้ง โปรแกรม Rcmdr เพิ่มเติม

ความสามารถของ Base Package การจัดการข้อมูลและหน่วยความจำ การคำนวณในรูป Array และ Matrix การวิเคราะห์ข้อมูลทางสถิติ การสร้างกราฟ การเขียนโปรแกรม

โปรแกรม R RGui ( Gui – Graphical user interface) ประกอบด้วย วินโดวส์ R Console สำหรับเขียนคำสั่งและแสดงผล ลัพธ์ วินโดวส์ R Graph สำหรับแสดงกราฟ Script Windows สำหรับเขียน แก้ไขคำสั่ง โปรแกรม

The R GUI

Open script

R Graph Windows

R และ สถิติ R มี Packages ทีมีผู้สร้างสำหรับการคำนวณและการวิเคราะห์ ข้อมูลทางสถิติ ซึ่งเราสามารถ ดาวน์โหลดมาใช้ได้อย่างสะดวก และรวดเร็ว มีผู้พัฒนา packages สำหรับเทคนิคการวิเคราะห์ใหม่ๆนอกจาก วิธีทางสถิติแบบเดิม เช่น data/text mining นักสถิติที่วิจัยและพัฒนาวิธีการทางสถิติใหม่ๆ นิยมเขียนวิธีการเป็น R packages

การทำงานของ R โดยทั่วไป พิมพ์คำสั่ง R ตามที่ต้องการ ใน command line interface หรือ โหลดไฟล์ที่มีคำสั่ง R อยู่แล้ว(Script file) มา run ช้า แต่มีข้อดี คือ เป็นการบันทึกขั้นตอนการวิเคราะห์ข้อมูล เก็บไว้เป็นไฟล์สำหรับงานแต่ละงานได้ เวลาพบความผิดพลาด ทราบได้ว่าผิดพลาดขั้นตอนไหน ถ้าการวิเคราะห์ต้องทำหลายขั้นตอน สามารถนำคำสั่งมา run ซ้ำใหม่ได้โดยไม่ต้อง click ใหม่ซ้ำ ๆ

Getting help >? t.test or >help(t.test)

R Advantages Disadvantages Fast and free. State of the art: Statistical researchers provide their methods as R packages. SPSS and SAS are years behind R! 2nd only to MATLAB for graphics. Mx, WinBugs, and other programs use or will use R. Active user community Excellent for simulation, programming, computer intensive analyses, etc. Forces you to think about your analysis. Interfaces with database storage software (SQL) Not user friendly @ start - steep learning curve, minimal GUI. No commercial support; figuring out correct methods or how to use a function on your own can be frustrating. Easy to make mistakes and not know. Working with large datasets is limited by RAM Data prep & cleaning can be messier & more mistake prone in R vs. SPSS or SAS Some users complain about hostility on the R listserve

R Commercial packages Many different datasets (and other “objects”) available at same time Datasets can be of any dimension Functions can be modified Experience is interactive-you program until you get exactly what you want One stop shopping - almost every analytical tool you can think of is available R is free and will continue to exist. Nothing can make it go away, its price will never increase. One datasets available at a given time Datasets are rectangular Functions are proprietary Experience is passive-you choose an analysis and they give you everything they think you need Tend to be have limited scope, forcing you to learn additional programs; extra options cost more and/or require you to learn a different language (e.g., SPSS Macros) They cost money. There is no guarantee they will continue to exist, but if they do, you can bet that their prices will always increase

ตัวอย่างประเภทข้อมูลและการเขียนคำสั่งใน R >Variables > a = 49 > sqrt(a) [1] 7 > a = "The dog ate my homework" > sub("dog","cat",a) [1] "The cat ate my homework“ > a = (1+1==3) > a [1] FALSE numeric character string logical

เวกเตอร์ > a = c(7,5,1) > a[2] [1] 5 ลิสต์: an ordered collection of data of arbitrary types. > doe = list(name="john",age=28,married=F) > doe$name [1] "john“ > doe$age [1] 28

Data frames data frame: is supposed to represent the typical data table that researchers come up with – like a spreadsheet. It is a rectangular table with rows and columns; data within each column has the same type (e.g. number, text, logical), but different columns may have different types. Example: localisation tumorsize progress XX348 proximal 6.3 FALSE XX234 distal 8.0 TRUE XX987 proximal 10.0 FALSE

R as a simple calculator > x<-c(1,3,2,10,5); y<-1:5 # creation of 2 vectors x [1]  1  3  2 10 5 > x+y [1]  2  5  5 14 10 > x*y [1]  1  6  6 40 25 > x/y [1] 1.0000000 1.5000000 0.6666667 2.5000000 1.0000000 > x^y [1]     1     9     8 10000  3125 > sum(x)            #sum of elements in x [1] 21 > cumsum(x)         #cumulative sum vector [1]  1  4  6 16 21

Basic math/stat tools # 20 numbers from 0 to 20, > x = round(runif(20,0,20), digits=1) > x [1] 10.0 1.6 2.5 15.2 3.1 12.6 19.4 6.1 [9] 9.2 10.9 9.5 14.1 14.3 14.3 12.8 [16] 15.9 0.1 13.1 8.5 8.7 > min(x) [1] 0.1 > max(x) [1] 19.4 > median(x) # médiane [1] 10.45 > mean(x) # moyenne [1] 10.095 > var(x) # variance [1] 27.43734 > sd(x) # standard deviation [1] 5.238067 > sqrt(var(x)) > length(x) [1] 20 > round(x) [1] 10 2 2 15 3 13 19 6 9 11 10 14 14 14 13 16 0 13 8 9 > cor(x,sin(x/20)) # corrélation [1] 0.997286 > quantile(x) # les quantiles, 0% 25% 50% 75% 100% 0.10 7.90 10.45 14.15 19.40

Statistical tools Samples tests Checking normality Kolmogorov-Smirnov test > #generate 500 observations from uniform (0,1) distribution > F500<-runif(500);a<-c(mean(F500),sd(F500)) > qqnorm(F500)    #normal probability plot > qqline(F500)    #ideal sample will fall near the straight line >ks.test(F500, "pnorm", mean=a[1], sd=a[2])         One-sample Kolmogorov-Smirnov test data:  F500 D = 0.0655, p-value = 0.02742 alternative hypothesis: two.sided