我一直在使用这个行代码中的broman包来将p值引入我的散文中。有没有办法更新内联代码,以便小于.001的p值自动重新格式化为“< .001”而不是当前输出“= .000”?
NSArray *devices = [AVCaptureDevice devices];
for (AVCaptureDevice *device in devices) {
NSLog(@"In use by other application %hhd", [device isInUseByAnotherApplication]);
}
气缸数显着预测每加仑英里数, p = library(broman)
m <- lm(mpg ~ cyl, mtcars)
mdf <- data.frame(summary(m)$coefficients)
# transform into a clean function
names(mdf) [names(mdf) == 'Pr...t..'] <- 'p'
。
答案 0 :(得分:1)
你可以简单地编写一个这样的函数:
myround2 <- function(x, digits = 3){
if (x < 10^-digits) return(paste('<', 10^-digits))
paste('=', myround(x, digits))
}
并在降价时使用myround
。
答案 1 :(得分:0)
I have a particular way I like my p-values formatted, so I wrote my own function to handle it all at once. I bring it up here only because format.pval
seems pretty rigid in what it will format (meaning, it seems it will do the same format for all values, where I prefer some values to be rounded to two decimal places and some to three). If format.pval
doesn't fit your exact needs, it isn't difficult to write your own function.
set.seed(pi)
p_very_large <- runif(10, .98, 1)
p_large <- runif(10, .10, .98)
p_small <- runif(10, .001, .10)
p_very_small <- runif(10, 1e-7, 1e-3)
cbind(format.pval(p_very_large, eps = .001, digits = 3),
pixiedust::pvalString(p_very_large))
cbind(format.pval(p_large, eps = .001, digits = 3),
pixiedust::pvalString(p_large))
cbind(format.pval(p_small, eps = .001, digits = 3),
pixiedust::pvalString(p_small))
cbind(format.pval(p_very_small, eps = .001, digits = 3),
pixiedust::pvalString(p_very_small))
答案 2 :(得分:0)
```{r inline_rename function}
# apply this function to clean up names of an lm object.
# e.g., m <- lm(mpg ~ cyl, mtcars); m <- inline_rename(m)
inline_rename <- function(x){
x <- data.frame(summary(x)$coefficients)
names(x) [names(x) == 'Estimate'] <- 'Est'
names(x) [names(x) == 'Pr...t..'] <- 'p'
names(x) [names(x) == 'Std..Error'] <- 'SE'
names(x) [names(x) == 't.value'] <- 't'
x
}
```
```{r format_pval function}
library(broman) # for myround function
format_pval <- function(x){
if (x < .001) return(paste('<', '.001'))
if (x > .250) return(paste('>', '.250'))
paste('=', myround(x, 3)) # 3 = no. of digits to round p value to if .001 < p < .250.
}
```
```{r create some regression models to pull stats from}
m <- lm(mpg ~ cyl + disp + hp + wt + qsec + vs + am + gear, mtcars)
m <- inline_rename(m)
```
重量显着预测mpg,$ {\ beta} $ = r myround(m["wt","Est"], 2)
, p r format_pval(m["wt","p"])
。
齿轮数不会显着预测mpg,$ {\ beta} $ = r myround(m["gear","Est"], 2)
, p r format_pval(m["gear","p"])
。
```{r}
m <- lm(mpg ~ hp, mtcars)
m <- inline_rename(m)
```
马力显着预测mpg,$ {\ beta} $ = r myround(m["hp","Est"], 2)
, p r format_pval(m["hp","p"])
。