cardioguy/CleaningData
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
README.md ## Overview This assignment uses data from: https://d396qusza40orc.cloudfront.net/getdata%2Fprojectfiles%2FUCI%20HAR%20Dataset.zip Run_analysis.R contains the main routine run_analysis and function read_dataset. <b>Dataset</b> The data consists of records with following: - Triaxial acceleration from the accelerometer (total acceleration) and the estimated body acceleration. - Triaxial Angular velocity from the gyroscope. - A 561-feature vector with time and frequency domain variables. - Its activity label. - An identifier of the subject who carried out the experiment. The individual variables are described in features.info and reproduced here. Feature Selection ================= The features selected for this database come from the accelerometer and gyroscope 3-axial raw signals tAcc-XYZ and tGyro-XYZ. These time domain signals (prefix 't' to denote time) were captured at a constant rate of 50 Hz. Then they were filtered using a median filter and a 3rd order low pass Butterworth filter with a corner frequency of 20 Hz to remove noise. Similarly, the acceleration signal was then separated into body and gravity acceleration signals (tBodyAcc-XYZ and tGravityAcc-XYZ) using another low pass Butterworth filter with a corner frequency of 0.3 Hz. Subsequently, the body linear acceleration and angular velocity were derived in time to obtain Jerk signals (tBodyAccJerk-XYZ and tBodyGyroJerk-XYZ). Also the magnitude of these three-dimensional signals were calculated using the Euclidean norm (tBodyAccMag, tGravityAccMag, tBodyAccJerkMag, tBodyGyroMag, tBodyGyroJerkMag). Finally a Fast Fourier Transform (FFT) was applied to some of these signals producing fBodyAcc-XYZ, fBodyAccJerk-XYZ, fBodyGyro-XYZ, fBodyAccJerkMag, fBodyGyroMag, fBodyGyroJerkMag. (Note the 'f' to indicate frequency domain signals). These signals were used to estimate variables of the feature vector for each pattern: '-XYZ' is used to denote 3-axial signals in the X, Y and Z directions. tBodyAcc-XYZ tGravityAcc-XYZ tBodyAccJerk-XYZ tBodyGyro-XYZ tBodyGyroJerk-XYZ tBodyAccMag tGravityAccMag tBodyAccJerkMag tBodyGyroMag tBodyGyroJerkMag fBodyAcc-XYZ fBodyAccJerk-XYZ fBodyGyro-XYZ fBodyAccMag fBodyAccJerkMag fBodyGyroMag fBodyGyroJerkMag The set of variables that were estimated from these signals are: mean(): Mean value std(): Standard deviation mad(): Median absolute deviation max(): Largest value in array min(): Smallest value in array sma(): Signal magnitude area energy(): Energy measure. Sum of the squares divided by the number of values. iqr(): Interquartile range entropy(): Signal entropy arCoeff(): Autorregresion coefficients with Burg order equal to 4 correlation(): correlation coefficient between two signals maxInds(): index of the frequency component with largest magnitude meanFreq(): Weighted average of the frequency components to obtain a mean frequency skewness(): skewness of the frequency domain signal kurtosis(): kurtosis of the frequency domain signal bandsEnergy(): Energy of a frequency interval within the 64 bins of the FFT of each window. angle(): Angle between to vectors. Additional vectors obtained by averaging the signals in a signal window sample. These are used on the angle() variable: gravityMean tBodyAccMean tBodyAccJerkMean tBodyGyroMean tBodyGyroJerkMean ## Loading the data The full path is used in the code provided. Note that the raw dataset is fairly large (the larger of the two files about 64Mb) but well within the capacity of most PCs. To speed things a bit only the mean and std related variables are read in from the outset. ## Routine descriptions <b>Run_analysis</b> Sets the working directory (using the full path) and loads the data.table library (available from CRAN). The filenames are passed as strings to avoid making a-priori assumptions about filenames and directory structure thus allowing greater flexibility. In this case the strings for the subdirectory name, and filenames for the raw data, label data and subject information are provided as string for both the test and training data. The feature names, and activity labels are read and the only those features with the text mean or std are selected. This subset of features is passed to the read_dataset , along with the string of filesnames and labels which reads and “assembles” the selected data set. Both the training and test data sets are read and merged together by row prior to the tidying (cleaning up) of the column labels/variables names for readability and saving as a CSV file. <b>Read_dataset</b> Receives 3 arguments consist of (a) a list of strings specifying the subdirectory and the data file, label file and subject information file, (b) a list of features to be selected (as strings) and (c) a list of activity names. A leader/header is created so that the full path can be used in the read.table calls. Three files are read in succession. The data file is read first, selecting only those features in the list of features (in this case those with mean and std in the name). The row label and subject identifier files are both read and “appended” as columns to the data frame. The last step is transforming the data frame into a data table before returning.