Skip to content

add residuals and fitted #75

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

Merged
merged 3 commits into from
Aug 22, 2023
Merged
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
8 changes: 6 additions & 2 deletions src/Loess.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module Loess

import Distances: euclidean
import StatsAPI: predict
import StatsAPI: fitted, predict, residuals

using Statistics, LinearAlgebra

export loess, predict
export loess, fitted, predict, residuals

include("kd.jl")

Expand Down Expand Up @@ -199,6 +199,10 @@ function predict(model::LoessModel, zs::AbstractMatrix)
end
end

fitted(model::LoessModel) = predict(model, model.xs)

residuals(model::LoessModel) = fitted(model) .- model.ys

"""
tricubic(u)

Expand Down
5 changes: 3 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ using RDatasets
x = [13.0,14.0,14.35,15.0,16.0]
y = [0.369486, 0.355579, 0.3545, 0.356952, 0.36883]
model = loess(x,y)
@test Loess.predict(model,x) ≈ y
@test fitted(model) ≈ y
@test all(isapprox(0; atol=1e-12), residuals(model))
end

@testset "reshaped views" begin
# See: https://github.com/MakieOrg/AlgebraOfGraphics.jl/pull/462
# and: https://github.com/JuliaStats/Loess.jl/pull/70
@test Loess.loess(reshape(view(rand(4), 1:4), (4, 1)), rand(4)) isa Loess.LoessModel
@test loess(reshape(view(rand(4), 1:4), (4, 1)), rand(4)) isa Loess.LoessModel
end

@testset "sine" begin
Expand Down