Anda di halaman 1dari 8

1

AGH 611 Praktikum Pengenalan R 7. Clear workspace (di R)


Willy B. Suwarno [bayuardi@gmail.com] > rm(list=ls())

1. Download, install, dan menjalankan R 8. Impor data


R untuk Windows dapat di-download di: > dat = read.csv("PRAK1.csv",
http://cran.r-project.org/bin/windows/base/ header=T)
> dat
2. Lingkungan R
- Terdiri dari 3 jendela (windows) utama: 9. Lihat struktur data
> str(dat)
R Console, R Editor, dan R Graphics.
- Ketik program di R Editor, tekan Ctrl+R
10. Mengakses data
pada baris atau blok yang akan dijalankan, > dat$geno
dan hasilnya akan muncul di R Console. > dat[1,2]
- Terdapat perbedaan menu untuk ketiga > dat[1,]
jendela tersebut. > dat[,2]
> dat[1:3,]
3. Perhitungan aljabar sederhana > dat[,1:3]
> 1 + 1 > dat[,c(1,2,3)]
[1] 2 > head(dat)
> 3 * 4 > tail(dat)
[1] 12
> 18 / 2 11. Mengubah tipe data menjadi faktor
[1] 9 > dat$ul = as.factor(dat$ul)
> 3 - 2
[1] 1 12. Plotting
> plot(ttan ~ ul, dat, col="gold")
4. Buat direktori kerja dgn File Explorer > plot(ttan ~ geno, dat,
- Misalnya di C:\MKPT\PRAK1 col="gold")

5. Set direktori (folder) kerja 13. Ringkasan data (min, max, kuartil, rataan)
- Aktifkan (klik) window R Console > summary(dat$ttan)
- Klik File > Change dir…
- Pilih folder C:\MKPT\PRAK1, klik OK 14. Sidik ragam faktor tunggal RKLT
> lm1 = aov(ttan ~ ul + geno, dat)
6. Entri data > anova(lm1)
- Lakukan entri data (Tabel 1) di MS Excel
ul geno ttan bpplot 15. Install library
1 P6 177 1.1 - Aktifkan (klik) window R console
2 P6 181 1.1 - Klik Packages > Install package(s)…
3 P6 180 0.9 - Pilih server mirror (Indonesia)
1 MKB 176 0.8 - Pilih R package yang akan diinstall
2 MKB 160 0.6 - Atau, jika Anda sudah mendownload
3 MKB 187 0.7 package (format zip), bisa diinstall melalui
1 P6xMKB 230 2.0 menu Packages > Install package(s) from
2 P6xMKB 237 2.3 local zip files…
3 P6xMKB 220 2.6
1 Semar3 213 1.9 16. Simpan listing program R
2 Semar3 211 2.0 - Aktifkan (klik) window R Editor (tempat
3 Semar3 223 2.6 menulis program)
1 Bisma 218 1.9 - Klik File > Save as...
2 Bisma 217 2.2 - Tulis nama file (PRAK1.R), klik Save
3 Bisma 208 2.2
- Save as ke folder PRAK1: 17. Simpan workspace
“PRAK1.xlsx” (Excel Workbook) dan - Aktifkan (klik) window R Console
“PRAK1.csv” (CSV (comma delimited)) - Klik File > Save Workspace…
- Tulis nama file (PRAK1.RData), klik Save
2

AGH 611 Praktikum Pengenalan SAS

Pengantar
SAS/STAT adalah suatu modul dari SAS System yang diperuntukkan untuk analisis statistik.
Lingkungan SAS/STAT yang sering digunakan terdiri dari tiga windows utama, yaitu:
1) Editor, berfungsi sebagai tempat menulis program. Setiap baris umumnya diakhiri dengan tanda
titik koma. Setiap bagian program (terdiri dari beberapa baris) diakhiri dengan pernyataan run;
2) Log berguna untuk menampilkan pesan apakah suatu perintah telah berhasil dikerjakan atau terdapat
kesalahan.
3) Output berfungsi untuk menampilkan hasil proses dari suatu program.

Menjalankan SAS
1. Buka SAS melalui menu: Start  Programs  The SAS System  The SAS System for Windows.
2. Di layar akan tampil dua window, yakni Log dan Program Editor. Ada satu window lagi yang tidak
tampil, yakni Output. Untuk berpindah antar window, klik menu Window, kemudian pilih
window yang dituju.

Memasukkan Data ke SAS


Data yang dientri melalui program spreadsheet (contohnya Microsoft Excel) dapat dimasukkan ke
SAS melalui dua cara: (1) melalui menu Import Data, (2) melalui copy-paste ke window Editor.

Cara 1. Impor data ke SAS versi 9.0 dapat dilakukan langsung bagi file Microsoft Excel 2003 (berakhiran
.xls, bukan .xlsx). Langkah-langkah impor data tersebut adalah sebagai berikut:

1. Buatlah satu folder baru menyimpan file data dan hasil analisisnya.
2. Di Excel, klik File – Save As, kemudian:
a. Pilih folder tempat Anda akan menyimpan file.
b. Tulis nama file dan pilih tipe file sebagai berikut:

3. Di SAS, klik File  Import. Akan muncul window Import Wizard seperti Gambar 1. Pilih Microsoft
Excel 97, 2000, or 2002 Workbook (pilihan ini bisa juga untuk file Excel 2003). Klik Next.

Gambar 1. Import Wizard – Memilih format file

4. Cari file yang akan diimpor (klik Browse) (Gambar 2)


3

Gambar 2. Import Wizard – Mencari file yang akan diimpor

5. Pilih sheet yang berisi data yang akan diimpor (catatan: di Excel, satu file bisa berisi beberapa sheet)
(Gambar 3)

Gambar 3. Import Wizard – Memilih sheet yang berisi data yang akan diimpor

6. Pada kolom Member, ketik nama data set, misalnya prak1 (Gambar 3). PENTING: Nama data
set ini akan digunakan dalam listing program berikutnya. Klik Finish.

Gambar 4. Import Wizard – Menulis nama data set (”Member”)

7. Periksa window Log, seharusnya ada pesan ”WORK.PRAK1 was successfully created.”
8. Untuk melihat apakah data sudah diimpor dengan benar, di Program Editor, ketik sbb:

proc print data=prak1;


run;
Kemudian klik icon Run pada toolbar.

Lihat window Log. Jika tidak ada pesan kesalahan (tidak ada pesan yang berwarna merah), buka
window Output. Jika ada pesan kesalahan, periksa kembali listing program di window Editor. Berikut
sebagian isi window Output jika program berhasil dijalankan:

Obs ul geno ttan bpplot


1 1 P6 176.75 1.06683
2 2 P6 181.20 1.09087
Lakukan clear Log dan Output setiap
3 3 P6 180.00 0.87651 kali menjalankan (run) program.
4 1 MKB 176.40 0.82617
5 2 MKB 160.25 0.63201
4

Cara 2. Data dapat dimasukkan ke SAS secara langsung melalui copy-paste dari Excel ke Program Editor.

/* hapus data, log, dan output */


proc datasets kill; run;
dm 'log; clear; output; clear';
options pagesize=max formdlim='-' nocenter nonumber nodate;

/* input data */
data jagung;
input ul geno$ ttan bpplot;
cards;
1 P6 177 1.1
2 P6 181 1.1
3 P6 180 0.9
1 MKB 176 0.8
2 MKB 160 0.6
3 MKB 187 0.7
1 P6xMKB 230 2.0
2 P6xMKB 237 2.3
3 P6xMKB 220 2.6
1 Semar3 213 1.9
2 Semar3 211 2.0
3 Semar3 223 2.6
1 Bisma 218 1.9
2 Bisma 217 2.2
3 Bisma 208 2.2
;

/* lihat data */
proc print data=jagung;
run;

/* anova faktor tunggal RKLT */


proc anova data=jagung;
class ul geno;
model ttan bpplot = ul geno;
means geno / duncan;
run;

/* urutkan data berdasarkan genotipe */


proc sort data=jagung;
by geno;
run;

/* hitung rata-rata per genotipe (genotype means) */


proc means data=jagung noprint;
by geno;
var ttan bpplot;
output out=jmeans mean=;
run;

/* lihat data rata-rata per genotipe */


proc print data=jmeans;
run;

/* analisis korelasi menggunakan data rata-rata per genotipe */


proc corr data=jmeans;
var ttan bpplot;
run;

/* analisis regresi menggunakan data rata-rata per genotipe */


proc reg data=jmeans;
model bpplot = ttan;
run;
5

Output SAS (hasil analisis data)


---------------------------------------------------------------------------------------------------

The SAS System

Obs ul geno ttan bpplot

1 1 P6 177 1.1
2 2 P6 181 1.1
3 3 P6 180 0.9
4 1 MKB 176 0.8
5 2 MKB 160 0.6
6 3 MKB 187 0.7
7 1 P6xMKB 230 2.0
8 2 P6xMKB 237 2.3
9 3 P6xMKB 220 2.6
10 1 Semar3 213 1.9
11 2 Semar3 211 2.0
12 3 Semar3 223 2.6
13 1 Bisma 218 1.9
14 2 Bisma 217 2.2
15 3 Bisma 208 2.2

---------------------------------------------------------------------------------------------------

The SAS System

The ANOVA Procedure

Class Level Information

Class Levels Values

ul 3 1 2 3

geno 5 Bisma MKB P6 P6xMKB Semar3

Number of observations 15

---------------------------------------------------------------------------------------------------

The SAS System

The ANOVA Procedure

Dependent Variable: ttan

Sum of
Source DF Squares Mean Square F Value Pr > F

Model 6 7052.000000 1175.333333 14.43 0.0007

Error 8 651.733333 81.466667

Corrected Total 14 7703.733333

R-Square Coeff Var Root MSE ttan Mean

0.915400 4.456495 9.025889 202.5333

Source DF Anova SS Mean Square F Value Pr > F

ul 2 14.933333 7.466667 0.09 0.9134


geno 4 7037.066667 1759.266667 21.59 0.0002

---------------------------------------------------------------------------------------------------
6

The SAS System

The ANOVA Procedure

Dependent Variable: bpplot

Sum of
Source DF Squares Mean Square F Value Pr > F

Model 6 6.69466667 1.11577778 22.24 0.0001

Error 8 0.40133333 0.05016667

Corrected Total 14 7.09600000

R-Square Coeff Var Root MSE bpplot Mean

0.943442 13.49272 0.223979 1.660000

Source DF Anova SS Mean Square F Value Pr > F

ul 2 0.17200000 0.08600000 1.71 0.2401


geno 4 6.52266667 1.63066667 32.50 <.0001

---------------------------------------------------------------------------------------------------

The SAS System

The ANOVA Procedure

Duncan's Multiple Range Test for ttan

NOTE: This test controls the Type I comparisonwise error rate, not the experimentwise error rate.

Alpha 0.05
Error Degrees of Freedom 8
Error Mean Square 81.46667

Number of Means 2 3 4 5
Critical Range 16.99 17.71 18.11 18.35

Means with the same letter are not significantly different.

g Mean N geno

A 229.000 3 P6xMKB
A
A 215.667 3 Semar3
A
A 214.333 3 Bisma

B 179.333 3 P6
B
B 174.333 3 MKB

---------------------------------------------------------------------------------------------------
7

The SAS System

The ANOVA Procedure

Duncan's Multiple Range Test for bpplot

NOTE: This test controls the Type I comparisonwise error rate, not the experimentwise error rate.

Alpha 0.05
Error Degrees of Freedom 8
Error Mean Square 0.050167

Number of Means 2 3 4 5
Critical Range .4217 .4395 .4494 .4553

Means with the same letter are not significantly different.

Mean N geno

A 2.3000 3 P6xMKB
A
A 2.1667 3 Semar3
A
A 2.1000 3 Bisma

B 1.0333 3 P6
B
B 0.7000 3 MKB

---------------------------------------------------------------------------------------------------

The SAS System

Obs geno _TYPE_ _FREQ_ ttan bpplot

1 Bisma 0 3 214.333 2.10000


2 MKB 0 3 174.333 0.70000
3 P6 0 3 179.333 1.03333
4 P6xMKB 0 3 229.000 2.30000
5 Semar3 0 3 215.667 2.16667

---------------------------------------------------------------------------------------------------

The SAS System


The CORR Procedure
2 Variables: ttan bpplot

Simple Statistics

Variable N Mean Std Dev Sum Minimum Maximum

ttan 5 202.53333 24.21616 1013 174.33333 229.00000


bpplot 5 1.66000 0.73726 8.30000 0.70000 2.30000

Pearson Correlation Coefficients, N = 5


Prob > |r| under H0: Rho=0

ttan bpplot

ttan 1.00000 0.98573


0.0020

bpplot 0.98573 1.00000


0.0020

---------------------------------------------------------------------------------------------------
8

The SAS System


The REG Procedure
Model: MODEL1
Dependent Variable: bpplot
Analysis of Variance

Sum of Mean
Source DF Squares Square F Value Pr > F

Model 1 2.11261 2.11261 102.87 0.0020


Error 3 0.06161 0.02054
Corrected Total 4 2.17422

Root MSE 0.14330 R-Square 0.9717


Dependent Mean 1.66000 Adj R-Sq 0.9622
Coeff Var 8.63281

Parameter Estimates

Parameter Standard
Variable DF Estimate Error t Value Pr > |t|

Intercept 1 -4.41815 0.60269 -7.33 0.0052


ttan 1 0.03001 0.00296 10.14 0.0020

Anda mungkin juga menyukai