Psychology Wiki Entries

I just finished the bulk of my first psychology wiki entries.

I’m using the wiki format to collect and organize journal article summaries for my own use. I think having the summaries in an easily searchable format will be helpful in future research.

Here is the first one I ever uploaded.

Judgement Under Uncertainty: Heuristics and Biases, by Amos Tversky and Daniel Kahneman

The full list can be found at “All pages“, along with some notes about using Latex and APA 6th Edition.

I’m still learning the WikiMedia interface, so I have the reference information for the article, but I haven’t gotten it formatted in the wiki yet. Also, if one of your articles is summarized and don’t want the summary available to the public, let me know and I will remove it from public view.

Posted in Uncategorized | Leave a comment

A Basic Regression in R

Here is a basic R program for doing a simple linear regression.  Below I’ll show some common modifications that one might want that aren’t intuitive to add.

First, we import the data, in this case from a CSV (comma separated variable) file.

emp <- read.table("/Vols/duphenix/Docs/self_emp/employ.csv", header=TRUE, sep=",")

I’ll explain each piece

  1. emp, is just a container name, I’ll use it every time I want to refer to, or use the raw data
  2. <-, assigns whatever follows it to the container name
  3. read.table(), is the function that actually pulls in the data from the disk or other location
  4. “/Vols/duphenix/Docs/self_emp/employ.csv”, is the path to the file or location containing the data.  On windows machines, this would begin with C:\ (or whatever drive letter you are using is) and then the file path.
  5. header=TRUE, this tells read.table that the first line in the csv file contains the variables names for each column.  The other option would be to use row.names to call a list containing the variable names, for now it is much easier to just use header=TRUE and have the variable names in the csv file.
  6. sep=”,”, lets read.table know that the separator between columns is a comma, “\t” would tell read.table that it was a tab delineated file (no matter what the file extension was).

You can use,

print(emp)

to print the data in the emp container we just made with read.table.  You would use this to verify that the data was imported correctly.

summary(emp)

Will print summary statistics for the data, by default the mean, median, maximum, minimum and quintiles.  You can get individual summary statistics from other functions.

names(emp)

Will print all the variable names from the emp dataset, which can be useful when you need to use them later in the program.

Now that we have the data entered, and have a list of the variable names we can get to the actual regression.

The most basic linear regression in R is called by the lm() function, lm stands for Linear Model.

lm(emp$dependent_var ~ emp$independent_var_1 + emp$independent_var_2)

In this case emp is the dataset, the $ is the separator and dependent_var is the dependent variable (or explanatory variable, or regressor, etc.) .  The ~ tells the lm function that the independent variables (or observed variables, or regressands, etc.) follow.  The next two, emp$independent_var_1, and emp$independent_var_2, are the first two independent variables.  You could use as many as you wanted here, depending either on your experimental design, or theoretical background.

Some variations should be mentioned here.  If you needed to force the intercept to 0, for theoretical or logical reasons, you could rewrite the line as follows,

lm(emp$dependent_var ~ -1 + emp$independent_var_1 + emp$independent_var_2)

with the -1 forcing the intercept to zero.

You could also use the more flexible generalized linear model, or glm().  By default this usually will give results identical to the lm() function, but you can specify a different family of distributions in it.  The following is an example of using the glm() function to get identical results to the lm() function.

glm(emp$dependent_var ~ -1 + emp$independent_var_1 + emp$independent_var_2, family = gaussian)

Posted in Uncategorized | 2 Comments

Welcome

I’ve moved from drupal to WordPress as it matches my current usage pattern. I’ll repost all the content from my old site soon.

Posted in Uncategorized | Tagged | Leave a comment