|
|
||
Rでできる回帰分析+α
線形回帰分析(単回帰、重回帰)
> trees.lm <- lm(Volume ~ Girth, data=trees)
# Rで~は? ...イコールみたいなもん?
residual:残差
intercept:切片
girth:周囲
t値が1に近いほどあてまりがいい(?)
重回帰
http://aoki2.si.gunma-u.ac.jp/R/mreg.html
線形回帰分析にはlm()
卒検:生物の年齢推定
記事ごとのアクセスを記録してコンテンツに利用, 記事間の遷移数を記録。
ログの収集は
Web解析HACKS
lob <- read.csv("a.log",sep="\t")
# sep ... the field separator character. Values on each line of the file are separated by this character. If sep = " (the default for read.table) the separator is ‘white space’, that is one or more spaces, tabs, newlines or carriage returns."
下ごしらえ
Unixtime -> R用に, POSIXctクラスオブジェクトに変換
ホストのカテゴリ化...正規表現
> pie(sort(table(log$page), decreasing=T))
# log$ipはlogっていうデータフレームがあって、そのipという列をとってきている
隣接行列。A->Aにあれば1, なければ0
> plot(graph.adjacency(logmat>5,weighted=T),layout=layout.circle)
syou6162.g.hatena.ne.jp/keyword/Tsukuba.R#5?mode=presentation
class_filterという関数
> letters
[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q"
[18] "r" "s" "t" "u" "v" "w" "x" "y" "z"
> LETTERS
[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q"
[18] "R" "S" "T" "U" "V" "W" "X" "Y" "Z"
> sample(letters,size=100,replace=TRUE)
sample()関数
行列のsubset関数はvectorのFilterのようなもの
which.maxをすると、最大のところのindexが帰ってくる
data.frame
基本的にmatrixと同じだが、d$nameでアクセスできる
> head(swiss[,1])でも、
> head(swiss$Fertility)でもアクセスできる。
matrixに数値以外も許したような表形式のデータ型
dataframeでもapply.
install.packages("animation") #した。今後はlibrary(animation)だけでいい。
そしてsaveMovie(expr, ...)
アルゴリズムの説明に。
AniWiki(animation.yihui.name)
R-Tips, RjpWiki
quickrun.vim...windowsでは使えない
-> terapadでR
コンストラクタが private 指定なので、new キーワードでインスタンスを生成することは
できません。TsuuchouS クラスの static 変数でインスタンスを new していて、他のオブジ
ェクトからは getInstance という static メソッドで参照するしかないのが単一のインスタ
ンスであることが保証されるポイントです。
public class Singleton { private static Singleton singleton = new Singleton(); private Singleton (){ // } public Singleton getInstance(){ return singleton; } }
単一インスタンスの肝: コンストラクタをprivate指定。
本家からソース落としてきて
tar xvf
で解凍して
cd して
./configure --prefix=$HOME #自分のとこのみ。$HOME/libとか$HOME/binができる
make
make install
make clean
一方gemは cdで入って
ruby setup.rb --prefix=$HOME
でいい。このままだとrequire 'rubygem'できないので
~/.bash_profile*1に
RUBYLIB=$HOME/lib/
を追加する。
Ruby variables and constants holds references to objects. Variables themselves do not have an intrinsic type. Instead, the type of a variable is defined solely by the messages to which the object referenced by the variables responds*1.
Programming Ruby 1.9: The Pragmatic Programmers' Guide (Facets of Ruby), p.330
Rubyの定数と変数は、オブジェクトへのリファレンスを保持しています。変数自体に型はありません。変数の型は、その変数によって参照されるオブジェクトがどのメッセージに対して応答を返すかによってのみ定義されます*2。
プログラミングRuby 第2版 言語編, p.286