Provides econometric modeling capabilities through R, enabling AI assistants to perform sophisticated analyses including linear regression, panel data models, instrumental variables regression, and diagnostic tests.
A Model Context Protocol (MCP) server that provides advanced econometric modeling and data analysis capabilities through R. This server enables AI assistants to perform sophisticated econometric and statistical analyses seamlessly, helping you quickly gain insights from your data.
Build the Docker image:
docker build -t r-econometrics-mcp .
Run the container:
docker run -it r-econometrics-mcp
Install the required Python packages:
pip install -r requirements.txt
Install the required R packages (if you run the server outside a container):
install.packages(c("plm", "lmtest", "sandwich", "AER", "jsonlite"), repos="https://cloud.r-project.org/")
Run the server:
python rmcp.py
The server communicates via standard input/output. When you run:
python rmcp.py
it starts and waits for JSON messages on standard input. To test the server manually, create a file (for example, test_request.json) with a compact (single-line) JSON message.
Create test_request.json with the following content (a one-line JSON):
{"tool": "linear_model", "args": {"formula": "y ~ x1", "data": {"x1": [1,2,3,4,5], "y": [1,3,5,7,9]}, "robust": false}}
Then run:
cat test_request.json | python rmcp.py
Output
{"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}
Here are some example queries you can use with Claude once the server is connected:
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?
Run a linear regression model.
Parameters:
formula
(string): The regression formula (e.g., 'y ~ x1 + x2')data
(object): Dataset as a dictionary/JSON objectrobust
(boolean, optional): Whether to use robust standard errorsRun a panel data model.
Parameters:
formula
(string): The regression formula (e.g., 'y ~ x1 + x2')data
(object): Dataset as a dictionary/JSON objectindex
(array): Panel index variables (e.g., ['individual', 'time'])effect
(string, optional): Type of effects: 'individual', 'time', or 'twoways'model
(string, optional): Model type: 'within', 'random', 'pooling', 'between', or 'fd'Perform model diagnostics.
Parameters:
formula
(string): The regression formula (e.g., 'y ~ x1 + x2')data
(object): Dataset as a dictionary/JSON objecttests
(array): Tests to run (e.g., ['bp', 'reset', 'dw'])Estimate instrumental variables regression.
Parameters:
formula
(string): The regression formula (e.g., 'y ~ x1 + x2 | z1 + z2')data
(object): Dataset as a dictionary/JSON objecteconometrics:formulas
: Information about common econometric model formulationseconometrics:diagnostics
: Reference for diagnostic testseconometrics:panel_data
: Guide to panel data analysis in RContributions are welcome! Please feel free to submit a Pull Request.
MIT License
Discover shared experiences
Shared threads will appear here, showcasing real-world applications and insights from the community. Check back soon for updates!