Docsity

Appunti data analysis prof. Colleoni, Appunti di Analisi Dei Dati

Toggle sidebar
bg1
28/03/2025:
Inferential statistics: We use inferential statistics to make estimates and test
hypotheses about the whole population based on your sample data. For instance, if
you have a sample of IULM students, and you find that there is a relationship in YOUR
DATA between students’ grade performance and academic communication, you can
use inferential statistics to answer hypotheses that can be expended to the whole
population of students.
HYPOTHESIS TESTING: In order to “test hypothesis”, we start with two contrasting
propositions (each called a hypothesis) relating to the value of one or more population
parameters.
- H 0: Null hypothesis
- H 1: Alternative hypothesis
- Our goal is to determine which one is more likely to be true.
- The Null Hypothesis usually suggests that there is no significant difference
between two samples. The Alternative suggests the opposite - that there is an
effect, a significant difference between groups or samples.
- Through testing, we use sample data to figure out which hypothesis is more
likely to reflect reality.
Using sample data, we either:
-reject the null (H 0) and conclude the sample data provides sufficient
evidence to support H 1, or
-fail to reject the null (H 0) and conclude the sample data does not support H
1
A Legal Analogy for Hypothesis Testing
In the U.S. legal system, a defendant is innocent until proven guilty.
- H 0: Innocent
- H 1: Guilty
- If evidence (sample data) strongly indicates the defendant is guilty, then we
reject H 0.
- Note that we have not proven guilt or innocence
Determining the Proper Form of Hypotheses
Hypothesis testing always assumes that H 0 is true and uses sample data to determine
whether H 1 is more likely to be true.
Statistically, we cannot “prove” that H 0 is true; we can only fail to reject it.
Therefore, what we wish to provide evidence for statistically should be identified as
the alternative hypothesis
Rejecting or failing to reject the null
The decision to reject or fail to reject a null hypothesis is based on computing a test
statistic from the sample data. The value of the test statistic, t or z, is compared to a
“critical value” from the sampling distribution of the test statistic when the null
hypothesis is true and the chosen level of significance,
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22

Anteprima parziale del testo

Scarica Appunti data analysis prof. Colleoni e più Appunti in PDF di Analisi Dei Dati solo su Docsity!

Inferential statistics: We use inferential statistics to make estimates and test hypotheses about the whole population based on your sample data. For instance, if you have a sample of IULM students, and you find that there is a relationship in YOUR DATA between students’ grade performance and academic communication, you can use inferential statistics to answer hypotheses that can be expended to the whole population of students. HYPOTHESIS TESTING: In order to “test hypothesis”, we start with two contrasting propositions (each called a hypothesis) relating to the value of one or more population parameters.

- H 0: Null hypothesis

  • H 1: Alternative hypothesis
  • Our goal is to determine which one is more likely to be true.
  • The Null Hypothesis usually suggests that there is no significant difference between two samples. The Alternative suggests the opposite - that there is an effect, a significant difference between groups or samples.
  • Through testing, we use sample data to figure out which hypothesis is more likely to reflect reality. Using sample data, we either:
  • reject the null (H 0) and conclude the sample data provides sufficient evidence to support H 1, or
  • fail to reject the null (H 0) and conclude the sample data does not support H 1 A Legal Analogy for Hypothesis Testing In the U.S. legal system, a defendant is innocent until proven guilty.
  • H 0: Innocent
  • H 1: Guilty
  • If evidence (sample data) strongly indicates the defendant is guilty, then we reject H 0.
  • Note that we have not proven guilt or innocence Determining the Proper Form of Hypotheses Hypothesis testing always assumes that H 0 is true and uses sample data to determine whether H 1 is more likely to be true. Statistically, we cannot “prove” that H 0 is true; we can only fail to reject it. Therefore, what we wish to provide evidence for statistically should be identified as the alternative hypothesis Rejecting or failing to reject the null The decision to reject or fail to reject a null hypothesis is based on computing a test statistic from the sample data. The value of the test statistic, t or z, is compared to a “critical value” from the sampling distribution of the test statistic when the null hypothesis is true and the chosen level of significance, 

The critical value divides the sampling distribution into two parts, a rejection region and a non-rejection region. If the test statistic falls into the rejection region, we reject the null hypothesis; otherwise, we fail to reject it If p-value is smaller than 0.05, we are in the rejection region AND YOU REJECT THE NULL (H0) > IT’S STATISTICALLY SIGNIFICANT P-VALUE A p-value (observed significance level) is the probability of obtaining a test statistic value equal to or more extreme than that obtained from the sample data if the Null Hypothesis were true. If the P-value is low, it suggests that the observed data is unusual under the assumption of the Null Hypothesis. Typically, if this value is less than α, we reject the Null Hypothesis, accepting that our observed effect is statistically significant. Reject H0 if the p-value < α

  • α is the threshold at which we decide whether to reject the Null Hypothesis.
  • The levels for α are usually set at α= 0.05 or 0.1.
  • The smaller the value of your p-value compared to alpha, the less the probability of being wrong rejecting the null. TYPES OF BIVARIATE ANALYSIS Comparison of two nominal variables CHI SQUARE TEST: tells us if there is a statistically significant relation between variables Association between two nominal variables: Chi square test for association
  • A formal statistical test to determine whether results are statistically significant
  • It is used to discover if there is a relationship between two categorical variables
  • To be used if the sample is large enough (n> 100)
  • If the variables were not related what would the frequency distribution be in the crosstabulation?
  • We find the expected frequencies (iethose in which we assume that the relationship does not exist) and make a difference with the observed frequencies: If the difference is very large it means that the relationship exists
  • The expected frequencies are calculated by multiplying the marginal cells and dividing by the total. Example of our table. The expected frequency of "male not attending" is given by: EF= 554*493/965 = 283

P- VALUE: IF IT’S +1 > NO STATISTICAL ASSOCIATION

Cramer v is the measure of the potential of the strength of the association 17/04/ Types of bivariate analyses: continuous-continuous: CORRELATION: to what extent variables move together, it’s a positive or negative relationship Chi square with nominal and ordinal variables: most of cases

  • Correlation is a measure of the linear relationship between two variables, X and Y, which does not depend on the units of measurement.
  • We can determine whether one variable is related to another by seeing whether scores on the two variables covary---whether they vary together.
  • Correlation is measured by the correlation coefficient, also known as the Pearson product moment correlation coefficient.
  • It is calculated as:
  • Where the covariance is a measure of the linear association between two variables, X and Y. Like the variance, different formulas are used for populations and samples. The covariance between X and Yis the average of the product of the deviations of each pair of observations from their respective means.
  • The Pearson correlation coefficient is scaled between -1 and 1 EXAMPLE OF CORRELATION: Is there an association between:
  • Children’s IQ and Parents’ IQ?
  • Urban growth and air quality violations?
  • Number of police patrol and number of crimes
  • Grade on exam and time spent on studying the exam SCATTERPLOT The relationship between any two variables can be portrayed graphically on an x- and y- axis. Each subject i 1 has (x 1, y 1). When score s for an entire sample is plotted, the result is called scatter plot. Direction of the relationship : Variables can be positively or negatively correlated.
  • Positive correlation: A value of one variable increase, value of other variable increase.
  • Negative correlation: A value of one variable increase, value of other variable decrease. Strength of the relationship: The magnitude of correlation:
  • Indicated by its numerical value
  • ignoring the sign
  • expresses the strength of the linear relationship between the variables. Pearson’s correlation coefficient There are many kinds of correlation coefficients, but the most commonly used measure of correlation is the Pearson’s correlation coefficient. (r) - The Pearson r range between -1 to +1. - Sign indicate the direction. - The numerical value indicates the strength. - Perfect correlation : -1 or 1 - No correlation: 0 - A correlation of zero indicates the value are not linearly related. • However, it is possible they are related in curvilinear fashion. OUTLIERS Outliers are scores that are so obviously deviant from the remainder of the data. On-line outliers ---- artificially inflate the correlation coefficient. Off-line outliers --- artificially deflate the correlation coefficient ONLINE OUTLIER: An outlier which falls near where the regression line would normally fall would necessarily increase the size of the correlation coefficient, as seen below. OFFLINE OUTLIER: An outlier that falls some distance away from the original regression line would decrease the size of the correlation coefficient, as seen below Nominal-ordinal: phi coefficient Esame parziale: 3 domande con file Excel e word per scrivere le risposte con diverse analisi da fare, 3 domande in 75 minuti Nell’esame totale più domande di teoria anche sui questionari, no excel da fare ma interpretare risultati già dati TESTING FOR DIFFERENCES ACROSS GROUPS: Test between the means of different groups: When you want to know if there is a ‘statistical difference’ between the two groups in the mean Use “t-test”.

In this case reputation doesn’t significantly change ANOVA: we have more than two groups, it’s the analysis of variance. To compare the difference of averages among more than one group. Look at the p-value. If it’s < 0.05 there is a significant relation between the means. This example is not significant

Variables and distributions

1. Introduction (15 minutes) Briefly review the dataset and the types of variables. Please make sure you classify your variables properly, whether they are nominal, ordinal, or scale. Add this classification to the datamap.csv file. 2. Measures of Central Tendency (20 minutes)

Task 1: Calculate the mean for continuous variables 'Age' and '% of Exams Completed' using the =MEDIA function. Discuss the implications of the average age of the students and the average percentage of exams completed. Task 2: Find the median for ordinal variables 'Clear Instruction' and 'Course Understanding' with the =MEDIANA function. Reflect on what this tells us about the general perception of course clarity and understanding. Task 3: Determine the mode for the nominal variable 'Medium of Instruction' using the =MODA.UNO.SINGOLO function. Discuss how the most common medium of instruction might relate to students' learning preferences or institutional capabilities.

3. Measures of Dispersion (20 minutes) Task 4: Compute the range for the continuous variable 'Study Hours Per Week' using =MASSIMO and =MINIMO. What does the range reveal about students' study habits? Task 5: Calculate the standard deviation for 'Age' and 'Academic Performance' using =DEV. ST.S. Evaluate how varied the age and self-esteem levels are among students. Task 6: Use the =VAR.S function to find the variance for '% of Exams. Interpret the variance in the context of students' exam completion and self-reported wellbeing. 4. Skewness and Kurtosis (15 minutes) Task 7: Assess the skewness for 'Age' and 'Self-Esteem' with the =SKEW function. Does the data suggest a symmetry, or are there tendencies toward younger or older ages, and higher or lower self-esteem? What does this tell you? Task 8: Use the =KURT function to explore kurtosis for '% of Exams Completed'. Discuss how the results might indicate the presence of outliers and the peakedness of the data distribution. 5. Reflection and Analysis (15 minutes) Analyze the skewness and kurtosis findings in conjunction with the mean and standard deviation for 'Self-Esteem'. How might these statistics reflect on the student population's psychological disposition towards their academic environment? 6. For nominal and ordinal data (15 minutes): Task 10: Examine the frequencies for 'Gender' and 'Regular Feedback'. What do the modes of these variables suggest about the demographic composition of the sample and the feedback culture in the academic environment? 7. (Optional) Hands-on exercise: Compare variables with different distribution ranges: Sometimes you want to compare variables that have different distribution range because when comparing two variables with different values, it gets complicated, the interpretation is not straightforward. For example, you might be given two KPIs to monitor, one the satisfaction (measured on a scale of 1 to 5) and the other the willingness to buy again your product (measured on a scale of 1 to 6). In this case, you cannot directly compare them. To allow for comparisons, we normalized the two variables using a z-score. In the following, you are calculating Z-scores for 'Study Hours Per Week' and 'Perceived Academic Progress'

a.3 Configure Your PivotTable: In the "Create PivotTable" dialog box, Excel automatically

selects the data range based on where you clicked. Ensure the table/range includes your "Academic

Year" data. Choose where you want the PivotTable report to be placed. You can select a new

worksheet or an existing worksheet. For beginners, a new worksheet is often clearer.

a.4 Create the Frequency Distribution: Once the PivotTable is created, you'll see a "PivotTable

Fields" pane on the right side of the screen. Drag the "Academic Year" field to both the "Rows" area

and the "Values" area. By default, Excel might sum the data in the "Values" area. We need to change

this to count since we're interested in frequencies, not sums.

Click on the small dropdown arrow next to "Sum of Academic Year" (or similar text) in the

"Values" area. Choose "Value Field Settings" from the dropdown menu. In the dialog box that

opens, select "Count" and click "OK".

a.5 Analyze the Frequency Distribution: Your PivotTable now displays the frequency

distribution of "Academic Year". Each row represents an academic year present in your dataset, and

the corresponding column shows how many entries (or students) belong to that year.

Use this table to discuss the distribution of students across different academic years in the dataset.

Consider what this distribution might imply about the composition of your dataset or any trends in

enrollment or participation across years.

b. Create Pie and Bar Charts for 'Academic year' (Nominal)

b.1. Prepare the Frequency Distribution: First, create a frequency distribution of "Academic Year" as

detailed previously. You need to copy and paste the results into a new spreadsheet.

b.2 Select Your Data: Highlight the cells that contain the frequency distribution for "Academic

Year", including both the labels (academic years) and their corresponding frequencies. Do not

include the column headers in your selection.

b.3. Insert a Pie Chart: Go to the Ribbon, click on the "Insert" tab, then click on the "Pie Chart" icon

in the Charts group. Choose the first option (2-D Pie) for a basic pie chart.

b.4. Customize Your Pie Chart: Once the chart appears, you can customize it by adding a chart title,

data labels, and adjusting colors if desired.

c.2 Insert a Bar Chart: Go to the "Insert" tab on the Ribbon, then click on the "Bar Chart" icon in

the Charts group. Choose "Clustered Bar" for a basic bar chart.

c.3 Customize Your Bar Chart: Adjust the chart title, axis titles, and other formatting options to

improve readability. To add axis titles, click on the chart, then click the green "+" symbol. Check the

"Axis Titles" box, and then click on each title to customize the text. Adjust the bar colors by clicking

on the bars and selecting the "Format Data Series" option, where you can choose different fill colors.

c.4 Analyze the Chart: The bar chart provides a clear visual comparison of the frequencies across

different academic years. Discuss any trends or patterns observed, such as increases or decreases in

frequency over consecutive years.

c.5. Now that you created the bar chart, try to change the data representation of the axes from

horizontal to vertical.

2. Frequency Distribution and Visualization ordinal variables (15 minutes)

a. Creating a Horizontal Stacked Bar Chart for "Instruction Quality Clear"

a.1 Preparing Your Data: Frequency Distribution: First, you need to prepare a frequency distribution

for each response option (1 through 5) of the "Instruction Quality Clear" variable. This can be done

using a PivotTable.

a.2 Reorganize Data for Stacked Bar Chart: Once you have the frequency distribution, organize your

data in a table where each row represents a response option (1 to 5), and each column represents the

frequency count of responses for that option.

a.3 Creating the Stacked Bar Chart: Highlight the table you prepared, including both the labels (1 to

5) and their corresponding frequencies. Ensure to include the column labels for Excel to correctly

legend the chart.

Insert a Stacked Bar Chart: Go to the Ribbon, click on the "Insert" tab, then in the Charts group,

click on the "Bar Chart" icon. Choose the "Stacked Bar" option for a horizontal chart.

Customize the Chart: Once the chart appears, you can customize it for better clarity and

presentation. Add a Chart Title: Click on "Chart Title" and type a descriptive title, like "Distribution

of Instruction Quality Clear Ratings". Add Data Labels: For clarity on the exact count of responses

for each option, add data labels by clicking on the chart, then the green "+" symbol, and check "Data

Labels". You might need to format the data labels to ensure they're clearly readable. Adjust the

Legend: If the legend is not clear or incorrectly positioned, you can click and drag it to a more

suitable location or format it for better clarity.

a.4 Analyze the Chart: Use the stacked bar chart to discuss the distribution of ratings across the

Likert scale. This visual representation allows you to quickly see which response options were most

and least popular, and how responses distribute across the scale.

a.2 Deciding on Bin Widths:

Excel will automatically generate a histogram. To adjust the bin widths to your preference, click on

the histogram to bring up the "Histogram Format Axis" pane on the right.

Under the "Axis Options", you can adjust the "Bin Width" to the value you decided upon. If Excel

auto-selected bin ranges, you might want to switch to "By Category" for categorical or date data.

Adjust Bin Widths Manually:

If you’re not satisfied with the automatic bins, you can define your own bins in a separate column

before creating the histogram. List the lower bounds of each bin in a column, select this range along

with your data when inserting the histogram, and Excel will use these as the bin ranges.

(Not mandatory: Deciding on bin widths:

Rule of Thumb: A common rule of thumb is to use the square root of the number of data points as

the number of bins. However, this might not always provide the most insightful visualization.

Sturges’ Rule: Another method is Sturges' formula which suggests that the number of bins (k) can be

calculated as k =1+3.322log10( n ), where n is the number of data points. This can provide a starting

point, but you might need to adjust based on your data's specifics.

Custom Widths: Decide on bin widths based on key intervals that are meaningful for your analysis.

For example, if graduation years span several decades, you might choose bin widths that represent

each decade.)

a.3. Creating the Histogram

Using Excel’s Histogram Chart Feature: Select your data for the "Graduation_High_School"

variable. Go to the Ribbon, click on the "Insert" tab, and then in the Charts section, click on the

"Histogram" symbol.

a. 4. Analyzing and Refining Your Histogram

After creating the histogram, analyze the distribution of "Graduation_High_School" grade. Look for

any patterns, peaks, or gaps in the data and consider if adjusting the bin widths could highlight these

features more effectively.

4. Contingency tables

a. Creating a Contingency Table Between Education Level and Age group

a. 1 Regrouping Age into Age group:

Objective: Transform the "Age" column into a new "Age Group" column with the categories: "14-

High School", "19-22 Bachelor", and "23-24 Master".

Instructions:

Use the IF function in Excel to create a new column named "Age Group".

For each row, categorize the age into the corresponding group based on the criteria provided. Here’s

an example formula that could be used for the first row:

=IF(C2<=21;"18-21 Years Old"; IF(C2<=25;"22-25 Years Old"; "26+ Years Old"))

=SE(C2<=21,"18-21 Years Old", SE(C2<=25,"22-25 Years Old", "26+ Years Old"))

b. Creating a Contingency Table:

Objective: Use the categorized "Age Group" and "Education Level" to create a contingency table,

analyzing the distribution of education levels across different age groups.

b.1 PivotTable for Contingency Table: Select any cell within your dataset. Go to the "Insert" tab and

click on "PivotTable". In the "Create PivotTable" dialog box, select your dataset range and choose

where you want the PivotTable to be placed. In the PivotTable Field List, drag the "Age Group" field

to the Rows area. Drag the "Education Level" field to the Columns area. Drag the "Education Level"

(or any other relevant field) to the Values area and set it to count. Ensure your PivotTable reflects the

count of each education level within each age group category.

Copy and paste the table and finally go back to your codebook, change the labels of the variables to

be more explanatory (ie. The education level variable).

b. Creating a Box Plot for "Graduation_High_School" Grade by Gender

b.1 Prepare Your Data: Ensure your data is organized with at least two columns: one for

"Graduation_High_School" grades and another for "Gender". Each row should represent an

individual observation (ie. a student).

b.2. Create the Box Plot: If your data is not already in two separate columns for each gender, you

might need to rearrange it. For simplicity, assume you have one column for grades and one for

gender. You may need to create two separate data series if they are mixed in one column. Then

Insert a Box and Whisker Plot: Go to the "Insert" tab on the Ribbon. Click on the "Insert Statistic

Chart" button (or "Insert Other Chart" in some versions), then select "Box and Whisker". Adjust the

Data for the Chart: Excel will try to create the chart based on the data selected. If it does not

automatically format the data correctly: Right-click the chart and choose "Select Data". Use the

"Select Data Source" dialog to correctly assign the "Graduation_High_School" grades to the

appropriate gender categories. You might need to add each gender as a separate series if Excel hasn’t

automatically done so based on your data structure.

b. 3 Customize Your Box Plot: Edit Series Names: If you added each gender as a series, make sure

to name them correctly in the "Select Data Source" dialog for clarity. Format the Plot: You can

format the box plot for better visual appeal and clarity by right-clicking on elements of the chart

(e.g., boxes, whiskers) and selecting the "Format" option. Here, you can adjust colors, add data

labels, and make other stylistic changes.

b. 4 Analyze the Box Plot: Discuss the Distribution: of "Graduation_High_School" grades by

gender. Key points to consider:

 The median (the line in the middle of the box) indicates the middle value of the

grade distribution.

 The upper and lower quartiles (the top and bottom of the box) show the spread of the

middle half of the data.

 Whiskers extend to show the range of the data, while points outside of the whiskers

may indicate outliers.

 Comparing across genders, you should discuss any noticeable differences in median

grades, the spread of grades, or the presence of outliers.

Associations between nominal and ordinal

variables

How to enable add-ins

File  Options  Add-ins  Manage: Go  Flag “Analysis ToolPak” +

“Analysis ToolPak - VBA”

Part 1: Chi-Square and Phi for Dichotomous Variables

Objective:

Examine the relationship between "participation_study_groups" (binary: 1 =

yes, 0 = no) and " Utilization_Academic_Support" (binary: 1 = yes, 0 = no)

using a chi-square test and phi coefficient.

Task 1: Create a Contingency Table

Instructions:

Create a PivotTable with " Utilization_Academic_Support" as rows and

"participation_study_groups" as columns.

Use count of gender as the Values.

Ensure to place the PivotTable in a new worksheet for clarity.

Task 2: Chi-Square Test

Instructions:

Use Excel's CHISQ.TEST function to calculate the chi-square test

significance.

You will need to create two tables: the first one you created above, and

represents the observed values of the crossed variables.