phit

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');

Sample by neighborhood

Neighborhood Rentals Mean area (m²) Mean rent
Riverside 455 82.1 2,174
Old Town 501 85.5 2,589
Hillcrest 476 85.3 2,441
Harbor 507 84.0 2,711
University 524 82.8 2,331
Northgate 537 84.3 2,115

Estimates

Term True value Estimate Std. error 95% CI CI covers true value
(Intercept) 400.0 420.8 11.4 [398.4, 443.2] Yes
area_m2 18.0 17.6 0.2 [17.2, 18.1] Yes
bedrooms 120.0 128.2 5.7 [117.1, 139.3] Yes
neighborhoodOld Town 350.0 337.2 9.8 [318.1, 356.4] Yes
neighborhoodHillcrest 200.0 192.8 9.9 [173.4, 212.2] Yes
neighborhoodHarbor 500.0 490.3 9.7 [471.2, 509.4] Yes
neighborhoodUniversity 150.0 143.4 9.7 [124.5, 162.4] Yes
neighborhoodNorthgate -100.0 -111.5 9.6 [-130.4, -92.7] Yes

n = 3,000. Residual SD = 150.7, and the true value is 150.0.

Neighborhood effects

Points are estimates with 95% confidence intervals. Red diamonds mark the true values.