edoardo@home:~$

Statistics homework 1

Theory: Give your best description of the many reaching out of statistics, in its various form, as a branch of math (Probability theory, etc.), as a set of methodologies used in many other disciplines, as an essential tool to dela with any sort of data, make reports and provide governance tools. Discuss whether it can be considered a “science” and what is the “scientific method”. What is the role of Statistics in math and science?

Practice: Create - in both languages C# and VB.NET - a program which does the following simple tasks to get acquainted with the tool:

  • when a button is pressed some text appears in a richtexbox on the startup form
  • when another button is pressed animate one or more colored balls within a rectangle


Theory

What is statistics

As said in [1] statistics is the science concerned with developing and studying methods for collecting, analyzing, interpreting and presenting empirical data. I will say, in other words, that is a branch of mathematics that provides a set of formal methods used by other sciences to make more understandable raw data.

Statistics applications

Since statistics deals with uncertainty and variations and since it is critical to handle large amounts of data exist many fields of application of this discipline.

Economics and finance

Statistics is used in stock market, in fact all investments are done following a statistical study that helps to figure out when and where one can invest in order to gain profit. This approach is applied to the majority of financial investments that range from cryptocurrencies and football markets.

Politics

The political domain also uses the statistics, in particular during political campaigns is common between political parties to use statistics methods to figure out what say and to whom to gain majority among voters.

Computer science

Statistics is largely used in computer science since is common to work with a large amount of data that needs to be classified and described as happens in data science.

Medical

Never as much as this moment statistics has been applied for medical purposes in fact also without a pandemic is used to predict diseases and to analyze a certain diseases aspects among the infected.

Commerce

Statistics is used to study how to direct certain kind of advertisements to a certain piece of population and throughout what kind of communications media.

Type of data that statistics deals with

Statistics is largely used also because can handle a large amount of data types that can be divided into quantitative data that usually consist in mathematical measurements and nominal data (color, names).

Can statistics be a science?

To answer this question we have to take into account another question: is mathematics a science? This because statistics, as said before, is a branch of math and if math is a science every formal extension of this science will also be.

My personal opinion is that mathematics is more than a science, mathematics is the way we use to describe the world and is the tool that all sciences use to reach some kind of knowledge in their field of interest. Since statistics is a branch of math and uses it intensively as every other science i will say that statistics is a science.

This is confirmed in [2] where you can find a sort of scientific method that every statistical process follows:

  1. Planning the research
  2. Design of experiments
  3. Performing the experiment and analyzing the data following the experimental protocol
  4. Documenting and presenting the results of the study

In conclusion statistics has a fundamental role in science in general, in fact being a science itself, just like math, helps other sciences to create, analyze and describe data in their field of interest.

References

[1] https://www.stat.uci.edu/what-is-statistics/

[2] https://en.wikipedia.org/wiki/Statistics



Practice

For the practical application i structured the user interface as follows:

  • Table layout panel with 2 columns and 2 rows, that contains:
    • Rich textbox centered in row 1 column 1
    • Rich textbox’s button centered in row 2 column 1
    • Panel centered in row 1 column 2, that contains:
      • Rectangle shape
      • Circle shape
      • Timer
    • Panel’s button centered in row 2 column 2

Drawing rectangle

I changed the panel’s property BorderStyle to FixedSinge and clicked on panel to create this event function: private void panel1_Paint(object sender, PaintEventArgs e) inside of which i wrote these lines of code:

if (panel1.BorderStyle == BorderStyle.FixedSingle)
{
    int halfThickness = this.rectangleThickness / 2;
    using (Pen p = new Pen(Color.Black, this.rectangleThickness))
    {
        e.Graphics.DrawRectangle(p, new Rectangle(
                halfThickness,
                halfThickness,
                panel1.ClientSize.Width - this.rectangleThickness,
                panel1.ClientSize.Height - this.rectangleThickness
            )
        );
    }
} else
{
    this.rectangleThickness = 0;
}

where rectangleThickness is a property belonging to main Form class and describes as the name says the thickness of the rectangle’s borders.

Drawing circle within rectangle

Inside panel1_Paint event function after the code above i added these lines of code:

// filling circle of red
e.Graphics.FillEllipse(Brushes.Red,
    this.ballPosX + this.rectangleThickness, this.ballPosY + this.rectangleThickness,
    this.ballWidth, this.ballHeight
);

// drawing ball's border
e.Graphics.DrawEllipse(Pens.Black,
    this.ballPosX + this.rectangleThickness, this.ballPosY + this.rectangleThickness,
    this.ballWidth, this.ballHeight
);

Ball’s animation effect

I added ball state as Form class properties:

private int ballWidth = 20;
private int ballHeight = 20;
private int ballPosX = 0;
private int ballPosY = 0;
private int moveStepX = 2;
private int moveStepY = 2;

I added a move ball event on timer tick:

private void moveBall(object sender, EventArgs e)
{
    ballPosX += moveStepX;
    ballPosY += moveStepY;

    // checking overflow x
    if (ballPosX < 0 || ballPosX + ballWidth > this.panel1.ClientSize.Width - this.rectangleThickness * 2)
    {
        moveStepX = -moveStepX;
    }

    // checking overflow y
    if (ballPosY < 0 || ballPosY + ballHeight > this.panel1.ClientSize.Height - this.rectangleThickness * 2)
    {
        moveStepY = -moveStepY;
    }

    // updates painting
    this.Refresh();
}

I added start moving ball envent on button click:

private void button2_Click(object sender, EventArgs e)
{
    this.timer1.Enabled = true;
}

Final result

Project source code

Download project