Showing posts with label rstats. Show all posts
Showing posts with label rstats. Show all posts

20 July 2015

Series about decision tree


Dear Readers,

Good morning and Eid Mubarak to all moslem brothers and sisters. I will be writing this post in Indonesia language, along with some English quotation.

I met "Prana Ugi" a keen statistician from Medan (the capital of North Sumatera). He's working a lot with SPSS on various subjects. What can I say, he was graduated from math and statistics program. No wonder huh. Today we'll be covering on the decision tree subjects. R codes will be developed later based on this (or these) post (or posts).

This first draft would still be a QA session between Prana Ugi and I. We will develop the text shortly.

# First post 




The QA was:

Me:
Seandainya ada banyak kolom ttg riwayat penyakit, apakah bisa menghasilkan risiko rendah sedang tinggi. Jadi yg bilang risikonya sebesar apa, adalah data. Seperti itu sepertinya data yg saya kirim tempo hari.


Prana Ugi:
Pak Dasapta Erwin Irawan => dari data excel yang bapak kirim, Ugi bingung pak untuk menentukan, kolom (variabel) mana yang dependen dan independen. Dari data excel bapak dimulai dari kolom A (no), sampai kolom AE (lag1). Boleh diberi keterangan pak, kolom yang berupa dependen dan independen.

Me:
Menurut saya yang independen hanya koordinat. kolom yang lain akan saling dependen kepada kolom yang lain. Skenario saya justru bagaimana mencari yang terkuat.


# Second post



no comment


# Third post



Me:
Proses learningnya apakah menggunakan prinsip regresi?

Prana Ugi:
Pak Dasapta Erwin Irawan => Ada banyak algoritma untuk menginduksi (membuat) pohon keputusan (decision tree), seperti: CART (C&RT), ID3, C4.5, SLIQ, SPRINT, QUEST, DTREG, THAID, CHAID, dan sebagainya. Pada CART, Metode klasifikasi CART terdiri dari dua metode yaitu metode pohon regresi dan pohon klasifikasi. Jika variabel dependen yang dimiliki bertipe kategorik maka CART menghasilkan pohon klasifikasi (classification trees). Sedangkan jika variabel dependen yang dimiliki bertipe kontinu atau numerik maka CART menghasilkan pohon regresi (regression trees). Pada Gambar yang Ugi posting, variabel dependennya bersifat kategori.
Prana Ugi Classification and Regression Trees (CART) adalah salah satu metode atau algoritma dari teknik pohon keputusan. CART adalah suatu metode statistik nonparametrik yang dapat menggambarkan hubungan antara variabel respon (variabel dependen) dengan satu atau lebih variabel prediktor (variabel independen). Menurut Breiman dkk (1993), apabila variabel respon berbentuk kontinu maka metode yang digunakan adalah metode regresi pohon (regression trees), sedangkan apabila variabel respon memiliki skala kategorik maka metode yang digunakan adalah metode klasifikasi pohon (classification trees). Semoga bermanfaat pak, diskusinya.

# Forth post



Data Mining, Concepts, Models, and Techniques
By: Florin Gorunescu, Springer

no comment

# Fifth post


Prana Ugi:
Alhamdulillah, proses perhitungan manual Classification and Regression Tree (CART) dengan algoritma ID3 (iterative dichotomiser 3) dan C4.5 dengan kriteria entropy (impurity) selesai. Algoritma diimplementasikan ke Excel berhasil, sekarang pindah ke R, semoga ada package-nya, kalau nggak ada, buat sendiri. 

Me:
coba R package berikut:
- CARET (https://cran.r-project.org/web/packages/caret/index.html),
- RPART (https://cran.r-project.org/web/packages/rpart/index.html), dan
- TREE (https://cran.r-project.org/web/packages/tree/index.html)```
We'll keep updating this post.

28 June 2015

Plotting selangkah demi selangkah

Dear friends,

Long time no post LOL. Here's an update.

Finally!

I managed to translate an article by Hadley Wickham "Build a plot layer by layer" to Indonesian language for class purposes. I used R Markdown to write the article. But somehow, I can't get it uploaded to my Rpubs repo, as well as to this blogger site.

I've tried to implement a "(semi)-automating the R markdown to blogger workflow" described here, but did work.

So I rendered the Rmd to pdf and posted to my repos:

  1. Academia (pdf format) 
  2. ResearchGate (Rmd, R code)


I hope the translation is clear enough for anyone (especially Indonesian), who is starting to learn ggplot2 package.

Here's a plot from the original post.


28 May 2015

1st Circular: Indonesia R meet up


Karena ternyata sudah banyak yang "terungkap" sebagai Pengguna R (pada tahap beginners hingga advanced), sudah saatnya merancang acara R meet up. Contohnya seperti ini: http://r-users-group.meetup.com/.

Komunitas Indonesia R User akan menyelenggarakan Indonesia R Meet Up yang pertama, dengan tema R 4 All.

TORnya sebagai berikut:

  • Siapa saja yang boleh hadir: semua yang berminat dan join R user group.
  • Siapa saja yang boleh mengirimkan abstrak: pengguna R (tidak ada batasan kompetensi), dan harus join R user group.
  • Apa saja yang boleh dipresentasikan: semua topik asal menggunakan R.

Topik sementara ini hanya dibagi dua: 

  1. Natural sciences (termasuk kedokteran, kesehatan)
  2. Social sciences (termasuk ekonomi)

  • Bagaimana format abstrak: 200 kata, ada max 5 kata kunci, menggandung latar belakang, metode, hasil, kesimpulan, rekomendasi. Kode R disampaikan sebagai lampiran.
  • Dikirim ke mana: di post di Wall R User Group.

Masukan-masukan terhadap penyelenggaraan acara agar dapat ditulis di kolom komentar.

Terimakasih.


27 May 2015

the 3rd workshop: Introduction to R


The event has been successfully held in ITB Central Library, today, 26 May 2015, 13.00-15.00.
There were 50 participants, which were the max capacity of the room. We still have 30 more waiting list participants.

Slides (pdf) in Indonesian language, data and code are available here.
Slides (ioslides) is available here.


26 May 2015

Preparing for the 3rd Introduction to R slides

I am now preparing the slides for the 3rd Introduction to R Mini Workshop. I am using R Markdown to write the slides. Just found out that somehow if I used the "smaller: yes" or "smaller: true" line in the YAML lines (see the following lines),

---
title: "Introduction to R: R in the library"
author: "Dasapta Erwin Irawan"
date: "26/05/2015"
output:
  ioslides_presentation:
    logo: itb.jpg
    smaller: yes
    widescreen: yes
    self_contained: no
---

I ended up getting the following errors.


pandoc: user error ([string "custom"]:253: attempt to concatenate field 'class' (a nil value))
Error: pandoc document conversion failed with error 1Execution halted

The error was dismissed if I delete the above-mentioned line.

  

09 May 2015

Upcoming 3rd Mini Workshop Intro to R



After a long hiatus here's an update.

My tweets shouting the upcoming 
Intro to R Workshop.

A teaser in Prezi http://goo.gl/ZYIA3v

The 3rd Intro to R mini workshop, 25May, ITB Central Library: 
 
1) installation:
1.1 what and How to install, 
1.2 how to upgrade, 
1.3 basic syntax; 

2) data prep: 
2.1 data entry, 
2.2 formatting rows-cols, 
2.3 dealing with NAs; 

3) basic ops: 
3.1 data loading, 
3.2 data structures, 
3.3 missing data 

4) basic anl: 
3.1 descriptive anl, 
3.2 basic plots; 
3.3 pairs anl; 
3.4 regression anl 







17 March 2015

hydrogeological analysis using open source tools: case Cikapundung River

Dear friends,

The following slides (in Rmd) or pdf format are from my recent talk on Sarasehan Geologi Populer, which was held by Geological Survey of Indonesia. It covers various open source tools, with more focus on R, for geological and hydrogeological analysis. This talk tells some bits of my research on finding out interaction between groundwater and surface water interaction by analysing water quality pattern. I used R in this research. The slides contains some R codes example. The objective of this talk is to raise awareness of open source apps and how its contribution to reproducibility in science.

You can view and download:
@dasaptaerwin


23 February 2015

Heatmap and corrgram to evaluate student's scores (updated)

Dear friends,
Here's my try out of making heatmap and corrgram in R to evaluate student performance. Both plots can be used to evaluate your students' performance and clustering. The number on the right side contains the student's number, and the tree on the left shows the clustering. Figure left (heatmap), Figure right (correlation matrix). The following is the code:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#install.packages("corrgram")
library(corrgram)
library(ggplot2)
# Using mtcars data
corrgram(mtcars)
heatmap(as.matrix(mtcars))
head(mtcars)
pairs(mtcars, main = "mtcars data")
coplot(mpg ~ disp | as.factor(cyl), data = mtcars,
       panel = panel.smooth, rows = 1)
# Some tweaking
library(RColorBrewer)
x  <- as.matrix(mtcars)
rc <- rainbow(nrow(x), start = 0, end = .3)
cc <- rainbow(ncol(x), start = 0, end = .3)
heatmap(x, Rowv=NA, Colv=NA, col=brewer.pal(9, "Blues")[1:9], scale="none", 
        margins=c(5,10), revC=T)
##############################################################
# Using scores data
# loading data (you can use any numerical data)
Scores <- read.csv("Scores.csv", header=T) 
# view data frame's dimension, headers, etc
View(Scores)
dim(Scores)
str(Scores)
# subsetting data frame
Scores2 <- Scores[c(2:11)] 
# making correlation matrix and heatmap
corrgram(Scores2)
heatmap(as.matrix(Scores2))

Results:
from 'corrgram(mtcars)'
from 'coplot(mpg .... etc)'
from 'corrgram(Scores2)'
from 'heatmap(as.matrix(Scores2))'

Happy heating :-) Thanks for stopping by.

@dasaptaerwin






17 December 2014

Twitter data mining: first try out





Dear friends,

This post was my first try in using R to generate word cloud from Twitter. Here we use: R for text mining processes with search keys "bencana" (hazards) and "Indonesia" on Twitter. The above two pictures show the result from two periods: 5-15 Dec 2014 (left pic) and 5-17 Dec 2014 (right pic). Different results demonstrate the dynamic of tweets over time.

Code originally written by: Miga M. Julian, available here. I will convert it to Rmd later. 

‪#‎rforall‬ #rstats

16 October 2014

Level plot and bubble plot try out

Dear friends,

I've posted example of level plot and bubble plot on water quality dataset on rpubs. The objective of these plots is to show comparison of element concentration in groundwater and in the river water. The river data plot is located in the lower right position of the figure, making an elbow-like shape.

The plots were made using the following base code:

plotNO3 <- data="data,<o:p" levelplot="" x="" y="">
          xlab="X coord", ylab="Y coord",
          main="Level plot NO3",
          col.regions=terrain.colors(100))

bubbleNO3 <- bubble="" data="" o:p="" zcol="NO3">
          xlab="X coord", ylab="Y coord",
          main="Bubble plot NO3",

          scales=list(tck=0.5))

In this example I used the following packages:
  • lattice        # for plotting
  • dplyr          # for data manipulation
  • gridExtra      # for multiple plot
  • sp             # for spatial analysis
I used gridExtra package to show multi-plots on a page, using the following code.

grid.arrange(bubbleSiO2, bubbleFe, bubbleMg, bubbleMn, ncol=2)
However, I haven't finished tweaking the code so it can show the figure in the correct size.
I invite you to drop a comment or two.

Cheers,
@dasaptaerwin