Discussion 05 - Matrix

Discussion 05 - Matrix - Masanao Yajima Your reader went...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Masanao Yajima
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Your reader went very easy on you since this is the first time. But the stake is going to get higher as we go on. Specially if you are unsure of for loops and variable assignment make sure you are able to use them since you will need it for the next homework.
Background image of page 2
# moment around 0 MomentZero <- function( x ) { moments <- rep( NA, 4 ) nx <- length( x ) for( i in 1:4 ){ moments[i] <- sum( x ^ i ) / nx } return( moments ) } # moment around the mean MomentMean <- function( x ) { moments <- NULL nx <- length( x ) mx <- mean( x ) for( i in 1:4 ) { moments <- c(moments, sum( ( x - mx ) ^ i ) / nx ) } return( moments ) } # skewness and kurtosis SkewKurtosis <- function( x ){ mu <- MomentMean( x ) skewness <- mu[3] / ( mu[2] ^ ( 3 / 2 ) ) kurtosis <- mu[4] / ( mu[2] ^ 2 )-3 result <- c( skewness, kurtosis ) names( result ) <- c( "skewness,", " kurtosis" ) return( result ) }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
# core function that is more general SampleMoment<- function( x, moment = c( 1:4 ), center = 0 ) { nx <- length( x ) return( sapply( moment, function( m ) { sum( ( x - center ) ^ m ) / nx } ) )
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/14/2011 for the course STATS 102A 102A taught by Professor Jandeleeuw during the Fall '10 term at UCLA.

Page1 / 12

Discussion 05 - Matrix - Masanao Yajima Your reader went...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online