简体   繁体   English

如何在 Spotfire 中提取拟合线斜率系数?

[英]How can I extract fitted line slope coefficients in Spotfire?

I have set up a trellis visualization in Spotfire showing line charts for my data.我在 Spotfire 中设置了一个网格可视化,显示了我的数据的折线图。 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.我使用的是 Spotfire 7.6.0.57 版本。 Thanks!谢谢!

When doing the straight line fit, there should be a data table created with a name like YourDataTable_Straight line .在进行直线拟合时,应该创建一个名为YourDataTable_Straight line的数据表。 The regressed coefficients will be there.回归系数将在那里。

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导出曲线拟合的系数

With ar script you are able to get the coefficients into a data frame.使用 ar 脚本,您可以将系数放入数据框中。 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. coef将作为您的输出,作为您的现场分析中的表格。

I've reached to this after reading this: Linear-Regression阅读本文后,我已经达到了这一点:线性回归

and this: TIBCO support和这个: TIBCO 支持

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 ).如果您想建立在 Spotfire 已经计算并显示在图表中的拟合(基于),还有另一个使用 IronPython 的选项。 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.这避免了在 R 中运行另一个拟合并提取那些(可能略有不同)拟合结果,在我的情况下(非常大的数据集)是一个真正的节省时间。 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:因此,注册一个 IronPython 脚本并将以下代码调整为您的页面和可视化标题:

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.结果将是一个名为 [Curve Fit Results] 的附加数据表,其中(在直线拟合的情况下)包含每个直线拟合的截距 a、斜率 b 和 R²。 You can eg tie this script to an action control in a text area to trigger it.例如,您可以将此脚本绑定到文本区域中的操作控件以触发它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM