我有以下四个方程(a,b,c,d),有几个不同的变量(x,t,v,w,n,f).我的目标是尝试找到所有可以生成方程(a,b,c,d)的所有正(和非)数的变量值集.常规循环只会遍历生成的每个序列,并系统地检查它是否生成正值.我希望它从每个序列中获取随机数并将其与R中的其他序列进行测试.例如(x = 8,t = 2.1,v = 13,w = 1,n = 10,f = 1)是可能的一组组合.
请不要建议解析性地解决这些问题,然后找出价值观.这些只是我正在处理的方程式的表示.我所拥有的方程非常复杂,超过15个变量.
#Equations
a <- x * t - 2*x
b <- v - x^2
c <- x - w*t - t*t
d <- (n - f)/t
x <- seq(from = 0.0001, to = 1000, by = 0.1)
t <- seq(from = 0.0001, to = 1000, by = 0.1)
v <- seq(from = 0.0001, to = 1000, by = 0.1)
w <- seq(from = 0.0001, to = 1000, …Run Code Online (Sandbox Code Playgroud) 我有这种格式的数据集(df)
index <- runif(n = 100,min = 0, max = 1)
type1 <- rep("low", 50)
type2 <- rep("high", 50)
type <- c(type1,type2)
level1 <- rep("single", 25)
level2 <- rep("multiple", 25)
level3 <- rep("single", 25)
level4 <- rep("multiple", 25)
level <- c(level1,level2,level3,level4)
block <- rep(1:5, 10)
set <- rep(1:5, 10)
df <- data.frame("index" = index,"type" = type, "level" = level, "block" = block, "set" = set)
df$block <- as.factor(df$block)
df$set <- as.factor(df$set)
Run Code Online (Sandbox Code Playgroud)
我想创建一个看起来像这样的模型
model <- lmer(index ~ type * level + …Run Code Online (Sandbox Code Playgroud) 在一项实验中,我试图找到第一胎出生的时间。id 和rep 给出了四种动物(A1、A2、B1、B2)、它们的年龄和婴儿。对于每个 id 和rep,我只想保留婴儿第一次出生的行
id <- c("A","A","A","A","A","A","B","B","B","B","B","B","B","B","B")
rep <- c(1,1,1,2,2,2,1,1,1,1,2,2,2,2,2)
age <- c(0,1,2,0,1,2,0,1,2,3,0,1,2,3,4)
babies <- c(0,0,1,0,1,0,0,0,0,1,0,0,0,1,1)
df <- data.frame(id,rep,age,babies)
Run Code Online (Sandbox Code Playgroud)
所以在这里,最终的数据框应该是这样的
id <- c("A","A","B","B")
rep <- c(1,2,1,2)
age <- c(2,1,3,3)
babies <- c(1,1,1,1)
df <- data.frame(id,rep,age,babies)
Run Code Online (Sandbox Code Playgroud) 我有以下混合效应模型的输出。我想谈谈模型解释了多少变化。随机效应下的方差是否对应于残差(注:这里的试验是随机效应)所解释的变异?即 58.6 % 或者有其他方法来推断这一点
\n\nREML criterion at convergence: 71.9\n\nScaled residuals: \n Min 1Q Median 3Q Max \n-1.82579 -0.59620 0.04897 0.62629 1.54639 \n\nRandom effects:\n Groups Name Variance Std.Dev.\n trial (Intercept) 0.06008 0.2451 \n Residual 0.58633 0.7974 \nNumber of obs: 60, groups: trial, 30\n\nFixed effects:\n Estimate Std. Error df t value Pr(>|t|) \n(Intercept) 1.5522 0.2684 12.6610 13.233 0.09888 \ndrugantho 0.8871 0.1753 14.0000 1.043 0.31601 \ninterventionadded 0.2513 0.2553 14.0000 -1.276 0.32436 ** \nsexmale 3.0026 0.6466 15.0000 4.066 0.00021 \n---\nSignif. codes: 0 \xe2\x80\x98***\xe2\x80\x99 …Run Code Online (Sandbox Code Playgroud) 我需要求解一个由四个方程组成的系统并求解(Alg,Blg,C,D)..其他只是变量.
dAlg = (ab*D + a1*f1*D*Alg*Blg + a2*f2*D*Alg*C)/e1 - m1*Alg;
dBlg = (f11*D*Blg)/eB - f1*Alg*Blg - mp*Blg;
dC = (f22*D*C)/eC - f2*Alg*C - mp*C;
dD = (f*R/(h + R)) - r*D - ab*D - a1*f1*D*Alg*Blg - f11*D*Blg -
a2*f2*D*Alg*C-f22*D*C;
Run Code Online (Sandbox Code Playgroud)
所以我想解决{dAlg = 0,dBlg = 0,dC = 0,dD = 0},然后找出所有可能的解决方案组合.
我不知道如何使用求解包在R上进行此操作(我发现的示例似乎更简单的方程式)...但是当我使用另一个包时,我得到以下答案.我想在R中实现同样的目标
{{Alg -> ((eC f11 - eB f22) mp)/(-eC f11 f2 + eB f1 f22),
Blg -> -((
eC f f11 f2 R - eB f f1 f22 R + …Run Code Online (Sandbox Code Playgroud) r simultaneous solver equation-solving differential-equations
对于主y轴和x轴,我有通用标题,如"Tank's Ratio"和"Counts".我想要第二行标签,我指定比率和计数.例如.就在"Tank's Ratio"之下,我希望"#in water /#in sand"中的字体较小,但是沿着y轴.类似地,对于x轴.这是基本代码
data <- data.frame(set = c(1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 4, 4), density = c(1, 3, 3, 1, 3, 1, 1, 1, 3, 3, 1, 3), counts = c(100, 2, 3, 76, 33, 12, 44, 13, 54, 36, 65, 1), ratio = c(1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 90, 1))
library(ggplot2)
ggplot(data, aes(x = counts, y = ratio)) +
geom_point() +
ylab("Tank's Ratio") +
xlab("Counts")
Run Code Online (Sandbox Code Playgroud) 我有一个 2 x 2 阶乘数据集,我使用mean_cl_boot函数绘制了置信区间。我想使用适当的函数在 R 中计算它。我怎样才能做到这一点?
我的数据集示例如下:
df <- data.frame(
fertilizer = c("N","N","N","N","N","N","N","N","N","N","N","N","P","P","P","P","P","P","P","P","P","P","P","P","N","N","N","N","N","N","N","N","N","N","N","N","P","P","P","P","P","P","P","P","P","P","P","P"),
level = c("low","low","high","high","low","low","high","high","low","low","high","high","low","low","high","high","low","low","high","high","low","low","high","high","low","low","high","high","low","low","high","high","low","low","high","high","low","low","high","high","low","low","high","high","low","low","high","low"),
repro = c(0,90,2,4,0,80,1,90,2,33,56,0,99,100,66,80,1,0,2,33,0,0,1,2,90,5,2,2,5,8,0,1,90,2,4,66,0,0,0,0,1,2,90,5,2,5,8,55)
)
Run Code Online (Sandbox Code Playgroud)
我知道有从图表中提取CI点的方式,但我并不想这样做。我想使用计算这个的函数。
这是方程a <- x * t - 2 * x。我想为 解这个方程t。所以基本上,设置a = 0并求解t。我是R求解方程包的新手。我需要解决复杂根的包。我使用的原始方程有实根和虚根。我只是在寻找代数解决方案,而不是数字解决方案。
我试过:
a <- x * t - 2 * x
solve(a,t)
Run Code Online (Sandbox Code Playgroud)
我遇到了一个错误:
a <- x * t - 2 * x
solve(a,t)
Run Code Online (Sandbox Code Playgroud) 我有一个 ggplot 存储在 say 中p,希望添加一个poly_stat_eq图层来显示曲线方程。我想更改文本的字体大小,但找不到有关如何实现它的文档
p +
stat_poly_eq(formula = y ~ x,
aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~")),
label.x = 4, label.y = -5, parse = TRUE)
Run Code Online (Sandbox Code Playgroud) 我有一些计数数据。我想用计数数据绘制直方图,并添加负二项式、正态密度函数和泊松密度函数,但将函数拟合到计数数据。
我尝试按照这个示例进行操作,但是(a)我无法拟合负二项式和泊松函数(b)无法将其缩放到计数数据级别(c)不知道如何将所有三个函数拟合到同一个图表上,并为每个函数添加图例(d)行另外,我怎样才能获得每个适合的基本统计数据?例如,负二项式拟合将生成参数 k。我怎样才能让它出现在情节上
set.seed(111)
counts <- rbinom(500,100,0.1)
df <- data.frame(counts)
ggplot(df, aes(x = counts)) +
geom_histogram(aes(y=..density..),colour = "black", fill = "white") +
stat_function(fun=dnorm,args=fitdistr(df$counts,"normal")$estimate)
ggplot(df, aes(x = counts)) +
geom_histogram(aes(y=..density..),colour = "black", fill = "white") +
stat_function(fun=poisson,args=fitdistr(df$counts,"poisson")$estimate)
ggplot(df, aes(x = counts)) +
geom_histogram(aes(y=..density..),colour = "black", fill = "white") +
stat_function(fun=dnbinom,args=fitdistr(df$counts,"dnbinom")$estimate)
Run Code Online (Sandbox Code Playgroud) r ×10
ggplot2 ×4
mixed-models ×2
axes ×1
combinations ×1
data-fitting ×1
dataframe ×1
distribution ×1
fonts ×1
for-loop ×1
math ×1
permutation ×1
random ×1
simultaneous ×1
size ×1
solver ×1
subtitle ×1
variance ×1