<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Thank You very much. I did in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Least-squares-estimation-of-fit-error/m-p/1121041#M24944</link>
    <description>&lt;P&gt;Thank You very much. I did not found this equation for QR factorisation.&lt;/P&gt;

&lt;P&gt;I have one another question. Routine DGEQPF permutes columns of orignial matrix. Then I assume that the values \delta_c will be permuted so. Is it true?&lt;/P&gt;</description>
    <pubDate>Thu, 22 Dec 2016 14:29:59 GMT</pubDate>
    <dc:creator>ZlamalJakub</dc:creator>
    <dc:date>2016-12-22T14:29:59Z</dc:date>
    <item>
      <title>Least squares - estimation of fit error</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Least-squares-estimation-of-fit-error/m-p/1121039#M24942</link>
      <description>&lt;P&gt;I am using routines DGEQPF, DORMQR and DTRSV (according to example in dgeqpfx.f) and it works well.&lt;/P&gt;

&lt;P&gt;I also need to calculate estimation of errors of fitted parameters but I did not find any example.&lt;/P&gt;

&lt;P&gt;Can someone give me advice how to calculate it?&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2016 06:30:06 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Least-squares-estimation-of-fit-error/m-p/1121039#M24942</guid>
      <dc:creator>ZlamalJakub</dc:creator>
      <dc:date>2016-12-22T06:30:06Z</dc:date>
    </item>
    <item>
      <title>The topic you ask about</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Least-squares-estimation-of-fit-error/m-p/1121040#M24943</link>
      <description>&lt;P&gt;The topic you ask about involves a combination of linear algebra, linear least squares and statistics, but it is not difficult to put the pieces together.&lt;/P&gt;

&lt;P&gt;Let &lt;EM&gt;c&lt;/EM&gt;&lt;SUB&gt;0&lt;/SUB&gt; be the "regression coefficients" or "fitted parameters" that you have found, and let &lt;EM&gt;R&lt;/EM&gt; be the upper triangular matrix obtained from the Q-R factorization of the regressor matrix. The "confidence interval" for &lt;EM&gt;c&lt;/EM&gt;, the true but unknown value of the regression coefficients, is given by &lt;EM&gt;c&lt;/EM&gt;&lt;SUB&gt;0&lt;/SUB&gt; -&amp;nbsp;&lt;EM&gt;δ&lt;/EM&gt;&lt;SUB&gt;c&lt;/SUB&gt;&amp;nbsp;&amp;lt; &lt;EM&gt;c&lt;/EM&gt; &amp;lt;&amp;nbsp;&lt;EM style="font-size: 16.26px;"&gt;c&lt;/EM&gt;&lt;SUB&gt;0&lt;/SUB&gt;&lt;SPAN style="font-size: 16.26px;"&gt;&amp;nbsp;+&amp;nbsp;&lt;/SPAN&gt;&lt;EM style="font-size: 16.26px;"&gt;δ&lt;/EM&gt;&lt;SUB&gt;c&lt;/SUB&gt;, where&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&lt;EM style="font-size: 16.26px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;δ&lt;/EM&gt;&lt;SUB&gt;c&lt;/SUB&gt;&amp;nbsp;= &amp;nbsp;&lt;EM&gt;t&lt;SUB&gt;ν,α&lt;/SUB&gt;&lt;/EM&gt;&lt;SUB&gt;/2&lt;/SUB&gt;&amp;nbsp;[diag (&lt;EM&gt;R&lt;SUP&gt;T&lt;/SUP&gt;R&lt;/EM&gt;)&lt;SUP&gt;-1&lt;/SUP&gt;Σ (&lt;EM&gt;y&lt;/EM&gt; - &lt;EM&gt;y&lt;SUB&gt;f&lt;/SUB&gt;&lt;/EM&gt;)&lt;SUP&gt;2&lt;/SUP&gt;/&lt;EM style="font-size: 16.26px;"&gt;ν&lt;/EM&gt;]&lt;SUP&gt;1/2&lt;/SUP&gt;,&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;EM&gt;t&lt;/EM&gt; is the Student-&lt;EM&gt;t&lt;/EM&gt; variable, with tail area&amp;nbsp;&lt;EM style="font-size: 16.26px;"&gt;α&lt;/EM&gt;/2 and degrees-of-freedom &lt;EM style="font-size: 16.26px;"&gt;ν =&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;n - m&lt;/EM&gt; of the Student-&lt;EM&gt;t&lt;/EM&gt; PDF,&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;EM&gt;n&lt;/EM&gt; = number of observations,&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;EM&gt;m&lt;/EM&gt; = number of regression coefficients,&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;EM&gt;y&lt;/EM&gt;, &lt;EM&gt;y&lt;SUB&gt;f&lt;/SUB&gt;&lt;/EM&gt; are the observed and fitted values of the dependent variable.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2016 13:46:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Least-squares-estimation-of-fit-error/m-p/1121040#M24943</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2016-12-22T13:46:00Z</dc:date>
    </item>
    <item>
      <title>Thank You very much. I did</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Least-squares-estimation-of-fit-error/m-p/1121041#M24944</link>
      <description>&lt;P&gt;Thank You very much. I did not found this equation for QR factorisation.&lt;/P&gt;

&lt;P&gt;I have one another question. Routine DGEQPF permutes columns of orignial matrix. Then I assume that the values \delta_c will be permuted so. Is it true?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2016 14:29:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Least-squares-estimation-of-fit-error/m-p/1121041#M24944</guid>
      <dc:creator>ZlamalJakub</dc:creator>
      <dc:date>2016-12-22T14:29:59Z</dc:date>
    </item>
    <item>
      <title>Whether pivoting is used or</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Least-squares-estimation-of-fit-error/m-p/1121042#M24945</link>
      <description>&lt;P&gt;Whether pivoting is used or not is a detail at the programming level, and depends on which Lapack routine is used for performing the QR decomposition.&lt;/P&gt;

&lt;P&gt;If you use DGEQRF, pivoting is not used and the question goes away.&lt;/P&gt;

&lt;P&gt;Please note that DGEQPF is now deprecated; use DGEQP3 instead. If pivoting is used, the permutation vector does need to be used in reporting&amp;nbsp;&lt;EM&gt;δ&lt;/EM&gt;&lt;SUB&gt;c&lt;/SUB&gt;. However, only the diagonal of &lt;EM&gt;R&lt;SUP&gt;T&lt;/SUP&gt;R&lt;/EM&gt; needs to be permuted, so doing so is not difficult, although it can appear tricky to do so at first look.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2016 17:38:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Least-squares-estimation-of-fit-error/m-p/1121042#M24945</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2016-12-22T17:38:40Z</dc:date>
    </item>
    <item>
      <title>Thanks for advice, I will try</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Least-squares-estimation-of-fit-error/m-p/1121043#M24946</link>
      <description>&lt;P&gt;Thanks for advice, I will try.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 19:25:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Least-squares-estimation-of-fit-error/m-p/1121043#M24946</guid>
      <dc:creator>ZlamalJakub</dc:creator>
      <dc:date>2016-12-23T19:25:32Z</dc:date>
    </item>
    <item>
      <title>I have finished my routine</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Least-squares-estimation-of-fit-error/m-p/1121044#M24947</link>
      <description>&lt;P&gt;I have finished my routine calculating LSQ fit and also standard deviations of fitted parameters. It is not well memory optimised, but seems to work.&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;	subroutine DSOLVEQRErrorEstim_MKL(A,B,X,Xerr,m,n,tol,info)
		implicit none
		integer*4,intent(in) :: m,n		! m - number of equations, n - number of unknowns
		real*8,intent(in) :: A(m,n)		! matrix A  (A*X=B)
		real*8,intent(inout) :: B(m,1)	! righthand side
		real*8,intent(out) :: X(n,1)		! fitted parameters
		real*8, intent(out) :: Xerr(n,1)	! standard deviations of fitted parameters
		real*8, intent(in) :: tol			!	Choose TOL to reflect the relative accuracy of the input data
		integer*4, intent(inout) :: info  ! result of MKL routines 0 if all is ok
	
      INTEGER          MMAX, NMAX, LDA, LDB, LDX, NRHMAX, LWORK
      real*8,parameter ::  ZERO=0.0D0
      INTEGER          I, IFAIL, J, K, NRHS
      real*8	       TAU(N),WORK(64*n)
      DOUBLE PRECISION RWORK(2*N)
      INTEGER          JPVT(N),ipiv(n)
      CHARACTER        CLABS(1), RLABS(1)
		real*8			 R(n,n)  ! factorised matrix R
	 	real*8			Acopy(m,n),Bcopy(m)  ! copy of input matrices
		real*8		Bout(m)
		real*8		err,sigma
		lda=m
		ldb=m
		nrhs=1
		lwork=64*n

		! get a copy of input matrices to evaluate deviations
		Acopy=A
		Bcopy(1:m)=B(1:m,1)


!        Initialize JPVT to be zero so that all columns are free
         JPVT=0

!        Compute the QR factorization of A
         CALL DGEQP3(M,N,A,LDA,JPVT,TAU,WORK,lwork,INFO)
			if (info/=0) then
				return
			endif
			
			! copy R for evaluation of deviations
			R=0.D0
			do i=1,n	! row
				R(1:i,i)=A(1:i,i)
			enddo
			call dtrmm('Left','Upper','Transpose','Not diagonal',n,n,1.D0,A,m,R,n)
			! in R is not R^T*R

!        Determine which columns of R to use
         DO 20 K = 1, N
            IF (ABS(A(K,K)).LE.TOL*ABS(A(1,1))) GO TO 40
   20    CONTINUE

!        Compute C = (Q**H)*B, storing the result in B
40 K = K - 1
         CALL DORMQR('Left','Transpose',M,NRHS,N,A,LDA,TAU,B,LDB,WORK,LWORK,INFO)
			if (info/=0) then
				return
			endif

!        Compute least-squares solution by backsubstitution in R*B = C
          CALL DTRSV('Upper','No transpose','Non-Unit',K,A,LDA,B(1,1),1)

!           Set the unused elements of the I-th solution vector to zero
				B(K+1:N,1)=ZERO
   60    CONTINUE
!        Unscramble the least-squares solution stored in B
         DO 100 I = 1, N
               X(JPVT(I),1) = B(I,1)
100		CONTINUE

! now estimate errors

		  ! we need inverse of R
			
		  ! DGETRF computes an LU factorization of a general M-by-N matrix A
		  ! using partial pivoting with row interchanges.
		  call DGETRF(n, n, R, n, ipiv, info)
		  if (info /= 0) then
			  !stop 'Matrix is numerically singular!'
			  return
		  end if

		  ! DGETRI computes the inverse of a matrix using the LU factorization
		  ! computed by DGETRF.
		  call DGETRI(n, R, n, ipiv, work, n, info)
			if (info/=0) then
				return
			endif
			! in R is now (R^T*R)^(-1)
			
			! evaluate A*X
			call DGEMM('None','None',m,1,n,1.D0,Acopy,m,X,n,0.D0,Bout,m)
			! calculate error of fit
			Bout=Bout-Bcopy
			err=dot_product(Bout,Bout)
			sigma=dsqrt(err/(m-n))
!        Unscramble the R
         DO I = 1, N
				Xerr(JPVT(I),1) = DSQRT(R(I,I))*sigma
			enddo
	return
end subroutine
&lt;/PRE&gt;

&lt;P&gt;&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Jan 2017 15:31:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Least-squares-estimation-of-fit-error/m-p/1121044#M24947</guid>
      <dc:creator>ZlamalJakub</dc:creator>
      <dc:date>2017-01-01T15:31:36Z</dc:date>
    </item>
  </channel>
</rss>

