Category Archives: Statistics

Variance Inflation Factors in R

The Variance Inflation Factors function is available in R for determining existence of multicollinearity. The VIF function is given by:

Vif

And to use this built-in function is R:

vif(fit)
sqrt(vif(fit))

Advertisements

Autocorrelation function

The autocorrelation function is the ratio of the kth sample autocovariance to the sample covariance, i.e.,

acf2

A plot of rk against lag k is evaluated for discernible patterns, relationships, and absolute values (e.g., close to zero).

Cryptographic roots in Blockchain technology

The Blockchain is expected to be the revolutionary technology to take the centre stage in our society where the traditional ledger system once dominates, from bitcoin that emerged in the finance sector to fields where transactions are dependent on authenticity, be it a paper document from bank, an import / export data exchange, or even documents in judicial systems, it is important to understand the principles of its fundamental roots in cryptography.

For example, to ensure the rightful spending of currency in bitcoins, there are a lot of technology being in place on the virtual money market. One being the Elliptic Curve Cryptography that is based on mathematics to ensure the identity of parties involved in any bitcoin transactions.

blockchain1

Poisson prediction for soccer match odds

It is the World Cup season. There are many prediction models, and one of the most widely used statistical technique is the Poisson distribution:

soccer-poisson1

The historic match results are available in the public domain, for example, at http://eloratings.net/. The data are analysed to obtain an index referred to attack strength or goal expectancy. This can further elaborates into more complex data like home team and away team expectancy.

soccer-poisson2

By using a matrix of score scales, usually from 0 to 9, all possible outcomes under 10 goals per team are defined with the respective probability. An example matrix with scores from 0 to 2 will look like one below:

soccer-poisson3

This is the basics of predicting soccer in a quantitative way using the Poisson distribution. There are of course many other prediction methods and models, including organic method like asking the famous Paul the octopus 🙂

51% Blockchain attack

One of the predicted, and proved feasible, attack to the blockchain technology is the 51% attack. There are several forms of this attack including weakness in the blockchain algorithm itself that allowed easier than usual forking of chain to dishonestly win the popular vote mechanism. In other cases, the perpetrator has to amass more hashing power than all other nodes in the blockchain combined to corrupt the distributed ledger, and hence the name of “51%”.

An interesting mathematical study on the effectiveness of this attack is based on the regularized incomplete beta function to calculate the probability of success of a perpetrator.

incompletebeta

Looking for insights from Fitbit data with R

With a month’s of Fitbit data, it’s about time to harvest for some insights from this technology packed wristband.

r-fitbit4


library(lubridate)
library(dplyr)
fitbitdata = read.csv('fitbit.csv')
fitbitdata % mutate(dow = wday(Date))
fitbitdata$dowlabel <- factor(fitbitdata$dow,levels=1:7,labels=c("Mon","Tue","Wed","Thu","Fri","Sat","Sun"),ordered=TRUE)
fitbitdata$scyl <- as.factor(as.integer(fitbitdata$distance)/max(fitbitdata$distance))
head(fitbitdata)
c1 <- rainbow(7)
c2 <- rainbow(7, alpha=0.4)
c3 <- rainbow(7, v=0.8)
boxplot(fitbitdata$steps~fitbitdata$dowlabel, col=c2, medcol=c3, whiskcol=c1, staplecol=c3, boxcol=c3, outcol=c3, pch=23, cex=2, alpha=fitbitdata$scyl)

r-fitbit3

Number of steps and distance traveled data per day is collected from the Fitbit’s phone app, converted into CSV format, and then uploaded to R for data analysis. With a few lines of R code to draw a box-plot for day of week analysis, this data set with a third part statistical package will fill the gap until the Fitbit App offers something more sophisticated .