Professional Documents
Culture Documents
Project - Advanced Statistics - Final-1
Project - Advanced Statistics - Final-1
Problem 1:
1.1) State the Null and Alternate Hypothesis for conducting one-way ANOVA for both the
variables ‘A’ and ‘B’ individually.
Answer:
For Variable A:
Null Hypothesis (Ho): There is no difference in the ‘relief’ time means at the three levels of ‘A’
ingredient population
Alternate Hypothesis (H1): From the three levels of ‘A’ ingredient there is a difference in at least one of
the ‘relief’ means.
For Variable B:
Null Hypothesis (Ho): There is no difference in the ‘relief’ time means at the three levels of ‘B’
ingredient population
Alternate Hypothesis (H1): From the three levels of ‘B’ ingredient there is a difference in at least one of
the ‘relief’ means.
1.2) Perform one-way ANOVA for variable ‘A’ with respect to the variable ‘Relief’. State
whether the Null Hypothesis is accepted or rejected based on the ANOVA results.
Answer:
Assumption: Level Significance: 5%
Since the p value is less than the significance level, we can reject the null hypothesis and state that
there is a difference in means of ‘Relief’ among the three levels of ingredient ‘A’
1.3) Perform one-way ANOVA for variable ‘B’ with respect to the variable ‘Relief’. State
whether the Null Hypothesis is accepted or rejected based on the ANOVA results.
Answer:
Assumption: Level Significance: 5%
P-value: 0.00135
Since the p value is less than the significance level, we can reject the null hypothesis and state that
there is a difference in means of ‘Relief’ among the three levels of ingredient ‘B’
1.4) Analyse the effects of one variable on another with the help of an interaction plot.
What is an interaction between two treatments?
[hint: use the ‘pointplot’ function from the ‘seaborn’ function]
Answer:
Assumed, the question seeks to analyse the interaction of the level of ‘A’ & ‘B’ ingredients to the level
of ‘Relief’
Basis the pointplot it can be inferred that at low levels of ingredient A, the relief is lesser compared to
that B, whereas at high levels of ingredient A, the relief in hours is higher than that compared to B.
Alternate Hypothesis (H1): The ‘Relief’ time mean differs with the changes in the levels of ‘A’ & ‘B’
ingredients
Since the p value in all the above scenarios are less than the significant value 0.05, we can say that we
reject the null hypothesis and relief time does differ with changes in the levels of ‘A’ & ‘B’ ingredients
1.6) Mention the business implications of performing ANOVA for this particular case study.
Answer:
Basis the two-way ANOVA it can be inferred that changing the levels of ingredients ‘A’ and ‘B’ change
the ‘Relief’ time of the medicine. Both ‘A’ and ‘B’ at a medium level provide the same hours of relief.
However higher the level of ingredient A, higher is the relief time vis-à-vis ingredient B
Problem 2:
2.1) Perform Exploratory Data Analysis [both univariate and multivariate analysis to be
performed]. The inferences drawn from this should be properly documented.
Answer:
Univariate analysis refers to the analysis of a single variable. The main purpose of univariate analysis is
to summarize and find patterns in the data. The key point is that there is only one variable involved in
the analysis.
Let us take the 'Enroll' dataset and work on that for the univariate analysis.
Histogram Analysis:
Applications Received, Acceptances, Enroll, Full time Graduates, Part time Graduates : Bulk of
the observations are in the first bin
Cost of Books: The maximum frequency is within the cost of 750
The maximum frequency of Instructional Expenditure is within the cost of 10000
The maximum Graduation rates is between 60 to 70 %
The datsaset for Graduates shows data exceeding 100%, which indicates corrupt datapoints
that needs to be normalized.
Student Faculty Ratio is between 10 to 20
Terminal: Shows that the most of the faculty members have a Terminal degree
Room Boarding Charges shows 4000 as cost incurred by most students
Boxplot Analysis:
The IQR for dataset is 660, there are several outliers falling in excess of 2000 and above
enrolment.
Cumulative Distribution:
The ogive curve shows the Cumulative distribution, the slope of the distribution represents the
histogram, sharper the cumulative distribution more the number of datapoints. The above figure
shows a sharp rise in datapoints upto 1000 Enrolments.
Multivariate analysis is performed to understand interactions between different fields in the dataset (or)
finding interactions between variables more than 2
Shows a positive correlation between number of Enrolments and Full time graduates
The Correlation coefficient is 0.96
2.2) Scale the variables and write the inference for using the type of scaling function for
this case study.
Answer:
Using the variable ‘Enroll’ as an example:
Scaling convert variables with different scales of measurements into a single scale to allow
comparison.
Standard Scaler normalizes the data using the formula (x-mean)/standard deviation.
This scaling allows changing the selected variable and translates to the Z-score of the attribute and
represents the data in terms of number of Standard Deviations above or below the average.
count 7.770000e+02
mean -5.249269e-17
std 1.000644e+00
min -8.022728e-01
25% -5.793514e-01
50% -3.725836e-01
75% 1.314128e-01
max 6.043678e+00
Taking an example of scaling the variable ‘Enroll’, we can observe the following:
The minimum scale is -0.8022728463187818 and maximum is 6.043678173482203, this
means there are enrolments that are 1 standard deviation below the average number of
enrolments and there are enrolments that’s are 6 standard deviations above average.
The 5 point summary shows the mean is in fact zero (-5.249269e-17) , the standard deviation is
1
Alternative method of scaling: Percentile scaling: MinMaxScaler normalizes the data using the formula
(x - min)/(max - min)
count 777.000000
mean 0.117189
std 0.146166
min 0.000000
25% 0.032563
50% 0.062765
75% 0.136385
max 1.000000
Name: Enroll_MinMaxScale, dtype: float64
We observe the following:
The median is 0.062765 is much closer to the minimum (0) than the maximum (1) indicating a
skewness problem of data
Alternative method of scaling: Log Transformation is a method where data is extremely skewed and
has large values by effectively moving the decimals across all attributes
count 777.000000
mean 6.176126
std 0.951072
min 3.583519
25% 5.493061
50% 6.075346
75% 6.805723
max 8.762959
Name: Enroll_logtransform_logtransform, dtype: float64
We observe the following:
The mean is 6.17 is much closer to the maximum of 8.76 indicating a skewness problem of data
2.3) Comment on the comparison between covariance and the correlation matrix.
Answer:
To measure how one variable varies with respect to the variation of another variable, we compute Co-
variance. Taking a reference of the attributes, ‘Full time Graduates’ and ‘Students Enrolled’ we notice a
positive relationship of 4.347530e+06, which indicates that as Full time Graduates increase, the number
of Students enrolled also will increase. However, this number does not indicate how large the co-
variance number is. The co-variance between ‘Full time Graduates’ and ‘Top10perc’: Percentage of
new students from top 10% of Higher Secondary class also shows a positive relationship of
12089.113681. However, between these two co-variances there is lack of comparability.
To determine the strength of the relationship, we compute the Correlation coefficient of the two
variables. The co-relation between ‘Full time Graduates’ and ‘Students Enrolled’ is 0.964640
& between ‘Full time Graduates’ and ‘Top10perc’ is 0.141289
This infers that there is higher association for Full time Graduates and Students Enrolled vis-à-vis Full
Time Graduates and Top 10perc
Heatmap:
High degree of co-relation is visible between:
o F.Graduates & Enrollements
o Acceptance & F.Graduates
o Room Board & Oustate
o Expend & Top 10 perc
o Percentage of faculties with Ph.D.’s & Percentage of faculties with terminal degree
2.4) Check the dataset for outliers before and after scaling. Draw your inferences from this
exercise.
Answer:
Using the attribute ‘Enrol’ as an example, the box plot before data Scaling is:
The IQR before transformation & scaling is 660 and infers a very high level of dispersion of the data
attribute to its standard deviation. The shape of the data frame is 777 records.
Using the ‘Log Transformation’ method of scaling, we see the following box-plot for the modified
dataset
The IQR after transformation & scaling is 1.31 and infers a very low level of dispersion of the data
attribute to its standard deviation. The shape of the data frame is 777 records. The new dataset has no
outliers.
2.5) Build the covariance matrix, eigenvalues and eigenvector.
Answer:
Covariance matrix:
Eigen Vectors
%s [[-2.48765602e-01 3.31598227e-01 6.30921033e-02 -2.81310530e-01
5.74140964e-03 1.62374420e-02 4.24863486e-02 1.03090398e-01
9.02270802e-02 -5.25098025e-02 3.58970400e-01 -4.59139498e-01
4.30462074e-02 -1.33405806e-01 8.06328039e-02 -5.95830975e-01
2.40709086e-02]
[-2.07601502e-01 3.72116750e-01 1.01249056e-01 -2.67817346e-01
5.57860920e-02 -7.53468452e-03 1.29497196e-02 5.62709623e-02
1.77864814e-01 -4.11400844e-02 -5.43427250e-01 5.18568789e-01
-5.84055850e-02 1.45497511e-01 3.34674281e-02 -2.92642398e-01
-1.45102446e-01]
[-1.76303592e-01 4.03724252e-01 8.29855709e-02 -1.61826771e-01
-5.56936353e-02 4.25579803e-02 2.76928937e-02 -5.86623552e-02
1.28560713e-01 -3.44879147e-02 6.09651110e-01 4.04318439e-01
-6.93988831e-02 -2.95896092e-02 -8.56967180e-02 4.44638207e-01
1.11431545e-02]
[-3.54273947e-01 -8.24118211e-02 -3.50555339e-02 5.15472524e-02
-3.95434345e-01 5.26927980e-02 1.61332069e-01 1.22678028e-01
-3.41099863e-01 -6.40257785e-02 -1.44986329e-01 1.48738723e-01
-8.10481404e-03 -6.97722522e-01 -1.07828189e-01 -1.02303616e-03
3.85543001e-02]
[-3.44001279e-01 -4.47786551e-02 2.41479376e-02 1.09766541e-01
-4.26533594e-01 -3.30915896e-02 1.18485556e-01 1.02491967e-01
-4.03711989e-01 -1.45492289e-02 8.03478445e-02 -5.18683400e-02
-2.73128469e-01 6.17274818e-01 1.51742110e-01 -2.18838802e-02
-8.93515563e-02]
[-1.54640962e-01 4.17673774e-01 6.13929764e-02 -1.00412335e-01
-4.34543659e-02 4.34542349e-02 2.50763629e-02 -7.88896442e-02
5.94419181e-02 -2.08471834e-02 -4.14705279e-01 -5.60363054e-01
-8.11578181e-02 -9.91640992e-03 -5.63728817e-02 5.23622267e-01
5.61767721e-02]
[-2.64425045e-02 3.15087830e-01 -1.39681716e-01 1.58558487e-01
3.02385408e-01 1.91198583e-01 -6.10423460e-02 -5.70783816e-01
-5.60672902e-01 2.23105808e-01 9.01788964e-03 5.27313042e-02
1.00693324e-01 -2.09515982e-02 1.92857500e-02 -1.25997650e-01
-6.35360730e-02]
[-2.94736419e-01 -2.49643522e-01 -4.65988731e-02 -1.31291364e-01
2.22532003e-01 3.00003910e-02 -1.08528966e-01 -9.84599754e-03
4.57332880e-03 -1.86675363e-01 5.08995918e-02 -1.01594830e-01
1.43220673e-01 -3.83544794e-02 -3.40115407e-02 1.41856014e-01
-8.23443779e-01]
[-2.49030449e-01 -1.37808883e-01 -1.48967389e-01 -1.84995991e-01
5.60919470e-01 -1.62755446e-01 -2.09744235e-01 2.21453442e-01
-2.75022548e-01 -2.98324237e-01 1.14639620e-03 2.59293381e-02
-3.59321731e-01 -3.40197083e-03 -5.84289756e-02 6.97485854e-02
3.54559731e-01]
[-6.47575181e-02 5.63418434e-02 -6.77411649e-01 -8.70892205e-02
-1.27288825e-01 -6.41054950e-01 1.49692034e-01 -2.13293009e-01
1.33663353e-01 8.20292186e-02 7.72631963e-04 -2.88282896e-03
3.19400370e-02 9.43887925e-03 -6.68494643e-02 -1.14379958e-02
-2.81593679e-02]
[ 4.25285386e-02 2.19929218e-01 -4.99721120e-01 2.30710568e-01
-2.22311021e-01 3.31398003e-01 -6.33790064e-01 2.32660840e-01
9.44688900e-02 -1.36027616e-01 -1.11433396e-03 1.28904022e-02
-1.85784733e-02 3.09001353e-03 2.75286207e-02 -3.94547417e-02
-3.92640266e-02]
[-3.18312875e-01 5.83113174e-02 1.27028371e-01 5.34724832e-01
1.40166326e-01 -9.12555212e-02 1.09641298e-03 7.70400002e-02
1.85181525e-01 1.23452200e-01 1.38133366e-02 -2.98075465e-02
4.03723253e-02 1.12055599e-01 -6.91126145e-01 -1.27696382e-01
2.32224316e-02]
[-3.17056016e-01 4.64294477e-02 6.60375454e-02 5.19443019e-01
2.04719730e-01 -1.54927646e-01 2.84770105e-02 1.21613297e-02
2.54938198e-01 8.85784627e-02 6.20932749e-03 2.70759809e-02
-5.89734026e-02 -1.58909651e-01 6.71008607e-01 5.83134662e-02
1.64850420e-02]
[ 1.76957895e-01 2.46665277e-01 2.89848401e-01 1.61189487e-01
-7.93882496e-02 -4.87045875e-01 -2.19259358e-01 8.36048735e-02
-2.74544380e-01 -4.72045249e-01 -2.22215182e-03 2.12476294e-02
4.45000727e-01 2.08991284e-02 4.13740967e-02 1.77152700e-02
-1.10262122e-02]
[-2.05082369e-01 -2.46595274e-01 1.46989274e-01 -1.73142230e-02
-2.16297411e-01 4.73400144e-02 -2.43321156e-01 -6.78523654e-01
2.55334907e-01 -4.22999706e-01 -1.91869743e-02 -3.33406243e-03
-1.30727978e-01 8.41789410e-03 -2.71542091e-02 -1.04088088e-01
1.82660654e-01]
[-3.18908750e-01 -1.31689865e-01 -2.26743985e-01 -7.92734946e-02
7.59581203e-02 2.98118619e-01 2.26584481e-01 5.41593771e-02
4.91388809e-02 -1.32286331e-01 -3.53098218e-02 4.38803230e-02
6.92088870e-01 2.27742017e-01 7.31225166e-02 9.37464497e-02
3.25982295e-01]
[-2.52315654e-01 -1.69240532e-01 2.08064649e-01 -2.69129066e-01
-1.09267913e-01 -2.16163313e-01 -5.59943937e-01 5.33553891e-03
-4.19043052e-02 5.90271067e-01 -1.30710024e-02 5.00844705e-03
2.19839000e-01 3.39433604e-03 3.64767385e-02 6.91969778e-02
1.22106697e-01]]
Eigen Values
%s [5.45052162 4.48360686 1.17466761 1.00820573 0.93423123 0.84849117
0.6057878 0.58787222 0.53061262 0.4043029 0.02302787 0.03672545
0.31344588 0.08802464 0.1439785 0.16779415 0.22061096]
2.6) Write the explicit form of the first PC (in terms of Eigen Vectors).
Answer:
Based on the above the largest Eigen Value is 5.45052162, Corresponsing to this largest
Eigen Value the Eigen Vectors are:
[-2.48765602e-01 3.31598227e-01 6.30921033e-02 -2.81310530e-01
5.74140964e-03 1.62374420e-02 4.24863486e-02 1.03090398e-01
9.02270802e-02 -5.25098025e-02 3.58970400e-01 -4.59139498e-01
4.30462074e-02 -1.33405806e-01 8.06328039e-02 -5.95830975e-01
2.40709086e-02]
Let x variable be the various dataset attributes, the PCA1 can be expressed as:
2.7) Discuss the cumulative values of the eigenvalues. How does it help you to decide on
the optimum number of principal components? What do the eigenvectors indicate?
Perform PCA and export the data of the Principal Component scores into a data frame.
Answer:
Discuss the cumulative values of the eigenvalues. How does it help you to decide on the
optimum number of principal components?
Cumulative Variance Explained [ 32.0206282 58.36084263 65.26175919
71.18474841 76.67315352
81.65785448 85.21672597 88.67034731 91.78758099 94.16277251
96.00419883 97.30024023 98.28599436 99.13183669 99.64896227
99.86471628 100.
The plot visually depicts how much of the variances are explained by how many Principal Components,
in the above case we see that the 1st PC explains ~32%, the 2nd ~ 58%..... Effectively we can get
material variances explained (i.e. 90%) by analysing only 9 Principal Components instead of all the 17
attributes in the dataset.
The plot visually depicts the sharp drop from principal component 9 onwards
What do the eigenvectors indicate?
The eigenvectors (principal components) determine the direction or axes, and the eigenvalues explain
the variance of the data along the new axes.
Perform PCA and export the data of the Principal Component scores into a data frame.
#Using scikit learn PCA from sklearn.decomposition import PCA we are generating only 9 PCA
dimensions (dimensionality reduction from 17 to 9)
Dataframe:
--See workbook for Dataframe--
2.8) Mention the business implication of using the Principal Component Analysis for this
case study.
Answer:
The PCA helps with the following interpretation:
Ability to reduce the dimensions from 14 to 9 that explains over 90% of the variances
The top 3 ranked university basis the Principal Componenst analysis are:
o Johns Hopkins University – Rank 8.047182
o Yale University – Rank 7.919327
o Harvard University – Rank 7.694199
The bottom 3 ranked universities being Voorhees College, Huron University, Goldey Beacom
College