SlideShare una empresa de Scribd logo
1 de 29
Descargar para leer sin conexión
introduction()
# Poetry is considered a form of literary art in which
# language is used for its aesthetic and evocative qualities. It
# contains multiple interpretations and therefore resonates
# differently in each reader.
#
# Code is the language used to communicate with computers. It has its
# own rules (syntax) and meaning (semantics). Like literature writers
# or poets, coders also have their own style that include - strategies
# for optimizing the code being read by a computer, and facilitating
# its understanding through visual organization and comments for other
# coders.
#
# Code can speak literature, logic, maths. It contains different
# layers of abstraction and it links them to the physical world of
# processors and memory chips. All these resources can contribute in
# expanding the boundaries of contemporary poetry by using code as a
# new language. Code to speak about life or death, love or hate. Code
# meant to be read, not run.
url("http://code-poems.com")
R version 2.15.2 (2012-10-26) -- "Trick or Treat"
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-w64-mingw32/x64 (64-bit)
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.
Natural language support but running in an English locale
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.
>
R version 2.15.2 (2012-10-26) -- "Trick or Treat"
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-w64-mingw32/x64 (64-bit)
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.
Natural language support but running in an English locale
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.
> print("Hello World")
[1] "Hello World"
>
Character vector of length 1 (mode
and type (typeof) comes with it)
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
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.
> print("Hello World")
[1] "Hello World"
> print
function (x, ...)
UseMethod("print")
<bytecode: 0x0000000010a7a2c8>
<environment: namespace:base>
>
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
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.
> print("Hello World")
[1] "Hello World"
> print
function (x, ...)
UseMethod("print")
<bytecode: 0x0000000010a7a2c8>
<environment: namespace:base>
>
This means that code
Is compiled, not interpreted
-- thus faster, but not for today…
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
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.
> print("Hello World")
[1] "Hello World"
> print
function (x, ...)
UseMethod("print")
<bytecode: 0x0000000010a7a2c8>
<environment: namespace:base>
>
Environment where it is
defined. Not for now…
> print("Hello World")
[1] "Hello World"
> print
function (x, ...)
UseMethod("print")
<bytecode: 0x0000000010a7a2c8>
<environment: namespace:base>
> formals("print")
$x
$...
> ?print
starting httpd help server ... done
>
Arglist, help also helps.
x is an input object.
print prints its argument and returns it invisibly (via invisible(x)).
It is a generic function which means that new printing methods can
be easily added for new classes.
> print("Hello World")
[1] "Hello World"
> print
function (x, ...)
UseMethod("print")
<bytecode: 0x0000000010a7a2c8>
<environment: namespace:base>
> formals("print")
$x
$...
> ?print
starting httpd help server ... done
>
print prints its argument and returns it invisibly (via invisible(x)).
It is a generic function which means that new printing methods can
be easily added for new classes.
Generic function.
summary(so_far)
# o R is interpreted language, but
# bite compiling is possible (see
# compiler package).
# o In the background, everything is
# about environments (which are
# similar to lists), but luckily, this
# is hidden from average user.
# o Everything is an object -- OO.
# o Objects come in classes.
# o Methods can be defined for objects.
> set.seed(1234)
> x <- runif(10)
> y <- 2 + 5 * x + rnorm(10)
> plot(x, y)
>
Random numbers are important.
r unif != run if, uniform
normal
Another generic function.
> set.seed(1234)
> x <- runif(10)
> y <- 2 + 5 * x + rnorm(10)
> plot(x, y)
> (n <- cor.test(x, y))
Pearson's product-moment correlation
data: x and y
t = 5.9327, df = 8, p-value = 0.0003487
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.6325328 0.9770136
sample estimates:
cor
0.9026646
>
Parenthesis: print in short.
> (n <- cor.test(x, y))
Pearson's product-moment correlation
data: x and y
t = 5.9327, df = 8, p-value = 0.0003487
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.6325328 0.9770136
sample estimates:
cor
0.9026646
> class(n)
[1] "htest"
>
> class(n)
[1] "htest"
> str(n)
List of 9
$ statistic : Named num 5.93
..- attr(*, "names")= chr "t"
$ parameter : Named int 8
..- attr(*, "names")= chr "df"
$ p.value : num 0.000349
$ estimate : Named num 0.903
..- attr(*, "names")= chr "cor"
$ null.value : Named num 0
..- attr(*, "names")= chr "correlation"
$ alternative: chr "two.sided"
$ method : chr "Pearson's product-moment correlation"
$ data.name : chr "x and y"
$ conf.int : atomic [1:2] 0.633 0.977
..- attr(*, "conf.level")= num 0.95
- attr(*, "class")= chr "htest"
>
It is a list, nothing more.
Attributes are important
Class is an attribute.
..- attr(*, "conf.level")= num 0.95
- attr(*, "class")= chr "htest"
> methods(class="htest")
[1] print.htest*
Non-visible functions are asterisked
>
..- attr(*, "conf.level")= num 0.95
- attr(*, "class")= chr "htest"
> methods(class="htest")
[1] print.htest*
Non-visible functions are asterisked
> print.htest
Error: object 'print.htest' not found
>
..- attr(*, "conf.level")= num 0.95
- attr(*, "class")= chr "htest"
> methods(class="htest")
[1] print.htest*
Non-visible functions are asterisked
> print.htest
Error: object 'print.htest' not found
> getAnywhere("print.htest")
A single object matching ‘print.htest’ was found
It was found in the following places
registered S3 method for print from namespace stats
namespace:stats
with value
function (x, digits = 4, quote = TRUE, prefix = "", ...)
{
cat("n")
Gimme that damn thing!
cat(strwrap(x$method, prefix = "t"), sep = "n")
cat("n")
cat("data: ", x$data.name, "n")
out <- character()
if (!is.null(x$statistic))
out <- c(out, paste(names(x$statistic), "=", format(round(x$statistic,
4))))
if (!is.null(x$parameter))
out <- c(out, paste(names(x$parameter), "=", format(round(x$parameter,
3))))
if (!is.null(x$p.value)) {
fp <- format.pval(x$p.value, digits = digits)
out <- c(out, paste("p-value", if (substr(fp, 1L, 1L) ==
"<") fp else paste("=", fp)))
}
cat(strwrap(paste(out, collapse = ", ")), sep = "n")
if (!is.null(x$alternative)) {
cat("alternative hypothesis: ")
if (!is.null(x$null.value)) {
if (length(x$null.value) == 1L) {
alt.char <- switch(x$alternative, two.sided = "not equal to",
less = "less than", greater = "greater than")
cat("true", names(x$null.value), "is", alt.char,
x$null.value, "n")
}
else {
cat(x$alternative, "nnull values:n")
print(x$null.value, ...)
}
}
else cat(x$alternative, "n")
}
if (!is.null(x$conf.int)) {
cat(format(100 * attr(x$conf.int, "conf.level")), "percent confidence interval:n",
format(c(x$conf.int[1L], x$conf.int[2L])), "n")
}
if (!is.null(x$estimate)) {
cat("sample estimates:n")
print(x$estimate, ...)
}
cat("n")
invisible(x)
}
<bytecode: 0x0000000010f7a3e0>
<environment: namespace:stats>
>
Return the value invisibly.
Defined in stats pkg.
> m <- lm(y ~ x)
>
lm linear regression
y ~ x formula, let’s get back to
this later
> m <- lm(y ~ x)
> m
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
1.740 4.857
>
lm linear regression
y ~ x formula, let’s get back to
this later
This makes life so much easier,
talk about it next year.
> m <- lm(y ~ x)
> m
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
1.740 4.857
> names(m)
[1] "coefficients" "residuals" "effects" "rank"
[5] "fitted.values" "assign" "qr" "df.residual"
[9] "xlevels" "call" "terms" "model"
>
lm linear regression
y ~ x formula, let’s get back to
this later
This makes life so much easier,
talk about it next year.
> print.lm
function (x, digits = max(3, getOption("digits") - 3), ...)
{
cat("nCall:n", paste(deparse(x$call), sep = "n", collapse = "n"),
"nn", sep = "")
if (length(coef(x))) {
cat("Coefficients:n")
print.default(format(coef(x), digits = digits), print.gap = 2,
quote = FALSE)
}
else cat("No coefficientsn")
cat("n")
invisible(x)
}
<bytecode: 0x0000000010542380>
<environment: namespace:stats>
>
> (s <- summary(m))
Call:
lm(formula = y ~ x)
Residuals:
Min 1Q Median 3Q Max
-0.7372 -0.4189 -0.2076 0.2832 1.2928
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.7401 0.4539 3.834 0.004990 **
x 4.8571 0.8187 5.933 0.000349 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.6751 on 8 degrees of freedom
Multiple R-squared: 0.8148, Adjusted R-squared: 0.7917
F-statistic: 35.2 on 1 and 8 DF, p-value: 0.0003487
>
> coef(m)
(Intercept) x
1.740131 4.857122
>
> coef(m)
(Intercept) x
1.740131 4.857122
> coef(s)
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.740131 0.4538773 3.833924 0.0049900329
x 4.857122 0.8186989 5.932733 0.0003486669
>
> coef(m)
(Intercept) x
1.740131 4.857122
> coef(s)
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.740131 0.4538773 3.833924 0.0049900329
x 4.857122 0.8186989 5.932733 0.0003486669
> class(s)
[1] "summary.lm"
>
> coef(m)
(Intercept) x
1.740131 4.857122
> coef(s)
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.740131 0.4538773 3.833924 0.0049900329
x 4.857122 0.8186989 5.932733 0.0003486669
> class(s)
[1] "summary.lm"
> getAnywhere("print.summary.lm")
A single object matching ‘print.summary.lm’ was found
It was found in the following places
registered S3 method for print from namespace stats
namespace:stats
with value
function (x, digits = max(3, getOption("digits") - 3), symbolic.cor =
x$symbolic.cor,
signif.stars = getOption("show.signif.stars"), ...)
{
cat("nCall:n", paste(deparse(x$call), sep = "n", collapse = "n"),
"nn", sep = "")
resid <- x$residuals
df <- x$df
rdf <- df[2L]
cat(if (!is.null(x$weights) && diff(range(x$weights)))
print(summay(presentation))
# o Print method is simplest.
# o It conveys meaning to user.
# o Results are usually structures in
# different ways,
# o need methods to access information:
> methods(class="lm")
[1] add1.lm* alias.lm* anova.lm
[4] case.names.lm* confint.lm* cooks.distance.lm*
[7] deviance.lm* dfbeta.lm* dfbetas.lm*
[10] drop1.lm* dummy.coef.lm* effects.lm*
[13] extractAIC.lm* family.lm* formula.lm*
[16] hatvalues.lm influence.lm* kappa.lm
[19] labels.lm* logLik.lm* model.frame.lm
[22] model.matrix.lm nobs.lm* plot.lm
[25] predict.lm print.lm proj.lm*
[28] qr.lm* residuals.lm rstandard.lm
[31] rstudent.lm simulate.lm* summary.lm
[34] variable.names.lm* vcov.lm*
> if (questions) {
+ answer(questions)
+ } else q("no")
# ERUG meeting -- December 11, 2012
# Poetry with R -- Dissecting the code
# P. Solymos

Más contenido relacionado

La actualidad más candente

Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with Statix
Eelco Visser
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
Rajiv Risi
 

La actualidad más candente (20)

Declare Your Language: Type Checking
Declare Your Language: Type CheckingDeclare Your Language: Type Checking
Declare Your Language: Type Checking
 
Declare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term RewritingDeclare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term Rewriting
 
Good Code
Good CodeGood Code
Good Code
 
Declare Your Language: Name Resolution
Declare Your Language: Name ResolutionDeclare Your Language: Name Resolution
Declare Your Language: Name Resolution
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
 
Compiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsCompiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type Constraints
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with Statix
 
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | Parsing
 
Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)
 
Graph Database Query Languages
Graph Database Query LanguagesGraph Database Query Languages
Graph Database Query Languages
 
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
 
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
 
Matlab and Python: Basic Operations
Matlab and Python: Basic OperationsMatlab and Python: Basic Operations
Matlab and Python: Basic Operations
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Advanced Python, Part 2
Advanced Python, Part 2Advanced Python, Part 2
Advanced Python, Part 2
 
Learn python - for beginners - part-2
Learn python - for beginners - part-2Learn python - for beginners - part-2
Learn python - for beginners - part-2
 
Lisp and prolog in artificial intelligence
Lisp and prolog in artificial intelligenceLisp and prolog in artificial intelligence
Lisp and prolog in artificial intelligence
 
Computation Chapter 4
Computation Chapter 4Computation Chapter 4
Computation Chapter 4
 
Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#
 

Destacado

Isec july2 h1_solymos
Isec july2 h1_solymosIsec july2 h1_solymos
Isec july2 h1_solymos
Peter Solymos
 
Kesebangunan
KesebangunanKesebangunan
Kesebangunan
novikaaaj
 
小さく始めて後で困らないためのVPCとChefを使ったAWS運用
小さく始めて後で困らないためのVPCとChefを使ったAWS運用小さく始めて後で困らないためのVPCとChefを使ったAWS運用
小さく始めて後で困らないためのVPCとChefを使ったAWS運用
Satoru Nakamura
 

Destacado (14)

BURN-Solymos-Adat-klonozas-2014-07-16
BURN-Solymos-Adat-klonozas-2014-07-16BURN-Solymos-Adat-klonozas-2014-07-16
BURN-Solymos-Adat-klonozas-2014-07-16
 
NACCB 2016 Madison WI
NACCB 2016 Madison WINACCB 2016 Madison WI
NACCB 2016 Madison WI
 
Viral - Viral Marketing - Buzz Marketing
Viral - Viral Marketing - Buzz MarketingViral - Viral Marketing - Buzz Marketing
Viral - Viral Marketing - Buzz Marketing
 
Isec july2 h1_solymos
Isec july2 h1_solymosIsec july2 h1_solymos
Isec july2 h1_solymos
 
Editoria di Print On Demand: studio di usabilità dell'interfaccia del sito we...
Editoria di Print On Demand: studio di usabilità dell'interfaccia del sito we...Editoria di Print On Demand: studio di usabilità dell'interfaccia del sito we...
Editoria di Print On Demand: studio di usabilità dell'interfaccia del sito we...
 
Complex models in ecology: challenges and solutions
Complex models in ecology: challenges and solutionsComplex models in ecology: challenges and solutions
Complex models in ecology: challenges and solutions
 
EASY WRITING MAGIC STEPS
EASY WRITING MAGIC STEPSEASY WRITING MAGIC STEPS
EASY WRITING MAGIC STEPS
 
How to deal with messy data?
How to deal with messy data?How to deal with messy data?
How to deal with messy data?
 
23 nisan
23 nisan23 nisan
23 nisan
 
Editoria di Print on Demand: studio di usabilità del sito web aziendale e str...
Editoria di Print on Demand: studio di usabilità del sito web aziendale e str...Editoria di Print on Demand: studio di usabilità del sito web aziendale e str...
Editoria di Print on Demand: studio di usabilità del sito web aziendale e str...
 
Parallel Computing with R
Parallel Computing with RParallel Computing with R
Parallel Computing with R
 
Kesebangunan
KesebangunanKesebangunan
Kesebangunan
 
Social Cooking Experimente
Social Cooking ExperimenteSocial Cooking Experimente
Social Cooking Experimente
 
小さく始めて後で困らないためのVPCとChefを使ったAWS運用
小さく始めて後で困らないためのVPCとChefを使ったAWS運用小さく始めて後で困らないためのVPCとChefを使ったAWS運用
小さく始めて後で困らないためのVPCとChefを使ったAWS運用
 

Similar a Poetry with R -- Dissecting the code

Ejercicios de estilo en la programación
Ejercicios de estilo en la programaciónEjercicios de estilo en la programación
Ejercicios de estilo en la programación
Software Guru
 
Workshop presentation hands on r programming
Workshop presentation hands on r programmingWorkshop presentation hands on r programming
Workshop presentation hands on r programming
Nimrita Koul
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
carliotwaycave
 

Similar a Poetry with R -- Dissecting the code (20)

R for Pythonistas (PyData NYC 2017)
R for Pythonistas (PyData NYC 2017)R for Pythonistas (PyData NYC 2017)
R for Pythonistas (PyData NYC 2017)
 
Ejercicios de estilo en la programación
Ejercicios de estilo en la programaciónEjercicios de estilo en la programación
Ejercicios de estilo en la programación
 
RDataMining slides-r-programming
RDataMining slides-r-programmingRDataMining slides-r-programming
RDataMining slides-r-programming
 
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 
R basics
R basicsR basics
R basics
 
R language introduction
R language introductionR language introduction
R language introduction
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
Effective Object Oriented Design in Cpp
Effective Object Oriented Design in CppEffective Object Oriented Design in Cpp
Effective Object Oriented Design in Cpp
 
Data analysis in R
Data analysis in RData analysis in R
Data analysis in R
 
Workshop presentation hands on r programming
Workshop presentation hands on r programmingWorkshop presentation hands on r programming
Workshop presentation hands on r programming
 
Anthony Starks - deck
Anthony Starks - deckAnthony Starks - deck
Anthony Starks - deck
 
Presentation R basic teaching module
Presentation R basic teaching modulePresentation R basic teaching module
Presentation R basic teaching module
 
2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors
 
Unit 3
Unit 3Unit 3
Unit 3
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Python for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comPython for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.com
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Poetry with R -- Dissecting the code

  • 1. introduction() # Poetry is considered a form of literary art in which # language is used for its aesthetic and evocative qualities. It # contains multiple interpretations and therefore resonates # differently in each reader. # # Code is the language used to communicate with computers. It has its # own rules (syntax) and meaning (semantics). Like literature writers # or poets, coders also have their own style that include - strategies # for optimizing the code being read by a computer, and facilitating # its understanding through visual organization and comments for other # coders. # # Code can speak literature, logic, maths. It contains different # layers of abstraction and it links them to the physical world of # processors and memory chips. All these resources can contribute in # expanding the boundaries of contemporary poetry by using code as a # new language. Code to speak about life or death, love or hate. Code # meant to be read, not run. url("http://code-poems.com")
  • 2. R version 2.15.2 (2012-10-26) -- "Trick or Treat" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-w64-mingw32/x64 (64-bit) 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. Natural language support but running in an English locale 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. >
  • 3. R version 2.15.2 (2012-10-26) -- "Trick or Treat" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-w64-mingw32/x64 (64-bit) 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. Natural language support but running in an English locale 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. > print("Hello World") [1] "Hello World" > Character vector of length 1 (mode and type (typeof) comes with it)
  • 4. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale 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. > print("Hello World") [1] "Hello World" > print function (x, ...) UseMethod("print") <bytecode: 0x0000000010a7a2c8> <environment: namespace:base> >
  • 5. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale 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. > print("Hello World") [1] "Hello World" > print function (x, ...) UseMethod("print") <bytecode: 0x0000000010a7a2c8> <environment: namespace:base> > This means that code Is compiled, not interpreted -- thus faster, but not for today…
  • 6. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale 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. > print("Hello World") [1] "Hello World" > print function (x, ...) UseMethod("print") <bytecode: 0x0000000010a7a2c8> <environment: namespace:base> > Environment where it is defined. Not for now…
  • 7. > print("Hello World") [1] "Hello World" > print function (x, ...) UseMethod("print") <bytecode: 0x0000000010a7a2c8> <environment: namespace:base> > formals("print") $x $... > ?print starting httpd help server ... done > Arglist, help also helps. x is an input object. print prints its argument and returns it invisibly (via invisible(x)). It is a generic function which means that new printing methods can be easily added for new classes.
  • 8. > print("Hello World") [1] "Hello World" > print function (x, ...) UseMethod("print") <bytecode: 0x0000000010a7a2c8> <environment: namespace:base> > formals("print") $x $... > ?print starting httpd help server ... done > print prints its argument and returns it invisibly (via invisible(x)). It is a generic function which means that new printing methods can be easily added for new classes. Generic function.
  • 9. summary(so_far) # o R is interpreted language, but # bite compiling is possible (see # compiler package). # o In the background, everything is # about environments (which are # similar to lists), but luckily, this # is hidden from average user. # o Everything is an object -- OO. # o Objects come in classes. # o Methods can be defined for objects.
  • 10. > set.seed(1234) > x <- runif(10) > y <- 2 + 5 * x + rnorm(10) > plot(x, y) > Random numbers are important. r unif != run if, uniform normal Another generic function.
  • 11. > set.seed(1234) > x <- runif(10) > y <- 2 + 5 * x + rnorm(10) > plot(x, y) > (n <- cor.test(x, y)) Pearson's product-moment correlation data: x and y t = 5.9327, df = 8, p-value = 0.0003487 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.6325328 0.9770136 sample estimates: cor 0.9026646 > Parenthesis: print in short.
  • 12. > (n <- cor.test(x, y)) Pearson's product-moment correlation data: x and y t = 5.9327, df = 8, p-value = 0.0003487 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.6325328 0.9770136 sample estimates: cor 0.9026646 > class(n) [1] "htest" >
  • 13. > class(n) [1] "htest" > str(n) List of 9 $ statistic : Named num 5.93 ..- attr(*, "names")= chr "t" $ parameter : Named int 8 ..- attr(*, "names")= chr "df" $ p.value : num 0.000349 $ estimate : Named num 0.903 ..- attr(*, "names")= chr "cor" $ null.value : Named num 0 ..- attr(*, "names")= chr "correlation" $ alternative: chr "two.sided" $ method : chr "Pearson's product-moment correlation" $ data.name : chr "x and y" $ conf.int : atomic [1:2] 0.633 0.977 ..- attr(*, "conf.level")= num 0.95 - attr(*, "class")= chr "htest" > It is a list, nothing more. Attributes are important Class is an attribute.
  • 14. ..- attr(*, "conf.level")= num 0.95 - attr(*, "class")= chr "htest" > methods(class="htest") [1] print.htest* Non-visible functions are asterisked >
  • 15. ..- attr(*, "conf.level")= num 0.95 - attr(*, "class")= chr "htest" > methods(class="htest") [1] print.htest* Non-visible functions are asterisked > print.htest Error: object 'print.htest' not found >
  • 16. ..- attr(*, "conf.level")= num 0.95 - attr(*, "class")= chr "htest" > methods(class="htest") [1] print.htest* Non-visible functions are asterisked > print.htest Error: object 'print.htest' not found > getAnywhere("print.htest") A single object matching ‘print.htest’ was found It was found in the following places registered S3 method for print from namespace stats namespace:stats with value function (x, digits = 4, quote = TRUE, prefix = "", ...) { cat("n") Gimme that damn thing!
  • 17. cat(strwrap(x$method, prefix = "t"), sep = "n") cat("n") cat("data: ", x$data.name, "n") out <- character() if (!is.null(x$statistic)) out <- c(out, paste(names(x$statistic), "=", format(round(x$statistic, 4)))) if (!is.null(x$parameter)) out <- c(out, paste(names(x$parameter), "=", format(round(x$parameter, 3)))) if (!is.null(x$p.value)) { fp <- format.pval(x$p.value, digits = digits) out <- c(out, paste("p-value", if (substr(fp, 1L, 1L) == "<") fp else paste("=", fp))) } cat(strwrap(paste(out, collapse = ", ")), sep = "n") if (!is.null(x$alternative)) { cat("alternative hypothesis: ") if (!is.null(x$null.value)) { if (length(x$null.value) == 1L) { alt.char <- switch(x$alternative, two.sided = "not equal to", less = "less than", greater = "greater than") cat("true", names(x$null.value), "is", alt.char, x$null.value, "n") } else { cat(x$alternative, "nnull values:n") print(x$null.value, ...) } } else cat(x$alternative, "n") }
  • 18. if (!is.null(x$conf.int)) { cat(format(100 * attr(x$conf.int, "conf.level")), "percent confidence interval:n", format(c(x$conf.int[1L], x$conf.int[2L])), "n") } if (!is.null(x$estimate)) { cat("sample estimates:n") print(x$estimate, ...) } cat("n") invisible(x) } <bytecode: 0x0000000010f7a3e0> <environment: namespace:stats> > Return the value invisibly. Defined in stats pkg.
  • 19. > m <- lm(y ~ x) > lm linear regression y ~ x formula, let’s get back to this later
  • 20. > m <- lm(y ~ x) > m Call: lm(formula = y ~ x) Coefficients: (Intercept) x 1.740 4.857 > lm linear regression y ~ x formula, let’s get back to this later This makes life so much easier, talk about it next year.
  • 21. > m <- lm(y ~ x) > m Call: lm(formula = y ~ x) Coefficients: (Intercept) x 1.740 4.857 > names(m) [1] "coefficients" "residuals" "effects" "rank" [5] "fitted.values" "assign" "qr" "df.residual" [9] "xlevels" "call" "terms" "model" > lm linear regression y ~ x formula, let’s get back to this later This makes life so much easier, talk about it next year.
  • 22. > print.lm function (x, digits = max(3, getOption("digits") - 3), ...) { cat("nCall:n", paste(deparse(x$call), sep = "n", collapse = "n"), "nn", sep = "") if (length(coef(x))) { cat("Coefficients:n") print.default(format(coef(x), digits = digits), print.gap = 2, quote = FALSE) } else cat("No coefficientsn") cat("n") invisible(x) } <bytecode: 0x0000000010542380> <environment: namespace:stats> >
  • 23. > (s <- summary(m)) Call: lm(formula = y ~ x) Residuals: Min 1Q Median 3Q Max -0.7372 -0.4189 -0.2076 0.2832 1.2928 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.7401 0.4539 3.834 0.004990 ** x 4.8571 0.8187 5.933 0.000349 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 0.6751 on 8 degrees of freedom Multiple R-squared: 0.8148, Adjusted R-squared: 0.7917 F-statistic: 35.2 on 1 and 8 DF, p-value: 0.0003487 >
  • 25. > coef(m) (Intercept) x 1.740131 4.857122 > coef(s) Estimate Std. Error t value Pr(>|t|) (Intercept) 1.740131 0.4538773 3.833924 0.0049900329 x 4.857122 0.8186989 5.932733 0.0003486669 >
  • 26. > coef(m) (Intercept) x 1.740131 4.857122 > coef(s) Estimate Std. Error t value Pr(>|t|) (Intercept) 1.740131 0.4538773 3.833924 0.0049900329 x 4.857122 0.8186989 5.932733 0.0003486669 > class(s) [1] "summary.lm" >
  • 27. > coef(m) (Intercept) x 1.740131 4.857122 > coef(s) Estimate Std. Error t value Pr(>|t|) (Intercept) 1.740131 0.4538773 3.833924 0.0049900329 x 4.857122 0.8186989 5.932733 0.0003486669 > class(s) [1] "summary.lm" > getAnywhere("print.summary.lm") A single object matching ‘print.summary.lm’ was found It was found in the following places registered S3 method for print from namespace stats namespace:stats with value function (x, digits = max(3, getOption("digits") - 3), symbolic.cor = x$symbolic.cor, signif.stars = getOption("show.signif.stars"), ...) { cat("nCall:n", paste(deparse(x$call), sep = "n", collapse = "n"), "nn", sep = "") resid <- x$residuals df <- x$df rdf <- df[2L] cat(if (!is.null(x$weights) && diff(range(x$weights)))
  • 28. print(summay(presentation)) # o Print method is simplest. # o It conveys meaning to user. # o Results are usually structures in # different ways, # o need methods to access information: > methods(class="lm") [1] add1.lm* alias.lm* anova.lm [4] case.names.lm* confint.lm* cooks.distance.lm* [7] deviance.lm* dfbeta.lm* dfbetas.lm* [10] drop1.lm* dummy.coef.lm* effects.lm* [13] extractAIC.lm* family.lm* formula.lm* [16] hatvalues.lm influence.lm* kappa.lm [19] labels.lm* logLik.lm* model.frame.lm [22] model.matrix.lm nobs.lm* plot.lm [25] predict.lm print.lm proj.lm* [28] qr.lm* residuals.lm rstandard.lm [31] rstudent.lm simulate.lm* summary.lm [34] variable.names.lm* vcov.lm*
  • 29. > if (questions) { + answer(questions) + } else q("no") # ERUG meeting -- December 11, 2012 # Poetry with R -- Dissecting the code # P. Solymos