Standardmäßig ist der Prompt ausgewählt, der zuerst die Quelle prüft. Sie können zu einem direkten Befehl wechseln oder eine lokale Kopie herunterladen.
Quelldateien prüfen
Lesen Sie SKILL.md und alle von SkillsMP angezeigten Begleitdateien, bevor Sie sich für eine Installation entscheiden.
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Ein direkter Befehl überspringt den Prüf-Prompt. Prüfen Sie die Quelle, bevor Sie ihn ausführen.
# Create a new Quarto document
quarto create-project my-report --type document
Core Workflow
Step 1: Basic Quarto Document Structure
The following shows the structure of a complete Quarto .qmd file. Save as analysis_report.qmd:
---
title: "Regression Analysis Report"
subtitle: "Quantitative Research Summary"
author:
- name: "Research Team"
affiliation: "University Department"
date: today
abstract: |
This report presents a regression analysis of the simulated dataset.
Key findings include a statistically significant positive relationship
between the predictor and outcome variables.
format:
html:
toc: true
toc-depth: 3
code-fold: true
number-sections: true
theme: cosmo
fig-width: 8
fig-height: 5
pdf:
documentclass: article
geometry: "margin=1in"
number-sections: true
execute:
echo: true
warning: false
message: false
jupyter: python3
---
# Introduction {#sec-intro}
This report analyzes a synthetic dataset to demonstrate reproducible reporting
with Quarto. See @sec-methods for the analytical approach.
# Methods {#sec-methods}## Data Generation```{python}
#| label: setup
#| include: false
import numpy as np
import pandas as pd
import statsmodels.api as sm
import matplotlib.pyplot as plt
from IPython.display import display
np.random.seed(42)
```
We simulated $n = 200$ observations from a linear model
$Y = \beta_0 + \beta_1 X_1 + \beta_2 X_2 + \varepsilon$ where
$\varepsilon \sim \mathcal{N}(0, \sigma^2)$.
```{python}
#| label: data-generation
n = 200
x1 = np.random.normal(5, 2, n)
x2 = np.random.binomial(1, 0.5, n)
y = 3.0 + 1.5 * x1 + 2.0 * x2 + np.random.normal(0, 3, n)
df = pd.DataFrame({"y": y, "x1": x1, "x2": x2})
print(f"Dataset: {len(df)} observations, {df.shape[1]} variables")
```
## Analytical Approach
We fit an OLS regression model and report heteroskedasticity-robust
standard errors (HC3).
# Results {#sec-results}
## Descriptive Statistics
```{python}
#| label: tbl-descriptive
#| tbl-cap: "Descriptive statistics for all variables."
desc = df.describe().round(2)
display(desc)
```
@tbl-descriptive presents the descriptive statistics.
## Regression Results
```{python}
#| label: regression-model
X = sm.add_constant(df[["x1", "x2"]])
model = sm.OLS(df["y"], X).fit(cov_type="HC3")
```
The regression results are shown in @tbl-regression.
```{python}
#| label: tbl-regression
#| tbl-cap: "OLS regression results with HC3 standard errors."
results_df = pd.DataFrame({
"Coefficient": model.params,
"Std. Error": model.bse,
"t-stat": model.tvalues,
"p-value": model.pvalues,
"95% CI Lower": model.conf_int()[0],
"95% CI Upper": model.conf_int()[1],
}).round(3)
display(results_df)
```
The model explains `{python} f"{model.rsquared_adj:.3f}"` of the variance
in the outcome ($\bar{R}^2$).
## Visualization```{python}
#| label: fig-scatter
#| fig-cap: "Scatter plot of X1 vs. Y by group X2."
#| fig-width: 6
#| fig-height: 4
fig, ax = plt.subplots(figsize=(6, 4))
for x2_val, color, label in [(0, "steelblue", "X2=0"), (1, "orange", "X2=1")]:
mask = df["x2"] == x2_val
ax.scatter(df.loc[mask, "x1"], df.loc[mask, "y"],
color=color, alpha=0.5, s=20, label=label)
# Fitted lines
xf = np.linspace(df["x1"].min(), df["x1"].max(), 100)
for x2_val, color in [(0, "steelblue"), (1, "orange")]:
yf = model.params["const"] + model.params["x1"] * xf + model.params["x2"] * x2_val
ax.plot(xf, yf, color=color, lw=2)
ax.set_xlabel("X1"); ax.set_ylabel("Y")
ax.set_title("Fitted Regression Lines by Group")
ax.legend()
plt.tight_layout()
plt.show()
```
@fig-scatter shows the relationship between X1 and Y, stratified by X2.
# Discussion {#sec-discussion}
The coefficient for X1 ($\hat{\beta}_1 = `{python} f"{model.params['x1']:.3f}"`$,
$p `{python} "< 0.001" if model.pvalues['x1'] < 0.001 else f"= {model.pvalues['x1']:.3f}"`$)
indicates a positive relationship.
# Conclusion {#sec-conclusion}
This analysis demonstrates Quarto's capabilities for reproducible reporting.
All figures and tables were generated from the same code that produced
the written results.
# References {.unnumbered}
::: {#refs}
:::
# Render to HTML
quarto render analysis_report.qmd --to html
# Render to PDF
quarto render analysis_report.qmd --to pdf
# Render all formats defined in YAML
quarto render analysis_report.qmd
Step 2: Parameterized Report Generation
# File: generate_reports.py"""Automate parameterized Quarto report generation."""import subprocess
import os
import json
from pathlib import Path
defrender_parameterized_report(
qmd_file,
output_dir,
params,
output_format="html",
):
"""Render a Quarto report with specific parameter values.
Args:
qmd_file: Path to .qmd source file
output_dir: Directory to save output
params: dict of parameter name → value
output_format: output format string
Returns:
Path to rendered output file, or None on failure
"""
Path(output_dir).mkdir(parents=True, exist_ok=True)
# Build parameter flags
param_flags = []
for key, value in params.items():
param_flags.extend(["-P", f"{key}:{value}"])
# Output file name
output_file = Path(output_dir) / f"report_{params.get('dataset', 'default')}.{output_format}"
cmd = [
"quarto", "render", qmd_file,
"--to", output_format,
"--output", str(output_file),
] + param_flags
print(f"Rendering: {' '.join(cmd)}")
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode == 0:
print(f"Success: {output_file}")
return output_file
else:
print(f"Error rendering {qmd_file}:")
print(result.stderr)
returnNone# Example: Generate reports for multiple datasets
datasets = ["2021", "2022", "2023"]
for year in datasets:
render_parameterized_report(
qmd_file="analysis_report.qmd",
output_dir="reports/",
params={"year": year, "alpha": "0.05"},
output_format="html",
)
# Example: Batch generation with different parameter combinationsfrom itertools import product
alphas = [0.01, 0.05]
methods = ["ols", "wls"]
for alpha, method in product(alphas, methods):
report = render_parameterized_report(
"sensitivity_analysis.qmd",
"reports/sensitivity/",
{"alpha": str(alpha), "method": method},
)
Step 3: Quarto Book and Website Setup
# Create a research book project
quarto create-project my-research-book --type book
# Generate a results section text from statistical outputimport numpy as np
import pandas as pd
import statsmodels.api as sm
defformat_p_value(p):
"""Format p-value for publication."""if p < 0.001: return"< .001"elif p < 0.01: returnf"= {p:.3f}"else: returnf"= {p:.3f}"defregression_results_text(model, predictor):
"""Generate APA-style regression results text."""
coeff = model.params[predictor]
se = model.bse[predictor]
t = model.tvalues[predictor]
p = model.pvalues[predictor]
ci_lo, ci_hi = model.conf_int().loc[predictor]
return (
f"The predictor {predictor} was "f"{'significantly'if p < 0.05else'not significantly'} "f"associated with the outcome, "f"b = {coeff:.2f}, SE = {se:.2f}, "f"t({int(model.df_resid)}) = {t:.2f}, p {format_p_value(p)}, "f"95% CI [{ci_lo:.2f}, {ci_hi:.2f}]."
)
np.random.seed(42)
x = np.random.normal(0, 1, 100)
y = 2.5 * x + np.random.normal(0, 1, 100)
model = sm.OLS(y, sm.add_constant(pd.DataFrame({"x": x}))).fit()
print("Generated results text:")
print(regression_results_text(model, "x"))
Example 2: Table Formatting for Publication
import pandas as pd
import numpy as np
defformat_regression_table(models_dict, variable_labels=None):
"""Create publication-ready regression comparison table.
Args:
models_dict: dict of {model_name: statsmodels result}
variable_labels: dict of {variable: display_name}
Returns:
DataFrame suitable for display in Quarto
"""if variable_labels isNone:
variable_labels = {}
all_vars = set()
for model in models_dict.values():
all_vars.update(model.params.index)
all_vars = sorted(all_vars)
rows = []
for var in all_vars:
row = {"Variable": variable_labels.get(var, var)}
for model_name, model in models_dict.items():
if var in model.params:
coef = model.params[var]
se = model.bse[var]
p = model.pvalues[var]
stars = "***"if p < 0.001else"**"if p < 0.01else"*"if p < 0.05else""
row[model_name] = f"{coef:.3f}{stars}\n({se:.3f})"else:
row[model_name] = "—"
rows.append(row)
df = pd.DataFrame(rows)
# Add fit statisticsfor stat_name, stat_fn in [("R²", lambda m: f"{m.rsquared:.3f}"),
("Adj. R²", lambda m: f"{m.rsquared_adj:.3f}"),
("N", lambda m: str(int(m.nobs)))]:
row = {"Variable": stat_name}
for model_name, model in models_dict.items():
row[model_name] = stat_fn(model)
rows.append(row)
return pd.DataFrame(rows)
# Demo
np.random.seed(42)
n = 200
x1 = np.random.normal(0, 1, n)
x2 = np.random.normal(0, 1, n)
y = 1.5 * x1 + 0.8 * x2 + np.random.normal(0, 1, n)
import statsmodels.api as sm
m1 = sm.OLS(y, sm.add_constant(pd.DataFrame({"x1": x1}))).fit()
m2 = sm.OLS(y, sm.add_constant(pd.DataFrame({"x1": x1, "x2": x2}))).fit()
table = format_regression_table({"Model 1": m1, "Model 2": m2},
{"const": "Intercept", "x1": "Predictor 1", "x2": "Predictor 2"})
print("Publication-ready regression table:")
print(table.to_string(index=False))