Skip to content

Commit

Permalink
Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
jchristopherson committed Mar 15, 2024
1 parent dc0be94 commit 9eb1466
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions examples/nl_regression_example.f90
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ program example
ylmod(21), lresid(21), lparams(4)
type(convergence_info) :: info
type(regression_statistics) :: stats(4), lstats(4)
type(bootstrap_regression_statistics) :: bstats(4)

! Data to fit
xp = [0.0d0, 0.1d0, 0.2d0, 0.3d0, 0.4d0, 0.5d0, 0.6d0, 0.7d0, 0.8d0, &
Expand Down Expand Up @@ -75,6 +76,26 @@ program example
print 103, tab // "Converge on Parameter Change: ", &
info%converge_on_residual_parameter, " (", info%residual_value, ")"

! Compare via a bootstrap solution
params = 1.0d0 ! reset the initial guess
call bootstrap_nonlinear_least_squares(fun, xp, yp, params, ymod, resid, &
stats = bstats)

! Display the Results
print '(A)', nl // "Bootstrap:"
print 100, (tab // "params(", i, "): ", params(i), i = 1, size(params))

print '(A)', "Statistics:"
print 104, ( &
"Coefficient ", i, ":" // nl // &
tab // "Standard Error: ", bstats(i)%standard_error, nl // &
tab // "Upper Confidence Limit: ", bstats(i)%upper_confidence_interval, nl // &
tab // "Lower Confidence Limit: ", bstats(i)%lower_confidence_interval, nl // &
tab // "T-Statistic: ", bstats(i)%t_statistic, nl // &
tab // "P-Value: ", bstats(i)%probability, &
i = 1, size(bstats) &
)

! As our model is simply a 3rd order polynomial, the linear_least_squares
! routine can also be used. As a comparison, here's the
! linear_least_squares solution
Expand All @@ -98,4 +119,5 @@ program example
101 format(A, I0, A, F6.3, A, F6.3, A, F6.3, A, F6.3)
102 format(A, I0)
103 format(A, L1, A, E9.3, A)
104 format(A, I0, A, F6.3, A, F6.3, A, F6.3, A, F6.3, A, F6.3)
end program

0 comments on commit 9eb1466

Please sign in to comment.