[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 ...
随机推荐
- 使用飞冰组件关于点击行回填在input内(React)
import { Table,Grid } from "@icedesign/base"; import { FormBinderWrapper as IceFormBinderW ...
- 关于Python课程的思考和意见
老师您好,我是信息管理与信息系统专业的一名学生,由于专业原因,我在大一下学期第一次接触Python,并因为它简洁的语言和强大的函数库所吸引,刚好在选课时得知学校有开python选修课,就慕名而来. 首 ...
- Beta冲刺前的准备
Beta冲刺前准备 1.讨论组长否重选的议题和结论 经过团队讨论,不重选组长.我们团队在队长的带领下积极完成任务,使得团队项目初具模型.经过alpha阶段,我们的团队从一开始的零散到如今的凝聚,通力合 ...
- css之positon与z-index
在网页设计中,position属性的使用是非常重要的.有时如果不能认识清楚这个属性,将会给我们带来很多意想不到的困难. position属性共有四种不同的定位方法,分别是static.fixed.re ...
- php优秀框架codeigniter学习系列——CI_Loader类分析
这是一个加载视图和文件的类. __construct() 设置视图文件的路径,和获取输出缓冲级别. initialize() 该方法只会被CI_Controller调用一次,会调用 $this-> ...
- JS高德地图应用 ---- 鼠标点击加入标记 & POI搜索
代码如下 (填入Key值) : <!DOCTYPE html> <html> <head> <meta charset="utf-8"&g ...
- Selenium-java测试环境搭建
1.1背景 Selenium也是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE.Mozilla Firefox.Mozilla ...
- 微信小程序页面列表与详情页跳转的正确姿势
初学小程序,碰到列表与详情页跳转遇到的问题,记录一下. 一.问题 1个列表页: 1个详情页: 列表页代码: onLoad:异步查询数据并setData 详情页代码: 保存成功后,调用navigateB ...
- c# 连接数据库SqlHelper
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- Request.ServerVariables参数说明
Request.ServerVariables["SERVER_NAME"] '获取服务器IP Request.ServerVariables["HTTP_REFERER ...