Homework4_R

A characteristic (or attribute or feature or property) of the units of observation can be measured and operationalized on different “levels”, on a given unit of observation, giving rise to possible different operative variables. Find out about the proposed classifications of variables and express your opinion about their respective usefulness

Level of measurement

Also called scale of measure is a classification that describes the nature of information within the values assigned to variables.
Stanley Smith Stevens developed the best-known classification with four levels, or scales, of measurement.

More in general, we have:

Qualitative/Categorical

  • Nominal: that cannot be put in any order
  • Ordinal: wich, even if they aren’t numbers, can be order and still does not allow for relative degree of difference between them

Quantitative/Numerical

  • Interval: the difference is meaningful(Numbers have order, like ordinal, but there are also equal intervals between adjacent categories)
  • Ratio: Differences are meaningful(Linke interval) but there is also a true zero point

Usefullness

While these levels are reasonable, they are not exhaustive. Other statisticians have proposed new typologies, but this seem the most used, because the extended levels of measurement are rarely used outside of academic geography.

We need to pay attention, cause can be that the same variable may be a different scale type depending on how it is measured and on the goals of the analysis:

Age usually is Ratio Data(Quantitaive), but in some case we can think to the age how Qualitative.

Example of advantage and disadvantage

Ordinal measurement is normally used for surveys and questionnaires. Statistical analysis is applied to the responses once they are collected to place the people who took the survey into the various categories. The data is then compared to draw inferences and conclusions about the whole surveyed population with regard to the specific variables. The advantage of using ordinal measurement is ease of collation and categorization. If you ask a survey question without providing the variables, the answers are likely to be so diverse they cannot be converted to statistics.

The same characteristics of ordinal measurement that create its advantages also create certain disadvantages. The responses are often so narrow in relation to the question that they create or magnify bias that is not factored into the survey. For example, on the question about satisfaction with the governor, people might be satisfied with his job performance but upset about a recent sex scandal. The survey question might lead respondents to state their dissatisfaction about the scandal, in spite of satisfaction with his job performance — but the statistical conclusion will not differentiate.

Statistics and geostatistics

https://petrowiki.org/Statistical_concepts

Sources:

https://en.wikipedia.org/wiki/Level_of_measurement

https://www.youtube.com/watch?v=KIBZUk39ncI

https://www.youtube.com/watch?v=eghn__C7JLQ

https://sciencing.com/advantages-disadvantages-using-ordinal-measurement-12043783.html

Homework2_RA

Note that any C# will have a Program.cs file in its solution folder while VB.NET does not. On the other hand, VB.NET has the file Application.Designer.vb within the project folder. Try to research what these (automatically created) files are doing in your application and try to discover / reverse engineer the differences on how a C# and VB.NET program are started.

Something about this files

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NameFile
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

A program need a main method to start execute.

The Windows Service project template generates a project that contains two files: the service1.cs file that contains the service implementation and the program.cs file that instantiates and essentially hosts the Windows service.

With Application.Run(new Form1()); Program.cs file start from form1.

https://docs.microsoft.com/en-us/previous-versions/dotnet/articles/bb332338(v=msdn.10)?redirectedfrom=MSDN#msdnwcfhc_topic4

Application.Designer.vb

Option Strict On
Option Explicit On


Namespace My

    Partial Friend Class MyApplication

        <Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
        Public Sub New()
            MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
            Me.IsSingleInstance = false
            Me.EnableVisualStyles = true
            Me.SaveMySettingsOnExit = true
            Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses
        End Sub

        <Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
        Protected Overrides Sub OnCreateMainForm()
            Me.MainForm = Global.Application1.Form1
        End Sub
    End Class
End Namespace

The Me identifier represents the instance of the current application. The OnCreateMainForm method establishes which window must be the startup one. In this case Form1 is the default name that Visual Studio assigns to the main window when a new project is created.

You might need to set custom actions for application events (such as Startup or Shutdown, which are usually handled in the ApplicationEvents.vb file) and Application.designer.vb is the right place.

https://www.informit.com/articles/article.aspx?p=1602817&seqNum=3

So

To start A C# program we use the Application.run().

In VB.Net we use the Global.Application1.FormToStart (the module also sets global variables)

Homework1_RA

Observe carefully the different way C# and VB.NET deals with events and the different ways to define the event handlers. Discuss in your blog what differences you can spot. Which way do you find easier or more comfortable and why?

VB.NET

Private Sub RichTextBox1_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragDrop
...
End Sub

We need to subscribe the handler to the event, which you can do adding a Handles clause to the method.

C#

private void Form1_Load(object sender, EventArgs e)
        {
           ...
            richTextBox1.DragDrop += new DragEventHandler(richTextBox1_DragDrop);
        }

In C# we need to create a delegate (pointer) to Handler and adding it to DragDrop list of “Event Handlers”.

You can think of a delegate as a pointer (or a reference) to a method. This is useful because the pointer can be passed around as a value.
The central concept of a delegate is its signature, or shape. That is the return type and the input arguments. For example, if we create a delegate void MyDelegate(object sender, EventArgs e), it can only point to methods which return void, and take an object and EventArgs. Kind of like a square hole and a square peg. So we say these methods have the same signature, or shape, as the delegate.

A good explanation here:

https://stackoverflow.com/questions/803242/understanding-events-and-event-handlers-in-c-sharp

Some difference:

https://stackoverflow.com/questions/38868304/vb-net-to-c-sharp-with-event-handlers

Conclusion

VB.NET allows you to declare and use events in a much simpler, cleaner way (the whole delegate thing is accomplished behind the scenes) while in C#, you have to type it out yourself.
However, in order to adhere to .NET conventions, you can declare your events in much the same way in VB.NET as you would in C#.

In my opinion, then, is more easier in VB.NET, but it’s more interesting in C# for understand how it works.

See also:

https://www.mobzystems.com/code/events-in-csharp-and-vbnet/

Homework 3_R

A frequency distribution

The frequency distribution of events is the number of times each event occourred in an experiment or study. There isn’t “best” number of bins, and different bin size can reveal different features of the data.

A frequency distribution provides a visual representation for the distribution observations within a particular test, with the goal to simplify the organization and presentation of data. Some of the graphs that can be used with frequency distributions are histograms, line charts, bar charts and pie charts. Frequency distributions are used for both qualitative and quantitative data.

Speaking of “univariate

Univariate is a term commoly used in statistics to descrive a type of data which consists of observations on only a single characteristic or attribute. So, in other words, the data has only one variable.

Information: From dataset to frequency distribution

A frequency distribution provides a snapshot view of the characteristics of a dataset. It paks information provided by dataset into ‘buckets’ or ranges, changing the amount of information that we can see.


Even if we gain knowlege, we lose information, so we can’t reconstruct a dataset given a distribution.

References:

Frequency distribution

Frequency distribution Wiki

Univariate

For further information

Homework 2_R

Variables and dataset

A variariable is an attribute that describes a person, place, thing or idea and its value can change from one entity to another.

Variables can be classified as:

  • Qualitative: Values that are names or labels
  • Quantitative: Numeric variables, that represent a mesaurable quantity

and also as:

  • Discrete: the set of values ​​it can take is finite or countable
  • Continuos: if the set of values ​​that it can assume is the set of real numbers or a range of real numbers

A dataset is a collection of data (information that are collected through observation of some object, called statistical unit).
A formal definition is: a dataset is a collection of rows or a collection of colums, where:

  • the rows represent all the attributes for one unit
  • the colums represent one attribute for all units

The values may be numbers or nominal data. More generally, values may be of any of the kinds described as a level of measurement.

Generation of a dataset

In statistics, datasets usually come from actual observations obtained by sampling a statistical population, and each row corresponds to the observations on one element of that poupolation.

Datasets may further be generated by algorithms for the purpose of testing certain kinds of software.

References:

Variables and attributes

Datasets

Homework 1_R

Statistical Population

A population is a set of similar items or events which is of interest for some question or experiment.

A group of existing objects or group of objects conceived as a generalization from experience are said Statistical Population.

Statistical Inference

Statistical inference is the process of using data analysis (a set of processes for modeling data with the goal of discovering useful information, providing conclusions and supporting decision-making) to deduce properties of an underlyning distribution of probability(matematical function that gives the probabilities of occurence of different possible outcomes for an experiment).

We need to define the population and then devise a sampling plan that produces a representative sample. The statistical results incorporate the uncertainty that is inherent in using a sample to understand an entire population.

Therefore, the population observed is represented by a subset of a popolation (a sample).

Descriptive Statistics

For descriptive statistics, we choose a group that we want to describe and then measure all subjects in that group. The statistical summary describes this group with complete certainty.

There is no uncertainty because you are describing only the people or items that you actually measure. You’re not trying to infer properties about a larger population.

In this case, the population isn’t a sample and the result rapresentation is limited of the observed group.

Summarize

Descriptive statistics: techniques used to summarize, organize and simplify data observed in interest population.

Inferential Statistics: techniques used to study samples and then make generalizations about the populations from wich they were selected.

References:

Statistical_population

Difference between descriptive and inferential statistics

Population in descriptive and in inferential

General description

Homework 3_A

Search on the web how to drag drop the name of any file into a richtextbox on your startup form and try to implement this feature in your first program.

VB.NET

For VB.NET I got information from:

https://stackoverflow.com/questions/11686631/drag-drop-and-get-file-path-in-vb-net
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        RichTextBox1.AllowDrop = True
    End Sub

    Private Sub RichTextBox1_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragDrop
        Dim files() As String = e.Data.GetData(DataFormats.FileDrop)
        Dim name As String = ""
        For Each path In files
            name = name & path
        Next
        Dim namePath As String = name.Substring(0, name.LastIndexOf("\"))
        Dim nameFile As String = name.Substring(name.LastIndexOf("\") + 1)
        RichTextBox1.Clear()
        RichTextBox1.AppendText("Path: " & namePath & Environment.NewLine & "Name File: " & nameFile)
    End Sub

    Private Sub RichTextBox1_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.Copy
        End If

    End Sub


End Class

C#

For C# I got information from:

https://social.msdn.microsoft.com/Forums/windows/en-US/3e3cf22c-f15c-4c60-b610-4be4edaf0ff5/dragging-a-file-into-a-richtextbox-want-only-the-path-to-the-file-not-the-file-iteself?forum=winforms

Moreover here I see how to read the contents of the file:

https://stackoverflow.com/questions/15333457/dragging-files-into-rich-textbox-to-read-text-in-file

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Application3_C
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            richTextBox1.AllowDrop = true;
            richTextBox1.DragDrop += new DragEventHandler(richTextBox1_DragDrop);
        }

  private void txtName_DragOver(object sender, DragEventArgs e)
  {
   e.Effect = DragDropEffects.Copy;
  }

        public void richTextBox1_DragDrop(object sender, DragEventArgs e)
        {
//First way with the parser
            if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
            {
                string[] FileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
                string s = "";
                richTextBox1.Clear();
                foreach (string File in FileList)
                {
                    s = s + " " + File;
                }
                string nameFile = s.Substring(s.LastIndexOf("\\") + 1);
                string pathFile = s.Substring(0, s.LastIndexOf("\\"));
                richTextBox1.AppendText("Path :" + pathFile + Environment.NewLine + "Name File: " + nameFile + Environment.NewLine);
            }
//Second way
            object filename = e.Data.GetData("FileDrop");

            if (filename != null)
            {
                var list = filename as string[];

                if (list != null && !string.IsNullOrWhiteSpace(list[0]))
                {
                    richTextBox1.AppendText("Path2: " + list[0]);
                 //   richTextBox1.LoadFile(list[0], RichTextBoxStreamType.PlainText); //For read the content
                }

            }


        }
    }
}

Homework 2_A

Create or search some simple but illuminating example of code which clearly shows the different behaviors of reference value data types and value type data types.

VB.NET

In VB.NET we can see the difference even just by applying the parameter ByVal or ByRef(we can see that the defaut is ‘ByValue’)

https://docs.microsoft.com/it-it/dotnet/visual-basic/programming-guide/language-features/procedures/passing-arguments-by-value-and-by-reference
Public Class Form1
    Private Sub BtnValue_Click(sender As Object, e As EventArgs) Handles BtnValue.Click
        'Value Tipe
        Dim valueV As Integer = 1
        Me.TxtValue.AppendText("Value before subroutine: " & valueV & Environment.NewLine)
        Increment_v(valueV)
        Me.TxtValue.AppendText("Value after subroutine: " & valueV & Environment.NewLine)

    End Sub

    Public Sub Increment_v(value As Integer)
        value = value + 1
        Me.TxtValue.AppendText("Value in subroutine: " & value & Environment.NewLine)
    End Sub

    Private Sub BtnRef_Click(sender As Object, e As EventArgs) Handles BtnRef.Click
        'Ref Type
        Dim valueR As Integer = 1
        Me.TxtRef.AppendText("Value before subroutine: " & valueR & Environment.NewLine)
        Increment_r(valueR)
        Me.TxtRef.AppendText("Value after subroutine: " & valueR & Environment.NewLine)

    End Sub

    Public Sub Increment_r(ByRef value As Integer)
        value = value + 1
        Me.TxtRef.AppendText("Value in subroutine: " & value & Environment.NewLine)
    End Sub

End Class

Another example in VB.NET, more interesting could be:

Public Class App2_VB
    Private Sub BtnExample_Click(sender As Object, e As EventArgs) Handles BtnExample.Click

        Dim a As Integer = 78
        Dim student1 As New Student
        student1.name = "Paperina"
        student1.age = 25

        Dim b As Integer = 11
        Dim student2 As New Student
        student2.name = "Pippo"
        student2.age = 23

        Me.TxtGeneral.AppendText("We have two objects Student:" & Environment.NewLine & "S1: " & student1.ToString &
                                 Environment.NewLine & "S2: " & student2.ToString & Environment.NewLine)

        Me.TxtGeneral.AppendText("And we have two values:" & Environment.NewLine & "a= " & a & " " & "b= " & b & Environment.NewLine)

        a = b

        student1 = student2

        Me.TxtGeneral.AppendText(Environment.NewLine & "*****************************************" & Environment.NewLine)

        Me.TxtGeneral.AppendText("Now i have assigned S1=S2 and a=b: " & Environment.NewLine & "S1: " & student1.ToString &
                                 Environment.NewLine & "S2: " & student2.ToString & Environment.NewLine & "And we have two values:" &
                                 Environment.NewLine & "a= " & a & " " & "b= " & b & Environment.NewLine)

        b = 100
        student2.name = "Valentino"
        student2.age = 46

        Me.TxtGeneral.AppendText(Environment.NewLine & "*****************************************" & Environment.NewLine)

        Me.TxtGeneral.AppendText("Now i have assigned a new value in S2 and b = 100: " & Environment.NewLine & "S1: " & student1.ToString &
                                 Environment.NewLine & "S2: " & student2.ToString & Environment.NewLine & "And we have two values:" &
                                 Environment.NewLine & "a= " & a & " " & "b= " & b & Environment.NewLine)


    End Sub
End Class
Public Class Student
    Public age As Integer
    Public name As String

    Public Overrides Function ToString() As String
        Return "Name: " & name & "-" & "Age: " & age
    End Function
End Class

We can see that when, in the end, I assign the value at ‘student2‘, change also ‘student1‘ because we have a pointer at the same object.
I got the idea for this code from this:

https://www.ict.social/vbnet/oop/reference-and-value-data-types-in-vbnet

C#

Also in C# we can pass a value with the keyword ref (See also: here), but I write only the second example in C#, cause the second is more funny.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Application2_C
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int a = 78;
            Student student1 = new Student 
            {
                name = "Paperina",
                age = 25
            };

            int b = 11;
            Student student2 = new Student
            {
                name = "Pippo",
                age = 23
            };

            this.TxtGeneral.AppendText("We have two objects Student:" + Environment.NewLine  + "S1: " + student1.ToString() +
                                     Environment.NewLine + "S2: " + student2.ToString() + Environment.NewLine);

            this.TxtGeneral.AppendText("And we have two values:" + Environment.NewLine + "a= " + a + " " + "b= " + b + Environment.NewLine);

            a = b;

            student1 = student2;

            this.TxtGeneral.AppendText(Environment.NewLine + "*****************************************" + Environment.NewLine);

            this.TxtGeneral.AppendText("Now i have assigned S1=S2 and a=b: " + Environment.NewLine + "S1: " + student1.ToString() +
                                     Environment.NewLine + "S2: " + student2.ToString() + Environment.NewLine + "And we have two values:" +
                                     Environment.NewLine + "a= " + a + " " + "b= " + b + Environment.NewLine);

            b = 100;
            student2.name = "Valentino";
            student2.age = 46;

            this.TxtGeneral.AppendText(Environment.NewLine + "*****************************************" + Environment.NewLine);

            this.TxtGeneral.AppendText("Now i have assigned a new value in S2 and b = 100: " + Environment.NewLine + "S1: " + student1.ToString() +
                                     Environment.NewLine + "S2: " + student2.ToString() + Environment.NewLine + "And we have two values:" +
                                     Environment.NewLine + "a= " + a + " " + "b= " + b + Environment.NewLine);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application2_C
{
    public class Student
    {
        public string name;
        public int age;

        public override string ToString()
        {
            return "Name: " + name + "-" + "Age: " + age;
        }
    }
}

Homework 1_A

Create, in both languages C# and VB.NET, a program which does the following simple tasks:

  • When a button is pressed some text appears in a richtexbox on the startup form
  • When another button is pressed the richtextbox is cleared
  • When the mouse enters the richtextbox, the richtext backcolor is switched to another color
  • When the mouse leaves the richtextbox, the richtext backcolor is reset to its original state

VB.NET

Public Class Form1
    Private Sub BtnAppears_Click(sender As Object, e As EventArgs) Handles BtnAppears.Click
        Me.TxtGeneral.AppendText("Some text appears" & Environment.NewLine)
    End Sub

    Private Sub BtnClear_Click(sender As Object, e As EventArgs) Handles BtnClear.Click
        Me.TxtGeneral.Clear()
    End Sub

    Private Sub TxtGeneral_MouseEnter(sender As Object, e As EventArgs) Handles TxtGeneral.MouseEnter
        Me.TxtGeneral.BackColor = Color.Blue
    End Sub

    Private Sub TxtGeneral_MouseLeave(sender As Object, e As EventArgs) Handles TxtGeneral.MouseLeave
        Me.TxtGeneral.BackColor = SystemColors.Window
    End Sub
End Class

C#

namespace Application1_C
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void BtnAppears_Click(object sender, EventArgs e)
        {
            this.TxtGeneral.AppendText("Some text appears" + Environment.NewLine);
        }

        private void BntClear_Click(object sender, EventArgs e)
        {
            this.TxtGeneral.ResetText();
        }

        private void TxtGeneral_MouseEnter(object sender, EventArgs e)
        {
            this.TxtGeneral.BackColor = Color.Red;
        }

        private void TxtGeneral_MouseLeave(object sender, EventArgs e)
        {
            this.TxtGeneral.BackColor = default(Color);
        }
    }
}