[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 ...
随机推荐
- 成功使Linux服务端和Windows客户端建立socket通信
一.准备工作 1.一台装有虚拟机的Windows7操作系统,虚拟机中装的是CentOS6.5版本的Linux 2.Windows7已经装有java环境 二.编码 使用java编写socket通信的服务 ...
- 部署安装kubernetes client-python,执行pip install setup.py时报错
之前在本地安装过kubernetes的python库,安装下来一切正常,但今天换到测试机器上去部署,确保错了,具体步骤如下. 第一步,克隆代码,执行以下命令: # git clone --rec ...
- login.html
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1 ...
- PAT甲级 1001 A+B Format
题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400 1001 A+B Format ( ...
- 初读"Thinking in Java"读书笔记之第四章 ---控制执行流程
true和false Java不允许将数字作为布尔值使用. 所有条件表达式都将布尔值作为判断条件,决定执行路径. if-lese 迭代 while,do-while,for为三个迭代语句. ,逗号操作 ...
- Vue源码之 Vue的生命周期
天地初开就是new Vue(options),里面就一句话 this._init(options); (Vue.prototype.init 的赋值在initMixin(Vue)方法里) _init方 ...
- n个骰子的点数之和
题目:把n个骰子扔在地上,所有骰子朝上一面的点数之和为S.输入n,打印出S的所有可能的值出现的概率. 解题思路:动态规划 第一步,确定问题解的表达式.可将f(n, s) 表示n个骰子点数的和为s的排列 ...
- 【转】Android-Input 按键字符映射文件&输入设备配置文件
https://source.android.com/devices/input/key-character-map-files 按键字符映射文件 按键字符映射文件(.kcm 文件)负责将 Andro ...
- Python02(Linux命令)
Trainning-day01回顾 1.who :查看登录到系统的用户信息 2.pwd :查看当前所在路径 3.ls :查看当前目录的内容 ls -l ls -a ls -la / ls -l -a ...
- Prime ring problem,递归,广搜,回溯法枚举,很好的题
题目描述: A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each ...