Simulated rents
The data on this page is simulated. It does not describe real rentals.
The app's database holds 3,000 simulated rentals in six neighborhoods. Each monthly rent was generated from known coefficients for floor area, bedrooms, and neighborhood, plus normal noise with a standard deviation of 150. Riverside is the reference neighborhood.
The page fits a linear regression with phit and compares each estimate with the value used to generate the data. Coefficient names follow R, so the Old Town effect is neighborhoodOld Town. Smaller samples give wider confidence intervals.
Code
phibble reads the table through Eloquent and phplyr summarises it. phplyr's lm() passes the formula and the data to phit, which builds the model matrix as R does. Setting the factor levels makes Riverside the reference neighborhood.
$rentals = DataFrame::fromQuery(SimulatedRental::query()->orderBy('id'))
->asFactor('neighborhood', ['Riverside', 'Old Town', 'Hillcrest', 'Harbor', 'University', 'Northgate']) |>
head($n);
$byNeighborhood = $rentals |>
group_by('neighborhood') |>
summarise(rentals: n(), mean_area: mean('area_m2'), mean_rent: mean('monthly_rent')) |>
arrange('neighborhood');
$fit = $rentals |> lm('monthly_rent ~ area_m2 + bedrooms + neighborhood');
$rentals = phplyr(DataFrame::fromQuery(SimulatedRental::query()->orderBy('id'))
->asFactor('neighborhood', ['Riverside', 'Old Town', 'Hillcrest', 'Harbor', 'University', 'Northgate']))
->head($n)
->get();
$byNeighborhood = phplyr($rentals)
->groupBy('neighborhood')
->summarise(rentals: n(), mean_area: mean('area_m2'), mean_rent: mean('monthly_rent'))
->arrange('neighborhood')
->get();
$fit = phplyr($rentals)->lm('monthly_rent ~ area_m2 + bedrooms + neighborhood');