[R] [Johns Hopkins] R Programming -- week 4
#Generating normal distribution (Pseudo) random number
x<-rnorm(10)
x x2<-rnorm(10,2,1)
x2 set.seed()
#Generating Poisson data rpois(10,1)
rpois(10,2)
rpois(10,20) ppois(2,2) #Cumulative distribution ##P r(x <= 2) 平均發生率為2
ppois(4,2) #Cumulative distribution ##P r(x <= 4) 平均發生率為4 #線性 y = B0+B1X+e
#e~N(0,2^2) 標準差為2正態分布
#assume x~N(0,1^2) B0=o.5 B1=2
set.seed(20)
x <- rnorm(100)
e <- rnorm(100,0,2)
y <- 0.5 + 2 * x + e
summary(y)
plot(x,y) # 若x為binary ex性別
set.seed(20)
x <- rbinom(100,1,0.5) #得到1的機率為0.5
e <- rnorm(100,0,2)
y <- 0.5 + 2 * x + e
summary(y)
plot(x,y) #廣義線性模組可能服從poisson分布 Y~Poisson(m)
#log mu = B0 + B1X #log mu 服從線性
#B0 = 0.5 B1 =0.3 #y服從 平均值為mu 的 PD
set.seed(20)
x <- rnorm(100)
log.mu <- 0.5 + 0.3 * x
y <- rpois(100,exp(log.mu))
summary(y)
plot(x,y) # sample(range vector, numbers)
# sample(range vector) 重新排列
# sample(range vector, replace = T) 重複性抽樣 #Profiler profiling is better than guessing
#Premature optimization is the root of all evil
system.time() #proc_time (class)
#user time: time charged to the CPU(s) for this expression
#elapsed time: "wall clock" time 運行時間
#parallel processing via parallel package ##elapsed time > user time
system.time(readlines("http://www.google.com")) #elapsed time < user time
hilbert <- function(n){
i <- 1:n
1/outer(i -1, i, "+")
}
x <- hilbert(1000)
system.time(svd(x)) # svd 多線程線性代數
[R] [Johns Hopkins] R Programming -- week 4的更多相关文章
- [R] [Johns Hopkins] R Programming 作業 Week 2 - Air Pollution
Introduction For this first programming assignment you will write three functions that are meant to ...
- [R] [Johns Hopkins] R Programming -- week 3
library(datasets) head(airquality) #按月分組 s <- split(airquality, airquality$Month) str(s) summary( ...
- R语言 启动报错 *** glibc detected *** /usr/lib64/R/bin/exec/R: free(): invalid next size (fast): 0x000000000263a420 *** 错误 解决方案
*** glibc detected *** /usr/lib64/R/bin/exec/R: free(): invalid next size (fast): 0x000000000263a420 ...
- python文件操作打开模式 r,w,a,r+,w+,a+ 区别辨析
主要分成三大类: r 和 r+ "读"功能 r 只读 r+ 读写(先读后写) 辨析:对于r,只有读取功能,利用光标的移动,可以选择要读取的内容. 对于r+,同时具有读和写 ...
- windows server 2008 r2 启用索引(转)
08r2的“windows search”服务默认是不安装的,要想启用索引执行下列步骤: 1.打开“服务器管理”——选中“角色”——右边选中“添加角色”——勾选“文件服务”. 2. ...
- C语言中文件打开模式(r/w/a/r+/w+/a+/rb/wb/ab/rb+/wb+/ab+)浅析
C语言文件打开模式浅析 在C语言的文件操作语法中,打开文件文件有以下12种模式,如下图: 打开模式 只可以读 只可以写 读写兼备 文本模式 r w a r+ w+ a+ 二进制模式 rb wb ...
- 【R笔记】R语言函数总结
R语言与数据挖掘:公式:数据:方法 R语言特征 对大小写敏感 通常,数字,字母,. 和 _都是允许的(在一些国家还包括重音字母).不过,一个命名必须以 . 或者字母开头,并且如果以 . 开头,第二个字 ...
- velecity报错:Caused by: org.apache.velocity.exception.ParseErrorException: Lexical error, Encountered: <EOF> after : "\'/order/pay?activity=\" + activityId);\r\n }*/\r\n</script>\r\n#end\r\n" at /a
Caused by: org.apache.velocity.exception.ParseErrorException: Lexical error, Encountered: <EOF> ...
- Android中View自己定义XML属性具体解释以及R.attr与R.styleable的差别
为View加入自己定义XML属性 Android中的各种Widget都提供了非常多XML属性,我们能够利用这些XML属性在layout文件里为Widget的属性赋值. 例如以下所看到的: <Te ...
随机推荐
- dva,清除模块数据
前言: 在项目中,模块过多,dva使用namespace分离模块后,若没有在模块卸载后清除对应的数据,下次进入时,有可能会有上一次数据的残留. 比如详情页,从A商品的详情页离开后,返回选择B商品进入, ...
- MySQL【文本处理函数】的使用方法
文本处理函数 名称 调用示例 示例结果 描述 LEFT LEFT('abc123', 3) abc 返回从左边取指定长度的子串 RIGHT RIGHT('abc123', 3) 123 返回从右边取指 ...
- xslt 2.0 分组
把数据拆成200个一组 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet vers ...
- Scrapy的piplines.py存储文件和存储mongodb
一.将数据保存到文件 1.piplines.py文件 import json class TencentPipeline(object): def open_spider(self,spider): ...
- SoapUI并发模式
soapUI支持test suite, test case级别的并发,合理使用这个功能,可以让自动化脚本短时间内跑完,为release省下时间. 1. 如何开启并发模式 图示,click projec ...
- 零基础IDEA整合SpringBoot + Mybatis项目,及常见问题详细解答
开发环境介绍:IDEA + maven + springboot2.1.4 1.用IDEA搭建SpringBoot项目:File - New - Project - Spring Initializr ...
- 二、Memcached缓存穿透、缓存雪崩
二.Memcached缓存穿透.缓存雪崩 1. 缓存雪崩 可能是数据魏加载到缓存中,或者缓存同一时间大面积失效,导致大量请求去数据库查询的过程,数据库过载,崩溃. 解决方法: 1 采用加锁计数,使用合 ...
- 吴恩达机器学习笔记5-Octave基本操作
1.逻辑运算 1==2 %false :注释用%,这句话意思是判断1是否等于2,false,输出0 1~=2 %true 1不等于2 为true,输出为1 1&&0 %and 1|| ...
- php优秀框架codeigniter学习系列——CI_Input类学习
这篇文章主要介绍CI核心框架工具类CI_Input. 根据CI文档自己的定义,该类用来: 提前处理全局变量,以保证安全; 提供一些帮助函数用来处理输入数据. 以下选取类中的重点方法进行说明. __co ...
- Good Time------打卡让生活更美好
Section 1团队介绍 Part 1 队员信息 姓名 学号 职务 王怡镔 2016012045 组长 于鑫宇 2016012029 组员 张济吨 2016012072 组员 黄鹤 20160120 ...