R中的波浪线Tilde_in_R

Tilde in R ~

Tilde symbol l is used within formulas of statistical models, as mainly this symbol is used to define the relationship between the dependent variable and the independent variables in the statistical model formula in the R programming language. The left side of the tilde symbol specifies the target variable (dependent variable or outcome) and the right side of the tilde specifies the predictor variable(independent variables). (Source: https://www.geeksforgeeks.org/use-of-tilde-in-r/)

Below source: https://bookdown.org/danieljcarter/r4steph/two-sample-t-test.html

Two-sample t-test

We can also conduct a two-sample t-test to determine if the mean population birthweight in boys is the same as the mean population birthweight in girls. The syntax here is slightly different as it uses R’s formula interface. A formula is indicated by the presence of a tilde (~), and the tilde is shorthand for ‘estimate’. So the formula in the code chunk below says: estimate birthweight from sex. This is slightly counter-intuitive for the t-test but will make more sense when applied more generally under a regression framework later on.

We use the var.test() command to conduct an F test to assess whether the equality of variance assumption holds.


```r
#--- Run the two-sample t-test
bab9 %$% t.test(bweight ~ sex, var.equal = T)

## 
##  Two Sample t-test
## 
## data:  bweight by sex
## t = 3, df = 600, p-value = 0.001
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   66.6 267.7
## sample estimates:
##   mean in group male mean in group female 
##                 3211                 3044

Bonferroni correction for multiple tests

Source: https://book.phylolab.net/binf8441/lab7.html
在这里插入图片描述


```r
numtest = 4
pvalue = 1:numtest
for(i in 1:numtest){
    pvalue[i] = t.test(data[,i+1] ~ data[,1])$p.value
}

print("the Bonferroni adjusted pvalues")
pvalue*numtest

We estimate the four columns based on the first column, 0 or 1 group. 是按照第一列分成的两组。

> t.test(data[,i+1] ~ data[,1])

	Welch Two Sample t-test

data:  data[, i + 1] by data[, 1]
t = -2.9682, df = 17.128, p-value = 0.008566
alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
95 percent confidence interval:
 -2.6167353 -0.4430667
sample estimates:
mean in group 0 mean in group 1 
      0.3970631       1.9269641 
      
  • 18
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

TuringSnowy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值