我编写了以下函数来计算矩阵(Weibull模型的信息矩阵)
#include <RcppEigen.h>
#include <math.h>
#include <vector>
using namespace std;
using Eigen::MatrixXd;
// [[Rcpp::depends(RcppEigen)]]
// [[Rcpp::export]]
MatrixXd Weibull_FIM(const vector<double> x, const vector<double> w, const vector<double> param)
{
if(x.size() != w.size()){
Rcpp::Rcout<<"The length of x and w is not equal."<<std::endl;
exit(1);
}
double a, b, lambda, h, constant;
a = param[0];
b = param[1];
lambda = param[2];
h = param[3];
a = a + 0; //just to not get a warning
Eigen::MatrixXd Fisher_mat(4, 4);
size_t i;
for(i=0; i < x.size(); i++) …Run Code Online (Sandbox Code Playgroud) 我的包裹顺利通过了Rcmd check.但是在R文档的构造PDF格式中,在示例部分中,行的一半(R代码)不在本文中.我还发现了另一个CRAN提交的软件包,ftsa它在一行中也会过度使用,请参阅ftsa 参考手册.
我想这个问题源于verbatimLatex环境的行为.但是有一些Latex软件包可以解决这个问题,https://tex.stackexchange.com/questions/14342/verbatim-environment-that-can-break-too-long-lines,但我不知道如何使用它们与Rcmd.
Rcmd check不显示Latex的任何错误,警告或注释?谢谢
我想在R文档中以粗体字设置(x_1,x_2,\ dots,x_n).我写
\deqn(\bold{x}_1, \bold{x}_2, \ldots, \bold{x}_n),
但是当Rstudio显示文档的HTML预览时,x不是粗体,并且HTML帮助页面中说明了\ bold {x}.这样其他乳胶数学大胆制片人\boldsymbol,\mathbf,\boldmath也没有成功.
那么,在数学模式下以粗体设置字符的正确命令是什么?
谢谢,
PS当我申请\mathbf和\boldsymbolpdf构造的文档中的字符x变得大胆,但HTML帮助页面怎么样?
当我在函数定义中使用可选参数时,我的省略号有问题.为了澄清,我定义了以下功能:
func1 <- function (x) (x-2)^2
func3 <- function (fun, arg.curve.user){
arg.curve.user$expr <- substitute(func1)
arg.curve.default <- list(col = "blue", n = 1000, main = "This is a test")
arg.curve <- modifyList (arg.curve.default, arg.curve.user)
do.call("curve", arg.curve)
}
# optimizes func1 and call func2 to plot func1
func2 <- function (lb, ub, n.restarts = 5, n.sim = 10, ...){
arg.curve.user <- as.list(substitute(list(...)))
output <- gosolnp(fun = func1, LB = lb, UB = ub, n.restarts = n.restarts,
n.sim = n.sim)$par
func3(fun = func1, …Run Code Online (Sandbox Code Playgroud) 我想同时以pdf和png格式绘制图:
pdf("test.pdf")
plot(sin, -pi, 2*pi)
dev.off()
png("test.png")
plot(sin, -pi, 2*pi)
dev.off()
Run Code Online (Sandbox Code Playgroud)
但是,我正在寻找一个技巧(最好不要通过加载新程序包),在该技巧中,plot函数仅被调用一次:
#no plot in pdf!
pdf("test1.pdf"); png("test1.png")
plot(sin, -pi, 2*pi)
dev.off(); dev.off()
Run Code Online (Sandbox Code Playgroud)
任何建议,将不胜感激。
如何在R中找到矩阵的符号反转; 例如:
Matrix.test <- function(x) matrix(c(x, x^2, x^3, x^4, x^5, x^6, x^7, x^8, x^9, 2*x, 3*x, 4*x, 2*x^2, 3*x^3, 4*x^4, 5*x^5), 4, 4)
Run Code Online (Sandbox Code Playgroud)
我知道有一个名为'Ryacas'的包,它是'yacas'的接口,但我不能用它来做这样的计算.'yacas'是一个用于符号操纵数学表达式的程序.请参阅链接了解更多详情.
谢谢
我在将参数传递给 时遇到了问题optim。例如,假设我想对多元函数进行框约束最小化
fr <- function(x) { ## Rosenbrock function
x1 <- x[1]
x2 <- x[2]
x3 <- x[3]
x4 <- x[4]
100 * (x2 - x1 * x1)^2 + (1 - x1)^2 +
100 * (x3 - x2 * x2)^2 + (1 - x2)^2 +
100 * (x4 - x3 * x3)^2 + (1 - x3)^2
}
Run Code Online (Sandbox Code Playgroud)
像往常一样optim可以使用如下:
optim(par = c(0, 1, 1, 2), fr, method = "L-BFGS-B", lower = c(0, 0, 0, 0), upper = …Run Code Online (Sandbox Code Playgroud)