[R] How to use R to perform prediction based on history data

Gabor Grothendieck ggrothendieck at gmail.com
Tue Aug 18 15:38:56 CEST 2009


Please read the last line to every message on r-help and note the
request to provide reproducible code.

Anyways, try this:

Lines <- "Field1 Field2 Field3     Field4  ResultField
1231    CA       TRUE    443        TRUE
23231  NC       TRUE    123        FALSE
1231    CA        FALSE    243        TRUE
23231  NC       TRUE    123 NA"

DF <- read.table(textConnection(Lines), header = TRUE)

# logistic regression using first 3 rows
mod <- glm(ResultField ~., DF[1:3, ], family = binomial)

# prediction using 4th row
predict(mod, DF[4, 1:4], type = "response")

and also have a look at the caret package.

On Fri, Aug 14, 2009 at 10:27 PM, Jack Su<jacksuyu at gmail.com> wrote:
> Say I have a csv file, each row contains several fields, one of them
> are whether the row is success.
>
> In history data, I have all the fields including the result of whether
> it is success. In future data, I only have fields without the result.
>
> For example:
>
> history data:
>
> Field1 Field2 Field3     Field4  ResultField
> 1231    CA       TRUE    443        TRUE
> 23231  NC       TRUE    123        FALSE
> 1231    CA        FALSE    243        TRUE
>
> The future data:
> Field1 Field2   Field3     Field4
> 23231  NC       TRUE    123
>
>
>
> I am newbie in R and statistics, I just feel R could have some
> mechanism to give the probably of success rate based on history data.
>
> I tried to read in the csv data, and try to call "factor" on the list,
> but I am seeing error message:
> Error in sort.list(unique.default(x), na.last = TRUE) :
>
> Any idea are highly welcome.
>
> Thanks in advance.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list