MATLAB Answers

LinearModel custom class questions

1 view (last 30 days)
Brig
Brig on 9 Nov 2012
Answered: Leah on 26 Sep 2013
I've been having issues with the LinearModel class. I want to create many different linear models on various subsets of predictors and observations. I would like to store all these models but don't want to have to re-store all of the observations used for each model (there are thousands of predictors for every observation).
If I have some data and create a model
ds = dataset({rand(5,1),'predictor'},{rand(5,1),'response'});
mdl = LinearModel.fit(ds);
I would like to be able to say
mdl.Variables = [];
but I get
Error using classreg.regr.FitObject/subsasgn (line 745)
The Variables property for class LinearModel is read-only.
It was suggested that I create my own class that inherits from LinearModel so I can change the permissions and store the model object sans variable info.
classdef customLinearModelClass< LinearModel
properties
end
methods
function clm= customLinearModelClass(linModel)
clm= clm@LinearModel;
end
end
end
but I get,
Error using customLinearModelClass
Class 'LinearModel' is Sealed and may not be used as a superclass.
And I could just copy all of the LinearModel code and create a new class that has the properties that I want but I would like to recreate a real LinearModel class if I want to. best case scenario I could do this.
customModel = magicFunction1(mdl);
mdl2 = magicFunction2(customModel);
where cutomModel does not contain all the Variable information and mdl and mdl2 are the same.
Any suggestions?

  0 Comments

Sign in to comment.

Answers (1)

Leah
Leah on 26 Sep 2013
I think in order for you to have all the functionality of the class you need to keep the variable information. Can you just copy out the information you need from the class to a new structure? Like sometimes I'll just take out the coeff, Adjusted Rsq and pvals and ditch the md class

  0 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!