tidyfun / tf

S3 classes and methods for tidy functional data
https://tidyfun.github.io/tf/
GNU Affero General Public License v3.0
5 stars 2 forks source link

functionality for applying a given basis to new data #3

Closed fabian-s closed 6 months ago

fabian-s commented 4 years ago
fabian-s commented 4 years ago

first step would probably add sp to tfb_spline class, similar to score_variance for tfb_fpc in https://github.com/tidyfun/tidyfun/pull/86

fabian-s commented 2 years ago

common operation that should be easy: apply given FPC (or spline!) basis to NEW data

fabian-s commented 2 years ago

interface:

1a: just write predict methods with first arg the fitted tfb/tfb_fpc, newdata
1b: write basis-extractor and predict methods with first arg the basis info and newdata 2a/b: samesame but use tfb(<new data>, old_tfb) or tfb(<new data>, tf_basis(old_tfb)) not predict

so: implicit basis extraction step or force users to make it explicit.

jeff-goldsmith commented 2 years ago

seems like a general tfb class that takes a known "basis representation" (including things like tuning parameters) and a corresponding method for estimating coefficients would work. this would work for splines and FPCA-based methods, as long as everything for the coefficient estimation was included in the "basis representation".

there's probably a way for this to go along with the second bullet, although i dunno that we'd want to require that every coefficient estimating approach boil down to mgcv.

one way to make this concrete is to use something like

tfb_vec = tfb(tfd_vec, basis_object)

(which assumes that basis_object implies a coefficient estimating function).

a problem is that right now we use tfb to do spline smoothing when called directly; that creates an implicit basis object, which stays invisible to users -- but we'd be asking users to know it's explicit when applying the basis representation to new data.

two options:

fabian-s commented 2 years ago

can we then do away with tfb_spline, tfb_fpc subclasses? EDIT: no

fabian-s commented 6 months ago

implement this in tf_rebase(object, basis_from): see 3-tfb-basistransfer branch

fabian-s commented 6 months ago

@jeff-goldsmith if you have time, would appreciate your thoughts on this new feature tf_rebase (see test-rebase.R for some examples). does this cover what we need for practical applications / what's missing? is the documentation clear enough?

jeff-goldsmith commented 6 months ago

this is awesome! tf_rebase worked like a charm and the help file is clear. Maybe we should add a (possibly contrived) example to the conversion vignette -- something like processing DTI$cca separately for male and female participants, then combining in various ways using tf_rebase?

fabian-s commented 6 months ago

great, glad you like it -- see https://github.com/tidyfun/tidyfun/issues/161 for your point about examples for tf_rebase