TSq = (50*60)/(50+60) * (mu1-mu2)' * inv(Sp) * (mu1-mu2);这行代码报错error using ==》mtimes
时间: 2023-12-29 17:06:15 浏览: 153
这个错误通常是因为 `*` 符号左右两边的矩阵/向量维度不匹配,无法进行矩阵乘法运算。请检查一下 `mu1`、`mu2` 和 `Sp` 的维度是否正确。
另外,公式中的 `inv(Sp)` 表示 `Sp` 的逆矩阵,需要保证 `Sp` 可逆。如果 `Sp` 不可逆,使用 `inv()` 函数将会报错。可以使用 `pinv()` 函数来计算广义逆矩阵来避免这个问题。
相关问题
milk.gas = milk[milk$v4 == "gasline",1:3] milk.gas milk.diesel = milk[milk$v4 == "diesel",1:3] milk.diesel n1 = dim(milk.gas)[1] n1 n2 = dim(milk.diesel)[1] n2 p = 3 y.bar.g = colMeans(milk.gas) y.bar.d = colMeans(milk.diesel) s.g = cov(milk.gas) s.d = cov(milk.diesel) s.pl = (s.g*(n1-1)+s.d*(n2-1))/(n1+n2-2) s.pl T.sq = (n1*n2)/(n1+n2)*t(y.bar.g-y.bar.d)%*%solve(s.pl)%*%(y.bar.g-y.bar.d) T.sq cut.off = (n1+n2-2)*p/(n1+n2-p-1)*qf(1-0.01,p,n1+n2-p-1) cut.off把上述R语言代码用自定义函数function表示
可以将上述R语言代码用自定义函数function表示如下:
```R
calculate_Tsq <- function(data) {
milk.gas <- data[data$v4 == "gasline", 1:3]
milk.diesel <- data[data$v4 == "diesel", 1:3]
n1 <- dim(milk.gas)[1]
n2 <- dim(milk.diesel)[1]
p <- 3
y.bar.g <- colMeans(milk.gas)
y.bar.d <- colMeans(milk.diesel)
s.g <- cov(milk.gas)
s.d <- cov(milk.diesel)
s.pl <- (s.g*(n1-1)+s.d*(n2-1))/(n1+n2-2)
T.sq <- (n1*n2)/(n1+n2)*t(y.bar.g-y.bar.d)%*%solve(s.pl)%*%(y.bar.g-y.bar.d)
cut.off <- (n1+n2-2)*p/(n1+n2-p-1)*qf(1-0.01,p,n1+n2-p-1)
return(list(T.sq=T.sq, cut.off=cut.off))
}
# example usage:
data <- read.csv("milk.csv")
result <- calculate_Tsq(data)
print(result$T.sq)
print(result$cut.off)
```
pin_memory=True/False
pin_memory参数可以设置为True或False。当pin_memory=True时,数据将被锁页在内存中,这有助于加速数据传输,特别是在使用GPU进行训练时。\[2\]然而,如果计算机的内存不足或系统卡顿,可以将pin_memory设置为False,以释放内存资源。\[1\]因为pin_memory的性能与计算机硬件有关,所以在默认情况下,pytorch将pin_memory设置为False,以适应更广泛的设备。\[3\]
#### 引用[.reference_title]
- *1* [RuntimeError: Pin memory thread exited unexpectedly 或 OSError: [Errno 9] Bad file descriptor 的解决...](https://blog.csdn.net/weixin_44025103/article/details/127697035)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [pytorch:参数pin_memory=True和non_blocking=True的作用](https://blog.csdn.net/Caesar6666/article/details/127283965)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [pytorch创建data.DataLoader时,参数pin_memory的理解](https://blog.csdn.net/tsq292978891/article/details/80454568)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文