phit
Examples

Predicting rent with a linear model

Fit monthly rent on floor area and bedrooms for 400 simulated flats, then predict with 95% prediction intervals.
Uses phit

Inputs

Running

fit_lm() fits monthly rent on floor area and bedrooms, as R's lm() would. predict() evaluates the fit on new data, here with 95% prediction intervals for a 2-bedroom flat.

use function Phit\{fit_lm, predict};

$fit = fit_lm('monthly_rent ~ area_m2 + bedrooms', $housing);
$p = predict($fit, ['area_m2' => $areas, 'bedrooms' => $beds], interval: 'prediction');
R²
0.9333
Residual σ
154.75
Observations
400

Coefficients

Term Estimate Std. error t p 95% CI
(Intercept) 457.0119 23.1998 19.70 < 0.0001 [411.402, 502.622]
area_m2 17.8767 0.4331 41.28 < 0.0001 [17.025, 18.728]
bedrooms 93.4212 12.3749 7.55 < 0.0001 [69.093, 117.750]

n = 400, R² = 0.9333, σ = 154.7470, log-likelihood = -2,582.79

Predicted rent for 2 bedrooms

Predictions

area_m2 fit lower upper
30 1,180.15 873.67 1,486.64
45 1,448.3 1,142.94 1,753.67
60 1,716.45 1,411.68 2,021.23
75 1,984.6 1,679.89 2,289.32
90 2,252.75 1,947.56 2,557.95
105 2,520.9 2,214.69 2,827.11
120 2,789.05 2,481.3 3,096.8

Script: site/vignettes/rent-model.php in phpstats/phit@76b22f0.