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

New Post: OUTLIER DETECTION ERROR

$
0
0
Hello,

I attended to Advanced analytics Workshop at MSTR world in Barcelona last july.

Now I'm trying to do the workshop as a POC.

All the integration works fine and I do a Forecast and ARIMA,

but with Outlier metric I get an Error.

I try this.

RScript<_RScriptFile="SeasonalForecasting.R",_InputNames="Revenue, MonthIndex,MonthOfYear",_OutputVar="Outlier",NumericParam1=3,StringParam9="SeasonalForecast">(Revenue, MonthIndex, MonthOfYear)

And the error.

2014-10-15 9:19:04 CRSupport_FO::ParseRScript: The output 'Outlier' specified in the _OutputVar parameter is not defined.

Outlier is the name of the new metric also.

Thanks.

New Post: OUTLIER DETECTION ERROR

$
0
0
This would seem to indicate the header block in your script is missing an entry for the output call Outlier. Can you make you at the top of the script in the MicroStrategy head block that there's an output defined using a line that should look something like:

RVAR Outlier -output -numeric -vector

If that's not the easy fix, please the complete header block (and the script too would be good) and we can dig a little deeping into what's gong on.

Thanks,

Rick

New Post: OUTLIER DETECTION ERROR

$
0
0
Hi Rick,

I put the line (first on top but normal Forecast then doesn't work).

There is the header after the modification.
#MICROSTRATEGY_BEGIN
#
#RVAR Target -input -numeric -vector
#RVAR Trend -input -numeric -vector
#RVAR Season -input -vector

#
#RVAR FileName -parameter StringParam9
#
#RVAR Forecast -output -numeric -vector  #Metric Expression: RScript<_RScriptFile="SeasonalForecasting.R", _InputNames="Target, Trend, Season", StringParam9="">(Target, Trend, Season)
#RVAR Outlier -output -numeric -vector
#
#MICROSTRATEGY_END
PD: the workshops was very usefull, tnks a lot. I hope you enjoy a little bit the city

New Post: Integration with Oracle R Enterprise

New Post: Taking user input for R parameters

$
0
0
Hi,

thanks for the reply. Could not try this for a while as we got busy with some other work.
I am trying this for few days now, but am not able to pass user value prompt to R script metric.
When I passed an existing metric as parameter, it works. But when I take the metric on which there is a value prompt, the value provided by user does not pass to R script.

The value needed from user is a numeric value and not a date.
Can you please help with this? I just need to pass user provided number to R script as 'target'.

thanks in advance,
Harsh

New Post: Taking user input for R parameters

$
0
0
Hi Harsh,

Can you clarify the exact behavior you're trying to accomplish? You say, "When I passed an existing metric as parameter, it works." Just to be clear, values can be passed into an R script in one of two ways: Either as Inputs which must be metrics that appear in between the parentheses of a metric expression, or as Parameters which are static values that appear in between the angle brackets of metric expression.

For example, here's the metric expression for the SeasonalForecasting.R script that comes with the R Integration Pack:

RScript<_RScriptFile="SeasonalForecasting.R", _InputNames="Target, Trend, Season", StringParam9="">(Target, Trend, Season)

So, when you say that it worked when you passed an existing metric as a parameter, you must really mean you passed in a metric as an Input, for example Target in the script above. And replacing Target with a different metric, one that is based on a value prompt that the user provides, then that number from the user should work as well.

Or, are you trying to pass in this value to a Parameter, as StringParam9 (or a NumericParam for a number). Parameters cannot take in values from a metric, they are defined by the static values in the metric expression.

If you can clarify what you're trying to do, hopefully we can help you better.

Thanks,

Rick

New Post: Taking user input for R parameters

$
0
0
Hi Rick,
Sorry for the confusion. I am not using parameter anywhere.
Our R script has an input numeric metric which should be provided by users running dashboard in MSTR.
For that, we added two reports as datasets in a dashboard, one containing core metrices and other containing metrices with value prompts.
Then we defined R metric as in
RScript<_RScriptFile="SeasonalForecasting.R", _InputNames="Target, Trend, Season">(Target, Trend, Season) where we set Season input as the metric with prompt. This passes null values to R script, which we checked by logging in the script.
If we pass one of the core metric as input in Season, the values are received in R script.
Please let me know if any other information would be relevant and I will provide it. The script is huge with more than 20 inputs, so I have avoided pasting it.

Regards,
Harsh

Updated Wiki: R Script "Shelf"

$
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, click on name to jump to that analytic)
ForecastingClassificationDescriptive


New!

These metric expressions work with R Integration Pack Version 1.
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 (File, All Versions)
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
DocumentationBack to Contents
Forecast returns the forecasted value:
RScript<_RScriptFile="SeasonalForecasting.R", _InputNames="Target, Trend, Season", StringParam9="">(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="ARIMA.R", _InputNames="Target", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(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="kMeansClustering.R", _InputNames="Vars", NumericParam1=4, NumericParam2=10, StringParam9="">(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
StorePerformance.mstr
Cluster&RegionRevenue.xlsx

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="kMedoidsClustering.R", _InputNames="Vars", NumericParam1=4, NumericParam2=10, StringParam9="">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", NumericParam1=4, NumericParam2=10, StringParam9="">(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="kNN.R", _InputNames="ID, Target, Training, Vars", BooleanParam9=TRUE, NumericParam1=1, StringParam9="kNN">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, NumericParam1=1, StringParam9="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="NaiveBayes.R", _InputNames="Target, Vars", BooleanParam9=TRUE, StringParam9="NaiveBayes", NumericParam1=1>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="NaiveBayes", NumericParam1=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="NeuralNetwork.R", _InputNames="Target, Vars", StringParam9="NeuralNetwork", BooleanParam9=TRUE, NumericParam1=3, NumericParam2=42>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", StringParam9="NeuralNetwork", BooleanParam9=TRUE, NumericParam1=3, NumericParam2=42>(Target, Vars)RScript<_RScriptFile="NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42>(Target, Vars)
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="PairwiseCorr.R", _InputNames="Labels, Vars", BooleanParam1=TRUE, NumericParam1=0, StringParam8="PairwiseCorr", StringParam9="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="RandomForest.R", _InputNames="Target, Vars", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="RandomForest.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="StepwiseLogisticRegression.R", _InputNames="Target, Vars", StringParam9="", BooleanParam1=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="StepwiseRegression.R", _InputNames="Target, Vars", StringParam9="StepwiseRegression", BooleanParam1=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
Survival_v1.pdfDocumentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="Survival.R", _InputNames="Time, Status, Vars", BooleanParam9=FALSE, StringParam9="">(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: R Script "Shelf"

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

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, click on name to jump to that analytic)
ForecastingClassificationDescriptive


New!

These metric expressions work with R Integration Pack Version 1.
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 (File, All Versions)
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="SeasonalForecasting.R", _InputNames="Target, Trend, Season", StringParam9="">(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="ARIMA.R", _InputNames="Target", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(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="kMeansClustering.R", _InputNames="Vars", NumericParam1=4, NumericParam2=10, StringParam9="">(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
StorePerformance.mstr
Cluster&RegionRevenue.xlsx

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="kMedoidsClustering.R", _InputNames="Vars", NumericParam1=4, NumericParam2=10, StringParam9="">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", NumericParam1=4, NumericParam2=10, StringParam9="">(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="kNN.R", _InputNames="ID, Target, Training, Vars", BooleanParam9=TRUE, NumericParam1=1, StringParam9="kNN">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, NumericParam1=1, StringParam9="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="NaiveBayes.R", _InputNames="Target, Vars", BooleanParam9=TRUE, StringParam9="NaiveBayes", NumericParam1=1>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="NaiveBayes", NumericParam1=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="NeuralNetwork.R", _InputNames="Target, Vars", StringParam9="NeuralNetwork", BooleanParam9=TRUE, NumericParam1=3, NumericParam2=42>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", StringParam9="NeuralNetwork", BooleanParam9=TRUE, NumericParam1=3, NumericParam2=42>(Target, Vars)RScript<_RScriptFile="NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42>(Target, Vars)
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="PairwiseCorr.R", _InputNames="Labels, Vars", BooleanParam1=TRUE, NumericParam1=0, StringParam8="PairwiseCorr", StringParam9="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="RandomForest.R", _InputNames="Target, Vars", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="RandomForest.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="StepwiseLogisticRegression.R", _InputNames="Target, Vars", StringParam9="", BooleanParam1=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="StepwiseRegression.R", _InputNames="Target, Vars", StringParam9="StepwiseRegression", BooleanParam1=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
Survival_v1.pdfDocumentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="Survival.R", _InputNames="Time, Status, Vars", BooleanParam9=FALSE, StringParam9="">(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: R Script "Shelf"

$
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, click on name to jump to that analytic)
ForecastingClassificationDescriptive


New!

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
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="SeasonalForecasting.R", _InputNames="Target, Trend, Season", StringParam9="">(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="ARIMA.R", _InputNames="Target", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(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="kMeansClustering.R", _InputNames="Vars", NumericParam1=4, NumericParam2=10, StringParam9="">(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
StorePerformance.mstr
Cluster&RegionRevenue.xlsx

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="kMedoidsClustering.R", _InputNames="Vars", NumericParam1=4, NumericParam2=10, StringParam9="">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", NumericParam1=4, NumericParam2=10, StringParam9="">(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="kNN.R", _InputNames="ID, Target, Training, Vars", BooleanParam9=TRUE, NumericParam1=1, StringParam9="kNN">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, NumericParam1=1, StringParam9="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="NaiveBayes.R", _InputNames="Target, Vars", BooleanParam9=TRUE, StringParam9="NaiveBayes", NumericParam1=1>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="NaiveBayes", NumericParam1=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="NeuralNetwork.R", _InputNames="Target, Vars", StringParam9="NeuralNetwork", BooleanParam9=TRUE, NumericParam1=3, NumericParam2=42>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", StringParam9="NeuralNetwork", BooleanParam9=TRUE, NumericParam1=3, NumericParam2=42>(Target, Vars)RScript<_RScriptFile="NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42>(Target, Vars)
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="PairwiseCorr.R", _InputNames="Labels, Vars", BooleanParam1=TRUE, NumericParam1=0, StringParam8="PairwiseCorr", StringParam9="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="RandomForest.R", _InputNames="Target, Vars", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="RandomForest.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="StepwiseLogisticRegression.R", _InputNames="Target, Vars", StringParam9="", BooleanParam1=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="StepwiseRegression.R", _InputNames="Target, Vars", StringParam9="StepwiseRegression", BooleanParam1=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
Survival_v1.pdfDocumentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="Survival.R", _InputNames="Time, Status, Vars", BooleanParam9=FALSE, StringParam9="">(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: R Script "Shelf"

$
0
0

R Scripts "Shelf"

These ready-to-go R Analytics 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, click on name to jump to that analytic)
ForecastingClassificationDescriptive


New!

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
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="SeasonalForecasting.R", _InputNames="Target, Trend, Season", StringParam9="">(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="ARIMA.R", _InputNames="Target", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(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="kMeansClustering.R", _InputNames="Vars", NumericParam1=4, NumericParam2=10, StringParam9="">(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
StorePerformance.mstr
Cluster&RegionRevenue.xlsx

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="kMedoidsClustering.R", _InputNames="Vars", NumericParam1=4, NumericParam2=10, StringParam9="">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", NumericParam1=4, NumericParam2=10, StringParam9="">(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="kNN.R", _InputNames="ID, Target, Training, Vars", BooleanParam9=TRUE, NumericParam1=1, StringParam9="kNN">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, NumericParam1=1, StringParam9="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="NaiveBayes.R", _InputNames="Target, Vars", BooleanParam9=TRUE, StringParam9="NaiveBayes", NumericParam1=1>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="NaiveBayes", NumericParam1=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="NeuralNetwork.R", _InputNames="Target, Vars", StringParam9="NeuralNetwork", BooleanParam9=TRUE, NumericParam1=3, NumericParam2=42>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", StringParam9="NeuralNetwork", BooleanParam9=TRUE, NumericParam1=3, NumericParam2=42>(Target, Vars)RScript<_RScriptFile="NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42>(Target, Vars)
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="PairwiseCorr.R", _InputNames="Labels, Vars", BooleanParam1=TRUE, NumericParam1=0, StringParam8="PairwiseCorr", StringParam9="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="RandomForest.R", _InputNames="Target, Vars", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="RandomForest.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="StepwiseLogisticRegression.R", _InputNames="Target, Vars", StringParam9="", BooleanParam1=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="StepwiseRegression.R", _InputNames="Target, Vars", StringParam9="StepwiseRegression", BooleanParam1=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
Survival_v1.pdfDocumentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="Survival.R", _InputNames="Time, Status, Vars", BooleanParam9=FALSE, StringParam9="">(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: R Script "Shelf"

$
0
0

R Scripts "Shelf"

These ready-to-go R Analytics 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, click on name to jump to that analytic)
ForecastingClassificationDescriptive


New!

Click Here: If you haven't already completed the installation steps for R and/or the R Integration Pack.
Click Here: For details on how to deploy these analytics using MicroStrategy.

R AnalyticMetric Expression
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="SeasonalForecasting.R", _InputNames="Target, Trend, Season", StringParam9="">(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="ARIMA.R", _InputNames="Target", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(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="kMeansClustering.R", _InputNames="Vars", NumericParam1=4, NumericParam2=10, StringParam9="">(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
StorePerformance.mstr
Cluster&RegionRevenue.xlsx

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="kMedoidsClustering.R", _InputNames="Vars", NumericParam1=4, NumericParam2=10, StringParam9="">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", NumericParam1=4, NumericParam2=10, StringParam9="">(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="kNN.R", _InputNames="ID, Target, Training, Vars", BooleanParam9=TRUE, NumericParam1=1, StringParam9="kNN">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, NumericParam1=1, StringParam9="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="NaiveBayes.R", _InputNames="Target, Vars", BooleanParam9=TRUE, StringParam9="NaiveBayes", NumericParam1=1>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="NaiveBayes", NumericParam1=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="NeuralNetwork.R", _InputNames="Target, Vars", StringParam9="NeuralNetwork", BooleanParam9=TRUE, NumericParam1=3, NumericParam2=42>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", StringParam9="NeuralNetwork", BooleanParam9=TRUE, NumericParam1=3, NumericParam2=42>(Target, Vars)RScript<_RScriptFile="NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42>(Target, Vars)
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="PairwiseCorr.R", _InputNames="Labels, Vars", BooleanParam1=TRUE, NumericParam1=0, StringParam8="PairwiseCorr", StringParam9="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="RandomForest.R", _InputNames="Target, Vars", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="RandomForest.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="StepwiseLogisticRegression.R", _InputNames="Target, Vars", StringParam9="", BooleanParam1=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="StepwiseRegression.R", _InputNames="Target, Vars", StringParam9="StepwiseRegression", BooleanParam1=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
Survival_v1.pdfDocumentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="Survival.R", _InputNames="Time, Status, Vars", BooleanParam9=FALSE, StringParam9="">(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. 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.

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: R Script "Shelf"

$
0
0

R Scripts "Shelf"

These ready-to-go R Analytics 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, click on name to jump to that analytic)
ForecastingClassificationDescriptive


New!

Click Here: If you haven't already completed the installation steps for R and/or the R Integration Pack.
Click Here: For details on how to deploy these analytics using MicroStrategy.

R AnalyticMetric Expression
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="SeasonalForecasting.R", _InputNames="Target, Trend, Season", StringParam9="">(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="ARIMA.R", _InputNames="Target", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(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="kMeansClustering.R", _InputNames="Vars", NumericParam1=4, NumericParam2=10, StringParam9="">(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
StorePerformance.mstr
Cluster&RegionRevenue.xlsx

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="kMedoidsClustering.R", _InputNames="Vars", NumericParam1=4, NumericParam2=10, StringParam9="">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", NumericParam1=4, NumericParam2=10, StringParam9="">(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="kNN.R", _InputNames="ID, Target, Training, Vars", BooleanParam9=TRUE, NumericParam1=1, StringParam9="kNN">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, NumericParam1=1, StringParam9="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="NaiveBayes.R", _InputNames="Target, Vars", BooleanParam9=TRUE, StringParam9="NaiveBayes", NumericParam1=1>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="NaiveBayes", NumericParam1=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="NeuralNetwork.R", _InputNames="Target, Vars", StringParam9="NeuralNetwork", BooleanParam9=TRUE, NumericParam1=3, NumericParam2=42>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", StringParam9="NeuralNetwork", BooleanParam9=TRUE, NumericParam1=3, NumericParam2=42>(Target, Vars)RScript<_RScriptFile="NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42>(Target, Vars)
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="PairwiseCorr.R", _InputNames="Labels, Vars", BooleanParam1=TRUE, NumericParam1=0, StringParam8="PairwiseCorr", StringParam9="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="RandomForest.R", _InputNames="Target, Vars", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="RandomForest.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="StepwiseLogisticRegression.R", _InputNames="Target, Vars", StringParam9="", BooleanParam1=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="StepwiseRegression.R", _InputNames="Target, Vars", StringParam9="StepwiseRegression", BooleanParam1=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
Survival_v1.pdfDocumentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="Survival.R", _InputNames="Time, Status, Vars", BooleanParam9=FALSE, StringParam9="">(Time, Status, Vars)

How to use:

RScriptsSourcing_v1.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. 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.

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: Home

$
0
0

Project Description

CLICK HERE for the R Integration Pack User Guide

CLICK HERE for the R Script "Shelf" that contains ready-to-go R Analytics

RIPBlockDiagram.png

The MicroStrategy R Integration Pack makes it easy for anyone to deploy sophisticated R Analytics to any user, anywhere, any time. Thanks to an architecture designed with extensibility at its core, MicroStrategy delivers an innovative R integration that sets the standard for simplicity, scalability and performance. Now virtually any algorithm, statistic or analysis can be added to the industry's leading Business Intelligence platform thanks to third generation features no other BI product can match:

  • No R left behind: Any R Script, all R packages
  • No Servers Required: R Scripts execute inside the BI engine just like our native analytics
  • Data from MicroStrategy, Results from R, plus easy-to-use function parameters that give end-users process control without any coding required
  • High-Performance, COM-based Execution
  • Centralized RScripts Repository enables fool-proof deployment of analytics from development to production.
  • R Programmers will be impressed with the drag-and-drop deployR() utility that makes capturing the analytic's signature quick and easy
  • On the other hand, even if you're just getting started on the R learning curve -- especially you're an "analytical amateurs", someone who loves data and isn't afraid to get on the R learning curve -- you can learn-by-example thanks to the industry's first free on-line collection of "Off-ths-Shelf" R Analytics. These scripts are designed to be deployed as-is with no modification required. Since you don't even have to look at the R code, anyone can add new analytics to their MicroStrategy environment, including powerful new tools like the ARIMA and Random Forecasts predictive algorithms, the k-Means and k-Mediods clustering algorithms, not to mention a complete Statistical Process Control (SPC) Charting solution and a cool data discover tool that that generates lucid Pair-wise Variable Correlation plots and tables. That said, data scientists and especially Analytic Amateurs are welcome to adapt and re-purpose any of the of the source code provided with these Off-the-Shelf scripts.
  • R Scripts are referenced, not embedded, making for easy maintenance and version control
  • R Scripts errors caught and logged
  • One Script, Multiple Execution Modes
  • Support for Windows, Linux, Unix, AIX
  • Transparent R Environment: Persist/Load Files, Objects & Images, Unattended Package Installation
  • Leverages all MicroStrategy platform features, including structured and unstructured data, in-memory cubes, re-usable metadata objects, visual data discovery, enterprise-level security and more, all seamlessly delivered via web and mobile, cloud and office.
  • Available at no extra cost

Getting Started

Conceptually, think of the R Analytic as a black box with an R Script inside. MicroStrategy doesn't need to know much about the R Script in the black box, it only needs to know how to pass data in and, after the script has executed in the R environment, how to consume the results.

RIPBlockDiagram.png

There are three main steps to using the R Integration Pack:

  1. Installation: A one-time install of R and the R Script functions into your MicroStrategy environment, performed by system administrator types or anyone with permissions to install and configure software on the system.
  2. Deployment: Delivering results from R to any BI User is what the R Integration Pack is all about. Thanks to the ever-growing collection of"Off-the-Shelf" R Scripts, you don’t need to know anything about R code, no programming is required. If you can create a metric in MicroStrategy, and practically anyone can, then you can deploy an R Analytic as well. It's really that simple!

Develop-NoNum.png

For more details, please see the R Integration Pack User Guide

Updated Wiki: Home

$
0
0

Project Description

CLICK HERE for the R Integration Pack User Guide

CLICK HERE for the R Script "Shelf" that contains ready-to-go R Analytics

RIPBlockDiagram.png

The MicroStrategy R Integration Pack makes it easy for anyone to deploy sophisticated R Analytics to any user, anywhere, any time. Thanks to an architecture designed with extensibility at its core, MicroStrategy delivers an innovative R integration that sets the standard for simplicity, scalability and performance. Now virtually any algorithm, statistic or analysis can be added to the industry's leading Business Intelligence platform thanks to third generation features no other BI product can match:

  • No R left behind: Any R Script, all R packages
  • No Servers Required: R Scripts execute inside the BI engine just like our native analytics
  • Data from MicroStrategy, Results from R, plus easy-to-use function parameters that give end-users process control without any coding required
  • High-Performance, COM-based Execution
  • Centralized RScripts Repository enables fool-proof deployment of analytics from development to production.
  • R Programmers will be impressed with the drag-and-drop deployR() utility that makes capturing the analytic's signature quick and easy
  • On the other hand, even if you're just getting started on the R learning curve -- especially you're an "analytical amateur", someone who loves data and isn't afraid to get on the R learning curve -- you can learn-by-example thanks to the industry's first free on-line collection of "Off-ths-Shelf" R Analytics. These scripts are designed to be deployed as-is with no modification required. Since you don't even have to look at the R code, anyone can add new analytics to their MicroStrategy environment, including powerful new tools like the ARIMA and Random Forecasts predictive algorithms, the k-Means and k-Mediods clustering algorithms, not to mention a complete Statistical Process Control (SPC) Charting solution and a cool data discover tool that that generates lucid Pair-wise Variable Correlation plots and tables. That said, data scientists and especially Analytic Amateurs are welcome to adapt and re-purpose any of the of the source code provided with these Off-the-Shelf scripts.
  • R Scripts are referenced, not embedded, making for easy maintenance and version control
  • R Scripts errors caught and logged
  • One Script, Multiple Execution Modes
  • Support for Windows, Linux, Unix, AIX
  • Transparent R Environment: Persist/Load Files, Objects & Images, Unattended Package Installation
  • Leverages all MicroStrategy platform features, including structured and unstructured data, in-memory cubes, re-usable metadata objects, visual data discovery, enterprise-level security and more, all seamlessly delivered via web and mobile, cloud and office.
  • Available at no extra cost

Getting Started

Conceptually, think of the R Analytic as a black box with an R Script inside. MicroStrategy doesn't need to know much about the R Script in the black box, it only needs to know how to pass data in and, after the script has executed in the R environment, how to consume the results.

RIPBlockDiagram.png

There are three main steps to using the R Integration Pack:

  1. Installation: A one-time install of R and the R Script functions into your MicroStrategy environment, performed by system administrator types or anyone with permissions to install and configure software on the system.
  2. Deployment: Delivering results from R to any BI User is what the R Integration Pack is all about. Thanks to the ever-growing collection of"Off-the-Shelf" R Scripts, you don’t need to know anything about R code, no programming is required. If you can create a metric in MicroStrategy, and practically anyone can, then you can deploy an R Analytic as well. It's really that simple!

Develop-NoNum.png

For more details, please see the R Integration Pack User Guide


Updated Wiki: Home

$
0
0

Project Description

CLICK HERE for the R Integration Pack User Guide

CLICK HERE for the R Script "Shelf" that contains ready-to-go R Analytics

RIPBlockDiagram.png

The MicroStrategy R Integration Pack makes it easy for anyone to deploy sophisticated R Analytics to any user, anywhere, any time. Thanks to an architecture designed with extensibility at its core, MicroStrategy delivers an innovative R integration that sets the standard for simplicity, scalability and performance. Now virtually any algorithm, statistic or analysis can be added to the industry's leading Business Intelligence platform thanks to third generation features no other BI product can match:

  • No R left behind: Any R Script, all R packages
  • No Servers Required: R Scripts execute inside the BI engine just like our native analytics
  • Data from MicroStrategy, Results from R, plus easy-to-use function parameters that give end-users process control without any coding required
  • High-Performance, COM-based Execution
  • Centralized RScripts Repository enables fool-proof deployment of analytics from development to production.
  • R Scripts are referenced, not embedded, making for easy maintenance and version control
  • R Scripts errors caught and logged
  • One Script, Multiple Execution Modes
  • Support for Windows, Linux, Unix, AIX
  • Transparent R Environment: Persist/Load Files, Objects & Images, Unattended Package Installation
  • Leverages all MicroStrategy platform features, including structured and unstructured data, in-memory cubes, re-usable metadata objects, visual data discovery, enterprise-level security and more, all seamlessly delivered via web and mobile, cloud and office.
  • Available at no extra cost

R Programmers will be impressed with the drag-and-drop deployR() utility that makes capturing the analytic's signature quick and easy.

But you don't need to know R to get started! Thanks to the our on-line collection of"Off-ths-Shelf" R Analytics, any MicroStrategy user can inject R analytics to solve common business problems thanks to powerful new tools like the ARIMA, Neural Network and Random Forecasts predictive algorithms, the k-Means and k-Mediods clustering algorithms, Stepwise Linear and Logistic Regression algorithm, even a cool Pairwise Variable Correlation tool. All these analytics leverage the best practices and enterprise-ready robustness features. Data scientists, and especially Analytic Amateurs who want to learn by example, are welcome to adapt and re-purpose any of the of the source code provided with these Off-the-Shelf scripts.

Getting Started

Conceptually, think of the R Analytic as a black box with an R Script inside. MicroStrategy doesn't need to know much about the R Script in the black box, it only needs to know how to pass data in and, after the script has executed in the R environment, how to consume the results.

RIPBlockDiagram.png

There are three main steps to using the R Integration Pack:

  1. Installation: A one-time install of R and the R Script functions into your MicroStrategy environment, performed by system administrator types or anyone with permissions to install and configure software on the system.
  2. Deployment: Delivering results from R to any BI User is what the R Integration Pack is all about. Thanks to the ever-growing collection of"Off-the-Shelf" R Scripts, you don’t need to know anything about R code, no programming is required. If you can create a metric in MicroStrategy, and practically anyone can, then you can deploy an R Analytic as well. It's really that simple!

Develop-NoNum.png

For more details, please see the R Integration Pack User Guide

Updated Wiki: R Script "Shelf"

$
0
0
<!-- https://rintegrationpack.codeplex.com/wikipage?title=RShelf-v1_RevB2 https://rintegrationpack.codeplex.com/wikipage?title=R%20Script%20%22Shelf%22-->

R Scripts "Shelf"

These ready-to-go R Analytics 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, click on name to jump to that analytic)
ForecastingClassificationDescriptive


New!

Click Here: If you haven't already completed the installation steps for R and/or the R Integration Pack.
Click Here: For details on how to deploy these analytics using MicroStrategy.

R AnalyticMetric Expression
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="SeasonalForecasting.R", _InputNames="Target, Trend, Season", StringParam9="">(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="ARIMA.R", _InputNames="Target", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(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="kMeansClustering.R", _InputNames="Vars", NumericParam1=4, NumericParam2=10, StringParam9="">(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
StorePerformance.mstr
Cluster&RegionRevenue.xlsx

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="kMedoidsClustering.R", _InputNames="Vars", NumericParam1=4, NumericParam2=10, StringParam9="">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", NumericParam1=4, NumericParam2=10, StringParam9="">(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="kNN.R", _InputNames="ID, Target, Training, Vars", BooleanParam9=TRUE, NumericParam1=1, StringParam9="kNN">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, NumericParam1=1, StringParam9="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="NaiveBayes.R", _InputNames="Target, Vars", BooleanParam9=TRUE, StringParam9="NaiveBayes", NumericParam1=1>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="NaiveBayes", NumericParam1=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="NeuralNetwork.R", _InputNames="Target, Vars", StringParam9="NeuralNetwork", BooleanParam9=TRUE, NumericParam1=3, NumericParam2=42>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", StringParam9="NeuralNetwork", BooleanParam9=TRUE, NumericParam1=3, NumericParam2=42>(Target, Vars)RScript<_RScriptFile="NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42>(Target, Vars)
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="PairwiseCorr.R", _InputNames="Labels, Vars", BooleanParam1=TRUE, NumericParam1=0, StringParam8="PairwiseCorr", StringParam9="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="RandomForest.R", _InputNames="Target, Vars", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="RandomForest.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Logistic Regression is a variant on classical Logistic 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="StepwiseLogisticRegression.R", _InputNames="Target, Vars", StringParam9="", BooleanParam1=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="StepwiseRegression.R", _InputNames="Target, Vars", StringParam9="StepwiseRegression", BooleanParam1=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
Survival_v1.pdfDocumentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="Survival.R", _InputNames="Time, Status, Vars", BooleanParam9=FALSE, StringParam9="">(Time, Status, Vars)

How to use:

RScriptsSourcing_v1.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. 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.

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: Home

$
0
0

Project Description

CLICK HERE for the R Integration Pack User Guide

CLICK HERE for the R Script "Shelf" that contains ready-to-go R Analytics

RIPBlockDiagram.png

The MicroStrategy R Integration Pack makes it easy for anyone to deploy sophisticated R Analytics to any user, anywhere, any time. Thanks to an architecture designed with extensibility at its core, MicroStrategy delivers an innovative R integration that sets the standard for simplicity, scalability and performance. Now virtually any algorithm, statistic or analysis can be added to the industry's leading Business Intelligence platform thanks to third generation features no other BI product can match:

  • No R left behind: Any R Script, all R packages
  • No Servers Required: R Scripts execute inside the BI engine just like our native analytics
  • Data from MicroStrategy, Results from R, plus easy-to-use function parameters that give end-users process control without any coding required
  • High-Performance, COM-based Execution
  • Centralized RScripts Repository enables fool-proof deployment of analytics from development to production.
  • R Scripts are referenced, not embedded, making for easy maintenance and version control
  • R Scripts errors caught and logged
  • One Script, Multiple Execution Modes
  • Support for Windows, Linux, Unix, AIX
  • Transparent R Environment: Persist/Load Files, Objects & Images, Unattended Package Installation
  • Leverages all MicroStrategy platform features, including structured and unstructured data, in-memory cubes, re-usable metadata objects, visual data discovery, enterprise-level security and more, all seamlessly delivered via web and mobile, cloud and office.
  • Available at no extra cost

R Programmers will be impressed with the drag-and-drop deployR() utility that makes capturing the analytic's signature quick and easy.

But you don't need to know R to get started! Thanks to our on-line collection of"Off-the-Shelf" R Analytics, any MicroStrategy user can inject R analytics to solve common business problems. Included with these analytics are powerful new tools like the predictive algorithms for ARIMA, Neural Network, Random Forests, Stepwise Linear and Logistic Regression algorithms, a cool Pairwise Variable Correlation visualization and many more. All these analytics leverage MicroStrategy's best practices and enterprise-ready robustness features. Data scientists, and especially Analytic Amateurs who want to learn by example, are welcome to adapt and re-purpose any of the of the source code provided with these Off-the-Shelf scripts.

Getting Started

Conceptually, think of the R Analytic as a black box with an R Script inside. MicroStrategy doesn't need to know much about the R Script in the black box, it only needs to know how to pass data in and, after the script has executed in the R environment, how to consume the results.

RIPBlockDiagram.png

There are three main steps to using the R Integration Pack:

  1. Installation: A one-time install of R and the R Script functions into your MicroStrategy environment, performed by system administrator types or anyone with permissions to install and configure software on the system.
  2. Deployment: Delivering results from R to any BI User is what the R Integration Pack is all about. Thanks to the ever-growing collection of"Off-the-Shelf" R Scripts, you don’t need to know anything about R code, no programming is required. If you can create a metric in MicroStrategy, and practically anyone can, then you can deploy an R Analytic as well. It's really that simple!

Develop-NoNum.png

For more details, please see the R Integration Pack User Guide

Updated Wiki: R Script "Shelf"

$
0
0

<!-- https://rintegrationpack.codeplex.com/wikipage?title=RShelf-v1_RevB2 https://rintegrationpack.codeplex.com/wikipage?title=R%20Script%20%22Shelf%22-->

R Scripts "Shelf"

These ready-to-go R Analytics 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, click on name to jump to that analytic)
ForecastingClassificationDescriptive


New!

Click Here: If you haven't already completed the installation steps for R and/or the R Integration Pack.
Click Here: For details on how to deploy these analytics using MicroStrategy.

R AnalyticMetric Expression
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="SeasonalForecasting.R", _InputNames="Target, Trend, Season", StringParam9="">(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="ARIMA.R", _InputNames="Target", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(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="kMeansClustering.R", _InputNames="Vars", NumericParam1=4, NumericParam2=10, StringParam9="">(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
StorePerformance.mstr
Cluster&RegionRevenue.xlsx

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="kMedoidsClustering.R", _InputNames="Vars", NumericParam1=4, NumericParam2=10, StringParam9="">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", NumericParam1=4, NumericParam2=10, StringParam9="">(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="kNN.R", _InputNames="ID, Target, Training, Vars", BooleanParam9=TRUE, NumericParam1=1, StringParam9="kNN">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, NumericParam1=1, StringParam9="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="NaiveBayes.R", _InputNames="Target, Vars", BooleanParam9=TRUE, StringParam9="NaiveBayes", NumericParam1=1>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="NaiveBayes", NumericParam1=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="NeuralNetwork.R", _InputNames="Target, Vars", StringParam9="NeuralNetwork", BooleanParam9=TRUE, NumericParam1=3, NumericParam2=42>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", StringParam9="NeuralNetwork", BooleanParam9=TRUE, NumericParam1=3, NumericParam2=42>(Target, Vars)RScript<_RScriptFile="NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42>(Target, Vars)
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="PairwiseCorr.R", _InputNames="Labels, Vars", BooleanParam1=TRUE, NumericParam1=0, StringParam8="PairwiseCorr", StringParam9="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="RandomForest.R", _InputNames="Target, Vars", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="RandomForest.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Logistic Regression is a variant on classical Logistic 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="StepwiseLogisticRegression.R", _InputNames="Target, Vars", StringParam9="", BooleanParam1=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="StepwiseRegression.R", _InputNames="Target, Vars", StringParam9="StepwiseRegression", BooleanParam1=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
Survival_v1.pdfDocumentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="Survival.R", _InputNames="Time, Status, Vars", BooleanParam9=FALSE, StringParam9="">(Time, Status, Vars)

How to use:

RScriptsSourcing_v1.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. 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.

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: R Script "Shelf"

$
0
0

R Scripts "Shelf"

These ready-to-go R Analytics 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, click on name to jump to that analytic)
ForecastingClassificationDescriptive


New!

Click Here: If you haven't already completed the installation steps for R and/or the R Integration Pack.
Click Here: For details on how to deploy these analytics using MicroStrategy.

R AnalyticMetric Expression
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="SeasonalForecasting.R", _InputNames="Target, Trend, Season", StringParam9="">(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="ARIMA.R", _InputNames="Target", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastLo1 returns the forecasted lower value of the first confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo1", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastHi1 returns the forecasted upper value of the first confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi1", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastLo2 returns the forecasted lower value of the second confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastLo2", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(Target)
ForecastHi2 returns the forecasted upper value of the second confidence band:
RScript<_RScriptFile="ARIMA.R", _InputNames="Target", _OutputVar="ForecastHi2", SortBy=(Month), NumericParam1=12, NumericParam2=12, NumericParam3=80, NumericParam4=95, StringParam8="", StringParam9="">(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="kMeansClustering.R", _InputNames="Vars", NumericParam1=4, NumericParam2=10, StringParam9="">(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
StorePerformance.mstr
Cluster&RegionRevenue.xlsx

Back to Contents
Cluster returns the cluster to which the record belongs:
RScript<_RScriptFile="kMedoidsClustering.R", _InputNames="Vars", NumericParam1=4, NumericParam2=10, StringParam9="">(Vars)
Medoids returns the cluster if a record is the mediod of that cluster, 0 otherwise:
RScript<_RScriptFile="kMedoidsClustering.R", _InputNames="Vars", _OutputVar="Medoids", NumericParam1=4, NumericParam2=10, StringParam9="">(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="kNN.R", _InputNames="ID, Target, Training, Vars", BooleanParam9=TRUE, NumericParam1=1, StringParam9="kNN">(ID, Target, Training, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="kNN.R", _InputNames="ID, Target, Training, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, NumericParam1=1, StringParam9="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="NaiveBayes.R", _InputNames="Target, Vars", BooleanParam9=TRUE, StringParam9="NaiveBayes", NumericParam1=1>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="NaiveBayes.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="NaiveBayes", NumericParam1=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="NeuralNetwork.R", _InputNames="Target, Vars", StringParam9="NeuralNetwork", BooleanParam9=TRUE, NumericParam1=3, NumericParam2=42>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", StringParam9="NeuralNetwork", BooleanParam9=TRUE, NumericParam1=3, NumericParam2=42>(Target, Vars)RScript<_RScriptFile="NeuralNetwork.R", _InputNames="Target, Vars", _OutputVar="ClassId", _Params="FileName='NeuralNetwork', TrainMode=TRUE, NumLayer=3, Seed=42>(Target, Vars)
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="PairwiseCorr.R", _InputNames="Labels, Vars", BooleanParam1=TRUE, NumericParam1=0, StringParam8="PairwiseCorr", StringParam9="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="RandomForest.R", _InputNames="Target, Vars", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
ClassId returns the predicted class as a number:
RScript<_RScriptFile="RandomForest.R", _InputNames="Target, Vars", _OutputVar="ClassId", BooleanParam9=TRUE, StringParam9="RandomForest", NumericParam1=750, NumericParam2=3, NumericParam3=42>(Target, Vars)
Stepwise Logistic Regression

Stepwise Logistic Regression is a variant on classical Logistic 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="StepwiseLogisticRegression.R", _InputNames="Target, Vars", StringParam9="", BooleanParam1=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="StepwiseRegression.R", _InputNames="Target, Vars", StringParam9="StepwiseRegression", BooleanParam1=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
Survival_v1.pdfDocumentation

Back to Contents
Risk returns the risk of an event occurring relative to the average :
RScript<_RScriptFile="Survival.R", _InputNames="Time, Status, Vars", BooleanParam9=FALSE, StringParam9="">(Time, Status, Vars)

How to use:

RScriptsSourcing_v1.png

These R Analytics are deployed to MicroStrategy as metrics by copying the metric expressions provided here into any MicroStrategy Metric Editor. 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.

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


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>