Search

[R] package:: fastglm

Properties
R package
Reference
Empty
Author
Kipoong Kim
Date
2021/03/06
Link
Empty
Created
3/12/2021, 11:44:00 AM
Tags
R
Programming
links
Empty

Introducing an R package :: "fastglm"

Introduction

โ€ข
R ๊ธฐ๋ณธ ๋‚ด์žฅ ํ•จ์ˆ˜์ธ "stats::glm"์€ ๊ฝค ๋น ๋ฅด๊ฒŒ fitting๋˜๋Š” ํŽธ์ด์ง€๋งŒ, 'bootstrap' ๋˜๋Š” 'permutation' ๋“ฑ๊ณผ ํ•จ๊ป˜ ๋ฐ˜๋ณต์ ์œผ๋กœ ๊ณ„์‚ฐํ•ด์•ผํ•˜๋Š” ๊ฒฝ์šฐ ๋‹ต๋‹ตํ•จ์„ ๋Š๋‚„ ์ˆ˜ ์žˆ์Œ.
โ€ข
ํ•„์ž๋„ 40000 x 5000 ๋ฒˆ์˜ glm fitting์„ ๋ฐ˜๋ณต์„ ํ•ด์•ผํ•ด์„œ ์†๋„๊ฐ€ ๋น ๋ฅธ glm ํ•จ์ˆ˜๋ฅผ ์ฐพ๋‹ค๊ฐ€ ๋ฐœ๊ฒฌํ•˜๊ฒŒ๋œ "fastglm" ํŒจํ‚ค์ง€.
โ€ข
์—ฌ๋Ÿฌ matrix decomposition ๋ฐฉ๋ฒ•์„ ์ ์šฉํ•˜์—ฌ ์†๋„๋ฅผ ํ–ฅ์ƒ์‹œํ‚จ ๊ฒƒ์œผ๋กœ ๋ณด์ž„.

Usage

fastglm(x, y, family = gaussian(), weights = NULL, offset = NULL, start = NULL, etastart = NULL, mustart = NULL, method = 0L, tol = 1e-08, maxit = 100L, ...)
R

์‚ฌ์šฉ๋ฒ•

๐Ÿ’ก
- ์—ฌ๊ธฐ์„œ x๋Š” ๋ฐ˜๋“œ์‹œ matrix์ด์–ด์•ผํ•˜๊ณ , y๋Š” numeric vector์ด์–ด์•ผํ•จ. - ๋ชจํ˜•์— ์ ˆํŽธ(intercept)ํ•ญ์„ ์ถ”๊ฐ€ํ•˜๊ธฐ ์œ„ํ•ด cbind(1, x) ๋“ฑ์„ ์ด์šฉํ•ด์•ผํ•จ. - family๋Š” gaussian() ๋˜๋Š” "gaussian" ๋“ฑ์œผ๋กœ ์ž…๋ ฅํ•˜๋ฉด ๋จ (๋ถ„ํฌ ์ด๋ฆ„์€ stats::glm๊ณผ ๋™์ผํ•จ). - stats::glm ์ฒ˜๋Ÿผ factor ํด๋ž˜์Šค์˜ y๋Š” ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์œผ๋ฏ€๋กœ, family = binomial์ธ ๊ฒฝ์šฐ y๋Š” ๋ฐ˜๋“œ์‹œ 0๊ณผ 1 ์‚ฌ์ด ๊ฐ’์„ ๊ฐ–๋Š” numeric vector๋กœ ๋ณ€ํ™˜ํ•ด์ค˜์•ผํ•จ. ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‰ฝ๊ฒŒ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์Œ. > y = as.factor( rep(0:1, each=50) ) > as.numeric( as.character( y ) ) - start์˜ ๊ฒฝ์šฐ, stats::glm์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ 0: 10๊ฐœ๊ณผ 1: 1000๊ฐœ ๋“ฑ์˜ ๊ทน๋‹จ์ ์ธ ๋น„์œจ์„ ๊ฐ–๋Š” ๊ฒฝ์šฐ์ฒ˜๋Ÿผ ์ˆ˜๋ ด์„ ํ•˜์ง€ ๋ชปํ•˜๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ์ด๋Ÿฌํ•œ ๊ฒฝ์šฐ start point๋ฅผ ์กฐ์ •ํ•˜์—ฌ ์ˆ˜๋ ดํ•˜๋„๋ก ๋งŒ๋“ค ์ˆ˜ ์žˆ์Œ. - method ๋ถ€๋ถ„์—์„œ ์ด 3๊ฐ€์ง€์˜ ๋ฐฉ๋ฒ•์ด ์žˆ๋Š”๋ฐ, ๊ทธ ์ค‘์—์„œ ์ฒซ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์˜ ์†๋„๊ฐ€ ๊ฐ€์žฅ ๋นจ๋ผ์„œ default๋กœ ์‚ฌ์šฉ๋จ.

์˜ˆ์ œ

library(mnormt) library(fastglm) Data <- rbind( c(21, 1), c(24, 1), c(25, 1), c(26, 1), c(28, 1), c(31, 1), c(33, 1), c(34, 1), c(35, 1), c(37, 1), c(43, 1), c(49, 1), c(51, 1), c(55, 1), c(25, 0), c(29, 0), c(43, 0), c(44, 0), c(46, 0), c(46, 0), c(51, 0), c(55, 0), c(56, 0), c(58, 0) ) x <- Data[,1]; y <- Data[,2] glm(y~x, family="binomial") glm(y~x, family="binomial", start=c(-2,0)) # Error fastglm(as.matrix(cbind(1,x)), y, family="binomial") fastglm(as.matrix(cbind(1,x)), y, family="binomial", start=c(-2,0))
R
TOP