
R
文章平均质量分 59
相逢一醉为前缘
这个作者很懒,什么都没留下…
展开
-
Statistical transformations 统计转换
下图显示了钻石数据集中的钻石总数,按切工分组。钻石数据集来自 ggplot2,包含大约 54,000 颗钻石的信息,包括每颗钻石的价格、克拉、颜色、净度和切工。该图表显示,与低质量切割相比,高质量切割的钻石更多。ggplot(data = diamonds) + geom_bar(mapping = aes(x = cut))在 x 轴上,图表显示切工,这是钻石的一个变量。 在 y 轴上,它显示计数,但计数不是钻石中的变量! 计数从何而来? 许多图表(如散点图)绘制数据集的原翻译 2022-01-11 22:08:26 · 299 阅读 · 0 评论 -
ggplot中的Geometric objects
在ggplot中我们说上面两图用不同的几何体表示,geom是几何对象,例如条形图使用bar geoms,折线图使用line geoms,箱线图使用boxplot geoms等等。你可以使用不同的几何体来描绘同一个数据。要更改图中的geom,请使用ggplot()中的geom函数。例如要画上面的图,代码为# leftggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy))# rightggplot(dat...翻译 2021-12-29 20:53:30 · 402 阅读 · 0 评论 -
弱大数定理、强大数定理
马尔可夫不等式 切比雪夫不等式 弱大数定理 强大数定理马尔可夫不等式转载 2021-12-17 08:33:16 · 4390 阅读 · 0 评论 -
ggplot 中的 Facets
对于分类变量比较有用的一个方法是将图拆分成多个facets,每个子图都展示数据的一个子集。要通过单个变量对绘图进行分面,请使用facet_wrap()。facet_wrap()的第一个参数应该是一个公式。ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy)) + facet_wrap(~ class, nrow = 2)如果要对两个变量的组合对绘图进行分面,那么需要facet_gri...翻译 2021-12-15 22:18:35 · 664 阅读 · 0 评论 -
关于ggplot2画图的一个小问题
如果你把代码写成这样ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy))则R只会运行第一行,然后只给出一个空白的画板。这是因为ggplot2画图"+"必须放在一行的末尾,而不是开头,否则就会出错。...翻译 2021-12-02 22:03:25 · 513 阅读 · 0 评论 -
making graphs with ggplot2
代码模板:ggplot(data = <DATA>) + <GEOM_FUNCTION>(mapping = aes(<MAPPINGS>))例如:ggplot(data = mpg)得到的结果是一块空白的画布。例如:ggplot(data = mpg) + geom_point(mapping = aes(x = hwy, y = cyl))图形为:上图作的是气缸数对每加仑油跑的里程数的散点图。基本上缸数越多,每加...翻译 2021-12-01 21:31:02 · 119 阅读 · 0 评论 -
Data visualisation,ggplot2
问题:大引擎的汽车比小引擎的汽车消耗更多的燃料吗?发动机尺寸与燃油效率之间的关系是怎样的?The mpg data framempg数据框包含美国环境保护署收集的38款汽车的观察结果。library(tidyverse)mpgmpg 中的变量包括:displ,汽车的发动机尺寸,以升为单位。hwy,汽车在高速公路上的燃油效率,以英里每加仑 (mpg) 为单位。燃油效率低的汽车在行驶相同距离时比燃油效率高的汽车消耗更多的燃料。 要了解有关 mpg 的更多信息,..转载 2021-11-29 22:06:06 · 163 阅读 · 0 评论 -
BSgenome简介
一、BSgenome和BSgenome数据包Bioconductor提供了某些物种的全基因组序列数据包,这些数据包是基于Biostrings构建的,称为BSgenome数据包。不同物种的BSgenome数据包都有类似的数据结构,可以用统一的方式进行处理。但是BSgenome数据包仅包含有数据,它们的处理的方法由另外一个软件包提供,即BSgenome包。先安装BSgenome包(如果没有安装):if (!requireNamespace("BiocManager", quietly = TRUE))转载 2020-07-10 17:21:07 · 4090 阅读 · 0 评论 -
One-tailed F-test with one restriction
beta <- c(1,4,2,3) # The coefficientsn <- 20 # The number of observationscombo <- c(0,1,1,-1,-1) # The contrast (starting with an intercept coefficient)sigma <- ...转载 2018-05-31 10:25:27 · 339 阅读 · 0 评论 -
Data Analysis: Regression
OLS Diagnostics in ROLS Diagnostics: Error Variance Variance• Formal tests for heteroskedasticity are available from the lmtestlibrary– library(lmtest)– bptest(ols.model1) will give you the Breusch‐Pa...转载 2018-05-31 12:30:07 · 277 阅读 · 0 评论 -
Instrumental Variables----------Implementation R 2.13
Wald testModel 1: hsngval ~ pcturban + faminc + reg2 + reg3 + reg4Model 2: hsngval ~ pcturban Res.Df Df F Pr(>F) 1 44 2 48 -4 12.975 4.643e-07 ***-...转载 2018-07-06 22:18:33 · 457 阅读 · 3 评论 -
IV in R
http://eclr.humanities.manchester.ac.uk/index.php/IV_in_R In this Section we will demonstrate how to use instrumental variables (IV) estimation (or better Two-Stage-Least Squares, 2SLS) to estimat...转载 2018-07-09 23:50:41 · 1666 阅读 · 2 评论 -
6 Neat Tricks with Monte Carlo Simulations
1转载 2018-07-28 23:54:31 · 219 阅读 · 0 评论 -
用R语言对一个信用卡数据实现logit,GBM,knn,xgboost
Prepare the data数据来自UCIhttp://archive.ics.uci.edu/ml/machine-learning-databases/credit-screening,一个信a用卡的数据,具体各项变量名以及变量名代表的含义不明(应该是出于保护隐私的目的),本文会用logit,GBM,knn,xgboost来对数据进行分类预测,对比准确率预计的准确率应该是:xg...转载 2018-09-11 17:37:23 · 774 阅读 · 0 评论 -
electricity consumption data,R
daixu转载 2018-09-14 22:16:07 · 342 阅读 · 0 评论 -
tricks in R
函数中给全局变量赋值R里可以用<<-来进行全局赋值,比如我在解Project Euler 15题时,就用了<<-,这个最好还是不要用,用全局赋值可能会给你surprise,会给出惊喜的代码不是好代码。当然所谓的全局和局部,都是相对的,主要看内存管理的实现方式,内存堆栈,在R里通过environment来实现,S中称之为frames。所谓的全局变量就是位于.Globa...转载 2018-10-06 22:35:05 · 247 阅读 · 0 评论 -
Standard error of regression coefficient without raw data
Is it possible to derive the standard error of a regression coefficient from summary data alone?E.g., assume we are given the following variance-covariance matrix.[Var(X)Cov(X,Y)Cov(X,Y)Var(Y)]We can ...转载 2018-05-30 21:27:21 · 1200 阅读 · 0 评论 -
R 语言 optim 使用
stats中的optim函数是解决优化问题的一个简易的方法。Univariate Optimizationf = function(x,a) (x-a)^2xmin = optimize(f,interval = c(0,1),a=1/3)xminGeneral Optimizationoptim函数包含了几种不同的算法。 算法的选择依赖于求解导数的难易程度,通常最好提供...转载 2018-06-11 15:55:40 · 21705 阅读 · 0 评论 -
【数据处理】reshape2包
https://zhuanlan.zhihu.com/p/22249895?refer=rdatamining前言reshape2是又一个用来做数据处理的拓展包,用于实现宽格式数据与长格式数据之间的互转。如果你熟悉结构化数据库查询,那么你一定知道列转行与行转列,宽长数据之间互转与之类似;如果你不熟悉的也没关系,它很简单,接着往下看你就能很快熟悉并掌握了。首先我们通过一个数据集来解释什么是长宽数据。...转载 2018-05-20 22:46:09 · 1452 阅读 · 0 评论 -
数据整理,R
### the first step: set your working directorysetwd("C:/users/TaoJie/Desktop/2016-2017新学期经验似然/drugsatfda")### R中的文件路径应把Windows系统默认的"\"替换为"/"install.packages("readr")install.packages("recipes")原创 2018-02-02 17:29:30 · 243 阅读 · 0 评论 -
数据输入输出,R图片保存
rm(list=ls())mydata <- read.table("clipboard", header=TRUE, sep="\t")mydata <- read.csv("c:\mydata\mydatafile.csv", header=TRUE)# The will open a window to search for the *.csv file.# In the exa...原创 2018-02-02 17:04:12 · 1193 阅读 · 0 评论 -
数据分析整理,R,caret包(1)
caret包可以处理至少以下事情.1、初步筛选属性(过滤以下属性)a、找出 属性值接近为常数的 属性 nearZeroVarb、找出 相关系数最大的 属性 findCorrelationc、找出 多重共线性的 属性 findLinearCombos2、处理缺失值 preProcess(data, meth转载 2018-02-03 11:32:29 · 5859 阅读 · 1 评论 -
ROC曲线
http://blog.youkuaiyun.com/sinat_26917383/article/details/51114244http://blog.youkuaiyun.com/dingming001/article/details/72956044http://blog.youkuaiyun.com/solo7773/article/details/8699693自己运算# 做一个logistic回归,生成概率预测值 m...转载 2018-02-09 17:58:56 · 748 阅读 · 0 评论 -
caret包,特征选择
http://www.cybaea.net/Journal/2010/11/16/Feature-selection-Using-the-caret-package/http://topepo.github.io/caret/recursive-feature-elimination.htmlRecursive Feature EliminationBackwards SelectionIn ca...转载 2018-02-10 05:13:40 · 1860 阅读 · 0 评论 -
Feature selection: All-relevant selection with the Boruta package
http://www.cybaea.net/Journal/2010/11/15/Feature-selection-All-relevant-selection-with-the-Boruta-package/There are two main approaches to selecting the features (variables) we will use for the analys...转载 2018-02-10 07:11:26 · 383 阅读 · 0 评论 -
R的一些小技巧
df=data.frame(i=3:1,y=runif(3))dfi=df$idf=df[,2]dflist=split(df,i)names(dflist)=NULLdflist作用:将data.frame按行对应生成列表> dflist[[1]][1] 0.6092747[[2]][1] 0.6222994[[3]][1]原创 2018-02-05 16:33:47 · 242 阅读 · 0 评论 -
数据整理练习,R
> library(nycflights13)> dim(flights)[1] 336776 19> head(flights, 3)# A tibble: 3 x 19 year month day dep_time sched_dep_time dep_delay arr_time 1 2013转载 2018-01-31 17:08:38 · 498 阅读 · 0 评论 -
5模型训练和调参(The caret package)
5. 模型训练和调参内容:Model Training and Parameter TuningAn ExampleBasic Parameter TuningNotes on ReproducibilityCustomizing the Tuning ProcessPre-Processing OptionsAlternate Tuning GridsPlotting the转载 2018-02-04 22:50:23 · 2479 阅读 · 0 评论 -
Simulations in R
目的:simulate data with R using random number generators of different kinds of mixture variables we control.set.seed(198911)vecpoisson=rpois(100,5)mean(vecpoisson)generate 5 samples from an exponential ...转载 2018-04-07 09:17:27 · 415 阅读 · 0 评论 -
Monte Carlo simulation, resampling
目的:原因:工具能做什么是什么:Computer simulation that generates are large number of simulated samples of data based on an assumed Data Generating Process (DGP) that characterizes the population from which the simu...转载 2018-04-07 12:05:55 · 555 阅读 · 0 评论 -
Plotting in R for Biologists
数据library(ggplot2)filename <- "/home/taoyan/Plotting in R for Biologists/Lesson-01/Encode_HMM_data.txt"my_data <- read.csv(filename, sep="\t", header=FALSE)# 查看一下数据head(my_data)对数据列名重命名names(my_...转载 2018-05-03 12:08:41 · 208 阅读 · 0 评论 -
R:写文件(输入与输出)
Write.table()函数的用法read.table()非常相似,只不过它把数据框写入文件而不是从文件中读取。参数和选项:write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ",eol = "\n", na = "NA", dec = ".", row.names = TRUE,col.names = TRUE, q...转载 2018-05-03 12:25:00 · 14641 阅读 · 0 评论 -
R语言代码调试1
Norman Matloff 和PeteSalzman在其著作《TheArt of Debugging, withGDB,DDD,Eclipse》中曾说过,确认原则是调试的本质。程序员编写程序是为实现特定目的,而一个程序可以由许多目的组成,调试是确认某些目的是否达到了,如果未能达到目的,那么便可通过在调试中查看变量,发现问题症结,进而解决问题。在R中进行debug有几种不同方式,你如果使用诸如Rs...转载 2018-05-03 20:46:27 · 977 阅读 · 0 评论 -
用R语言快速生成Latex表格
Latex是我非常需(tao)要(yan)的一个工具,奈何写论文总是需要它,有时候我们需要生成一些表格,但是Latex的表格编辑工具真的是太难用了……尤其是当我们有很多表格需要从R语言中生成的时候。后来我有幸发现了神器xtableR包,有了它,可以非常快速地生成Latex格式的表格。首先当然是需要安装一下xtable包,然后假设我们有一个矩阵如下: data(iris) head(iris)我们...转载 2018-05-20 10:02:07 · 2820 阅读 · 0 评论 -
练习:数据整理,R
library(car)library(reshape2)str(mtcars)> str(mtcars)'data.frame': 32 obs. of 11 variables: $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ... $ cyl : num 6 6 4 6 8 6 8 4 4 6原创 2018-01-30 21:10:55 · 348 阅读 · 0 评论