Question: I have:

```
myColCI<-function(colName){
  predictorvariable <- glm(death180 ~ nepalData[,colName], data=nepalData, family="binomial")
  summary(predictorvariable)
  confint(predictorvariable)
}

```

One of the names of the column is parity so when after making my function, when I put `myColCI(parity)`, it says the 

> 
> object "parity" is not found
> 
> 
> 

Can anyone give me a pointer to what's wrong with my code.

Answer: 
Your formula is wrong here, hence you are getting the error, The right hand side after tilda side shouldn't be a reference to a dataframe. It should be column names separated by plus signs :

From the documentation of `?formula`

> 
> The models fit by, e.g., the lm and glm functions are specified in a
>  compact symbolic form. The ~ operator is basic in the formation of
>  such models. An expression of the form y ~ model is interpreted as a
>  specification that the response y is modelled by a linear predictor
>  specified symbolically by model. Such a model consists of a series of
>  terms separated by + operators. The terms themselves consist of
>  variable and factor names separated by : operators. Such a term is
>  interpreted as the interaction of all the variables and factors
>  appearing in the term.
> 
> 
> 

`dependent_variable ~ Independent_variable1 + Independent_variable2` etc

From data `mtcars`, I have written a glm formula as :
`glm(am ~ mpg + disp + hp, data=mtcars, family="binomial")`

So, your formula should be something like this:

```
glm(death180 ~ column1 + column2 +column3, data= nepalData, family="binomial")

```

To invoke this inside a function, since you have only one dependent variable it seems you can use below (Note here that, removing the datframe reference here and adding the as.formula expression to incorporate strings, convert the expression as valid formula):

```
myColCI<-function(colName){
  predictorvariable <- glm(as.formula(paste0("death180 ~", colName)), data=nepalData, family="binomial")
  summary(predictorvariable)
  confint(predictorvariable)
}

myColCI("parity")

```
This is what you have to do

```
myColCI("parity")

```

This should give you the answer.

I don't think your code is wrong. You are trying to subset a column of a data frame using the column name. In R, when you do this, you have to pass the name as a string. eg

```
dataframe[,"column_name"]

```

For your function, if you want to have both the confidence intervals and summary output, you would have to modify a little bit. Just like this:

```
myColCI<-function(colName){
  predictorvariable <- glm(death180 ~ nepalData[,colName], 
  data=nepalData, family="binomial")
  return(list(summary(predictorvariable),confint(predictorvariable)))
}

```