Product: TIBCO Spotfire®
How to implement a Winsorized mean function using Spotfire Expression Functions.
A Winsorized mean is a Winsorized statistical measure of central tendency, much like the mean and median, and even more similar to the truncated mean (available directly in the Spotfire expression as the TrimmedMean() function). It involves the calculation of the mean after replacing certain parts of a probability distribution or sample at the high and low ends with the most extreme remaining values, typically doing so for an equal amount at both extremes.
To define a new custom function, select Edit > Data Function Properties from the Spotfire desktop client's main menu, then select the "Expression Functions" tab in the "Data Function Properties" dialog. Here you’ll be able to add a new function or edit existing ones. Custom functions consist of a script using TERR/R syntax that includes the function declaration, along with the output assignment.
1). In Edit > Data Function Properties > Expression Functions, create a new function by clicking the 'New' button.
2). Enter the following details:
Name: WinsorizedMean
Description: Calculates the mean after replacing certain parts of a probability distribution at the high and low ends with the most extreme remaining values, typically doing so for an equal amount at both extremes.Example: WinsorizedMean(arg1)
Category: Statistical functions
Return type: Real
Script:
# Define the TrimmedMeanWinsor function: WinsorizedMean <- function( input ) { p95 <- quantile( input, .95 ) p05 <- quantile( input, .05 ) input <- replace( input, input < p05, p05 ) input <- replace( input, input > p95, p95 ) out <- mean( input ) out } # Run the function to produce the output output <- rep( WinsorizedMean( input1 ), length( input1 ) )
3). Click "OK" to save the Expression Function.
When using custom expressions in Spotfire, you can now use the custom WinsorizedMean() function by passing it a single column. For example:
WinsorizedMean([myColumn1])
See the attached (Filename: WinsorizedMean.png).
Note:
This uses a hard coded p95 and p05 percentiles for the upper and lower limits used in the Winsorizing. The .95 and .05 values can be manually adjusted as required. Additionally, you could modify the Expression Function to take two additional arguments, so you pass the upper and lower limits explicitly.
Disclaimer:
External: Winsorized Mean
Comments
0 comments
Article is closed for comments.