phit

Binary and count outcomes

This example fits generalized linear models from R formulas. phplyr's glm() passes the formula and the phibble DataFrame to Phit\fit_glm(), which builds R's model matrix and fits the model. The coefficient names, deviances, and AIC follow R's glm().

The logistic and probit models use 80 simulated students, where passed is 1 when a student passed and 0 otherwise. Those outcomes were drawn from a logistic model, so the probit fit shows how the coefficients change with the link. The Poisson model uses 120 simulated clinic records, where calls is a count that rises with visitors and falls with staff. Both data sets come from the phit documentation and are read from CSV files. Checking the interaction box replaces + with *, which adds the product of the two predictors.

Model
Terms
$data = DataFrame::fromCsv('learning.csv');
$fit = $data |> glm('passed ~ study_hours + practice_score', family: 'binomial', link: 'logit');
$data = DataFrame::fromCsv('learning.csv');
$fit = phplyr($data)->glm('passed ~ study_hours + practice_score', family: 'binomial', link: 'logit');
Term Estimate Std. error z p Odds ratio
(Intercept) -3.1710 1.4790 -2.14 0.0320
study_hours 0.0637 0.1132 0.56 0.5737 1.066
practice_score 0.0342 0.0289 1.18 0.2367 1.035

80 observations, binomial family with the logit link. Residual deviance 98.97 on 77 degrees of freedom; null deviance 104.77. AIC = 104.97. McFadden's pseudo R² = 0.055. Converged in 5 iterations.

Predictions

The line is the predicted probability of passing as study hours varies, with the other predictor held at its mean. The band is a 95% confidence interval, computed on the link scale and transformed to the response scale. Points are the observations.