SPSSINC ROBUST REGR

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

SPSSINC ROBUST REGR

drfg2008
SPSSINC ROBUST REGR

The model computes an intercept. Is there any means to build the model without an intercept?

Thanks
Dr. Frank Gaeth

Reply | Threaded
Open this post in threaded view
|

Re: SPSSINC ROBUST REGR

Jon K Peck
There is no provision for suppressing the intercept in this extension command, but you can easily modify it to do this.  Here are the steps.

1) Using the dialog box or syntax, specify your model and that the generated R program be saved to a file (under the Save subdialog).
2) Open that file in a syntax window.
3) Put BEGIN PROGRAM R. at the top and END PROGRAM at the bottom.
4 )Look around line 33 for this code:
    model <- paste(dep,"~",paste(enter,collapse="+"))
5) Insert this line right after it.
  model <- sub("~", "~0+", model)
6) Select then entire file and run it.

HTH,

Jon Peck (no "h")
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        drfg2008 <[hidden email]>
To:        [hidden email]
Date:        08/22/2011 08:17 AM
Subject:        [SPSSX-L] SPSSINC ROBUST REGR
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




SPSSINC ROBUST REGR

The model computes an intercept. Is there any means to build the model
without an intercept?

Thanks

-----
Dr. Frank Gaeth
FU-Berlin

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/SPSSINC-ROBUST-REGR-tp4723566p4723566.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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: SPSSINC ROBUST REGR

drfg2008
In reply to this post by drfg2008


Couldn't find: model <- paste(dep,"~",paste(enter,collapse="+"))



This is the R - SPSS Syntax

BEGIN PROGRAM R.
library(MASS)
makefactor = function(var, vallabels, ordfac) {
# return a labeled factor for variable var and label set vallabels
# if vallabels is NULL, the raw values will label the factor.
# if ordfac is TRUE, returns an ordered factor
values = sort(unique(var))
lbls = values
lmatch = match(vallabels$values, values, nomatch=0)
lmatch2 = match(values[lmatch], vallabels$values)
lbls[lmatch] = vallabels$labels[lmatch2]
if (ordfac) {
  return (ordered(var, levels=values, labels=lbls))}
else {
  return (factor(var, levels=values, labels=lbls))
}
}
loopfactor = function(vars, indexes) {
if (length(indexes) == 0) {return(dta)}
for (v in 1:length(indexes)) {
  vl = spssdictionary.GetValueLabels(vars[v])
  dta[indexes[v]] = makefactor(dta[[indexes[v]]], vl, FALSE)
}
return(dta)
}

catlistnames = c()
catlistrindex = c()

dta<-spssdata.GetDataFromSPSS("liq_lay standard_Back_1 standard_Lay_1 standard_Back_2 standard_Lay_2")
# Convert NaN values to NAMA
is.na(dta)<- is.na(dta)

dta=loopfactor(catlistnames, catlistrindex)

res <- tryCatch(
    summary(
        resrlm <- rlm(liq_lay ~ standard_Back_1+standard_Lay_1+standard_Back_2+standard_Lay_2, data=dta, na.action=na.exclude, method="MM", model=FALSE)
    ),
error=function(e)
    {return(c("ERROR:",e))}
)

if (!is.null(res$message)) {print(res$message);break} else {
  caption = paste(c(res$call), sprintf("\nResidual standard error: %.5f\nDegrees of freedom: %s", res$sigma, res$df[[2]]))
  spsspivottable.Display(coefficients(res),
    title="SPSSINC Robust Regression", "SPSSINCROBUSTREGR",
    caption=caption,
    isSplit=FALSE)

   
   
   spssdictionary.EndDataStep()
}

rm(dta)
rm(res)
rm(resrlm)
END PROGRAM   .
Dr. Frank Gaeth

Reply | Threaded
Open this post in threaded view
|

Re: SPSSINC ROBUST REGR

Jon K Peck
You are using a much older version of the module, it appears.  The equivalent modification would be to change
resrlm <- rlm(liq_lay ~
to read
resrlm <- rlm(liq_lay ~ 0+

Jon Peck (no "h")
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        drfg2008 <[hidden email]>
To:        [hidden email]
Date:        08/24/2011 02:31 PM
Subject:        Re: [SPSSX-L] SPSSINC ROBUST REGR
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Couldn't find: model <- paste(dep,"~",paste(enter,collapse="+"))



This is the R - SPSS Syntax

BEGIN PROGRAM R.
library(MASS)
makefactor = function(var, vallabels, ordfac) {
# return a labeled factor for variable var and label set vallabels
# if vallabels is NULL, the raw values will label the factor.
# if ordfac is TRUE, returns an ordered factor
values = sort(unique(var))
lbls = values
lmatch = match(vallabels$values, values, nomatch=0)
lmatch2 = match(values[lmatch], vallabels$values)
lbls[lmatch] = vallabels$labels[lmatch2]
if (ordfac) {
 return (ordered(var, levels=values, labels=lbls))}
else {
 return (factor(var, levels=values, labels=lbls))
}
}
loopfactor = function(vars, indexes) {
if (length(indexes) == 0) {return(dta)}
for (v in 1:length(indexes)) {
 vl = spssdictionary.GetValueLabels(vars[v])
 dta[indexes[v]] = makefactor(dta[[indexes[v]]], vl, FALSE)
}
return(dta)
}

catlistnames = c()
catlistrindex = c()

dta<-spssdata.GetDataFromSPSS("liq_lay standard_Back_1 standard_Lay_1
standard_Back_2 standard_Lay_2")
# Convert NaN values to NAMA
is.na(dta)<- is.na(dta)

dta=loopfactor(catlistnames, catlistrindex)

res <- tryCatch(
   summary(
       resrlm <- rlm(liq_lay ~
standard_Back_1+standard_Lay_1+standard_Back_2+standard_Lay_2, data=dta,
na.action=na.exclude, method="MM", model=FALSE)
   ),
error=function(e)
   {return(c("ERROR:",e))}
)

if (!is.null(res$message)) {print(res$message);break} else {
 caption = paste(c(res$call), sprintf("\nResidual standard error:
%.5f\nDegrees of freedom: %s", res$sigma, res$df[[2]]))
 spsspivottable.Display(coefficients(res),
   title="SPSSINC Robust Regression", "SPSSINCROBUSTREGR",
   caption=caption,
   isSplit=FALSE)



  spssdictionary.EndDataStep()
}

rm(dta)
rm(res)
rm(resrlm)
END PROGRAM   .


-----
Dr. Frank Gaeth
FU-Berlin

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/SPSSINC-ROBUST-REGR-tp4723566p4731778.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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: SPSSINC ROBUST REGR

drfg2008
that works perfectly, thanks
Dr. Frank Gaeth