0

I have a data form as follows:

x    y   chla   sst   ssha   eke  tuna
:    :     :     :      :     :     : 
:    :     :     :      :     :     :

I used a GAM model as follows:

GAM <- gam(tuna~s(chla), family = binomial, data = nonLinear)

By using this model above, I can process the data for chla, sst and ssha. But when I processed the eke data, it was not working R gave me the following error:

error in eval(expr, envir, enclos) : object `eke` not found.

Can anybody help me to solve this problem? I already installed the ROCR package to calculate the AUC. But I do not know how (the syntax) to calculate the AUC. Can anybody help me to solve this problem too?

I also used the following command to make a graph:

plot(GAM, xlab=..., ylab=..... font.lab= ...shade=....)

But when I run that command, the result is not so good. I mean, the scale on the y-axis is very weird. How do I set the scale on the y-axis and x-axis in 1 and 5 interval (for instance) respectively?

Shawn Hemelstrand
  • 2,676
  • 4
  • 17
  • 30
ahmad
  • 21
  • 1
  • 5
  • GAM mean Generalized Additive Model – ahmad May 21 '14 at 03:11
  • I have no idea about R, but I suspect adding screenshots of your 'not quite right' graphs might be helpful. – Journeyman Geek May 21 '14 at 03:54
  • Can you add the output of `str(nonLinear)` to your question. As well as `dput(names(nonLinear))` I'm working if "eke" has a bad character or is a different class than the other vectors. – MrFlick May 21 '14 at 05:59
  • I am sorry MrFlick I do not understand what do you mean. Could you help me with the example syntax? – ahmad May 22 '14 at 01:29

1 Answers1

1

Since you didn't include any test data, I will use the test data in the gam package to calculate AUC and plot an ROC curve.

library(gam)
library(ROCR)

#sample binomial regression    
data(kyphosis)
GAM<-gam(Kyphosis ~ poly(Age,2) + s(Start), data=kyphosis, family=binomial)

#get the predicted probabilities for each sample
gampred <- predict(GAM, type="response")

#make a ROCR prediction object using the predicted values from
#    our model and the true values from the real data
rp <- prediction(gampred, kyphosis$Kyphosis) 

#now calculate AUC
auc <- performance( rp, "auc")@y.values[[1]]
auc

#not plot ROC curve
roc <- performance( rp, "tpr", "fpr")
plot( roc )

ROC curve

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • Actually I want to plot the Chl-a vs s(Chl-a), SST vs s(SST) and soon. How do I do that? – ahmad May 22 '14 at 00:30
  • @ahmad I don't know what your notation means. – MrFlick May 22 '14 at 00:33
  • From your answer, I think the name of your data is kyphosis. is it true? My input data is in .txt (for instance 2005.txt). When I change kyphosis with 2005 or with 2005.txt, R program said `Error:unexpected input in "rp <- prediction(gampred, 2005$". What should I do now? – ahmad May 22 '14 at 00:51
  • @ahmad Since you didn't supply any data, I used the example dataset kyphosis form the GAM package. The data frame is named "kyphosis" and the response variable in that data.frame used for the GAM regression is named "Kyphosis" (capitalization matters). – MrFlick May 22 '14 at 00:58
  • As I know, gam model has a smoothing function for each of the model covariates. I also used mgcv package in here. So that why I want to plot Chl-a vs s(Chl-a), SST vs s(SST), SSHA vs s(SSHA), and EKE vs s(EKE). – ahmad May 22 '14 at 01:09
  • @ahmad That's a different question than the one you started this with. Rather than asking about new topics in the comments, it's better to open a new question on the site if you need further assistance. – MrFlick May 22 '14 at 01:11
  • I am sorry MrFlick, but may I sent my data to your email address (just for example)? – ahmad May 22 '14 at 01:19