Monday, 11 June 2018

How to Perform Mann-Witney U Test(Step by Step) - Hypothesis Testing

This is an interesing procedure and really very straightforward if you would follow through. I happy to know that you are making effort to learn hypothesis testing.

Feel free to leave me a comment below if you have any challenges. I would be happy to give you needed support.

  1. What is Mann-Whitney u-Test?
  2. Exercise 1
  3. Solution Steps

1. What is Mann-Whitney u-Test?

Mann-Whitney u-Test is a non-parametric test used to test whether two independent samples were selected from population having the same distribution. Another name for the Mann-Whitney U Test is Wilcoxon Rank Sum Test.
Note: This is not the same as Wilcoxon Signed Rank Test which is used for dependent samplest.

Just as you know, the easiest way to understand as statistical test is to just perform the test yourself. So now we are going to go through an example and be sure to follow along with a pen,  notebook and a calculator. It is really easy and fun!

2. Excercise

A  researcher gave an aptitude test to 24 respondents, 12 were men and 12 of them were women. He recorded the scores for each of the responded and tabulated it in the table below:


Use thid data provided to test the null hypothesis that the distribution of scores is the same for men as for women. Use a significance level of 0.05. (Use the Wilcoxon Rank Sum Test)

3. Solution Steps

We would follow the step by step procedure. We would also use excel to tabulate our data to make it easier to perform calculation.

Step 1: State the null and alternate hypothesis and rejection criteria

The null hypothesis states that median difference between the pairs ranks of the observations is zero (that is there is no difference in the ranks of the two pairs of observations) and the alternate hypothesis states that the median difference between the ranks of data is not zero.

These are stated below.

H0: μm = μw
H1: μm ≠ μw

Alpha = 0.05

Rejection Criteria: Reject the null hypothesis if Ustat < Ucrit

Step 2: Perform a ranking of all the observation

In this case, we simply subtract corresponding pairs of the data.
We would used MS Excel to help us do it faster. So, I have transfered the table excel and the added a column for the difference in the two pairs of observations.

Total number of observation is 24, so we need to rank the observations from 1 to 24. In the figure, I have colored the observation for Men as blue and for Women as red. This is so that, when I sort the data, I would know which one belongs to which group.

I sorted the data to make it easy to assign the ranks to each of the observation.

Step 3: Calculate the Rank Sums

We calculate the sum of the ranks for the two groups

Sum for Men (n1) = 10+9+20+3+13+14+23+8+11+15+5+1 = 132

Sum for Women (n2) = 12=16+18+19+21+7+6+4+17+24+2+22 = 168

Step 4: Calculate the U Statistic for the Two Groups

The formula the the U statistic is given as:

For the Men observation, we have

We also calculate the U for the Women observation, we have
The U-stat is the smaller value of the two and that would be

Ustat = 66

Step 5:Determine the Critical value from Table

From Mann-Withney u-test table, we check the value under column 12 and row 12
We have a critical value of U to be

Ucrit = 37

Since the calculated value of U is greater than the critical value, we accept the null hypothesis and agree that the two groups are the same.

Thanks for learning. Leave a comment if you have any challenges following this lesson.

How to Perform Wald-Wolfowitz Test - Testing for Homogeneity with Run Test

Hello! Good to see your interest in learning statistics.

Today, we are going to go through the steps of performing the Walf-Wolfowitz run test. Remember, the easiest way to understand hypothesis testing is to solve an example. So intead of boring you with explanations, we would solve an example together. I would be explaining as we solve.

  1. What is Wald-Wolfowitz Test?
  2. Formula for the Wald-Wolfowitz Test?
  3. Exercise 1
  4. Solution Steps

What is Wald-Wolfowitz Test?

Wald-Wolfowitz Test (also called Wald-Wolfowitz run test) is a non-parametric hypothesis test used to test the randomness of a two-valued data sequence. It tests to see if the sequence are mutually independent.

Formula for Wald-Wolfowitz Test

The three formulas for the Wald-Wolfowitz run test  are given below:

where the mean is given by the formula

and the variance is given by the formula

Note: Variance is the square of the standard deviation. So we calculated variance. To get the standard deviation, we must take the square root of the variance.

Let's now solve an example!

Example 1

There are two IVM(Innoson Vehicle Manufacturers) buses, one with 48 passengers,  and another with 38 passengers.
Let X and Y denote the number of miles travelled per day for the 48-passenger and 38-passenger buses respectively. Innoson would like to test the equality of the two distributions.
That is, if:

H0: F(z) = G(z)

The company observed the following data on a random sample of n1 = 10 buses carrying 48 passengers and n2 = 11 buses carying 38 passengers.

X: 104 253 300 308 315 323 331 396 414 452
Y:  184 196 197 248 260 279 355 386 393 432 450

Using normal approximation to R, conduct a Wald-Wolfowitz test at 0.05 level of significance


We would solve this problem step by step.

Step 1: State the null and the alternate hypothesis and rejection criteria

H0: F(z) = G(z)
H1: F(z) = G(z)

Rejection criteria: Reject the null hypothesis if

Step 2: Merge the two lists and sort in ascending order

104  184  196  197  248  253  260  279  300  308  315  331  355  386  393  394  414  432  450  452

Step 3: Count the number of runs: R, n1 and n2

Number of runs R = 9
n1 = 10
n2 =  11

Step 4: Calculate the mean

We calculate the mean using the formular and we have the results below

Step 5: Calculate the variance

We calculation the variance using the calculation steps below

Step 6: Calculate Z

We calculate the value of Z following the formula below:

Note: Used 9.5 intead of 9  because we applied half-unit correction for continuity

Step 7: Draw your conclusion

We fail to reject the null hypothesis ast the 0.05 level because the P value is greater thatn 0.05. This means that there is not sufficient evidence at 0.05 level to conclude that the two distribution functions are not equal.

Thanks for your effort in learning statistics. If you have any challenge, let me know in the comment box below.

Thursday, 7 June 2018

Advanced Statistics Quiz 11 - Cluster Analysis

Good to see you here!
Today's quiz would be based on Cluster Analysis. So let's get started.

Question 1: What is Cluster Analysis?
Cluster Analysis is the statistical procedure that is aimed at grouping data object basedon the information found in the data set that describes the objects and their attributes

Question 2: What is the Goal of Cluster Analysis?
The objective of cluster analysis ia to group objects with similar characteristics into one cluster.

Question 3: What are the two types of Clustering?
The two types of clustering are:
Hierarchical Clustering: Clusters are arranged in a hierarchical tree
Partitioning Clustering: Data are grouped into distinct subsets that does not overlap

Question 4: Describe the k-Means Clustering
K-Means clustering is a partitioning clustering approach where each cluster is  associated with a centroid or center point and each data point is assigned to  the centroid that is closest to it. The number of clusters is specified in advance.

Question 5: Write the k-Means Clustering Algorithm?
i. Choose the initial value of K
ii. repeat
iii. Form K clusters by assigning each point to the closest centroid
iv. Recalculate the centroid of each cluster
v. Move the centroid to the new computed position
vi. until The centroids position don't change

Question 6: How do you Choose Initial Value of K for k-Means Clustering
  • Use another clustering method to estimate it
  • Run the algorithm with different values of K and then choose the one that is optimal
  • Use the prior knowledge about the characteristics of the data

Question 7: How do you choose the centroid for the cluster?
  • Random selection from the feature space
  • Random selection from the data set
  • Look for dense regions of space
  • Space them uniformly around the feature space

Question 8:  How is the quality of a cluster measured?
  • The size of the cluster vs the distance betweent the clusters
  • The Distance between members of the clusters
  • Teh Diameter of the smallest sphere

Question 9: What are some limitations of k-Means Clustering?
Not efficient if data contains outliers
Fails for non-convex round clusters

Question 9: What is McQueen's Algorithm used for?
The McQueen's Algorithm is used for measuring the goodness of the clustering and for minimizing the compactness function in finite steps

Question 10: Outline and explain the two types of Hierarchical Clustering
The two types of hierarchical clustering are:
Top-Down Clustering
Bottom-Top Clustering

How Bottom-Top or Agglomerative Clustering work
  • Start with each of the data points in its own cluster
  • Merge two clusters that are similar
  • Repeat the merging untill there is a single cluster of allt he data points

How Top-Down or Divisive Clustering Work
  • Start with all examples in one big cluster
  • Remove the data point that seems to far away from other points
  • Repeat the process untill all points is in its own cluster

Question 11: Mention three ways to compute dissimilarity between clusters
  • Single Link
  • Complete Link
  • Group Average

Question 12: Compare k-Means and Hierarchical Clustering
k-Means produces single partition while hierarchical produces different partitions
k-Means needs the number of clusters specified in advance while hierarchical does not
k-Means is have a more efficient run-time than the hierarchical

Question 13: What is a Dendrogram?
A dendrogram is a tree diagram used to illustrate the arrangement of clusters in hierarchical clustering.

I would stop here so I can allow you some time to get your head around these concepts.
Thank you for reading.!
Feel free to check out the quiz on other Statistics topics.

Wednesday, 6 June 2018

Advanced Statistics Quiz 10 - Pattern Recognition

Hello! Good to see you again!
Today's lesson would be based on pattern recognition. How well can you explain the concepts of in Pattern Recognition. Lets see.

Question 1: What do you understant by Sufficient Statistic?
If a sample is taken and we obtain the sample mean m and the standard deviation s, then this two parameters are sufficient statistics if allthe information conatind in the data can be summarized  by just these statistics. This is based on the assumption that the data follows a multivariate normal distribution.

Question 2: Why are Maximum Likelihood Estimates Preferable
MLE are preferable due to a set of asymptotic properties which includes:
  • Consistency
  • Asymptotic Nomality
  • Efficiency

Question 3: What is Consistency, Asymptotic Normality and Efficiency?
Consistency: This means that the estimator converges in probability the the value that is being estimated
Asymptotic Normality: This means that the estimator has a normal distribution with functionally known variance and standard deviation
Efficiency: This means that the estimator has a low mean squared error.

Question 4: What is Linear Discriminant Analysis
LDA is a statistical procedure that seeks to reduce the dimensionality of the data while preserving as much of the class discriminatory information as possible.

Question 5: What are Limitations of LDA?
LDA is a parametric method, which means that it assumes unimodal Gaussian likelihoods. For Gaussian distributions, LDA projections may not preserve complex structure in the data.
LDA produces at mos C-1 feature projections
LDA will also fail if the discriminatory information is in the variance of the data instead of the mean

Question 6: Wilk's Lamda Test
The Wilk's Lamda Test is a statistical test to find out which variables contribute significantly in the discriminant function. The closer the Wilk's lambda is to 0, the more the variable contributes to the discriminant function.

Try to digest these ones for now and thanks for reading. Wishing you success in your quiz!

Advanced Statistics Quiz 9 - Concepts from Factor Analysis and PCA

Hello, good to see you here! I'm here to help you understand some of the advanced concepts of statistics.
Today's quiz would be based on the concept of Factor Analysis. I quess you will find it clear and interesting.

 Question 1: Briefly explain Factor Analysis?
Factor analysis is a statistical procedure used to draw inferences on quantities that cannot be quantified numerically. Quantities such as intelligence, friendliness and patroitism.

Question 2: What is the goal of Factor Analysis?
The objective a factor analysis is to describe the correlation between p measured attributes in terms of variation in few underlying unobservable factors.

Question 3: Explain Communality and Uniqueness in Factor Analysis
 These explains the variation caused by the different factors under consideraion. The portion of the variance that is contributed by the k common factors is the communality and the portion that is not explained by the common factor is the uniqueness also known as specific variance

Question 4: Outline the various methods of carrying ouf Factor Analysis problem
  • Maximum Likelihood Method
  • Least Squares Method
  • Principal Components
  • Alpha Factoring
  • Image Factoring

Question 5:  What is the concept of Rotation in Factor Analysis?
Rotation is the process of obtaining a different set of loadings by multiplying  the loadings by an orthogonal matrix chosen based on a specific criteria.

Question 6: Outline and explain the types of rotations you know?
Varimax: Orthogonal rotation that minimizes the number of variables that have high loadings on each other. It simplifies interpretation of factors
Quartimax: A rotation mentod that minimizes the number of factors needed to explain each variable. It simplifies interpretation of observed variable
Equamax:A mixed rotation method which is a combination of the Varimax and the Quatimax methods.
Direct Oblimin: Non-orthogonal rotation
Promax Rotation: Non-orthogonal rotation  that allows correlation of factors.

Question 7: What is Keiser-Meyer-Olkin(KMO) Test used for?
The KMO is a measure of how suitable the available data is to be used for Factor Analysis. The value of the KMO statistic ranges from 0 to 1.

Question 8: What is Principal Component Analysis(PCA)?
PCA is a variance-maximation procedure that aims are transforming a set of features into  few principal components

Question 9: How if Principal Component Analysis Performed?
  • Compute teh sample covariance matrix
  • Compute the eigenvalues
  • Choose a dimension k
  • Define the dimension reduced data
Question 10: Briefly Explain Bartlett's Test of Sphericity
Bartlett's test is a measure of sampling adequacy and relates to the significance of the study and just like the KMO, test how suitable the data is.

Take some time to get used to these concepts in your own word and I would like to thank you or reading!

Tuesday, 5 June 2018

Advanced Statistics Quiz 8a - Concepts from Multivariate Linear Regression

Hello, good to see you! I made this post to help you prepare for oral and written quiz or exam on advanced or mathematical statistics as a continuation of the Advanced Statistics Quiz 8

Question 1: Outline and explain the effects of Multicollinearity?
The effects of multicollinearity are:
  • Variation Inflation Factor(VIF)
  • Tolerance
  • Condition Indices

Variation Inflation Factor(VIF): The variation inflation factor is a metric used to measure the severity of multicolinearity. It is the ration of the variation of a model w.r.t mutiple terms divided by the variance of the model with one term alone. It explains how much the variance of an estimated regression coefficient is changed due to multicollinearity.

Tolerance: This is the inversion of VIF and indicates that a variable under consideration is almost a perfect linear combination of the independent variables already in the equation and need not be added to the regression equation.Tolerance values of the range of 0.2 and below is condidered good.

Condition Indices: The condition indices is a function of eigenvalues and measures the relative amount of variation associated with an eigenvalue such that a large condition index indicates a high degree of collinearity.

Question 2: What is Leverage Matrix in Multivariate Linear Regression?
The leverage matrix which is also called the hat matrix or projection matrix is used for investigating whether one or more observations are outlying with regards to their X-values and therefore excessively influencing the results of the regression

Question 3: What is Binary Logistic Regression
This is a regression model where the dependent variable is binary or categorical and is used to determine the the probability of a binary response based on the independent variables or feature vector.

We continues in the next part.
Thank you!

Advanced Statistics Quiz 8 - Concepts from Multivariate Linear Regression

Hello, good to see you!
I made this post to help you prepare for oral and written quiz or exam on advanced or mathematical statistics. 
So basically, I would be explaining the concepts in very easy to understand way to help you understand it and be able to answer in your own words.

Question 1: What is Partial F-Test and when is it applied
Partial F-Test is a statistical test used to in multivariate linear regression where extra variables have been included, to determing whether the extra variables  provide enough extra explanatory power as a group.

It is used when the simultaneous test of the statistical significance of a group of variables is being tested and requires two regression models.

Question 2: Outline and Expain the 3 Modelling Algorithms
The three modelling algorithms are:
  • Forward Selection
  • Backward Selection
  • Stepwise Selection

Foward Selection
Step 1: In the first step of this algorithm, a list of independent variables with the highest correlation coefficient in the absolute value with the target variable is selected.
Then calculate the F-statistic to see if a very strong linear relationship exists between the variables.
If there is a strong relationship, then stop, else go to step 1
Step 2: In the second step, take the next variable, the highest partial correlation coefficient among the residues with the target variable.. Then calculate Fchange, the extended linear regression. If the calculated value, shows a strong relationship stop, else repeat the process

Backward Elimination
This algorithm works in opposite direction to the Foward Selection. In this case, we start by including all the variables from the start, then we select the least suitable ones. Then we calculate the error. Based on the error value, we remove or eliminate the least suitable variables from the selection. We repeat the caculation until the error is at a minimum value. 

Stepwise Selection
This algorithm is a combination of the Foward Selection and Backward Elimination. This involves gradually removing variables fromthe list of independent variables repeatadly. The stop rule now has a minimum and maximum value. We stop when the F statistic has reached a significant level.

Question 3: What is Adjusted Coefficient of Determination R2 and What is it Used For?  What is the difference between R2 and Adjusted R2?
The Adjusted Coefficient of Determination is used in multiple regression to determine how well a multiple regression equation fits the sample data.
The main difference between R2 and adjusted R2 is that R2 increases automatically as new independent variables are added to the regression equation(even if they don't contribute to the explanatory power of the equation)
However, the adjusted R2 increases only if the added new independent variables contribute to the explanatory power of the regression equation. Therefore, the adjusted R2 is mor useful measure of regression fit than just the R2.

Question 4: What is Heteroscedasticity?
Heteroscedasticity is a concept in regression that means unequal scatter. It is a systematic  variation is the spread of the residues  oeer the change of measured values.Remember that residue is the errror measured between the regression line and the data point. It is the opposit of homoscedasticity(which means constant variation in the residues)

Question 5: What are the Type of Residues
Common Residual
Deleted Residual
Standardized Residual
Studendized Residual

Question 6: What is Covariance Ratio?
 The coveriance ratio is given by:
CovR = CovTL/CovTLj
CovTL is the covariance between the target variable and the linear regression
CovTLj is the covariance betweent the target variable and teh linear regression gotten by omitting the jth case.

Question 7: What is Multicollinearity in Regression?
Multicolinearity means the linear correlation relationship between the two or more explanatory variables.

Question 8: Mention some problems caused by Multicollinearity?
  • the effect of the explanatory variables on the depended variables cannot really be separated
  • the explanatory variables can assume the role of other  explanatory variables
  • estimation of regression coefficients becomes unreliable
  • in extreme situations, analysis cannot be performed on the data
We continue with the next part. You can ask a question in the box below or in the form by the left of this page.

Thank you!

Wednesday, 23 May 2018

Sampling Techniques - Random, Systematic, Stratified etc

Hello! Good to see you again!
In this class I will explain the various sampling techniques you need to know. We would also consider examples of the technique as well as  the advantages and disadvantages of each technique

  • Basics of Sampling
  • Simple Random Sampling
  • Convenient Sampling
  • Systematic Sampling
  • Cluster Sampling
  • Stratified Sampling

Basics of Sampling
To find things out about the population of interest, we need to take a sample from that population. A sample is a selection of some of the objects of the population as a representative of the population. The technique chosen for sampling depends on factors such as the nature of the population being samples as well as the amount of resources available in terms of time and money.
The idea is for each object in the population to be equally likely to be chosen as part of the sample, this is called unbiased sample.

Simple Random Sampling
This is theoritically the ideal method of sampling. In this, case you list all member of the population and used random numbers to determine which objects are to be selected. 
This produces an unbiased sampling
It could be difficult to take simple random samples when dealing with peoples
It is suitable if the population is geographically concentrated and a sampling frame exists.

A sampling frame is a list of all the people or objects in the population

Convenient Sampling
In this case, you do what is convenient or easy.
Ask people nearby or people who walk past in a shopping mall
Take 20 objects coming off the production line

This is most times biased in some biased
Can have self-selection bias where people choose to participate if they have interest in the subject in question.
Convinient sampling provides a quick and convenient way to take samples.

Systematic Sampling
Choose a certain point at random and systematically take objects at certain number apart.
For example, if there is a population of 1000 and you want to take a sample of 5 objects, you can start from the first object and take after every 20 objects

Easier to carry out than Simple Random Sampling and a good approximation of SRS.
If there is a pattern, then a particular type of object could be chosen more often than others.

Cluster Sampling
Population is divided into clustes which are then chosen at random
Within each cluster, all objects in the cluster are included in the sample
Can be more convenient and practical than simple random sampling

Stratified Sampling
Resembles cluster sampling, but the strata or groups are chosen specifically to represent different characteristics of the population
Can be complex to administer
A sampling framework is required.

Snowball Sampling
This is also called chain sampling, chain-referal sampling or referral sampling. In this technique, existing participants are used to recruit further participants among their acquaintances.

It helps you to discover characteristics about a population that you were not aware existed
It allows studies to take place which are otherwise impossible to conduct due to lack of participants.
It also exibits community bias sometimes

Monday, 21 May 2018

Theory of Estimation: Unbiased Estimation

I was happy to see that Estimation was really an easy topic to understand, easier than I always thought.
In this  article, I would teach you in very simple way, the theory of estimation and you would understand it very clearly.

The challenge many have sometimes is caused by lecturers not explaining the concept clear enough, especially from the basics.


1. Basics: What is Estimation?

Estimation is the process involved in systematically inferring the hidden or unobserved variable from a given information set using a mathematical mapping between the unkowns and the knowns as well as a criterion for estimation.

To carry out estimation you need the following:
  • Data: Set of data
  • Estimator: The estimator takes in the data as well as two more items (Objective Function and Model) and then helps us make an estimate.
  • Model: This is a mapping between the knowns(your dataset) and the unknowns (the parameter)
  • Objective Function: This is a mathematical statement the can be mimimized or maximized to find best possible solutions among a set of solutions.

2. Basic Concepts of Estimation

Take note of these three basic concepts

The theory of estimation provides the following to help us in the task of making estimation:
  • Method for estimating the unknowns (eg. model parameters)
  • Means for accessing the 'goodness' of the resulting estimates
  • Making confident statements about the true values (how sure we are about the estimate)

3. Unbiased Estimator

A statistic could be defined as an unbiased estimate of a given parameter if the mean of hte sampling distribution of that statistic can be proved to be equal to the parameter being estimated.

Unbiasedness means, that for a large number of observations(samples), the average over all estimations lies close to the true parameter.

4. Sample Mean Example

Given an n-dimensional vector, X1, . . . ,Xn, prove that the extimator for the means μ is unbiased.

To estimate the mean, we use the sample mean as an estimator.

We now prove that the expected value of the estimator is equal to the true mean μ (condition for unbiasedness). This we would do using the linearity of the expected value
From the above, we can conclude that the estimator
is an unbiased estimator of the sample mean. Thank you for your effort in learning. You can reach me if you find anything difficult.

We consider more examples in the following parts.

Sunday, 20 May 2018

How to Display Logged In User Details Using AngularJS

Hey! Good to see you!

Let's keep it simple this time. I would just give you:
  • the HTML code
  • the AngularJS Script

We would like to display the users Firstname, Lastname, email and Department

Then I would tell you the files you need to  include in your header.

File to Include in your Header
You need to include Bootstrap, JQuery and AngularJS in the header section of your html page

<script type="application/javascript" src="jquery.min.js"></script>  
<script type="text/javascript" src="bootstrap.js"> </script> 
<script type="application/javascript" src="angular.js"></script>
Listing 1: Header Files

AngularJS Script
The AngularJS script is given below. You need to enclose it in a <script></script>

var ShowUser = function(){
  url: baseUrl + "api/user",  //The Base URL depends on your sharepoint server
  method: "GET",
  headers: { "Accept": "application/json; odata=verbose" }
  }).then(function mySucces(response) {
   $scope.DisplayName = + ', ' +;
   $scope.Location =;
   $scope.Department =;
   $scope.TotalPoints = 280;

 }, function error(response)  {
Listing 2: AngularJS Script

The script retrieves the user's details from a the Request URL. Then it places the retrieved data in the $Scope variable. Data placed in the $Scope is accessible from the html page by using the {{}}  to enclose the variable name. That's all you need

The HTML Code
The HTML section that displays the  user details is given below. You can modify it to fit your page design.
 <li>{{Department}} </li>
Listing 3: HTML Code

Make sure you try it and let me know if you have any challenges.
Thanks .

Wednesday, 16 May 2018

How to Post Data to a SharePoint List with AngularJS - Easy Steps

Hello, good to see you here.
Be sure that it really is not so difficult to post data from a form to a SharePoint List. I would show you the steps and also give you the codes.
Just 5 Steps. Lets go!


If you have any issue though, just let me know. Use the comment box below or the form to left of this page.

Step 1: Create a SharePoint List 

Create a list in SharePoint and called CustomerDetails.
This list should contain the following fields three fields.
  • Firstname
  • Lastname
  • Address
We are keeping it very simple so you will understand exactly how it works.

Step 2: Add Bootstrap, AngularJS and JQuery

Create a html page and add AngularJS and BootStrap to the header like shown below:


<title>AngularJS Tutorial</title>
<script type="text/javascript" src="bootstrap.js"> </script>
<script type="application/javascript" src="jquery.min.js"></script>
<script type="application/javascript" src="angular.js"></script>
<script type="application/javascript" src="index.js"></script>


//We would place the form here

Listing 1: Add files in header section

Step 3: Add the html Form

Add the following html to the body of your page, in between the <body> and </body> tags. This is the form that would be filled to be submitted to the SharePoint list

<form name="userForm" ng-app="myapp" ng-controller="myController" >
  <div class="form-group">
 <label for="firstname">Firstname </label> 
 <input type="text" ng-model="Firstname" class="form-control" id="firstname" />    
  <div class="form-group">
 <label for="lastname">Lastname:</label>
 <input type="text" ng-model="Lastname" class="form-control" id="lastname" />
  <div class="form-group">
 <label for="address">Address:</label>
 <input type="text" ng-model="Address" class="form-control" id="address" />
  <button type="submit" class="btn btn-primary"  ng-click="submitCustomer()" class="btn btn-default" data-dismiss="modal">Submit</button>
Listing 2: Code the HTML Form

Step 4: Add the Script

Add the following code to your AngularJS script. Name this script index.js. It's a bit complicated but I want you to first try it, then I would explain how it works to you or help you debug any error you may be getting. Remember to link this script to your html page and place the two in the same folder

var myapp = angular.module('myapp', []);

myapp.controller('myController', function($q, $scope, $http){

 //add nomination to start workflow                                                      
 function getRequestDigest(){
   var deferred = $q.defer();   
     $http ({
     url: "RequestDigest url ", //Get this url from your IT department
     method: "POST",
     headers: {
     "Content-Type": "application/json; odata=verbose",
     "Accept": "application/json; odata=verbose"
    }).success(function (response) {
     console.log('X-RequestDigest value:', response.d.GetContextWebInformation.FormDigestValue); 
     $scope.requestDigest = response.d.GetContextWebInformation.FormDigestValue;
    }).error(function (err) {
     console.log('Error in POST request digest', err);
    return deferred.promise;
 //digest end

 function AddCustomer(listName){
    $scope.submitError = false;
    var deferred = $q.defer();
    var requestData;
    var  GetItemTypeForListName = function (name) {
   return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem";
     var itemType = GetItemTypeForListName(listName);

    requestData = {
    "Title": $scope.Firstname,
    "LastNamePhonetic": $scope.Lastname,
    "WorkAddress": $scope.Address,
  __metadata : { type: itemType }
    var postUrl = baseUrl + "_api/web/lists/getbytitle(listName)/items"; //Replace baseUrl
    var config = {
     headers: {
    "Content-Type": "application/json; odata=verbose",
    'Accept': 'application/json; odata=verbose',
    'X-RequestDigest': $scope.requestDigest
   console.log("requestDigest", $scope.requestDigest);
   $ (postUrl, JSON.stringify(requestData), config).then(function (data) {
      console.log("success", data);
      console.log("failed", error);

   return deferred.promise;


 //button- generate new item in the list and run wf
  $scope.submitCustomer = function (){
    var promise1 = getRequestDigest();
    promise1.then(function(){       //1st run the RequestDigest, then the AddCustomer
 //button end

Listing 3: Content of your index.js file

Step 5: Test your page!

Although it looks complicated, but it is really very simple. Trust me!

Go ahead to view the page.
Enter some items in the form and submit and check that the items gets inserted. Then go the list in SharePoint to make sure the item actually got inserted.

Let me know if you have challenges, I would be able to provide some guidance for you 

Wednesday, 9 May 2018

How to Succeed in Math (5 Secrets of Making Math Very Easy) - By a Genius

Good to see you again! Today's discussion would be Math and I would give you some secrets on how to succeed in Math.

You know, Math have always been and would always be my favorite subject. I learnt it, I practiced it, an I taught it as a teacher some time in the past in secondary school.  

So what I'm going to tell you are actually secrets, if you don't know these five points then you will always likely hate Math. An believe me, Math is actually the most interesting subject.

In this post, I would like to let you know how to succeed in study of Mathematics. I would be talking to you based on my own personal experience.

Point 1: Spend all the Time on it
Assuming that you have been having a particular course, every semester for three years
  • MTH 101 - Introduction to Elementary Math
If on the first semester of the fouth year, you have 6 courses with the same Math course included (that is the 7th time you are having this same course), that is Introduction to Mathmatics(MTH 101). 

The question now is: How easy would this course be at this time? 

You guess right?

I tell you, this MTH 101 would be the easiest course for that semester. The reason is that, you've spend so much time on a studying Math over the months, therefore it would be the easiest compared to other courses that are totally new. This is in the sense that it would be less difficult.
Whats the Point: The point is that the more the percentage of your time you spend in studying Math at the expense of time that would have been used for other causes, the easier Math becomes compared to  those other courses.
This nails the first point.

Spend plenty of time studying Math and you will find out that other courses becomes more difficult(meaning that Math becomes easier!). Even if it appears not interesting, just spend time on it.

I'm sure you get the point now. Let's move to the the second point.

Point 2: Get a Good(Possibly the Best Textbook)
No matter how anyone may choose to see it, a good textbook would always help you enjoy the study of Math. And the more you enjoy studying Math, the easier it becomes. So don't just settle with the recommend textbooks in school. Go out there to get the bookshops and get one. I found out from experience that textbooks written by Americans are always very good when it comes to study of Math. An example is K.A Stroud Engineering Mathematics. If you are in University, no matter the faculty or department, once there is Math in your curriculum, buy Engineering Mathematics.

Point 3: The Principle of First Principles
The principle of First Principles in Mathematics states that, "For you to understand a new topic in Mathematics, learn its first principles".

Lets take an example: what do you understand by dy/dx in Calculus?


This is the meaning of dy/dx from the first principle. The basics is that dy/dx is the slope of the graph. From here you can appreciate how the concept of differentiation and integration, that is the two basic topics in calculus. So what is the point. To learn a new topic in Math, go all the way to the first principle, and that you can do by finding the first part of the chapter that discusses the topic and the first principles would likely be explained there.

Point 4: Ask For Help From Math Pros (just like me!)
This is very important. As the saying goes that 'a day with a good teacher is better than a thousand days spend reading a book'. This is so true in the case of Mathematics. So if there is someone you know that is very good in Mathematics, pester on him to teach you, explain solutions to Math problems, explain the concepts to you an so on. Fortunately, Kindson the Math Pro is there for you. So just paste the Math exercises on the comment box below and I would get back to you.

Point 5: Solve and Solve and Solve!
Get as many examples and exercises as possible. Just keep solving. For textbooks that have solved examples, try to solve it yourself first and then compare your own solution with the example in the textbook. For the exercises, solve all if you can and then verify if your answer is correct.

I assure you that I you apply this five points, you will make so much improvement in Math and with time you will find Math very interesting. Trust me!

I will stop here for now, and I would like to thank you for reading. If this have been informative for your tell me how you feel in the comment box below and Follow me on Google+. 

You can as wells subscribe to my YouTube channel at Kindson The Math Pro on YouTube

Monday, 30 April 2018

How to Add a Progressbar Column to Table Using AngularJS and BootStrap UI

Hello, my friend. I'm Kindson, and good to see you here!

In this tutorial, we are going to learn how to add a progresss bar column to HTML table using AngularJS
  1. Introduction
  2. About AngularJS
  3. What you Need
  4. How it works
  5. How to Vary Color Based on Value
  6. Final Notes

1. Introduction

By now you should know how to display tabular data using AnuglarJS. If not you can look at this lesson: Display SharePoing Table Using AngularJS
Remember you can reach me if you have challenges.

Sometime you may need to display percentages in a progress bar in a table column. Or it may be number of points a user have accumulated in membership website. Using a progressbar would make it more interesting for your users.

2. About AngularJS

AngularJS is a very easy to use framework that helps you to create dynamic page that integrates data into your html page using AngularJS markup.
All you need to to is to add the link to the js file in the head tag of your page.

3. What You Need

  • BootStrap
  • JQuery
  • AngularJS

4. How it Works

It works in a very simple way.
The lenght of the progress bar is defined by the values in another column of the table. So basically, any table that have a column containing number can be used to display a progressbar.
The code is shown in Listing 1.0.

<table border="1" class="em-c-table">
    <thead class="em-c-table__header">
        <tr >
    <tbody class="em-c-table__body">
        <tr ng-repeat="row in data">
            <td><div class="progress progress-striped">
      <div class="progress progress-bar-warning" ng-style="{width: row.Percentage+'%'}"> {{row.Percentage}}</div>
Listing 1.0: HTML Table Structure

The progressbar is displayed in the third column of the table
 Note there are two div tags and one ng-style attribute
  • The first div tag sets the type of progressbar:  "progress progress-stripped
  • The second div tag sets the  color: "progress progress-bar-warning"
  • The ng-style is used to set the width of the bar to the value of the Percentage field in the table.
I hope this is clear. But if not, leave me a comment. I would explain more clearly to you.

5. How to Change Color Based on Value

You may want to vary the color of the bar depending on the value of the lenght. For example:
0 - 60: green
61 - 90: orange
91 - 99: red

To achieve this, you simply need to add a simple class to the <td> tag.

ng-class="{'progress-bar-danger': percent<33, 'progress-bar-info': percent>=33 && percent<66, 'progress-bar-success': percent>=66}"

6. Final Notes

Make sure you try it yourself. Just copy the code to your IDE and try to modify it to fit your data and then make sure it works.
If you completed this tutorial, thumbs up to you!. If you have any challenges, let me know in the comment box below or to the left of this page.

Tuesday, 24 April 2018

Add Pagination to a Page Using AngularJS and BootStrap

In this tutorial, I am going to teach you an easy way to add pagination to a html page using AngularJS and Bootstrap. Trust me, this would be very easy!

I would also share my code freely with you. So you can copy and use, though it took my some days to figure out and put it together.

  1. Background
  2. Scripts and CSS to Include
  3. Script that Handles Pagination
  4. The HTML Page
  5. Final Notes


We would use a dataset from SharePoint list retrieved using AngularJS.
The list is named users with two fields Name and Points

2. Scrips and CSS to Include

Place the following 4 scripts and on css file in the head tag of your html file. These are all the scripts you need for pagination.

  <script type="application/javascript" src="js/angular.1.6.2.js"></script>
  <script type="application/javascript" src="js/angular-route.1.6.2.js"></script>
  <script type="application/javascript" src="js/jquery-3.2.1.js"></script>
  <script src="//"></script>

  <link href="//" rel="stylesheet">
Listing 1.0: Scripts and Css for AngularJS and BootStrap

3. Script That Handles Pagination

You then need to write the script that handles the pagination.
In the script below, there is a function called GetListItems(). You need to write this script yourself as this is not the focus of this lesson. Just know that this script returns the data we would need to paginate.
(If you want the whole code, let me know in the comment box below or to the left of this page)

        var appVar = angular.module('plunker', ['ui.bootstrap']);

        appVar.controller("controller1", function($scope){    
            GetListItems($scope, "Users"); //Uses the $.ajax to retrieve data from sharepoint and place it in the scope
            $scope.viewby = 10;
            $scope.totalItems = $;
            $scope.currentPage = 4;
            $scope.itemsPerPage = $scope.viewby;
            $scope.maxSize = 5; //Number of pager buttons to show
            $scope.setPage = function (pageNo) {
            $scope.currentPage = pageNo;
            $scope.pageChanged = function() {
            console.log('Page changed to: ' + $scope.currentPage);
            $scope.setItemsPerPage = function(num) {
            $scope.itemsPerPage = num;
            $scope.currentPage = 1; //reset to first page
Listing 1.1: Script that Handles Pagination

4. The HTML Page

Now lets see how your table would look like in the html page.

<div ng-app="plunker">    
    <div id="App1" ng-controller="controller1">    
        <h1>List of Items Being Paginated Final</h1>    
        <table border="1">
            <tr >
        <tr ng-repeat="row in data.slice(((currentPage-1)*itemsPerPage), ((currentPage)*itemsPerPage)) | orderBy : '-Percentage'">
        <select ng-model="viewby" ng-change="setItemsPerPage(viewby)">
        </select> records at a time.
    <pagination total-items="totalItems" ng-model="currentPage" ng-change="pageChanged()" class="pagination-sm" items-per-page="itemsPerPage"></pagination>
    <pre>The selected page no: {{currentPage}}</pre>
Listing 1.2: HTML Page With Table Markup

The Table is quite simple, contains only two columns, Name and Points.
The code includes a dropdownlist (Select list) to display numbers that the user can select.. Selecting any of the numbers filters the list and displays that number of items in the table

5. Final Notes

I sincerely hope that these lesson helps you to achieve pagination in your page. I do thing it is quite simple provided you already have a knowlede of HTML, AngularJS and JavaScript.
However, if you have any difficulties, just let me know in the comment box below or to the left of this page, so I could speak with you over skype and guide you.

Welldone, my programmer!