Introduction
Presidency University
   October, 2024
Why should we learn to program?
    I   Independence: otherwise, you need to rely on others giving
        you exactly the right tool for your theory.
Why should we learn to program?
    I   Independence: otherwise, you need to rely on others giving
        you exactly the right tool for your theory.
    I   Honesty: otherwise, you end up distorting your problem to
        match the ready-made software you have.
Why should we learn to program?
    I   Independence: otherwise, you need to rely on others giving
        you exactly the right tool for your theory.
    I   Honesty: otherwise, you end up distorting your problem to
        match the ready-made software you have.
    I   Clarity: helps in visualizing or demonstrating concepts we
        usually learn in theory.
Why should we learn to program?
    I   Independence: otherwise, you need to rely on others giving
        you exactly the right tool for your theory.
    I   Honesty: otherwise, you end up distorting your problem to
        match the ready-made software you have.
    I   Clarity: helps in visualizing or demonstrating concepts we
        usually learn in theory.
    I   Fun: Coding can be a fun game (can be painstaking also !!!)
What we shall deal with?
    I   In this course we shall primarily deal with programming in
          I   R: free, open source statistical software which can be used as
              a calculator for simple calculations, analyzing data using
              statistical techniques, powerful tool for plotting and visualizing
              the data or as a programming language.
What we shall deal with?
    I   In this course we shall primarily deal with programming in
          I   R: free, open source statistical software which can be used as
              a calculator for simple calculations, analyzing data using
              statistical techniques, powerful tool for plotting and visualizing
              the data or as a programming language.
          I   Latex: free, open source programming language used for
              writing scientific articles, making presentations (or may be
              even preparing your bio-data !!!)
Open Source
    I   So we are mainly dealing with open source softwares in this
        course. What does “open source” mean?
Open Source
    I   So we are mainly dealing with open source softwares in this
        course. What does “open source” mean?
    I   The story begins in 1971 when Richard Stallman joined MIT’s
        Artificial Intelligence Lab. The environment at the AI Lab
        back then was supportive for collaboration and software
        development was a communal effort amongst colleagues.
Open Source
    I   So we are mainly dealing with open source softwares in this
        course. What does “open source” mean?
    I   The story begins in 1971 when Richard Stallman joined MIT’s
        Artificial Intelligence Lab. The environment at the AI Lab
        back then was supportive for collaboration and software
        development was a communal effort amongst colleagues.
    I   Unfortunately, during the early 80’s, manufacturers increasingly
        copyrighted their technologies, hide source code, and required
        licensed use of software. Stallman was not pleased.
        What does society need? It needs information that is
    truly available to its citizens—for example, programs that
    people can read, fix, adapt, and improve, not just
    operate. But what software owners typically deliver is a
    black box that we can’t study or change.
        Society also needs freedom. When a program has an
    owner, the users lose freedom to control part of their own
    lives.
        And, above all, society needs to encourage the spirit
    of voluntary cooperation in its citizens. When software
    owners tell us that helping our neighbors in a natural way
    is “piracy”, they pollute our society’s civic spirit.
        This is why we say that free software is a matter of
    freedom, not price.
— Richard Stallman (Ref: Why Software Should Not Have Owners)
I   In 1984, Stallman started the GNU Project as the key stepping
    stone to building a “free” software community.
    Software was meant to be “free,” not in terms of price, but
    in terms of accessibility. This mission began by creating a
    free operating system, entirely open to the community.
I   In 1984, Stallman started the GNU Project as the key stepping
    stone to building a “free” software community.
    Software was meant to be “free,” not in terms of price, but
    in terms of accessibility. This mission began by creating a
    free operating system, entirely open to the community.
I   In 1985, the Free Software Foundation was formed which
    states the four following rules to define whether a program is
    free software:
      I   Software is considered free if you, the user, has the freedom to:
            I   Run the program as you wish, for any purpose.
            I   Modify the program to suit your needs.
            I   Redistribute copies, either gratis or for a fee.
            I   Distribute modified versions of the program, so that the
                community can benefit from your improvements.
I   Stallman’s vision of a free operating system finally materialsed
    during early 1990s when the GNU Project eventually combined
    with Linux. Linux (or “GNU/Linux”) eventually became the OS
    with the largest installed base of all general-purpose operating
    systems.
I   Stallman’s vision of a free operating system finally materialsed
    during early 1990s when the GNU Project eventually combined
    with Linux. Linux (or “GNU/Linux”) eventually became the OS
    with the largest installed base of all general-purpose operating
    systems.
I   In 1998, Netscape decided to open source the code for
    Netscape Communicator as a result of which another
    web-browser Mozilla Fireox came up which later became one
    of the most popular browsers during 2000s.
I   Stallman’s vision of a free operating system finally materialsed
    during early 1990s when the GNU Project eventually combined
    with Linux. Linux (or “GNU/Linux”) eventually became the OS
    with the largest installed base of all general-purpose operating
    systems.
I   In 1998, Netscape decided to open source the code for
    Netscape Communicator as a result of which another
    web-browser Mozilla Fireox came up which later became one
    of the most popular browsers during 2000s.
I   Gradually open source softwares captured a significant share in
    the market and ppen source alternatives to proprietary
    software cropped up in all aspects of software.
Ref: “Open Source Software vs. Proprietary Software” by Singh,
Bansal, and Jha.
History of R
     I   (1993) Started as teaching tool by Robert Gentleman &
         Ross Ihaka at the Univesity of Auckland because S didn’t run
         on the Apple computers they had.
     I   (1995) Convinced by Martin Machler to release as Free
         Software.
     I   (2000) Version 1.0 released.
Download and Install R
    I   Type CRAN in Google. CRAN means The Comprehensive R
        Archieve Network.
    I   Visit their webpage and download the latest version of R
        suitable for your machine and operating system.
    I   Install R with the recommended settings.
Start R
   When you start R, something like the following should appear.
   This is the R prompt or the R console. You can type commands in
   this prompt and press        to run the commands.
Example: R as Calculator
   Let’s see what the following commands give:
   5+10
   [1] 15
   2*5
   [1] 10
   2/5
   [1] 0.4
Using R console
    I   No need to write the commands again and again.
    I   Press the    key to get the last command.
    I   Then we can manipulate the line by moving the cursor using
           and the    and with the              keys.
Alternative: Using Script Files
     I   A better way is to create R scripts which is a text file
         containing R commands.
     I   Script files are useful for the following reasons:
           I   submit many lines of commands to R at a single go.
           I   replay an analysis at a later date.
           I   Edit a line.
Creating a script file
   You can create R scripts by opening any text editor (e.g., notepad
   in Windows) and saving the file with extension .r , e.g. test.r
Creating a script file
   A better way (in windows) is to create the script file from R.
Creating a script file
   A typical script looks like this
Running Commands from script
   You can run a single line (on which the cursor is) or a selection (i.e.
   a chunk of code) at a time by selcting the line or chunk and then
   using CTRL+R or using menu button.
Commenting a code
  Look at the example script file
Commenting a code
    I   You can make any comment inside the code using #.
    I   R will realize any part (in a line) after # as comment and will
        not run it.
    I   Remember if your comment is in more than one line use # in
        every line.
    I   Commenting a code is very useful for future reference or for
        use of others.
How do we learn R?
Online Resources
    I   The official intro, "An Introduction to R", available online in
        HTML and PDF
    I   John Verzani, "simpleR", in PDF
    I   Google R Style Guide offers some rules for naming, spacing,
        etc., which are generally good ideas
    I   Quick-R.
    I   Patrick Burns, The R Inferno.
    I   Thomas Lumley, "R Fundamentals and Programming
        Techniques"
Help in R
   Also you should practice to use the help files in R.
Help in R
   Suppose we need to know how to find quotient in R.
   We do not know the exact name by which R identifies quotient.
   So type help.search(“quotient”) or its abbreviation ??quotient .
   This should list all the topics that involve quotient.
Help in R
   In this case it provides a link for arithmetic operators.
   Click on the link and study the help file.
Help in R
   Lets see how to find factorial of a number in R. Type ??factorial
   This will open a window.
   Clearly the link “Special Functions” may be useful. So click it.
Help in R
   If you know the name of the function then you can use ? instead of
   ?? .
   For example type ?log .
Online Help
   So far you need not to use any internet connection.
   But if you are still not satisfied you can google like this “ **** in
   R”.
   There are lots of help available online.
Online Help
   Another way is to visit the CRAN task views.
   It contains list of different packages useful for a particular topic,
   e.g. optimization.
   The Documentation link in CRAN is another source of help.
Online Help
   If you still do not find the answer to your query you should register
   in the R-forum with your mail.
   Most of your queries will be answered by other users within a day.
How to use Latex?
    I   Suppose we need to write the normal density as
                                1     1       2
                    fµ,σ (x) = √ e − 2σ2 (x−µ) , x ∈ R.
                              σ 2π
How to use Latex?
    I   Suppose we need to write the normal density as
                                     1     1       2
                         fµ,σ (x) = √ e − 2σ2 (x−µ) , x ∈ R.
                                   σ 2π
    I   The complete Latex code for this stuff is
        \documentclass[english]{article}
        \usepackage[T1]{fontenc}
        \usepackage[latin9]{inputenc}
        \usepackage{amssymb}
        \usepackage{babel}
        \begin{document}
        Suppose we need to write the normal density as
        \[
        f_{\mu,\sigma}(x)=\frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{1}{2\sigma^{2}}(x-\
        \]
        \end{document}
Learning Latex with Lyx
     I   How do we learn programming in Latex?
Learning Latex with Lyx
     I   How do we learn programming in Latex?
     I   An easy solution is to use the editor Lyx.
Learning Latex with Lyx
     I   How do we learn programming in Latex?
     I   An easy solution is to use the editor Lyx.
     I   There are other alternative editors for writing Latex codes like
         Kile, Texniccenter, Overleaf but Lyx is relatively easy to start
         with.
Why Lyx?
    I   Easy user interface: It depends on "What You See Is What
        You Get" structure and so there are different menu options
        available.
Why Lyx?
    I   Easy user interface: It depends on "What You See Is What
        You Get" structure and so there are different menu options
        available.
    I   Helps to learn Latex: Although there are menu options to
        insert symbols and formatting, Lyx shows the codes for all and
        these can also be implmeneted directly using Latex codes.
        Further Lyx gives the complete Latex code of document (or for
        the specific paragraph).
Why Lyx?
    I   Easy user interface: It depends on "What You See Is What
        You Get" structure and so there are different menu options
        available.
    I   Helps to learn Latex: Although there are menu options to
        insert symbols and formatting, Lyx shows the codes for all and
        these can also be implmeneted directly using Latex codes.
        Further Lyx gives the complete Latex code of document (or for
        the specific paragraph).
    I   Can be combined easily with R: Lyx can be connected easily
        with R, as a result of which R codes can be easily embedded
        and run in a document with the outputs in appropriate places.