R统计软件使用方法课件

上传人:20****08 文档编号:242760468 上传时间:2024-09-02 格式:PPTX 页数:50 大小:3.41MB
返回 下载 相关 举报
R统计软件使用方法课件_第1页
第1页 / 共50页
R统计软件使用方法课件_第2页
第2页 / 共50页
R统计软件使用方法课件_第3页
第3页 / 共50页
点击查看更多>>
资源描述
单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,#,Main Topics Today,What is R?,How to administrate R?,How does R work?,How to apply R for statistical problem?,How to program your R function?,Main Topics Today What is R?,1,What is R?,A brief history of R,What is R?A brief history of R,2,The legend of R,R started in the early 1990s as a project by,Ross Ihaka,and,Robert Gentleman,at the University of Auckland, New Zealand, intended to provide a,statistical environment,in their teaching lab. The lab had Macintosh computers, for which no suitable commercial environment was available.,Robert Gentleman,Ross Ihaka,The legend of RR started in th,3,Rs Parents(1),The S language,S: an,interactive environment,for data analysis developed at,Bell Laboratories,since 1976,Exclusively licensed by,AT&T/Lucent,to,Insightful Corporation, Seattle WA. Product name: “S-plus”.,You can learn more from:,http:/cm.bell- father is S, mother is Scheme, but why my name is “R”?,Rs Parents(1)The S languageYo,4,The Scheme language,Scheme is a statically scoped and properly tail-recursive dialect of the Lisp programming language invented by Guy Lewis Steele Jr. and Gerald Jay Sussman.,Learn more:,http:/swiss.csail.mit.edu/projects/scheme/,S,chemes underlying semantics +,S,syntax = R,Rs Parents(2),“ We have named our language R in part to acknowledge the,influence of,S,and in part to celebrate our own efforts.”,-,R,. Ihaka,R,. Gentleman,- Ihaka R. & Gentleman R., 1996,The Scheme languageRs Parents,5,R Now,Since mid-1997 there has been a core group who can modify the R source code CVS archive.,The R package system,CRAN (the Comprehensive,R Archive Network ),http:/www.r-project.org,R NowSince mid-1997 there has,6,The characters of R,R is “GNU S” A language and environment for data manipula-tion, calculation and graphical display.,That is R is a,Free Software,(or,Open source,software),.,(Here,Free,refers to freedom, not price, although R is free in that sense as well.),The core of R is an interpreted computer language.,A,mosaic,of procedure-based programming and object-oriented programming,Good,interface,to procedures written in C, C+, FORTRAN and other languages,A flexible,data exchange,mechanism accessing,relational databases -ODBC,PostgreSQL, MySQL and so on.,小偷与强盗的谈判,The characters of RR is “GNU S,7,R and Statistics,Most packages deal with statistics and data analysis.,Powerful statistical graphics.,Well crosstalking with other statistical softwares.,Most R user are statistical experts. You can learn more modern analysis method from they by email.,You can do it when you come across a thing no body do it before.,R and StatisticsMost packages,8,Install and administrate R,Focus on Windows(MS),Install and administrate R Foc,9,How do I get R?,The informational web site,http:/www.r-project.org/,CRAN - the Comprehensive R Archive Network.,The primary site is,http:/cran.r-project.org/,.Mirror sites are available for many countries.,CRAN sites have binary distributions for Windows 95, 98, ME, NT4, 2000 and XP on Intel, for the Macintosh (System 8.6 to 9.1 and MacOS X), and for several Linux distributions.,New releases occur frequently,about every 3 months.,Be prepared to re-install,frequently.,Also you can get it,from your friends,teachers, etc.,Down it!,It is about 20.6M in size.,Using Precompiled,Binary Distributions,How do I get R?Down it!Using P,10,Installing R,Double click “,rw1091.exe” using your mouse. That is OK. You can install it as all other standard MS softwares.,Installing RDouble click “rw10,11,R Console/RGui in Windows(MS),Command box,Graphics box,Menu,Icons,R Console/RGui in Windows(MS)C,12,Several concepts in Administrating R,Workspace,xxx.RData,History,xxx.Rhistory,Package,Object,Session,Console,Run your R codes,Load/save workspace,Load/save History,Change your working directory,- Ihaka R. & Gentleman R., 1996,Several concepts in Administra,13,Add a new package,Commands:,library(),add a package in the library,detach(package : xxx),detach a package,All can do in the GUI (,except detach(),),Load a local package,Install packages from,internet or local,Update the local package from internet,Add a new packageCommands:Load,14,Packages in R Environment,Basic,packages,package:methods package:stats package:graphics“ package:utils package:base,Recommanded,packages,grid; lattice;e1071,Contributed,packages,(more than 366 packages nowadays),You can see what packages,loaded now by the command,search(),.,Packages in R EnvironmentBasic,15,Dont lose your way!,Three useful system command,getwd(),Get Working Directory,setwd(),Set Working Directory,list.files(),List the Files in a Directory/Folder,Dont lose your way!Three usef,16,Show the Demonstrations of the Packages/Functions,Commands,demo(),Demonstrations of R Functionality,example(),Run an Examples Section from the Online Help,Show the Demonstrations of the,17,Getting Helps,Several commands,help.start(),help() or ?(),help.search(),apropos(),Internet searching,I like it very,much. It seems,omnipotence.,Getting HelpsSeveral commands,18,Quit R,Command,q(),Terminate an R Session,Quit RCommand,19,How does R work?,Basic R Structure and data manipulation,How does R work?Basic R Struct,20,Basic R working flow(Object orientation),package,- R for Beginners.,Emmanuel Paradis,Basic R working flow(Object or,21,Object orientation,Object: a collection of atomic variables and/or other objects that belong together,Parlance:,class,: the “abstract” definition of it,object,: a concrete instance,method,: other word for function,slot,: a component of an object,Object orientationObject: a co,22,Types of Data in R,The basic data object is a,vector,of elements of type:,numeric,numbers - either floating point or integer,character,each element is a character string,logical,each element is,TRUE,or,FALSE,list,elements can be any type of object, including other lists,Components of the,S,language, such as functions, are also vectors.,Any vector can include the missing data marker,NA,as an element.,All vectors have a,length,and a,mode,. The functions,length,and,mode,return this information as does the,str,function.,A,structure,consists of a data object plus additional information. Matrices (or arrays, in general) and time series are examples of structures.,Types of Data in RThe basic d,23,Operators,Operators,24,Vectors, Matrices and Arrays,Command:,array(data = NA, dim = length(data), dimnames = NULL),matrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL),Vectors, Matrices and ArraysCo,25,Lists,List,vs.,Vector,list:,an ordered collection of data of arbitrary types.,vector:,an ordered collection of data of the same type.,Typically, vector elements are accessed by their index (an integer), list elements by their name (a character string). But both types support both access methods.,ListsList vs. Vector,26,Factors,Factors: classification variables,If the levels of a factor are numeric (e.g. the treatments are labelled“1”, “2”, and “3”) it is important to ensure that the data are ctually,stored as a factor and not as numeric data. Always check this by using summary.,FactorsFactors: classification,27,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. ( A,list,actually),Data framesdata frame: is supp,28,Subsetting,Individual elements of a vector, matrix, array or data frame are accessed with “, ,” by specifying their index, or their name,Subsetting Individual elem,29,Using R on Windows(MS),Basic statistical analysis by R,Using R on Windows(MS)Basic st,30,Data Input,From the keyboard one by one,c( ),;,scan( ),From the file,read.table(),; read.csv();,read.csv2();,read.dta(); read.spss();,By a spreadsheet,data.entry(),edit(),fix(),Data InputFrom the keyboard on,31,Data Edit,Commands,edit(),fix(),Tips:,edit(),can invoke,an notepad in the RGui!,Data EditCommandsTips: edit(),32,Data Discription,Commands,summary(),mean(),sd(),hist(),boxplot(),Data DiscriptionCommands,33,Probability Distribution,Probability Distribution,34,Three useful prefix in Probability Distribution Function,dxxx,for the density,pxxx,for the CDF,qxxx,for the quantile function,rxxx,for the simulation(random deviates),They are different!,The seed is set by,the system.,You can set seed yourself,by,set.seed().,Three useful prefix in Probabi,35,Statistical Inference,Commands,qxxx (),for the quantile function,t.test(),wilcox.test(stats),kruskal.test(stats),var.test();,shapiro.test();,qqnorm();,qqline(),-,Statistical InferenceCommands,36,Analysis of variance and Regression Analysis,Commands,anova(),lm(),Analysis of variance and Regre,37,Experiment Design,Commands,sample(),power.t.test(),Experiment DesignCommands,38,Save Object/Data,Every R object can be stored into and restored from a file with the commands “save” and “load”., save(x, file=“x.Rdata”), load(“x.Rdata”),Importing and exporting data,with rectangular tables in the form of tab-delimited text files., write.table(x, file=“x.txt”, sep=“t”),Save Object/DataEvery R object,39,Graphics with R,Graphics with R,40,A Friendly R Environment - Rcmdr,If you dont like a command line environment, package,Rcmdr,may be a good choice!,A Friendly R Environment - Rc,41,R programming (.R),Program your R code own,R programming (.R)Program your,42,Control Flow,if(cond) expr,if(cond) cons.expr else alt.expr,for(var in seq) expr,while(cond) expr,repeat expr,break,next,Control Flow if(cond) expr,43,Loops,The main loop construct in,R,is,for,. The commonest use, as in C and other languages, is to count from 1 to,n,.,for (i in 1:n) ,# do something,LoopsThe main loop construct i,44,Leaving loops,The,break,and,next,commands allow the flow of a loop to be altered,break,jumps out the loop,next,jumps to the next iteration of the loop,Leaving loopsThe break and nex,45,Avoiding Iteration,The canonical bad,R,program looks like this,#,multiply two vectors,for(i in 1:n) ,di - ai * bi,#compute the inner product,s - 0,for (i in 1:n),s - s + di,The right way to do this is,s-sum(a*b),apply(); lapply(); sapply(),Avoiding IterationThe canonica,46,Write R function,A function definition looks like,median - function(x, na.rm = FALSE),lots of code.,# a return value,Write R functionA function de,47,More,Packages,Objects and methods,Debugging and optimisation,Connecting to other packages,Interface to other programme language or DataBase,R+? +R!,More PackagesR+? +R!,48,Some Resources,A Course,(The ppt is showed with R Development Core Group),http:/faculty.washington.edu/tlumley/Rcourse/,A Paper (,citing R in a publication,),Ihaka R. & Gentleman R. 1996. R: a language for data analysis and graphics.,Journal of Computational and Graphical Statistics,5: 299314.,Two URL,http:/www.r-project.org,http:/www.ats.ucla.edu/stat/,Several Books,Using R for Data Analysis and GraphicsAn Introduction.,J.H. Maindonald,An Introduction to R,. The R Development Core Team,simpleR Using R for Introductory Statistics,. John Verzani,R for Beginners.,Emmanuel Paradis,The R Reference Manual Base Package.,The R Development Core Team,Some ResourcesA Course (The pp,49,Acknowledge,PhD. Qi Liu Prof. Naiqing Zhao,Prof. Gang Pei Everyone Here,Prof. Yixue Li,Any Question?,AcknowledgePhD. Qi Liu Prof.,50,
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > PPT模板库


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!