Skip to content

Commit

Permalink
Merge f1a0669 into 8621065
Browse files Browse the repository at this point in the history
  • Loading branch information
nalimilan committed Sep 11, 2018
2 parents 8621065 + f1a0669 commit d467307
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
9 changes: 5 additions & 4 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,17 @@ julia> predict(ols)
4.33333
6.83333
```
<!-- Andreas Noack: As of 9 May 2018 this example doesn't work so I've temporarily commented it out
julia> newX = DataFrame(X=[2,3,4]);
julia> predict(ols, newX, :confint)
julia> predict(ols, newX, interval=:confint)
3×3 Array{Float64,2}:
4.33333 1.33845 7.32821
6.83333 2.09801 11.5687
9.33333 1.40962 17.257
The columns of the matrix are prediction, 95% lower and upper confidence bounds -->
```

The columns of the matrix are prediction, 95% lower and upper confidence bounds
.

### Probit Regression:
```jldoctest
Expand Down
1 change: 1 addition & 0 deletions src/GLM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,6 @@ module GLM
include("glmfit.jl")
include("ftest.jl")
include("negbinfit.jl")
include("deprecated.jl")

end # module
1 change: 1 addition & 0 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@Base.deprecate predict(mm::LinearModel, newx::AbstractMatrix, interval::Symbol, level::Real = 0.95) predict(mm, newx; interval=interval, level=level)
18 changes: 11 additions & 7 deletions src/lm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,23 @@ function coeftable(mm::LinearModel)
["x$i" for i = 1:size(mm.pp.X, 2)], 4)
end

predict(mm::LinearModel, newx::AbstractMatrix) = newx * coef(mm)

"""
predict(mm::LinearModel, newx::AbstractMatrix, interval_type::Symbol, level::Real = 0.95)
predict(mm::LinearModel, newx::AbstractMatrix;
interval::Symbol = :none, level::Real = 0.95)
Specifying `interval_type` will return a 3-column matrix with the prediction and
If `interval` differs from `:none`, return a 3-column matrix with the prediction and
the lower and upper confidence bounds for a given `level` (0.95 equates alpha = 0.05).
Valid values of `interval_type` are `:confint` delimiting the uncertainty of the
Valid values of `interval` are `:confint` delimiting the uncertainty of the
predicted relationship, and `:predint` delimiting estimated bounds for new data points.
"""
function predict(mm::LinearModel, newx::AbstractMatrix, interval_type::Symbol, level::Real = 0.95)
function predict(mm::LinearModel, newx::AbstractMatrix;
interval::Symbol=:none, level::Real = 0.95)
retmean = newx * coef(mm)
interval_type == :confint || error("only :confint is currently implemented") #:predint will be implemented
if interval === :none
return retmean
elseif interval !== :confint
error("only :confint is currently implemented") #:predint will be implemented
end
length(mm.rr.wts) == 0 || error("prediction with confidence intervals not yet implemented for weighted regression")

R = cholesky!(mm.pp).U #get the R matrix from the QR factorization
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ end
@test isapprox(predict(gm12, newX, offset=newoff),
logistic.(newX * coef(gm12) .+ newoff))

# Prediction from DataFrames
# Prediction from DataFrames
d = convert(DataFrame, X)
d[:y] = Y

Expand All @@ -451,7 +451,7 @@ end

Ylm = X * [0.8, 1.6] + 0.8randn(10)
mm = fit(LinearModel, X, Ylm)
pred = predict(mm, newX, :confint)
pred = predict(mm, newX, interval=:confint)

@test isapprox(pred[1,2], 0.6122189104014528)
@test isapprox(pred[2,2], -0.33530477814532056)
Expand Down

0 comments on commit d467307

Please sign in to comment.