Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: FittedModel Objects... How does Mathematica do it?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115444] Re: FittedModel Objects... How does Mathematica do it?
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Tue, 11 Jan 2011 06:57:40 -0500 (EST)
  • References: <iggq2q$4be$1@smc.vnet.net>

Hi,

> LinearModelFit (and similar statistical functions) are documented with
> examples such as:
> 
> data = {{0, 1}, {1, 0}, {3, 2}, {5, 4}};
> lm = LinearModelFit[data, x, x]
> 
> which returns a FittedModel 'object'. One can then execute code such
> as lm["FitResiduals"] or lm["RSquared"] to retrieve the properties one
> desires.
> 
> 1. How exactly does Mathematica generate/store the objects associated
> with the head 'lm'?!? I'd *really* appreciate a simple example of how
> to do this and/or some tips on when/how to use more complicated head
> structures.
>
> 2. And taking that one step further, how does Mathematica generate/
> store additional info, such as 'Descriptions' on specific properties?
> For example, lm["ParameterErrors", "LongDescription"], returns
> "standard errors for parameter estimates".

The variable lm is set to an expression with head FittedModel, whose
arguments contain the data necessary to describe the fitted model. It is
the SubValues of the symbol FittedModel that contain all the definitions
for the various properties. It's not easy to read but you can look at
all these definitions with SubValues[FittedModel].

> 3. Does Mathematica immediately calculate and store all these
> lm{"objects"], or are they generated (where appropriate) only when
> requested? 

>From what I can see in the SubValues, it looks like most of it is
generated on request from the data that is stored in the FittedModel. My
guess is that they store everything that takes a while to generate as
data in the FittedModel and generate stuff that is fast and comes in
many variants on the fly.

> (And is this really OOP? <-- not intended to start an OOP
> flame war!)

I would say this makes use of many aspects that you also find in OOP.

> 4. (Possibly related, so I figured I'd include it...) How does
> Mathematica store all the metadata available on example data sets?---
> Is there documentation on how to conform to this standard/approach?
> For instance: ExampleData[{"Matrix","FIDAP007"}, "Properties"]. (on
> second thought, I guess this is probably stored in some standard file
> format, hidden from view...)

I have no insight on how the Data-functions are implemented, but they
typically do get their data as wdx-files from the Wolfram servers and
store/cache these in local directories, something like:

FileNames["*",
 FileNameJoin[{$UserBaseDirectory, "Paclets", "Repository"}]]

Basically you could try to import these files and see what is in them.
Again that is not an easy read but I think one could do some
reengineering of how they possibly work from the content.

hth,

albert


  • Prev by Date: Re: Simple PDE with side conditions
  • Next by Date: Re: How to change the directory for the docs?
  • Previous by thread: FittedModel Objects... How does Mathematica do it?
  • Next by thread: Re: FittedModel Objects... How does Mathematica do it?