[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-help
Subject:    Re: [R] Fitting quantile (or cdf?) function to data with specified percentiles
From:       David Winsemius <dwinsemius () comcast ! net>
Date:       2016-05-29 20:07:47
Message-ID: 30DFE357-9DF8-4268-A100-13D91ED964D4 () comcast ! net
[Download RAW message or body]


> On May 26, 2016, at 7:51 PM, Franco Danilo Roca Landaveri <fradarola@hotmail.com> \
> wrote: 
> Hello,
> 
> I hope you can help me. In class, we were given an Excel worksheet with specified \
> formulas that take the total score from a survey (or from a specific section) and \
> convert it to a percentage, according to a table that assigns scores to a \
> percentile. Since the formulas are too long and complicated (some have been input \
> by hand) I figured we could fit the data with a function with some parameters. I \
> plotted the table and sure it resembled a more-or-less symmetrical quantile \
> function, and I wanted to use R to find a curve that fitted the data. Here it is: 
> percentile <- c(0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.05, 0.05, 0.05,
> 0.05, 0.05, 0.10, 0.10, 0.15, 0.15, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50,
> 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.90, 0.95, 0.95, 0.99, 0.99, 0.99, 0.99,
> 0.99, 0.99, 0.99, 0.99, 0.99)
> 
> score <- c(10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
> 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
> 45, 46, 47, 48, 49, 50)
> 

Use approxfun:

myapprox <- approxfun( x=score, y=percentile)

> myapprox(27.8)
[1] 0.29

> myapprox(27.8)
[1] 0.29

> myapprox(50)
[1] 0.99
> myapprox(51)
[1] NA

You can change how values outside the max and min limits are handles with furhter \
arguments to approxfun.

— 
David.


> I looked up the quantreg package, but I didn't know how to use it properly since I \
> don't have the raw data, only the percentiles, and also because what I'm trying to \
> get is the percentile based on the score, not the other way around. Then I tried to \
> fit it using a sigmoid curve (similar to a cdf), using the following code: 
> require(drc)
> model1 <- drm(percentile ~ score, fct = LL.4())
> summary(model1)
> 
> But I found another problem, the fitted curve apparently went over 1 on the y axis, \
> something not possible for a cdf. I'd like to know what would be the most \
> appropiate way to do this, and also if it is possible to fit a quantile function \
> with this data, apart from the cdf. 
> Thank you very much for your help
> 		 	   		  
> ______________________________________________
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic