lfplot.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/REC-html40/loose.dtd">
  3. <html>
  4. <head>
  5. <title>Description of lfplot</title>
  6. <meta name="keywords" content="lfplot">
  7. <meta name="description" content="Plot (for one or two dimensions) a locfit() fit.">
  8. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  9. <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  10. <meta name="robots" content="index, follow">
  11. <link type="text/css" rel="stylesheet" href="../../../m2html.css">
  12. <script type="text/javascript">
  13. if (top.frames.length == 0) { top.location = "../../../index.html"; };
  14. </script>
  15. </head>
  16. <body>
  17. <a name="_top"></a>
  18. <!-- ../../menu.html chronux_2_10 --><!-- # locfit --><!-- menu.html m -->
  19. <h1>lfplot
  20. </h1>
  21. <h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  22. <div class="box"><strong>Plot (for one or two dimensions) a locfit() fit.</strong></div>
  23. <h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  24. <div class="box"><strong>function lfplot(varargin) </strong></div>
  25. <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  26. <div class="fragment"><pre class="comment"> Plot (for one or two dimensions) a locfit() fit.
  27. Usage:
  28. fit = locfit(x,y);
  29. lfplot(fit);
  30. Plot the fitted smooth curve, and add a scatterplot of the data.
  31. Required argument:
  32. fit (produced by locfit()).
  33. Optional arguments:
  34. 'nodata' - don't add data to plot.
  35. 'contour' - for 2-d predictors, use contour instead of surf.
  36. 'direct' - fit directly, instead of using interpolation
  37. (see the predict() function).
  38. 'what' - locfit what argument ('coef', 'infl', 'vari', 'band' etc).
  39. Any additional arguments are passed to Matlab's plot(), contour()
  40. or surf() function as appropriate.
  41. To add confidence bands, use the lfband() function.
  42. Author: Catherine Loader.</pre></div>
  43. <!-- crossreference -->
  44. <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  45. This function calls:
  46. <ul style="list-style-image:url(../../../matlabicon.gif)">
  47. <li><a href="invlink.html" class="code" title="function y0 = invlink(y,fali)">invlink</a> inverse link function for locfit.</li><li><a href="lfmarg.html" class="code" title="function xfit = lfmarg(fit)">lfmarg</a> computes grid margins from a locfit object, used for plotting.</li><li><a href="plotbyfactor.html" class="code" title="function plotbyfactor(x,y,f)">plotbyfactor</a> </li><li><a href="predict.html" class="code" title="function [y, se] = predict(varargin)">predict</a> Interpolate a fit produced by locfit().</li></ul>
  48. This function is called by:
  49. <ul style="list-style-image:url(../../../matlabicon.gif)">
  50. <li><a href="../../../chronux_2_10/locfit/Book/fig11_1.html" class="code" title="">fig11_1</a> Local Regression and Likelihood, Figure 11.1</li><li><a href="../../../chronux_2_10/locfit/Book/fig11_4.html" class="code" title="">fig11_4</a> Local Regression and Likelihood, Figure 11.4.</li><li><a href="../../../chronux_2_10/locfit/Book/fig11_5.html" class="code" title="">fig11_5</a> Local Regression and Likelihood, Figure 11.5.</li><li><a href="../../../chronux_2_10/locfit/Book/fig1_1.html" class="code" title="">fig1_1</a> Local Regression and Likelihood, Figure 1.1.</li><li><a href="../../../chronux_2_10/locfit/Book/fig2_2.html" class="code" title="">fig2_2</a> Local Regression and Likelihood, Figure 2.2.</li><li><a href="../../../chronux_2_10/locfit/Book/fig2_3.html" class="code" title="">fig2_3</a> Local Regression and Likelihood, Figure 2.3.</li><li><a href="../../../chronux_2_10/locfit/Book/fig2_4.html" class="code" title="">fig2_4</a> Local Regression and Likelihood, Figure 2.4.</li><li><a href="../../../chronux_2_10/locfit/Book/fig2_5.html" class="code" title="">fig2_5</a> Local Regression and Likelihood, Figure 2.5.</li><li><a href="../../../chronux_2_10/locfit/Book/fig2_6.html" class="code" title="">fig2_6</a> Local Regression and Likelihood, Figure 2.6.</li><li><a href="../../../chronux_2_10/locfit/Book/fig3_1.html" class="code" title="">fig3_1</a> Local Regression and Likelihood, Figure 3.1.</li><li><a href="../../../chronux_2_10/locfit/Book/fig4_1.html" class="code" title="">fig4_1</a> Local Regression and Likelihood, Figure 4.1.</li><li><a href="../../../chronux_2_10/locfit/Book/fig4_2.html" class="code" title="">fig4_2</a> Local Regression and Likelihood, Figure 4.2.</li><li><a href="../../../chronux_2_10/locfit/Book/fig5_1.html" class="code" title="">fig5_1</a> Local Regression and Likelihood, Figure 5.1.</li><li><a href="../../../chronux_2_10/locfit/Book/fig5_2.html" class="code" title="">fig5_2</a> Local Regression and Likelihood, Figure 5.2.</li><li><a href="../../../chronux_2_10/locfit/Book/fig5_3.html" class="code" title="">fig5_3</a> Local Regression and Likelihood, Figure 5.3.</li><li><a href="../../../chronux_2_10/locfit/Book/fig5_4.html" class="code" title="">fig5_4</a> Local Regression and Likelihood, Figure 5.4.</li><li><a href="../../../chronux_2_10/locfit/Book/fig5_5.html" class="code" title="">fig5_5</a> Local Regression and Likelihood, Figure 5.5.</li><li><a href="../../../chronux_2_10/locfit/Book/fig6_2.html" class="code" title="">fig6_2</a> Local Regression and Likelihood, Figure 6.2.</li><li><a href="../../../chronux_2_10/locfit/Book/fig6_3.html" class="code" title="">fig6_3</a> Local Regression and Likelihood, Figure 6.3.</li><li><a href="../../../chronux_2_10/locfit/Book/fig6_5.html" class="code" title="">fig6_5</a> Local Regression and Likelihood, Figure 6.5.</li><li><a href="../../../chronux_2_10/locfit/Book/fig6_7.html" class="code" title="">fig6_7</a> Local Regression and Likelihood, Figure 6.6.</li><li><a href="../../../chronux_2_10/locfit/Book/fig7_1.html" class="code" title="">fig7_1</a> Local Regression and Likelihood, Figure 7.1.</li><li><a href="../../../chronux_2_10/locfit/Book/fig7_2.html" class="code" title="">fig7_2</a> Local Regression and Likelihood, Figure 7.2.</li><li><a href="../../../chronux_2_10/locfit/Book/fig7_3.html" class="code" title="">fig7_3</a> Local Regression and Likelihood, Figure 7.3.</li><li><a href="../../../chronux_2_10/locfit/Book/fig7_4.html" class="code" title="">fig7_4</a> Local Regression and Likelihood, Figure 7.4.</li><li><a href="../../../chronux_2_10/locfit/Book/fig8_1.html" class="code" title="">fig8_1</a> Local Regression and Likelihood, Figure 8.1.</li><li><a href="../../../chronux_2_10/locfit/Book/fig8_3.html" class="code" title="">fig8_3</a> Local Regression and Likelihood, Figure 8.3.</li><li><a href="../../../chronux_2_10/locfit/Book/fig9_2.html" class="code" title="">fig9_2</a> Local Regression and Likelihood, Figure 9.2.</li><li><a href="../../../chronux_2_10/locfit/Neuro/lfex1.html" class="code" title="">lfex1</a> Local Estimation a spike firing rate (in spikes per unit time).</li><li><a href="../../../chronux_2_10/locfit/Neuro/lfex2.html" class="code" title="">lfex2</a> Model the success probability of successive trials of a monkey</li><li><a href="lfgui.html" class="code" title="function varargout = lfgui(varargin)">lfgui</a> LFGUI M-file for lfgui.fig</li><li><a href="../../../chronux_2_10/spectral_analysis/helper/den_jack.html" class="code" title="function [m,ll,ul,llj,ulj]=den_jack(X,family,varargin)">den_jack</a> Function to compute smooth estimates of the mean of x using locfit,</li></ul>
  51. <!-- crossreference -->
  52. <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
  53. <div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function lfplot(varargin)</a>
  54. 0002
  55. 0003 <span class="comment">% Plot (for one or two dimensions) a locfit() fit.</span>
  56. 0004 <span class="comment">%</span>
  57. 0005 <span class="comment">% Usage:</span>
  58. 0006 <span class="comment">% fit = locfit(x,y);</span>
  59. 0007 <span class="comment">% lfplot(fit);</span>
  60. 0008 <span class="comment">%</span>
  61. 0009 <span class="comment">% Plot the fitted smooth curve, and add a scatterplot of the data.</span>
  62. 0010 <span class="comment">%</span>
  63. 0011 <span class="comment">% Required argument:</span>
  64. 0012 <span class="comment">% fit (produced by locfit()).</span>
  65. 0013 <span class="comment">%</span>
  66. 0014 <span class="comment">% Optional arguments:</span>
  67. 0015 <span class="comment">% 'nodata' - don't add data to plot.</span>
  68. 0016 <span class="comment">% 'contour' - for 2-d predictors, use contour instead of surf.</span>
  69. 0017 <span class="comment">% 'direct' - fit directly, instead of using interpolation</span>
  70. 0018 <span class="comment">% (see the predict() function).</span>
  71. 0019 <span class="comment">% 'what' - locfit what argument ('coef', 'infl', 'vari', 'band' etc).</span>
  72. 0020 <span class="comment">% Any additional arguments are passed to Matlab's plot(), contour()</span>
  73. 0021 <span class="comment">% or surf() function as appropriate.</span>
  74. 0022 <span class="comment">%</span>
  75. 0023 <span class="comment">% To add confidence bands, use the lfband() function.</span>
  76. 0024 <span class="comment">%</span>
  77. 0025 <span class="comment">% Author: Catherine Loader.</span>
  78. 0026
  79. 0027 fit = varargin{1};
  80. 0028 data = fit.data;
  81. 0029 xdata = data.x;
  82. 0030 n = size(xdata,1);
  83. 0031 d = size(xdata,2);
  84. 0032 fali = fit.fit_points.family_link;
  85. 0033 ydata = data.y;
  86. 0034 wdata = data.weights;
  87. 0035 cdata = data.censor;
  88. 0036 <span class="keyword">if</span> (length(cdata)==1) cdata = zeros(n,1); <span class="keyword">end</span>;
  89. 0037 showdata = (fit.evaluation_structure.derivative==0);
  90. 0038 ppargs = {};
  91. 0039 plotargs = {};
  92. 0040
  93. 0041 type = <span class="string">'s'</span>;
  94. 0042 na = 2;
  95. 0043 <span class="keyword">while</span> na &lt;= length(varargin)
  96. 0044 inc = 0;
  97. 0045 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'contour'</span>))
  98. 0046 type = <span class="string">'c'</span>;
  99. 0047 inc = 1;
  100. 0048 <span class="keyword">end</span>;
  101. 0049 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'what'</span>))
  102. 0050 ppargs = {ppargs{:}, <span class="string">'what'</span>, varargin{na+1}};
  103. 0051 showdata = 0;
  104. 0052 inc = 2;
  105. 0053 <span class="keyword">end</span>;
  106. 0054 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'nodata'</span>))
  107. 0055 showdata = 0;
  108. 0056 inc = 1;
  109. 0057 <span class="keyword">end</span>;
  110. 0058 <span class="keyword">if</span> (strcmp(varargin{na},<span class="string">'direct'</span>))
  111. 0059 ppargs = {ppargs{:} <span class="string">'direct'</span>};
  112. 0060 inc = 1;
  113. 0061 <span class="keyword">end</span>;
  114. 0062 <span class="keyword">if</span> (inc==0)
  115. 0063 plotargs = {plotargs{:} varargin{na}};
  116. 0064 inc = 1;
  117. 0065 <span class="keyword">end</span>;
  118. 0066 na = na+inc;
  119. 0067 <span class="keyword">end</span>;
  120. 0068
  121. 0069 xfit = <a href="lfmarg.html" class="code" title="function xfit = lfmarg(fit)">lfmarg</a>(fit);
  122. 0070 yfit = <a href="predict.html" class="code" title="function [y, se] = predict(varargin)">predict</a>(fit,xfit,ppargs{:});
  123. 0071 yfit = <a href="invlink.html" class="code" title="function y0 = invlink(y,fali)">invlink</a>(yfit,fali);
  124. 0072 fam = mod(fali(1),64);
  125. 0073 <span class="keyword">if</span> (fam&gt;4)
  126. 0074 ydata = ydata ./ wdata;
  127. 0075 <span class="keyword">end</span>;
  128. 0076
  129. 0077 <span class="keyword">if</span> (d==1)
  130. 0078 plot(xfit{1},yfit,plotargs{:});
  131. 0079 <span class="keyword">if</span> (showdata)
  132. 0080 hold on;
  133. 0081 <span class="keyword">if</span> (length(ydata)==1) ydata = zeros(n,1); <span class="keyword">end</span>;
  134. 0082 <a href="plotbyfactor.html" class="code" title="function plotbyfactor(x,y,f)">plotbyfactor</a>(xdata,ydata,cdata);
  135. 0083 hold off;
  136. 0084 <span class="keyword">end</span>;
  137. 0085 <span class="keyword">end</span>;
  138. 0086
  139. 0087 <span class="keyword">if</span> (d==2)
  140. 0088 x1 = xfit{1};
  141. 0089 x2 = xfit{2};
  142. 0090 yfit = reshape(yfit,length(x1),length(x2));
  143. 0091 <span class="keyword">if</span> (type==<span class="string">'c'</span>)
  144. 0092 [C h] = contour(x1,x2,yfit',plotargs{:});
  145. 0093 clabel(C,h);
  146. 0094 <span class="keyword">if</span> (showdata)
  147. 0095 hold on;
  148. 0096 <a href="plotbyfactor.html" class="code" title="function plotbyfactor(x,y,f)">plotbyfactor</a>(xdata(:,1),xdata(:,2),cdata);
  149. 0097 hold off;
  150. 0098 <span class="keyword">end</span>;
  151. 0099 <span class="keyword">else</span>
  152. 0100 surf(x1,x2,yfit',plotargs{:});
  153. 0101 <span class="keyword">end</span>;
  154. 0102 <span class="keyword">end</span>;
  155. 0103
  156. 0104 <span class="keyword">return</span>;</pre></div>
  157. <hr><address>Generated on Fri 12-Aug-2011 11:36:15 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2005</address>
  158. </body>
  159. </html>