如何从 Free Pascal 调用 R 函数?
在我的 Lazarus/Free Pascal 应用程序中,我生成了一个大型多列数值矩阵。我想在此表上运行主成分分析 (PCA),但似乎找不到任何包来做到这一点。
R 语言有一个 .dll 库,可导出 PCA 函数,但它返回“princomp”类的对象。我不确定如何从此类中提取相关信息(例如转换后的矩阵)以在 Lazarus/FPC 中使用。
In my Lazarus/Free Pascal application I generate a large multi-column numerical matrix. I want to run a Principal Component Analysis (PCA) on this table, but cannot seem to find any packages to do so.
The R language has a .dll library that exports the PCA function, but it returns an object of the class "princomp." I am not sure how I would then go about extracting relevant information (such as the transformed matrix) from this class for use within Lazarus/FPC.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看 ALGLIB:
http://en.wikipedia.org/wiki/ALGLIB
http://www.alglib.net/download.php
我认为它有很多数值例程,等等奇异值分解和特征值分解。因此,如果没有特殊的 PCA 例程,请记住 PCA 均值向量是所有数据向量的平均值,并且 PCA 向量是协方差矩阵的特征向量,相应的特征值是数据投影的方差在这些向量上。
Take a look at ALGLIB:
http://en.wikipedia.org/wiki/ALGLIB
http://www.alglib.net/download.php
I think it has many numerical routines, among other singular value decomposition and eigenvalue decomposition. So if it does not have a special PCA routine, remember that the PCA mean vector is the mean of all the data vectors and that the PCA vectors are the eigenvectors of the covariance matrix and the corresponding eigenvalues are the variances of the projection of the data on those vectors.
R中实际上有两个PCA函数:princomp和prcomp。第一个计算数据协方差矩阵的特征值,第二个执行奇异值分解。有关每个函数返回的内容(“princomp”或“prcomp”类的对象)的详细信息在函数帮助页面的“值”部分下描述。通常,这些矩阵是具有载荷(即旋转矩阵)、主成分的标准差(即协方差/相关矩阵的特征值的平方根)以及旋转数据集(如果需要)的矩阵。
There are actually two PCA functions in R: princomp and prcomp. The first calculates the eigenvalues of the covariance matrix of the data, the second performs a singular value decomposition. The details about what each function returns (an object of class "princomp" or "prcomp") are described in the help pages of the functions under the section "Value". Typically these are a matrix with the loadings (i.e. the rotation matrix), the standard deviations of the principal components (i.e., the square roots of the eigenvalues of the covariance/correlation matrix), and, if requested, the rotated dataset.