Lusi Lab Library 1. LSM Description

advertisement
Lusi Lab Library
source('http://www.depts.ttu.edu/psy/lusi/files/lusi.txt') or source('http://tiny.cc/lusilab')
Functions:
1. lsm
2. splot
3. bsmed
1. LSM
Description
Calculates Language Style Matching based on LIWC output.
Usage
lsm(x, comp=c(9.95,5.26,6.51,8.53,5.27,12.93,5.90,1.66,2.02), append=F, print=F, graph=F,
cats=c('ppron','ipron','article','auxverb','adverb','prep','conj','negate','quant'), ncats=length(cats))
LSMMeans : Prints a matrix of LSM comparison means by category, from the 2015 LIWC manual.
Arguments
x
Can be the path to a .txt or .csv file, or a data frame.
comp
The values each row is being compared to. Default is the grand means from the
LIWC 2015 manual. More specific comparisons are also available (e.g.,
comp='Narrative', see LSMMeans), or a new comparison can be calculated from
the current data (i.e., comp=T to compare each row with each category's mean).
Can also specify with manually entered values (e.g., comp=c(2.3, 3.4, 5.4) in the
same order as cats), or directed to a row with labels corresponding to cats
(e.g., comp=data[1,] to compare all rows with the first).
append
If T, appends the output to the end of the source file.
print
If T, creates a new "LSM.csv" file containing the output.
graph
If T, graphs histograms of each category, and overall LSM.
cats
The categories to be used in the comparison. Default categories are ppron,
ipron, article, auxverb, adverb, prep, conj, negate, quant, in that order.
Can also be specified, e.g., cats=c('article','auxverb','adverb'), or edited, e.g.,
cats=cats[cats!='negate'].
ncats
The number of categories that should go into the comparison. Default is all.
ncats=8 will exclude the quant category, and ncats=7 will exclude both the
negate and quant categories.
Examples
comps=lsm('X:/file.csv', c(3.44, 5.23, 12.6, 6.34), print=T, cats=('quant', 'article', 'prep', 'ppron'))
This will read the file specified, and compare each category listed with the specified value
for that category, then create an "LSM.csv" file in the working directory. The LSM values for
each category, for each line are also saved as a matrix called comps.
data=read.table('x:/file.txt',T)
comps=lsm(data, data[1,], T, F, T, cats, 7)
This will compare each line of the input data with the first line of that data in the first 7
default categories, then append and graph the data. Since the input is not a file path, you
will be prompted to provide a path, and if no file exists there, it will be created.
data$ALSM=lsm(data, 'Expressive', ncats=7)[,'LSM']
This will create a new variable in your data called LSM based on a comparison of each row
with the expressive writing means from the LIWC 2015 manual, excluding the quant and
negate categories from the LSM calculation.
data=cbind(data, lsm(data, T, ncats=7))
This will add LSM variable to the data for each of the first 7 categories (e.g., LSMppron,
LSM) based on a comparison of each row with each category's mean.
2. splot
Description
Plots two variables at levels of a third variable. Helpful for visualizing interactions and such.
Usage
splot(y, x, s=NA, data=NA, su=NULL, lim=4, loess=F, colors=NA, lpos='auto', lines=T, split='median',
type='scatter', na='omit')
Arguments
y
Required. Y variable; can be the name of a variable in the defined data, or
vector of the same length as the other variables.
x
Required. X variable; can be the name of a variable in the defined data, or
vector of the same length as the other variables.
s
Required. The variable you want to split by; can be the name of a variable in
the defined data, or vector of the same length as the other variables. This is
treated as a factor, and if there are too many levels, it will be median split to
create 2 ("high" and "Low") levels (or 3 if split is specified). See lim.
data
Not required if variables are objects. The data frame or matrix your variables
are coming from or are the same length as.
su
Subset of your date (e.g., VarA==1&VarB<10). Default none.
lim
Sets the maximum number of levels your by variable can have before it is
median split. Default 5.
loess
If T, fits loess lines rather than regression lines to your variables at each level
of your by factor. Default F.
colors
Applies colors to the data points and prediction lines of each level of your
factor, in this order. Can be any vector of color names (e.g., colors=c('red', 'green',
'blue') or colors=grey(1:5/5)) of at least the number of levels of your factor. Default
green3, purple, black, red, blue, cyan, magenta, yellow, gray.
lpos
Sets the position of the legend. Can be any names position (e.g., 'bottomleft').
Default 'auto' (will got top right or left depending on the beta direction).
lines
If F, does not calculate or display regression or loess lines. Default T.
split
How to split the splitting variable. Options are "Median", "Quantile", and
"Standard Deviation" ('m', 'q', or 's'). Default 'median'.
type
Type of plot, between scatter and bar. If your x variable is a factor (has fewer
than lim levels), splot will produce a bar graph (mean value of y at each level of
x and s). If your x variable is not a factor, but you specify type='bar', it will split x
based on the split specified (median by default).
na
Currently only omits any rows (across all included variables) with missing data.
Might do something in the future.
Examples
splot(mpg, disp, vs, mtcars)
This is a minimally defined splot,
showing an interaction between
displacement and V versus straight
engines, whatever those are,
predicting miles per gallon.
splot(mpg, cyl, am, mtcars)
This automatically displayed a bar
graph because cyl only has 3 levels.
splot(mpg, drat, qsec, mtcars, type='bar', split='q')
This one binned drat since type was
specified as bar.
Won't currently run if there are levels
with no observations. For example, there
are no cars with fewer than 4 gears that
weight 1 standard deviation less than the
mean, so
splot(mpg, wt, gear, mtcars, type='bar', split='s')
would break splot.
3. bsmed
Description
Displays the results of Sobel and bootstrapping tests for simple mediation.
*Bootstrapping indicated 'significance' when the confidence interval does not include 0.
Usage
bsmed(x, y, m, i=1000, alpha=.05)
m
x
c (c')
y
Arguments
x
X variable; must be an existing object, or a variable some loaded data (e.g.,
data$variable).
y
Y variable; must be an existing object, or a variable some loaded data (e.g.,
data$variable).
m
Mediating variable; must be an existing object, or a variable some loaded data
(e.g., data$variable).
The number of iterations to be processed for bootstrapping. Default is 1000.
i
alpha
The alpha level for the bootstrapping confidence interval. Default is .05 (i.e.,
2.5% and 97.5%).
Examples
bsmed(mtcars$disp, mtcars$mpg, mtcars$wt)
This displays the mediation of weight on the relationship between displacement and miles
per gallon.
Download