Skip to content

Commit

Permalink
Return a Tuple from simplelinreg (#16)
Browse files Browse the repository at this point in the history
* Return a Tuple from simplelinreg

* add tests

* Bump minor version b/c breaking change

Co-authored-by: Phillip Alday <[email protected]>
  • Loading branch information
dmbates and palday authored Jun 2, 2021
1 parent 2789ecd commit 458b799
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MixedModelsMakie"
uuid = "b12ae82c-6730-437f-aff9-d2c38332a376"
authors = ["Phillip Alday <[email protected]>, Douglas Bates <[email protected]> and contributors"]
version = "0.1.2"
version = "0.2.0"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
4 changes: 2 additions & 2 deletions src/xyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ end
"""
simplelinreg(x, y)
Return the coefficients, `[a, b]`, from a simple linear regression, `y = a + bx + ϵ`
Return a Tuple of the coefficients, `(a, b)`, from a simple linear regression, `y = a + bx + ϵ`
"""
function simplelinreg(x, y)
x, y = float(x), float(y)
A = cholesky!(Symmetric([length(x) sum(x) sum(y); 0.0 sum(abs2, x) dot(x, y); 0.0 0.0 sum(abs2, y)])).factors
ldiv!(UpperTriangular(view(A, 1:2, 1:2)), view(A, 1:2, 3))
(ldiv!(UpperTriangular(view(A, 1:2, 1:2)), view(A, 1:2, 3))..., )
end
3 changes: 3 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
14 changes: 13 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
using MixedModelsMakie
using Random # we don't depend on exact PRNG vals, so no need for StableRNGs
using Test

@testset "There are no tests" begin
@testset "There are no graphical tests" begin
@test true
end

@testset "Simple linear regression" begin
a, b = 1, 2
x = collect(1:10)
y = randn(MersenneTwister(42), 10) * 0.1
@. y += a + b * x
result = simplelinreg(x, y)
@test result isa Tuple
@test a result[1] atol=0.05
@test b result[2] atol=0.05
end

2 comments on commit 458b799

@palday
Copy link
Owner

@palday palday commented on 458b799 Jun 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/38044

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.0 -m "<description of version>" 458b799dc0e91c5122d3c774173dd4ffb2da6e8d
git push origin v0.2.0

Please sign in to comment.