Stars=CROSS_SECTION("https://cran.r-universe.dev/dslabs/data/stars/csv") Linear=CROSS_SECTION_MODEL(Stars,"column(magnitude)=a+b*column(temp)") Quadratic=CROSS_SECTION_MODEL(Stars,"column(magnitude)=a+b*column(temp)+c*column(temp)^2") LogTemp=CROSS_SECTION_MODEL(Stars,"column(magnitude)=a+b*LOG10(column(temp))") Intro=HTML_SLIDE("

What the Stars Taught Me About Fitting a Model

I am not an astronomer, but I find the science fascinating. A public dataset gives me a way to ask questions, draw pictures, and see where my understanding falls short.

Many astronomical relationships are nonlinear. That curiosity helped inspire RainbowStats’ CROSS_SECTION_MODEL: write an equation, estimate its coefficients, and compare the fitted relationship with the observations.

Our question: how much can a star’s temperature tell us about its absolute magnitude?

An exploration by Bill Igoe · RainbowStats · November 2026

") Dataset=HTML_SLIDE("

Start with the data, not the curve

The dslabs stars dataset is a teaching compilation of selected stars: 96 rows in the version examined here.

ColumnMeaning
starStar name or identifier
magnitudeAbsolute magnitude: smaller numbers mean brighter stars
tempTemperature in kelvin
typeSpectral classification

Absolute magnitude compares brightness at a standard distance. The magnitude scale itself is logarithmic.

The package credits multiple open-access VizieR sources. Names repeat; rows are not necessarily distinct, independent stars.

") Theory=HTML_SLIDE("

Temperature is only part of the story

For a star described by an effective temperature, total luminosity follows:

L = 4πR²σT&sup4;

Radius matters as well as temperature. A cool, large star can be very luminous; a small star can be faint despite being hot.

This dataset mixes stellar populations. A single curve cannot be expected to explain them all.

The equation concerns bolometric luminosity. A magnitude measured in a particular band is not automatically bolometric magnitude. Our fitted temperature slope is not a direct test of the fourth-power law.

") Equations=HTML_SLIDE("

Three equations, the same observations

ModelEquationCoefficients
Linearm = a + bT2
Quadraticm = a + bT + cT²3
Log temperaturem = a + b log10(T)2

All three use least squares. The last two are curved in temperature but remain linear in their unknown coefficients.

We specify the theory-shaped equation; CROSS_SECTION_MODEL estimates a, b, and, where needed, c.

") LinearCurve=EXTRACT(Linear,"curve") QuadraticCurve=EXTRACT(Quadratic,"curve") LogCurve=EXTRACT(LogTemp,"curve") Comparison=HTML_SLIDE("

Which equation fits better?

ModelR²Training RMSELOOCV RMSEAIC
Linear0.4015.6625.752611.34
Quadratic0.4815.2735.443599.64
Log temperature0.5364.9845.070586.85

The logarithmic model performs best on these measures, using one fewer coefficient than the quadratic.

RMSE is in magnitude units; lower is better. LOOCV leaves one row out at a time. AIC balances fit and parameter count.

Recorded from production on November 7, 2026: all 96 rows used, none omitted. This table is a fixed snapshot; the following model summary is computed live. Repeated stars make row-wise validation potentially optimistic.

") LogSummary=EXTRACT(LogTemp,"summary") LogCoefficients=EXTRACT(LogTemp,"model") LogResiduals=EXTRACT(LogTemp,"residual_plot") Interpretation=HTML_SLIDE("

A better curve is not yet an explanation

The quadratic bends upward at the hot end. The logarithmic model keeps declining and fits these observations better overall.

Yet the logarithmic model explains only about 54% of the variation in magnitude. The remaining scatter is part of the scientific question.

Radius, evolutionary stage, composition, and the measurement band can matter. Spectral type alone is not a label for giant, main-sequence star, or white dwarf.

A flexible equation helps us explore a theory. A good fit does not establish that the theory is correct.

") Cautions=HTML_SLIDE("

What this small exercise cannot establish

These plots place temperature increasing to the right and numeric magnitude increasing upward. That differs from the usual orientation of a Hertzsprung–Russell diagram.

") Conclusion=HTML_SLIDE("

Curiosity becomes an equation we can examine

I did not set out to make an astronomical discovery. I wanted to understand what I was looking at.

That led to a useful addition to RainbowStats: write an equation using named data columns, fit it, draw the actual model curve, and examine what remains unexplained.

The same workflow extends beyond astronomy. Multiple columns, transformations, and interactions let us turn proposed relationships into models we can test against data.

The most useful result may be the next question: what information would explain the stars that our curve misses?

") References=HTML_SLIDE("

Appendix: data, physics, and further reading

  1. dslabs: stars documentation — variables and provenance. CSV used here.
  2. Ohio State: Stellar Properties — luminosity, temperature, radius, and the H–R diagram.
  3. NASA: Types of Stars — accessible background on stellar populations and evolution.
  4. robustbase: starsCYG — a related 47-star example with 43 main-sequence stars and four giants; documented in Rousseeuw and Leroy (1987), Robust Regression and Outlier Detection.
  5. Gaia Collaboration (2018): Observational Hertzsprung–Russell diagrams, A&A 616, A10 — further reading on much larger stellar samples, not a study replicated here.
") SLIDESHOW(Intro,Dataset,Theory,Equations,LinearCurve,QuadraticCurve,LogCurve,Comparison,LogSummary,LogCoefficients,LogResiduals,Interpretation,Cautions,Conclusion,References)