Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The cost function can optionally be defined if there is one you prefer over the default average squared error. If you wanted to do so then the you would write a function that returns the cost you want to minimize using two inputs: (1) the vector of known labels that you are predicting, and (2) the vector of predicted probabilities from your model for those corresponding labels. So for the cost function that (I think) you described in your post you are looking for a function that will return the average number of accurate classifications which would look something like this:</p> <pre><code>cost &lt;- function(labels,pred){ mean(labels==ifelse(pred &gt; 0.5, 1, 0)) } </code></pre> <p>With that function defined you can then pass it into your <code>glm.cv()</code> call. Although I wouldn't recommend using your own cost function over the default one unless you have reason to. Your example isn't reproducible, so here is another example:</p> <pre><code>&gt; library(boot) &gt; &gt; cost &lt;- function(labels,pred){ + mean(labels==ifelse(pred &gt; 0.5, 1, 0)) + } &gt; &gt; #make model &gt; nodal.glm &lt;- glm(r ~ stage+xray+acid, binomial, data = nodal) &gt; #run cv with your cost function &gt; (nodal.glm.err &lt;- cv.glm(nodal, nodal.glm, cost, nrow(nodal))) $call cv.glm(data = nodal, glmfit = nodal.glm, cost = cost, K = nrow(nodal)) $K [1] 53 $delta [1] 0.8113208 0.8113208 $seed [1] 403 213 -2068233650 1849869992 -1836368725 -1035813431 1075589592 -782251898 ... </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload