Quantcast
Channel: R Integration Pack
Viewing all 456 articles
Browse latest View live

Updated Wiki: RShelf

$
0
0

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is easy.
No R experience is required.

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

Contents (grouped by type of analysis)
ForecastingClassificationDescriptive
R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values.

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs.

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

On a long enough timeline, the survival rate for everything drops to zero, including events such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future.

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of new the features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top


Updated Wiki: RShelf

$
0
0
<!-- https://rintegrationpack.codeplex.com/wikipage?title=RShelf -->

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is easy.
No R experience is required.

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

Contents (grouped by type of analysis)
ForecastingClassificationDescriptive
R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values.

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs.

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

On a long enough timeline, the survival rate for everything drops to zero, including events such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future.

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of new the features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top

Updated Wiki: RShelf

$
0
0

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is easy.
No R experience is required.

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

Contents (grouped by type of analysis)
ForecastingClassificationDescriptive
R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values.

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs.

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

On a long enough timeline, the survival rate for everything drops to zero, including events such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future.

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of new the features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top

Updated Wiki: RShelf

$
0
0

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is simple.
No R experience is required.

Contents (grouped by type of analysis)
ForecastingClassificationDescriptive

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values.

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs.

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

On a long enough timeline, the survival rate for everything drops to zero, including events such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future.

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of new the features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top

Updated Wiki: RShelf

$
0
0

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is simple.
No R experience is required.

Contents (grouped by type of analysis)

ForecastingClassificationDescriptive

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values.

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs.

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

On a long enough timeline, the survival rate for everything drops to zero, including events such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future.

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of new the features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top

Updated Wiki: RShelf

$
0
0

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is simple.
No R experience is required.

Contents (grouped by type of analysis)

ForecastingClassificationDescriptive

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values.

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs.

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

On a long enough timeline, the survival rate for everything drops to zero, including events such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future.

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of new the features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top

Updated Wiki: RShelf

$
0
0

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is simple.
No R experience is required.

Contents (grouped by type of analysis)

ForecastingClassificationDescriptive

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values.

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs.

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

On a long enough timeline, the survival rate for everything drops to zero, including events such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future.

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of new the features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top

Updated Wiki: RShelf

$
0
0

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is simple.
No R experience is required.

Contents (grouped by type of analysis)

ForecastingClassificationDescriptive

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values.

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs.

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

On a long enough timeline, the survival rate for everything drops to zero, including events such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future.

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of new the features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top


Updated Wiki: RShelf

$
0
0

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is simple.
No R experience is required.

Contents (grouped by type of analysis)
ForecastingClassificationDescriptive

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values.

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs.

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

On a long enough timeline, the survival rate for everything drops to zero, including events such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future.

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of the new features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top

Updated Wiki: RShelf

$
0
0

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is simple.
No R experience is required.

Contents (grouped by type of analysis)
ForecastingClassificationDescriptive

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values.

SeasonalForecasting.png

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.

ARIMA.png

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".

kMeans.png

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".

kMedoids.png

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.

NaiveBayes.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.

NaiveBayes.PNG.png

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs.

PairwiseCorr.PNG

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.

RandomForest.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

On a long enough timeline, the survival rate for everything drops to zero, including events such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future.

Survival.PNG

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of the new features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top

Updated Wiki: RShelf

$
0
0

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is simple.
No R experience is required.

Contents (grouped by type of analysis)
ForecastingClassificationDescriptive

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values.

SeasonalForecasting.PNG

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.

ARIMA.png

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".

kMeans.png

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".

kMedoids.PNG

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.

NaiveBayes.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.

NaiveBayes.PNG.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs.

PairwiseCorr.PNG

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.

RandomForest.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

On a long enough timeline, the survival rate for everything drops to zero, including events such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future.

Survival.PNG

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of the new features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top

Updated Wiki: RShelf

$
0
0

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is simple.
No R experience is required.

Contents (grouped by type of analysis)
ForecastingClassificationDescriptive

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values.

SeasonalForecasting.PNG

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.

ARIMA.png

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".

kMeans.png

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".

kMedoids.PNG

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.

NaiveBayes.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.

NaiveBayes.PNG.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs.

PairwiseCorr.PNG

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.

RandomForest.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

On a long enough timeline, the survival rate for everything drops to zero, including events such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future.

Survival.PNG

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of the new features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top

Updated Wiki: RShelf

$
0
0

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is simple.
No R experience is required.

Contents (grouped by type of analysis)
ForecastingClassificationDescriptive

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values.

SeasonalForecasting.PNG

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.

ARIMA.png

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".

kMeans.png

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".

kMedoids.PNG

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.

NaiveBayes.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.

NaiveBayes.PNG.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs.

PairwiseCorr.PNG

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.

RandomForest.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

On a long enough timeline, the survival rate for everything drops to zero, including events such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future.

Survival.PNG

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of the new features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top

Updated Wiki: RShelf

$
0
0

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is simple.
No R experience is required.

Contents (grouped by type of analysis)
ForecastingClassificationDescriptive

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values.

SeasonalForecasting.PNG

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.

ARIMA.png

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".

kMeans.png

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".

kMedoids.PNG

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.

NaiveBayes.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.

NaiveBayes.PNG.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs.

PairwiseCorr.PNG

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.

RandomForest.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

On a long enough timeline, the survival rate for everything drops to zero, including events such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future.

Survival.PNG

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of the new features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top

Updated Wiki: RShelf

$
0
0

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is simple.
No R experience is required.

Contents (grouped by type of analysis)
ForecastingClassificationDescriptive

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values.

SeasonalForecasting.PNG

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.

ARIMA.png

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".

kMedoids.PNG

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.

NaiveBayes.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.

NaiveBayes.PNG.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs.

PairwiseCorr.PNG

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.

RandomForest.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

On a long enough timeline, the survival rate for everything drops to zero, including events such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future.

Survival.PNG

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of the new features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top


Updated Wiki: RShelf

$
0
0

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is simple.
No R experience is required.

Contents (grouped by type of analysis)
ForecastingClassificationDescriptive

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values. SeasonalForecasting.PNG

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.ARIMA.png

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".kMeans.png

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".kMedoids.PNG

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.NaiveBayes.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.NaiveBayes.PNG.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs. PairwiseCorr.PNG

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.RandomForest.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

Survival Analysis can be used to predict the probability of an event occuring, such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future. Survival.PNG

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of the new features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top

Updated Wiki: RShelf

$
0
0

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is simple.
No R experience is required.

Contents (grouped by type of analysis)
ForecastingClassificationDescriptive

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values. SeasonalForecasting.PNG

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.ARIMA.png

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".kMeans.png

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".kMedoids.PNG

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.NaiveBayes.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.NaiveBayes.PNG.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs. PairwiseCorr.PNG

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.RandomForest.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

Survival Analysis can be used to predict the probability of an event occuring, such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future. Survival.PNG

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of the new features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top

Updated Wiki: RShelf

$
0
0

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is simple.
No R experience is required.

Contents (grouped by type of analysis)
ForecastingClassificationDescriptive



New!

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values. SeasonalForecasting.PNG

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.ARIMA.png

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".kMeans.png

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".kMedoids.PNG

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.NaiveBayes.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.NaiveBayes.PNG.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs. PairwiseCorr.PNG

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.RandomForest.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

Survival Analysis can be used to predict the probability of an event occuring, such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future. Survival.PNG

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of the new features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top

Updated Wiki: RShelf

$
0
0

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is simple.
No R experience is required.

Contents (grouped by type of analysis)
ForecastingClassificationDescriptive


New!

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values. SeasonalForecasting.PNG

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.ARIMA.png

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".kMeans.png

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".kMedoids.PNG

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.NaiveBayes.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.NaiveBayes.PNG.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs. PairwiseCorr.PNG

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.RandomForest.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

Survival Analysis can be used to predict the probability of an event occuring, such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future. Survival.PNG

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of the new features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top

Updated Wiki: RShelf

$
0
0
<!-- https://rintegrationpack.codeplex.com/wikipage?title=RShelf -->

R Scripts "Shelf"

Here you'll find ready-to-go R Analytics which can easily be added to your R-enabled MicroStrategy environment.
If you can create a MicroStrategy metric then deploying R Analytics to MicroStrategy is simple.
No R experience is required.

Contents (clickable, grouped by type of analysis)
ForecastingClassificationDescriptive


New!

These metric expressions work withR Integration Pack Version 2.
Click Here: For metric expressions that work with Version 1 (or any version).

Click Here: If you haven't already completed the installation steps.
Click Here: For details on how to deploy these analytics and use the new R Integration Pack Version 2 features.

R AnalyticMetric Expression (URL, Version 2)   [Switch to File]
Seasonal Forecasting

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses R’s ordinary least squares regression algorithm to fit the best curve that captures the general trend and season variability of numeric data so it can use to predict future values. SeasonalForecasting.PNG

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/SeasonalForecasting.R", _InputNames="Target, Trend, Season", _Params="FileName=''">(Target, Trend, Season)
ARIMA

One of the most common applications of predictive analytics is to forecast time-based data. This analytic uses the Auto-Regressive Integrated with Moving Average (ARIMA) algorithm to project a sequence of values ahead into the future, based on the assumption that data points taken over time may have an internal structure that can be measured. While ARIMA tends to be esoteric and complex, this analytic uses the “auto.arima” function from R’s “forecast” package to search through a variety of possible models in order to find the best one. Not only does this script generate the expected forecast values, it also provides outputs based on confidence bands, nominally set at 80% and 95% confidence levels.ARIMA.png

R Script
Documentation

Back to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), _Params="CycleLength=12, Horizon=12, Conf1=80, Conf2=95, ImageName='', FileName=''">(Target)
k-Means Clustering

Using the K-Means algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a central point, it's "mean".kMeans.png

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMeansClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Medoids Clustering

Using the K-Medoids algorithm, this analytic clusters records "by their nature" so that records within a cluster have more in common with each other than with those records in the other clusters. Each cluster is defined by a prototypical record, it's "medoid".kMedoids.PNG

R Script
Documentation

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", _Params="Exact_k=4, Max_k=10, FileName=''">(Vars)
k-Nearest Neighbors

k-Nearest Neighbors (kNN) is a simple classification technique that is unique in the sense that no model is explicitly trained. In the kNN process, two datasets are read in: the training dataset in which the dependent variable is already known, and the test dataset in which the dependent variable is unknown. Classifications for the test set are made by determining the k most similar records in the training dataset (known as neighbors) and returning the majority vote amongst those neighbors.

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", _Params="TrainIncluded=TRUE, k=1, FileName='kNN'">(ID, Target, Training, Vars)
Naive Bayes

Naïve Bayes is a simple classification technique wherein the Naïve assumption that the effect of the value of each variable is independent from all other variables is made. For each independent variable, the algorithm then calculates the conditional likelihood of each potential class given the particular value for that variable and then multiplies those effects together to determine the probability for each class. The class with the highest probability is returned as the predicted class.NaiveBayes.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:/div> RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="TrainMode=TRUE, FileName='NaiveBayes', Correction=1">(Target, Vars)
Neural Network

Neural Network is an advanced machine learning classification technique wherein a model is constructed that aims to simulate the thought process performed by the human brain. A model consists of “neurons” that are interconnected by an activation function. Every record is then passed through the network from the appropriate input neuron to the proper output neuron through a series of weights and transformations defined by the activation function.NaiveBayes.PNG.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42
Pairwise Variable Correlation

PairwiseCorr measures the correlation between pairs of numeric variables to show how they behave with respect to each other. The primary output of this analytic is a correlation plot and a correlation table that contain the correlations of the variables when taken in pairs. PairwiseCorr.PNG

R Script
Documentation

Back to Contents
Result returns "Ok" when the correlations were calculated with no errors:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/PairwiseCorr.R", _InputNames="Labels, Vars", _Params="HasLabels=TRUE, WindowSize=0, ImageName='PairwiseCorr', FileName='PairwiseCorr'">(Labels, Vars)
Random Forests

Random Forest is an advanced classification technique wherein the training dataset is used to construct many independent decision trees. Every record is then passed into each individual decision tree for classification, and the class that is predicted by the majority of those decision trees is returned as the predicted class for that record.RandomForest.PNG

R Script
Documentation

Back to Contents
Class returns the predicted class as a string:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _Params="TrainMode=TRUE, FileName='RandomForest', NumTree=750, NumVar=3, Seed=42">(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/RandomForests.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Probability returns the predicted probability for each record:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseLogissticRegression.R", _InputNames="Target, Vars", _Params="FileName='', Stepwise=TRUE">(Target, Vars)
Stepwise Regression

Stepwise Linear Regression is a variant on classical Linear Regression in which variables are only included in the model if they have a significant effect.

R Script
Documentation

Back to Contents
Forecast returns the predictions from the model:
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/StepwiseRegression.R", _InputNames="Target, Vars", _Params="FileName='StepwiseRegression', Stepwise=TRUE">(Target, Vars)
Survival Analysis

Survival Analysis can be used to predict the probability of an event occuring, such as a component failure or a customer being lost. This analytic uses the Cox Regression algorithm to quantify the effect that each independent variable has on the likelihood that such an event will occur at some point in the future. Survival.PNG

R Script
Documentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="http://s3-us-west-1.amazonaws.com/rshelf/Survival.R", _InputNames="Time, Status, Vars", _Params="TrainMode=FALSE, FileName=''">(Time, Status, Vars)

How to use:

RScriptsSourcing.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. The shelf includes metric expressions for Version 1 of the R Integration Pack as well as variations that take advantage of the new features in Version 2.

First, you'll have to decide how you want to access the R Script to be executed:

  1. URL "On-the-Shelf":Metric Expression (URL) is the fastest way to get started for systems with internet connectivity is to access these R Analytics via the web (requires R Integration Pack Version 2 or higher).
  2. File "Off-the-Shelf":Metric Expression (File) accesses these R Scripts using the file system. Just download and save theR Script to the Centralized RScripts Repository. Please note that each metric expression can also be found inside its R Script within the MicroStrategy header block at the top.

Params.png

And Version 2 of the R Integration Pack makes it even simpler for end-users control the analytic's execution thanks to the_Params parameter that allows function parameters to be referenced by name using a string of name-value pairs. This is in addition to the original set of 27 pre-defined parameters (9 boolean, 9 numeric and 9 string).

After you've copied the metric expression for the analytic you wish to deploy:

  1. Paste the Metric Expression into any MicroStrategy metric editor
  2. Match analytic's inputs and function parameters for your application
  3. Name and save the metric so it can be added to any MicroStrategy report, scorecard or dashboard

For details about how a particular analytic works, be sure to check out its Documentation.

Go to top

Share your scripts:

We'd like to encourage everyone in the community to use and share these R Scripts.  Have you written an R Script you'd like to share with the rest of the community? That would be great!

If you have a R Script you'd like to contribute, please email your script and it's documentation torpechter@microstrategy.com. We'll test it to confirm its ready for general use by others. Once accepted, we'll add it to this page.

Code Disclaimer:

This page provides programming examples.  MicroStrategy grants you a nonexclusive copyright license to use all programming code examples from which you can use or generate similar function tailored to your own specific needs.  All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. MicroStrategy, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.  All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Go to top

Viewing all 456 articles
Browse latest View live