博文

目前显示的是 2019的博文

docker

curl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh sudo usermod -aG docker xuefliang sudo chmod a+rw /var/run/docker.sock docker search portainer docker pull portainer/portainer docker volume create portainer_data docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer docker pull teddysun/v2ray must create a configuration file /etc/v2ray/config.json mkdir -p /etc/v2ray docker run -d -p 1080:1080 --name v2ray --restart=always -v /etc/v2ray:/etc/v2ray teddysun/v2ray docker pull rocker/r-base docker run --rm -ti rocker/r-base docker pull rocker/r-apt docker pull rocker/rstudio-daily docker run -e PASSWORD=yourpassword --rm -p 8787:8787 rocker/rstudio docker pull rocker/tidyverse docker pull rocker/r-ver docker pull rocker/verse docker pull rocker/geospatial docker pull rocker/binder docker pull rocker/shiny docker run -d --name rstudio -v /home/xuefliang/Documents:/home/rstudio

Choropleth Map in ggplot2

library(tidyverse) states<-as.data.frame(state.x77) %>%   mutate(region=tolower(rownames(states))) states_map <- map_data("state")   fact_join <- left_join(states_map, states, by = "region") ggplot(fact_join, aes(long, lat, group = group))+   geom_polygon(aes(fill = Population), color = "white")+   # 将map颜色设置为“岩浆”色,简称为“A”,共有“A”,“B”,“C”,“D”和“E”五种   scale_fill_viridis_c(option = "C")+   theme_classic()

dtplyr使用

devtools::install_github("tidyverse/dtplyr") library(tidyverse) library(dtplyr) mtcars2 <- lazy_dt(mtcars) mtcars2 %>%   filter(wt < 5) %>%   mutate(l100k = 235.21 / mpg) %>% # liters / 100 km   group_by(cyl) %>%   summarise(l100k = mean(l100k)) %>%   as_tibble()

miraclecast安装

sudo add-apt-repository ppa:thopiekar/miraclecast sudo apt-get update sudo apt-get install miraclecast

ipv6

ping6  2001:c50:ffff:1::9999 ping6  www.twnic.net https://v6directory.twnic.net.tw/directory.cgi?more=11600

fable 包

library(tidyverse) library(tsibble) library(lubridate) library(fable) library(verification) data(tourism) #简化州名 tourism <- tourism %>%   mutate(     State = recode(State,                    "Australian Capital Territory" = "ACT",                    "New South Wales" = "NSW",                    "Northern Territory" = "NT",                    "Queensland" = "QLD",                    "South Australia" = "SA",                    "Tasmania" = "TAS",                    "Victoria" = "VIC",                    "Western Australia" = "WA"     )   ) #单序列预测 snowy <- tourism %>%   filter(     Region == "Snowy Mountains",     Purpose == "Holiday"   ) snowy %>%   autoplot(Trips) #seasonal naive、ETS和arima fit <- snowy %>%   model(     snaive = SNAIVE(Trips ~ lag("year")),     ets = ETS(Trips),

inspectdf

#检查变量类型分布 inspect_types(stations_norway) %>%   show_plot() #检查字符变量分布 #high_cardinality 将少数类别合并   stations_norway %>%     select_if(is.character)%>%     inspect_cat() %>%     show_plot(high_cardinality = 1) #检查数值变量分布 stations_norway %>%   select_if(is.numeric) %>%   inspect_num() %>%   show_plot() #检查变量缺失值分布 stations_norway %>%   inspect_na() #检查字符变量不平衡性分布 stations_norway %>%   select_if(is.character)%>%   inspect_imb()%>%   show_plot()

缺失值替代

sqltxt <-"select ym_mc,xt_djjgdm from inoc_jzjl where jz_sj > =to_date('2018-01-01','yyyy-mm-dd') and jz_sj <=to_date('2018-12-31','yyyy-mm-dd') and sfmf='1'" dzmc <- con %>%   tbl(in_schema('ipvsdb','SYS_XZQH_ZZJG')) %>%   select(DZMC,DZBM) %>%   filter(str_length(DZBM)==4) %>%   collect() %>%   clean_names() vacc<- tbl(con,sql(sqltxt)) %>%   collect() %>%   clean_names()%>%   mutate(shi=str_sub(xt_djjgdm,1,4)) %>%   group_by(shi,ym_mc) %>%   summarise(n=n()) %>%   left_join(dzmc,by=c('shi'='dzbm')) %>%   drop_na(dzmc) %>%   spread(ym_mc,n) %>%   mutate_all(list(~replace_na(.,0)))   mutate_if(is.numeric,list(~replace_na(.,0))) write.csv(vacc,'~//My Pictures//vacc.csv')

分市州计算每电子监管码接种剂次数

xzqh<- con %>%   tbl(in_schema('ipvsdb','SYS_XZQH_ZZJG')) %>%   select(DZMC,DZBM) %>%   filter(str_length(DZBM)==4) %>%   collect() %>%   clean_names() sql_txt <- "select grda_code,ym_bm,ym_mc,xt_djjgdm,jz_sj,jz_zc,dzjgm,substr(xt_djjgdm,1,4) as shi from INOC_JZJL where jz_sj>=to_date('2018-01-01','yyyy-mm-dd') and jz_sj<=to_date('2019-12-31','yyyy-mm-dd') and ym_bm='0311'" sunhao <- tbl(con,sql(sql_txt)) %>%   collect() %>%   clean_names() %>%   filter(!is.na(dzjgm)) %>%   mutate(year=str_sub(jz_sj,1,4)) %>%   group_by(shi,year) %>%   summarise(count=n(),dzn=n_distinct(dzjgm)) %>%   mutate(jici=round(count/dzn,2)) %>%   left_join(xzqh,by = c("shi"="dzbm"))

单位数用户数扫码数

#Sys.setenv(NLS_LANG="AMERICAN_AMERICA.ZHS16GBK") Sys.setenv(NLS_LANG="AMERICAN_AMERICA.UTF8") library(ROracle) library(tidyverse) library(dbplyr) library(knitr) library(magrittr) library(lubridate) library(janitor) drv <- dbDriver("Oracle") connect.string <- paste(   "(DESCRIPTION=",   "(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.30.12)(PORT=1521))",   "(CONNECT_DATA=(SERVICE_NAME=JZDB1)))", sep = "") con <- dbConnect(drv, username = "", password = "",                  dbname = connect.string) dqmc <- con %>%   tbl(in_schema('ipvsdb','SYS_XZQH_ZZJG')) %>%   select(DZMC,DZBM) %>%   filter(str_length(DZBM)==4) %>%   collect() %>%   clean_names() %>%   remove_empty(c("rows", "cols")) #单位数 sqltxt <- "select * from sys_org" tmp <- tbl(con,sql(sqltxt)) %>%   collect() %>%   clean_names() %>

分市州用户管理

Sys.setenv(NLS_LANG="AMERICAN_AMERICA.ZHS16GBK") library(ROracle) library(tidyverse) library(dbplyr) library(knitr) library(magrittr) library(stringr) library(lubridate) library(janitor) drv <- dbDriver("Oracle") connect.string <- paste(   "(DESCRIPTION=",   "(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.30.12)(PORT=1521))",   "(CONNECT_DATA=(SERVICE_NAME=JZDB1)))", sep = "") con <- dbConnect(drv, username = "", password = "",                  dbname = connect.string) sqltxt <-"select * from sys_user" user<- tbl(con,sql(sqltxt)) %>%   collect() %>%   clean_names()%>%   mutate(shi=str_sub(jgbm,1,4)) %>%   group_by(shi,jlzt) %>%   summarise(n=n())   spread(jlzt,n) tmp <- con %>%   tbl(in_schema('ipvsdb','SYS_XZQH_ZZJG')) %>%   select(DZMC,DZBM) %>%   filter(str_length(DZBM)==4) %>%   collect() %>%   clean_names()

tidyr包

library(tidyr) library(dplyr) data(who) names(who) #pivot_longer类似gather who %>% pivot_longer(   cols = new_sp_m014:newrel_f65,   names_to = c("diagnosis", "gender", "age"),   names_pattern = "new_?(.*)_(.)(.*)",   values_to = "count",   values_drop_na = TRUE ) stocks <- tibble(   time = as.Date('2009-01-01') + 0:9,   X = rnorm(10, 0, 1),   Y = rnorm(10, 0, 2),   Z = rnorm(10, 0, 4) ) stocks %>% gather("stock", "price", -time) stocks %>% pivot_longer(-time,                         names_to = 'stock',                         values_to = 'price') stocksm <- stocks %>%   pivot_longer(cols = c(X,Y,Z),                names_to = 'stock',                values_to = 'price') stocksm %>% spread(stock, price) #填补缺失值 stocksm %>% pivot_wider(names_from = stock,                         values_from = price,                         values_fill = list(seen = 0)) #每行有4个

sqlite

sudo apt-get install sqlite3 sqlitebrowser

分疫苗分针次接种率

Sys.setenv(NLS_LANG="AMERICAN_AMERICA.ZHS16GBK") library(ROracle) library(tidyverse) library(dbplyr) library(knitr) library(magrittr) library(stringr) library(lubridate) library(janitor) ym_jzl <- function(csrq_begin,csrq_end,static_date,ymbm,jzzc,month,jcqk,czlx,level,condition) {   static_date <- if_else(condition,static_date - ddays(12*30),static_date)     temp <- con %>%     tbl(in_schema('ipvsdb','GRDA_ET')) %>%     filter(between(CSRQ,to_date(csrq_begin,"YYYY-MM-DD"),                    to_date(csrq_end,"YYYY-MM-DD")) &  JCQK==jcqk & CZLX==czlx) %>%     select(GRDA_ET_LSH,GLDW_BM,CSRQ)     jzjl <-  con %>%     tbl(in_schema('ipvsdb','INOC_JZJL')) %>%     right_join(temp,by=c('GRDA_ET_LSH'='GRDA_ET_LSH')) %>%     select(CSRQ,YM_BM,JZ_ZC,GRDA_ET_LSH,GLDW_BM) %>%     collect() %>%      clean_names() %>%     mutate(csrq=as.Date(csrq))

计算日期间隔

library(lubridate) library(janitor) as.period(ymd('2019-09-06')-ymd('2019-01-09'),unit = 'days')

anbox

sudo add-apt-repository ppa:morphis/anbox-support sudo apt install -y anbox-modules-dkms sudo modprobe ashmem_linux sudo modprobe binder_linux sudo snap install --devmode --beta anbox sudo apt install wget lzip unzip squashfs-tools wget https://raw.githubusercontent.com/geeks-r-us/anbox-playstore-installer/master/install-playstore.sh chmod +x install-playstore.sh sudo ./install-playstore.sh sudo ./install-playstore.sh --clean anbox.appmgr sudo /snap/anbox/current/bin/anbox-bridge.sh start sudo /snap/anbox/current/bin/anbox-bridge.sh restart https://blog.csdn.net/ZhangRelay/article/details/84465548 https://www.linuxuprising.com/2018/07/anbox-how-to-install-google-play-store.html

tidyverts软件包

library(tidyverse) library(tsibble) library(lubridate) library(feasts) #有一套新的进行整洁的时间序列分析的软件包, 为tidyverts软件包。 #tsibble提供了数据基础设施,用于整理时态数据和争用工具。 一个tsibble是一个时间序列对象,比ts,xts等现有类更容易使用。 #使用as_tsibble()可以轻松地将现有ts对象转换为tsibble对象 USAccDeaths %>%   as_tsibble() #这将创建一个Index列,其中包含时间或日期索引。 这些在tsibbles中始终是显式的,并且可以采用丰富的时间和日期类来处理任何类型的时态数据。 第二列是测量变量。 请注意标题中的[1M] ,表示这是月度数据。 #从csv文件创建tsibbles也很容易,首先使用readr::read_csv()然后使用as_tsibble()函数读取它们。 tourism %>%   filter(Purpose=='Holiday') %>%   group_by(State) %>%   summarise(Trips=sum(Trips)) #这里我们有一些名为Keys的附加列。 键和索引的每个唯一组合应该有一行。 不是索引或关键变量的列是测量变量。有三个键( Region , State和Purpose )和一个Measurement( Trips ) tourism %>%   mutate(Year=year(Quarter)) %>%   index_by(Year) %>%   group_by(Region,State,Purpose) %>%   summarise(Trips=sum(Trips)) %>%   ungroup() #Date和Time变量将索引拆分为两个组件,表示日期和一小时。 这使得生成一些有趣的图很容易。  pedestrian %>%   mutate(     Day = lubridate::wday(Date, label = TRUE),     Weekend = (Day %in% c("Sun", "Sat"))

贝叶斯分析Example

--- title: "Untitled" author: "xuefliang" date: "7/11/2019" output:   html_document:     theme: readable     highlight: haddock      df_print: paged     code_folding: show     toc: true     number_sections: true     fig_width: 10.08     fig_height: 6 tags: [r, bayesian, posterior, test] editor_options:   chunk_output_type: console --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE,warning = FALSE,message = FALSE,comment=">") options(knitr.kable.NA = '',digits=2) set.seed(333) library(tidyverse) library(bayestestR) library(rstanarm) library(insight) ``` ## 示例1:启动贝叶斯模型   一旦安装了必要的软件包,我们就可以加载rstanarm(拟合模型),bayestestR(计算有用的指标)和访问参数。 ### 简单的线性模型(又名回归) 我们将从一个简单的回归开始,测试Petal.Length(预测变量或独立变量)与Sepal.Length(响应变量或依赖变量)之间的关系,它们来自iris数据集,默认包含在R中。 #### 拟合模型 让我们从适合模型的频率版本开始,只是为了得到一些参考: ```{r} model <- lm(Sepal.Length ~ Petal.Length, data=iris) summary(model) ``` 在该模型中,Petal.Length和Sepal.Length之间的线性关系是正的和显着的(β= 0.41,t= 21.6,p <.00

贝叶斯分析入门

--- title: "贝叶斯分析入门" author: "xuefliang" date: "5/31/2019" output:   html_document:     theme: readable     highlight: haddock      df_print: paged     code_folding: show     toc: true     toc_float: TRUE     number_sections: false      fig_width: 10.08     fig_height: 6     fig_caption: TRUE tags: [r, bayesian, posterior, test] editor_options:   chunk_output_type: console --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE,warning = FALSE,message = FALSE,comment=">",tidy = T) #eval判断是否执行这个代码eval判断是否执行这个代码 #echo选择是否让代码在结果中显示 #results是否输出结果 options(knitr.kable.NA = '',digits=2) set.seed(333) ``` ```{r results='hide'} #https://github.com/easystats/bayestestR#documentation #https://www.r-bloggers.com/bayesian-models-in-r-2/ #devtools::install_github("easystats/easystats") #https://blog.csdn.net/leolotus/article/details/50769017 ## https://blog.csdn.net/leolotus/article/details/50956532 library(tidyverse) li

贝叶斯分析Article

--- title: "贝叶斯分析Article" author: "xuefliang" date: "7/11/2019" output:   html_document:     theme: readable     highlight: haddock     df_print: paged     code_folding: show     toc: true     toc_float: TRUE     number_sections: false     fig_width: 10.08     fig_height: 6 tags: [r, bayesian, posterior, test] editor_options:   chunk_output_type: console --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE,warning = FALSE,message = FALSE,comment=">") options(knitr.kable.NA = '',digits=2) set.seed(333) library(tidyverse) library(bayestestR) library(rstanarm) library(insight) ``` ## 可信区间(CI) ### 什么是可信区间? 可信区间是贝叶斯统计中的一个重要概念。 其核心目的是描述和总结与您的参数相关的不确定性 。 在这方面,它可能看起来与频率主义的置信区间很相似。然而,虽然他们的目标相似,但他们的统计定义和意义却截然不同。实际上,虽然后者是通过一个充满罕见测试假设和近似的复杂算法获得的,但可信区间的计算相当简单。 由于贝叶斯推断返回了可能的效应值(后验)的分布,可信区间只是包含特定百分比的可能值的范围。 例如,95%可信区间仅仅是后验分布的中心部分,其包含95%的值。 请注意,与频率主义区间相比,这大大提高了贝叶斯区间的可解释性。事实上,贝叶斯框架允许说“给定观察到的数据,效果有95%的概率落在这个范围内” ,而频率较低的直接替代方案(95% 置信区间 )将“ 有

ggfortify包学习

library(ggfortify) library(tidyverse) #PCA (主成分分析) df <- iris[c(1, 2, 3, 4)] prcomp(df) %>%   #autoplot()   #选择数据中的一列来给画出的点按类别自动分颜色   #autoplot(data = iris, colour = 'Species')   #给定label = TRUE 可以给每个点加上标识(以rownames为标准),也可以调整标识的大小   #autoplot( data = iris, colour = 'Species', label = TRUE, label.size = 3)   #给定 shape = FALSE 可以让所有的点消失,只留下标识,这样可以让图更清晰,辨识度更大   # autoplot(data = iris, colour = 'Species', shape = FALSE, label.size = 3)   # 给定 loadings = TRUE 可以很快的画出特征向量。   # autoplot(data = iris, colour = 'Species', loadings = TRUE)   # 可以显示特征向量的标识以及调整他们的大小   autoplot(data = iris, colour = 'Species',            loadings = TRUE, loadings.colour = 'blue',            loadings.label = TRUE, loadings.label.size = 3) # 因素分析 factanal(state.x77, factors = 3, scores = 'regression') %>%   #autoplot(data = state.x77, colour = 'Income')   autoplot(label = TRUE, label.size = 3,          loadings = TRUE, loadings.label = TRUE, load

hrbraddins包

sudo add-apt-repository -y ppa:opencpu/poppler sudo apt-get update sudo sudo apt-get install -y libpoppler-cpp-dev remotes::install_gitlab("hrbrmstr/hrbraddins")

dbplot包学习

#sudo apt-get install sqlitebrowser sqlite3 #remotes::install_github("edgararuiz/dbplot") library(DBI) library(tidyverse) library(janitor) library(dbplot) library(modeldb) library(tidypredict) # Create an ephemeral in-memory RSQLite database con <- dbConnect(RSQLite::SQLite(), ":memory:") dbListTables(con) dbWriteTable(con, "flights", nycflights13::flights) dbWriteTable(con, "mtcars", mtcars) dbListTables(con) dbReadTable(con, "flights") res <- dbSendQuery(con, "SELECT * FROM flights") dbFetch(res) dbListFields(con,"flights") flight <- tbl(con,"flights") flight %>% dbplot_histogram(distance,binwidth = 700)+   labs(title = "Flights - Distance traveled") +   theme_classic() flight %>%   dbplot_raster(sched_dep_time, sched_arr_time) flight %>%   dbplot_raster(     sched_dep_time,     sched_arr_time,     mean(distance, na.rm = TRUE)   ) flight %>%   dbplot_bar(origin) flight %>