英文:
In Vega lite (Deneb) how do I apply a parameter list of regression types to a calculated regression line
问题
I have created a "poly" regression line for a scatterplot in vega lite similar to the below.
我已经为散点图创建了一个“poly”回归线,类似于下面的图表。
I have also created a parameter list, listing the types of regression (linear, log, etc.)
我还创建了一个参数列表,列出了回归的类型(线性、对数等)。
However, I am unable to correctly map the list so that I am able to switch between different types of regression calcs. So I am looking for some advice.
然而,我无法正确地映射该列表,以便能够在不同类型的回归计算之间切换。所以我正在寻求一些建议。
在下面的代码中,我尝试替换:
"method": "poly",
with
"method": {"expr": "regressionline"}
where "regressionline" is the name of my parameter list, but I dont think it is correct.
在下面的代码中,我尝试将:
"method": "poly",
替换为
"method": {"expr": "regressionline"}
其中"regressionline"是我的参数列表的名称,但我认为这不正确。
I was wondering if it is actually possible, and if there is another method.
我在想这是否真的可能,并且是否有其他方法。
Many thanks
非常感谢
英文:
I have created a "poly" regression line for a scatterplot in vega lite similar to the below.
I have also created a parameter list, listing the types of regression (linear, log, etc.)
However, I am unable to correctly map the list so that I am able to switch between different types of regression calcs. So I am looking for some advice.
In the below code, I have tried replacing:
"method": "poly",
with
"method": {"expr": "regressionline"}
where "regressionline" is the name of my parameter list, but I dont think it is correct.
I was wondering if it is actually possible, and if there is another method.
Many thanks
{
"data": {"name": "dataset"},
"params": [
{
"name": "regressionline",
"value": "linear",
"bind": {
"input": "radio",
"options": [
"linear",
"log",
"exp",
"pow",
"quad",
"poly"
]
}
}
],
"layer": [
{
"mark": "rect",
"encoding": {
"x": {
"bin": {"maxbins": 20},
"field": "Total Ref Estimate - RF",
"title": "Total Estimate"
},
"y": {
"bin": {"maxbins": 10},
"field": "Premarket % Costs",
"title": "Premarket % Costs"
},
"color": {
"aggregate": "count",
"scale": {
"scheme": "goldgreen"
},
"legend": {
"direction": "horizontal",
"gradientLength": 120,
"orient": "none",
"legendX": 500,
"legendY": 10
}
}
}
},
{
"mark": {
"type": "point",
"tooltip": true,
"color": "white",
"stroke": "black",
"strokeWidth": 0.5,
"size": 25
},
"encoding": {
"x": {
"field": "Total Ref Estimate - RF",
"type": "quantitative",
"axis": {
"format": "$.1s",
"labelFontSize": 10
},
"scale": {
"domain": [0, 70000000]
}
},
"y": {
"field": "Premarket % Costs",
"type": "quantitative",
"scale": {"domain": [0, 1]},
"axis": {
"format": ".0%",
"labelFontSize": 10
}
},
"xOffset": {
"field": "External ID"
}
}
},
{
"mark": {
"type": "line",
"color": "firebrick",
"strokeWidth": 2.5,
"strokeDash": [1, 4]
},
"transform": [
{
"regression": "Premarket % Costs",
"on": "Total Ref Estimate - RF",
"method": "poly",
"extent": [1000000, 30000000]
}
],
"encoding": {
"x": {
"field": "Total Ref Estimate - RF",
"type": "quantitative"
},
"y": {
"field": "Premarket % Costs",
"type": "quantitative"
}
}
},
{
"transform": [
{
"regression": "Premarket % Costs",
"on": "Total Ref Estimate - RF",
"method": "poly",
"extent": [1000000, 30000000],
"params": true
},
{
"calculate": "'R²: '+format(datum.rSquared, '.2f')",
"as": "R2"
}
],
"mark": {
"type": "text",
"color": "firebrick",
"x": "width",
"align": "right",
"y": -5
},
"encoding": {
"text": {
"type": "nominal",
"field": "R2"
}
}
}
]
}
答案1
得分: 1
以下对我有效。
"method": {"signal": "regressionline"},
模式引发验证错误(因为VL不明确支持信号),但这确实有效,我可以成功地在线性、二次和多项式之间切换。对于其他方法的有效性我不太确定,因为我已经有一段时间没有研究线性回归了。
英文:
The following works for me.
"method": {"signal": "regressionline"},
The schema throws a validation error (as VL doesn't support signals explicitly) but this does work and I can successfully switch between linear, quad and poly. Not sure about the validity of the other methods as I haven't looked at linear regressions in a while.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论