Re: R in SPSS 16 - Graphical output

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: R in SPSS 16 - Graphical output

Michael-416
Hi Jon,

I am trying to use simple R functions to explore my data from within SPSS 16.
I read that SPSS 16 cannot output graphics in the Viewer and therefore I
need to export them to an external data file. I have however a hard time
finding information on have to do this. For instance, if I use

library(UsingR)
print(simple.hist.and.boxplot(variable_name))
(should output both an histogram and boxplot of the data)

I get an output like this:

$stats
     [,1]
[1,]   47
[2,]   60
[3,]   80
[4,]   97
[5,]  150

$n
[1] 28

$conf
        [,1]
[1,] 68.9521
[2,] 91.0479

$out
[1] 999 999 999

$group
[1] 1 1 1

$names
[1] "1"

What is the correct procedure to use to make it work ?

Regards,

Michael

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: R in SPSS 16 - Graphical output

Jon K Peck

See below.
Jon Peck
SPSS, an IBM Company
[hidden email]
312-651-3435



From: Michael <[hidden email]>
To: [hidden email], [hidden email]
Cc: Michael <[hidden email]>
Date: 12/09/2009 02:36 PM
Subject: Re: R in SPSS 16 - Graphical output





Hi Jon,

I am trying to use simple R functions to explore my data from within SPSS 16.
I read that SPSS 16 cannot output graphics in the Viewer and therefore I
need to export them to an external data file. I have however a hard time
finding information on have to do this.


>>>Later versions of SPSS do indeed include the graphics in the Viewer.  I don't have Version 16 installed on my current machine, but I think you could use the savePlot function in R to write the graphics to a file of whatever image type you want.

Alternative you can modify set the R graphics driver or use dev.print.
HTH,
Jon

For instance, if I use

library(UsingR)
print(simple.hist.and.boxplot(variable_name))
(should output both an histogram and boxplot of the data)

I get an output like this:

$stats
    [,1]
[1,]   47
[2,]   60
[3,]   80
[4,]   97
[5,]  150

$n
[1] 28

$conf
       [,1]
[1,] 68.9521
[2,] 91.0479

$out
[1] 999 999 999

$group
[1] 1 1 1

$names
[1] "1"

What is the correct procedure to use to make it work ?

Regards,

Michael


Reply | Threaded
Open this post in threaded view
|

Desired Data Value Labels not being applied by template?

Simon Palmer-4
Hello all,

I am trying to re-run some code that produces (separate) pie charts
for multiple variables. I am using a template to display Data Labels
on the segments, but I want the Percent to display rather than the
original category labels ("Strongly Agree", "Agree" etc). But despite
saving the template with the Data Value Labels showing Percent and
selecting all settings, when I create new charts with that template
specified in the GRAPHSPEC subcommand of GGRAPH, the original category
labels appear rather than the percents that I want.

The particularly perplexing dilemma is that I  got exactly what I
wanted when I ran this last year, but now I have this problem even
when I re-run the same syntax using the same data and template as last
time. I am running it on a newer computer and using version 18 rather
than 17 so my best guess is that something is set up differently. But
I can't figure out what. Can anybody help? I don't think the problem
is my syntax, but I have attached it just in case:

BEGIN PROGRAM.
import spss, spssaux
varDict = spssaux.VariableDict()
varlist = []
for x in range (1,21):
         varlist.append('Q' + str(x))
for var in varlist:
        texttitle = varDict[var].VariableLabel
        spss.Submit(r"""
        GGRAPH
   /GRAPHDATASET NAME="graphdataset" VARIABLES=%(varname)s COUNT()
[name="COUNT"] MISSING=LISTWISE
     REPORTMISSING=NO
   /GRAPHSPEC SOURCE=INLINE
    TEMPLATE=[chart_data_labels.sgt].
BEGIN GPL
   SOURCE: s=userSource(id("graphdataset"))
   DATA: fred=col(source(s), name("%(varname)s"), unit.category())
   DATA: COUNT=col(source(s), name("COUNT"))
   COORD: polar.theta(startAngle(0))
   GUIDE: axis(dim(1), null())
   GUIDE: legend(aesthetic(aesthetic.color.interior))
   GUIDE: text.title(label("%(title)s"))
   SCALE: linear(dim(1), dataMinimum(), dataMaximum())
   SCALE: cat(aesthetic(aesthetic.color.interior), include("1", "2",
"3", "4", "5", "9999"))
   ELEMENT: interval.stack(position(summary.percent(COUNT))),
color.interior(fred))
END GPL.
        """ %{'varname':var, 'title':texttitle})
END PROGRAM.

Thanks in anticipation,
Simon

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Desired Data Value Labels not being applied by template?

ViAnn Beadle
Chart templates are a continuing work in progress in SPSS charts. You can directly speciffy the percentage chart labels using the label function on the ELEMENT statement, as in label(summary.percent(fred)). You might need a template to format the number including the percent sign but that's a much simpler template than one which adds the label to the chart. Generally speaking, templates work best for formatting rather than adding structural elements to the chart. If this doesn't work for you, send me your template by private email and I'll futz around with.

On Wed, Dec 9, 2009 at 4:18 PM, Simon Palmer <[hidden email]> wrote:
Hello all,

I am trying to re-run some code that produces (separate) pie charts
for multiple variables. I am using a template to display Data Labels
on the segments, but I want the Percent to display rather than the
original category lWabels ("Strongly Agree", "Agree" etc). But despite
saving the template with the Data Value Labels showing Percent and
selecting all settings, when I create new charts with that template
specified in the GRAPHSPEC subcommand of GGRAPH, the original category
labels appear rather than the percents that I want.

The particularly perplexing dilemma is that I  got exactly what I
wanted when I ran this last year, but now I have this problem even
when I re-run the same syntax using the same data and template as last
time. I am running it on a newer computer and using version 18 rather
than 17 so my best guess is that something is set up differently. But
I can't figure out what. Can anybody help? I don't think the problem
is my syntax, but I have attached it just in case:

BEGIN PROGRAM.
import spss, spssaux
varDict = spssaux.VariableDict()
varlist = []
for x in range (1,21):
       varlist.append('Q' + str(x))
for var in varlist:
      texttitle = varDict[var].VariableLabel
      spss.Submit(r"""
      GGRAPH
 /GRAPHDATASET NAME="graphdataset" VARIABLES=%(varname)s COUNT()
[name="COUNT"] MISSING=LISTWISE
   REPORTMISSING=NO
 /GRAPHSPEC SOURCE=INLINE
  TEMPLATE=[chart_data_labels.sgt].
BEGIN GPL
 SOURCE: s=userSource(id("graphdataset"))
 DATA: fred=col(source(s), name("%(varname)s"), unit.category())
 DATA: COUNT=col(source(s), name("COUNT"))
 COORD: polar.theta(startAngle(0))
 GUIDE: axis(dim(1), null())
 GUIDE: legend(aesthetic(aesthetic.color.interior))
 GUIDE: text.title(label("%(title)s"))
 SCALE: linear(dim(1), dataMinimum(), dataMaximum())
 SCALE: cat(aesthetic(aesthetic.color.interior), include("1", "2",
"3", "4", "5", "9999"))
 ELEMENT: interval.stack(position(summary.percent(COUNT))),
color.interior(fred))
END GPL.
      """ %{'varname':var, 'title':texttitle})
END PROGRAM.

Thanks in anticipation,
Simon

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: Desired Data Value Labels not being applied by template?

Simon Palmer-4
Hello ViAnn,

> You can directly speciffy the percentage chart labels using the
> label function on the ELEMENT statement, as in
> label(summary.percent(fred)).

Thank you for your assistance - this was just the piece of magic I
needed.

Cheers,
Simon

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

comparing ranked data with non-occurring ranks

bgreen
Hello,

I am hoping for some advice regarding comparing offence seriousness
between three groups. Offences are ranked on a scale from 1-155. This
data is i effect, pre and post data so it is not independent.  For
some people there is no offending at time 2 (a good thing) but,
accordingly, there is no ranking.  I wanted to compare the offence
seriousness at time 1 and at time 2.

My questions:

1) I could simply exclude all persons who did not have an offence at
time two and compare the average or median ranking for each group. Is
there a better way to handle the non-offending of persons at time 2
than simply excluding them? Assigning a value greater than the least
serious offence seems problematic

2) Is there a better way to examine whether offence seriousness has
declined than comparing the average or median values for each group?

Any advice is appreciated,

Bob

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: comparing ranked data with non-occurring ranks

Steve Simon, P.Mean Consulting
Bob Green wrote:

> I am hoping for some advice regarding comparing offence seriousness
> between three groups. Offences are ranked on a scale from 1-155. This
> data is i effect, pre and post data so it is not independent.  For
> some people there is no offending at time 2 (a good thing) but,
> accordingly, there is no ranking.  I wanted to compare the offence
> seriousness at time 1 and at time 2.
>
> My questions:
>
> 1) I could simply exclude all persons who did not have an offence at
> time two and compare the average or median ranking for each group. Is
> there a better way to handle the non-offending of persons at time 2
> than simply excluding them? Assigning a value greater than the least
> serious offence seems problematic
>
> 2) Is there a better way to examine whether offence seriousness has
> declined than comparing the average or median values for each group?

The obvious thing is to compute a non-offence as zero. Then compute a
sign test.

The problem with this, I suspect, is that the way your sample was
collected prohibits the possibility of a zero (no offence) as a pre
measurement. In that case, you're comparing apples and oranges.

Another possibility is to compute three events:
  1. pre offence is followed by no offence.
  2. pre offence is followed by a less serious post offence.
  3. pre offence is followed by an equal or more serious post offence.

Estimate each of these probabilities and place confidence limits around
the values. They won't be independent since they sum to zero, but
whether or not the confidence limits for some of these probabilities
include/exclude 0.5 would make for an interesting discussion.

A third possibility is to use the sign test first with no offence
excluded and then with no offence included. If both tests support the
same conclusion, you have a nice explanation. If they support
contradictory conclusions, then discuss both in detail and let the
reader decide which one is best.

Good luck!
--
Steve Simon, Standard Disclaimer
Two free webinars coming soon!
"What do all these numbers mean? Odds ratios,
relative risks, and number needed to treat"
Thursday, December 17, 2009, 11am-noon, CST.
"The first three steps in a descriptive
data analysis, with examples in PASW/SPSS"
Thursday, January 21, 2010, 11am-noon, CST.
Details at www.pmean.com/webinars

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: comparing ranked data with non-occurring ranks

bgreen
Steve,

Many thanks. Your reply makes a lot of sense.  Regarding your
suggestion"Estimate each of these probabilities and place confidence
limits around the values. They won't be independent since they sum to
zero, but whether or not the confidence limits for some of these
probabilities include/exclude 0.5 would make for an interesting discussion."

I did a search of the SPSS archives and came across an e-mail from
John Peck: "When we investigated this question a few years ago, we
came up with 16 ways of computing the ci's, if my memory is correct.

There is an extension command, PROPOR, that can be downloaded from
Developer Central (www.spss.com/devcentral) that does just a few of
these and is pretty flexible in the data structures it accepts.  It
requires at least v16 and the Python plugin, but no Python knowledge
is required to use it."

To calculate the difference in proportions, as you describe, across
three groups, what would be the preferred option in SPSS?


Thanks again,


Bob


At 12:40 AM 11/12/2009, Steve Simon, P.Mean Consulting wrote:

>Bob Green wrote:
>
>>I am hoping for some advice regarding comparing offence seriousness
>>between three groups. Offences are ranked on a scale from 1-155. This
>>data is i effect, pre and post data so it is not independent.  For
>>some people there is no offending at time 2 (a good thing) but,
>>accordingly, there is no ranking.  I wanted to compare the offence
>>seriousness at time 1 and at time 2.
>>My questions:
>>1) I could simply exclude all persons who did not have an offence at
>>time two and compare the average or median ranking for each group. Is
>>there a better way to handle the non-offending of persons at time 2
>>than simply excluding them? Assigning a value greater than the least
>>serious offence seems problematic
>>2) Is there a better way to examine whether offence seriousness has
>>declined than comparing the average or median values for each group?
>
>The obvious thing is to compute a non-offence as zero. Then compute
>a sign test.
>
>The problem with this, I suspect, is that the way your sample was
>collected prohibits the possibility of a zero (no offence) as a pre
>measurement. In that case, you're comparing apples and oranges.
>
>Another possibility is to compute three events:
>  1. pre offence is followed by no offence.
>  2. pre offence is followed by a less serious post offence.
>  3. pre offence is followed by an equal or more serious post offence.
>
>Estimate each of these probabilities and place confidence limits
>around the values. They won't be independent since they sum to zero,
>but whether or not the confidence limits for some of these
>probabilities include/exclude 0.5 would make for an interesting discussion.
>
>A third possibility is to use the sign test first with no offence
>excluded and then with no offence included. If both tests support
>the same conclusion, you have a nice explanation. If they support
>contradictory conclusions, then discuss both in detail and let the
>reader decide which one is best.
>
>Good luck!
>--
>Steve Simon, Standard Disclaimer
>Two free webinars coming soon!
>"What do all these numbers mean? Odds ratios,
>relative risks, and number needed to treat"
>Thursday, December 17, 2009, 11am-noon, CST.
>"The first three steps in a descriptive
>data analysis, with examples in PASW/SPSS"
>Thursday, January 21, 2010, 11am-noon, CST.
>Details at www.pmean.com/webinars

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD