Factors in R

The video below discusses the factor data type in R. Factors are the data type used to store categorical variables. In R, factors are recognized by statistical procedures such are linear least-squares regression (the lm() function) and handled appropriately.

The data file used in this video can be downloaded here. The R code file can be downloaded here.

The video is about 31 minutes.

Python With Spyder 14: If Statements

This is the 14th in a series of videos providing a tutorial on Python 2.7 using Anaconda Python and the Spyder IDE. Click here to go to a “home page” for the video series.

This video introduces the “if” statement in Python. “If” statements are, of course, extremely important in programming languages as they are the most direct way to implement conditional logic. And it is the ability for programs to make “decisions” based on such conditional logic that allows program to perform non-trivial tasks.

The source code used in this video can be found here. You can right click on the link and use “Save As” to save the file.

Note: The source code files are plain text files with a “.txt” extention. You will probably want to change the extensions to “.py” after you download them. If you do so, please be aware that if you have Python installed, the file will become executable, so that it will run if you click on it (accidentally or otherwise).

The video is about 27 minutes long.

PWS14-DSSThumb

Video Index: For Loops

Click on the topics below to jump to that location in the video.

Time Topic
00:00Title slide
00:06Introduction
00:48Comments between three double quotes (“””)
00:58The syntax of the “if” statement in Python
02:00The “elif” statement
02:42The “else” statement
03:18More than one “elif” statement allowed
03:42Good coding practices focus on readable code.
03:59Comparison to the if() function in Excel
05:16The examples of “if” statements in this video build on the GetItems() function from the last video.
05:40List data for the examples: Names of the highest paid CEOs in 2014.
06:15Define the function GetItems() in the console
06:45Example of running GetItems()
07:16Reminder: Python list indices start at 0
08:09Review of how the GetItems() function works.
08:59Need to check for valid function arguments.
10:04Need to check that the first function argument is a list.
10:20Use of the “if” statement to check the argument
10:22Use of isinstance() built-in function to check an objects type.
10:47Logical “not”
10:55isinstance() syntax
11:21Use print statement to print an error message.
11:40Return and empty list.
11:52Check that second argument to GetItems() is a list.
12:36Need to check for valid indices in IndexList argument.
13:15Need to first check that index is an integer.
13:30Use “if” statement and isinstance() to check that index is an interger.
13:50Use “else” statement to print a warning.
14:04Append the value of None to the returned list.
14:37Check that the index is value for the GetItems() argument InputList.
14:46The usual range of indices for a list is 0 to n-1 (n = length of the list).
15:00Negative indices are possible.
15:18Use len() built-in function to same the length of InputList.
15:48Use “if” statement to check the index value.
16:26Use “else” statement to print a warning and return None.
17:00Change the name of the functions GetItems() to GetListItems()
17:33Spyder editor warns of a syntax error.
18:19Run code cell with cntr-Enter to define the function GetListItems() and the test case.
18:46Test list checking for the second argument by using a string.
19:22Test list checking for the first argument using a dictionary.
20:39Test checking for valid index values with an out-of-range positive index
21:21Test negative indices with a valid example.
21:41Test negative index that is out of range.
22:10Test empty list for the first argument.
23:03Test with single integer as the second argument.
24:17Modify the function to handle as single integer index value
26:06Re-run the function definition in the console
26:17Re-run the test case with a single integer index.
26:26Summary and conclusion

Python With Spyder 13: For Loops

This is the 13th in a series of videos providing a tutorial on Python 2.7 using Anaconda Python and the Spyder IDE. Click here to go to a “home page” for the video series.

This video introduces looping or iteration in Python using the “for” statement. Looping, of course, is one of the most important things in programming languages as many problems require iteration over an index or a set.

The source code used in this video can be found here. You can right click on the link and use “Save As” to save the file.

Note: The source code files are plain text files with a “.txt” extention. You will probably want to change the extensions to “.py” after you download them. If you do so, please be aware that if you have Python installed, the file will become executable, so that it will run if you click on it (accidentally or otherwise).

The video is about 34 minutes long.

PWS13-DSSThumb

Video Index: For Loops

Click on the topics below to jump to that location in the video.

Time Topic
00:00Title Slide
00:06Inrtoduction
00:23The idea of program flow control
01:12The syntax of the Python “for” statement
01:33Iterables
01:58The colon (“:”) in the for statement signals a following block of code
02:11The end of the block of code
02:21What the “for” statement does.
02:54Comparison of the Python “for” to other computer languages
04:18Data example: The names of the 200 highest paid CEOs in 2014
04:35CEO name list defined in a code cell
04:44Execution of the code in a cell
05:02Length of a list using built-in function len()
05:18List of CEO first names defined
05:45List of CEO last names defined
06:32First example: get an arbitrary set of list items — the GetItems() function
07:10How the GetItems() example function works.
08:29Create the GetItems() function with “def”
09:11Define and empty list for output
09:25The “for” statement in GetItems()
09:47The “for” statement ends with a colon (“:”)
10:15Summary of the GetItems() code.
10:43Return the output from GetItems()
11:00No error checking done! A bad practice!
11:42Run the code cell with cntrl-enter to define the GetItems() function
11:58Test the GetItems() function.
12:34Summary and review of the GetItems() function.
13:10Final example in this video will iterate over an index.
13:23Iterating over an index is consistent with earlier computer languages.
13:53Final example will compute a correlation.
14:03Example will correlation the length of the CEO first and last names.
14:22Review formulas for the sample correlation.
14:45The formula for the sample mean.
14:54The summation notation from mathematics.
15:25The formula for the sample standard deviation.
16:21The formula for the sample covariance.
17:18The formula for the sample correlation.
18:19Define the function mean() to compute the sample mean.
18:52The “for” loop in the mean() function.
19:18The “+=” notation.
20:12The “/=” notation.
20:53Define the function sd() to compute the sample standard deviation.
21:09Call the mean() function from the sd() function.
21:23The “for” loop in the sd() function.
22:39An index was not used in the mean() or sd() functions.
22:57Stepping through X and Y at the same time using an index.
23:33The range() function
25:30Defining the cor() function to compute the sample correlation.
26:53The “for” loop in the cor() function using the range() function and an index.
27:45Using the index to retrieve values from X and Y (subscripts for X and Y).
28:33Summary: Why the index approach is natural for two lists X and Y.
31:05Compute the length of a string with the len() function.
31:20Computing the length of the first names and last names using the map() function.
32:30Computing the correlation between the first name length and the last name length using cor(), map(), and len().
33:28Conclusion

Recording Video Directly from an IPEVO Ziggi-HD Document Camera Using the VLC Video Player

I just bought ahere.

In any case, recording directly from this document camera is NOT straightforward, in part because of the lack of documentation, and also a bug in the current version of the VLC player.

Here are the instructions. They were quickly put together, mostly for my own purposes, so they are a bit terse. I may make a video of this at some point, in which case I will edit this message. Note: My VLC player is up-to-date (version 2.2.1) and I did all of this on a Windows 7 notebook computer.

  1. Plug in the IPEVO Ziggi document camera to a USB port on your computer.
  2. Start the VLC player.
  3. Go to Media menu and then the Open Capture Device menu item. A dialog will appear.
  4. On this dialog, Capture mode should be set to Direct Show.
  5. Video device name should be IPEVO Ziggi+HD.
  6. Audio device name: I use Categories UncategorizedLeave a comment