简单拟合一个线性模型 states <- as.data.frame(state.x77[,c("Murder", "Population", "Illiteracy", "Income", "Frost")]) fit <- lm(Murder ~ Population + Illiteracy + Income + Frost, data=states) #summary(fit) 线性模型假设的综合验证 使用gvlma包中的gvlma函数验证模型的线性假设。gvlma函数由Pena和Slate ( 2006 )编写,能对线性模型假设进行综合验证,同时还能做偏斜度、峰度和异方差性的评价。换句话说,它给模型假设提供了一个单独的综合检验(通过/不通过)。 # Listing 8.8 - Global test of linear model assumptions library(gvlma) gvmodel <- gvlma(fit) summary(gvmodel) ## ## Call: ## lm(formula = Murder ~ Population + Illiteracy + Income + Frost, ## data = states) ## ## Residuals: ## Min 1Q Median 3Q Max ## -4.

Continue reading

1.Survival Analysis Basics Basic concept Censoring:right censoring Survival and hazard functions Log-rank test: Kaplan-Meier survival estimate null hypothesis is that there is no difference in survival between the two groups Non-parametric test , so no assumptions about the survival distributions Log rank statistic is approximately distributed as a chi-square test statistic. Survival analysis in R #data library("survival") library("survminer") data("lung") #survival fit fit <- survfit(Surv(time, status) ~ sex, data = lung) #summary summary(fit)$table ## records n.

Continue reading

What do you do when you want to use results from the literature to anchor your own analysis? we’ll go through a practical scenario on scraping an html table from a Nature Genetics article into R and wrangling the data into a useful format. 01. Scraping a html table from a webpage #load packages library("rvest") library("knitr") library(tidyverse) #scraping web page url <- "https://www.nature.com/articles/ng.2802/tables/2" #====🔥find where is the table lives on this webpage==== table_path='//*[@id="content"]/div/div/figure/div[1]/div/div[1]/table' #get the table nature_genetics_table2 <- url %>% read_html() %>% html_nodes(xpath=table_path) %>% html_table(fill=T) %>% .

Continue reading

Author's picture

Jixing Liu

Reading And Writing

Data Scientist

China