I am currently working on a small sponsorship application(PHP/MySql) for my personal blog, and am almost finish, but I am stuck on how to calculate the click-thru rate of my sponsors campaigns.
I was always terrible with working out percentages, so any practical help would be appreciated. The data is stored in the DB as simple numbers.. So as expected, when a page refreshes, or a sponsors ad is clicked, the data updates with an incrementation of 1.
So using these values...say $clicks and $impressions, how would I determine the click-thru rate? What would be the sum I would use to calculate? An example function would really be appreciated.
Kind Regards, Lea
What you're after is the percentage of $impressions that leads to $clicks. The ratio is found by calculating $clicks/$impressions, and then you can multiply by 100 to see the percentage.
As an example, if there are 100 impressions and 1 click, the ratio will be 1/100 = 0.01, and the percentage will be 0.01 * 100 = 1%.
Related
I have a database that has over 1,000 users and points that rank them on skill. I'm going to take the user with the most points and base off my rankings on that alone. So, say the player has 900 points, I will create 5 "divisions" based off that. The higher the division, the lesser the percentages and harder it is to get into. So, with that being said, let me show you an example.
Here are 5 divisions based from best to least.
Master
Platinum
Gold
Silver
Bronze
Iron
So, the player with the most points would already be in the "Master" division. Then I want to create percentages based off of these divisions. So, for example, here is how I plan on setting up the percentages.
Master 5%
Platinum 10%
Gold 15%
Silver 20%
Bronze 25%
Iron 25%
So as you can see, I need to be able to get the percentages of this and use it on the player who has the most points. So in this case, I need to be able to display this on any user's profile. So I need to take the user's points of the profile I am looking at and compare it with the player who has the most points and form a division for the given player's profile I am looking at.
function rank($rank, $mostpoints) {
$count = $rank / $mostpoints;
}
I am aware it isn't really much. But I know I can finish the rest off with IF statements, however, I want to know the best way to take percents of this number. I need to be able to take the current rank and spit out a division. I realized, however, that I can't just take the percent of Master (5%) and divide it by the most points and have it allocate as the Master. I need a way to be able to break the mostpoints into 5 sections based on the percentages and then do if statements to see if the user belongs in them based on the rank. Can anyone provide any feedback on the most efficient way to do this?
I am working on a website where users can bet on events with variable win chance. One of the rquests is to display the "Luck factor" of a certain user, based on his bets.
Here is the definition of the Luck factor:
The luck percentage displayed shows how many bets you have won compared to how many you 'should' have won. For example, if you play 10 times with a 10% chance of winning and win two of the 10 bets, your luck will show as 200%, since you have won twice as many as you 'should' have. Bet size is not taken into account when calculating luck, so it is possible to have a luck less than 100% and still show a profit if your winning bets risked more than your losing bets.
Here is my (MySQL) database structure:
Table bet
Columns:
winchance (0.01 - 99.99)
win (true/false)
The application is written in php, but I am sure a pseudocode example would push me to the right direction.
If I understand your question, right, You can take the average of winning probability using mysql winchance column and real winning ratio, would be (number of wins / total number of bets). Given these two values, luck factor would be real ratio / winchance avg * 100.
For instance, avg win chance is 0.1 and real winning ratio, is 2 / 10 = 0.2, then luck factor is 0.2/0.1 * 100 = 200%. This shall be easily calculated with mysql inbuilt functions itself.
I need to calculate a star rating for a product
I know how to calculate the weighted average, but its not good enough
example (5*252 + 4*124 + 3*40 + 2*29 + 1*33) / (252+124+40+29+33) = 4.11
I want to avoid cases when a product get a 1000 five star ratings and one 4 star, and another one gets just one 5 stars and it gets on top
I know there is a way but i couldn't find it
thanks
Try sort you product record using new column (rating * votes).
it will help you to find the most voted product with best rating.
use sorting which can include number of ratings, something like number of votes divided by calculated avg rating.
You can multiply for a weight function, that gives a penalty to product with lower number of votes and converge in time. Something like this should do the job.
a parabole truncated to 1 should do the job
EX:
convergence_step=1000
if voters<convergence_step:
meanscore=score*{[(voters)/(float)(convergence_step)]^2}
else
meanscore=score
One element of my site is a rating system. I am puzzled a bit by how best to set up the formula and I hope someone with more math aptitude can help me.
Users upload pictures that are rated 1-10 by other users. The users rating then is the average of those scores.
Simple enough. However, I want to add some system which rewards users for uploading more pictures. SO that the formula would be average of ratings + some function of the number of pictures uploaded.
An example might be, Rating = AVG + .05 * Count
This formula would be somewhat fair for users who have uploaded 1-20 pictures... However, if users upload 2000 pictures they will have bipassed the entire rating system and automatically will have a 10/10.
So, my limited knowledge of post algebra math is failing. What would be some formula that would produce the desired effect? The word "log" keeps bouncing around in my head--but I honesty can't remember anything about why... :)
Just do something like:
avg + numofpics*scale*(.9^numofpics)
This will make it do that as they upload more pictures they get less and less. You can change .09 (the rate of decay) depending on how many pictures you expect the average user to upload.
This the equation used for half life decay
you could do something like:
Rating = Average + (\sum_{i=1}^numofuploads 1/i)*scalefactor
though the sum grows to infinity - the sum grows very slowly
Edit:
The idea is basically the same as with #maxhud's solution you add less points to your rating for every picture, and for simplicity say scaling is 1/3, and for now i use exact not floating point math
1 -> avg + (1/1)*.3 = avg + 1/3
2 -> avg + (1/1+1/2)/3 = avg + (3/2)/3) = avg + 1/2
3 -> avg + (3/2+1/3)/3 = avg + (10/6)/3 = avg + 10/18 = avg + 5/9 ~ avg + .55555
4 -> ...
technically the series (1+1/2+1/3+…) is going to infinity but you'd have to upload a huge amount of pictures to go over 50 - so you'd better choose your scaling factor carefully and give a bit, of thought. If you want to have a maximum of points that can be achieved via uploading this is the WRONG solution. You should rather go with something like
avg + scaling*(.9^n)
where n is the number of pictures. if you could upload infinitely many pictures you would have
avg + scaling*(1/(1-.9)) = avg + 10*scaling
for your rating: which is, as I commented, much better.
ps: I think #maxhud should leave
avg + numofpics*scale*(.9^numofpics)
^^^^^^^^^
because after uploading 10 pictures you have outweight your shrinking growth function.
Consider an alternative approach - you want to reward users by increasing for uploading images but perhaps the user is uploading many many images that are not rated highly. Do you want to reward them if the majority of their images are poor?? Consider stackoverflow as an example - you can answer many many questions, but if they are not considered "good" by the rest of the community your reputation will not increase, no matter how many answers you provide.
It is possible that this is not how you want to do it and want to reward quantity rather than quality, but should you decide the opposite you could try something like
UserRating = 10 * (AverageRating/10 + Scalefactor*((AverageRating/10)^2 * ImageUploadCount)))
You choose scale factor to be what you want and obviously limit the rating as maximum 10. This way, you reward mutiple image uploads, but you reward users with higher quality image uploads too. Consider someone automates uploading images with some type of web bot and all images are considered poor by users - do you want to reward it? This way you can reward multiple uploads, but better quality uploads are treated more favourably. Maybe not what you are looking for but worth considering perhaps - only you can decide....
I have found an excel file online that helps with the calculations of a Drugs Half-life and helps to determine how much of the given drug is likely to remain in ones system based on
Hal-life Hour Number
The quantity of the Drug taken per dose
how much is in your system from previous doses
Below is a screenshot of the Excel file showing both the Output with the calculations already performed and also shows the actual Math that is involved for each day...
The Columns A, B, C, D, E, etc.. is the Day 24 hours
Column D Row 6 is the Half life for a Drug in Hours
From the Image below you can see that the calculation is perfromed and that Value is then used in the Next Day's equation
Ok so I am not that knowledgeable with Math outside of basic Addition, Subtraction, Multiplication, and Division I do not know much more then that.
My goal is to create a tool similar to this Excel file but with PHP, I am not sure how to do so but I think all the answers are right here in the image above as far as the math portion.
Looking at D3 I can see that it takes...
D2's value which is 30 in the Image
It then Adds C3's value
Then Multiplies that by 1/2
I am not sure what the ^ does though?
Then it Divides 24 hours by D6 which holds the Hour Number
In my PHP I would like to have a Function that I can pass an array of Data, so let's say I pass in an Array with...
the Number of Days to calculate (my image shows like 4 days so if I pass 10 days, it will shows the daily results up to 10 days)
Then an array of the Daily amount consumed in mg (so in my image this would be an array with 30,0,30,0,0,0,0
Then I would also pass in the Half Life in Hours, so in my image the drug used has a half-life of 4.5 hours
This function would then return an array with the data for each day, should show the remaining mg in one's system for each day, I can then use this data result to build charts, graphs, or simply a List
I would appreciate any help to get me started, I think I can pull this off on my own but I need help getting the math portion 100%, above I break down the equation as I see it, please help me understand better for example I am not sure what ^ does in the equation or how to do it in PHP
I hope my question is not too vague, I will come back with more specific once I get a good start on this but please help if you can so far, thank you for reading.
function calcHalfLife( $mgTaken , $drugHalfLifeHours , $day ) {
//total number of half-lifes elapsed
$total_half_lifes = ($day * 24) / $drugHalfLifeHours;
//total reduction in dosage
$reductionFactor = pow( 0.5 , $total_half_lifes );
//return the current dosage in the person's system
return round( $mgTaken * $reductionFactor , 2 );
}
The above function should do the trick. Pass in the MG dosage taken, the number of hours for that drug's half-life, and the number of days since the dosage.
The function calculates the number of half-lifes experienced by the drug by taking the number of days * 24 hours in a day and dividing that by the total number of hours it takes for a half-life of that drug. This is the number of times the drug's dosage would be cut in half.
It then takes 0.5 (50% as a decimal) and increments it to the power of the total number of half lifes experienced by the drug. So 1 half life would be 0.5, 2 would be 0.5 * 0.5 = 0.25 etc etc. This is the decimal representation of the percentage of the drug left in the person's system.
It then multiplies that remainder by the original amount taken and rounds it off to 2 decimal places. The return floating point value will be a representation of the remaining MG dosage of the drug in the person's system.
If you're looking to build a function/system that allows you to calculate a daily dosage of that drug (ie: the person takes the same dosage each day as opposed to once) that is a very different formula and function, but the basic principle is the same as the one I wrote for you here.
Good luck ;)