QScript Turf

From Q
Jump to navigation Jump to search

Turf

Runs TURF optimization on a Pick Any question. Each variable in the Pick Any question represents survey responses to a particular alternative. TURF optimization computes the top portfolios of a given size in terms of portfolio reach, with ties broken by portfolio frequency.

baseN

A readonly number that is the Base n (unweighted total sample size).

basePopulation

A readonly number that is the Base Population (weighted total sample size).

equals(obj)

Whether two objects are the same.
objThe object to compare against.
Returns:true or false
Example:
data_file.getQuestionByName('Q2').equals(data_file.questions()[0])

excludedAlternatives

A readonly array of labels of variables (alternatives) that have been excluded from the TURF analysis as their proportion is less than minimumProportionOfPositiveResponses.

failed

A read-only property that is true if the input data is not appropriate.

failureMessage

A read-only property that contains a string explaining why the input data is not appropriate if failed is true.

forcedAlternatives

Gets/sets an array of variables in the input question that correspond to alternatives that must be in the optimal portfolios. The default is an empty array. Note that minimumPortfolioSize and maximumPortfolioSize are set to the number of forced alternatives if they were previously less than this number.
Example:
turf.forcedAlternatives = [var_1, var_2]; // var_1 and var_2 are variables from the input question.

maximumPortfolioSize

Gets/sets the maximum size of the portfolios considered in TURF optimization. Must be at least as large as minimumPortfolioSize. The default value is 8. maximumPortfolioSize must be greater than or equal to the number of forced alternatives.
Example:
turf.maximumPortfolioSize = 12;

minimumAlternativesPerCase

Gets/sets the minimum number of alternatives that each respondent has to select in order for the respondent to be counted in the portfolio's reach. The default value is 1.
Example:
turf.minimumAlternativesPerCase = 2;

minimumPortfolioSize

Gets/sets the minimum size of the portfolios considered in TURF optimization. Must be a value from 1 to maximumPortfolioSize. The default value is 1. minimumPortfolioSize must be greater than or equal to the number of forced alternatives.
Example:
turf.minimumPortfolioSize = 4;

minimumProportionOfPositiveResponses

Gets/sets the minimum proportion of positive responses that each alternative must have in order to be considered in the portfolio optimization process. The default value is 0, which means that all alternatives will be considered. Must be a value from 0 to 1.
Example:
turf.minimumProportionOfPositiveResponses = 0.2;

missingN

A readonly number that is the Missing n (number of observations with missing data).

mutuallyExclusiveAlternatives

Gets/sets an array of arrays which each contain variables (alternatives) that cannot appear in the same portfolio. The variables must be from the input question.
Example:
turf.mutuallyExclusiveAlternatives = [[var_1, var_2]]; // var_1 and var_2 will not appear in the same portfolio.

numberOfCombinations

A readonly property of the number of combinations considered in the TURF analysis. If this is greater than 2^63 - 1 (9,223,372,036,854,775,807) then 2^63 - 1 is returned.

numberOfIterations

Gets/sets the number of iterations in the stochastic optimization method. The default value is 20.
Example:
turf.numberOfIterations = 50;

numberOfPortfolios

Gets/sets the maximum number of optimal portfolios to record for each portfolio size. The default value is 1, which means that only the best portfolio is displayed.
Example:
turf.numberOfPortfolios = 20;

optimalPortfolios(portfolio_size)

Returns an array containing the optimal portfolios of size portfolio_size, in order of descending reach, then descending frequency. portfolio_size must be an integer from minimumPortfolioSize to maximumPortfolioSize.
portfolio_sizeThe size of the optimal portfolios that are returned.
Example:
var portfolios = turf.optimalPortfolios(5);
log('The reach of the most optimal portfolio of size 5 is: ' + portfolios[0].reach);

optimizationMethod

Gets/sets the optimization method used to find the optimal TURF portfolios. Must be the strings 'Default', 'Exhaustive' or 'Stochastic'. When set to 'Default', if the total number of portfolio combinations considered is less than thresholdNumberOfCombinations, then the 'Exhaustive' method is used. Otherwise, the 'Stochastic' method is used. The 'Exhaustive' method iterates through every single valid portfolio to find the optimal portfolios. The 'Stochastic' method finds optimal portfolios via a hill-climbing method with random starting points. While the 'Stochastic' method is much faster for cases with a large number of combinations, it does not guarantee the best portfolios, although in most cases the results are identical.
Example:
turf.optimizationMethod = 'Stochastic';

thresholdNumberOfCombinations

Gets/sets the threshold number of combinations used in the 'Default' optimization method. See the optimizationMethod property for more details. The default value is 1,000,000.
Example:
turf.thresholdNumberOfCombinations = 1000;

type

Returns 'Turf'.

See also