How can I plot only one fitted variable after using sbiofit?
2 ビュー (過去 30 日間)
古いコメントを表示
I'm fitting a model to a dataset. I have two variables I'm fitting simultaneously: the therapy, and the quantity of an endogenous protein. Call the model variables Drug and Prot. The corresponding columns in the dataset woudl be DrugObs and ProtObs. Drug and Prot are of different magnitude. I fit the model:
[fitcon, simdat] = sbiofit( m1, gmidata, resmap, estpars, doses, 'UseParallel',true);
If I use plot(fitcon) I get a trellis plot of data and mode for each group (that is, each subject). This is great! However, since the magnitudes are different I'd like to plot the PRED and OBS of each variable in a different plot.
Also, it's useful to look at these things in both log and linear form.
So is there any easy way to say
plot(fitcon,'PREDVarToPlot','Drug', 'OBSVarToPlot', 'DrugObs'); % and
plot(fitcon,'PREDVarToPlot','Prot', 'OBSVarToPlot', 'ProtObs'); %
and also
plot(fitcon,'PREDVarToPlot','Drug', 'OBSVarToPlot', 'DrugObs',YScale,'log'); % and
plot(fitcon,'PREDVarToPlot','Prot', 'OBSVarToPlot', 'ProtObs',YScale,'log'); %
I can do this by going into the plot but its tedious:
fh = gcf;
fhc = fh.Children
nfhc = numel(fhc)
for i = 1:nfhc
test the specific figure child to see if its an axes or a legend
if axes get axes children
fhcc = fhc(i).Childen % These are lines
fhcc(1).Visible = 'off' % This is one way. Any way to delete the line completely?
fhcc(3).Visible = 'off' % fhcc([1 3]) are two of the four plotted variables corresponding to etiher drug, or protein. Could be fhcc([2 4])
elseif legend
castr = fhc(i).String
castr = castr([2 4])
end
Another approach would be to allow the second variable to be plotted using a different (right hand) yscale. I've not tried this in script, but as I understand it I'd have to loop through current axes and create a new Child axes with YAxisLocation = 'right'. Not sure then how I would transfer one set of variables (Drug and DrugObs or Prot and ProtObs) to that new axis. Again, it would be ideal if there was an ability to say:
plot(fitcon, 'LeftAxis', 'Drug','RightAxis','Prot');
Are there any easy ways to do this, or must I create a script function? Thanks!
0 件のコメント
採用された回答
Jeremy Huard
2019 年 8 月 30 日
Hi Jim,
thanks for this feedback. It would be a good thing to have.
Have you had a look at sbiopredictionci? It computes the compute confidence intervals for model predictions. It also has a plot method that will create a grid with one column per group and one row per response. This is basically what you are asking for, except that you will also have a plot of the confidence intervals.
It would look like this:
Would this work for you?
Best,
Jérémy
3 件のコメント
Jeremy Huard
2019 年 9 月 3 日
Hi Jim,
Thanks for your suggestion.
Just to clarify one thing: the plots commands do not rerun the simulations. They simply add the simulation data contained in simdat to the trellis.
This is in essence what plot(fitcon) does. fitcon (the OptimResults object) saves the simulation data in its property fitted. So, the sbiotrellis + plot commands are more efficient because your code does what they do twice plus some other things to delete the unnecessary lines.
Best,
Jérémy
その他の回答 (1 件)
Priya Moorthy
2019 年 9 月 3 日
編集済み: Priya Moorthy
2019 年 9 月 4 日
Hi, Jim,
Currently, SimBiology plot functions do not support using multiple y-axes. You can pass a custom plot function to sbiotrellis that will allow you to use different axis scales. You will need a helper function that allows you to use plotting functions like @semilogy with simData objects.
If your original call is:
[fitcon, simdat] = sbiofit( m1, gmidata, resmap, estpars, doses, 'UseParallel',true );
...then the the plotting function calls are as follows, where groupVariableName and independentVariableName are the group and time column names from your experimental data:
To plot linearly:
h = sbiotrellis(expData, groupVariableName, independentVariableName, ‘DrugObs’, ':o');
plot(h, simData, [], 'time', ‘Drug’);
To plot on a log scale:
h = sbiotrellis(gmidata, @semilogy, groupVariableName, independentVariableName, ‘DrugObs’, ':o');
plot(h, simdat, @(sd, xcol, ycol)plotSimDataHelperFcn(sd, xcol, ycol, @semilogy), 'time', 'Drug');
The helper function would look something like this:
function plotSimDataHelperFcn(sd, xcol, ycol, fcnhandle)
% SD is a single SimData object
% XCOL and YCOL are strings or char vectors that refer to states in the
% simData object
% FCNHANDLE must have signature FCNHANDLE(X,Y)
if strcmpi(xcol, 'time')
x = sd.Time;
else
x = sd.selectbyname(xcol).Data;
end
if strcmpi(ycol, 'time')
y = sd.Time;
else
y = sd.selectbyname(ycol).Data;
end
fcnhandle(x,y);
There are some features coming up in a future release to make it easier to plot select variables from simData objects and experimental objects from the desktop interface (you can try it out in the R2019b prerelease, although there will be some changes to the features in the final release).
Best,
Priya
2 件のコメント
Priya Moorthy
2019 年 9 月 4 日
Jim,
Your copyobj method certainly works, although it is relying on the order of the lines to decide which ones to turn off and on. You could also delete lines instead of just changing their visibility. My solution is virtually the same as Jérémy's; I just added the function handle argument to enable changing the y-axis scale.
As Jérémy said, using the plot command with SimData objects will not re-run the simulation; however using the plot command with the fit results object may rerun simulations to get the predicted data. So, using sbiotrellis with the SimData objects returned from the fitting function is probably the more efficient solution.
Best,
Priya
コミュニティ
その他の回答 SimBiology コミュニティ
参考
カテゴリ
Help Center および File Exchange で Import Data についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!