Reputation: 11
I have set up a trellis visualization in Spotfire showing line charts for my data. I've also added a "Straight Line Fit" in the "Lines & Curves" tab of the properties
.
Does anyone know how to access those coefficients of intercept and slope? I would like to sort my visualizations with the slope (most- to least-negative) information calculated.
I'm using the Spotfire 7.6.0.57 build. Thanks!
Upvotes: 1
Views: 4423
Reputation: 320
There is another option using IronPython if you want to build on the fits already computed by Spotfire and shown in the chart (based on this). This avoids running yet another fit in R and extracting those (potentially slightly different) fit results, which in my case (very large data set) was a real time saver. The same would probably work for line charts I reckon. So register an IronPython script and adjust the below code to your page and visualzation titles:
from Spotfire.Dxp.Application.Visuals import ScatterPlot, FittingModels
# grab the fitting model of the first (counting starts at 0!) lines & curves item and export to data table
for page in Document.Pages: #Loop through every page
if page.Title == 'Your Page Title': #find the right page
for viz in page.Visuals: #On this page, loop through every viz
if viz.Title == 'Your Scatter Plot Title': #find the right viz
ScatterPlot=viz.As[ScatterPlot]()
ScatterPlot.FittingModels[0].Enabled=True # [0] is the first fit in the list of fits in the lines & curves section of the properties menue
ds = ScatterPlot.FittingModels[0].GetResultsDataSource()
if Document.Data.Tables.Contains("Curve Fit Results"):
table=Document.Data.Tables["Curve Fit Results"]
table.ReplaceData(ds)
else:
Document.Data.Tables.Add("Curve Fit Results", ds)
The result will be an additional data table called [Curve Fit Results] wich (in case of a straight line fit) holds intercept a, slope b and R² for each straight line fit. You can e.g. tie this script to an action control in a text area to trigger it.
Upvotes: 1
Reputation: 1
With a r script you are able to get the coefficients into a data frame. I've used this one, for exactly that issue:
tb.lm <- lm(y ~ x, data = yourtable)
tb.summary.lm <- summary(tb.lm)
df <- as.data.frame(tb.summary.lm$coefficients)
row.names(df)=c("intercept","slope")
coef <- data.frame(yourColumnname = row.names(df),df)
Where coef
will be your output, as a table in your spotfire analysis.
I've reached to this after reading this: Linear-Regression
and this: TIBCO support
Upvotes: 0
Reputation: 56
Go to the 'Straight Line Fit' in 'Lines & Curves' of the properties, select it and go to 'More'. From there you can export the coefficients to a text file, re-import it and link it's columns to the original data table. Exporting the coefficients of a curve fit
Upvotes: 2
Reputation: 996
When doing the straight line fit, there should be a data table created with a name like YourDataTable_Straight line
. The regressed coefficients will be there.
Upvotes: 0