Statistika: R

Z Wikiverzity

Statistika: R

S je statistika v Matlabu a R se má k S jako se má Octave k Matlabu.

Základní info[editovat]

R na projektech Wikimedia[editovat]

Další dokumentace[editovat]

Tutoriály aj.[editovat]

Česky[editovat]

Slovenčina[editovat]

Anglicky[editovat]

Online instalace[editovat]

Debianovské balíky[editovat]

  • Documentation:
    • r-doc-html – R manuals in html format
    • r-doc-info – manuals in info format. The sibling packages r-doc-html and r-doc-pdf provide the same manuals
    • r-doc-pdf – pdf manuals for statistical computing system
    • r-base-html – html documentation for the libraries included in the r-base package.
    • r-base-latex – latex documentation suitable for off-line printing for the libraries included in the r-base package.
  • Core:
    • r-base-core – the core GNU R system from which only the optional documentation packages r-base-html, r-base-latex, r-doc-html, r-doc-pdf and r-doc-info have been split off to somewhat reduce the size of this package.
  • Frontends:
    • littler – scripting and command-line front-end – a leighweight binary wrapper around the GNU R language
    • rkward – KDE frontend to the R statistics language, also provide seamless integration with an office-suite.
    • r-cran-zelig – a unified front-end for estimating statistical models
    • ess – Emacs statistics mode, supporting R,S and others
  • Interface to other soft:
    • r-cran-foreign – functions for reading and writing data stored by statistical packages such as Minitab, S, SAS, SPSS, Stata,
    • postgresql-7.4-plr – Procedural language interface between PostgreSQL 7.4 and R
    • postgresql-8.1-plr – Procedural language interface between PostgreSQL 8.1 and R
    • r-cran-rmpin – an interface to the MPI libraries (Message-Passing Interface) API for distributed computing
  • Routines:
    • r-cran-mcmcpack – routines for Markov chain Monte Carlo model estimation
    • r-noncran-lindsey – libraries contributed by Jim and Patrick Lindsey: linear and nonlinear modelling, statistical tests, time series analysis, classification, clustering, ...
    • r-cran-matchit – package of nonparametric matching methods
    • r-mathlib – libRmath shared and static libraries which can be called from standalone C or C++ code
    • r-cran-design – regression modeling strategies tools by Frank Harrell
    • r-cran-qtl – package for genetic marker linkage analysis
    • r-cran-eco – routines for Bayesian ecological inference
    • Cartographic packages:
      • r-cran-mapproj – support for cartographic projections of map data
      • r-cran-maps – support for producing geographic maps
      • r-cran-mapdata – support for producing geographic maps (supplemental data)
  • Other packages:
    • r-base – a meta-package which eases the transition from the pre-1.5.0 package setup with its larger r-base package. Once installed, it can be safely removed
    • r-other-gking-matchit – package of nonparametric matching methods (dummy package) This package has been renamed to "r-cran-matchit"
    • r-base-dev – installation of auxiliary GNU R packages
    • r-recommended – collection of recommended packages [metapackage]: This set comprises the following packages (listed in their upstream names):
 - KernSmooth: Functions for kernel smoothing for Wand & Jones (1995)
 - VR: The MASS, class, nnet and spatial packages from Venables and
   Ripley, `Modern Applied Statistics with S' (4th edition).
 - boot: Bootstrap R (S-Plus) Functions from the book "Bootstrap Methods
   and Their Applications" by A.C. Davison and D.V. Hinkley (1997).
 - codetools: Code analysis tools for R
 - cluster: Functions for clustering (by Rousseeuw et al.)
 - foreign: Read data stored by Minitab, S, SAS, SPSS, Stata, ...
 - lattice: Implementation of Trellis (R) graphics
 - mgcv: Multiple smoothing parameter estimation and GAMs by GCV
 - nlme: Linear and nonlinear mixed effects models
 - rpart: Recursive partitioning and regression trees
 - rcompgen: A command line completion generator for R
 - survival: Survival analysis, including penalised likelihood.

První pokus[editovat]

Předpokládáme, že nám dá někdo zpracovat data např. v excelové tabulce či jiné tabulce. Univerzálním způsobem výměny dat je export do textového souboru, buď csv (Comma separated values) či jinak oddělenými položkami, mezerami či tabelátory.

I když je soubor .xls, můžeme ho načíst např. OpenOffice.org/Calc a uložíme jej jako csv. Zvolíme "upravit nastavení filtru" a zvolíme např. oddělovač pole | (svislítko), oddělovač textu nic. dybychom nechali oddělovač polí čárku, mohli bychom mít problém např. s desetinnými čísly, která jsou v některých lokalizacích (čestina, němčina, ...) oddělena desetinnými čárkami.

Dejme tomu, že textový soubor s daty, oddělenými tabelátory, se jmenuje data.txt. Přejdeme do tohoto adresáře (příkazem cd adresář), abychom měli naše soubory po ruce, a spustíme programové prostředí jazyka R jednoduše příkazem velké R:

R

odpovědí nám bude uvítání a prompt:

R version 2.6.1 (2007-11-26)
Copyright (C) 2007 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> 

Prompt ("zobák", znaménko > "větší než) hlásí připravenost systému přijmout náš příkaz. U níže uvedených příkladů budeme tímto promptem signalizovat, že následuje příkaz (prompt samozřejmě nepíšeme).

Načteme naši tabulku např. do proměnné lidi:

> lidi <- read.table("data.csv")

Znaky <- znamenají přiřazení proměnné. Kdybychom si proměnnou nazvali data, byla by to chyba, protože to je už název nějaké funkce, proto jsme si ji nazvali např. "lidi". Možná dostaneme nějaké chybové hlášky, jako např.

Warning message:
In read.table("data.csv", sep = "|", header=TRUE, na.strings="--") :
  incomplete final line found by readTableHeader on 'data.csv'

První řádek tabulky často znamená nadpisy sloupců, což jsme řekli argumentem header=TRUE Při exportu z nějakého spreadsheetu zde můžou názvy sloupů obsahovat mezery, diakritiku či jiné znaky - proto si možná s textovým souborem budeme muset trochu pohrát, než se podaří nám jej správně načíst. Argumentem na.strings="--" jsem řekli, že prázdná pole, které se nám nepodařilo zaplnit daty, jsme označili dvěma pomlčkami (R si je potom označí písmeny NA = not available). V případě, že máme v tabulce pouze prázdná políčka, stačí uvést na.strings="". Příkazem

> lidi

vypíšeme pro kontrolu tabulku. Vypíšeme si seznam objektů, které máme na "pracovní ploše":

 > ls()
[1] "lidi"

Související články[editovat]