Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for predict with DataFrame #335

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ function predict(mm::LinearModel, newx::AbstractMatrix;
else
error("only :confidence and :prediction intervals are defined")
end
retinterval = quantile(TDist(dof_residual(mm)), (1. - level)/2) * sqrt.(retvariance)
retinterval = vec(quantile(TDist(dof_residual(mm)), (1. - level)/2) * sqrt.(retvariance))
(prediction = retmean, lower = retmean .+ retinterval, upper = retmean .- retinterval)
end

Expand Down
12 changes: 12 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,18 @@ end
@test pred3.upper ≈ pred3.prediction + quantile(TDist(dof_residual(mm)), 0.975)*sqrt.(diag(newX*vcov(mm)*newX') .+ deviance(mm)/dof_residual(mm)) ≈
[3.9288331595737196, 4.077092463922373, 4.762903743958081, 3.82184595169028, 4.034521019386702]

mm = fit(LinearModel, @formula(y ~ 0 + x1 + x2),
DataFrame(y=Ylm, x1=X[:, 1], x2=X[:, 2]))
pred4 = predict(mm, DataFrame(newX, :auto), interval=:confidence)
@test pred4.prediction == pred2.prediction
@test pred4.lower == pred2.lower
@test pred4.upper == pred2.upper

pred5 = predict(mm, DataFrame(newX, :auto), interval=:prediction)
@test pred5.prediction == pred3.prediction
@test pred5.lower == pred3.lower
@test pred5.upper == pred3.upper

# Prediction with dropcollinear (#409)
x = [1.0 1.0
1.0 2.0
Expand Down