R MCP 服务器
模型上下文协议 (MCP) 服务器通过 R 提供高级计量经济学建模和数据分析功能。该服务器使 AI 助手能够无缝执行复杂的计量经济学和统计分析,帮助您快速从数据中获得洞察。
Related MCP server: Statsource MCP Server
特征
**线性回归:**运行具有可选稳健标准误差的线性模型。
**面板数据分析:**估计固定效应、随机效应、合并、之间和一阶差分模型。
**工具变量:**建立和估计 IV 回归模型。
**诊断测试:**评估异方差性、自相关性和模型错误指定。
**描述性统计:**使用 R 的 summary() 功能为数据集生成汇总统计数据。
**相关性分析:**计算变量之间的皮尔逊或斯皮尔曼相关性。
**分组聚合:**按指定列对数据进行分组,并使用 dplyr 计算汇总统计数据。
**资源:**访问各种计量经济学技术的参考文献。
**提示:**使用预定义的提示模板进行常见的计量经济学分析。
安装
使用 Docker(推荐)
构建 Docker 镜像:
docker build -t r-econometrics-mcp .运行容器:
docker run -it r-econometrics-mcp手动安装
安装所需的 Python 包:
pip install -r requirements.txt安装所需的 R 包(如果在容器外运行服务器):
install.packages(c("plm", "lmtest", "sandwich", "AER", "jsonlite"), repos="https://cloud.r-project.org/")运行服务器:
python rmcp.py用法
服务器通过标准输入/输出进行通信。运行以下命令:
python rmcp.py它启动后会等待标准输入的 JSON 消息。要手动测试服务器,请创建一个包含紧凑(单行)JSON 消息的文件(例如,test_request.json)。
示例测试
创建具有以下内容的 test_request.json(单行 JSON):
{"tool": "linear_model", "args": {"formula": "y ~ x1", "data": {"x1": [1,2,3,4,5], "y": [1,3,5,7,9]}, "robust": false}}然后运行:
cat test_request.json | python rmcp.py输出
{"coefficients": {"(Intercept)": -1, "x1": 2}, "std_errors": {"(Intercept)": 2.8408e-16, "x1": 8.5654e-17}, "t_values": {"(Intercept)": -3520120717017444, "x1": 23349839270207356}, "p_values": {"(Intercept)": 5.0559e-47, "x1": 1.7323e-49}, "r_squared": 1, "adj_r_squared": 1, "sigma": 2.7086e-16, "df": [2, 3, 2], "model_call": "lm(formula = formula, data = data)", "robust": false}与 Claude Desktop 一起使用
启动 Claude Desktop
打开 MCP 服务器面板
添加具有以下配置的新服务器:
姓名:R计量经济学
传输:stdio
命令:path/to/python r_econometrics_mcp.py
(或者如果使用 Docker):docker run -i r-econometrics-mcp
示例查询
以下是服务器连接后可以与 Claude 一起使用的一些示例查询:
线性回归
Can you analyze the relationship between price and mpg in the mtcars dataset using linear regression?面板数据分析
I have panel data with variables gdp, investment, and trade for 30 countries over 20 years. Can you help me determine if a fixed effects or random effects model is more appropriate?工具变量
I'm trying to estimate the causal effect of education on wages, but I'm concerned about endogeneity. Can you help me set up an instrumental variables regression?诊断测试
After running my regression model, I'm concerned about heteroskedasticity. Can you run appropriate diagnostic tests and suggest corrections if needed?工具参考
线性模型
运行线性回归模型。
参数:
formula(字符串):回归公式(例如,'y ~ x1 + x2')data(对象):作为字典/JSON 对象的数据集robust(布尔值,可选):是否使用稳健标准误差
面板模型
运行面板数据模型。
参数:
formula(字符串):回归公式(例如,'y ~ x1 + x2')data(对象):作为字典/JSON 对象的数据集index(数组):面板索引变量(例如,['individual','time'])effect(字符串,可选):效果类型:“个体”、“时间”或“双向”model(字符串,可选):模型类型:'within'、'random'、'pooling'、'between' 或 'fd'
诊断
执行模型诊断。
参数:
formula(字符串):回归公式(例如,'y ~ x1 + x2')data(对象):作为字典/JSON 对象的数据集tests(数组):要运行的测试(例如,['bp','reset','dw'])
iv_回归
估计工具变量回归。
参数:
formula(字符串):回归公式(例如,'y ~ x1 + x2 | z1 + z2')data(对象):作为字典/JSON 对象的数据集
资源
econometrics:formulas:有关常见计量经济学模型公式的信息econometrics:diagnostics:诊断测试参考econometrics:panel_data:R 面板数据分析指南
贡献
欢迎贡献代码!欢迎提交 Pull 请求。
执照
MIT 许可证