반응형

Programing/R- programming 58

two-way ANOVA

/* * http://sosal.kr/ * made by so_Sal */ > teaching_time ageGroup method days1 50 C 14 two-way ANOVA > aov.out summary(aov.out) Df Sum Sq Mean Sq F value Pr(>F) ageGroup 4 24.933 6.233 14.38 0.001002 ** method 2 18.533 9.267 21.39 0.000617 ***Residuals 8 3.467 0.433 ---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1> 연령대에 따라 학습능률에 차이가 있고,가르치는 방법에 따라서도 학습능률에 차이가 있다.

범주형 자료의 통계분석 R programming

/* * http://sosal.kr/ * made by so_Sal */ 1. 적합성 검정 ( goodness of fit ) 관찰된 비율값이 기대값과 같은지 조사하는 검정방법. - Heart attack 발생 1년 후 생존률은 0.7이라고 가정하자. 따라서 환자 40명중 28명이 생존할것으로 기대된다. 실제로 40명중 24명이 생존, 16명이 죽었다면 생존률이 0.7이라는 귀무가설을 기각할 수 있는가? > # Goodness of Fit > chisq.test( c(24, 16), p=c(0.7, 0.3) ) Chi-squared test for given probabilities data: c(24, 16) X-squared = 1.9048, df = 1, p-value = 0.1675 자유도가 1..

상관관계 분석 R programming

/* * http://sosal.kr/ * made by so_Sal */ Pearson 상관분석은 변수들이 얼마나 직선적인 관계를 가지는지 분석하는 기법으로 상관계수를 이용하여 측정한다. 상관계수: Correlation coefficient > attach(iris) > cor(Sepal.Length, Petal.Width)[1] 0.8179411# Pearson 상관계수: 0.8179... > cor.test(Sepal.Length, Petal.Width) Pearson's product-moment correlation data: Sepal.Length and Petal.Widtht = 17.2965, df = 148, p-value < 2.2e-16alternative hypothesis: tru..

데이터 검정 R programming

/* * http://sosal.kr/ * made by so_Sal */ DataPima Indian: 9~13세기에 걸쳐 아메리카로 이주해온 몽골리언계주식: 식물성. (나무의 순, 잡초, 밀, 콩, 호박 등)1960년대 이후 고지방/고칼로리 식습관으로 당뇨환자 증가. Pima.tr data 8개의 변수npreg: number of pregnancies.glu: plasma glucose concentration in an oral glucose tolerance test.bp: diastolic blood pressure (mm Hg).skin:triceps skin fold thickness (mm).bmi: body mass index (weight in kg/(height in m)\^2).pe..

파일 입출력, R 프로그래밍

/* * http://sosal.kr/ * made by so_Sal */ FILE I/O 일반적으로 R programming의 작업 환경은 내문서에서 시작된다. getwd() # 현재 디렉토리 위치를 반환하는 함수 getwd returns an absolute filepath representing the current working directory of the R process; setwd(dir) is used to set the working directory to dir. > getwd()[1] "C:/Users/sosal/Documents" setwd() # 현재 디렉토리 위치를 바꾸는 함수 윈도우즈의 경우 파일-> 직업 디렉토리 변경기능을 통해 GUI로 설정할 수 있다. > help(get..

데이터 추출 및 병합 연산 R프로그래밍

/* * http://sosal.kr/ * made by so_Sal */ 실습데이터)> weight height gender testDate patients patients.sub patients.sub weight height1 65.4 1702 55.0 1553 380.0 NA4 72.2 1735 51.0 1616 NA 166 1. subset (부분집합) patients 변수에서 몸무게가 60키로 이상히고, 성별이 남자인 경우를 추출하는 경우 - 조건문을 사용하는 경우> patients[ (patients$weight > 60 & patients$gender=='M'), ] weight height gender testDate1 65.4 170 M 2013-09-013 380.0 NA M 2013..

apply 함수군 (lapply, sapply, tapply) R 프로그래밍

/* * http://sosal.kr/ * made by so_Sal */ apply() 함수는 벡터, 행렬 등의 데이터 프레임에서 row/column 단위의 계산을 할 때 함수를 쉽게 적용할 수 있도록 도와준다. apply 함수 외에 리스트, 벡터, 테이블 형태로 결과를 반환해주는 lapply, sapply, tapply 함수에 대해 알아보자. 실습데이터) > weight height gender testDate patients patients.sub patients.sub weight height 1 65.4 170 2 55.0 155 3 380.0 NA 4 72.2 173 5 51.0 161 6 NA 166 - 각 환자(row)별로 몸무게와 키의 평균을 구한다 > apply(patients.sub,..

결측치 NA (Missing value) 연산 / R programming

/* * http://sosal.kr/ * made by so_Sal */ R 프로그래밍에서 결측지(missing value)는 NA (Not Available) 라는 문자로 처리해야 한다.NaN (Not a Number)는 분모를 0으로 나누는 것과 같이 계산이 불가능 할 경우 출력되는 문자다. > y y[1] 1 2 3 NA is.na()는 벡터의 결측지가 존재할 경우 true> is.na(y)[1] FALSE FALSE FALSE TRUE> > summary(y) Min. 1st Qu. Median Mean 3rd Qu. Max. NA's 1.0 1.5 2.0 2.0 2.5 3.0 1 > NA는 missing value를 표현하는 논리형 자료이지만, "NA"는 문자열 그 자체이다.> is.na( N..

R프로그래밍 범주형 변수 factor (categorical variable)

/* * http://sosal.kr/ * made by so_Sal */ factor는 R에서 제공하는 categorical variable(범주형 변수)로, 여러개의 level로 구성된다. 혈액형이라는 범주형 변수가 존재할 때, A,B,AB,O 라는 level을 가지게 된다. > BloodType summary(BloodType) Length Class Mode 10 character character 위에서 정의한 BloodType이라는 vector를 factor로 형변한 하기 위해서 factor() 함수를 사용한다. Description The function factor is used to encode a vector as a factor (the terms ‘category’ and ‘enum..

반응형